android_kernel_google_msm/kernel
Iliyan Malchev 7e87a4dc87 PM: wakeup_reason: correctly deduce wakeup interrupts
The wakeup_reason driver works by having a callback log_wakeup_reason(), be
called by the resume path once for each wakeup interrupt, with the irq number
as argument.  It then saves this interrupt in an array, and reports it when
requested (via /sys/kernel/wakeup_reasons/last_resume_reason) and also prints
the information out in kmsg.

This approach works, but it has the deficiency that often the reported wakeup
interrupt, while correct, is not the interrupt truly responsible for the
wakeup.  The reason for this is due to chained interrupt controllers (whether
in hardware or simulated in software).  It could be, for example, that the
power button is wired to a GPIO handled by a single interrupt for all GPIOs,
which interrupt then determines the GPIO and maps this to a software interrupt.
Whether this is done in software, or by chaining interrupt controllers, the end
result is that the wakeup reason will show not the interrupt associated with
the power button, but the base-GPIO interrupt instead.

This patch reworks the wakeup_sources driver such that it reports those final
interrupts we are interested in, and not the intermediate (and not the base)
ones.  It does so as follows:

-- The assumption is that generic_handle_irq() is called to dispatch all
   interrupts; due to this, chained interrupts result in recursive calls of
   generic_handle_irq().
-- We reconstruct the chains of interrupts that originate with the base wakeup
   interrupt and terminate with the interrupt we are interested in by tracing
   the calls to generic_handle_irq()
-- The tracing works by maitaining a per-cpu counter that is incremented with
   each call to generic_handle_irq(); that counter is reported to the
   wakeup_sources driver by a pair of functions, called
   log_possible_wakeup_reason_start() and log_possible_wakeup_reason_complete().
   The former is called before generic_handle_irq() handles the interrupt
   (thereby potentially calling itself recusively) and the latter afterward.
-- The two functions mentioned above are complemented by log_base_wake_reason()
   (renamed from log_wakeup_reason()), which is used to report the base wakeup
   interrupts to the wakeup_reason driver.
-- The three functions work together to build a set of trees, one per base
   wakeup reason, the leaves of which correspond to the interrupts we are
   interesed in; these trees can be arbitratily complex, though in reality they
   most often are a single node, or a chain of two nodes.  The complexity
   supports arbitrarily involved interrupt dispatch.
-- On resume, we build the tree; once the tree is completed, we walk it
   recursively, and print out to kmesg the (more useful) list of wakeup
   sources; simiarly, we walk the tree and print the leaves when
   /sys/kernel/wakeup_reasons/last_resume_reason is read.

