Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:18

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  * Copyright (c) 2016 embedded brains GmbH & Co. KG
0005  *
0006  * Redistribution and use in source and binary forms, with or without
0007  * modification, are permitted provided that the following conditions
0008  * are met:
0009  * 1. Redistributions of source code must retain the above copyright
0010  *    notice, this list of conditions and the following disclaimer.
0011  * 2. Redistributions in binary form must reproduce the above copyright
0012  *    notice, this list of conditions and the following disclaimer in the
0013  *    documentation and/or other materials provided with the distribution.
0014  *
0015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0016  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0017  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0018  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0019  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0020  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0021  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0024  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0025  * POSSIBILITY OF SUCH DAMAGE.
0026  */
0027 
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031 
0032 #include <rtems/cpuuse.h>
0033 #include <rtems/print.h>
0034 
0035 #include <ctype.h>
0036 #include <inttypes.h>
0037 
0038 #include <rtems/score/schedulerimpl.h>
0039 
0040 static char bits_to_char( uint8_t bits )
0041 {
0042   return isprint( bits ) ? (char) bits : '?';
0043 }
0044 
0045 static void name_to_str( uint32_t name, char str[ 5 ] )
0046 {
0047   str[ 0 ] = bits_to_char( (uint8_t) ( name >> 24 ) );
0048   str[ 1 ] = bits_to_char( (uint8_t) ( name >> 16 ) );
0049   str[ 2 ] = bits_to_char( (uint8_t) ( name >> 8 ) );
0050   str[ 3 ] = bits_to_char( (uint8_t) ( name >> 0 ) );
0051   str[ 4 ] = '\0';
0052 }
0053 
0054 int rtems_cpu_info_report( const rtems_printer *printer )
0055 {
0056   uint32_t cpu_max;
0057   uint32_t cpu_index;
0058   int      n;
0059 
0060   cpu_max = rtems_configuration_get_maximum_processors();
0061 
0062   n = rtems_printf(
0063     printer,
0064      "-------------------------------------------------------------------------------\n"
0065      "                            PER PROCESSOR INFORMATION\n"
0066      "-------+--------+--------------+-----------------------------------------------\n"
0067      " INDEX | ONLINE | SCHEDULER ID | SCHEDULER NAME\n"
0068      "-------+--------+--------------+-----------------------------------------------\n"
0069    );
0070 
0071   for ( cpu_index = 0; cpu_index < cpu_max; ++cpu_index ) {
0072     const Per_CPU_Control *cpu;
0073     const Scheduler_Control *scheduler;
0074     char scheduler_str[ 5 ];
0075     uint32_t scheduler_id;
0076 
0077     cpu = _Per_CPU_Get_by_index( cpu_index );
0078     scheduler = _Scheduler_Get_by_CPU( cpu );
0079 
0080     if ( scheduler != NULL ) {
0081       scheduler_id = _Scheduler_Build_id( _Scheduler_Get_index( scheduler ) );
0082       name_to_str( scheduler->name, scheduler_str );
0083     } else {
0084       scheduler_id = 0;
0085       scheduler_str[ 0 ] = '\0';
0086     }
0087 
0088     n += rtems_printf(
0089       printer,
0090       " %5" PRIu32 " | %6i |   0x%08" PRIx32 " | %s\n",
0091       cpu_index,
0092       _Per_CPU_Is_processor_online( cpu ),
0093       scheduler_id,
0094       &scheduler_str[ 0 ]
0095     );
0096   }
0097 
0098   return n;
0099 }