summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAjay Dudani2017-04-17 18:54:15 -0500
committerAjay Dudani2017-04-18 17:38:18 -0500
commit0c5f7d838911fd95013dad6320cb7fbc4166255c (patch)
treef3b7b4c9a5175d463a2936f414c81bdc218fc45a /libsuspend
parent907b14e51eccaf2be5c3c7a48d8de03a7e94a998 (diff)
downloadplatform-system-core-0c5f7d838911fd95013dad6320cb7fbc4166255c.tar.gz
platform-system-core-0c5f7d838911fd95013dad6320cb7fbc4166255c.tar.xz
platform-system-core-0c5f7d838911fd95013dad6320cb7fbc4166255c.zip
Revert "Revert "libsuspend: move to exponential backoff""
Test: Left device overnight, libsuspend exponential backoff path was exercised multiple time and device went into suspend. This reverts commit 23c8bab0243bc6e7be8b95702c262c354009d56a. Change-Id: Ifa5c41bc1ca5da7baa28b216d70305c98806bf36
Diffstat (limited to 'libsuspend')
-rw-r--r--libsuspend/autosuspend_wakeup_count.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/libsuspend/autosuspend_wakeup_count.c b/libsuspend/autosuspend_wakeup_count.c
index 4dedf7f9f..2da204ae0 100644
--- a/libsuspend/autosuspend_wakeup_count.c
+++ b/libsuspend/autosuspend_wakeup_count.c
@@ -24,6 +24,7 @@
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>
27#include <sys/stat.h> 28#include <sys/stat.h>
28#include <sys/types.h> 29#include <sys/types.h>
29#include <unistd.h> 30#include <unistd.h>
@@ -35,12 +36,24 @@
35#define SYS_POWER_STATE "/sys/power/state" 36#define SYS_POWER_STATE "/sys/power/state"
36#define SYS_POWER_WAKEUP_COUNT "/sys/power/wakeup_count" 37#define SYS_POWER_WAKEUP_COUNT "/sys/power/wakeup_count"
37 38
39#define BASE_SLEEP_TIME 100000
40
38static int state_fd; 41static int state_fd;
39static int wakeup_count_fd; 42static int wakeup_count_fd;
40static pthread_t suspend_thread; 43static pthread_t suspend_thread;
41static sem_t suspend_lockout; 44static sem_t suspend_lockout;
42static const char *sleep_state = "mem"; 45static const char *sleep_state = "mem";
43static void (*wakeup_func)(bool success) = NULL; 46static 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}
44 57
45static void *suspend_thread_func(void *arg __attribute__((unused))) 58static void *suspend_thread_func(void *arg __attribute__((unused)))
46{ 59{
@@ -48,10 +61,12 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
48 char wakeup_count[20]; 61 char wakeup_count[20];
49 int wakeup_count_len; 62 int wakeup_count_len;
50 int ret; 63 int ret;
51 bool success; 64 bool success = true;
52 65
53 while (1) { 66 while (1) {
54 usleep(100000); 67 update_sleep_time(success);
68 usleep(sleep_time);
69 success = false;
55 ALOGV("%s: read wakeup_count\n", __func__); 70 ALOGV("%s: read wakeup_count\n", __func__);
56 lseek(wakeup_count_fd, 0, SEEK_SET); 71 lseek(wakeup_count_fd, 0, SEEK_SET);
57 wakeup_count_len = TEMP_FAILURE_RETRY(read(wakeup_count_fd, wakeup_count, 72 wakeup_count_len = TEMP_FAILURE_RETRY(read(wakeup_count_fd, wakeup_count,
@@ -75,7 +90,6 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
75 continue; 90 continue;
76 } 91 }
77 92
78 success = true;
79 ALOGV("%s: write %*s to wakeup_count\n", __func__, wakeup_count_len, wakeup_count); 93 ALOGV("%s: write %*s to wakeup_count\n", __func__, wakeup_count_len, wakeup_count);
80 ret = TEMP_FAILURE_RETRY(write(wakeup_count_fd, wakeup_count, wakeup_count_len)); 94 ret = TEMP_FAILURE_RETRY(write(wakeup_count_fd, wakeup_count, wakeup_count_len));
81 if (ret < 0) { 95 if (ret < 0) {
@@ -84,8 +98,8 @@ static void *suspend_thread_func(void *arg __attribute__((unused)))
84 } else { 98 } else {
85 ALOGV("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE); 99 ALOGV("%s: write %s to %s\n", __func__, sleep_state, SYS_POWER_STATE);
86 ret = TEMP_FAILURE_RETRY(write(state_fd, sleep_state, strlen(sleep_state))); 100 ret = TEMP_FAILURE_RETRY(write(state_fd, sleep_state, strlen(sleep_state)));
87 if (ret < 0) { 101 if (ret >= 0) {
88 success = false; 102 success = true;
89 } 103 }
90 void (*func)(bool success) = wakeup_func; 104 void (*func)(bool success) = wakeup_func;
91 if (func != NULL) { 105 if (func != NULL) {