summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2021-11-05 14:24:17 -0600
committerCommit Bot <commit-bot@chromium.org>2021-11-08 23:36:07 +0000
commit687b239833af6369141afeea2f25956184d70b09 (patch)
treea113f23a847fefe5f073fc6b364f975fff145fe4
parentff45017216f37d00a9588abef0a2609635f0a042 (diff)
downloadchrome-ec-687b239833af6369141afeea2f25956184d70b09.tar.gz
Task: Introduce generic deferred check
Code will currently check whether it's running in a deferred context by directly checking against TASK_ID_HOOKS. However, this should be checked in a function which can be set based on the OS running to account for OS differences. BRANCH=None BUG=b:195137794 TEST=make -j buildall Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I54c266bb3a36ee3aa3fe6f8a09fcbfafe2fb43e9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3265285 Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r--common/motion_sense.c6
-rw-r--r--common/usbc/usb_pd_dpm.c2
-rw-r--r--include/task.h18
-rw-r--r--zephyr/shim/src/tasks.c15
4 files changed, 37 insertions, 4 deletions
diff --git a/common/motion_sense.c b/common/motion_sense.c
index 6a93e15dde..a9b15fd071 100644
--- a/common/motion_sense.c
+++ b/common/motion_sense.c
@@ -332,10 +332,10 @@ static inline int motion_sense_init(struct motion_sensor_t *sensor)
BUILD_ASSERT(SENSOR_COUNT < 32);
#if defined(HAS_TASK_CONSOLE)
- ASSERT((task_get_current() == TASK_ID_HOOKS) ||
+ ASSERT((in_deferred_context()) ||
(task_get_current() == TASK_ID_CONSOLE));
#else
- ASSERT(task_get_current() == TASK_ID_HOOKS);
+ ASSERT(in_deferred_context());
#endif /* HAS_TASK_CONSOLE */
/* Initialize accelerometers. */
@@ -386,7 +386,7 @@ static void motion_sense_switch_sensor_rate(void)
struct motion_sensor_t *sensor;
unsigned int sensor_setup_mask = 0;
- ASSERT(task_get_current() == TASK_ID_HOOKS);
+ ASSERT(in_deferred_context());
for (i = 0; i < motion_sensor_count; ++i) {
sensor = &motion_sensors[i];
diff --git a/common/usbc/usb_pd_dpm.c b/common/usbc/usb_pd_dpm.c
index e3a392d5dc..5053f0a482 100644
--- a/common/usbc/usb_pd_dpm.c
+++ b/common/usbc/usb_pd_dpm.c
@@ -468,7 +468,7 @@ static void balance_source_ports(void)
uint32_t removed_ports, new_ports;
static bool deferred_waiting;
- if (task_get_current() == TASK_ID_HOOKS)
+ if (in_deferred_context())
deferred_waiting = false;
/*
diff --git a/include/task.h b/include/task.h
index f93991679e..94b7a39908 100644
--- a/include/task.h
+++ b/include/task.h
@@ -10,6 +10,7 @@
#include "common.h"
#include "compile_time_macros.h"
+#include <stdbool.h>
#include "task_id.h"
/* Task event bitmasks */
@@ -166,6 +167,23 @@ static inline void task_wake(task_id_t tskid)
*/
task_id_t task_get_current(void);
+#ifdef CONFIG_ZEPHYR
+/**
+ * Check if this current task is running in deferred context
+ */
+bool in_deferred_context(void);
+#else
+/* All ECOS deferred calls run from the HOOKS task */
+static inline bool in_deferred_context(void)
+{
+#ifdef HAS_TASK_HOOKS
+ return (task_get_current() == TASK_ID_HOOKS);
+#else
+ return false;
+#endif /* HAS_TASK_HOOKS */
+}
+#endif /* CONFIG_ZEPHYR */
+
/**
* Return a pointer to the bitmap of events of the task.
*/
diff --git a/zephyr/shim/src/tasks.c b/zephyr/shim/src/tasks.c
index 95322d598c..252fe5e66e 100644
--- a/zephyr/shim/src/tasks.c
+++ b/zephyr/shim/src/tasks.c
@@ -94,6 +94,8 @@ const static struct task_ctx_static shimmed_tasks_static[TASK_ID_COUNT] = {
/* In dynamic tasks, allocate one extra spot for the sysworkq */
static struct task_ctx_dyn shimmed_tasks_dyn[TASK_ID_COUNT + 1];
+#define TASK_ID_SYSWORKQ TASK_ID_COUNT
+
static int tasks_started;
#undef CROS_EC_TASK
#undef TASK_TEST
@@ -369,6 +371,19 @@ inline int in_interrupt_context(void)
return k_is_in_isr();
}
+inline bool in_deferred_context(void)
+{
+ /*
+ * Deferred calls run in the sysworkq, but in ECOS usage we also
+ * consider HOOKS calls such as HOOK_TICK and HOOK_SECOND as well.
+ */
+ return (task_get_current() == TASK_ID_SYSWORKQ)
+#if HAS_TASK_HOOKS
+ || (task_get_current() == TASK_ID_HOOKS)
+#endif
+ ;
+}
+
#if IS_ENABLED(CONFIG_KERNEL_SHELL) && IS_ENABLED(CONFIG_THREAD_MONITOR)
static int taskinfo(const struct shell *shell, size_t argc, char **argv)
{