diff options
27 files changed, 668 insertions, 302 deletions
diff --git a/cpukit/ChangeLog b/cpukit/ChangeLog index f79a2a9f7e..694a76e8bb 100644 --- a/cpukit/ChangeLog +++ b/cpukit/ChangeLog @@ -1,3 +1,25 @@ +2007-05-15 Joel Sherrill <joel.sherrill@oarcorp.com> + + * Makefile.am, preinstall.am, libmisc/Makefile.am, rtems/Makefile.am, + rtems/include/rtems.h, rtems/include/rtems/rtems/ratemon.h, + rtems/inline/rtems/rtems/ratemon.inl, rtems/src/ratemoncancel.c, + rtems/src/ratemoncreate.c, rtems/src/ratemondelete.c, + rtems/src/ratemongetstatus.c, rtems/src/ratemonident.c, + rtems/src/ratemonperiod.c, rtems/src/ratemontimeout.c, + score/Makefile.am, score/include/rtems/score/object.h, + score/src/threadhandler.c, wrapup/Makefile.am: Integrate Rate + Monotonic Statistics and Period Usage into Rate Monotonic Manager. + Added the following directives: rtems_rate_monotonic_get_statistics, + rtems_rate_monotonic_reset_statistics, + rtems_rate_montonic_reset_all_statistics, + rtems_rate_montonic_report_statistics, and rtems_object_get_name. + Obsoleted the rtems/rtmonuse.h file as a public interface. + * rtems/src/ratemongetstatistics.c, + rtems/src/ratemonreportstatistics.c, rtems/src/ratemonresetall.c, + rtems/src/ratemonresetstatistics.c, rtems/src/rtemsobjectgetname.c, + score/src/objectgetnameasstring.c: New files. + * libmisc/rtmonuse/rtmonuse.c, libmisc/rtmonuse/rtmonuse.h: Removed. + 2007-05-14 Joel Sherrill <joel.sherrill@OARcorp.com> * libcsupport/Makefile.am, libcsupport/src/unixlibc.c: Split off dummry diff --git a/cpukit/Makefile.am b/cpukit/Makefile.am index 7b1d40c4b5..4b606f3ea0 100644 --- a/cpukit/Makefile.am +++ b/cpukit/Makefile.am @@ -114,9 +114,6 @@ if LIBSHELL include_rtems_HEADERS += libmisc/shell/shell.h endif -## rtmonuse -include_rtems_HEADERS += libmisc/rtmonuse/rtmonuse.h - ## i2c include_rtems_HEADERS += libi2c/libi2c.h diff --git a/cpukit/libmisc/Makefile.am b/cpukit/libmisc/Makefile.am index 630102c1fa..afcb6569dc 100644 --- a/cpukit/libmisc/Makefile.am +++ b/cpukit/libmisc/Makefile.am @@ -64,10 +64,6 @@ endif EXTRA_DIST += shell/README -## rtmonuse -noinst_LIBRARIES += librtmonuse.a -librtmonuse_a_SOURCES = rtmonuse/rtmonuse.c rtmonuse/rtmonuse.h - ## serdbg if LIBSERDBG diff --git a/cpukit/libmisc/rtmonuse/rtmonuse.c b/cpukit/libmisc/rtmonuse/rtmonuse.c deleted file mode 100644 index b954fae988..0000000000 --- a/cpukit/libmisc/rtmonuse/rtmonuse.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - * $Id$ - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <rtems.h> -#include <stdlib.h> -#include <stdio.h> -#include <assert.h> -#include <ctype.h> -#include <inttypes.h> - -#include <rtems/rtmonuse.h> - -typedef struct { - rtems_id id; - uint32_t count; - uint32_t missed_count; - uint32_t min_cpu_time; - uint32_t max_cpu_time; - uint32_t total_cpu_time; - uint32_t min_wall_time; - uint32_t max_wall_time; - uint32_t total_wall_time; -} Period_usage_t; - -Period_usage_t *Period_usage_Information; - -/*PAGE - * - * Period_usage_Initialize - */ - -void Period_usage_Initialize( void ) -{ - int maximum; - - maximum = _Configuration_Table->RTEMS_api_configuration->maximum_periods; - - Period_usage_Information = malloc( sizeof(Period_usage_t) * (maximum+1) ); - - Period_usage_Reset(); -} - -/*PAGE - * - * Period_usage_Reset - */ - -void Period_usage_Reset( void ) -{ - uint32_t i; - Period_usage_t *the_usage; - - for ( i=0 ; - i<_Configuration_Table->RTEMS_api_configuration->maximum_periods ; - i++ ) { - the_usage = &Period_usage_Information[ i ]; - - the_usage->count = 0; - the_usage->missed_count = 0; - the_usage->min_cpu_time = 0xFFFFFFFF; - the_usage->max_cpu_time = 0; - the_usage->total_cpu_time = 0; - the_usage->min_wall_time = 0xFFFFFFFF; - the_usage->max_wall_time = 0; - the_usage->total_wall_time = 0; - - } -} - -/*PAGE - * - * Period_usage_Update - */ - -void Period_usage_Update( - rtems_id id -) -{ - rtems_rate_monotonic_period_status rm_status; - rtems_status_code status; - Period_usage_t *the_usage; - - assert( Period_usage_Information ); - - status = rtems_rate_monotonic_get_status( id, &rm_status ); - assert( status == RTEMS_SUCCESSFUL ); - - the_usage = &Period_usage_Information[ rtems_get_index( id ) ]; - - the_usage->id = id; - the_usage->count++; - if ( rm_status.state == RATE_MONOTONIC_EXPIRED ) - the_usage->missed_count++; - the_usage->total_cpu_time += rm_status.ticks_executed_since_last_period; - the_usage->total_wall_time += rm_status.ticks_since_last_period; - - /* - * Update CPU time - */ - - if ( rm_status.ticks_executed_since_last_period < the_usage->min_cpu_time ) - the_usage->min_cpu_time = rm_status.ticks_executed_since_last_period; - - if ( rm_status.ticks_executed_since_last_period > the_usage->max_cpu_time ) - the_usage->max_cpu_time = rm_status.ticks_executed_since_last_period; - - /* - * Update Wall time - */ - - if ( rm_status.ticks_since_last_period < the_usage->min_wall_time ) - the_usage->min_wall_time = rm_status.ticks_since_last_period; - - if ( rm_status.ticks_since_last_period > the_usage->max_wall_time ) - the_usage->max_wall_time = rm_status.ticks_since_last_period; - -} - -/*PAGE - * - * Period_usage_Dump - */ - -void Period_usage_Dump( void ) -{ - uint32_t i; - Period_usage_t *the_usage; - Rate_monotonic_Control *the_period; - uint32_t u32_name; - char *cname; - char name[5]; - uint32_t api_index; - uint32_t ival_cpu, fval_cpu; - uint32_t ival_wall, fval_wall; - Objects_Information *information; - - if ( !Period_usage_Information ) { - fprintf(stdout, "Period statistics library is not initialized\n" ); - return; - } - - fprintf(stdout, - "Period information by period\n" - " ID OWNER PERIODS MISSED CPU TIME WALL TIME\n" - ); - - /* - * RTEMS does not use an index of zero for object ids. - */ - - for ( i=1 ; - i<=_Configuration_Table->RTEMS_api_configuration->maximum_periods ; - i++ ) { - the_usage = &Period_usage_Information[ i ]; - if ( the_usage->count == 0 ) - continue; - - the_period = - (Rate_monotonic_Control *)_Rate_monotonic_Information.local_table[ i ]; - - name[ 0 ] = ' '; - name[ 1 ] = ' '; - name[ 2 ] = ' '; - name[ 3 ] = ' '; - name[ 4 ] = '\0'; - - if ( the_period->owner ) { - api_index = _Objects_Get_API(the_period->owner->Object.id); - information = _Objects_Information_table[ api_index ][ 1 ]; - - if ( information->is_string ) { - cname = the_period->owner->Object.name; - name[ 0 ] = cname[0]; - name[ 1 ] = cname[1]; - name[ 2 ] = cname[2]; - name[ 3 ] = cname[3]; - name[ 4 ] = '\0'; - } else { - u32_name = (uint32_t )the_period->owner->Object.name; - name[ 0 ] = (u32_name >> 24) & 0xff; - name[ 1 ] = (u32_name >> 16) & 0xff; - name[ 2 ] = (u32_name >> 8) & 0xff; - name[ 3 ] = (u32_name >> 0) & 0xff; - name[ 4 ] = '\0'; - } - } - - if ( !isprint(name[0]) ) name[0] = '*'; - if ( !isprint(name[1]) ) name[1] = '*'; - if ( !isprint(name[2]) ) name[2] = '*'; - if ( !isprint(name[3]) ) name[3] = '*'; - - - ival_cpu = the_usage->total_cpu_time * 100 / the_usage->count; - fval_cpu = ival_cpu % 100; - ival_cpu /= 100; - ival_wall = the_usage->total_wall_time * 100 / the_usage->count; - fval_wall = ival_wall % 100; - ival_wall /= 100; - fprintf(stdout, - "0x%08" PRIx32 " %4s %6" PRId32 " %3" PRId32 " " - "%" PRId32 "/%" PRId32 "/%" PRId32 ".%02" PRId32 " " - "%" PRId32 "/%" PRId32 "/%" PRId32 ".%02" PRId32 "\n", - the_usage->id, - name, - the_usage->count, - the_usage->missed_count, - - the_usage->min_cpu_time, - the_usage->max_cpu_time, - ival_cpu, fval_cpu, - /* (double) the_usage->total_cpu_time / (double) the_usage->count, */ - - the_usage->min_wall_time, - the_usage->max_wall_time, - ival_wall, fval_wall - /* (double) the_usage->total_wall_time / (double) the_usage->count */ - ); - } -} diff --git a/cpukit/libmisc/rtmonuse/rtmonuse.h b/cpukit/libmisc/rtmonuse/rtmonuse.h deleted file mode 100644 index 27fb7c1c8a..0000000000 --- a/cpukit/libmisc/rtmonuse/rtmonuse.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - * @file rtems/rtmonuse.h - */ - -/* - * $Id$ - */ - -#ifndef __RATE_MONOTONIC_USAGE_h -#define __RATE_MONOTONIC_USAGE_h - -#ifdef __cplusplus -extern "C" { -#endif - -void Period_usage_Initialize( void ); - -void Period_usage_Reset( void ); - -void Period_usage_Update( - rtems_id id -); - -void Period_usage_Dump( void ); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/cpukit/preinstall.am b/cpukit/preinstall.am index 86d792a304..e1a12cfd9e 100644 --- a/cpukit/preinstall.am +++ b/cpukit/preinstall.am @@ -206,9 +206,6 @@ $(PROJECT_INCLUDE)/rtems/shell.h: libmisc/shell/shell.h $(PROJECT_INCLUDE)/rtems $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/shell.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/shell.h endif -$(PROJECT_INCLUDE)/rtems/rtmonuse.h: libmisc/rtmonuse/rtmonuse.h $(PROJECT_INCLUDE)/rtems/$(dirstamp) - $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/rtmonuse.h -PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/rtmonuse.h $(PROJECT_INCLUDE)/rtems/libi2c.h: libi2c/libi2c.h $(PROJECT_INCLUDE)/rtems/$(dirstamp) $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/libi2c.h diff --git a/cpukit/rtems/Makefile.am b/cpukit/rtems/Makefile.am index b4bd102927..13405c03a4 100644 --- a/cpukit/rtems/Makefile.am +++ b/cpukit/rtems/Makefile.am @@ -52,7 +52,7 @@ include_rtems_rtems_HEADERS += inline/rtems/rtems/asr.inl \ inline/rtems/rtems/timer.inl ## src -librtems_a_SOURCES = +librtems_a_SOURCES = src/rtemsobjectgetname.c ## TASK_C_FILES librtems_a_SOURCES += src/tasks.c src/taskcreate.c src/taskdelete.c \ @@ -64,7 +64,9 @@ librtems_a_SOURCES += src/tasks.c src/taskcreate.c src/taskdelete.c \ ## RATEMON_C_FILES librtems_a_SOURCES += src/ratemon.c src/ratemoncancel.c src/ratemoncreate.c \ - src/ratemondelete.c src/ratemongetstatus.c src/ratemonident.c \ + src/ratemondelete.c src/ratemongetstatus.c src/ratemongetstatistics.c \ + src/ratemonresetstatistics.c src/ratemonresetall.c \ + src/ratemonreportstatistics.c src/ratemonident.c \ src/ratemonperiod.c src/ratemontimeout.c ## INTR_C_FILES diff --git a/cpukit/rtems/include/rtems.h b/cpukit/rtems/include/rtems.h index b4eb12a1c7..c6329fe41b 100644 --- a/cpukit/rtems/include/rtems.h +++ b/cpukit/rtems/include/rtems.h @@ -126,7 +126,7 @@ extern "C" { * object ID. * * Input parameters: - * id - message queue id + * id - object id * * Output parameters: * *name - user defined object name @@ -139,6 +139,27 @@ rtems_status_code rtems_object_id_to_name( rtems_name *name ); +/* + * rtems_object_get_name + * + * This directive returns the name associated with the specified + * object ID. + * + * Input parameters: + * id - object id + * + * Output parameters: + * *name - user defined object name + * name - if successful + * NULL - if unsuccessful + */ + +char *rtems_object_get_name( + rtems_id id, + size_t length, + char *name +); + #ifdef __cplusplus } #endif diff --git a/cpukit/rtems/include/rtems/rtems/ratemon.h b/cpukit/rtems/include/rtems/rtems/ratemon.h index 0d9d5aa903..84e3454164 100644 --- a/cpukit/rtems/include/rtems/rtems/ratemon.h +++ b/cpukit/rtems/include/rtems/rtems/ratemon.h @@ -15,7 +15,7 @@ * + conclude current and start the next period * + obtain status information on a period * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2007. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -35,6 +35,9 @@ extern "C" { #include <rtems/score/object.h> #include <rtems/score/thread.h> #include <rtems/score/watchdog.h> +#include <rtems/rtems/status.h> + +#include <string.h> /* * The following enumerated type defines the states in which a @@ -59,10 +62,26 @@ typedef enum { #define RTEMS_PERIOD_STATUS WATCHDOG_NO_TIMEOUT /* + * The following defines the statistics kept on each period instance. + */ + +typedef struct { + uint32_t count; + uint32_t missed_count; + uint32_t min_cpu_time; + uint32_t max_cpu_time; + uint32_t total_cpu_time; + uint32_t min_wall_time; + uint32_t max_wall_time; + uint32_t total_wall_time; +} rtems_rate_monotonic_period_statistics; + +/* * The following defines the period status structure. */ typedef struct { + Objects_Id owner; rtems_rate_monotonic_period_states state; uint32_t ticks_since_last_period; uint32_t ticks_executed_since_last_period; @@ -74,13 +93,14 @@ typedef struct { */ typedef struct { - Objects_Control Object; - Watchdog_Control Timer; - rtems_rate_monotonic_period_states state; - uint32_t owner_ticks_executed_at_period; - uint32_t time_at_period; - uint32_t next_length; - Thread_Control *owner; + Objects_Control Object; + Watchdog_Control Timer; + rtems_rate_monotonic_period_states state; + uint32_t owner_ticks_executed_at_period; + uint32_t time_at_period; + uint32_t next_length; + Thread_Control *owner; + rtems_rate_monotonic_period_statistics Statistics; } Rate_monotonic_Control; RTEMS_EXTERN Objects_Information _Rate_monotonic_Information; @@ -171,6 +191,52 @@ rtems_status_code rtems_rate_monotonic_get_status( ); /* + * rtems_rate_monotonic_get_statistics + * + * DESCRIPTION: + * + * This routine implements the rtems_rate_monotonic_get_statistics directive. + * Statistics gathered from the use of this period are returned. + */ + +rtems_status_code rtems_rate_monotonic_get_statistics( + Objects_Id id, + rtems_rate_monotonic_period_statistics *statistics +); + +/* + * rtems_rate_monotonic_reset_statistics + * + * DESCRIPTION: + * + * This directive allows a thread to reset the statistics information + * on a specific period instance. + */ +rtems_status_code rtems_rate_monotonic_reset_statistics( + Objects_Id id +); + +/* + * rtems_rate_montonic_reset_all_statistics + * + * DESCRIPTION: + * + * This directive allows a thread to reset the statistics information + * on ALL period instances. + */ +void rtems_rate_montonic_reset_all_statistics( void ); + +/* + * rtems_rate_montonic_report_statistics + * + * DESCRIPTION: + * + * This directive allows a thread to print the statistics information + * on ALL period instances which have non-zero counts using printk. + */ +void rtems_rate_montonic_report_statistics( void ); + +/* * rtems_rate_monotonic_period * * DESCRIPTION: @@ -199,11 +265,28 @@ rtems_status_code rtems_rate_monotonic_period( * state and not restarted. */ -void _Rate_monotonic_Timeout ( +void _Rate_monotonic_Timeout( Objects_Id id, void *ignored ); +/* + * _Rate_monotonic_Reset_statistics + * + * DESCRIPTION: + * + * This method resets the statistics information for a period instance. + */ + +#define _Rate_monotonic_Reset_statistics( _the_period ) \ + do { \ + memset( \ + &(_the_period)->Statistics, \ + 0, \ + sizeof( rtems_rate_monotonic_period_statistics ) \ + ); \ + } while (0) + #ifndef __RTEMS_APPLICATION__ #include <rtems/rtems/ratemon.inl> #endif diff --git a/cpukit/rtems/inline/rtems/rtems/ratemon.inl b/cpukit/rtems/inline/rtems/rtems/ratemon.inl index 97f177d66e..bae2940617 100644 --- a/cpukit/rtems/inline/rtems/rtems/ratemon.inl +++ b/cpukit/rtems/inline/rtems/rtems/ratemon.inl @@ -6,7 +6,7 @@ * This file contains the static inline implementation of the inlined * routines in the Rate Monotonic Manager. * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2007. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be diff --git a/cpukit/rtems/src/ratemoncancel.c b/cpukit/rtems/src/ratemoncancel.c index 254a1f51f9..fff77eb448 100644 --- a/cpukit/rtems/src/ratemoncancel.c +++ b/cpukit/rtems/src/ratemoncancel.c @@ -1,8 +1,7 @@ /* - * Rate Monotonic Manager + * Rate Monotonic Manager -- Cancel a Period * - * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2007. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be diff --git a/cpukit/rtems/src/ratemoncreate.c b/cpukit/rtems/src/ratemoncreate.c index 5585a8ea36..01dffcca58 100644 --- a/cpukit/rtems/src/ratemoncreate.c +++ b/cpukit/rtems/src/ratemoncreate.c @@ -1,8 +1,7 @@ /* - * Rate Monotonic Manager + * Rate Monotonic Manager -- Create a Period * - * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2007. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -68,6 +67,8 @@ rtems_status_code rtems_rate_monotonic_create( _Watchdog_Initialize( &the_period->Timer, NULL, 0, NULL ); + _Rate_monotonic_Reset_statistics( the_period ); + _Objects_Open( &_Rate_monotonic_Information, &the_period->Object, diff --git a/cpukit/rtems/src/ratemondelete.c b/cpukit/rtems/src/ratemondelete.c index b49311acbb..7eeabb2415 100644 --- a/cpukit/rtems/src/ratemondelete.c +++ b/cpukit/rtems/src/ratemondelete.c @@ -1,8 +1,7 @@ /* - * Rate Monotonic Manager + * Rate Monotonic Manager -- Delete a Period * - * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2007. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be diff --git a/cpukit/rtems/src/ratemongetstatistics.c b/cpukit/rtems/src/ratemongetstatistics.c new file mode 100644 index 0000000000..aae74b0328 --- /dev/null +++ b/cpukit/rtems/src/ratemongetstatistics.c @@ -0,0 +1,71 @@ +/* + * Rate Monotonic Manager -- Get Statistics + * + * COPYRIGHT (c) 1989-2007. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/support.h> +#include <rtems/score/isr.h> +#include <rtems/score/object.h> +#include <rtems/rtems/ratemon.h> +#include <rtems/score/thread.h> + +/*PAGE + * + * rtems_rate_monotonic_get_statistics + * + * This directive allows a thread to obtain statistics information on a + * period. + * + * Input parameters: + * id - rate monotonic id + * statistics - pointer to statistics control block + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + * + */ + +rtems_status_code rtems_rate_monotonic_get_statistics( + Objects_Id id, + rtems_rate_monotonic_period_statistics *statistics +) +{ + Objects_Locations location; + Rate_monotonic_Control *the_period; + + if ( !statistics ) + return RTEMS_INVALID_ADDRESS; + + the_period = _Rate_monotonic_Get( id, &location ); + switch ( location ) { + case OBJECTS_REMOTE: /* should never return this */ + return RTEMS_INTERNAL_ERROR; + + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + + case OBJECTS_LOCAL: + + *statistics = the_period->Statistics; + + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} diff --git a/cpukit/rtems/src/ratemongetstatus.c b/cpukit/rtems/src/ratemongetstatus.c index e6363a7a71..d059e1ae3b 100644 --- a/cpukit/rtems/src/ratemongetstatus.c +++ b/cpukit/rtems/src/ratemongetstatus.c @@ -1,8 +1,7 @@ /* - * Rate Monotonic Manager + * Rate Monotonic Manager -- Get Status * - * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2007. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -61,6 +60,7 @@ rtems_status_code rtems_rate_monotonic_get_status( return RTEMS_INVALID_ID; case OBJECTS_LOCAL: + status->owner = ((the_period->owner) ? the_period->owner->Object.id : 0); status->state = the_period->state; if ( status->state == RATE_MONOTONIC_INACTIVE ) { diff --git a/cpukit/rtems/src/ratemonident.c b/cpukit/rtems/src/ratemonident.c index b81b92042e..bfe7ad4148 100644 --- a/cpukit/rtems/src/ratemonident.c +++ b/cpukit/rtems/src/ratemonident.c @@ -1,8 +1,7 @@ /* - * Rate Monotonic Manager + * Rate Monotonic Manager -- Name to Id Lookup * - * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2007. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be diff --git a/cpukit/rtems/src/ratemonperiod.c b/cpukit/rtems/src/ratemonperiod.c index e722c41ca7..83ae0e040d 100644 --- a/cpukit/rtems/src/ratemonperiod.c +++ b/cpukit/rtems/src/ratemonperiod.c @@ -1,8 +1,7 @@ /* - * Rate Monotonic Manager + * Rate Monotonic Manager - Period Blocking and Status * - * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2007. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be @@ -24,6 +23,61 @@ #include <rtems/rtems/ratemon.h> #include <rtems/score/thread.h> +void _Rate_monotonic_Update_statistics( + Rate_monotonic_Control *the_period +) +{ + uint32_t ticks_since_last_period; + uint32_t ticks_executed_since_last_period; + + /* + * Assume we are only called in states where it is appropriate + * to update the statistics. This should only be RATE_MONOTONIC_ACTIVE + * and RATE_MONOTONIC_EXPIRED. + */ + + /* + * Grab basic information + */ + + ticks_since_last_period = + _Watchdog_Ticks_since_boot - the_period->time_at_period; + + ticks_executed_since_last_period = the_period->owner->ticks_executed - + the_period->owner_ticks_executed_at_period; + + /* + * Now update the statistics + */ + + the_period->Statistics.count++; + if ( the_period->state == RATE_MONOTONIC_EXPIRED ) + the_period->Statistics.missed_count++; + the_period->Statistics.total_cpu_time += ticks_executed_since_last_period; + the_period->Statistics.total_wall_time += ticks_since_last_period; + + /* + * Update CPU time + */ + + if ( ticks_executed_since_last_period < the_period->Statistics.min_cpu_time ) + the_period->Statistics.min_cpu_time = ticks_executed_since_last_period; + + if ( ticks_executed_since_last_period > the_period->Statistics.max_cpu_time ) + the_period->Statistics.max_cpu_time = ticks_executed_since_last_period; + + /* + * Update Wall time + */ + + if ( ticks_since_last_period < the_period->Statistics.min_wall_time ) + the_period->Statistics.min_wall_time = ticks_since_last_period; + + if ( ticks_since_last_period > the_period->Statistics.max_wall_time ) + the_period->Statistics.max_wall_time = ticks_since_last_period; +} + + /*PAGE * * rtems_rate_monotonic_period @@ -86,7 +140,12 @@ rtems_status_code rtems_rate_monotonic_period( _ISR_Disable( level ); switch ( the_period->state ) { case RATE_MONOTONIC_INACTIVE: + /* + * No need to update statistics -- there are not a period active + */ + _ISR_Enable( level ); + the_period->state = RATE_MONOTONIC_ACTIVE; _Watchdog_Initialize( &the_period->Timer, @@ -106,6 +165,12 @@ rtems_status_code rtems_rate_monotonic_period( return RTEMS_SUCCESSFUL; case RATE_MONOTONIC_ACTIVE: + + /* + * Update statistics from the concluding period + */ + _Rate_monotonic_Update_statistics( the_period ); + /* * This tells the _Rate_monotonic_Timeout that this task is * in the process of blocking on the period and that we @@ -143,7 +208,13 @@ rtems_status_code rtems_rate_monotonic_period( break; case RATE_MONOTONIC_EXPIRED: + /* + * Update statistics from the concluding period + */ + _Rate_monotonic_Update_statistics( the_period ); + _ISR_Enable( level ); + the_period->state = RATE_MONOTONIC_ACTIVE; the_period->owner_ticks_executed_at_period = _Thread_Executing->ticks_executed; diff --git a/cpukit/rtems/src/ratemonreportstatistics.c b/cpukit/rtems/src/ratemonreportstatistics.c new file mode 100644 index 0000000000..352bd1d946 --- /dev/null +++ b/cpukit/rtems/src/ratemonreportstatistics.c @@ -0,0 +1,90 @@ +/* + * Rate Monotonic Manager -- Report Statistics for All Periods + * + * COPYRIGHT (c) 1989-2007. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems.h> +#include <stdlib.h> +#include <ctype.h> +#include <inttypes.h> + +#include <rtems/bspIo.h> + +/* + * This directive allows a thread to print the statistics information + * on ALL period instances which have non-zero counts using printk. + * + * The implementation of this directive straddles the fence between + * inside and outside of RTEMS. It is presented as part of the Manager + * but actually uses other services of the Manager. + */ +void rtems_rate_montonic_report_statistics( void ) +{ + rtems_status_code status; + rtems_id id; + rtems_rate_monotonic_period_statistics the_stats; + rtems_rate_monotonic_period_status the_status; + char name[5]; + uint32_t ival_cpu, fval_cpu; + uint32_t ival_wall, fval_wall; + + printk( + "Period information by period\n" + " ID OWNER PERIODS MISSED CPU TIME WALL TIME\n" + ); + + /* + * Cycle through all possible ids and try to report on each one. If it + * is a period that is inactive, we just get an error back. No big deal. + */ + for ( id=_Rate_monotonic_Information.minimum_id ; + id <= _Rate_monotonic_Information.maximum_id ; + id++ ) { + status = rtems_rate_monotonic_get_statistics( id, &the_stats ); + if ( status != RTEMS_SUCCESSFUL ) + continue; + + /* If the above passed, so should this but check it anyway */ + status = rtems_rate_monotonic_get_status( id, &the_status ); + if ( status != RTEMS_SUCCESSFUL ) + continue; + + if ( the_stats.count == 0 ) + continue; + + ival_cpu = the_stats.total_cpu_time * 100 / the_stats.count; + + name[ 0 ] = '\0'; + + if ( the_status.owner ) { + rtems_object_get_name( the_status.owner, sizeof(name), name ); + } + + fval_cpu = ival_cpu % 100; + ival_cpu /= 100; + ival_wall = the_stats.total_wall_time * 100 / the_stats.count; + fval_wall = ival_wall % 100; + ival_wall /= 100; + printk( + "0x%08" PRIx32 " %4s %6" PRId32 " %3" PRId32 " " + "%" PRId32 "/%" PRId32 "/%" PRId32 ".%02" PRId32 " " + "%" PRId32 "/%" PRId32 "/%" PRId32 ".%02" PRId32 "\n", + id, name, + the_stats.count, the_stats.missed_count, + the_stats.min_cpu_time, the_stats.max_cpu_time, ival_cpu, fval_cpu, + the_stats.min_wall_time, the_stats.max_wall_time, ival_wall, fval_wall + ); + } +} diff --git a/cpukit/rtems/src/ratemonresetall.c b/cpukit/rtems/src/ratemonresetall.c new file mode 100644 index 0000000000..8b91ddd3e5 --- /dev/null +++ b/cpukit/rtems/src/ratemonresetall.c @@ -0,0 +1,56 @@ +/* + * Rate Monotonic Manager -- Reset Statistics for All Periods + * + * COPYRIGHT (c) 1989-2007. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/support.h> +#include <rtems/score/object.h> +#include <rtems/rtems/ratemon.h> +#include <rtems/score/thread.h> + +/* + * rtems_rate_montonic_reset_all_statistics + */ +void rtems_rate_montonic_reset_all_statistics( void ) +{ + Objects_Id id; + rtems_status_code status; + + /* + * Prevent allocation or deallocation of any of the periods while + * we are cycling. Also this is an optimization which ensures that + * we only disable/enable once. The call to + * rtems_rate_monotonic_reset_statistics will be in a nested dispatch + * disabled critical section. + */ + _Thread_Disable_dispatch(); + + /* + * Cycle through all possible ids and try to reset each one. If it + * is a period that is inactive, we just get an error back. No big deal. + */ + for ( id=_Rate_monotonic_Information.minimum_id ; + id <= _Rate_monotonic_Information.maximum_id ; + id++ ) { + status = rtems_rate_monotonic_reset_statistics( id ); + } + + /* + * Done so exit thread dispatching disabled critical section. + */ + _Thread_Enable_dispatch(); +} diff --git a/cpukit/rtems/src/ratemonresetstatistics.c b/cpukit/rtems/src/ratemonresetstatistics.c new file mode 100644 index 0000000000..6d8f9c5e11 --- /dev/null +++ b/cpukit/rtems/src/ratemonresetstatistics.c @@ -0,0 +1,66 @@ +/* + * Rate Monotonic Manager -- Reset Statistics + * + * COPYRIGHT (c) 1989-2007. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems/system.h> +#include <rtems/rtems/status.h> +#include <rtems/rtems/support.h> +#include <rtems/score/isr.h> +#include <rtems/score/object.h> +#include <rtems/rtems/ratemon.h> +#include <rtems/score/thread.h> + +/*PAGE + * + * rtems_rate_monotonic_reset_statistics + * + * This directive allows a thread to reset the statistics information + * on a specific period instance. + * + * Input parameters: + * id - rate monotonic id + * + * Output parameters: + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + * + */ + +rtems_status_code rtems_rate_monotonic_reset_statistics( + Objects_Id id +) +{ + Objects_Locations location; + Rate_monotonic_Control *the_period; + + the_period = _Rate_monotonic_Get( id, &location ); + switch ( location ) { + case OBJECTS_REMOTE: /* should never return this */ + return RTEMS_INTERNAL_ERROR; + + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + + case OBJECTS_LOCAL: + + _Rate_monotonic_Reset_statistics( the_period ); + + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} diff --git a/cpukit/rtems/src/ratemontimeout.c b/cpukit/rtems/src/ratemontimeout.c index deb9a18bc6..3649d574d5 100644 --- a/cpukit/rtems/src/ratemontimeout.c +++ b/cpukit/rtems/src/ratemontimeout.c @@ -1,8 +1,7 @@ /* - * Rate Monotonic Manager + * Rate Monotonic Manager -- Period End Timeout Handler * - * - * COPYRIGHT (c) 1989-1999. + * COPYRIGHT (c) 1989-2007. * On-Line Applications Research Corporation (OAR). * * The license and distribution terms for this file may be diff --git a/cpukit/rtems/src/rtemsobjectgetname.c b/cpukit/rtems/src/rtemsobjectgetname.c new file mode 100644 index 0000000000..2fbf39425d --- /dev/null +++ b/cpukit/rtems/src/rtemsobjectgetname.c @@ -0,0 +1,34 @@ +/* + * RTEMS Object Helper -- Obtain Name of Object as String + * + * COPYRIGHT (c) 1989-2007. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems/system.h> +#include <rtems/score/object.h> + +/* + * This method objects the name of an object and returns its name + * in the form of a C string. It attempts to be careful about + * overflowing the user's string and about returning unprintable characters. + */ + +char *rtems_object_get_name( + Objects_Id id, + size_t length, + char *name +) +{ + return _Objects_Get_name_as_string( id, length, name ); +} diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am index 9c9fd67919..3699743ce9 100644 --- a/cpukit/score/Makefile.am +++ b/cpukit/score/Makefile.am @@ -114,7 +114,7 @@ libscore_a_SOURCES += src/object.c src/objectallocate.c \ src/objectgetisr.c src/objectgetbyindex.c src/objectgetnext.c \ src/objectinitializeinformation.c src/objectnametoid.c \ src/objectshrinkinformation.c src/objectgetnoprotection.c \ - src/objectidtoname.c + src/objectidtoname.c src/objectgetnameasstring.c ## PROTECTED_HEAP_C_FILES libscore_a_SOURCES += src/pheapallocatealigned.c src/pheapallocate.c \ diff --git a/cpukit/score/include/rtems/score/object.h b/cpukit/score/include/rtems/score/object.h index 3e03213dd1..c6592ee8bf 100644 --- a/cpukit/score/include/rtems/score/object.h +++ b/cpukit/score/include/rtems/score/object.h @@ -798,6 +798,24 @@ Objects_Control *_Objects_Get_next( Objects_Id *next_id_p ); +/** + * This method objects the name of an object and returns its name + * in the form of a C string. It attempts to be careful about + * overflowing the user's string and about returning unprintable characters. + * + * @param[in] id is the object to obtain the name of + * @param[in] length indicates the length of the caller's buffer + * @param[inout] name is a string which will be filled in. + * + * @return This method returns @a name or NULL on error. + */ + +char *_Objects_Get_name_as_string( + Objects_Id id, + size_t length, + char *name +); + /* * Pieces of object.inl are promoted out to the user */ diff --git a/cpukit/score/src/objectgetnameasstring.c b/cpukit/score/src/objectgetnameasstring.c new file mode 100644 index 0000000000..ec962e32a3 --- /dev/null +++ b/cpukit/score/src/objectgetnameasstring.c @@ -0,0 +1,96 @@ +/* + * COPYRIGHT (c) 1989-2007. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + * + * $Id$ + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <rtems/system.h> +#include <rtems/score/object.h> +#include <rtems/score/thread.h> +#include <stdlib.h> +#include <stdio.h> +#include <ctype.h> +#include <inttypes.h> + + +/* + * This method objects the name of an object and returns its name + * in the form of a C string. It attempts to be careful about + * overflowing the user's string and about returning unprintable characters. + */ + +char *_Objects_Get_name_as_string( + Objects_Id id, + size_t length, + char *name +) +{ + #ifdef RTEMS_POSIX_API + Objects_Information *information; + #endif + char *s; + char *d; + uint32_t i; + char lname[5]; + Objects_Control *the_object; + Objects_Locations location; + + if ( length == 0 ) + return NULL; + + if ( name == NULL ) + return NULL; + + information = _Objects_Get_information( id ); + if ( !information ) + return NULL; + + the_object = _Objects_Get( information, id, &location ); + switch ( location ) { + + case OBJECTS_REMOTE: + /* not supported */ + case OBJECTS_ERROR: + return NULL; + + case OBJECTS_LOCAL: + + /* + * Neither the Classic nor ITRON APIs use string names. + */ + #ifdef RTEMS_POSIX_API + + if ( information->is_string ) { + s = the_object->name; + } else + #endif + { + uint32_t u32_name = (uint32_t) the_object->name; + + lname[ 0 ] = (u32_name >> 24) & 0xff; + lname[ 1 ] = (u32_name >> 16) & 0xff; + lname[ 2 ] = (u32_name >> 8) & 0xff; + lname[ 3 ] = (u32_name >> 0) & 0xff; + lname[ 4 ] = '\0'; + s = lname; + } + + for ( i=0, d=name ; i<(length-1) && *s ; i++, s++, d++ ) { + *d = (!isprint(*s)) ? '*' : *s; + } + *d = '\0'; + + _Thread_Enable_dispatch(); + return name; + } + return NULL; /* unreachable path */ +} diff --git a/cpukit/score/src/threadhandler.c b/cpukit/score/src/threadhandler.c index b7708e2b03..c11a8b34b5 100644 --- a/cpukit/score/src/threadhandler.c +++ b/cpukit/score/src/threadhandler.c @@ -112,7 +112,12 @@ void _Thread_Handler( void ) _Thread_Enable_dispatch(); #if defined(__USE_INIT_FINI__) - if (!doneCons && (volatile void *)_init) + /* + * _init could be a weak symbol and we SHOULD test it but it isn't + * in any configuration I know of and it generates a warning on every + * RTEMS target configuration. --joel (12 May 2007) + */ + if (!doneCons) /* && (volatile void *)_init) */ _init (); #endif #if defined(__USE__MAIN__) diff --git a/cpukit/wrapup/Makefile.am b/cpukit/wrapup/Makefile.am index 22f431a6f0..2441529500 100644 --- a/cpukit/wrapup/Makefile.am +++ b/cpukit/wrapup/Makefile.am @@ -38,7 +38,6 @@ TMP_LIBS += ../libmisc/libmonitor.a TMP_LIBS += ../libmisc/libuntar.a TMP_LIBS += ../libmisc/libstackchk.a TMP_LIBS += ../libmisc/libcpuuse.a -TMP_LIBS += ../libmisc/librtmonuse.a ## XXX temporarily removed because it causes a ## XXX number of BSPs to not link "main(){}" used by autoconf |