summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Barnes <robbarnes@google.com>2023-02-01 10:27:55 -0700
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2023-02-15 15:58:42 +0000
commit70e826325a4f54f666a0bad67e7a410f9dbb11d1 (patch)
treeccbfaf7c2d97eac411b883728cf2d786d21cd359
parent9e0966e1125c0de9cc0080f5e28b9ad2a14f0ff9 (diff)
downloadchrome-ec-70e826325a4f54f666a0bad67e7a410f9dbb11d1.tar.gz
tasks: Add extra IDLE task id
Add the idle task to the non-shimmed extra tasks list. BUG=b:267470086 BRANCH=None TEST=Unit tests Change-Id: I87cbbcd32777ab65de09c053a9098031f0950c3e Signed-off-by: Rob Barnes <robbarnes@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4214557 Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com>
-rw-r--r--zephyr/shim/include/shimmed_task_id.h6
-rw-r--r--zephyr/shim/include/shimmed_tasks.h3
-rw-r--r--zephyr/shim/src/tasks.c15
-rw-r--r--zephyr/test/tasks/extra_tasks.c5
4 files changed, 27 insertions, 2 deletions
diff --git a/zephyr/shim/include/shimmed_task_id.h b/zephyr/shim/include/shimmed_task_id.h
index a0295ad764..f6300ed150 100644
--- a/zephyr/shim/include/shimmed_task_id.h
+++ b/zephyr/shim/include/shimmed_task_id.h
@@ -213,7 +213,6 @@ enum {
#define CROS_EC_TASK(name, ...) TASK_ID_##name,
#define TASK_TEST(name, ...) CROS_EC_TASK(name)
enum {
- TASK_ID_IDLE = -1, /* We don't shim the idle task */
CROS_EC_TASK_LIST
#ifdef TEST_BUILD
TASK_ID_TEST_RUNNER,
@@ -228,9 +227,12 @@ enum {
* Additional task IDs for features that runs on non shimmed threads,
* task_get_current() needs to be updated to identify these ones.
*/
+/* clang-format off */
#define CROS_EC_EXTRA_TASKS(fn) \
COND_CODE_1(CONFIG_TASK_HOSTCMD_THREAD_MAIN, (fn(HOSTCMD)), ()) \
- fn(SYSWORKQ)
+ fn(SYSWORKQ) \
+ fn(IDLE)
+/* clang-format on */
#define EXTRA_TASK_INTERNAL_ID(name) EXTRA_TASK_##name,
enum {
diff --git a/zephyr/shim/include/shimmed_tasks.h b/zephyr/shim/include/shimmed_tasks.h
index 75be968f4a..cf579f1ed9 100644
--- a/zephyr/shim/include/shimmed_tasks.h
+++ b/zephyr/shim/include/shimmed_tasks.h
@@ -47,4 +47,7 @@
#define HAS_TASK_USB_MUX 1
#endif /* CONFIG_PLATFORM_EC_USB_MUX_TASK */
+/* These non-shimmed (extra) tasks are always present */
+#define HAS_TASK_IDLE 1
+
#endif /* __CROS_EC_SHIMMED_TASKS_H */
diff --git a/zephyr/shim/src/tasks.c b/zephyr/shim/src/tasks.c
index a5d47cea29..84384a27ea 100644
--- a/zephyr/shim/src/tasks.c
+++ b/zephyr/shim/src/tasks.c
@@ -78,6 +78,17 @@ static struct task_ctx_base_data *task_get_base_data(task_id_t cros_task_id)
return &shimmed_tasks_data[cros_task_id];
}
+test_export_static k_tid_t get_idle_thread(void)
+{
+ extern struct k_thread z_idle_threads[];
+
+ if (!IS_ENABLED(CONFIG_SMP)) {
+ return &z_idle_threads[0];
+ }
+ __ASSERT(false, "%s does not support SMP", __func__);
+ return NULL;
+}
+
task_id_t task_get_current(void)
{
if (in_deferred_context()) {
@@ -90,6 +101,10 @@ task_id_t task_get_current(void)
}
#endif
+ if (get_idle_thread() == k_current_get()) {
+ return TASK_ID_IDLE;
+ }
+
for (size_t i = 0; i < TASK_ID_COUNT; ++i) {
if (task_to_k_tid[i] == k_current_get())
return i;
diff --git a/zephyr/test/tasks/extra_tasks.c b/zephyr/test/tasks/extra_tasks.c
index c302437c20..98aa300b17 100644
--- a/zephyr/test/tasks/extra_tasks.c
+++ b/zephyr/test/tasks/extra_tasks.c
@@ -3,10 +3,14 @@
* found in the LICENSE file.
*/
+#include "task.h"
+
#include <zephyr/kernel.h>
#include <zephyr/kernel/thread.h>
#include <zephyr/ztest.h>
+k_tid_t get_idle_thread(void);
+
/* Utility functions for finding a Zephyr thread by name */
static k_tid_t found_thread;
static void find_thread_by_name_cb(const struct k_thread *thread,
@@ -53,6 +57,7 @@ ZTEST_USER(extra_tasks, test_idle_thread_mapping)
idle_thread = find_thread_by_name("idle");
zassert_not_null(idle_thread);
+ zassert_equal(idle_thread, get_idle_thread());
}
ZTEST_SUITE(extra_tasks, NULL, NULL, NULL, NULL, NULL);