From 01cb5540bd7b391f9a19c79b284fdfc4385afc06 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Tue, 12 Apr 2016 07:31:01 +0200 Subject: shell: Add CPUINFO command Update #2723. --- cpukit/libmisc/Makefile.am | 2 + cpukit/libmisc/cpuuse/cpuinforeport.c | 86 +++++++++++++++++++++++++++++++++++ cpukit/libmisc/cpuuse/cpuuse.h | 7 +++ cpukit/libmisc/shell/main_cpuinfo.c | 38 ++++++++++++++++ cpukit/libmisc/shell/shellconfig.h | 6 +++ 5 files changed, 139 insertions(+) create mode 100644 cpukit/libmisc/cpuuse/cpuinforeport.c create mode 100644 cpukit/libmisc/shell/main_cpuinfo.c (limited to 'cpukit/libmisc') diff --git a/cpukit/libmisc/Makefile.am b/cpukit/libmisc/Makefile.am index 9cd52ea5ef..a50de9426d 100644 --- a/cpukit/libmisc/Makefile.am +++ b/cpukit/libmisc/Makefile.am @@ -30,6 +30,7 @@ EXTRA_DIST += cpuuse/README noinst_LIBRARIES += libcpuuse.a libcpuuse_a_SOURCES = cpuuse/cpuusagereport.c cpuuse/cpuusagereset.c \ cpuuse/cpuuse.h cpuuse/cpuusagedata.c cpuuse/cpuusagetop.c +libcpuuse_a_SOURCES += cpuuse/cpuinforeport.c ## devnull noinst_LIBRARIES += libdevnull.a @@ -114,6 +115,7 @@ libshell_a_SOURCES = shell/cat_file.c shell/cmds.c shell/internal.h \ libshell_a_SOURCES += shell/main_cmdls.c libshell_a_SOURCES += shell/main_cmdchown.c libshell_a_SOURCES += shell/main_cmdchmod.c +libshell_a_SOURCES += shell/main_cpuinfo.c libshell_a_SOURCES += shell/main_profreport.c if LIBDRVMGR diff --git a/cpukit/libmisc/cpuuse/cpuinforeport.c b/cpukit/libmisc/cpuuse/cpuinforeport.c new file mode 100644 index 0000000000..389a26c174 --- /dev/null +++ b/cpukit/libmisc/cpuuse/cpuinforeport.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2016 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * 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 + +#include +#include + +#include + +static char bits_to_char( uint8_t bits ) +{ + return isprint( bits ) ? (char) bits : '?'; +} + +static void name_to_str( uint32_t name, char str[ 5 ] ) +{ + str[ 0 ] = bits_to_char( (uint8_t) ( name >> 24 ) ); + str[ 1 ] = bits_to_char( (uint8_t) ( name >> 16 ) ); + str[ 2 ] = bits_to_char( (uint8_t) ( name >> 8 ) ); + str[ 3 ] = bits_to_char( (uint8_t) ( name >> 0 ) ); + str[ 4 ] = '\0'; +} + +int rtems_cpu_info_report( const rtems_printer *printer ) +{ + uint32_t cpu_max; + uint32_t cpu_index; + int n; + + cpu_max = rtems_configuration_get_maximum_processors(); + + n = rtems_printf( + printer, + "-------------------------------------------------------------------------------\n" + " PER PROCESSOR INFORMATION\n" + "-------+--------+--------------+-----------------------------------------------\n" + " INDEX | ONLINE | SCHEDULER ID | SCHEDULER NAME\n" + "-------+--------+--------------+-----------------------------------------------\n" + ); + + for ( cpu_index = 0; cpu_index < cpu_max; ++cpu_index ) { + const Per_CPU_Control *cpu; + const Scheduler_Control *scheduler; + char scheduler_str[ 5 ]; + uint32_t scheduler_id; + + cpu = _Per_CPU_Get_by_index( cpu_index ); + scheduler = _Scheduler_Get_by_CPU( cpu ); + + if ( scheduler != NULL ) { + scheduler_id = _Scheduler_Build_id( _Scheduler_Get_index( scheduler ) ); + name_to_str( scheduler->name, scheduler_str ); + } else { + scheduler_id = 0; + scheduler_str[ 0 ] = '\0'; + } + + n += rtems_printf( + printer, + " %5" PRIu32 " | %6i | 0x%08" PRIx32 " | %s\n", + cpu_index, + _Per_CPU_Is_processor_online( cpu ), + scheduler_id, + &scheduler_str[ 0 ] + ); + } + + return n; +} diff --git a/cpukit/libmisc/cpuuse/cpuuse.h b/cpukit/libmisc/cpuuse/cpuuse.h index 55777186f8..23f58faf1b 100644 --- a/cpukit/libmisc/cpuuse/cpuuse.h +++ b/cpukit/libmisc/cpuuse/cpuuse.h @@ -73,6 +73,13 @@ void rtems_cpu_usage_top( void ); void rtems_cpu_usage_reset( void ); +/** + * @brief Reports per-processor information. + * + * @return The number of characters printed. + */ +int rtems_cpu_info_report( const rtems_printer *printer ); + #ifdef __cplusplus } #endif diff --git a/cpukit/libmisc/shell/main_cpuinfo.c b/cpukit/libmisc/shell/main_cpuinfo.c new file mode 100644 index 0000000000..c5bc9a3f3f --- /dev/null +++ b/cpukit/libmisc/shell/main_cpuinfo.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Dornierstr. 4 + * 82178 Puchheim + * Germany + * + * + * 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 +#include + +static int rtems_shell_main_cpuinfo(int argc, char **argv) +{ + rtems_printer printer; + + rtems_print_printer_fprintf(&printer, stdout); + rtems_cpu_info_report(&printer); + + return 0; +} + +rtems_shell_cmd_t rtems_shell_CPUINFO_Command = { + .name = "cpuinfo", + .usage = "cpuinfo", + .topic = "rtems", + .command = rtems_shell_main_cpuinfo +}; diff --git a/cpukit/libmisc/shell/shellconfig.h b/cpukit/libmisc/shell/shellconfig.h index 5e4f03f8fa..9f68b313fb 100644 --- a/cpukit/libmisc/shell/shellconfig.h +++ b/cpukit/libmisc/shell/shellconfig.h @@ -80,6 +80,7 @@ extern rtems_shell_cmd_t rtems_shell_MD5_Command; extern rtems_shell_cmd_t rtems_shell_RTC_Command; extern rtems_shell_cmd_t rtems_shell_SHUTDOWN_Command; +extern rtems_shell_cmd_t rtems_shell_CPUINFO_Command; extern rtems_shell_cmd_t rtems_shell_CPUUSE_Command; extern rtems_shell_cmd_t rtems_shell_TOP_Command; extern rtems_shell_cmd_t rtems_shell_STACKUSE_Command; @@ -430,6 +431,11 @@ extern rtems_shell_alias_t * const rtems_shell_Initial_aliases[]; defined(CONFIGURE_SHELL_COMMAND_SHUTDOWN) &rtems_shell_SHUTDOWN_Command, #endif + #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \ + !defined(CONFIGURE_SHELL_NO_COMMAND_CPUINFO)) || \ + defined(CONFIGURE_SHELL_COMMAND_CPUINFO) + &rtems_shell_CPUINFO_Command, + #endif #if (defined(CONFIGURE_SHELL_COMMANDS_ALL) && \ !defined(CONFIGURE_SHELL_NO_COMMAND_CPUUSE)) || \ defined(CONFIGURE_SHELL_COMMAND_CPUUSE) -- cgit v1.2.3