From 74537fc87aee7efac762e7ee884227af63db9d3a Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Fri, 16 Aug 2024 13:44:24 +0800 Subject: [PATCH] subsys/profiling: SYS_INIT not required The timer & dwork can be statically initialized, SYS_INIT is not strictly required. Signed-off-by: Yong Cong Sin Signed-off-by: Yong Cong Sin --- subsys/profiling/perf/perf.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/subsys/profiling/perf/perf.c b/subsys/profiling/perf/perf.c index 1ce0c0cea75..db6a7bf53dc 100644 --- a/subsys/profiling/perf/perf.c +++ b/subsys/profiling/perf/perf.c @@ -27,7 +27,12 @@ struct perf_data_t { bool buf_full; }; -static struct perf_data_t perf_data; +static void perf_tracer(struct k_timer *timer); +static void perf_dwork_handler(struct k_work *work); +static struct perf_data_t perf_data = { + .timer = Z_TIMER_INITIALIZER(perf_data.timer, perf_tracer, NULL), + .dwork = Z_WORK_DELAYABLE_INITIALIZER(perf_dwork_handler), +}; static void perf_tracer(struct k_timer *timer) { @@ -65,14 +70,6 @@ static void perf_dwork_handler(struct k_work *work) } } -static int perf_init(void) -{ - k_timer_init(&perf_data.timer, perf_tracer, NULL); - k_work_init_delayable(&perf_data.dwork, perf_dwork_handler); - - return 0; -} - static int cmd_perf_record(const struct shell *sh, size_t argc, char **argv) { if (k_work_delayable_is_pending(&perf_data.dwork)) { @@ -157,5 +154,3 @@ SHELL_STATIC_SUBCMD_SET_CREATE(m_sub_perf, SHELL_SUBCMD_SET_END ); SHELL_CMD_ARG_REGISTER(perf, &m_sub_perf, "Lightweight profiler", NULL, 0, 0); - -SYS_INIT(perf_init, APPLICATION, 0);