From 7044b10c88b7e0b840371c32c3517f76778ac356 Mon Sep 17 00:00:00 2001 From: xuxingliang Date: Wed, 28 Aug 2024 16:28:46 +0800 Subject: [PATCH] task: use get_task_name where possible Signed-off-by: xuxingliang --- arch/arm/include/cxd56xx/crashdump.h | 24 ++- arch/risc-v/src/bl602/bl602_start.c | 13 +- arch/risc-v/src/common/riscv_exception.c | 7 +- arch/xtensa/src/common/xtensa_assert.c | 13 +- binfmt/libelf/libelf_coredump.c | 4 +- .../arm/cxd56xx/common/src/cxd56_crashdump.c | 4 +- .../stm32/nucleo-f429zi/src/stm32_bbsram.c | 26 ++-- .../arm/stm32f7/nucleo-144/src/stm32_bbsram.c | 26 ++-- .../rx65n/rx65n-grrose/src/rx65n_sbram.c | 26 ++-- .../rx65n/rx65n-rsk2mb/src/rx65n_sbram.c | 26 ++-- drivers/note/note_driver.c | 1 - drivers/note/notelog_driver.c | 140 +++--------------- drivers/note/noteram_driver.c | 12 +- drivers/segger/note_sysview.c | 6 +- drivers/serial/serial.c | 4 +- drivers/syslog/Kconfig | 1 + drivers/syslog/vsyslog.c | 8 +- fs/procfs/fs_procfsproc.c | 12 +- include/nuttx/sched.h | 8 + libs/libc/gdbstub/lib_gdbstub.c | 10 +- sched/misc/assert.c | 18 +-- sched/sched/sched_dumponexit.c | 4 +- sched/task/task_activate.c | 6 +- sched/task/task_exit.c | 6 +- 24 files changed, 118 insertions(+), 287 deletions(-) diff --git a/arch/arm/include/cxd56xx/crashdump.h b/arch/arm/include/cxd56xx/crashdump.h index 72dd29644b3fc..6bb852aa9d5c6 100644 --- a/arch/arm/include/cxd56xx/crashdump.h +++ b/arch/arm/include/cxd56xx/crashdump.h @@ -100,19 +100,17 @@ typedef enum typedef struct { - struct timespec ts; /* timestamp */ - fault_flags_t flags; /* What is in the dump */ - uintptr_t current_regs; /* Used to validate the dump */ - int lineno; /* __LINE__ to up_assert */ - pid_t pid; /* Process ID */ - uint32_t regs[XCPTCONTEXT_REGS]; /* Interrupt register save area */ - crash_stack_t stacks; /* Stack info */ -#if CONFIG_TASK_NAME_SIZE > 0 - char name[CONFIG_TASK_NAME_SIZE + 1]; /* Task name (with NULL - * terminator) */ -#endif - char filename[MAX_FILE_PATH_LENGTH]; /* the Last of chars in - * __FILE__ to up_assert */ + struct timespec ts; /* timestamp */ + fault_flags_t flags; /* What is in the dump */ + uintptr_t current_regs; /* Used to validate the dump */ + int lineno; /* __LINE__ to up_assert */ + pid_t pid; /* Process ID */ + uint32_t regs[XCPTCONTEXT_REGS]; /* Interrupt register save area */ + crash_stack_t stacks; /* Stack info */ + char name[CONFIG_TASK_NAME_SIZE + 1]; /* Task name (with NULL + * terminator) */ + char filename[MAX_FILE_PATH_LENGTH]; /* the Last of chars in + * __FILE__ to up_assert */ } info_t; typedef struct diff --git a/arch/risc-v/src/bl602/bl602_start.c b/arch/risc-v/src/bl602/bl602_start.c index 104a72bc2f56f..c3ecc556afe89 100644 --- a/arch/risc-v/src/bl602/bl602_start.c +++ b/arch/risc-v/src/bl602/bl602_start.c @@ -99,28 +99,21 @@ __cyg_profile_func_enter(void *this_fn, void *call_site) if (sp < stack_base) { -#if CONFIG_TASK_NAME_SIZE > 0 struct tcb_s *rtcb; -#endif + __asm volatile("csrc mstatus, 8"); __asm__("li s11, 0"); -#if CONFIG_TASK_NAME_SIZE > 0 /* get current task */ rtcb = running_task(); syslog(LOG_EMERG, "task %s stack overflow detected! base:0x%x >= sp:0x%x\n", - rtcb->name, - stack_base, - sp); -#else - syslog(LOG_EMERG, - "stack overflow detected! base:0x%x >= sp:0x%x\n", + get_task_name(rtcb), stack_base, sp); -#endif + /* PANIC(); */ while (1) diff --git a/arch/risc-v/src/common/riscv_exception.c b/arch/risc-v/src/common/riscv_exception.c index e77a3c8ee8bb3..d909203cac677 100644 --- a/arch/risc-v/src/common/riscv_exception.c +++ b/arch/risc-v/src/common/riscv_exception.c @@ -103,11 +103,8 @@ int riscv_exception(int mcause, void *regs, void *args) #ifdef CONFIG_ARCH_KERNEL_STACK if ((tcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_KERNEL) { -# if CONFIG_TASK_NAME_SIZE > 0 - _alert("Segmentation fault in PID %d: %s\n", tcb->pid, tcb->name); -# else - _alert("Segmentation fault in PID %d\n", tcb->pid); -# endif + _alert("Segmentation fault in PID %d: %s\n", + tcb->pid, get_task_name(tcb)); tcb->flags |= TCB_FLAG_FORCED_CANCEL; diff --git a/arch/xtensa/src/common/xtensa_assert.c b/arch/xtensa/src/common/xtensa_assert.c index 54dfebff2dd6a..0b51bd603ac20 100644 --- a/arch/xtensa/src/common/xtensa_assert.c +++ b/arch/xtensa/src/common/xtensa_assert.c @@ -75,11 +75,8 @@ void xtensa_panic(int xptcode, uint32_t *regs) syslog_flush(); -#if CONFIG_TASK_NAME_SIZE > 0 - _alert("Unhandled Exception %d task: %s\n", xptcode, running_task()->name); -#else - _alert("Unhandled Exception %d\n", xptcode); -#endif + _alert("Unhandled Exception %d task: %s\n", xptcode, + get_task_name(running_task())); PANIC_WITH_REGS("panic", regs); /* Should not return */ for (; ; ); @@ -177,12 +174,8 @@ void xtensa_user_panic(int exccause, uint32_t *regs) syslog_flush(); -#if CONFIG_TASK_NAME_SIZE > 0 _alert("User Exception: EXCCAUSE=%04x task: %s\n", - exccause, running_task()->name); -#else - _alert("User Exception: EXCCAUSE=%04x\n", exccause); -#endif + exccause, get_task_name(running_task())); PANIC_WITH_REGS("user panic", regs); /* Should not return */ for (; ; ); diff --git a/binfmt/libelf/libelf_coredump.c b/binfmt/libelf/libelf_coredump.c index 568654b3b5562..a37bbdeada00c 100644 --- a/binfmt/libelf/libelf_coredump.c +++ b/binfmt/libelf/libelf_coredump.c @@ -248,11 +248,11 @@ static void elf_emit_tcb_note(FAR struct elf_dumpinfo_s *cinfo, elf_emit(cinfo, &nhdr, sizeof(nhdr)); - strlcpy(name, tcb->name, sizeof(name)); + strlcpy(name, get_task_name(tcb), sizeof(name)); elf_emit(cinfo, name, sizeof(name)); info.pr_pid = tcb->pid; - strlcpy(info.pr_fname, tcb->name, sizeof(info.pr_fname)); + strlcpy(info.pr_fname, get_task_name(tcb), sizeof(info.pr_fname)); elf_emit(cinfo, &info, sizeof(info)); /* Fill Process status */ diff --git a/boards/arm/cxd56xx/common/src/cxd56_crashdump.c b/boards/arm/cxd56xx/common/src/cxd56_crashdump.c index c3c37a164c93d..38a0a70f313fc 100644 --- a/boards/arm/cxd56xx/common/src/cxd56_crashdump.c +++ b/boards/arm/cxd56xx/common/src/cxd56_crashdump.c @@ -149,9 +149,7 @@ void board_crashdump(uintptr_t sp, struct tcb_s *tcb, /* Save Context */ -#if CONFIG_TASK_NAME_SIZE > 0 - strlcpy(pdump->info.name, tcb->name, sizeof(pdump->info.name)); -#endif + strlcpy(pdump->info.name, get_task_name(tcb), sizeof(pdump->info.name)); pdump->info.pid = tcb->pid; diff --git a/boards/arm/stm32/nucleo-f429zi/src/stm32_bbsram.c b/boards/arm/stm32/nucleo-f429zi/src/stm32_bbsram.c index 9f4c643368f04..982dcca93927d 100644 --- a/boards/arm/stm32/nucleo-f429zi/src/stm32_bbsram.c +++ b/boards/arm/stm32/nucleo-f429zi/src/stm32_bbsram.c @@ -232,18 +232,16 @@ typedef enum typedef struct { - fault_flags_t flags; /* What is in the dump */ - uintptr_t current_regs; /* Used to validate the dump */ - int lineno; /* __LINE__ to up_assert */ - pid_t pid; /* Process ID */ - uint32_t regs[XCPTCONTEXT_REGS]; /* Interrupt register save area */ - stacks_t stacks; /* Stack info */ -#if CONFIG_TASK_NAME_SIZE > 0 - char name[CONFIG_TASK_NAME_SIZE + 1]; /* Task name (with NULL - * terminator) */ -#endif - char filename[MAX_FILE_PATH_LENGTH]; /* the Last of chars in - * __FILE__ to up_assert */ + fault_flags_t flags; /* What is in the dump */ + uintptr_t current_regs; /* Used to validate the dump */ + int lineno; /* __LINE__ to up_assert */ + pid_t pid; /* Process ID */ + uint32_t regs[XCPTCONTEXT_REGS]; /* Interrupt register save area */ + stack_t stacks; /* Stack info */ + char name[CONFIG_TASK_NAME_SIZE + 1]; /* Task name (with NULL + * terminator) */ + char filename[MAX_FILE_PATH_LENGTH]; /* the Last of chars in + * __FILE__ to up_assert */ } info_t; typedef struct @@ -420,9 +418,7 @@ void board_crashdump(uintptr_t sp, struct tcb_s *tcb, /* Save Context */ -#if CONFIG_TASK_NAME_SIZE > 0 - strlcpy(pdump->info.name, tcb->name, sizeof(pdump->info.name)); -#endif + strlcpy(pdump->info.name, get_task_name(tcb), sizeof(pdump->info.name)); pdump->info.pid = tcb->pid; diff --git a/boards/arm/stm32f7/nucleo-144/src/stm32_bbsram.c b/boards/arm/stm32f7/nucleo-144/src/stm32_bbsram.c index 9e11adaaa69be..be29fb27d85b0 100644 --- a/boards/arm/stm32f7/nucleo-144/src/stm32_bbsram.c +++ b/boards/arm/stm32f7/nucleo-144/src/stm32_bbsram.c @@ -232,18 +232,16 @@ typedef enum typedef struct { - fault_flags_t flags; /* What is in the dump */ - uintptr_t current_regs; /* Used to validate the dump */ - int lineno; /* __LINE__ to up_assert */ - int pid; /* Process ID */ - uint32_t regs[XCPTCONTEXT_REGS]; /* Interrupt register save area */ - stacks_t stacks; /* Stack info */ -#if CONFIG_TASK_NAME_SIZE > 0 - char name[CONFIG_TASK_NAME_SIZE + 1]; /* Task name (with NULL - * terminator) */ -#endif - char filename[MAX_FILE_PATH_LENGTH]; /* the Last of chars in - * __FILE__ to up_assert */ + fault_flags_t flags; /* What is in the dump */ + uintptr_t current_regs; /* Used to validate the dump */ + int lineno; /* __LINE__ to up_assert */ + int pid; /* Process ID */ + uint32_t regs[XCPTCONTEXT_REGS]; /* Interrupt register save area */ + stack_t stacks; /* Stack info */ + char name[CONFIG_TASK_NAME_SIZE + 1]; /* Task name (with NULL + * terminator) */ + char filename[MAX_FILE_PATH_LENGTH]; /* the Last of chars in + * __FILE__ to up_assert */ } info_t; typedef struct @@ -420,9 +418,7 @@ void board_crashdump(uintptr_t sp, struct tcb_s *tcb, /* Save Context */ -#if CONFIG_TASK_NAME_SIZE > 0 - strlcpy(pdump->info.name, tcb->name, sizeof(pdump->info.name)); -#endif + strlcpy(pdump->info.name, get_task_name(tcb), sizeof(pdump->info.name)); pdump->info.pid = tcb->pid; diff --git a/boards/renesas/rx65n/rx65n-grrose/src/rx65n_sbram.c b/boards/renesas/rx65n/rx65n-grrose/src/rx65n_sbram.c index 881c785040f5b..601e228567688 100644 --- a/boards/renesas/rx65n/rx65n-grrose/src/rx65n_sbram.c +++ b/boards/renesas/rx65n/rx65n-grrose/src/rx65n_sbram.c @@ -181,18 +181,16 @@ typedef enum typedef struct { - fault_flags_t flags; /* What is in the dump */ - uintptr_t current_regs; /* Used to validate the dump */ - int lineno; /* __LINE__ to up_assert */ - pid_t pid; /* Process ID */ - uint32_t regs[XCPTCONTEXT_REGS]; /* Interrupt register save area */ - stack_t stacks; /* Stack info */ -#if CONFIG_TASK_NAME_SIZE > 0 - char name[CONFIG_TASK_NAME_SIZE + 1]; /* Task name (with NULL - * terminator) */ -#endif - char filename[MAX_FILE_PATH_LENGTH]; /* the Last of chars in - * __FILE__ to up_assert */ + fault_flags_t flags; /* What is in the dump */ + uintptr_t current_regs; /* Used to validate the dump */ + int lineno; /* __LINE__ to up_assert */ + pid_t pid; /* Process ID */ + uint32_t regs[XCPTCONTEXT_REGS]; /* Interrupt register save area */ + stack_t stacks; /* Stack info */ + char name[CONFIG_TASK_NAME_SIZE + 1]; /* Task name (with NULL + * terminator) */ + char filename[MAX_FILE_PATH_LENGTH]; /* the Last of chars in + * __FILE__ to up_assert */ } info_t; struct fullcontext @@ -374,9 +372,7 @@ void board_crashdump(uintptr_t sp, struct tcb_s *tcb, /* Save Context */ -#if CONFIG_TASK_NAME_SIZE > 0 - strlcpy(pdump->info.name, tcb->name, sizeof(pdump->info.name)); -#endif + strlcpy(pdump->info.name, get_task_name(tcb), sizeof(pdump->info.name)); pdump->info.pid = tcb->pid; diff --git a/boards/renesas/rx65n/rx65n-rsk2mb/src/rx65n_sbram.c b/boards/renesas/rx65n/rx65n-rsk2mb/src/rx65n_sbram.c index f5918bb850ceb..1925632a4b220 100644 --- a/boards/renesas/rx65n/rx65n-rsk2mb/src/rx65n_sbram.c +++ b/boards/renesas/rx65n/rx65n-rsk2mb/src/rx65n_sbram.c @@ -181,18 +181,16 @@ typedef enum typedef struct { - fault_flags_t flags; /* What is in the dump */ - uintptr_t current_regs; /* Used to validate the dump */ - int lineno; /* __LINE__ to up_assert */ - pid_t pid; /* Process ID */ - uint32_t regs[XCPTCONTEXT_REGS]; /* Interrupt register save area */ - stack_t stacks; /* Stack info */ -#if CONFIG_TASK_NAME_SIZE > 0 - char name[CONFIG_TASK_NAME_SIZE + 1]; /* Task name (with NULL - * terminator) */ -#endif - char filename[MAX_FILE_PATH_LENGTH]; /* the Last of chars in - * __FILE__ to up_assert */ + fault_flags_t flags; /* What is in the dump */ + uintptr_t current_regs; /* Used to validate the dump */ + int lineno; /* __LINE__ to up_assert */ + pid_t pid; /* Process ID */ + uint32_t regs[XCPTCONTEXT_REGS]; /* Interrupt register save area */ + stack_t stacks; /* Stack info */ + char name[CONFIG_TASK_NAME_SIZE + 1]; /* Task name (with NULL + * terminator) */ + char filename[MAX_FILE_PATH_LENGTH]; /* the Last of chars in + * __FILE__ to up_assert */ } info_t; struct fullcontext @@ -372,9 +370,7 @@ void board_crashdump(uintptr_t sp, struct tcb_s *tcb, /* Save Context */ -#if CONFIG_TASK_NAME_SIZE > 0 - strlcpy(pdump->info.name, tcb->name, sizeof(pdump->info.name)); -#endif + strlcpy(pdump->info.name, get_task_name(tcb), sizeof(pdump->info.name)); pdump->info.pid = tcb->pid; diff --git a/drivers/note/note_driver.c b/drivers/note/note_driver.c index a710c4ee0fb83..cee07d3b9a79b 100644 --- a/drivers/note/note_driver.c +++ b/drivers/note/note_driver.c @@ -2007,4 +2007,3 @@ int note_driver_register(FAR struct note_driver_s *driver) return -ENOMEM; } - diff --git a/drivers/note/notelog_driver.c b/drivers/note/notelog_driver.c index e311e5ec63026..ccce11aee0d7a 100644 --- a/drivers/note/notelog_driver.c +++ b/drivers/note/notelog_driver.c @@ -149,21 +149,11 @@ static void notelog_start(FAR struct note_driver_s *drv, FAR struct tcb_s *tcb) { #ifdef CONFIG_SMP -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "CPU%d: Start %s, TCB@%p, state=%d\n", - tcb->cpu, tcb->name, tcb, tcb->task_state); + tcb->cpu, get_task_name(tcb), tcb, tcb->task_state); #else - syslog(LOG_INFO, "CPU%d: Start TCB@%p, state=%d\n" - tcb->cpu, tcb, tcb->task_state); -#endif -#else -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "Start %s, TCB@%p, state=%d\n", - tcb->name, tcb, tcb->task_state); -#else - syslog(LOG_INFO, "Start TCB@%p, state=%d\n", - tcb, tcb->task_state); -#endif + get_task_name(tcb), tcb, tcb->task_state); #endif } @@ -171,21 +161,11 @@ static void notelog_stop(FAR struct note_driver_s *drv, FAR struct tcb_s *tcb) { #ifdef CONFIG_SMP -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "CPU%d: Stop %s, TCB@%p, state=%d\n", - tcb->cpu, tcb->name, tcb, tcb->task_state); -#else - syslog(LOG_INFO, "CPU%d: Stop TCB@%p, state=%d\n", - tcb->cpu, tcb, tcb->task_state); -#endif + tcb->cpu, get_task_name(tcb), tcb, tcb->task_state); #else -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "Stop %s, TCB@%p, state=%d\n", - tcb->name, tcb, tcb->task_state); -#else - syslog(LOG_INFO, "Stop TCB@%p, state=%d\n", - tcb, tcb->task_state); -#endif + get_task_name(tcb), tcb, tcb->task_state); #endif } @@ -194,21 +174,11 @@ static void notelog_suspend(FAR struct note_driver_s *drv, FAR struct tcb_s *tcb) { #ifdef CONFIG_SMP -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "CPU%d: Suspend %s, TCB@%p, state=%d\n", - tcb->cpu, tcb->name, tcb, tcb->task_state); -#else - syslog(LOG_INFO, "CPU%d: Suspend TCB@%p, state=%d\n", - tcb->cpu, tcb, tcb->task_state); -#endif + tcb->cpu, get_task_name(tcb), tcb, tcb->task_state); #else -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "Suspend %s, TCB@%p, state=%d\n", - tcb->name, tcb, tcb->task_state); -#else - syslog(LOG_INFO, "Suspend TCB@%p, state=%d\n", - tcb, tcb->task_state); -#endif + get_task_name(tcb), tcb, tcb->task_state); #endif } @@ -216,21 +186,11 @@ static void notelog_resume(FAR struct note_driver_s *drv, FAR struct tcb_s *tcb) { #ifdef CONFIG_SMP -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "CPU%d: Resume %s, TCB@%p, state=%d\n", - tcb->cpu, tcb->name, tcb, tcb->task_state); + tcb->cpu, get_task_name(tcb), tcb, tcb->task_state); #else - syslog(LOG_INFO, "CPU%d: Resume TCB@%p, state=%d\n", - tcb->cpu, tcb, tcb->task_state); -#endif -#else -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "Resume %s, TCB@%p, state=%d\n", - tcb->name, tcb, tcb->task_state); -#else - syslog(LOG_INFO, "Resume TCB@%p, state=%d\n", - tcb, tcb->task_state); -#endif + get_task_name(tcb), tcb, tcb->task_state); #endif } #endif @@ -239,74 +199,44 @@ static void notelog_resume(FAR struct note_driver_s *drv, static void notelog_cpu_start(FAR struct note_driver_s *drv, FAR struct tcb_s *tcb, int cpu) { -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "CPU%d: Task %s TCB@%p CPU%d START\n", - tcb->cpu, tcb->name, tcb, cpu); -#else - syslog(LOG_INFO, "CPU%d: TCB@%p CPU%d START\n", - tcb->cpu, tcb, cpu); -#endif + tcb->cpu, get_task_name(tcb), tcb, cpu); } static void notelog_cpu_started(FAR struct note_driver_s *drv, FAR struct tcb_s *tcb) { -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "CPU%d: Task %s TCB@%p CPU%d STARTED\n", - tcb->cpu, tcb->name, tcb, tcb->cpu); -#else - syslog(LOG_INFO, "CPU%d: TCB@%p CPU%d STARTED\n", - tcb->cpu, tcb, tcb->cpu); -#endif + tcb->cpu, get_task_name(tcb), tcb, tcb->cpu); } #ifdef CONFIG_SCHED_INSTRUMENTATION_SWITCH static void notelog_cpu_pause(FAR struct note_driver_s *drv, FAR struct tcb_s *tcb, int cpu) { -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "CPU%d: Task %s TCB@%p CPU%d PAUSE\n", - tcb->cpu, tcb->name, tcb, cpu); -#else - syslog(LOG_INFO, "CPU%d: TCB@%p CPU%d PAUSE\n", - tcb->cpu, tcb, cpu); -#endif + tcb->cpu, get_task_name(tcb), tcb, cpu); } static void notelog_cpu_paused(FAR struct note_driver_s *drv, FAR struct tcb_s *tcb) { -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "CPU%d: Task %s TCB@%p CPU%d PAUSED\n", - tcb->cpu, tcb->name, tcb, tcb->cpu); -#else - syslog(LOG_INFO, "CPU%d: TCB@%p CPU%d PAUSED\n", - tcb->cpu, tcb, tcb->cpu); -#endif + tcb->cpu, get_task_name(tcb), tcb, tcb->cpu); } static void notelog_cpu_resume(FAR struct note_driver_s *drv, FAR struct tcb_s *tcb, int cpu) { -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "CPU%d: Task %s TCB@%p CPU%d RESUME\n", - tcb->cpu, tcb->name, tcb, cpu); -#else - syslog(LOG_INFO, "CPU%d: TCB@%p CPU%d RESUME\n", - tcb->cpu, tcb, cpu); -#endif + tcb->cpu, get_task_name(tcb), tcb, cpu); } static void notelog_cpu_resumed(FAR struct note_driver_s *drv, FAR struct tcb_s *tcb) { -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "CPU%d: Task %s TCB@%p CPU%d RESUMED\n", - tcb->cpu, tcb->name, tcb, tcb->cpu); -#else - syslog(LOG_INFO, "CPU%d: TCB@%p CPU%d RESUMED\n", - tcb->cpu, tcb, tcb->cpu); -#endif + tcb->cpu, get_task_name(tcb), tcb, tcb->cpu); } #endif #endif @@ -316,21 +246,11 @@ static void notelog_premption(FAR struct note_driver_s *drv, FAR struct tcb_s *tcb, bool locked) { #ifdef CONFIG_SMP -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "CPU%d: Task %s TCB@%p preemption %s\n", - tcb->cpu, tcb->name, tcb, locked ? "LOCKED" : "UNLOCKED"); -#else - syslog(LOG_INFO, "CPU%d: TCB@%p preemption %s\n", - tcb->cpu, tcb, locked ? "LOCKED" : "UNLOCKED"); -#endif + tcb->cpu, get_task_name(tcb), tcb, locked ? "LOCKED" : "UNLOCKED"); #else -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "Task %s, TCB@%p preemption %s\n", - tcb->name, tcb, locked ? "LOCKED" : "UNLOCKED"); -#else - syslog(LOG_INFO, "TCB@%p preemption %s\n", - tcb, locked ? "LOCKED" : "UNLOCKED"); -#endif + get_task_name(tcb), tcb, locked ? "LOCKED" : "UNLOCKED"); #endif } #endif @@ -340,21 +260,11 @@ static void notelog_csection(FAR struct note_driver_s *drv, FAR struct tcb_s *tcb, bool enter) { #ifdef CONFIG_SMP -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "CPU%d: Task %s TCB@%p critical section %s\n", - tcb->cpu, tcb->name, tcb, enter ? "ENTER" : "LEAVE"); + tcb->cpu, get_task_name(tcb), tcb, enter ? "ENTER" : "LEAVE"); #else - syslog(LOG_INFO, "CPU%d: TCB@%p critical section %s\n", - tcb->cpu, tcb, enter ? "ENTER" : "LEAVE"); -#endif -#else -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "Task %s, TCB@%p critical section %s\n", - tcb->name, tcb, enter ? "ENTER" : "LEAVE"); -#else - syslog(LOG_INFO, "TCB@%p critical section %s\n", - tcb, enter ? "ENTER" : "LEAVE"); -#endif + get_task_name(tcb), tcb, enter ? "ENTER" : "LEAVE"); #endif } #endif @@ -376,21 +286,11 @@ static void note_spinlock(FAR struct note_driver_s *drv, FAR const char * msg = tmp[type - NOTE_SPINLOCK_LOCK]; #ifdef CONFIG_SMP -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "CPU%d: Task %s TCB@%p spinlock@%p %s\n", - tcb->cpu, tcb->name, tcb, spinlock, msg); -#else - syslog(LOG_INFO, "CPU%d: TCB@%p spinlock@%p %s\n", - tcb->cpu, tcb, spinlock, msg); -#endif + tcb->cpu, get_task_name(tcb), tcb, spinlock, msg); #else -#if CONFIG_TASK_NAME_SIZE > 0 syslog(LOG_INFO, "Task %s TCB@%p spinlock@%p %s\n", - tcb->name, tcb, spinlock, msg); -#else - syslog(LOG_INFO, "TCB@%p spinlock@%p %s\n", - tcb, spinlock, msg); -#endif + get_task_name(tcb), tcb, spinlock, msg); #endif } #endif diff --git a/drivers/note/noteram_driver.c b/drivers/note/noteram_driver.c index 13fcad98d725a..f095445010cd9 100644 --- a/drivers/note/noteram_driver.c +++ b/drivers/note/noteram_driver.c @@ -624,7 +624,7 @@ static void noteram_dump_init_context(FAR struct noteram_dump_context_s *ctx) * Name: get_task_name ****************************************************************************/ -static FAR const char *get_task_name(pid_t pid) +static const char *get_taskname(pid_t pid) { FAR const char *taskname; @@ -658,7 +658,7 @@ static int noteram_dump_header(FAR struct lib_outstream_s *s, #endif ret = lib_sprintf(s, "%8s-%-3u [%d] %3" PRIu32 ".%09" PRIu32 ": ", - get_task_name(pid), get_pid(pid), cpu, sec, nsec); + get_taskname(pid), get_pid(pid), cpu, sec, nsec); return ret; } @@ -694,9 +694,9 @@ static int noteram_dump_sched_switch(FAR struct lib_outstream_s *s, ret = lib_sprintf(s, "sched_switch: prev_comm=%s prev_pid=%u " "prev_prio=%u prev_state=%c ==> " "next_comm=%s next_pid=%u next_prio=%u\n", - get_task_name(current_pid), get_pid(current_pid), + get_taskname(current_pid), get_pid(current_pid), current_priority, get_task_state(cctx->current_state), - get_task_name(next_pid), get_pid(next_pid), + get_taskname(next_pid), get_pid(next_pid), next_priority); cctx->current_pid = cctx->next_pid; @@ -740,7 +740,7 @@ static int noteram_dump_one(FAR uint8_t *p, FAR struct lib_outstream_s *s, ret += noteram_dump_header(s, note, ctx); ret += lib_sprintf(s, "sched_wakeup_new: comm=%s pid=%d " "target_cpu=%d\n", - get_task_name(pid), get_pid(pid), cpu); + get_taskname(pid), get_pid(pid), cpu); } break; @@ -794,7 +794,7 @@ static int noteram_dump_one(FAR uint8_t *p, FAR struct lib_outstream_s *s, ret += noteram_dump_header(s, note, ctx); ret += lib_sprintf(s, "sched_waking: comm=%s " "pid=%d target_cpu=%d\n", - get_task_name(cctx->next_pid), + get_taskname(cctx->next_pid), get_pid(cctx->next_pid), cpu); cctx->pendingswitch = true; } diff --git a/drivers/segger/note_sysview.c b/drivers/segger/note_sysview.c index 24fe2f4c7450c..1b221fff5a19e 100644 --- a/drivers/segger/note_sysview.c +++ b/drivers/segger/note_sysview.c @@ -135,11 +135,7 @@ static void note_sysview_send_taskinfo(FAR struct tcb_s *tcb) SEGGER_SYSVIEW_TASKINFO info; info.TaskID = tcb->pid; -#if CONFIG_TASK_NAME_SIZE > 0 - info.sName = tcb->name; -#else - info.sName = ""; -#endif + info.sName = get_task_name(tcb); info.Prio = tcb->sched_priority; info.StackBase = (uintptr_t)tcb->stack_base_ptr; info.StackSize = tcb->adj_stack_size; diff --git a/drivers/serial/serial.c b/drivers/serial/serial.c index 5d48239cab985..9f8fb2a3ffc63 100644 --- a/drivers/serial/serial.c +++ b/drivers/serial/serial.c @@ -1804,9 +1804,9 @@ static int uart_unlink(FAR struct inode *inode) static void uart_launch_foreach(FAR struct tcb_s *tcb, FAR void *arg) { #ifdef CONFIG_TTY_LAUNCH_ENTRY - if (!strcmp(tcb->name, CONFIG_TTY_LAUNCH_ENTRYNAME)) + if (!strcmp(get_task_name(tcb), CONFIG_TTY_LAUNCH_ENTRYNAME)) #else - if (!strcmp(tcb->name, CONFIG_TTY_LAUNCH_FILEPATH)) + if (!strcmp(get_task_name(tcb), CONFIG_TTY_LAUNCH_FILEPATH)) #endif { *(FAR int *)arg = 1; diff --git a/drivers/syslog/Kconfig b/drivers/syslog/Kconfig index 372f5b68b717d..88500531f3f73 100644 --- a/drivers/syslog/Kconfig +++ b/drivers/syslog/Kconfig @@ -153,6 +153,7 @@ config SYSLOG_PRIORITY config SYSLOG_PROCESS_NAME bool "Prepend process name to syslog message" default n + depends on TASK_NAME_SIZE > 0 ---help--- Prepend Process name to syslog message. diff --git a/drivers/syslog/vsyslog.c b/drivers/syslog/vsyslog.c index a51c31e2a3625..9ce1ab2fc480b 100644 --- a/drivers/syslog/vsyslog.c +++ b/drivers/syslog/vsyslog.c @@ -83,7 +83,7 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap) { struct lib_syslograwstream_s stream; int ret = 0; -#if CONFIG_TASK_NAME_SIZE > 0 && defined(CONFIG_SYSLOG_PROCESS_NAME) +#ifdef CONFIG_SYSLOG_PROCESS_NAME FAR struct tcb_s *tcb = nxsched_get_tcb(nxsched_gettid()); #endif #ifdef CONFIG_SYSLOG_TIMESTAMP @@ -196,7 +196,7 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap) "[%s] " #endif -#if CONFIG_TASK_NAME_SIZE > 0 && defined(CONFIG_SYSLOG_PROCESS_NAME) +#ifdef CONFIG_SYSLOG_PROCESS_NAME /* Prepend the thread name */ "%s: " @@ -242,10 +242,10 @@ int nx_vsyslog(int priority, FAR const IPTR char *fmt, FAR va_list *ap) , CONFIG_SYSLOG_PREFIX_STRING #endif -#if CONFIG_TASK_NAME_SIZE > 0 && defined(CONFIG_SYSLOG_PROCESS_NAME) +#ifdef CONFIG_SYSLOG_PROCESS_NAME /* Prepend the thread name */ - , tcb != NULL ? tcb->name : "(null)" + , get_task_name(tcb) #endif ); diff --git a/fs/procfs/fs_procfsproc.c b/fs/procfs/fs_procfsproc.c index 695f60c2808c1..e84f7311165dd 100644 --- a/fs/procfs/fs_procfsproc.c +++ b/fs/procfs/fs_procfsproc.c @@ -486,11 +486,7 @@ static ssize_t proc_status(FAR struct proc_file_s *procfile, /* Show the task name */ -#if CONFIG_TASK_NAME_SIZE > 0 - name = tcb->name; -#else - name = ""; -#endif + name = get_task_name(tcb); linesize = procfs_snprintf(procfile->line, STATUS_LINELEN, "%-12s%.18s\n", "Name:", name); copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining, @@ -670,11 +666,7 @@ static ssize_t proc_cmdline(FAR struct proc_file_s *procfile, /* Show the task name */ -#if CONFIG_TASK_NAME_SIZE > 0 - name = tcb->name; -#else - name = ""; -#endif + name = get_task_name(tcb); linesize = strlen(name); memcpy(procfile->line, name, linesize); copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining, diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h index e607802bb6aca..728262352c667 100644 --- a/include/nuttx/sched.h +++ b/include/nuttx/sched.h @@ -222,6 +222,14 @@ #define get_current_mm() (get_group_mm(nxsched_self()->group)) +/* Get task name from tcb */ + +#if CONFIG_TASK_NAME_SIZE > 0 +# define get_task_name(tcb) ((tcb)->name) +#else +# define get_task_name(tcb) "" +#endif + /* These are macros to access the current CPU and the current task on a CPU. * These macros are intended to support a future SMP implementation. */ diff --git a/libs/libc/gdbstub/lib_gdbstub.c b/libs/libc/gdbstub/lib_gdbstub.c index b97d6486b8ec1..32cda12c8b149 100644 --- a/libs/libc/gdbstub/lib_gdbstub.c +++ b/libs/libc/gdbstub/lib_gdbstub.c @@ -1251,17 +1251,10 @@ static int gdb_query(FAR struct gdb_state_s *state) } nxsched_get_stateinfo(tcb, thread_state, sizeof(thread_state)); -#if CONFIG_TASK_NAME_SIZE > 0 snprintf(thread_info, sizeof(thread_info), "Name: %s, State: %s, Priority: %d, Stack: %zu", - tcb->name, thread_state, tcb->sched_priority, + get_task_name(tcb), thread_state, tcb->sched_priority, tcb->adj_stack_size); -#else - snprintf(thread_info, sizeof(thread_info), - "State: %s, Priority: %d, Stack: %zu", - thread_state, tcb->sched_priority, - tcb->adj_stack_size); -#endif ret = gdb_bin2hex(state->pkt_buf, sizeof(state->pkt_buf), thread_info, strlen(thread_info)); @@ -1968,4 +1961,3 @@ int gdb_process(FAR struct gdb_state_s *state, int stopreason, state->last_stopaddr = stopaddr; return ret; } - diff --git a/sched/misc/assert.c b/sched/misc/assert.c index 7e6fd98ed3317..506d70ef98e29 100644 --- a/sched/misc/assert.c +++ b/sched/misc/assert.c @@ -415,11 +415,7 @@ static void dump_task(FAR struct tcb_s *tcb, FAR void *arg) #ifndef CONFIG_SCHED_CPULOAD_NONE , intpart, fracpart #endif -#if CONFIG_TASK_NAME_SIZE > 0 - , tcb->name -#else - , "" -#endif + , get_task_name(tcb) , args ); } @@ -630,18 +626,14 @@ static void dump_assert_info(FAR struct tcb_s *rtcb, FAR const char *filename, int linenum, FAR const char *msg, FAR void *regs) { -#if CONFIG_TASK_NAME_SIZE > 0 FAR struct tcb_s *ptcb = NULL; -#endif struct utsname name; -#if CONFIG_TASK_NAME_SIZE > 0 if (rtcb->group && (rtcb->flags & TCB_FLAG_TTYPE_MASK) != TCB_FLAG_TTYPE_KERNEL) { ptcb = nxsched_get_tcb(rtcb->group->tg_pid); } -#endif uname(&name); _alert("Current Version: %s %s %s %s %s\n", @@ -653,20 +645,16 @@ static void dump_assert_info(FAR struct tcb_s *rtcb, "(CPU%d)" #endif ": " -#if CONFIG_TASK_NAME_SIZE > 0 "%s " "process: %s " -#endif "%p\n", msg ? msg : "", filename ? filename : "", linenum, #ifdef CONFIG_SMP this_cpu(), #endif -#if CONFIG_TASK_NAME_SIZE > 0 - rtcb->name, - ptcb ? ptcb->name : "Kernel", -#endif + get_task_name(rtcb), + ptcb ? get_task_name(ptcb) : "Kernel", rtcb->entry.main); /* Dump current CPU registers, running task stack and backtrace. */ diff --git a/sched/sched/sched_dumponexit.c b/sched/sched/sched_dumponexit.c index 2fde136e338ee..aece6501c06ef 100644 --- a/sched/sched/sched_dumponexit.c +++ b/sched/sched/sched_dumponexit.c @@ -57,8 +57,8 @@ static void dumphandler(FAR struct tcb_s *tcb, FAR void *arg) syslog(LOG_INFO, "tcb=%p name=%s, pid:%d, priority=%d state=%d " "stack_alloc_ptr: %p, adj_stack_size: %zu\n", - tcb, tcb->name, tcb->pid, tcb->sched_priority, tcb->task_state, - tcb->stack_alloc_ptr, tcb->adj_stack_size); + tcb, get_task_name(tcb), tcb->pid, tcb->sched_priority, + tcb->task_state, tcb->stack_alloc_ptr, tcb->adj_stack_size); filelist = &tcb->group->tg_filelist; files_dumplist(filelist); diff --git a/sched/task/task_activate.c b/sched/task/task_activate.c index 00aa1c2e55777..1fcba2695e90d 100644 --- a/sched/task/task_activate.c +++ b/sched/task/task_activate.c @@ -86,11 +86,7 @@ void nxtask_activate(FAR struct tcb_s *tcb) nxsched_remove_blocked(tcb); -#if CONFIG_TASK_NAME_SIZE > 0 - sinfo("%s pid=%d,TCB=%p\n", tcb->name, -#else - sinfo("pid=%d,TCB=%p\n", -#endif + sinfo("%s pid=%d,TCB=%p\n", get_task_name(tcb), tcb->pid, tcb); /* Add the task to ready-to-run task list, and diff --git a/sched/task/task_exit.c b/sched/task/task_exit.c index 3dc03fa41e1d8..4dcd19e48a3af 100644 --- a/sched/task/task_exit.c +++ b/sched/task/task_exit.c @@ -91,11 +91,7 @@ int nxtask_exit(void) dtcb = this_task(); #endif -#if CONFIG_TASK_NAME_SIZE > 0 - sinfo("%s pid=%d,TCB=%p\n", dtcb->name, -#else - sinfo("pid=%d,TCB=%p\n", -#endif + sinfo("%s pid=%d,TCB=%p\n", get_task_name(dtcb), dtcb->pid, dtcb); /* Update scheduler parameters */