30 Jan, 2019

1 commit


12 Dec, 2018

1 commit


23 Nov, 2018

2 commits

  • The SPDX identifier is enough. Remove the license boilerplate.

    Signed-off-by: Thomas Gleixner
    Acked-by: Kees Cook
    Acked-by: Ingo Molnar
    Acked-by: John Stultz
    Acked-by: Corey Minyard
    Cc: Peter Zijlstra
    Cc: Kate Stewart
    Cc: Philippe Ombredanne
    Cc: Peter Anvin
    Cc: Russell King
    Cc: Richard Cochran
    Cc: "Paul E. McKenney"
    Cc: Nicolas Pitre
    Cc: David Riley
    Cc: Colin Cross
    Cc: Mark Brown
    Link: https://lkml.kernel.org/r/20181031182253.047449481@linutronix.de

    Thomas Gleixner
     
  • Update the time(r) core files files with the correct SPDX license
    identifier based on the license text in the file itself. The SPDX
    identifier is a legally binding shorthand, which can be used instead of the
    full boiler plate text.

    This work is based on a script and data from Philippe Ombredanne, Kate
    Stewart and myself. The data has been created with two independent license
    scanners and manual inspection.

    The following files do not contain any direct license information and have
    been omitted from the big initial SPDX changes:

    timeconst.bc: The .bc files were not touched
    time.c, timer.c, timekeeping.c: Licence was deduced from EXPORT_SYMBOL_GPL

    As those files do not contain direct license references they fall under the
    project license, i.e. GPL V2 only.

    Signed-off-by: Thomas Gleixner
    Acked-by: Kees Cook
    Acked-by: Ingo Molnar
    Acked-by: John Stultz
    Acked-by: Corey Minyard
    Cc: Peter Zijlstra
    Cc: Kate Stewart
    Cc: Philippe Ombredanne
    Cc: Russell King
    Cc: Richard Cochran
    Cc: Nicolas Pitre
    Cc: David Riley
    Cc: Colin Cross
    Cc: Mark Brown
    Cc: H. Peter Anvin
    Cc: Paul E. McKenney
    Link: https://lkml.kernel.org/r/20181031182252.879109557@linutronix.de

    Thomas Gleixner
     

20 Jul, 2018

1 commit

  • Add 'const' to some function arguments and variables to make it easier
    to read the code.

    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Cc: Miroslav Lichvar
    Cc: Richard Cochran
    Cc: Prarit Bhargava
    Cc: Stephen Boyd
    Signed-off-by: Ondrej Mosnacek
    [jstultz: Also fixup pre-existing checkpatch warnings for
    prototype arguments with no variable name]
    Signed-off-by: John Stultz

    Ondrej Mosnacek
     

23 Jul, 2017

1 commit

  • The messages printed by tk_debug_account_sleep_time() are basically
    useful for system sleep debugging, so print them only when the other
    debug messages from the core suspend/hibernate code are enabled.

    While at it, make it clear that the messages from
    tk_debug_account_sleep_time() are about timekeeping suspend
    duration, because in general timekeeping may be suspeded and
    resumed for multiple times during one system suspend-resume cycle.

    Signed-off-by: Rafael J. Wysocki

    Rafael J. Wysocki
     

15 Feb, 2017

