summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Murray2016-10-18 12:05:59 -0500
committerTim Murray2016-10-18 12:05:59 -0500
commit23c8bab0243bc6e7be8b95702c262c354009d56a (patch)
treeb164a784cdd435f7903a605e627d6a4061671c91 /libsuspend
parentfb896944b6a78d951c8442b444af860a28117e5c (diff)
downloadplatform-system-core-23c8bab0243bc6e7be8b95702c262c354009d56a.tar.gz
platform-system-core-23c8bab0243bc6e7be8b95702c262c354009d56a.tar.xz
platform-system-core-23c8bab0243bc6e7be8b95702c262c354009d56a.zip
Revert "libsuspend: move to exponential backoff"
This reverts commit fb896944b6a78d951c8442b444af860a28117e5c. bug 32180327 Change-Id: Ic26bdffac6c56b102348f5393e6eb5d895960d7e
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 de345492b..23a029027 100644
--- a/libsuspend/autosuspend_wakeup_count.c
+++ b/libsuspend/autosuspend_wakeup_count.c
@@ -21,7 +21,6 @@
21#include <stddef.h> 21#include <stddef.h>
22#include <stdbool.h> 22#include <stdbool.h>
23#include <string.h> 23#include <string.h>
24#include <sys/param.h>
25#include <sys/stat.h> 24#include <sys/stat.h>
26#include <sys/types.h> 25#include <sys/types.h>
27#include <unistd.h> 26#include <unistd.h>
@@ -35,24 +34,12 @@
35#define SYS_POWER_STATE "/sys/power/state" 34#define SYS_POWER_STATE "/sys/power/state"
36#define SYS_POWER_WAKEUP_COUNT "/sys/power/wakeup_count" 35#define SYS_POWER_WAKEUP_COUNT "/sys/power/wakeup_count"
37 36
38#define BASE_SLEEP_TIME 100000
39
40static int state_fd; 37static int state_fd;
41static int wakeup_count_fd; 38static int wakeup_count_fd;
42static pthread_t suspend_thread; 39static pthread_t suspend_thread;
43static sem_t suspend_lockout; 40static sem_t suspend_lockout;
44static const char *sleep_state = "mem"; 41static const char *sleep_state = "mem";
45static void (*wakeup_func)(bool success) = NULL; 42static void (*wakeup_func)(bool success) = NULL;
46static int sleep_time = BASE_SLEEP_TIME;
47
48static void update_sleep_time(bool success) {
49 if (success) {
50 sleep_time = BASE_SLEEP_TIME;
51 return;
52 }
53 // double sleep time after each failure up to one minute
54 sleep_time = MIN(sleep_time * 2, 60000000);
55}
56 43
57static void *suspend_thread_func(void *arg __attribute__((unused))) 44static void *suspend_thread_func(void *arg __attribute__((unused)))
58{ 45{
@@ -60,12 +47,10 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
60 char wakeup_count[20]; 47 char wakeup_count[20];
61 int wakeup_count_len; 48 int wakeup_count_len;
62 int ret; 49 int ret;
63 bool success = true; 50 bool success;
64 51
65 while (1) { 52 while (1) {
66 update_sleep_time(success); 53 usleep(100000);
67 usleep(sleep_time);
68 success = false;
69 ALOGV("%s: read wakeup_count\n", __func__); 54 ALOGV("%s: read wakeup_count\n", __func__);
70 lseek(wakeup_count_fd, 0, SEEK_SET); 55 lseek(wakeup_count_fd, 0, SEEK_SET);
71 wakeup_count_len = TEMP_FAILURE_RETRY(read(wakeup_count_fd, wakeup_count, 56 wakeup_count_len = TEMP_FAILURE_RETRY(read(wakeup_count_fd, wakeup_count,
@@ -89,6 +74,7 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
89 continue; 74 continue;
90 } 75 }
91 76
77 success = true;
92 ALOGV("%s: write %*s to wakeup_count\n", __func__, wakeup_count_len, wakeup_count); 78 ALOGV("%s: write %*s to wakeup_count\n", __func__, wakeup_count_len, wakeup_count);
93 ret = TEMP_FAILURE_RETRY(write(wakeup_count_fd, wakeup_count, wakeup_count_len)); 79 ret = TEMP_FAILURE_RETRY(write(wakeup_count_fd, wakeup_count, wakeup_count_len));
94 if (ret < 0) { 80 if (ret < 0) {
@@ -97,8 +83,8 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
97 } else { 83 } else {
98 ALOGV("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE); 84 ALOGV("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE);
99 ret = TEMP_FAILURE_RETRY(write(state_fd, sleep_state, strlen(sleep_state))); 85 ret = TEMP_FAILURE_RETRY(write(state_fd, sleep_state, strlen(sleep_state)));
100 if (ret >= 0) { 86 if (ret < 0) {
101 success = true; 87 success = false;
102 } 88 }
103 void (*func)(bool success) = wakeup_func; 89 void (*func)(bool success) = wakeup_func;
104 if (func != NULL) { 90 if (func != NULL) {