summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWei Wang <wvw@google.com>2016-06-07 18:44:31 -0700
committerZhao Wei Liew <zhaoweiliew@gmail.com>2016-10-02 20:14:27 -0700
commit9fb2889443c3904defe932e00bda2ba9ca513902 (patch)
tree0a8f4bd03ed1ac7c283bdf79cf2ade26bbc9deec
parent91552490da0c6c66189cde1cfb761b7c678b60a1 (diff)
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 (cherry picked from commit 2bf13f822cf39123ee0e97e40caf1288ba4f457a)
-rw-r--r--power/power-8916.c12
-rw-r--r--power/power-8937.c14
-rw-r--r--power/power-8952.c14
-rw-r--r--power/power-8974.c12
-rw-r--r--power/power-8992.c12
-rw-r--r--power/power-8994.c12
-rw-r--r--power/power-8996.c14
-rw-r--r--power/utils.c12
-rw-r--r--power/utils.h2
9 files changed, 56 insertions, 48 deletions
diff --git a/power/power-8916.c b/power/power-8916.c
index 3ce1b84..dbae941 100644
--- a/power/power-8916.c
+++ b/power/power-8916.c
@@ -360,7 +360,9 @@ int power_hint_override(struct power_module *module __unused, power_hint_t hint,
if (hint == POWER_HINT_INTERACTION) {
int duration = 500, duration_hint = 0;
- static unsigned long long previous_boost_time = 0;
+ static struct timespec s_previous_boost_timespec;
+ struct timespec cur_boost_timespec;
+ long long elapsed_time;
if (data) {
duration_hint = *((int *)data);
@@ -368,10 +370,8 @@ int power_hint_override(struct power_module *module __unused, power_hint_t hint,
duration = duration_hint > 0 ? duration_hint : 500;
- struct timeval cur_boost_timeval = {0, 0};
- gettimeofday(&cur_boost_timeval, NULL);
- unsigned long long cur_boost_time = cur_boost_timeval.tv_sec * 1000000 + cur_boost_timeval.tv_usec;
- double 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);
if (elapsed_time > 750000)
elapsed_time = 750000;
// don't hint if it's been less than 250ms since last boost
@@ -380,7 +380,7 @@ int power_hint_override(struct power_module *module __unused, power_hint_t hint,
else if (elapsed_time < 250000 && duration <= 750)
return HINT_HANDLED;
- previous_boost_time = cur_boost_time;
+ s_previous_boost_timespec = cur_boost_timespec;
if (duration >= 1500) {
int resources[] = {
diff --git a/power/power-8937.c b/power/power-8937.c
index 02440a6..f2b4e7c 100644
--- a/power/power-8937.c
+++ b/power/power-8937.c
@@ -125,10 +125,9 @@ int power_hint_override(struct power_module *module, power_hint_t hint,
void *data)
{
int duration, duration_hint;
- static unsigned long long previous_boost_time = 0;
- unsigned long long cur_boost_time;
- struct timeval cur_boost_timeval = {0, 0};
- double elapsed_time;
+ static struct timespec s_previous_boost_timespec;
+ struct timespec cur_boost_timespec;
+ long long elapsed_time;
int resources_launch_boost[] = {
SCHED_BOOST_ON_V3, 0x1,
MAX_FREQ_BIG_CORE_0, 0xFFF,
@@ -175,9 +174,8 @@ int power_hint_override(struct power_module *module, power_hint_t hint,
duration = duration_hint > 0 ? duration_hint : 500;
- 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);
if (elapsed_time > 750000)
elapsed_time = 750000;
// don't hint if it's been less than 250ms since last boost
@@ -186,7 +184,7 @@ int power_hint_override(struct power_module *module, power_hint_t hint,
else if (elapsed_time < 250000 && duration <= 750)
return HINT_HANDLED;
- previous_boost_time = cur_boost_time;
+ s_previous_boost_timespec = cur_boost_timespec;
if (duration >= 1500) {
interaction(duration, ARRAY_SIZE(resources_interaction_fling_boost),
diff --git a/power/power-8952.c b/power/power-8952.c
index 05955d1..119a3de 100644
--- a/power/power-8952.c
+++ b/power/power-8952.c
@@ -107,10 +107,9 @@ int power_hint_override(struct power_module *module, power_hint_t hint,
void *data)
{
int duration, duration_hint;
- static unsigned long long previous_boost_time = 0;
- unsigned long long cur_boost_time;
- struct timeval cur_boost_timeval = {0, 0};
- double elapsed_time;
+ static struct timespec s_previous_boost_timespec;
+ struct timespec cur_boost_timespec;
+ long long elapsed_time;
int resources_launch_boost[] = {
ALL_CPUS_PWR_CLPS_DIS,
SCHED_BOOST_ON,
@@ -153,9 +152,8 @@ int power_hint_override(struct power_module *module, power_hint_t hint,
duration = duration_hint > 0 ? duration_hint : 500;
- 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);
if (elapsed_time > 750000)
elapsed_time = 750000;
// don't hint if it's been less than 250ms since last boost
@@ -164,7 +162,7 @@ int power_hint_override(struct power_module *module, power_hint_t hint,
else if (elapsed_time < 250000 && duration <= 750)
return HINT_HANDLED;
- previous_boost_time = cur_boost_time;
+ s_previous_boost_timespec = cur_boost_timespec;
if (duration >= 1500) {
interaction(duration, ARRAY_SIZE(resources_cpu_boost),
diff --git a/power/power-8974.c b/power/power-8974.c
index 0b6a4b3..02c9258 100644
--- a/power/power-8974.c
+++ b/power/power-8974.c
@@ -142,7 +142,9 @@ int power_hint_override(__attribute__((unused)) struct power_module *module,
if (hint == POWER_HINT_INTERACTION) {
int duration = 500, duration_hint = 0;
- static unsigned long long previous_boost_time = 0;
+ static struct timespec s_previous_boost_timespec;
+ struct timespec cur_boost_timespec;
+ long long elapsed_time;
if (data) {
duration_hint = *((int *)data);
@@ -150,10 +152,8 @@ int power_hint_override(__attribute__((unused)) struct power_module *module,
duration = duration_hint > 0 ? duration_hint : 500;
- struct timeval cur_boost_timeval = {0, 0};
- gettimeofday(&cur_boost_timeval, NULL);
- unsigned long long cur_boost_time = cur_boost_timeval.tv_sec * 1000000 + cur_boost_timeval.tv_usec;
- double 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);
if (elapsed_time > 750000)
elapsed_time = 750000;
// don't hint if it's been less than 250ms since last boost
@@ -162,7 +162,7 @@ int power_hint_override(__attribute__((unused)) struct power_module *module,
else if (elapsed_time < 250000 && duration <= 750)
return HINT_HANDLED;
- previous_boost_time = cur_boost_time;
+ s_previous_boost_timespec = cur_boost_timespec;
int resources[] = { (duration >= 2000 ? CPUS_ONLINE_MIN_3 : CPUS_ONLINE_MIN_2),
0x20F, 0x30F, 0x40F, 0x50F };
diff --git a/power/power-8992.c b/power/power-8992.c
index eee3443..879dae5 100644
--- a/power/power-8992.c
+++ b/power/power-8992.c
@@ -169,7 +169,9 @@ int power_hint_override(__attribute__((unused)) struct power_module *module,
if (hint == POWER_HINT_INTERACTION) {
int duration = 500, duration_hint = 0;
- static unsigned long long previous_boost_time = 0;
+ static struct timespec s_previous_boost_timespec;
+ struct timespec cur_boost_timespec;
+ long long elapsed_time;
if (data) {
duration_hint = *((int *)data);
@@ -177,10 +179,8 @@ int power_hint_override(__attribute__((unused)) struct power_module *module,
duration = duration_hint > 0 ? duration_hint : 500;
- struct timeval cur_boost_timeval = {0, 0};
- gettimeofday(&cur_boost_timeval, NULL);
- unsigned long long cur_boost_time = cur_boost_timeval.tv_sec * 1000000 + cur_boost_timeval.tv_usec;
- double 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);
if (elapsed_time > 750000)
elapsed_time = 750000;
// don't hint if it's been less than 250ms since last boost
@@ -189,7 +189,7 @@ int power_hint_override(__attribute__((unused)) struct power_module *module,
else if (elapsed_time < 250000 && duration <= 750)
return HINT_HANDLED;
- previous_boost_time = cur_boost_time;
+ s_previous_boost_timespec = cur_boost_timespec;
if (duration >= 1500) {
int resources[] = {
diff --git a/power/power-8994.c b/power/power-8994.c
index 3d93288..4a62826 100644
--- a/power/power-8994.c
+++ b/power/power-8994.c
@@ -179,7 +179,9 @@ int power_hint_override(__attribute__((unused)) struct power_module *module,
if (hint == POWER_HINT_INTERACTION) {
int duration = 500, duration_hint = 0;
- static unsigned long long previous_boost_time = 0;
+ static struct timespec s_previous_boost_timespec;
+ struct timespec cur_boost_timespec;
+ long long elapsed_time;
if (data) {
duration_hint = *((int *)data);
@@ -187,10 +189,8 @@ int power_hint_override(__attribute__((unused)) struct power_module *module,
duration = duration_hint > 0 ? duration_hint : 500;
- struct timeval cur_boost_timeval = {0, 0};
- gettimeofday(&cur_boost_timeval, NULL);
- unsigned long long cur_boost_time = cur_boost_timeval.tv_sec * 1000000 + cur_boost_timeval.tv_usec;
- double 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);
if (elapsed_time > 750000)
elapsed_time = 750000;
// don't hint if it's been less than 250ms since last boost
@@ -199,7 +199,7 @@ int power_hint_override(__attribute__((unused)) struct power_module *module,
else if (elapsed_time < 250000 && duration <= 750)
return HINT_HANDLED;
- previous_boost_time = cur_boost_time;
+ s_previous_boost_timespec = cur_boost_timespec;
if (duration >= 1500) {
int resources[] = {
diff --git a/power/power-8996.c b/power/power-8996.c
index 0e1bdf9..decced0 100644
--- a/power/power-8996.c
+++ b/power/power-8996.c
@@ -271,10 +271,9 @@ static int process_video_encode_hint(void *metadata)
int power_hint_override(__unused struct power_module *module,
power_hint_t hint, void *data)
{
- struct timeval cur_boost_timeval = {0, 0};
- static unsigned long long previous_boost_time = 0;
- unsigned long long cur_boost_time;
- double elapsed_time;
+ static struct timespec s_previous_boost_timespec;
+ struct timespec cur_boost_timespec;
+ long long elapsed_time;
int duration;
int resources_launch_boost[] = {
@@ -317,9 +316,8 @@ int power_hint_override(__unused struct power_module *module,
if (hint == POWER_HINT_INTERACTION) {
duration = data ? *((int *)data) : 500;
- 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);
if (elapsed_time > 750000)
elapsed_time = 750000;
/**
@@ -330,7 +328,7 @@ int power_hint_override(__unused struct power_module *module,
else if (elapsed_time < 250000 && duration <= 750)
return HINT_HANDLED;
- previous_boost_time = cur_boost_time;
+ s_previous_boost_timespec = cur_boost_timespec;
if (duration >= 1500) {
interaction(duration, ARRAY_SIZE(resources_interaction_fling_boost),
diff --git a/power/utils.c b/power/utils.c
index 202b718..ac73edd 100644
--- a/power/utils.c
+++ b/power/utils.c
@@ -33,6 +33,7 @@
#include <errno.h>
#include <string.h>
#include <stdlib.h>
+#include <sys/stat.h>
#include "utils.h"
#include "list.h"
@@ -42,6 +43,9 @@
#define LOG_TAG "QCOM PowerHAL"
#include <utils/Log.h>
+#define USINSEC 1000000L
+#define NSINUS 1000L
+
#define SOC_ID_0 "/sys/devices/soc0/soc_id"
#define SOC_ID_1 "/sys/devices/system/soc/soc0/id"
@@ -391,6 +395,14 @@ void start_prefetch(int pid, const char* packageName) {
}
}
+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;
+}
+
int get_soc_id(void)
{
int fd;
diff --git a/power/utils.h b/power/utils.h
index fb8d84c..3c4da92 100644
--- a/power/utils.h
+++ b/power/utils.h
@@ -44,4 +44,6 @@ void undo_hint_action(int hint_id);
void undo_initial_hint_action();
void set_profile(int profile);
void start_prefetch(int pid, const char *packageName);
+
+long long calc_timespan_us(struct timespec start, struct timespec end);
int get_soc_id(void);