From ae9927ec756fbe652190088c0820717b8690b093 Mon Sep 17 00:00:00 2001 From: Rob Barnes Date: Wed, 1 Feb 2023 08:45:25 -0700 Subject: system_safe_mode: Use common method for identifying critical tasks Legacy EC uses tasks, Zephyr uses threads, so separate methods were used to identify critical tasks/threads. This change switches Zephyr EC to use task ids to identify critical tasks. This allows some duplicate code to be removed and avoids the CONFIG_THREAD_MONITOR dependency. This relies on the tasks shim for mapping between task ids and thread ids. BUG=b:266696987 BRANCH=None TEST=Observe threads being disabled when safe mode runs Change-Id: I87bcb7de87b0575cfc5d90bd12b21314ddeea093 Signed-off-by: Rob Barnes Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4214562 Reviewed-by: Daisuke Nojiri Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4482719 --- common/system_safe_mode.c | 29 +++++++++++++++++++---------- include/system_safe_mode.h | 1 + 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/common/system_safe_mode.c b/common/system_safe_mode.c index dbad287463..e62a93831a 100644 --- a/common/system_safe_mode.c +++ b/common/system_safe_mode.c @@ -26,17 +26,24 @@ static const int safe_mode_allowed_hostcmds[] = { EC_CMD_GET_UPTIME_INFO }; -#ifndef CONFIG_ZEPHYR - -/* TODO: This function can be generalized for zephyr and legacy EC by - * improving ec_tasks support in zephyr. - */ -static bool task_is_safe_mode_critical(task_id_t task_id) +bool is_task_safe_mode_critical(task_id_t task_id) { const task_id_t safe_mode_critical_tasks[] = { +#ifdef HAS_TASK_HOOK TASK_ID_HOOKS, +#endif +#ifdef HAS_TASK_IDLE TASK_ID_IDLE, +#endif +#ifdef HAS_TASK_HOSTCMD TASK_ID_HOSTCMD, +#endif +#ifdef HAS_TASK_MAIN + TASK_ID_MAIN, +#endif +#ifdef HAS_TASK_SYSWORKQ + TASK_ID_SYSWORKQ, +#endif }; for (int i = 0; i < ARRAY_SIZE(safe_mode_critical_tasks); i++) if (safe_mode_critical_tasks[i] == task_id) @@ -44,15 +51,17 @@ static bool task_is_safe_mode_critical(task_id_t task_id) return false; } -bool current_task_is_safe_mode_critical(void) +bool is_current_task_safe_mode_critical(void) { - return task_is_safe_mode_critical(task_get_current()); + return is_task_safe_mode_critical(task_get_current()); } +#ifndef CONFIG_ZEPHYR + int disable_non_safe_mode_critical_tasks(void) { for (task_id_t task_id = 0; task_id < TASK_ID_COUNT; task_id++) { - if (!task_is_safe_mode_critical(task_id)) { + if (!is_task_safe_mode_critical(task_id)) { task_disable_task(task_id); } } @@ -101,7 +110,7 @@ int start_system_safe_mode(void) return EC_ERROR_INVAL; } - if (current_task_is_safe_mode_critical()) { + if (is_current_task_safe_mode_critical()) { /* TODO: Restart critical tasks */ panic_printf( "Fault in critical task, cannot enter system safe mode\n"); diff --git a/include/system_safe_mode.h b/include/system_safe_mode.h index b7b31d9707..a39e61c195 100644 --- a/include/system_safe_mode.h +++ b/include/system_safe_mode.h @@ -7,6 +7,7 @@ #define __CROS_EC_SYSTEM_SAFE_MODE_H #include "stdbool.h" +#include "task.h" /** * Checks if running in system safe mode -- cgit v1.2.1