From f945859627ff54f5a6136fcf9fa48064c54b785c Mon Sep 17 00:00:00 2001 From: Wei Wang Date: Tue, 7 Jun 2016 18:44:31 -0700 Subject: [PATCH] sdm710-common: power: Use monotonic time for interaction boost Using the wall clock will cause boosts to be disabled when/if the clock is adjusted backward. Bug: 29191415 Bug: 29208304 Change-Id: I8af5f40b46d996ce7bccb8324fc186e2f3a5b267 Signed-off-by: SamarV-121 --- power/power-710.c | 22 +++++++++++----------- power/utils.c | 10 ++++++++++ power/utils.h | 2 ++ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/power/power-710.c b/power/power-710.c index 2df2ed7..b576bab 100644 --- a/power/power-710.c +++ b/power/power-710.c @@ -201,11 +201,11 @@ static int process_activity_launch_hint(void* data) { } static int process_interaction_hint(void* data) { - struct timeval cur_boost_timeval = {0, 0}; - static unsigned long long previous_boost_time = 0; - static unsigned long long previous_duration = 0; - unsigned long long cur_boost_time; - double elapsed_time; + static struct timespec s_previous_boost_timespec; + static int s_previous_duration = 0; + + struct timespec cur_boost_timespec; + long long elapsed_time; int duration = kMinInteractiveDuration; if (current_mode != NORMAL_MODE) { @@ -221,15 +221,15 @@ static int process_interaction_hint(void* data) { } } - gettimeofday(&cur_boost_timeval, NULL); - cur_boost_time = cur_boost_timeval.tv_sec * 1000000 + cur_boost_timeval.tv_usec; - elapsed_time = (double) (cur_boost_time - previous_boost_time); + clock_gettime(CLOCK_MONOTONIC, &cur_boost_timespec); + + elapsed_time = calc_timespan_us(s_previous_boost_timespec, cur_boost_timespec); // don't hint if previous hint's duration covers this hint's duration - if ((previous_duration * 1000) > (elapsed_time + duration * 1000)) { + if ((s_previous_duration * 1000) > (elapsed_time + duration * 1000)) { return HINT_HANDLED; } - previous_boost_time = cur_boost_time; - previous_duration = duration; + s_previous_boost_timespec = cur_boost_timespec; + s_previous_duration = duration; if (duration >= kMinFlingDuration) { perf_hint_enable_with_type(VENDOR_HINT_SCROLL_BOOST, -1, SCROLL_PREFILING); diff --git a/power/utils.c b/power/utils.c index 21aac0f..030f56e 100644 --- a/power/utils.c +++ b/power/utils.c @@ -42,6 +42,9 @@ #define LOG_TAG "QCOM PowerHAL" #include +#define USINSEC 1000000L +#define NSINUS 1000L + char scaling_gov_path[4][80] = {"sys/devices/system/cpu/cpu0/cpufreq/scaling_governor", "sys/devices/system/cpu/cpu1/cpufreq/scaling_governor", "sys/devices/system/cpu/cpu2/cpufreq/scaling_governor", @@ -331,3 +334,10 @@ void undo_initial_hint_action() { } } } + +long long calc_timespan_us(struct timespec start, struct timespec end) { + long long diff_in_us = 0; + diff_in_us += (end.tv_sec - start.tv_sec) * USINSEC; + diff_in_us += (end.tv_nsec - start.tv_nsec) / NSINUS; + return diff_in_us; +} diff --git a/power/utils.h b/power/utils.h index 12d3001..770f843 100644 --- a/power/utils.h +++ b/power/utils.h @@ -45,3 +45,5 @@ void release_request(int lock_handle); int interaction_with_handle(int lock_handle, int duration, int num_args, int opt_list[]); int perf_hint_enable(int hint_id, int duration); int perf_hint_enable_with_type(int hint_id, int duration, int type); + +long long calc_timespan_us(struct timespec start, struct timespec end);