From 7ced9d9bb2fd51cfef2ce33d22e779adfed604c2 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 12 Jan 2017 09:25:56 +0100 Subject: score: Add and use _Thread_Get_name() Update #2858. --- cpukit/libmisc/cpuuse/cpuusagereport.c | 4 +- cpukit/libmisc/monitor/mon-task.c | 8 +++- cpukit/libmisc/monitor/monitor.h | 1 + cpukit/libmisc/stackchk/check.c | 60 ++++++++++++--------------- cpukit/score/Makefile.am | 1 + cpukit/score/include/rtems/score/threadimpl.h | 8 +++- cpukit/score/src/threadname.c | 37 +++++++++++++++++ 7 files changed, 82 insertions(+), 37 deletions(-) create mode 100644 cpukit/score/src/threadname.c diff --git a/cpukit/libmisc/cpuuse/cpuusagereport.c b/cpukit/libmisc/cpuuse/cpuusagereport.c index 1049296cbd..2a01a8aa3d 100644 --- a/cpukit/libmisc/cpuuse/cpuusagereport.c +++ b/cpukit/libmisc/cpuuse/cpuusagereport.c @@ -40,7 +40,7 @@ typedef struct { static bool cpu_usage_visitor( Thread_Control *the_thread, void *arg ) { cpu_usage_context *ctx; - char name[ 13 ]; + char name[ 38 ]; uint32_t ival; uint32_t fval; Timestamp_Control uptime; @@ -49,7 +49,7 @@ static bool cpu_usage_visitor( Thread_Control *the_thread, void *arg ) uint32_t nanoseconds; ctx = arg; - rtems_object_get_name( the_thread->Object.id, sizeof( name ), name ); + _Thread_Get_name( the_thread, name, sizeof( name ) ); _Thread_Get_CPU_time_used( the_thread, &used ); _TOD_Get_uptime( &uptime ); diff --git a/cpukit/libmisc/monitor/mon-task.c b/cpukit/libmisc/monitor/mon-task.c index fadf51d4b0..5e948c13a7 100644 --- a/cpukit/libmisc/monitor/mon-task.c +++ b/cpukit/libmisc/monitor/mon-task.c @@ -47,6 +47,12 @@ rtems_monitor_task_canonical( api = rtems_thread->API_Extensions[ THREAD_API_RTEMS ]; + _Thread_Get_name( + rtems_thread, + canonical_task->name_string, + sizeof( canonical_task->name_string ) + ); + rtems_monitor_task_wait_info( canonical_task, rtems_thread ); canonical_task->entry = rtems_thread->Start.Entry; @@ -97,7 +103,7 @@ rtems_monitor_task_dump( length += rtems_monitor_dump_id(monitor_task->id); length += rtems_monitor_pad(11, length); - length += rtems_monitor_dump_name(monitor_task->id); + length += fprintf(stdout, "%s", monitor_task->name_string); length += rtems_monitor_pad(21, length); length += rtems_monitor_dump_decimal(monitor_task->cpu); length += rtems_monitor_pad(26, length); diff --git a/cpukit/libmisc/monitor/monitor.h b/cpukit/libmisc/monitor/monitor.h index e2575cc931..a1113649b0 100644 --- a/cpukit/libmisc/monitor/monitor.h +++ b/cpukit/libmisc/monitor/monitor.h @@ -95,6 +95,7 @@ typedef struct { rtems_id id; rtems_name name; /* end of common portion */ + char name_string[10]; Thread_Entry_information entry; void *stack; uint32_t stack_size; diff --git a/cpukit/libmisc/stackchk/check.c b/cpukit/libmisc/stackchk/check.c index b054e78eee..afc276165f 100644 --- a/cpukit/libmisc/stackchk/check.c +++ b/cpukit/libmisc/stackchk/check.c @@ -43,6 +43,7 @@ #include #include #include +#include /* * This structure is used to fill in and compare the "end of stack" @@ -238,10 +239,8 @@ static void Stack_check_report_blown_task( "task name: 0x%08" PRIx32 "\n", running->Object.name.name_u32 ); - printk( - "task name string: %s\n", - rtems_object_get_name(running->Object.id, sizeof(name), name) - ); + _Thread_Get_name(running, name, sizeof(name)); + printk("task name string: %s\n", name); printk( "task stack area (%lu Bytes): 0x%08" PRIxPTR " .. 0x%08" PRIxPTR "\n", (unsigned long) stack->size, @@ -362,8 +361,9 @@ static bool Stack_check_Dump_threads_usage( void *high_water_mark; void *current; Stack_Control *stack; - char name[5]; + char name[ 22 ]; const rtems_printer *printer; + uint32_t id; printer = arg; @@ -394,37 +394,32 @@ static bool Stack_check_Dump_threads_usage( else used = 0; - - #if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE) - if ( the_thread ) - #endif - { - rtems_printf( - printer, - "0x%08" PRIx32 " %4s", - the_thread->Object.id, - rtems_object_get_name( the_thread->Object.id, sizeof(name), name ) - ); - } - #if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE) - else { - rtems_printf( printer, "0x%08x INTR", ~0 ); - } - #endif +#if (CPU_ALLOCATE_INTERRUPT_STACK == TRUE) + if ( the_thread == NULL ) { + id = 0xffffffff; + strlcpy( name, "INTR", sizeof( name ) ); + } else +#endif + { + id = the_thread->Object.id; + _Thread_Get_name( the_thread, name, sizeof( name ) ); + } rtems_printf( printer, - " %p - %p %p %8" PRId32 " ", - stack->area, - stack->area + stack->size - 1, - current, + "0x%08" PRIx32 " %-21s 0x%08" PRIuPTR " 0x%08" PRIuPTR " 0x%08" PRIuPTR " %6" PRId32 " ", + id, + name, + (uintptr_t) stack->area, + (uintptr_t) stack->area + (uintptr_t) stack->size - 1, + (uintptr_t) current, size ); if (Stack_check_Initialized == 0) { - rtems_printf( printer, "Unavailable\n" ); + rtems_printf( printer, "N/A\n" ); } else { - rtems_printf( printer, "%8" PRId32 "\n", used ); + rtems_printf( printer, "%6" PRId32 "\n", used ); } return false; @@ -453,9 +448,10 @@ void rtems_stack_checker_report_usage_with_plugin( const rtems_printer* printer ) { - rtems_printf( printer, "Stack usage by thread\n"); - rtems_printf( printer, -" ID NAME LOW HIGH CURRENT AVAILABLE USED\n" + rtems_printf( + printer, + " STACK USAGE BY THREAD\n" + "ID NAME LOW HIGH CURRENT AVAIL USED\n" ); /* iterate over all threads and dump the usage */ @@ -471,8 +467,6 @@ void rtems_stack_checker_report_usage_with_plugin( RTEMS_DECONST( rtems_printer *, printer ) ); #endif - - printer = NULL; } void rtems_stack_checker_report_usage( void ) diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am index 9b376c3f06..953f1eb195 100644 --- a/cpukit/score/Makefile.am +++ b/cpukit/score/Makefile.am @@ -299,6 +299,7 @@ libscore_a_SOURCES += src/threadentryadaptorpointer.c libscore_a_SOURCES += src/threadgetcputimeused.c libscore_a_SOURCES += src/threadglobalconstruction.c libscore_a_SOURCES += src/threaditerate.c +libscore_a_SOURCES += src/threadname.c libscore_a_SOURCES += src/threadscheduler.c libscore_a_SOURCES += src/threadtimeout.c libscore_a_SOURCES += src/threadwaitgetid.c diff --git a/cpukit/score/include/rtems/score/threadimpl.h b/cpukit/score/include/rtems/score/threadimpl.h index f131bbd506..cb9e8e6539 100644 --- a/cpukit/score/include/rtems/score/threadimpl.h +++ b/cpukit/score/include/rtems/score/threadimpl.h @@ -11,7 +11,7 @@ * COPYRIGHT (c) 1989-2008. * On-Line Applications Research Corporation (OAR). * - * Copyright (c) 2014, 2016 embedded brains GmbH. + * Copyright (c) 2014, 2017 embedded brains GmbH. * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at @@ -1951,6 +1951,12 @@ RTEMS_INLINE_ROUTINE void _Thread_Remove_timer_and_unblock( #endif } +size_t _Thread_Get_name( + const Thread_Control *the_thread, + char *buffer, + size_t buffer_size +); + /** @}*/ #ifdef __cplusplus diff --git a/cpukit/score/src/threadname.c b/cpukit/score/src/threadname.c new file mode 100644 index 0000000000..6e4ffa4044 --- /dev/null +++ b/cpukit/score/src/threadname.c @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2017 embedded brains GmbH. + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include + +size_t _Thread_Get_name( + const Thread_Control *the_thread, + char *buffer, + size_t buffer_size +) +{ + const char *name; + + name = the_thread->Join_queue.Queue.name; + + if ( name != NULL && name[ 0 ] != '\0' ) { + return strlcpy( buffer, name, buffer_size ); + } else { + return _Objects_Name_to_string( + the_thread->Object.name, + false, + buffer, + buffer_size + ); + } +} -- cgit v1.2.3