sdm845-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
This commit is contained in:
Wei Wang 2016-06-07 18:44:31 -07:00 committed by Bruno Martins
parent cbf9d771a4
commit 7690a1c964
3 changed files with 23 additions and 11 deletions

View File

@ -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);

View File

@ -42,6 +42,9 @@
#define LOG_TAG "QCOM PowerHAL"
#include <utils/Log.h>
#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;
}

View File

@ -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);