Signed-off-by: Iliyan Malchev <malchev@google.com>
Change-Id: If8acb2951b61d2c6bcf4d011fe04d7f91057d139
2017-10-15 17:05:07 +03:00
..
debug debug: add parameters to prevent entering debug mode on errors 2012-05-18 17:03:10 -07:00
events perf: don't leave group_entry on sibling list (use-after-free) 2017-06-07 13:08:01 -06:00
gcov
irq PM: wakeup_reason: correctly deduce wakeup interrupts 2017-10-15 17:05:07 +03:00
power PM: wakeup_reason: correctly deduce wakeup interrupts 2017-10-15 17:05:07 +03:00
sched kernel: Only expose su when daemon is running 2017-05-19 18:41:25 -06:00
time tick: Upstream fixes 2017-08-25 20:00:22 +03:00
trace ring-buffer: Prevent overflow of size in ring_buffer_resize() 2017-06-26 21:35:28 +03:00
.gitignore kernel/hz.bc: ignore. 2016-10-29 23:12:15 +08:00
acct.c Merge branch 'for-linus2' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs 2012-01-08 12:19:57 -08:00
async.c kernel/async: remove redundant declaration. 2012-01-13 09:32:18 +10:30
audit.c constify path argument of audit_log_d_path() 2012-03-20 21:29:40 -04:00
audit.h audit: remove AUDIT_SETUP_CONTEXT as it isn't used 2012-01-17 16:16:57 -05:00
audit_tree.c VFS: Make clone_mnt()/copy_tree()/collect_mounts() return errors 2015-07-13 11:17:46 -07:00
audit_watch.c get rid of kern_path_parent() 2017-09-22 19:11:54 +03:00
auditfilter.c audit: allow interfield comparison in audit rules 2012-01-17 16:17:01 -05:00
auditsc.c BACKPORT: audit: fix a double fetch in audit_log_single_execve_arg() 2016-11-11 13:44:38 +11:00
backtracetest.c
bounds.c
capability.c Revert "capabitlies: ns_capable can use the cap helpers rather than lsm call" 2012-01-17 10:19:41 -08:00
cgroup.c move d_rcu from overlapping d_child to overlapping d_alias 2017-09-22 19:11:55 +03:00
cgroup_freezer.c cgroup: remove cgroup_subsys argument from callbacks 2012-02-02 09:20:22 -08:00
compat.c compat: Fix RT signal mask corruption via sigprocmask 2012-05-10 08:58:33 -07:00
configs.c
cpu.c cpu: Handle smpboot_unpark_threads() uniformly 2016-10-29 23:12:40 +08:00
cpu_pm.c
cpuset.c Autogenerated GPG tag for Rusty D1ADB8F1: 15EE 8D6C AB0E 7F0C F999 BFCB D920 0E6C D1AD B8F1 2012-04-02 08:53:24 -07:00
crash_dump.c
cred.c cred: copy_process() should clear child->replacement_session_keyring 2012-04-11 08:20:11 -07:00
delayacct.c
dma.c Remove all #inclusions of asm/system.h 2012-03-28 18:30:03 +01:00
elfcore.c
exec_domain.c
exit.c kernel: Only expose su when daemon is running 2017-05-19 18:41:25 -06:00
extable.c
fork.c kernel: Only expose su when daemon is running 2017-05-19 18:41:25 -06:00
freezer.c freezer: skip waking up tasks with PF_FREEZER_SKIP set 2013-07-12 14:22:56 -07:00
futex.c futex: Make lookup_pi_state more robust 2014-06-11 15:16:22 -07:00
futex_compat.c futex: Mark get_robust_list as deprecated 2012-03-29 11:37:17 +02:00
groups.c
hrtimer.c hrtimer: Provide clock_was_set_delayed() 2017-08-25 20:00:23 +03:00
hung_task.c hung_task: fix the broken rcu_lock_break() logic 2012-03-05 15:49:42 -08:00
irq_work.c irq_work: fix compile failure on tile from missing include 2012-04-13 13:15:16 -04:00
itimer.c itimer: Use printk_once instead of WARN_ONCE 2012-04-10 11:00:30 +02:00
jump_label.c static keys: Inline the static_key_enabled() function 2012-02-28 20:01:08 +01:00
kallsyms.c vsprintf: Fix %ps on non symbols when using kallsyms 2013-02-08 15:14:22 -08:00
Kconfig.freezer
Kconfig.hz
Kconfig.locks locking/kconfig: Simplify INLINE_SPIN_UNLOCK usage 2012-03-23 13:18:57 +01:00
Kconfig.preempt locking/kconfig: Simplify INLINE_SPIN_UNLOCK usage 2012-03-23 13:18:57 +01:00
kexec.c Merge branch 'akpm' (Andrew's patch-bomb) 2012-03-28 17:19:28 -07:00
kfifo.c
kmod.c PM / Sleep: Mitigate race between the freezer and request_firmware() 2012-03-28 23:30:28 +02:00
kprobes.c kprobes: return proper error code from register_kprobe() 2012-03-05 15:49:42 -08:00
ksysfs.c rcu: Add a module parameter to force use of expedited RCU primitives 2016-10-29 23:12:17 +08:00
kthread.c kthread: Fix the race condition when kthread is parked 2016-10-29 23:12:39 +08:00
latencytop.c
lglock.c brlocks/lglocks: turn into functions 2015-07-13 11:17:40 -07:00
lockdep.c lockdep: remove task argument from debug_check_no_locks_held 2013-07-12 14:22:56 -07:00
lockdep_internals.h
lockdep_proc.c
lockdep_states.h
Makefile hotplug: Fix UP bug in smpboot hotplug code 2016-10-29 23:12:39 +08:00
module.c module: Remove module size limit 2012-03-26 12:50:53 +10:30
mutex-debug.c
mutex-debug.h
mutex.c sched/rt: Use schedule_preempt_disabled() 2012-03-01 10:28:03 +01:00
mutex.h
notifier.c
nsproxy.c userns: make each net (net_ns) belong to a user_ns 2017-09-01 13:38:07 +03:00
padata.c padata: Fix cpu hotplug 2012-03-29 19:52:46 +08:00
panic.c panic: resume console if panic after console suspend. 2013-09-09 17:16:14 -07:00
params.c params: <level>_initcall-like kernel parameters 2012-03-26 12:50:51 +10:30
pid.c proc: Usable inode numbers for the namespace file descriptors. 2015-07-13 11:18:01 -07:00
pid_namespace.c proc: Usable inode numbers for the namespace file descriptors. 2015-07-13 11:18:01 -07:00
posix-cpu-timers.c [S390] cputime: add sparse checking and cleanup 2011-12-15 14:56:19 +01:00
posix-timers.c
printk.c flo: Put device-specific code behind #ifndef CONFIG_UML. 2015-05-20 15:22:06 +09:00
profile.c
ptrace.c __ptrace_may_access() should not deny sub-threads 2016-10-29 23:12:26 +08:00
range.c
rcu.h rcu: Add a module parameter to force use of expedited RCU primitives 2016-10-29 23:12:17 +08:00
rcupdate.c rcu: Make exit_rcu() more precise and consolidate 2016-10-29 23:12:17 +08:00
rcutiny.c rcu: Add RCU_NONIDLE() for idle-loop RCU read-side critical sections 2012-02-21 09:06:13 -08:00
rcutiny_plugin.h rcu: Make exit_rcu() more precise and consolidate 2016-10-29 23:12:17 +08:00
rcutorture.c PTR_ERR should be called before its argument is cleared. 2012-02-21 09:06:10 -08:00
rcutree.c rcu: Use smp_hotplug_thread facility for RCUs per-CPU kthread 2016-10-29 23:12:39 +08:00
rcutree.h rcu: Use smp_hotplug_thread facility for RCUs per-CPU kthread 2016-10-29 23:12:39 +08:00
rcutree_plugin.h rcu: Use smp_hotplug_thread facility for RCUs per-CPU kthread 2016-10-29 23:12:39 +08:00
rcutree_trace.c rcu: Use smp_hotplug_thread facility for RCUs per-CPU kthread 2016-10-29 23:12:39 +08:00
relay.c relay: prevent integer overflow in relay_open() 2012-02-10 09:04:49 +01:00
res_counter.c net: introduce res_counter_charge_nofail() for socket allocations 2012-01-22 15:08:46 -05:00
resource.c kernel: Restrict permissions of /proc/iomem. 2016-06-03 11:56:04 -07:00
rtmutex-debug.c
rtmutex-debug.h
rtmutex-tester.c
rtmutex.c
rtmutex.h
rtmutex_common.h
rwsem.c Remove all #inclusions of asm/system.h 2012-03-28 18:30:03 +01:00
seccomp.c seccomp: Use atomic operations that are present in kernel 3.4. 2014-10-31 19:46:31 -07:00
semaphore.c
signal.c signal, x86: add SIGSYS info and make it synchronous. 2014-10-31 19:46:15 -07:00
smp.c smp, idle: Allocate idle thread for each possible cpu during boot 2016-10-29 23:12:38 +08:00
smpboot.c smpboot: use kmemleak_not_leak for smpboot_thread_data 2016-10-29 23:12:40 +08:00
smpboot.h smpboot: Provide infrastructure for percpu hotplug threads 2016-10-29 23:12:39 +08:00
softirq.c softirq: Use hotplug thread infrastructure 2016-10-29 23:12:39 +08:00
spinlock.c locking/kconfig: Simplify INLINE_SPIN_UNLOCK usage 2012-03-23 13:18:57 +01:00
srcu.c rcu: Call out dangers of expedited RCU primitives 2012-02-21 09:06:08 -08:00
stacktrace.c
stop_machine.c stop_machine: Mark per cpu stopper enabled early 2016-10-29 23:12:39 +08:00
sys.c userns: Add kuid_t and kgid_t and associated infrastructure in uidgid.h 2017-09-01 13:38:06 +03:00
sys_ni.c seccomp: add "seccomp" syscall 2014-10-31 19:46:27 -07:00
sysctl.c FROMLIST: mm: mmap: Add new /proc tunable for mmap_base ASLR. 2016-10-29 23:12:40 +08:00
sysctl_binary.c msm: 8x55: put reason for boot in procfs from SMEM 2013-02-08 15:14:28 -08:00
taskstats.c
test_kprobes.c
time.c jiffies: Fix timeval conversion to jiffies 2016-10-29 23:12:15 +08:00
timeconst.bc kernel: Replace timeconst.pl with a bc script 2016-10-29 23:12:15 +08:00
timer.c tick: Upstream fixes 2017-08-25 20:00:22 +03:00
tracepoint.c static keys: Introduce 'struct static_key', static_key_true()/false() and static_key_slow_[inc|dec]() 2012-02-24 10:05:59 +01:00
tsacct.c [S390] cputime: add sparse checking and cleanup 2011-12-15 14:56:19 +01:00
uid16.c
up.c
user-return-notifier.c
user.c proc: Usable inode numbers for the namespace file descriptors. 2015-07-13 11:18:01 -07:00
user_namespace.c proc: Usable inode numbers for the namespace file descriptors. 2015-07-13 11:18:01 -07:00
utsname.c proc: Usable inode numbers for the namespace file descriptors. 2015-07-13 11:18:01 -07:00
utsname_sysctl.c
wait.c lockdep/waitqueues: Add better annotation 2011-12-21 10:07:39 +01:00
watchdog.c kernel/watchdog.c: add comment to watchdog() exit path 2012-03-23 16:58:32 -07:00
workqueue.c time: Remove CONFIG_TIMER_STATS 2017-07-02 13:03:26 +03:00
workqueue_sched.h