2008-06-06 Joel Sherrill <joel.sherrill@OARcorp.com>

* libcsupport/src/__times.c, libmisc/cpuuse/cpuusagereport.c,
	libmisc/cpuuse/cpuusagereset.c, libmisc/monitor/mon-task.c,
	rtems/include/rtems/rtems/ratemon.h, rtems/src/ratemongetstatus.c,
	rtems/src/ratemonperiod.c, score/include/rtems/score/thread.h,
	score/src/threaddispatch.c, score/src/threadinitialize.c,
	score/src/threadtickletimeslice.c: Add typedefs for cpu usage and
	period timing statistics. Also renamed related variables and
	structure members so they are the same whether you are using
	nanosecond (e.g. struct timespec) or ticks (e.g. uint32_t)
	granularity. This lays the groundwork for future cleanup.
This commit is contained in:
Joel Sherrill
2008-06-06 15:44:11 +00:00
parent f176759649
commit 5fa5185324
12 changed files with 73 additions and 87 deletions

View File

@@ -1,3 +1,16 @@
2008-06-06 Joel Sherrill <joel.sherrill@OARcorp.com>
* libcsupport/src/__times.c, libmisc/cpuuse/cpuusagereport.c,
libmisc/cpuuse/cpuusagereset.c, libmisc/monitor/mon-task.c,
rtems/include/rtems/rtems/ratemon.h, rtems/src/ratemongetstatus.c,
rtems/src/ratemonperiod.c, score/include/rtems/score/thread.h,
score/src/threaddispatch.c, score/src/threadinitialize.c,
score/src/threadtickletimeslice.c: Add typedefs for cpu usage and
period timing statistics. Also renamed related variables and
structure members so they are the same whether you are using
nanosecond (e.g. struct timespec) or ticks (e.g. uint32_t)
granularity. This lays the groundwork for future cleanup.
2008-06-05 Joel Sherrill <joel.sherrill@OARcorp.com>
* sapi/include/confdefs.h: Rework to be more accurate on allocation. In

View File

@@ -71,7 +71,7 @@ clock_t _times(
ptms->tms_utime = ticks;
}
#else
ptms->tms_utime = _Thread_Executing->ticks_executed;
ptms->tms_utime = _Thread_Executing->cpu_time_used;
#endif
ptms->tms_stime = ticks;
ptms->tms_cutime = 0;

View File

@@ -80,7 +80,7 @@ void rtems_cpu_usage_report_with_plugin(
the_thread = (Thread_Control *)information->local_table[ i ];
if ( the_thread )
total_units += the_thread->ticks_executed;
total_units += the_thread->cpu_time_used;
}
}
}
@@ -142,12 +142,12 @@ void rtems_cpu_usage_report_with_plugin(
);
#else
ival = (total_units) ?
the_thread->ticks_executed * 10000 / total_units : 0;
the_thread->cpu_time_used * 10000 / total_units : 0;
fval = ival % 100;
ival /= 100;
(*print)( context,
"%8" PRId32 " %3" PRId32 ".%02" PRId32"\n",
the_thread->ticks_executed,
the_thread->cpu_time_used,
ival,
fval
);

View File

@@ -31,7 +31,7 @@ static void CPU_usage_Per_thread_handler(
the_thread->cpu_time_used.tv_sec = 0;
the_thread->cpu_time_used.tv_nsec = 0;
#else
the_thread->ticks_executed = 0;
the_thread->cpu_time_used = 0;
#endif
}

View File

