summaryrefslogtreecommitdiff
path: root/zephyr
diff options
context:
space:
mode:
authorKeith Short <keithshort@chromium.org>2022-03-30 18:18:08 -0600
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-03-31 20:28:50 +0000
commit1d844062cdf82d56cd4190f92c2fab592da7bc36 (patch)
treebf2325e854778f2eeb69e49c992f30ece8be09c6 /zephyr
parent9198149037b783de361169e91793aba964c54ff9 (diff)
downloadchrome-ec-1d844062cdf82d56cd4190f92c2fab592da7bc36.tar.gz
zephyr: Fix the override of the system workqueue
After the conversion of HOOK_INIT to SYS_INIT within the Zephyr shim code, the EC reported a false error that the sysworkq priority was incorrect. Move the code that sets the system workqueue thread priority to sooner in the initialization order. Also move the check of the system workqueue thread to occur after all other threads are started. BUG=none BRANCH=none TEST=zmake testall TEST=Run "kernel threads" on byra and verify system workqueue is set to the lowest priority, but above the idle priority. Signed-off-by: Keith Short <keithshort@chromium.org> Change-Id: I14743cbb6643dce9e9b73584d75ec3298c8d9117 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3562002 Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'zephyr')
-rw-r--r--zephyr/app/ec/ec_app_main.c8
-rw-r--r--zephyr/shim/src/hooks.c25
-rw-r--r--zephyr/shim/src/tasks.c21
3 files changed, 34 insertions, 20 deletions
diff --git a/zephyr/app/ec/ec_app_main.c b/zephyr/app/ec/ec_app_main.c
index 32ad941f6c..3e01cf04ee 100644
--- a/zephyr/app/ec/ec_app_main.c
+++ b/zephyr/app/ec/ec_app_main.c
@@ -74,14 +74,6 @@ void ec_app_main(void)
}
/*
- * Hooks run from the system workqueue and must be the lowest priority
- * thread. By default, the system workqueue is run at the lowest
- * cooperative thread priority, blocking all preemptive threads until
- * the deferred work is completed.
- */
- k_thread_priority_set(&k_sys_work_q.thread, LOWEST_THREAD_PRIORITY);
-
- /*
* Print the init time. Not completely accurate because it can't take
* into account the time before timer_init(), but it'll at least catch
* the majority of the time.
diff --git a/zephyr/shim/src/hooks.c b/zephyr/shim/src/hooks.c
index 8ad9c4ebc1..35eb78d840 100644
--- a/zephyr/shim/src/hooks.c
+++ b/zephyr/shim/src/hooks.c
@@ -80,24 +80,26 @@ static void hook_tick_work(struct k_work *work)
work_queue_error(&hook_ticks_work_data, rv);
}
-static int check_hook_task_priority(const struct device *unused)
+/*
+ * Hooks run from the system workqueue and must be the lowest priority
+ * thread. The system workqueue priority is initialized by
+ * CONFIG_SYSTEM_WORKQUEUE_PRIORITY, but it's not possible to set this option
+ * based on another Kconfig symbol (e.g. CONFIG_NUM_PREEMPT_PRIORITIES - 1).
+ *
+ * Override the system workqueue priority as the last item at the POST_KERNEL
+ * initialization level, which runs before all SYS_INIT calls at the
+ * APPLICATION initialization level.
+ */
+static int set_system_workqueue_priority(const struct device *unused)
{
ARG_UNUSED(unused);
k_tid_t thread = &k_sys_work_q.thread;
- /*
- * Numerically lower priorities take precedence, so verify the hook
- * related threads cannot preempt any of the shimmed tasks.
- */
- if (k_thread_priority_get(thread) < (TASK_ID_COUNT - 1))
- cprintf(CC_HOOK,
- "ERROR: %s has priority %d but must be >= %d\n",
- k_thread_name_get(thread),
- k_thread_priority_get(thread), (TASK_ID_COUNT - 1));
+ k_thread_priority_set(thread, K_LOWEST_APPLICATION_THREAD_PRIO);
return 0;
}
-SYS_INIT(check_hook_task_priority, APPLICATION, HOOK_PRIO_FIRST);
+SYS_INIT(set_system_workqueue_priority, POST_KERNEL, 99);
static int zephyr_shim_setup_hooks(const struct device *unused)
{
@@ -115,7 +117,6 @@ static int zephyr_shim_setup_hooks(const struct device *unused)
return 0;
}
-
SYS_INIT(zephyr_shim_setup_hooks, APPLICATION, 1);
void hook_notify(enum hook_type type)
diff --git a/zephyr/shim/src/tasks.c b/zephyr/shim/src/tasks.c
index a2a4df8320..562a6fe1c9 100644
--- a/zephyr/shim/src/tasks.c
+++ b/zephyr/shim/src/tasks.c
@@ -293,6 +293,21 @@ BUILD_ASSERT((K_PRIO_PREEMPT(TASK_ID_COUNT - 1) < K_IDLE_PRIO),
"CONFIG_NUM_PREEMPT_PRIORITIES too small, some tasks would run at "
"idle priority");
+static void check_system_work_queue_priority(void)
+{
+ k_tid_t thread = &k_sys_work_q.thread;
+
+ /*
+ * Numerically lower priorities take precedence, so verify the hook
+ * related threads cannot preempt any of the shimmed tasks.
+ */
+ if (k_thread_priority_get(thread) < (TASK_ID_COUNT - 1))
+ cprintf(CC_HOOK,
+ "ERROR: %s has priority %d but must be >= %d\n",
+ k_thread_name_get(thread),
+ k_thread_priority_get(thread), (TASK_ID_COUNT - 1));
+}
+
void start_ec_tasks(void)
{
int priority;
@@ -355,6 +370,12 @@ void start_ec_tasks(void)
/* Create an entry for sysworkq we can send events to */
shimmed_tasks_dyn[TASK_ID_COUNT].zephyr_tid = &k_sys_work_q.thread;
+ /*
+ * Now that all threads are created, validate the system workqueue
+ * priority.
+ */
+ check_system_work_queue_priority();
+
tasks_started = 1;
}