summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Murray2016-10-18 13:52:09 -0500
committerandroid-build-merger2016-10-18 13:52:09 -0500
commit274359228caf8ed7b7bd5b71a0faf2bccb9d8ba5 (patch)
tree89764b7f3b699930c187b38c4d48654ae736060e /libsuspend
parent61d28ddedff2e8d2ebd0d73a9298a85e425346e4 (diff)
parent4dcd461945cf640da38df41bdc85dac79500bbff (diff)
downloadplatform-system-core-274359228caf8ed7b7bd5b71a0faf2bccb9d8ba5.tar.gz
platform-system-core-274359228caf8ed7b7bd5b71a0faf2bccb9d8ba5.tar.xz
platform-system-core-274359228caf8ed7b7bd5b71a0faf2bccb9d8ba5.zip
Revert "libsuspend: move to exponential backoff" am: 23c8bab024
am: 4dcd461945 Change-Id: Ie1087acf944c43ab2c4f02a63817563d6125393f
Diffstat (limited to 'libsuspend')
-rw-r--r--libsuspend/autosuspend_wakeup_count.c24
1 files changed, 5 insertions, 19 deletions
diff --git a/libsuspend/autosuspend_wakeup_count.c b/libsuspend/autosuspend_wakeup_count.c
index 3457d5baf..d3fb45fcf 100644
--- a/libsuspend/autosuspend_wakeup_count.c
+++ b/libsuspend/autosuspend_wakeup_count.c
@@ -24,7 +24,6 @@
24#include <stddef.h> 24#include <stddef.h>
25#include <stdbool.h> 25#include <stdbool.h>
26#include <string.h> 26#include <string.h>
27#include <sys/param.h>
28#include <sys/stat.h> 27#include <sys/stat.h>
29#include <sys/types.h> 28#include <sys/types.h>
30#include <unistd.h> 29#include <unistd.h>
@@ -36,24 +35,12 @@
36#define SYS_POWER_STATE "/sys/power/state" 35#define SYS_POWER_STATE "/sys/power/state"
37#define SYS_POWER_WAKEUP_COUNT "/sys/power/wakeup_count" 36#define SYS_POWER_WAKEUP_COUNT "/sys/power/wakeup_count"
38 37
39#define BASE_SLEEP_TIME 100000
40
41static int state_fd; 38static int state_fd;
42static int wakeup_count_fd; 39static int wakeup_count_fd;
43static pthread_t suspend_thread; 40static pthread_t suspend_thread;
44static sem_t suspend_lockout; 41static sem_t suspend_lockout;
45static const char *sleep_state = "mem"; 42static const char *sleep_state = "mem";
46static void (*wakeup_func)(bool success) = NULL; 43static void (*wakeup_func)(bool success) = NULL;
47static int sleep_time = BASE_SLEEP_TIME;
48
49static void update_sleep_time(bool success) {
50 if (success) {
51 sleep_time = BASE_SLEEP_TIME;
52 return;
53 }
54 // double sleep time after each failure up to one minute
55 sleep_time = MIN(sleep_time * 2, 60000000);
56}
57 44
58static void *suspend_thread_func(void *arg __attribute__((unused))) 45static void *suspend_thread_func(void *arg __attribute__((unused)))
59{ 46{
@@ -61,12 +48,10 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
61 char wakeup_count[20]; 48 char wakeup_count[20];
62 int wakeup_count_len; 49 int wakeup_count_len;
63 int ret; 50 int ret;
64 bool success = true; 51 bool success;
65 52
66 while (1) { 53 while (1) {
67 update_sleep_time(success); 54 usleep(100000);
68 usleep(sleep_time);
69 success = false;
70 ALOGV("%s: read wakeup_count\n", __func__); 55 ALOGV("%s: read wakeup_count\n", __func__);
71 lseek(wakeup_count_fd, 0, SEEK_SET); 56 lseek(wakeup_count_fd, 0, SEEK_SET);
72 wakeup_count_len = TEMP_FAILURE_RETRY(read(wakeup_count_fd, wakeup_count, 57 wakeup_count_len = TEMP_FAILURE_RETRY(read(wakeup_count_fd, wakeup_count,
@@ -90,6 +75,7 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
90 continue; 75 continue;
91 } 76 }
92 77
78 success = true;
93 ALOGV("%s: write %*s to wakeup_count\n", __func__, wakeup_count_len, wakeup_count); 79 ALOGV("%s: write %*s to wakeup_count\n", __func__, wakeup_count_len, wakeup_count);
94 ret = TEMP_FAILURE_RETRY(write(wakeup_count_fd, wakeup_count, wakeup_count_len)); 80 ret = TEMP_FAILURE_RETRY(write(wakeup_count_fd, wakeup_count, wakeup_count_len));
95 if (ret < 0) { 81 if (ret < 0) {
@@ -98,8 +84,8 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
98 } else { 84 } else {
99 ALOGV("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE); 85 ALOGV("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE);
100 ret = TEMP_FAILURE_RETRY(write(state_fd, sleep_state, strlen(sleep_state))); 86 ret = TEMP_FAILURE_RETRY(write(state_fd, sleep_state, strlen(sleep_state)));
101 if (ret >= 0) { 87 if (ret < 0) {
102 success = true; 88 success = false;
103 } 89 }
104 void (*func)(bool success) = wakeup_func; 90 void (*func)(bool success) = wakeup_func;
105 if (func != NULL) { 91 if (func != NULL) {