summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Barnaś <mb@semihalf.com>2021-10-04 18:01:42 +0200
committerCommit Bot <commit-bot@chromium.org>2021-10-05 00:33:25 +0000
commit79d8c7d2c15083f2fc4c07e4e2816a02b363fb41 (patch)
tree0bc92aeb2a31753b45293e58690bb4abe8efce8c
parent071a821a4caab683c420d85af868a320085a097a (diff)
downloadchrome-ec-79d8c7d2c15083f2fc4c07e4e2816a02b363fb41.tar.gz
zephyr: shim: split task structure to save memory
Split task_ctx structure to separate const data from mutable. This saves a lot of ram and flash memory. BRANCH=main BUG=b:200693667 TEST=Compile and flash firmware for lazor. Check that RAM and flash have more free bytes. EC should work correctly. Change-Id: Ia0706e9e1521f6fbdf8f5d299e83ba2940094091 Signed-off-by: Michał Barnaś <mb@semihalf.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3202197 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
-rw-r--r--zephyr/shim/src/tasks.c87
1 files changed, 53 insertions, 34 deletions
diff --git a/zephyr/shim/src/tasks.c b/zephyr/shim/src/tasks.c
index 2f1fec16d6..8ee3dca266 100644
--- a/zephyr/shim/src/tasks.c
+++ b/zephyr/shim/src/tasks.c
@@ -32,15 +32,11 @@ CROS_EC_TASK_LIST
#undef TASK_TEST
/** Context for each CROS EC task that is run in its own zephyr thread */
-struct task_ctx {
+struct task_ctx_static {
#ifdef CONFIG_THREAD_NAME
/** Name of thread (for debugging) */
const char *name;
#endif
- /** Zephyr thread structure that hosts EC tasks */
- struct k_thread zephyr_thread;
- /** Zephyr thread id for above thread */
- k_tid_t zephyr_tid;
/** Address of Zephyr thread's stack */
k_thread_stack_t *stack;
/** Usabled size in bytes of above thread stack */
@@ -49,6 +45,13 @@ struct task_ctx {
void (*entry)(void *p);
/** The parameter that is passed into the task entry point */
intptr_t parameter;
+};
+
+struct task_ctx_dyn {
+ /** Zephyr thread structure that hosts EC tasks */
+ struct k_thread zephyr_thread;
+ /** Zephyr thread id for above thread */
+ k_tid_t zephyr_tid;
/** A wait-able event that is raised when a new task event is posted */
struct k_poll_signal new_event;
/** The current platform/ec events set for this task/thread */
@@ -80,22 +83,24 @@ struct task_ctx {
#endif /* CONFIG_THREAD_NAME */
#define TASK_TEST(_name, _entry, _parameter, _size) \
CROS_EC_TASK(_name, _entry, _parameter, _size)
-static struct task_ctx shimmed_tasks[] = {
+const static struct task_ctx_static shimmed_tasks_static[TASK_ID_COUNT] = {
CROS_EC_TASK_LIST
#ifdef TEST_BUILD
[TASK_ID_TEST_RUNNER] = {},
#endif
};
+
+static struct task_ctx_dyn shimmed_tasks_dyn[TASK_ID_COUNT];
+
static int tasks_started;
#undef CROS_EC_TASK
#undef TASK_TEST
task_id_t task_get_current(void)
{
- for (size_t i = 0; i < ARRAY_SIZE(shimmed_tasks); ++i) {
- if (shimmed_tasks[i].zephyr_tid == k_current_get()) {
+ for (size_t i = 0; i < TASK_ID_COUNT; ++i) {
+ if (shimmed_tasks_dyn[i].zephyr_tid == k_current_get())
return i;
- }
}
#if defined(HAS_TASK_HOOKS)
@@ -111,14 +116,14 @@ task_id_t task_get_current(void)
uint32_t *task_get_event_bitmap(task_id_t cros_task_id)
{
- struct task_ctx *const ctx = &shimmed_tasks[cros_task_id];
+ struct task_ctx_dyn *const ctx = &shimmed_tasks_dyn[cros_task_id];
return &ctx->event_mask;
}
uint32_t task_set_event(task_id_t cros_task_id, uint32_t event)
{
- struct task_ctx *const ctx = &shimmed_tasks[cros_task_id];
+ struct task_ctx_dyn *const ctx = &shimmed_tasks_dyn[cros_task_id];
atomic_or(&ctx->event_mask, event);
k_poll_signal_raise(&ctx->new_event, 0);
@@ -128,7 +133,7 @@ uint32_t task_set_event(task_id_t cros_task_id, uint32_t event)
uint32_t task_wait_event(int timeout_us)
{
- struct task_ctx *const ctx = &shimmed_tasks[task_get_current()];
+ struct task_ctx_dyn *const ctx = &shimmed_tasks_dyn[task_get_current()];
const k_timeout_t timeout = (timeout_us == -1) ? K_FOREVER :
K_USEC(timeout_us);
const int64_t tick_deadline =
@@ -170,7 +175,7 @@ uint32_t task_wait_event(int timeout_us)
uint32_t task_wait_event_mask(uint32_t event_mask, int timeout_us)
{
- struct task_ctx *const ctx = &shimmed_tasks[task_get_current()];
+ struct task_ctx_dyn *const ctx = &shimmed_tasks_dyn[task_get_current()];
uint32_t events = 0;
const int64_t tick_deadline =
k_uptime_ticks() + k_us_to_ticks_near64(timeout_us);
@@ -208,20 +213,25 @@ uint32_t task_wait_event_mask(uint32_t event_mask, int timeout_us)
return events & event_mask;
}
-static void task_entry(void *task_contex, void *unused1, void *unused2)
+static void task_entry(void *task_context_static,
+ void *task_context_dyn,
+ void *unused1)
{
+ ARG_UNUSED(task_context_dyn);
ARG_UNUSED(unused1);
- ARG_UNUSED(unused2);
- struct task_ctx *const ctx = (struct task_ctx *)task_contex;
+ struct task_ctx_static *const ctx_static =
+ (struct task_ctx_static *)task_context_static;
#ifdef CONFIG_THREAD_NAME
+ struct task_ctx_dyn *const ctx_dyn =
+ (struct task_ctx_dyn *)task_context_dyn;
/* Name thread for debugging */
- k_thread_name_set(ctx->zephyr_tid, ctx->name);
+ k_thread_name_set(ctx_dyn->zephyr_tid, ctx_static->name);
#endif
/* Call into task entry point */
- ctx->entry((void *)ctx->parameter);
+ ctx_static->entry((void *)ctx_static->parameter);
}
/*
@@ -230,9 +240,9 @@ static void task_entry(void *task_contex, void *unused1, void *unused2)
*/
static void timer_expire(struct k_timer *timer_id)
{
- struct task_ctx *const ctx =
- CONTAINER_OF(timer_id, struct task_ctx, timer);
- task_id_t cros_ec_task_id = ctx - shimmed_tasks;
+ 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;
task_set_event(cros_ec_task_id, TASK_EVENT_TIMER);
}
@@ -240,7 +250,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 *const ctx = &shimmed_tasks[cros_ec_task_id];
+ struct task_ctx_dyn *const ctx = &shimmed_tasks_dyn[cros_ec_task_id];
if (event.val <= now.val) {
/* Timer requested for now or in the past, fire right away */
@@ -258,7 +268,7 @@ int timer_arm(timestamp_t event, task_id_t cros_ec_task_id)
void timer_cancel(task_id_t cros_ec_task_id)
{
- struct task_ctx *const ctx = &shimmed_tasks[cros_ec_task_id];
+ struct task_ctx_dyn *const ctx = &shimmed_tasks_dyn[cros_ec_task_id];
k_timer_stop(&ctx->timer);
}
@@ -266,21 +276,23 @@ void timer_cancel(task_id_t cros_ec_task_id)
#ifdef TEST_BUILD
void set_test_runner_tid(void)
{
- shimmed_tasks[TASK_ID_TEST_RUNNER].zephyr_tid = k_current_get();
+ shimmed_tasks_dyn[TASK_ID_TEST_RUNNER].zephyr_tid = k_current_get();
}
#endif
void start_ec_tasks(void)
{
- for (size_t i = 0; i < ARRAY_SIZE(shimmed_tasks); ++i) {
- struct task_ctx *const ctx = &shimmed_tasks[i];
+ 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];
- k_timer_init(&ctx->timer, timer_expire, NULL);
+ k_timer_init(&ctx_dyn->timer, timer_expire, NULL);
#ifdef TEST_BUILD
/* Do not create thread for test runner; it will be set later */
if (i == TASK_ID_TEST_RUNNER) {
- ctx->zephyr_tid = NULL;
+ ctx_dyn->zephyr_tid = NULL;
continue;
}
#endif
@@ -289,10 +301,17 @@ void start_ec_tasks(void)
* comment in config.h for CONFIG_TASK_LIST for existing flags
* implementation.
*/
- ctx->zephyr_tid = k_thread_create(
- &ctx->zephyr_thread, ctx->stack, ctx->stack_size,
- task_entry, ctx, NULL, NULL,
- K_PRIO_PREEMPT(TASK_ID_COUNT - i - 1), 0, K_NO_WAIT);
+ ctx_dyn->zephyr_tid = k_thread_create(
+ &ctx_dyn->zephyr_thread,
+ ctx_static->stack,
+ ctx_static->stack_size,
+ task_entry,
+ (void *)ctx_static,
+ ctx_dyn,
+ NULL,
+ K_PRIO_PREEMPT(TASK_ID_COUNT - i - 1),
+ 0,
+ K_NO_WAIT);
}
tasks_started = 1;
}
@@ -306,8 +325,8 @@ int init_signals(const struct device *unused)
{
ARG_UNUSED(unused);
- for (size_t i = 0; i < ARRAY_SIZE(shimmed_tasks); ++i) {
- struct task_ctx *const ctx = &shimmed_tasks[i];
+ for (size_t i = 0; i < TASK_ID_COUNT; ++i) {
+ struct task_ctx_dyn *const ctx = &shimmed_tasks_dyn[i];
/* Initialize the new_event structure */
k_poll_signal_init(&ctx->new_event);