@@ -37,7 +37,7 @@ rtems_monitor_task_canonical(
* FIXME: make this optionally cpu_time_executed
*/
#if 0
canonical_task->ticks = rtems_thread->ticks_executed;
canonical_task->ticks = rtems_thread->cpu_time_executed;
#else
canonical_task->ticks = 0;
#endif

View File

@@ -62,6 +62,11 @@ extern "C" {
* is used.
*/
#define RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
typedef struct timespec rtems_rate_monotonic_period_time_t;
#else
typedef uint32_t rtems_rate_monotonic_period_time_t;
#endif
#include <rtems/score/object.h>
@@ -72,6 +77,7 @@ extern "C" {
#include <string.h>
/**
* The following enumerated type defines the states in which a
* period may be.
@@ -98,42 +104,23 @@ typedef enum {
typedef struct {
uint32_t count;
uint32_t missed_count;
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
struct timespec min_cpu_time;
struct timespec max_cpu_time;
struct timespec total_cpu_time;
#else
uint32_t min_cpu_time;
uint32_t max_cpu_time;
uint32_t total_cpu_time;
#endif
#ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
struct timespec min_wall_time;
struct timespec max_wall_time;
struct timespec total_wall_time;
#else
uint32_t min_wall_time;
uint32_t max_wall_time;
uint32_t total_wall_time;
#endif
RTEMS_CPU_USAGE_STATISTICS_TIME_TYPE min_cpu_time;
RTEMS_CPU_USAGE_STATISTICS_TIME_TYPE max_cpu_time;
RTEMS_CPU_USAGE_STATISTICS_TIME_TYPE total_cpu_time;
rtems_rate_monotonic_period_time_t min_wall_time;
rtems_rate_monotonic_period_time_t max_wall_time;
rtems_rate_monotonic_period_time_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;
#ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
struct timespec since_last_period;
#else
uint32_t ticks_since_last_period;
#endif
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
struct timespec executed_since_last_period;
#else
uint32_t ticks_executed_since_last_period;
#endif
Objects_Id owner;
rtems_rate_monotonic_period_states state;
rtems_rate_monotonic_period_time_t since_last_period;
RTEMS_CPU_USAGE_STATISTICS_TIME_TYPE executed_since_last_period;
} rtems_rate_monotonic_period_status;
/**
@@ -144,16 +131,8 @@ typedef struct {
Objects_Control Object;
Watchdog_Control Timer;
rtems_rate_monotonic_period_states state;
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
struct timespec owner_executed_at_period;
#else
uint32_t owner_ticks_executed_at_period;
#endif
#ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
struct timespec time_at_period;
#else
uint32_t time_at_period;
#endif
RTEMS_CPU_USAGE_STATISTICS_TIME_TYPE owner_executed_at_period;
rtems_rate_monotonic_period_time_t time_at_period;
uint32_t next_length;
Thread_Control *owner;
rtems_rate_monotonic_period_statistics Statistics;

View File

@@ -68,13 +68,13 @@ rtems_status_code rtems_rate_monotonic_get_status(
status->since_last_period.tv_sec = 0;
status->since_last_period.tv_nsec = 0;
#else
status->ticks_since_last_period = 0;
status->since_last_period = 0;
#endif
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
status->executed_since_last_period.tv_sec = 0;
status->executed_since_last_period.tv_nsec = 0;
#else
status->ticks_executed_since_last_period = 0;
status->executed_since_last_period = 0;
#endif
} else {
/*
@@ -94,7 +94,7 @@ rtems_status_code rtems_rate_monotonic_get_status(
&status->since_last_period
);
#else
status->ticks_since_last_period =
status->since_last_period =
_Watchdog_Ticks_since_boot - the_period->time_at_period;
#endif
@@ -105,9 +105,9 @@ rtems_status_code rtems_rate_monotonic_get_status(
&status->executed_since_last_period
);
#else
status->ticks_executed_since_last_period =
the_period->owner->ticks_executed -
the_period->owner_ticks_executed_at_period;
status->executed_since_last_period =
the_period->owner->cpu_time_used -
the_period->owner_executed_at_period;
#endif
}

View File

@@ -33,16 +33,10 @@ void _Rate_monotonic_Update_statistics(
)
{
rtems_rate_monotonic_period_statistics *stats;
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
struct timespec executed;
#else
uint32_t ticks_executed_since_last_period;
#endif
RTEMS_CPU_USAGE_STATISTICS_TIME_TYPE executed;
rtems_rate_monotonic_period_time_t since_last_period;
#ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
struct timespec period_start;
struct timespec since_last_period;
#else
uint32_t ticks_since_last_period;
rtems_rate_monotonic_period_time_t period_start;
#endif
#if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
@@ -69,14 +63,13 @@ void _Rate_monotonic_Update_statistics(
_Timespec_Subtract( &period_start, &uptime, &since_last_period );
the_period->time_at_period = uptime;
#else
ticks_since_last_period =
_Watchdog_Ticks_since_boot - the_period->time_at_period;
since_last_period = _Watchdog_Ticks_since_boot - the_period->time_at_period;
the_period->time_at_period = _Watchdog_Ticks_since_boot;
#endif
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
{
struct timespec ran, used;
rtems_rate_monotonic_period_time_t ran, used;
/* Grab CPU usage when the thread got switched in */
used = _Thread_Executing->cpu_time_used;
@@ -95,8 +88,8 @@ void _Rate_monotonic_Update_statistics(
);
}
#else
ticks_executed_since_last_period = the_period->owner->ticks_executed -
the_period->owner_ticks_executed_at_period;
executed = the_period->owner->cpu_time_used -
the_period->owner_executed_at_period;
#endif
/*
@@ -123,13 +116,13 @@ void _Rate_monotonic_Update_statistics(
if ( _Timespec_Greater_than( &executed, &stats->max_cpu_time ) )
stats->max_cpu_time = executed;
#else
stats->total_cpu_time += ticks_executed_since_last_period;
stats->total_cpu_time += executed;
if ( ticks_executed_since_last_period < stats->min_cpu_time )
stats->min_cpu_time = ticks_executed_since_last_period;
if ( executed < stats->min_cpu_time )
stats->min_cpu_time = executed;
if ( ticks_executed_since_last_period > stats->max_cpu_time )
stats->max_cpu_time = ticks_executed_since_last_period;
if ( executed > stats->max_cpu_time )
stats->max_cpu_time = executed;
#endif
/*
@@ -137,13 +130,13 @@ void _Rate_monotonic_Update_statistics(
*/
#ifndef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
stats->total_wall_time += ticks_since_last_period;
stats->total_wall_time += since_last_period;
if ( ticks_since_last_period < stats->min_wall_time )
stats->min_wall_time = ticks_since_last_period;
if ( since_last_period < stats->min_wall_time )
stats->min_wall_time = since_last_period;
if ( ticks_since_last_period > stats->max_wall_time )
stats->max_wall_time = ticks_since_last_period;
if ( since_last_period > stats->max_wall_time )
stats->max_wall_time = since_last_period;
#else
_Timespec_Add_to( &stats->total_wall_time, &since_last_period );
@@ -241,7 +234,7 @@ rtems_status_code rtems_rate_monotonic_period(
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
{
struct timespec ran;
RTEMS_CPU_USAGE_STATISTICS_TIME_TYPE ran;
the_period->owner_executed_at_period =
_Thread_Executing->cpu_time_used;
@@ -260,8 +253,8 @@ rtems_status_code rtems_rate_monotonic_period(
_Timespec_Add_to( &the_period->owner_executed_at_period, &ran );
}
#else
the_period->owner_ticks_executed_at_period =
_Thread_Executing->ticks_executed;
the_period->owner_executed_at_period =
_Thread_Executing->cpu_time_used;
#endif
the_period->state = RATE_MONOTONIC_ACTIVE;

View File

@@ -43,6 +43,11 @@ extern "C" {
* is used.
*/
#define RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
#define RTEMS_CPU_USAGE_STATISTICS_TIME_TYPE struct timespec
#else
#define RTEMS_CPU_USAGE_STATISTICS_TIME_TYPE uint32_t
#endif
#include <rtems/score/context.h>
@@ -344,11 +349,7 @@ struct Thread_Control_struct {
/** This field is the amount of CPU time consumed by this thread
* since it was created.
*/
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
struct timespec cpu_time_used;
#else
uint32_t ticks_executed;
#endif
RTEMS_CPU_USAGE_STATISTICS_TIME_TYPE cpu_time_used;
/** This field points to the Ready FIFO for this priority. */
Chain_Control *ready;
/** This field contains precalculated priority map indices. */

View File

@@ -108,7 +108,7 @@ void _Thread_Dispatch( void )
_Thread_Time_of_last_context_switch = uptime;
}
#else
heir->ticks_executed++;
heir->cpu_time_used++;
#endif
/*

View File

@@ -211,7 +211,7 @@ boolean _Thread_Initialize(
the_thread->cpu_time_used.tv_sec = 0;
the_thread->cpu_time_used.tv_nsec = 0;
#else
the_thread->ticks_executed = 0;
the_thread->cpu_time_used = 0;
#endif
/*

View File

@@ -53,7 +53,7 @@ void _Thread_Tickle_timeslice( void )
/*
* Increment the number of ticks this thread has been executing
*/
executing->ticks_executed++;
executing->cpu_time_used++;
#endif
/*