PM/freezer: y2038, use boottime to compare tstamps
Wall time obtained from do_gettimeofday gives 32 bit timeval which can only represent time until January 2038. This patch moves to ktime_t, a 64-bit time. Also, wall time is susceptible to sudden jumps due to user setting the time or due to NTP. Boot time is constantly increasing time better suited for subtracting two timestamps. Signed-off-by: Abhilash Jindal <klock.android@gmail.com> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
parent
f97238373b
commit
f7b382b988
|
@ -30,13 +30,12 @@ static int try_to_freeze_tasks(bool user_only)
|
||||||
unsigned long end_time;
|
unsigned long end_time;
|
||||||
unsigned int todo;
|
unsigned int todo;
|
||||||
bool wq_busy = false;
|
bool wq_busy = false;
|
||||||
struct timeval start, end;
|
ktime_t start, end, elapsed;
|
||||||
u64 elapsed_msecs64;
|
|
||||||
unsigned int elapsed_msecs;
|
unsigned int elapsed_msecs;
|
||||||
bool wakeup = false;
|
bool wakeup = false;
|
||||||
int sleep_usecs = USEC_PER_MSEC;
|
int sleep_usecs = USEC_PER_MSEC;
|
||||||
|
|
||||||
do_gettimeofday(&start);
|
start = ktime_get_boottime();
|
||||||
|
|
||||||
end_time = jiffies + msecs_to_jiffies(freeze_timeout_msecs);
|
end_time = jiffies + msecs_to_jiffies(freeze_timeout_msecs);
|
||||||
|
|
||||||
|
@ -78,10 +77,9 @@ static int try_to_freeze_tasks(bool user_only)
|
||||||
sleep_usecs *= 2;
|
sleep_usecs *= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
do_gettimeofday(&end);
|
end = ktime_get_boottime();
|
||||||
elapsed_msecs64 = timeval_to_ns(&end) - timeval_to_ns(&start);
|
elapsed = ktime_sub(end, start);
|
||||||
do_div(elapsed_msecs64, NSEC_PER_MSEC);
|
elapsed_msecs = ktime_to_ms(elapsed);
|
||||||
elapsed_msecs = elapsed_msecs64;
|
|
||||||
|
|
||||||
if (todo) {
|
if (todo) {
|
||||||
pr_cont("\n");
|
pr_cont("\n");
|
||||||
|
|
Loading…
Reference in New Issue