Commit 72e624de authored by Abhilash Jindal's avatar Abhilash Jindal Committed by Rafael J. Wysocki

cpufreq: speedstep-lib: Use monotonic clock

Wall time obtained from do_gettimeofday is susceptible to sudden jumps due to
user setting the time or due to NTP.

Monotonic time is constantly increasing time better suited for comparing two
timestamps.
Signed-off-by: default avatarAbhilash Jindal <klock.android@gmail.com>
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 309d0631
...@@ -386,7 +386,7 @@ unsigned int speedstep_get_freqs(enum speedstep_processor processor, ...@@ -386,7 +386,7 @@ unsigned int speedstep_get_freqs(enum speedstep_processor processor,
unsigned int prev_speed; unsigned int prev_speed;
unsigned int ret = 0; unsigned int ret = 0;
unsigned long flags; unsigned long flags;
struct timeval tv1, tv2; ktime_t tv1, tv2;
if ((!processor) || (!low_speed) || (!high_speed) || (!set_state)) if ((!processor) || (!low_speed) || (!high_speed) || (!set_state))
return -EINVAL; return -EINVAL;
...@@ -415,14 +415,14 @@ unsigned int speedstep_get_freqs(enum speedstep_processor processor, ...@@ -415,14 +415,14 @@ unsigned int speedstep_get_freqs(enum speedstep_processor processor,
/* start latency measurement */ /* start latency measurement */
if (transition_latency) if (transition_latency)
do_gettimeofday(&tv1); tv1 = ktime_get();
/* switch to high state */ /* switch to high state */
set_state(SPEEDSTEP_HIGH); set_state(SPEEDSTEP_HIGH);
/* end latency measurement */ /* end latency measurement */
if (transition_latency) if (transition_latency)
do_gettimeofday(&tv2); tv2 = ktime_get();
*high_speed = speedstep_get_frequency(processor); *high_speed = speedstep_get_frequency(processor);
if (!*high_speed) { if (!*high_speed) {
...@@ -442,8 +442,7 @@ unsigned int speedstep_get_freqs(enum speedstep_processor processor, ...@@ -442,8 +442,7 @@ unsigned int speedstep_get_freqs(enum speedstep_processor processor,
set_state(SPEEDSTEP_LOW); set_state(SPEEDSTEP_LOW);
if (transition_latency) { if (transition_latency) {
*transition_latency = (tv2.tv_sec - tv1.tv_sec) * USEC_PER_SEC + *transition_latency = ktime_to_us(ktime_sub(tv2, tv1));
tv2.tv_usec - tv1.tv_usec;
pr_debug("transition latency is %u uSec\n", *transition_latency); pr_debug("transition latency is %u uSec\n", *transition_latency);
/* convert uSec to nSec and add 20% for safety reasons */ /* convert uSec to nSec and add 20% for safety reasons */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment