PM-runtime: Switch accounting over to ktime_get_mono_fast_ns()
authorVincent Guittot <vincent.guittot@linaro.org>
Mon, 4 Feb 2019 16:25:52 +0000 (17:25 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 5 Feb 2019 11:04:39 +0000 (12:04 +0100)
commitc155f6499f9797f200aa46eb3ccbf198f4206970
tree197cff260e5ade3feaa27b681b5356f9ba68686f
parentf800ea320c09fbc8bf15aecd5c05e8e6b27ae64e
PM-runtime: Switch accounting over to ktime_get_mono_fast_ns()

Similar to what happened whith autosuspend, a deadlock has been
reported with PM-runtime accounting in the call path:

change_clocksource
    ...
    write_seqcount_begin
    ...
    timekeeping_update
        ...
        sh_cmt_clocksource_enable
            ...
            rpm_resume
                update_pm_runtime_accounting
                    ktime_get
                        do
                            read_seqcount_begin
                        while read_seqcount_retry
    ....
    write_seqcount_end

Make PM-runtime accounting use ktime_get_mono_fast_ns() to avoid this
problem.

With ktime_get_mono_fast_ns(), the timestamp is not guaranteed to be
monotonic across an update of timekeeping and as a result time can go
backward. Add a test to skip accounting for such situation which should
stay exceptional.

Fixes: a08c2a5a3194 ("PM-runtime: Replace jiffies-based accounting with ktime-based accounting")
Reported-by: Biju Das <biju.das@bp.renesas.com>
Signed-off-by: Vincent Guittot <vincent.guittot@linaro.org>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
[ rjw: Subject, changelog, comment cleanup ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/power/runtime.c