1 commit

  • We cannot do printk() from tk_debug_account_sleep_time(), because
    tk_debug_account_sleep_time() is called under tk_core seq lock.
    The reason why printk() is unsafe there is that console_sem may
    invoke scheduler (up()->wake_up_process()->activate_task()), which,
    in turn, can return back to timekeeping code, for instance, via
    get_time()->ktime_get(), deadlocking the system on tk_core seq lock.

    [ 48.950592] ======================================================
    [ 48.950622] [ INFO: possible circular locking dependency detected ]
    [ 48.950622] 4.10.0-rc7-next-20170213+ #101 Not tainted
    [ 48.950622] -------------------------------------------------------
    [ 48.950622] kworker/0:0/3 is trying to acquire lock:
    [ 48.950653] (tk_core){----..}, at: [] retrigger_next_event+0x4c/0x90
    [ 48.950683]
    but task is already holding lock:
    [ 48.950683] (hrtimer_bases.lock){-.-...}, at: [] retrigger_next_event+0x38/0x90
    [ 48.950714]
    which lock already depends on the new lock.

    [ 48.950714]
    the existing dependency chain (in reverse order) is:
    [ 48.950714]
    -> #5 (hrtimer_bases.lock){-.-...}:
    [ 48.950744] _raw_spin_lock_irqsave+0x50/0x64
    [ 48.950775] lock_hrtimer_base+0x28/0x58
    [ 48.950775] hrtimer_start_range_ns+0x20/0x5c8
    [ 48.950775] __enqueue_rt_entity+0x320/0x360
    [ 48.950805] enqueue_rt_entity+0x2c/0x44
    [ 48.950805] enqueue_task_rt+0x24/0x94
    [ 48.950836] ttwu_do_activate+0x54/0xc0
    [ 48.950836] try_to_wake_up+0x248/0x5c8
    [ 48.950836] __setup_irq+0x420/0x5f0
    [ 48.950836] request_threaded_irq+0xdc/0x184
    [ 48.950866] devm_request_threaded_irq+0x58/0xa4
    [ 48.950866] omap_i2c_probe+0x530/0x6a0
    [ 48.950897] platform_drv_probe+0x50/0xb0
    [ 48.950897] driver_probe_device+0x1f8/0x2cc
    [ 48.950897] __driver_attach+0xc0/0xc4
    [ 48.950927] bus_for_each_dev+0x6c/0xa0
    [ 48.950927] bus_add_driver+0x100/0x210
    [ 48.950927] driver_register+0x78/0xf4
    [ 48.950958] do_one_initcall+0x3c/0x16c
    [ 48.950958] kernel_init_freeable+0x20c/0x2d8
    [ 48.950958] kernel_init+0x8/0x110
    [ 48.950988] ret_from_fork+0x14/0x24
    [ 48.950988]
    -> #4 (&rt_b->rt_runtime_lock){-.-...}:
    [ 48.951019] _raw_spin_lock+0x40/0x50
    [ 48.951019] rq_offline_rt+0x9c/0x2bc
    [ 48.951019] set_rq_offline.part.2+0x2c/0x58
    [ 48.951049] rq_attach_root+0x134/0x144
    [ 48.951049] cpu_attach_domain+0x18c/0x6f4
    [ 48.951049] build_sched_domains+0xba4/0xd80
    [ 48.951080] sched_init_smp+0x68/0x10c
    [ 48.951080] kernel_init_freeable+0x160/0x2d8
    [ 48.951080] kernel_init+0x8/0x110
    [ 48.951080] ret_from_fork+0x14/0x24
    [ 48.951110]
    -> #3 (&rq->lock){-.-.-.}:
    [ 48.951110] _raw_spin_lock+0x40/0x50
    [ 48.951141] task_fork_fair+0x30/0x124
    [ 48.951141] sched_fork+0x194/0x2e0
    [ 48.951141] copy_process.part.5+0x448/0x1a20
    [ 48.951171] _do_fork+0x98/0x7e8
    [ 48.951171] kernel_thread+0x2c/0x34
    [ 48.951171] rest_init+0x1c/0x18c
    [ 48.951202] start_kernel+0x35c/0x3d4
    [ 48.951202] 0x8000807c
    [ 48.951202]
    -> #2 (&p->pi_lock){-.-.-.}:
    [ 48.951232] _raw_spin_lock_irqsave+0x50/0x64
    [ 48.951232] try_to_wake_up+0x30/0x5c8
    [ 48.951232] up+0x4c/0x60
    [ 48.951263] __up_console_sem+0x2c/0x58
    [ 48.951263] console_unlock+0x3b4/0x650
    [ 48.951263] vprintk_emit+0x270/0x474
    [ 48.951293] vprintk_default+0x20/0x28
    [ 48.951293] printk+0x20/0x30
    [ 48.951324] kauditd_hold_skb+0x94/0xb8
    [ 48.951324] kauditd_thread+0x1a4/0x56c
    [ 48.951324] kthread+0x104/0x148
    [ 48.951354] ret_from_fork+0x14/0x24
    [ 48.951354]
    -> #1 ((console_sem).lock){-.....}:
    [ 48.951385] _raw_spin_lock_irqsave+0x50/0x64
    [ 48.951385] down_trylock+0xc/0x2c
    [ 48.951385] __down_trylock_console_sem+0x24/0x80
    [ 48.951385] console_trylock+0x10/0x8c
    [ 48.951416] vprintk_emit+0x264/0x474
    [ 48.951416] vprintk_default+0x20/0x28
    [ 48.951416] printk+0x20/0x30
    [ 48.951446] tk_debug_account_sleep_time+0x5c/0x70
    [ 48.951446] __timekeeping_inject_sleeptime.constprop.3+0x170/0x1a0
    [ 48.951446] timekeeping_resume+0x218/0x23c
    [ 48.951477] syscore_resume+0x94/0x42c
    [ 48.951477] suspend_enter+0x554/0x9b4
    [ 48.951477] suspend_devices_and_enter+0xd8/0x4b4
    [ 48.951507] enter_state+0x934/0xbd4
    [ 48.951507] pm_suspend+0x14/0x70
    [ 48.951507] state_store+0x68/0xc8
    [ 48.951538] kernfs_fop_write+0xf4/0x1f8
    [ 48.951538] __vfs_write+0x1c/0x114
    [ 48.951538] vfs_write+0xa0/0x168
    [ 48.951568] SyS_write+0x3c/0x90
    [ 48.951568] __sys_trace_return+0x0/0x10
    [ 48.951568]
    -> #0 (tk_core){----..}:
    [ 48.951599] lock_acquire+0xe0/0x294
    [ 48.951599] ktime_get_update_offsets_now+0x5c/0x1d4
    [ 48.951629] retrigger_next_event+0x4c/0x90
    [ 48.951629] on_each_cpu+0x40/0x7c
    [ 48.951629] clock_was_set_work+0x14/0x20
    [ 48.951660] process_one_work+0x2b4/0x808
    [ 48.951660] worker_thread+0x3c/0x550
    [ 48.951660] kthread+0x104/0x148
    [ 48.951690] ret_from_fork+0x14/0x24
    [ 48.951690]
    other info that might help us debug this:

    [ 48.951690] Chain exists of:
    tk_core --> &rt_b->rt_runtime_lock --> hrtimer_bases.lock

    [ 48.951721] Possible unsafe locking scenario:

    [ 48.951721] CPU0 CPU1
    [ 48.951721] ---- ----
    [ 48.951721] lock(hrtimer_bases.lock);
    [ 48.951751] lock(&rt_b->rt_runtime_lock);
    [ 48.951751] lock(hrtimer_bases.lock);
    [ 48.951751] lock(tk_core);
    [ 48.951782]
    *** DEADLOCK ***

    [ 48.951782] 3 locks held by kworker/0:0/3:
    [ 48.951782] #0: ("events"){.+.+.+}, at: [] process_one_work+0x1f8/0x808
    [ 48.951812] #1: (hrtimer_work){+.+...}, at: [] process_one_work+0x1f8/0x808
    [ 48.951843] #2: (hrtimer_bases.lock){-.-...}, at: [] retrigger_next_event+0x38/0x90
    [ 48.951843] stack backtrace:
    [ 48.951873] CPU: 0 PID: 3 Comm: kworker/0:0 Not tainted 4.10.0-rc7-next-20170213+
    [ 48.951904] Workqueue: events clock_was_set_work
    [ 48.951904] [] (unwind_backtrace) from [] (show_stack+0x10/0x14)
    [ 48.951934] [] (show_stack) from [] (dump_stack+0xac/0xe0)
    [ 48.951934] [] (dump_stack) from [] (print_circular_bug+0x1d0/0x308)
    [ 48.951965] [] (print_circular_bug) from [] (validate_chain+0xf50/0x1324)
    [ 48.951965] [] (validate_chain) from [] (__lock_acquire+0x468/0x7e8)
    [ 48.951995] [] (__lock_acquire) from [] (lock_acquire+0xe0/0x294)
    [ 48.951995] [] (lock_acquire) from [] (ktime_get_update_offsets_now+0x5c/0x1d4)
    [ 48.952026] [] (ktime_get_update_offsets_now) from [] (retrigger_next_event+0x4c/0x90)
    [ 48.952026] [] (retrigger_next_event) from [] (on_each_cpu+0x40/0x7c)
    [ 48.952056] [] (on_each_cpu) from [] (clock_was_set_work+0x14/0x20)
    [ 48.952056] [] (clock_was_set_work) from [] (process_one_work+0x2b4/0x808)
    [ 48.952087] [] (process_one_work) from [] (worker_thread+0x3c/0x550)
    [ 48.952087] [] (worker_thread) from [] (kthread+0x104/0x148)
    [ 48.952087] [] (kthread) from [] (ret_from_fork+0x14/0x24)

    Replace printk() with printk_deferred(), which does not call into
    the scheduler.

    Fixes: 0bf43f15db85 ("timekeeping: Prints the amounts of time spent during suspend")
    Reported-and-tested-by: Tony Lindgren
    Signed-off-by: Sergey Senozhatsky
    Cc: Petr Mladek
    Cc: Sergey Senozhatsky
    Cc: Peter Zijlstra
    Cc: "Rafael J . Wysocki"
    Cc: Steven Rostedt
    Cc: John Stultz
    Cc: "[4.9+]"
    Link: http://lkml.kernel.org/r/20170215044332.30449-1-sergey.senozhatsky@gmail.com
    Signed-off-by: Thomas Gleixner

    Sergey Senozhatsky
     

