summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Barnes <robbarnes@google.com>2023-02-01 08:45:25 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-05-01 21:29:29 +0000
commitae9927ec756fbe652190088c0820717b8690b093 (patch)
treeed1f21f20ae0c496cadee6f83062f3762e5261c1
parentf2e7fd5a61404ff60652fe6dfc9a4e0d1cdad5a9 (diff)
downloadchrome-ec-ae9927ec756fbe652190088c0820717b8690b093.tar.gz
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 <robbarnes@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4214562 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4482719
-rw-r--r--common/system_safe_mode.c29
-rw-r--r--include/system_safe_mode.h1
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