xilinx_zynq_zedboard cpu_idle_report implementation

Giovanni Macciocu G.Macciocu at sron.nl
Wed Jan 8 14:53:41 UTC 2014


Hi All,

details:

Rtems head: 7 Jan. 2014
BSP: xilinx_zynq_zedboard
Goal: cpu_idle_report_implementation

I'm adjusting a piece of code we've used succesfully with rtems 4.9 and rtems 4.10 in combination with the Sparc BSP (Leon processor).
This code is used to measure the idle time of the processor.
I'm adjusting this code in order to be used with the recent rtems head of 7 Jan. 2014 and the BSP of the xilinx_zynq_zedboard

I've added the following include 
#include <rtems/score/objectimpl.h>
in order to access the 'Object_Information' object

The only problem I'm still having is that I cannot find an equal implementation of '_Thread_Idle'
in rtems 4.9 and 4.10 (sparc bsp) this is implemented at line 435 of sparc-rtems4.10/include/rtems/score/thread.h (SCORE_EXTERN Thread_Control *Thread_Idle;)
however in 4.11 with the xilinx_zynq_zedboard bsp I cannot find a similar implementation.

file: rtems/cpukit/libmisc/cpuuse/cpuidlereport.c

// CPU Usage Reporter

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <rtems.h>

#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <inttypes.h>

#include <rtems/cpuuse.h>
#include <rtems/bspIo.h>

// added this in v4.11 in order to acces 'Objects_Information'
#include <rtems/score/objectimpl.h>

#if defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
#include <rtems/score/timespec.h>
#endif

#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
extern struct timespec    CPU_usage_Uptime_at_last_reset;
#endif

uint32_t rtems_cpu_idle_report( void ) 
{
  uint32_t ival, fval, promille = 1000; 
  
  /*
   *  When not using nanosecond CPU usage resolution, we have to count
   *  the number of "ticks" we gave credit for to give the user a rough
   *  guideline as to what each number means proportionally.
   */
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS

  struct timespec uptime, total, rane/

  _TOD_Get_uptime( &uptime );
  _Timespec_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total );
  
  ran = _Thread_Idle->cpu_time_used;
  _Timespec_Divide( &ran, &total, &ival, &fval );

#else

  uint32_t             i;
  uint32_t             api_index;
  Thread_Control      *the_thread;
  Objects_Information *information;
  uint32_t             total_units = 0;

  for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
    
    if ( !_Objects_Information_table[ api_index ] )
      continue;
    information = _Objects_Information_table[ api_index ][ 1 ];
    if ( information ) {
      for ( i=1 ; i <= information->maximum ; i++ ) {
        the_thread = (Thread_Control *)information->local_table[ i ];

        if ( the_thread )
          total_units += the_thread->cpu_time_used;
      }
    }
  }

  ival = (total_units) ?  _Thread_Idle->cpu_time_used * 10000 / total_units : 0;
  fval = ival % 100;
  ival /= 100;

#endif

  promille = ival * 10 + fval / 100; 
  return promille;
}

Any ideas on what I'm missing here?

Thanks,

Giovanni Macciocu, Software Design Engineer
SRON Netherlands Institute for Space Research






More information about the devel mailing list