01 Sep, 2016

1 commit

  • In addition to keeping a histogram of suspend times, also
    print out the time spent in suspend to dmesg.

    This helps to keep track of suspend time while debugging using
    kernel logs.

    Cc: Thomas Gleixner
    Cc: Ingo Molnar
    Cc: Richard Cochran
    Cc: Prarit Bhargava
    Signed-off-by: Ruchi Kandoi
    [jstultz: Tweaked commit message]
    Signed-off-by: John Stultz

    Ruchi Kandoi
     

24 Aug, 2016

1 commit

  • It was reported that hibernation could fail on the 2nd attempt, where the
    system hangs at hibernate() -> syscore_resume() -> i8237A_resume() ->
    claim_dma_lock(), because the lock has already been taken.

    However there is actually no other process would like to grab this lock on
    that problematic platform.

    Further investigation showed that the problem is triggered by setting
    /sys/power/pm_trace to 1 before the 1st hibernation.

    Since once pm_trace is enabled, the rtc becomes unmeaningful after suspend,
    and meanwhile some BIOSes would like to adjust the 'invalid' RTC (e.g, smaller
    than 1970) to the release date of that motherboard during POST stage, thus
    after resumed, it may seem that the system had a significant long sleep time
    which is a completely meaningless value.

    Then in timekeeping_resume -> tk_debug_account_sleep_time, if the bit31 of the
    sleep time happened to be set to 1, fls() returns 32 and we add 1 to
    sleep_time_bin[32], which causes an out of bounds array access and therefor
    memory being overwritten.

    As depicted by System.map:
    0xffffffff81c9d080 b sleep_time_bin
    0xffffffff81c9d100 B dma_spin_lock
    the dma_spin_lock.val is set to 1, which caused this problem.

    This patch adds a sanity check in tk_debug_account_sleep_time()
    to ensure we don't index past the sleep_time_bin array.

    [jstultz: Problem diagnosed and original patch by Chen Yu, I've solved the
    issue slightly differently, but borrowed his excelent explanation of the
    issue here.]

    Fixes: 5c83545f24ab "power: Add option to log time spent in suspend"
    Reported-by: Janek Kozicki
    Reported-by: Chen Yu
    Signed-off-by: John Stultz
    Cc: linux-pm@vger.kernel.org
    Cc: Peter Zijlstra
    Cc: Xunlei Pang
    Cc: "Rafael J. Wysocki"
    Cc: stable
    Cc: Zhang Rui
    Link: http://lkml.kernel.org/r/1471993702-29148-3-git-send-email-john.stultz@linaro.org
    Signed-off-by: Thomas Gleixner

    John Stultz
     

