Skip to content

Commit

Permalink
shell: modules: kernel: cleanup thread list subcmd
Browse files Browse the repository at this point in the history
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 <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
  • Loading branch information
ycsin authored and nashif committed Sep 18, 2024
1 parent 8321214 commit aa9446c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 38 deletions.
71 changes: 37 additions & 34 deletions subsys/shell/modules/kernel_service/thread/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,13 @@
#include <zephyr/drivers/timer/system_timer.h>
#include <zephyr/kernel.h>

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++;
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions subsys/shell/modules/kernel_service/thread/thread.c
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down
2 changes: 0 additions & 2 deletions subsys/shell/modules/kernel_service/thread/unwind.c
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down

0 comments on commit aa9446c

Please sign in to comment.