From aa9446ca6bec779d1def8d9b06669930d8f7484f Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Wed, 28 Aug 2024 13:51:54 +0800 Subject: [PATCH] shell: modules: kernel: cleanup `thread list` subcmd Parts related to the thread runtime stats are somewhat standalone, refactor it out instead of having two #ifdef and two places. Signed-off-by: Yong Cong Sin Signed-off-by: Yong Cong Sin --- .../modules/kernel_service/thread/list.c | 71 ++++++++++--------- .../modules/kernel_service/thread/thread.c | 2 - .../modules/kernel_service/thread/unwind.c | 2 - 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/subsys/shell/modules/kernel_service/thread/list.c b/subsys/shell/modules/kernel_service/thread/list.c index 655881342e2d34..b0a9304f8d6318 100644 --- a/subsys/shell/modules/kernel_service/thread/list.c +++ b/subsys/shell/modules/kernel_service/thread/list.c @@ -10,43 +10,13 @@ #include #include -static void shell_tdata_dump(const struct k_thread *cthread, void *user_data) -{ - struct k_thread *thread = (struct k_thread *)cthread; - const struct shell *sh = (const struct shell *)user_data; - unsigned int pcnt; - size_t unused; - size_t size = thread->stack_info.size; - const char *tname; - int ret; - char state_str[32]; - #ifdef CONFIG_THREAD_RUNTIME_STATS +static void rt_stats_dump(const struct shell *sh, struct k_thread *thread) +{ k_thread_runtime_stats_t rt_stats_thread; k_thread_runtime_stats_t rt_stats_all; -#endif /* CONFIG_THREAD_RUNTIME_STATS */ - - tname = k_thread_name_get(thread); - - shell_print(sh, "%s%p %-10s", - (thread == k_current_get()) ? "*" : " ", - thread, - tname ? tname : "NA"); - /* Cannot use lld as it's less portable. */ - shell_print(sh, "\toptions: 0x%x, priority: %d timeout: %" PRId64, - thread->base.user_options, - thread->base.prio, - (int64_t)thread->base.timeout.dticks); - shell_print(sh, "\tstate: %s, entry: %p", - k_thread_state_str(thread, state_str, sizeof(state_str)), - thread->entry.pEntry); - -#ifdef CONFIG_SCHED_CPU_MASK - shell_print(sh, "\tcpu_mask: 0x%x", thread->base.cpu_mask); -#endif /* CONFIG_SCHED_CPU_MASK */ - -#ifdef CONFIG_THREAD_RUNTIME_STATS - ret = 0; + int ret = 0; + unsigned int pcnt; if (k_thread_runtime_stats_get(thread, &rt_stats_thread) != 0) { ret++; @@ -86,8 +56,41 @@ static void shell_tdata_dump(const struct k_thread *cthread, void *user_data) shell_print(sh, "\tAverage execution cycles: ?"); #endif /* CONFIG_SCHED_THREAD_USAGE_ANALYSIS */ } +} #endif /* CONFIG_THREAD_RUNTIME_STATS */ +static void shell_tdata_dump(const struct k_thread *cthread, void *user_data) +{ + struct k_thread *thread = (struct k_thread *)cthread; + const struct shell *sh = (const struct shell *)user_data; + unsigned int pcnt; + size_t unused; + size_t size = thread->stack_info.size; + const char *tname; + int ret; + char state_str[32]; + + tname = k_thread_name_get(thread); + + shell_print(sh, "%s%p %-10s", + (thread == k_current_get()) ? "*" : " ", + thread, + tname ? tname : "NA"); + /* Cannot use lld as it's less portable. */ + shell_print(sh, "\toptions: 0x%x, priority: %d timeout: %" PRId64, + thread->base.user_options, + thread->base.prio, + (int64_t)thread->base.timeout.dticks); + shell_print(sh, "\tstate: %s, entry: %p", + k_thread_state_str(thread, state_str, sizeof(state_str)), + thread->entry.pEntry); + +#ifdef CONFIG_SCHED_CPU_MASK + shell_print(sh, "\tcpu_mask: 0x%x", thread->base.cpu_mask); +#endif /* CONFIG_SCHED_CPU_MASK */ + + IF_ENABLED(CONFIG_THREAD_RUNTIME_STATS, (rt_stats_dump(sh, thread))); + ret = k_thread_stack_space_get(thread, &unused); if (ret) { shell_print(sh, diff --git a/subsys/shell/modules/kernel_service/thread/thread.c b/subsys/shell/modules/kernel_service/thread/thread.c index dc9bf6ceec9648..ecc0660138f288 100644 --- a/subsys/shell/modules/kernel_service/thread/thread.c +++ b/subsys/shell/modules/kernel_service/thread/thread.c @@ -1,7 +1,5 @@ /* * Copyright (c) 2024 Meta Platforms - * Copyright (c) 2018 Nordic Semiconductor ASA - * Copyright (c) 2016 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */ diff --git a/subsys/shell/modules/kernel_service/thread/unwind.c b/subsys/shell/modules/kernel_service/thread/unwind.c index e75df2d4864790..903f05822b14a9 100644 --- a/subsys/shell/modules/kernel_service/thread/unwind.c +++ b/subsys/shell/modules/kernel_service/thread/unwind.c @@ -1,7 +1,5 @@ /* * Copyright (c) 2024 Meta Platforms - * Copyright (c) 2018 Nordic Semiconductor ASA - * Copyright (c) 2016 Intel Corporation * * SPDX-License-Identifier: Apache-2.0 */