24 Jul, 2014

1 commit

  • Convert the core timekeeping logic to use timespec64s. This moves the
    2038 issues out of the core logic and into all of the accessor
    functions.

    Future changes will need to push the timespec64s out to all
    timekeeping users, but that can be done interface by interface.

    Signed-off-by: John Stultz
    Signed-off-by: Thomas Gleixner
    Signed-off-by: John Stultz

    John Stultz
     

03 Mar, 2014

1 commit

  • Include appropriate header file kernel/time/timekeeping_internal.h in
    kernel/time/timekeeping_debug.c because it has prototype declaration of
    function defined in kernel/time/timekeeping_debug.c.

    This eliminates the following warning in
    kernel/time/timekeeping_debug.c:
    kernel/time/timekeeping_debug.c:68:6: warning: no previous prototype for ‘tk_debug_account_sleep_time’ [-Wmissing-prototypes]

    Signed-off-by: Rashika Kheria
    Reviewed-by: Josh Triplett
    Signed-off-by: John Stultz

    Rashika Kheria
     

30 May, 2013

1 commit

  • Below is a patch from android kernel that maintains a histogram of
    suspend times. Please review and provide feedback.

    Statistices on the time spent in suspend are kept in
    /sys/kernel/debug/sleep_time.

    Cc: Android Kernel Team
    Cc: Colin Cross
    Cc: Todd Poynor
    Cc: San Mehat
    Cc: Benoit Goby
    Cc: John Stultz
    Cc: Thomas Gleixner
    Signed-off-by: Colin Cross
    Signed-off-by: Todd Poynor
    [zoran.markovic@linaro.org: Re-formatted suspend time table to better
    fit expected values. Moved accounting of suspend time into timekeeping
    core. Removed CONFIG_SUSPEND_TIME flag and made the feature conditional
    on CONFIG_DEBUG_FS. Changed the file name to sleep_time to better fit
    terminology in timekeeping core. Changed seq_printf to seq_puts. Tweaked
    commit message]
    Signed-off-by: Zoran Markovic
    Signed-off-by: John Stultz

    Colin Cross