summaryrefslogtreecommitdiff
path: root/power
diff options
context:
space:
mode:
authorEvan Green <evgreen@chromium.org>2019-03-01 13:09:08 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-03-28 19:04:16 -0700
commit49b8070623ee1cecac387488ce668a4a11403653 (patch)
treebf4cc3078a496e7a9c8aa14c902be79cd3897c69 /power
parenta029c7a27f3bd1a1066db9c167c6166688fe4ef3 (diff)
downloadchrome-ec-49b8070623ee1cecac387488ce668a4a11403653.tar.gz
power/intel_x86: Introduce s0ix failure detection
This change introduces logic in the EC that can detect if the host attempted to go into S0ix, but never made it. The host already sends commands indicating its intent to enter S0ix, and the EC has a SLP_S0 line that gets asserted by the AP when it actually enters S0ix. All that's needed to monitor failures is to arm a timer when receiving the S0ix suspend message. If the SLP_S0 pin goes low, then the suspend occurred and the timer is canceled. If the timer expires before SLP_S0 goes low, then the EC wakes the AP up, since it has entered a shallower idle state than intended, and should be alerted to avoid short battery life. The timer is also started when SLP_S0 is deasserted on resume. The SoC comes out of S0ix to perform housekeeping activities unbeknownst to Linux. In cases where housekeeping fails to suspend all the way back down, this timer will wake the AP. Additionally, the number of S0ix transitions is reported on resume. This enabled the AP to analyze the amount of "sleepwalking" that is done, and can complain if it seems to be waking up too often. Design doc at: https://docs.google.com/document/d/1mY-v02KAuOyET3td9s5GnxeUgMiAcD058oLEo57DZpY/edit BUG=b:123716513 BRANCH=None TEST=Test S0ix on hatch with modified code that forces a timeout, use ectool to send messages manually before and after timeout, Hack Linux to fail suspend very late to verify no regressions. Signed-off-by: Evan Green <evgreen@chromium.org> Change-Id: Ia64b496675a13dbed4ef74637f51e39eee68aa1a Reviewed-on: https://chromium-review.googlesource.com/1501512 Commit-Ready: Evan Green <evgreen@chromium.org> Tested-by: Evan Green <evgreen@chromium.org> Reviewed-by: Furquan Shaikh <furquan@chromium.org> Reviewed-by: Karthikeyan Ramasubramanian <kramasub@chromium.org>
Diffstat (limited to 'power')
-rw-r--r--power/common.c52
-rw-r--r--power/intel_x86.c117
2 files changed, 157 insertions, 12 deletions
diff --git a/power/common.c b/power/common.c
index cccb34911a..09501a16ec 100644
--- a/power/common.c
+++ b/power/common.c
@@ -873,37 +873,69 @@ DECLARE_CONSOLE_COMMAND(pause_in_s5, command_pause_in_s5,
static enum host_sleep_event host_sleep_state;
void __attribute__((weak))
-power_chipset_handle_host_sleep_event(enum host_sleep_event state)
+power_chipset_handle_host_sleep_event(enum host_sleep_event state,
+ struct host_sleep_event_context *ctx)
{
/* Default weak implementation -- no action required. */
}
static int host_command_host_sleep_event(struct host_cmd_handler_args *args)
{
- const struct ec_params_host_sleep_event *p = args->params;
+ const struct ec_params_host_sleep_event_v1 *p = args->params;
+ struct ec_response_host_sleep_event_v1 *r = args->response;
+ struct host_sleep_event_context ctx;
+ enum host_sleep_event state = p->sleep_event;
- host_sleep_state = p->sleep_event;
+ host_sleep_state = state;
+ switch (state) {
+ case HOST_SLEEP_EVENT_S3_SUSPEND:
+ case HOST_SLEEP_EVENT_S0IX_SUSPEND:
+ case HOST_SLEEP_EVENT_S3_WAKEABLE_SUSPEND:
+ ctx.sleep_timeout_ms = EC_HOST_SLEEP_TIMEOUT_DEFAULT;
+
+ /* The original version contained only state. */
+ if (args->version >= 1)
+ ctx.sleep_timeout_ms =
+ p->suspend_params.sleep_timeout_ms;
+
+ break;
+
+ default:
+ break;
+ }
- power_chipset_handle_host_sleep_event(host_sleep_state);
+ power_chipset_handle_host_sleep_event(host_sleep_state, &ctx);
+ switch (state) {
+ case HOST_SLEEP_EVENT_S3_RESUME:
+ case HOST_SLEEP_EVENT_S0IX_RESUME:
+ if (args->version >= 1) {
+ r->resume_response.sleep_transitions =
+ ctx.sleep_transitions;
+
+ args->response_size = sizeof(*r);
+ }
+
+ break;
+
+ default:
+ break;
+ }
return EC_RES_SUCCESS;
}
DECLARE_HOST_COMMAND(EC_CMD_HOST_SLEEP_EVENT,
host_command_host_sleep_event,
- EC_VER_MASK(0));
+ EC_VER_MASK(0) | EC_VER_MASK(1));
enum host_sleep_event power_get_host_sleep_state(void)
{
return host_sleep_state;
}
-#ifdef CONFIG_POWER_S0IX
-void power_reset_host_sleep_state(void)
+void power_set_host_sleep_state(enum host_sleep_event state)
{
- host_sleep_state = HOST_SLEEP_EVENT_DEFAULT_RESET;
- power_chipset_handle_host_sleep_event(host_sleep_state);
+ host_sleep_state = state;
}
-#endif /* CONFIG_POWER_S0IX */
#endif /* CONFIG_POWER_TRACK_HOST_SLEEP_STATE */
diff --git a/power/intel_x86.c b/power/intel_x86.c
index 758f8c2ed5..4e7230d395 100644
--- a/power/intel_x86.c
+++ b/power/intel_x86.c
@@ -39,6 +39,7 @@
/* Console output macros */
#define CPRINTS(format, args...) cprints(CC_CHIPSET, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_CHIPSET, format, ## args)
enum sys_sleep_state {
SYS_SLEEP_S3,
@@ -224,7 +225,109 @@ static void handle_chipset_reset(void)
}
DECLARE_HOOK(HOOK_CHIPSET_RESET, handle_chipset_reset, HOOK_PRIO_FIRST);
-#endif
+#ifdef CONFIG_POWER_TRACK_HOST_SLEEP_STATE
+#ifdef CONFIG_POWER_S0IX_FAILURE_DETECTION
+
+static uint16_t slp_s0ix_timeout;
+static uint32_t slp_s0ix_transitions;
+
+static void s0ix_transition_timeout(void);
+DECLARE_DEFERRED(s0ix_transition_timeout);
+
+static void s0ix_increment_transition(void)
+{
+ if ((slp_s0ix_transitions & EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK) <
+ EC_HOST_RESUME_SLEEP_TRANSITIONS_MASK)
+ slp_s0ix_transitions += 1;
+}
+
+static void s0ix_suspend_transition(void)
+{
+ s0ix_increment_transition();
+ hook_call_deferred(&s0ix_transition_timeout_data, -1);
+}
+
+static void s0ix_resume_transition(void)
+{
+ s0ix_increment_transition();
+
+ /*
+ * Start the timer again to ensure the AP doesn't get itself stuck in
+ * a state where it's no longer in S0ix, but from the Linux perspective
+ * is still suspended. Perhaps a bug in the SoC-internal periodic
+ * housekeeping code might result in a situation like this.
+ */
+ if (slp_s0ix_timeout)
+ hook_call_deferred(&s0ix_transition_timeout_data,
+ (uint32_t)slp_s0ix_timeout * 1000);
+}
+
+static void s0ix_transition_timeout(void)
+{
+ /* Mark the timeout. */
+ slp_s0ix_transitions |= EC_HOST_RESUME_SLEEP_TIMEOUT;
+ hook_call_deferred(&s0ix_transition_timeout_data, -1);
+
+ /*
+ * Wake up the AP so they don't just chill in a non-suspended state and
+ * burn power. Overload a vaguely related event bit since event bits are
+ * at a premium.
+ */
+ host_set_single_event(EC_HOST_EVENT_HANG_DETECT);
+}
+
+static void s0ix_start_suspend(struct host_sleep_event_context *ctx)
+{
+ uint16_t timeout = ctx->sleep_timeout_ms;
+
+ slp_s0ix_transitions = 0;
+
+ /* Use zero internally to indicate no timeout. */
+ if (timeout == EC_HOST_SLEEP_TIMEOUT_DEFAULT) {
+ timeout = CONFIG_SLEEP_TIMEOUT_MS;
+
+ } else if (timeout == EC_HOST_SLEEP_TIMEOUT_INFINITE) {
+ slp_s0ix_timeout = 0;
+ return;
+ }
+
+ slp_s0ix_timeout = timeout;
+ hook_call_deferred(&s0ix_transition_timeout_data,
+ (uint32_t)timeout * 1000);
+}
+
+static void s0ix_complete_resume(struct host_sleep_event_context *ctx)
+{
+ hook_call_deferred(&s0ix_transition_timeout_data, -1);
+ ctx->sleep_transitions = slp_s0ix_transitions;
+}
+
+static void s0ix_reset_tracking(void)
+{
+ slp_s0ix_transitions = 0;
+ slp_s0ix_timeout = 0;
+}
+
+#else /* !CONFIG_POWER_S0IX_FAILURE_DETECTION */
+
+#define s0ix_suspend_transition()
+#define s0ix_resume_transition()
+#define s0ix_start_suspend(_ctx)
+#define s0ix_complete_resume(_ctx)
+#define s0ix_reset_tracking()
+
+#endif /* CONFIG_POWER_S0IX_FAILURE_DETECTION */
+
+void power_reset_host_sleep_state(void)
+{
+ power_set_host_sleep_state(HOST_SLEEP_EVENT_DEFAULT_RESET);
+ s0ix_reset_tracking();
+ power_chipset_handle_host_sleep_event(HOST_SLEEP_EVENT_DEFAULT_RESET,
+ NULL);
+}
+
+#endif /* CONFIG_POWER_TRACK_HOST_SLEEP_STATE */
+#endif /* CONFIG_POWER_S0IX */
void chipset_throttle_cpu(int throttle)
{
@@ -459,11 +562,13 @@ enum power_state common_intel_x86_power_handle_state(enum power_state state)
#ifdef CONFIG_POWER_S0IX
case POWER_S0S0ix:
+
/*
* Call hooks only if we haven't notified listeners of S0ix
* suspend.
*/
s0ix_transition(S0IX_NOTIFY_SUSPEND, HOOK_CHIPSET_SUSPEND);
+ s0ix_suspend_transition();
/*
* Enable idle task deep sleep. Allow the low power idle task
@@ -479,6 +584,7 @@ enum power_state common_intel_x86_power_handle_state(enum power_state state)
*/
disable_sleep(SLEEP_MASK_AP_RUN);
+ s0ix_resume_transition();
return POWER_S0;
#endif
@@ -549,7 +655,9 @@ power_board_handle_host_sleep_event(enum host_sleep_event state)
/* Default weak implementation -- no action required. */
}
-void power_chipset_handle_host_sleep_event(enum host_sleep_event state)
+void
+power_chipset_handle_host_sleep_event(enum host_sleep_event state,
+ struct host_sleep_event_context *ctx)
{
power_board_handle_host_sleep_event(state);
@@ -561,6 +669,8 @@ void power_chipset_handle_host_sleep_event(enum host_sleep_event state)
* notification needs to be sent to listeners.
*/
s0ix_notify = S0IX_NOTIFY_SUSPEND;
+
+ s0ix_start_suspend(ctx);
power_signal_enable_interrupt(sleep_sig[SYS_SLEEP_S0IX]);
} else if (state == HOST_SLEEP_EVENT_S0IX_RESUME) {
/*
@@ -574,10 +684,13 @@ void power_chipset_handle_host_sleep_event(enum host_sleep_event state)
;
lpc_s0ix_resume_restore_masks();
power_signal_disable_interrupt(sleep_sig[SYS_SLEEP_S0IX]);
+ s0ix_complete_resume(ctx);
+
} else if (state == HOST_SLEEP_EVENT_DEFAULT_RESET) {
power_signal_disable_interrupt(sleep_sig[SYS_SLEEP_S0IX]);
}
#endif
+
}
#endif