summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Baltieri <fabiobaltieri@google.com>2022-04-05 15:02:44 +0000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-04-07 20:03:23 +0000
commit915e3e4c1ee1db76e1ce4ddf8198beac12b811cb (patch)
treee4406a7ecd98ac2eb1cbcedd84a561efcf56b9ac
parent55d76be934ce776beb85ec31aad2aa23312bdc2b (diff)
downloadchrome-ec-915e3e4c1ee1db76e1ce4ddf8198beac12b811cb.tar.gz
zephyr: shim: tasks: use the Zephyr cfg/data convention
Zephyr task shim code has a conventional pair of const/non const data structures, but these are oddly named. Change the structure reference variables to the more conventional *cfg and *data, as it's commonly used in the Zephyr driver model. BRANCH=none BUG=none TEST=zmake testall Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com> Change-Id: I6af3585899d1245014ee387aa2eb3da5339af271 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3572082 Reviewed-by: Tristan Honscheid <honscheid@google.com>
-rw-r--r--zephyr/shim/src/tasks.c130
1 files changed, 60 insertions, 70 deletions
diff --git a/zephyr/shim/src/tasks.c b/zephyr/shim/src/tasks.c
index a2a4df8320..5b8fb502be 100644
--- a/zephyr/shim/src/tasks.c
+++ b/zephyr/shim/src/tasks.c
@@ -33,7 +33,7 @@ CROS_EC_TASK_LIST
#undef TASK_TEST
/** Context for each CROS EC task that is run in its own zephyr thread */
-struct task_ctx_static {
+struct task_ctx_cfg {
#ifdef CONFIG_THREAD_NAME
/** Name of thread (for debugging) */
const char *name;
@@ -48,7 +48,7 @@ struct task_ctx_static {
intptr_t parameter;
};
-struct task_ctx_dyn {
+struct task_ctx_data {
/** Zephyr thread structure that hosts EC tasks */
struct k_thread zephyr_thread;
/** Zephyr thread id for above thread */
@@ -64,36 +64,26 @@ struct task_ctx_dyn {
struct k_timer timer;
};
-#ifdef CONFIG_THREAD_NAME
-#define CROS_EC_TASK(_name, _entry, _parameter, _size) \
- { \
- .entry = _entry, \
- .parameter = _parameter, \
- .stack = _name##_STACK, \
- .stack_size = _size, \
- .name = #_name, \
- },
-#else
-#define CROS_EC_TASK(_name, _entry, _parameter, _size) \
- { \
- .entry = _entry, \
- .parameter = _parameter, \
- .stack = _name##_STACK, \
- .stack_size = _size, \
+#define CROS_EC_TASK(_name, _entry, _parameter, _size) \
+ { \
+ .entry = _entry, \
+ .parameter = _parameter, \
+ .stack = _name##_STACK, \
+ .stack_size = _size, \
+ COND_CODE_1(CONFIG_THREAD_NAME, (.name = #_name,), ()) \
},
-#endif /* CONFIG_THREAD_NAME */
#define TASK_TEST(_name, _entry, _parameter, _size) \
CROS_EC_TASK(_name, _entry, _parameter, _size)
/* Note: no static entry is required for sysworkq, as it isn't started here */
-const static struct task_ctx_static shimmed_tasks_static[TASK_ID_COUNT] = {
+const static struct task_ctx_cfg shimmed_tasks_cfg[TASK_ID_COUNT] = {
CROS_EC_TASK_LIST
#ifdef TEST_BUILD
[TASK_ID_TEST_RUNNER] = {},
#endif
};
-/* In dynamic tasks, allocate one extra spot for the sysworkq */
-static struct task_ctx_dyn shimmed_tasks_dyn[TASK_ID_COUNT + 1];
+/* In tasks data, allocate one extra spot for the sysworkq */
+static struct task_ctx_data shimmed_tasks_data[TASK_ID_COUNT + 1];
#define TASK_ID_SYSWORKQ TASK_ID_COUNT
@@ -105,7 +95,7 @@ task_id_t task_get_current(void)
{
/* Include sysworkq entry in search for the task ID */
for (size_t i = 0; i < TASK_ID_COUNT + 1; ++i) {
- if (shimmed_tasks_dyn[i].zephyr_tid == k_current_get())
+ if (shimmed_tasks_data[i].zephyr_tid == k_current_get())
return i;
}
@@ -115,29 +105,30 @@ task_id_t task_get_current(void)
__test_only k_tid_t task_get_zephyr_tid(size_t cros_tid)
{
- return shimmed_tasks_dyn[cros_tid].zephyr_tid;
+ return shimmed_tasks_data[cros_tid].zephyr_tid;
}
atomic_t *task_get_event_bitmap(task_id_t cros_task_id)
{
- struct task_ctx_dyn *const ctx = &shimmed_tasks_dyn[cros_task_id];
+ struct task_ctx_data *const data = &shimmed_tasks_data[cros_task_id];
- return &ctx->event_mask;
+ return &data->event_mask;
}
uint32_t task_set_event(task_id_t cros_task_id, uint32_t event)
{
- struct task_ctx_dyn *const ctx = &shimmed_tasks_dyn[cros_task_id];
+ struct task_ctx_data *const data = &shimmed_tasks_data[cros_task_id];
- atomic_or(&ctx->event_mask, event);
- k_poll_signal_raise(&ctx->new_event, 0);
+ atomic_or(&data->event_mask, event);
+ k_poll_signal_raise(&data->new_event, 0);
return 0;
}
uint32_t task_wait_event(int timeout_us)
{
- struct task_ctx_dyn *const ctx = &shimmed_tasks_dyn[task_get_current()];
+ struct task_ctx_data *const data =
+ &shimmed_tasks_data[task_get_current()];
const k_timeout_t timeout = (timeout_us == -1) ? K_FOREVER :
K_USEC(timeout_us);
const int64_t tick_deadline =
@@ -146,14 +137,14 @@ uint32_t task_wait_event(int timeout_us)
struct k_poll_event poll_events[1] = {
K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL,
K_POLL_MODE_NOTIFY_ONLY,
- &ctx->new_event),
+ &data->new_event),
};
/* Wait for signal, then clear it before reading events */
const int rv = k_poll(poll_events, ARRAY_SIZE(poll_events), timeout);
- k_poll_signal_reset(&ctx->new_event);
- uint32_t events = atomic_set(&ctx->event_mask, 0);
+ k_poll_signal_reset(&data->new_event);
+ uint32_t events = atomic_set(&data->event_mask, 0);
if (rv == -EAGAIN) {
events |= TASK_EVENT_TIMER;
@@ -179,7 +170,8 @@ uint32_t task_wait_event(int timeout_us)
uint32_t task_wait_event_mask(uint32_t event_mask, int timeout_us)
{
- struct task_ctx_dyn *const ctx = &shimmed_tasks_dyn[task_get_current()];
+ struct task_ctx_data *const data =
+ &shimmed_tasks_data[task_get_current()];
uint32_t events = 0;
const int64_t tick_deadline =
k_uptime_ticks() + k_us_to_ticks_near64(timeout_us);
@@ -198,37 +190,36 @@ uint32_t task_wait_event_mask(uint32_t event_mask, int timeout_us)
struct k_poll_event poll_events[1] = {
K_POLL_EVENT_INITIALIZER(K_POLL_TYPE_SIGNAL,
K_POLL_MODE_NOTIFY_ONLY,
- &ctx->new_event),
+ &data->new_event),
};
/* Ensure to honor the -1 timeout as FOREVER */
k_poll(poll_events, ARRAY_SIZE(poll_events),
timeout_us == -1 ? K_FOREVER : K_TICKS(ticks_left));
- k_poll_signal_reset(&ctx->new_event);
- events |= atomic_set(&ctx->event_mask, 0);
+ k_poll_signal_reset(&data->new_event);
+ events |= atomic_set(&data->event_mask, 0);
}
/* Replace any events that weren't in the mask */
if (events & ~event_mask) {
- atomic_or(&ctx->event_mask, events & ~event_mask);
- k_poll_signal_raise(&ctx->new_event, 0);
+ atomic_or(&data->event_mask, events & ~event_mask);
+ k_poll_signal_raise(&data->new_event, 0);
}
return events & event_mask;
}
-static void task_entry(void *task_context_static,
- void *task_context_dyn,
+static void task_entry(void *task_context_cfg,
+ void *task_context_data,
void *unused1)
{
- ARG_UNUSED(task_context_dyn);
+ ARG_UNUSED(task_context_data);
ARG_UNUSED(unused1);
- struct task_ctx_static *const ctx_static =
- (struct task_ctx_static *)task_context_static;
+ struct task_ctx_cfg *const cfg = task_context_cfg;
/* Call into task entry point */
- ctx_static->entry((void *)ctx_static->parameter);
+ cfg->entry((void *)cfg->parameter);
}
/*
@@ -237,9 +228,9 @@ static void task_entry(void *task_context_static,
*/
static void timer_expire(struct k_timer *timer_id)
{
- struct task_ctx_dyn *const ctx =
- CONTAINER_OF(timer_id, struct task_ctx_dyn, timer);
- task_id_t cros_ec_task_id = ctx - shimmed_tasks_dyn;
+ struct task_ctx_data *const data =
+ CONTAINER_OF(timer_id, struct task_ctx_data, timer);
+ task_id_t cros_ec_task_id = data - shimmed_tasks_data;
task_set_event(cros_ec_task_id, TASK_EVENT_TIMER);
}
@@ -247,7 +238,7 @@ static void timer_expire(struct k_timer *timer_id)
int timer_arm(timestamp_t event, task_id_t cros_ec_task_id)
{
timestamp_t now = get_time();
- struct task_ctx_dyn *const ctx = &shimmed_tasks_dyn[cros_ec_task_id];
+ struct task_ctx_data *const data = &shimmed_tasks_data[cros_ec_task_id];
if (event.val <= now.val) {
/* Timer requested for now or in the past, fire right away */
@@ -256,24 +247,24 @@ int timer_arm(timestamp_t event, task_id_t cros_ec_task_id)
}
/* Check for a running timer */
- if (k_timer_remaining_get(&ctx->timer))
+ if (k_timer_remaining_get(&data->timer))
return EC_ERROR_BUSY;
- k_timer_start(&ctx->timer, K_USEC(event.val - now.val), K_NO_WAIT);
+ k_timer_start(&data->timer, K_USEC(event.val - now.val), K_NO_WAIT);
return EC_SUCCESS;
}
void timer_cancel(task_id_t cros_ec_task_id)
{
- struct task_ctx_dyn *const ctx = &shimmed_tasks_dyn[cros_ec_task_id];
+ struct task_ctx_data *const data = &shimmed_tasks_data[cros_ec_task_id];
- k_timer_stop(&ctx->timer);
+ k_timer_stop(&data->timer);
}
#ifdef TEST_BUILD
void set_test_runner_tid(void)
{
- shimmed_tasks_dyn[TASK_ID_TEST_RUNNER].zephyr_tid = k_current_get();
+ shimmed_tasks_data[TASK_ID_TEST_RUNNER].zephyr_tid = k_current_get();
}
#ifdef CONFIG_SET_TEST_RUNNER_TID_RULE
@@ -299,18 +290,17 @@ void start_ec_tasks(void)
/* Initialize all EC tasks, which does not include the sysworkq entry */
for (size_t i = 0; i < TASK_ID_COUNT; ++i) {
- struct task_ctx_dyn *const ctx_dyn = &shimmed_tasks_dyn[i];
- const struct task_ctx_static *const ctx_static =
- &shimmed_tasks_static[i];
+ struct task_ctx_data *const data = &shimmed_tasks_data[i];
+ const struct task_ctx_cfg *const cfg = &shimmed_tasks_cfg[i];
- k_timer_init(&ctx_dyn->timer, timer_expire, NULL);
+ k_timer_init(&data->timer, timer_expire, NULL);
priority = K_PRIO_PREEMPT(TASK_ID_COUNT - i - 1);
#ifdef TEST_BUILD
/* Do not create thread for test runner; it will be set later */
if (i == TASK_ID_TEST_RUNNER) {
- ctx_dyn->zephyr_tid = NULL;
+ data->zephyr_tid = NULL;
continue;
}
#endif
@@ -323,7 +313,7 @@ void start_ec_tasks(void)
* enabled cros-ec tasks.
*/
if (i == TASK_ID_CONSOLE_STUB) {
- ctx_dyn->zephyr_tid = NULL;
+ data->zephyr_tid = NULL;
uart_shell_set_priority(priority);
continue;
}
@@ -334,13 +324,13 @@ void start_ec_tasks(void)
* comment in config.h for CONFIG_TASK_LIST for existing flags
* implementation.
*/
- ctx_dyn->zephyr_tid = k_thread_create(
- &ctx_dyn->zephyr_thread,
- ctx_static->stack,
- ctx_static->stack_size,
+ data->zephyr_tid = k_thread_create(
+ &data->zephyr_thread,
+ cfg->stack,
+ cfg->stack_size,
task_entry,
- (void *)ctx_static,
- ctx_dyn,
+ (void *)cfg,
+ data,
NULL,
priority,
0,
@@ -348,12 +338,12 @@ void start_ec_tasks(void)
#ifdef CONFIG_THREAD_NAME
/* Name thread for debugging */
- k_thread_name_set(ctx_dyn->zephyr_tid, ctx_static->name);
+ k_thread_name_set(data->zephyr_tid, cfg->name);
#endif
}
/* Create an entry for sysworkq we can send events to */
- shimmed_tasks_dyn[TASK_ID_COUNT].zephyr_tid = &k_sys_work_q.thread;
+ shimmed_tasks_data[TASK_ID_COUNT].zephyr_tid = &k_sys_work_q.thread;
tasks_started = 1;
}
@@ -369,9 +359,9 @@ int init_signals(const struct device *unused)
/* Initialize event structures for all entries, including sysworkq */
for (size_t i = 0; i < TASK_ID_COUNT + 1; ++i) {
- struct task_ctx_dyn *const ctx = &shimmed_tasks_dyn[i];
+ struct task_ctx_data *const data = &shimmed_tasks_data[i];
- k_poll_signal_init(&ctx->new_event);
+ k_poll_signal_init(&data->new_event);
}
return 0;