2008-12-08 Joel Sherrill <joel.sherrill@oarcorp.com>

* libcsupport/src/__times.c, libmisc/cpuuse/cpuusagereport.c,
	libmisc/cpuuse/cpuusagereset.c, posix/src/clockgettime.c,
	posix/src/pthread.c, posix/src/timersettime.c,
	rtems/include/rtems/rtems/ratemon.h,
	rtems/src/clockgetsecondssinceepoch.c, rtems/src/clockgetuptime.c,
	rtems/src/ratemongetstatus.c, rtems/src/ratemonperiod.c,
	rtems/src/ratemonreportstatistics.c, rtems/src/taskwakewhen.c,
	rtems/src/timerfirewhen.c, rtems/src/timerserver.c,
	rtems/src/timerserverfirewhen.c, score/Makefile.am,
	score/preinstall.am, score/include/rtems/score/thread.h,
	score/include/rtems/score/tod.h, score/src/coretod.c,
	score/src/coretodget.c, score/src/coretodgetuptime.c,
	score/src/coretodset.c, score/src/coretodtickle.c,
	score/src/threaddispatch.c, score/src/threadinitialize.c: Add
	SuperCore handler Timestamp to provide an opaque class for the
	representation and manipulation of uptime, time of day, and the
	difference between two timestamps. By using SuperCore Timestamp, it
	is clear which methods and APIs really have to be struct timespec and
	which can be in an optimized native format.
	* score/include/rtems/score/timestamp.h,
	score/src/coretodgetuptimetimespec.c: New files.
This commit is contained in:
Joel Sherrill
2008-12-08 19:41:31 +00:00
parent 6d10c295ee
commit c16bcc009b
30 changed files with 573 additions and 159 deletions

View File

@@ -1,3 +1,27 @@
2008-12-08 Joel Sherrill <joel.sherrill@oarcorp.com>
* libcsupport/src/__times.c, libmisc/cpuuse/cpuusagereport.c,
libmisc/cpuuse/cpuusagereset.c, posix/src/clockgettime.c,
posix/src/pthread.c, posix/src/timersettime.c,
rtems/include/rtems/rtems/ratemon.h,
rtems/src/clockgetsecondssinceepoch.c, rtems/src/clockgetuptime.c,
rtems/src/ratemongetstatus.c, rtems/src/ratemonperiod.c,
rtems/src/ratemonreportstatistics.c, rtems/src/taskwakewhen.c,
rtems/src/timerfirewhen.c, rtems/src/timerserver.c,
rtems/src/timerserverfirewhen.c, score/Makefile.am,
score/preinstall.am, score/include/rtems/score/thread.h,
score/include/rtems/score/tod.h, score/src/coretod.c,
score/src/coretodget.c, score/src/coretodgetuptime.c,
score/src/coretodset.c, score/src/coretodtickle.c,
score/src/threaddispatch.c, score/src/threadinitialize.c: Add
SuperCore handler Timestamp to provide an opaque class for the
representation and manipulation of uptime, time of day, and the
difference between two timestamps. By using SuperCore Timestamp, it
is clear which methods and APIs really have to be struct timespec and
which can be in an optimized native format.
* score/include/rtems/score/timestamp.h,
score/src/coretodgetuptimetimespec.c: New files.
2008-12-08 Joel Sherrill <joel.sherrill@oarcorp.com> 2008-12-08 Joel Sherrill <joel.sherrill@oarcorp.com>
* libfs/src/nfsclient/src/nfs.c: Use * libfs/src/nfsclient/src/nfs.c: Use

View File

@@ -1,7 +1,7 @@
/* /*
* times() - POSIX 1003.1b 4.5.2 - Get Process Times * times() - POSIX 1003.1b 4.5.2 - Get Process Times
* *
* COPYRIGHT (c) 1989-1999. * COPYRIGHT (c) 1989-2008.
* On-Line Applications Research Corporation (OAR). * On-Line Applications Research Corporation (OAR).
* *
* The license and distribution terms for this file may be * The license and distribution terms for this file may be
@@ -23,7 +23,7 @@
#include <errno.h> #include <errno.h>
#include <assert.h> #include <assert.h>
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
#include <rtems/score/timespec.h> #include <rtems/score/timestamp.h>
#endif #endif
clock_t _times( clock_t _times(
@@ -53,16 +53,17 @@ clock_t _times(
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
{ {
struct timespec per_tick; Timestamp_Control per_tick;
uint32_t ticks; uint32_t ticks;
uint32_t fractional_ticks; uint32_t fractional_ticks;
per_tick.tv_sec = _Timestamp_Set(
_TOD_Microseconds_per_tick / TOD_MILLISECONDS_PER_SECOND; &per_tick,
per_tick.tv_nsec = _TOD_Microseconds_per_tick / TOD_MILLISECONDS_PER_SECOND,
(_TOD_Microseconds_per_tick % TOD_MILLISECONDS_PER_SECOND) / 1000; (_TOD_Microseconds_per_tick % TOD_MILLISECONDS_PER_SECOND) / 1000
);
_Timespec_Divide( _Timestamp_Divide(
&_Thread_Executing->cpu_time_used, &_Thread_Executing->cpu_time_used,
&per_tick, &per_tick,
&ticks, &ticks,

View File

@@ -28,11 +28,11 @@
#include <rtems/bspIo.h> #include <rtems/bspIo.h>
#if defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS) #if defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
#include <rtems/score/timespec.h> #include <rtems/score/timestamp.h>
#endif #endif
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
extern struct timespec CPU_usage_Uptime_at_last_reset; extern Timestamp_Control CPU_usage_Uptime_at_last_reset;
#else #else
extern uint32_t CPU_usage_Ticks_at_last_reset; extern uint32_t CPU_usage_Ticks_at_last_reset;
#endif #endif
@@ -54,7 +54,7 @@ void rtems_cpu_usage_report_with_plugin(
char name[13]; char name[13];
uint32_t ival, fval; uint32_t ival, fval;
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
struct timespec uptime, total, ran; Timestamp_Control uptime, total, ran;
#else #else
uint32_t total_units = 0; uint32_t total_units = 0;
#endif #endif
@@ -69,7 +69,7 @@ void rtems_cpu_usage_report_with_plugin(
*/ */
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
_TOD_Get_uptime( &uptime ); _TOD_Get_uptime( &uptime );
_Timespec_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total ); _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total );
#else #else
for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) { for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) {
if ( !_Objects_Information_table[ api_index ] ) if ( !_Objects_Information_table[ api_index ] )
@@ -123,13 +123,13 @@ void rtems_cpu_usage_report_with_plugin(
*/ */
ran = the_thread->cpu_time_used; ran = the_thread->cpu_time_used;
if ( _Thread_Executing->Object.id == the_thread->Object.id ) { if ( _Thread_Executing->Object.id == the_thread->Object.id ) {
struct timespec used; Timestamp_Control used;
_Timespec_Subtract( _Timestamp_Subtract(
&_Thread_Time_of_last_context_switch, &uptime, &used &_Thread_Time_of_last_context_switch, &uptime, &used
); );
_Timespec_Add_to( &ran, &used ); _Timestamp_Add_to( &ran, &used );
}; };
_Timespec_Divide( &ran, &total, &ival, &fval ); _Timestamp_Divide( &ran, &total, &ival, &fval );
/* /*
* Print the information * Print the information
@@ -137,7 +137,9 @@ void rtems_cpu_usage_report_with_plugin(
(*print)( context, (*print)( context,
"%3" PRId32 ".%06" PRId32 " %3" PRId32 ".%03" PRId32 "\n", "%3" PRId32 ".%06" PRId32 " %3" PRId32 ".%03" PRId32 "\n",
ran.tv_sec, ran.tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND, _Timestamp_Get_seconds( &ran ),
_Timestamp_Get_nanoseconds( &ran ) /
TOD_NANOSECONDS_PER_MICROSECOND,
ival, fval ival, fval
); );
#else #else
@@ -159,8 +161,8 @@ void rtems_cpu_usage_report_with_plugin(
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
(*print)( context, "Time since last CPU Usage reset %" PRId32 (*print)( context, "Time since last CPU Usage reset %" PRId32
".%06" PRId32 " seconds\n", ".%06" PRId32 " seconds\n",
total.tv_sec, _Timestamp_Get_seconds( &total ),
total.tv_nsec / TOD_NANOSECONDS_PER_MICROSECOND _Timestamp_Get_nanoseconds( &total ) / TOD_NANOSECONDS_PER_MICROSECOND
); );
#else #else
(*print)( context, (*print)( context,

View File

@@ -16,6 +16,7 @@
#endif #endif
#include <rtems.h> #include <rtems.h>
#include <rtems/score/timestamp.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <ctype.h>
@@ -28,8 +29,7 @@ static void CPU_usage_Per_thread_handler(
) )
{ {
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
the_thread->cpu_time_used.tv_sec = 0; _Timestamp_Set_to_zero( &the_thread->cpu_time_used );
the_thread->cpu_time_used.tv_nsec = 0;
#else #else
the_thread->cpu_time_used = 0; the_thread->cpu_time_used = 0;
#endif #endif
@@ -40,7 +40,7 @@ static void CPU_usage_Per_thread_handler(
* External data that is shared by cpu usage code but not declared in .h files. * External data that is shared by cpu usage code but not declared in .h files.
*/ */
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
extern struct timespec CPU_usage_Uptime_at_last_reset; extern Timestamp_Control CPU_usage_Uptime_at_last_reset;
#else #else
extern uint32_t CPU_usage_Ticks_at_last_reset; extern uint32_t CPU_usage_Ticks_at_last_reset;
#endif #endif

View File

@@ -36,21 +36,29 @@ int clock_gettime(
if ( !tp ) if ( !tp )
rtems_set_errno_and_return_minus_one( EINVAL ); rtems_set_errno_and_return_minus_one( EINVAL );
if ( clock_id == CLOCK_REALTIME ) if ( clock_id == CLOCK_REALTIME ) {
_TOD_Get(tp); _TOD_Get(tp);
return 0;
}
#ifdef CLOCK_MONOTONIC #ifdef CLOCK_MONOTONIC
else if ( clock_id == CLOCK_MONOTONIC ) if ( clock_id == CLOCK_MONOTONIC ) {
_TOD_Get_uptime(tp); _TOD_Get_uptime_as_timespec( tp );
return 0;
}
#endif #endif
#ifdef _POSIX_CPUTIME #ifdef _POSIX_CPUTIME
else if ( clock_id == CLOCK_PROCESS_CPUTIME ) if ( clock_id == CLOCK_PROCESS_CPUTIME ) {
_TOD_Get_uptime(tp); _TOD_Get_uptime_as_timespec( tp );
return 0;
}
#endif #endif
#ifdef _POSIX_THREAD_CPUTIME #ifdef _POSIX_THREAD_CPUTIME
else if ( clock_id == CLOCK_THREAD_CPUTIME ) if ( clock_id == CLOCK_THREAD_CPUTIME )
rtems_set_errno_and_return_minus_one( ENOSYS ); rtems_set_errno_and_return_minus_one( ENOSYS );
#endif #endif
else
rtems_set_errno_and_return_minus_one( EINVAL ); rtems_set_errno_and_return_minus_one( EINVAL );
return 0; return 0;

View File

@@ -31,6 +31,7 @@
#include <rtems/posix/config.h> #include <rtems/posix/config.h>
#include <rtems/posix/key.h> #include <rtems/posix/key.h>
#include <rtems/posix/time.h> #include <rtems/posix/time.h>
#include <rtems/score/timespec.h>
/*PAGE /*PAGE
* *

View File

@@ -59,10 +59,12 @@ int timer_settime(
/* Convert absolute to relative time */ /* Convert absolute to relative time */
if (flags == TIMER_ABSTIME) { if (flags == TIMER_ABSTIME) {
struct timespec now;
_TOD_Get( &now );
/* Check for seconds in the past */ /* Check for seconds in the past */
if ( _Timespec_Greater_than( &_TOD_Now, &normalize.it_value ) ) if ( _Timespec_Greater_than( &now, &normalize.it_value ) )
rtems_set_errno_and_return_minus_one( EINVAL ); rtems_set_errno_and_return_minus_one( EINVAL );
_Timespec_Subtract( &_TOD_Now, &normalize.it_value, &normalize.it_value ); _Timespec_Subtract( &now, &normalize.it_value, &normalize.it_value );
} }
/* If the function reaches this point, then it will be necessary to do /* If the function reaches this point, then it will be necessary to do

View File

@@ -70,7 +70,9 @@ extern "C" {
* statistics. * statistics.
*/ */
#if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS)
typedef struct timespec rtems_rate_monotonic_period_time_t; #include <rtems/score/timestamp.h>
typedef Timestamp_Control rtems_rate_monotonic_period_time_t;
#else #else
typedef uint32_t rtems_rate_monotonic_period_time_t; typedef uint32_t rtems_rate_monotonic_period_time_t;
#endif #endif
@@ -382,8 +384,11 @@ void _Rate_monotonic_Timeout(
#define _Rate_monotonic_Reset_wall_time_statistics( _the_period ) \ #define _Rate_monotonic_Reset_wall_time_statistics( _the_period ) \
do { \ do { \
/* set the minimums to a large value */ \ /* set the minimums to a large value */ \
(_the_period)->Statistics.min_wall_time.tv_sec = 0x7fffffff; \ _Timestamp_Set( \
(_the_period)->Statistics.min_wall_time.tv_nsec = 0x7fffffff; \ &(_the_period)->Statistics.min_wall_time, \
0x7fffffff, \
0x7fffffff \
); \
} while (0) } while (0)
#else #else
#define _Rate_monotonic_Reset_wall_time_statistics( _the_period ) #define _Rate_monotonic_Reset_wall_time_statistics( _the_period )
@@ -398,8 +403,11 @@ void _Rate_monotonic_Timeout(
#define _Rate_monotonic_Reset_cpu_use_statistics( _the_period ) \ #define _Rate_monotonic_Reset_cpu_use_statistics( _the_period ) \
do { \ do { \
/* set the minimums to a large value */ \ /* set the minimums to a large value */ \
(_the_period)->Statistics.min_cpu_time.tv_sec = 0x7fffffff; \ _Timestamp_Set( \
(_the_period)->Statistics.min_cpu_time.tv_nsec = 0x7fffffff; \ &(_the_period)->Statistics.min_cpu_time, \
0x7fffffff, \
0x7fffffff \
); \
} while (0) } while (0)
#else #else
#define _Rate_monotonic_Reset_cpu_use_statistics( _the_period ) #define _Rate_monotonic_Reset_cpu_use_statistics( _the_period )

View File

@@ -33,6 +33,6 @@ rtems_status_code rtems_clock_get_seconds_since_epoch(
if ( !_TOD_Is_set ) if ( !_TOD_Is_set )
return RTEMS_NOT_DEFINED; return RTEMS_NOT_DEFINED;
*the_interval = _TOD_Seconds_since_epoch; *the_interval = _TOD_Seconds_since_epoch();
return RTEMS_SUCCESSFUL; return RTEMS_SUCCESSFUL;
} }

View File

@@ -20,6 +20,7 @@
#include <rtems/rtems/clock.h> #include <rtems/rtems/clock.h>
#include <rtems/score/isr.h> #include <rtems/score/isr.h>
#include <rtems/score/thread.h> #include <rtems/score/thread.h>
#include <rtems/score/timestamp.h>
#include <rtems/score/tod.h> #include <rtems/score/tod.h>
#include <rtems/score/watchdog.h> #include <rtems/score/watchdog.h>
@@ -45,6 +46,6 @@ rtems_status_code rtems_clock_get_uptime(
if ( !uptime ) if ( !uptime )
return RTEMS_INVALID_ADDRESS; return RTEMS_INVALID_ADDRESS;
_TOD_Get_uptime( uptime ); _TOD_Get_uptime_as_timespec( uptime );
return RTEMS_SUCCESSFUL; return RTEMS_SUCCESSFUL;
} }

View File

@@ -65,14 +65,12 @@ rtems_status_code rtems_rate_monotonic_get_status(
if ( status->state == RATE_MONOTONIC_INACTIVE ) { if ( status->state == RATE_MONOTONIC_INACTIVE ) {
#ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
status->since_last_period.tv_sec = 0; _Timestamp_Set_to_zero( &status->since_last_period );
status->since_last_period.tv_nsec = 0;
#else #else
status->since_last_period = 0; status->since_last_period = 0;
#endif #endif
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
status->executed_since_last_period.tv_sec = 0; _Timestamp_Set_to_zero( &status->executed_since_last_period );
status->executed_since_last_period.tv_nsec = 0;
#else #else
status->executed_since_last_period = 0; status->executed_since_last_period = 0;
#endif #endif
@@ -83,12 +81,12 @@ rtems_status_code rtems_rate_monotonic_get_status(
*/ */
#if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \ #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS) defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
struct timespec uptime; Timestamp_Control uptime;
_TOD_Get_uptime( &uptime ); _TOD_Get_uptime( &uptime );
#endif #endif
#ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
_Timespec_Subtract( _Timestamp_Subtract(
&the_period->time_at_period, &the_period->time_at_period,
&uptime, &uptime,
&status->since_last_period &status->since_last_period
@@ -99,7 +97,7 @@ rtems_status_code rtems_rate_monotonic_get_status(
#endif #endif
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
_Timespec_Subtract( _Timestamp_Subtract(
&_Thread_Time_of_last_context_switch, &_Thread_Time_of_last_context_switch,
&uptime, &uptime,
&status->executed_since_last_period &status->executed_since_last_period

View File

@@ -22,11 +22,6 @@
#include <rtems/score/object.h> #include <rtems/score/object.h>
#include <rtems/rtems/ratemon.h> #include <rtems/rtems/ratemon.h>
#include <rtems/score/thread.h> #include <rtems/score/thread.h>
#if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
#include <rtems/score/timespec.h>
extern struct timespec _Thread_Time_of_last_context_switch;
#endif
void _Rate_monotonic_Update_statistics( void _Rate_monotonic_Update_statistics(
Rate_monotonic_Control *the_period Rate_monotonic_Control *the_period
@@ -40,7 +35,7 @@ void _Rate_monotonic_Update_statistics(
#endif #endif
#if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \ #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS) defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
struct timespec uptime; Timestamp_Control uptime;
/* /*
* Obtain the current time since boot * Obtain the current time since boot
@@ -60,7 +55,7 @@ void _Rate_monotonic_Update_statistics(
#ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
period_start = the_period->time_at_period; period_start = the_period->time_at_period;
_Timespec_Subtract( &period_start, &uptime, &since_last_period ); _Timestamp_Subtract( &period_start, &uptime, &since_last_period );
the_period->time_at_period = uptime; the_period->time_at_period = uptime;
#else #else
since_last_period = _Watchdog_Ticks_since_boot - the_period->time_at_period; since_last_period = _Watchdog_Ticks_since_boot - the_period->time_at_period;
@@ -75,17 +70,17 @@ void _Rate_monotonic_Update_statistics(
used = _Thread_Executing->cpu_time_used; used = _Thread_Executing->cpu_time_used;
/* partial period, cpu usage info reset while executing. Throw away */ /* partial period, cpu usage info reset while executing. Throw away */
if (_Timespec_Less_than( &used, &the_period->owner_executed_at_period)) if (_Timestamp_Less_than( &used, &the_period->owner_executed_at_period))
return; return;
/* How much time time since last context switch */ /* How much time time since last context switch */
_Timespec_Subtract(&_Thread_Time_of_last_context_switch, &uptime, &ran); _Timestamp_Subtract(&_Thread_Time_of_last_context_switch, &uptime, &ran);
/* executed += ran */ /* executed += ran */
_Timespec_Add_to( &used, &ran ); _Timestamp_Add_to( &used, &ran );
/* executed = current cpu usage - value at start of period */ /* executed = current cpu usage - value at start of period */
_Timespec_Subtract( _Timestamp_Subtract(
&the_period->owner_executed_at_period, &the_period->owner_executed_at_period,
&used, &used,
&executed &executed
@@ -112,12 +107,12 @@ void _Rate_monotonic_Update_statistics(
*/ */
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
_Timespec_Add_to( &stats->total_cpu_time, &executed ); _Timestamp_Add_to( &stats->total_cpu_time, &executed );
if ( _Timespec_Less_than( &executed, &stats->min_cpu_time ) ) if ( _Timestamp_Less_than( &executed, &stats->min_cpu_time ) )
stats->min_cpu_time = executed; stats->min_cpu_time = executed;
if ( _Timespec_Greater_than( &executed, &stats->max_cpu_time ) ) if ( _Timestamp_Greater_than( &executed, &stats->max_cpu_time ) )
stats->max_cpu_time = executed; stats->max_cpu_time = executed;
#else #else
stats->total_cpu_time += executed; stats->total_cpu_time += executed;
@@ -142,12 +137,12 @@ void _Rate_monotonic_Update_statistics(
if ( since_last_period > stats->max_wall_time ) if ( since_last_period > stats->max_wall_time )
stats->max_wall_time = since_last_period; stats->max_wall_time = since_last_period;
#else #else
_Timespec_Add_to( &stats->total_wall_time, &since_last_period ); _Timestamp_Add_to( &stats->total_wall_time, &since_last_period );
if ( _Timespec_Less_than( &since_last_period, &stats->min_wall_time ) ) if ( _Timestamp_Less_than( &since_last_period, &stats->min_wall_time ) )
stats->min_wall_time = since_last_period; stats->min_wall_time = since_last_period;
if ( _Timespec_Greater_than( &since_last_period, &stats->max_wall_time ) ) if ( _Timestamp_Greater_than( &since_last_period, &stats->max_wall_time ) )
stats->max_wall_time = since_last_period; stats->max_wall_time = since_last_period;
#endif #endif
} }
@@ -211,7 +206,7 @@ rtems_status_code rtems_rate_monotonic_period(
case RATE_MONOTONIC_INACTIVE: { case RATE_MONOTONIC_INACTIVE: {
#if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \ #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS) defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
struct timespec uptime; Timestamp_Control uptime;
#endif #endif
/* /*
@@ -244,7 +239,7 @@ rtems_status_code rtems_rate_monotonic_period(
_Thread_Executing->cpu_time_used; _Thread_Executing->cpu_time_used;
/* How much time time since last context switch */ /* How much time time since last context switch */
_Timespec_Subtract( _Timestamp_Subtract(
&_Thread_Time_of_last_context_switch, &_Thread_Time_of_last_context_switch,
&uptime, &uptime,
&ran &ran
@@ -254,7 +249,7 @@ rtems_status_code rtems_rate_monotonic_period(
* *
* the_period->owner_executed_at_period += ran * the_period->owner_executed_at_period += ran
*/ */
_Timespec_Add_to( &the_period->owner_executed_at_period, &ran ); _Timestamp_Add_to( &the_period->owner_executed_at_period, &ran );
} }
#else #else
the_period->owner_executed_at_period = the_period->owner_executed_at_period =

View File

@@ -24,7 +24,7 @@
#if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \ #if defined(RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS) || \
defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS) defined(RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS)
#include <rtems/score/timespec.h> #include <rtems/score/timestamp.h>
/* We print to 1/10's of milliseconds */ /* We print to 1/10's of milliseconds */
#define NANOSECONDS_DIVIDER 1000 #define NANOSECONDS_DIVIDER 1000
@@ -149,23 +149,22 @@ ididididid NNNN ccccc mmmmmm X
*/ */
{ {
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
struct timespec cpu_average; Timestamp_Control cpu_average;
Timestamp_Control *min_cpu = &the_stats.min_cpu_time;
Timestamp_Control *max_cpu = &the_stats.max_cpu_time;
Timestamp_Control *total_cpu = &the_stats.total_cpu_time;
_Timespec_Divide_by_integer( _Timestamp_Divide_by_integer( total_cpu, the_stats.count, &cpu_average );
&the_stats.total_cpu_time,
the_stats.count,
&cpu_average
);
(*print)( context, (*print)( context,
"%" PRId32 "." NANOSECONDS_FMT "/" /* min cpu time */ "%" PRId32 "." NANOSECONDS_FMT "/" /* min cpu time */
"%" PRId32 "." NANOSECONDS_FMT "/" /* max cpu time */ "%" PRId32 "." NANOSECONDS_FMT "/" /* max cpu time */
"%" PRId32 "." NANOSECONDS_FMT " ", /* avg cpu time */ "%" PRId32 "." NANOSECONDS_FMT " ", /* avg cpu time */
the_stats.min_cpu_time.tv_sec, _Timestamp_Get_seconds( min_cpu ),
the_stats.min_cpu_time.tv_nsec / NANOSECONDS_DIVIDER, _Timestamp_Get_nanoseconds( min_cpu ) / NANOSECONDS_DIVIDER,
the_stats.max_cpu_time.tv_sec, _Timestamp_Get_seconds( max_cpu ),
the_stats.max_cpu_time.tv_nsec / NANOSECONDS_DIVIDER, _Timestamp_Get_nanoseconds( max_cpu ) / NANOSECONDS_DIVIDER,
cpu_average.tv_sec, _Timestamp_Get_seconds( &cpu_average ),
cpu_average.tv_nsec / NANOSECONDS_DIVIDER _Timestamp_Get_nanoseconds( &cpu_average ) / NANOSECONDS_DIVIDER
); );
#else #else
uint32_t ival_cpu, fval_cpu; uint32_t ival_cpu, fval_cpu;
@@ -186,22 +185,22 @@ ididididid NNNN ccccc mmmmmm X
*/ */
{ {
#ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_RATE_MONOTONIC_STATISTICS
struct timespec wall_average; Timestamp_Control wall_average;
_Timespec_Divide_by_integer( Timestamp_Control *min_wall = &the_stats.min_wall_time;
&the_stats.total_wall_time, Timestamp_Control *max_wall = &the_stats.max_wall_time;
the_stats.count, Timestamp_Control *total_wall = &the_stats.total_wall_time;
&wall_average
); _Timestamp_Divide_by_integer(total_wall, the_stats.count, &wall_average);
(*print)( context, (*print)( context,
"%" PRId32 "." NANOSECONDS_FMT "/" /* min wall time */ "%" PRId32 "." NANOSECONDS_FMT "/" /* min wall time */
"%" PRId32 "." NANOSECONDS_FMT "/" /* max wall time */ "%" PRId32 "." NANOSECONDS_FMT "/" /* max wall time */
"%" PRId32 "." NANOSECONDS_FMT "\n", /* avg wall time */ "%" PRId32 "." NANOSECONDS_FMT "\n", /* avg wall time */
the_stats.min_wall_time.tv_sec, _Timestamp_Get_seconds( min_wall ),
the_stats.min_wall_time.tv_nsec / NANOSECONDS_DIVIDER, _Timestamp_Get_nanoseconds( min_wall ) / NANOSECONDS_DIVIDER,
the_stats.max_wall_time.tv_sec, _Timestamp_Get_seconds( max_wall ),
the_stats.max_wall_time.tv_nsec / NANOSECONDS_DIVIDER, _Timestamp_Get_nanoseconds( max_wall ) / NANOSECONDS_DIVIDER,
wall_average.tv_sec, _Timestamp_Get_seconds( &wall_average ),
wall_average.tv_nsec / NANOSECONDS_DIVIDER _Timestamp_Get_nanoseconds( &wall_average ) / NANOSECONDS_DIVIDER
); );
#else #else
uint32_t ival_wall, fval_wall; uint32_t ival_wall, fval_wall;

View File

@@ -67,7 +67,7 @@ rtems_status_code rtems_task_wake_when(
seconds = _TOD_To_seconds( time_buffer ); seconds = _TOD_To_seconds( time_buffer );
if ( seconds <= _TOD_Seconds_since_epoch ) if ( seconds <= _TOD_Seconds_since_epoch() )
return RTEMS_INVALID_CLOCK; return RTEMS_INVALID_CLOCK;
_Thread_Disable_dispatch(); _Thread_Disable_dispatch();
@@ -80,7 +80,7 @@ rtems_status_code rtems_task_wake_when(
); );
_Watchdog_Insert_seconds( _Watchdog_Insert_seconds(
&_Thread_Executing->Timer, &_Thread_Executing->Timer,
seconds - _TOD_Seconds_since_epoch seconds - _TOD_Seconds_since_epoch()
); );
_Thread_Enable_dispatch(); _Thread_Enable_dispatch();
return RTEMS_SUCCESSFUL; return RTEMS_SUCCESSFUL;

View File

@@ -63,7 +63,7 @@ rtems_status_code rtems_timer_fire_when(
return RTEMS_INVALID_ADDRESS; return RTEMS_INVALID_ADDRESS;
seconds = _TOD_To_seconds( wall_time ); seconds = _TOD_To_seconds( wall_time );
if ( seconds <= _TOD_Seconds_since_epoch ) if ( seconds <= _TOD_Seconds_since_epoch() )
return RTEMS_INVALID_CLOCK; return RTEMS_INVALID_CLOCK;
the_timer = _Timer_Get( id, &location ); the_timer = _Timer_Get( id, &location );
@@ -75,7 +75,7 @@ rtems_status_code rtems_timer_fire_when(
_Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data ); _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
_Watchdog_Insert_seconds( _Watchdog_Insert_seconds(
&the_timer->Ticker, &the_timer->Ticker,
seconds - _TOD_Seconds_since_epoch seconds - _TOD_Seconds_since_epoch()
); );
_Thread_Enable_dispatch(); _Thread_Enable_dispatch();
return RTEMS_SUCCESSFUL; return RTEMS_SUCCESSFUL;

View File

@@ -189,7 +189,7 @@ static void _Timer_Server_process_seconds_chain(
* of Day (TOD) has not been set backwards. If it has then * of Day (TOD) has not been set backwards. If it has then
* we want to adjust the _Timer_Seconds_chain to indicate this. * we want to adjust the _Timer_Seconds_chain to indicate this.
*/ */
snapshot = _TOD_Seconds_since_epoch; snapshot = _TOD_Seconds_since_epoch();
if ( snapshot > _Timer_Server_seconds_last_time ) { if ( snapshot > _Timer_Server_seconds_last_time ) {
/* /*
* This path is for normal forward movement and cases where the * This path is for normal forward movement and cases where the
@@ -232,7 +232,7 @@ Thread _Timer_Server_body(
* the server was initiated. * the server was initiated.
*/ */
_Timer_Server_ticks_last_time = _Watchdog_Ticks_since_boot; _Timer_Server_ticks_last_time = _Watchdog_Ticks_since_boot;
_Timer_Server_seconds_last_time = _TOD_Seconds_since_epoch; _Timer_Server_seconds_last_time = _TOD_Seconds_since_epoch();
/* /*
* Insert the timers that were inserted before we got to run. * Insert the timers that were inserted before we got to run.

View File

@@ -67,7 +67,7 @@ rtems_status_code rtems_timer_server_fire_when(
return RTEMS_INVALID_CLOCK; return RTEMS_INVALID_CLOCK;
seconds = _TOD_To_seconds( wall_time ); seconds = _TOD_To_seconds( wall_time );
if ( seconds <= _TOD_Seconds_since_epoch ) if ( seconds <= _TOD_Seconds_since_epoch() )
return RTEMS_INVALID_CLOCK; return RTEMS_INVALID_CLOCK;
the_timer = _Timer_Get( id, &location ); the_timer = _Timer_Get( id, &location );
@@ -77,7 +77,7 @@ rtems_status_code rtems_timer_server_fire_when(
(void) _Watchdog_Remove( &the_timer->Ticker ); (void) _Watchdog_Remove( &the_timer->Ticker );
the_timer->the_class = TIMER_TIME_OF_DAY_ON_TASK; the_timer->the_class = TIMER_TIME_OF_DAY_ON_TASK;
_Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data ); _Watchdog_Initialize( &the_timer->Ticker, routine, id, user_data );
the_timer->Ticker.initial = seconds - _TOD_Seconds_since_epoch; the_timer->Ticker.initial = seconds - _TOD_Seconds_since_epoch();
/* /*
* _Timer_Server_schedule_operation != NULL because we checked that * _Timer_Server_schedule_operation != NULL because we checked that

View File

@@ -29,10 +29,10 @@ include_rtems_score_HEADERS = include/rtems/score/address.h \
include/rtems/score/stack.h include/rtems/score/states.h \ include/rtems/score/stack.h include/rtems/score/states.h \
include/rtems/score/sysstate.h include/rtems/score/thread.h \ include/rtems/score/sysstate.h include/rtems/score/thread.h \
include/rtems/score/threadq.h include/rtems/score/threadsync.h \ include/rtems/score/threadq.h include/rtems/score/threadsync.h \
include/rtems/score/timespec.h include/rtems/score/tod.h \ include/rtems/score/timespec.h include/rtems/score/timestamp.h \
include/rtems/score/tqdata.h include/rtems/score/userext.h \ include/rtems/score/tod.h include/rtems/score/tqdata.h \
include/rtems/score/watchdog.h include/rtems/score/wkspace.h \ include/rtems/score/userext.h include/rtems/score/watchdog.h \
include/rtems/score/cpuopts.h include/rtems/score/wkspace.h include/rtems/score/cpuopts.h
if HAS_MP if HAS_MP
# We only build multiprocessing related files if HAS_MP was defined # We only build multiprocessing related files if HAS_MP was defined
@@ -169,7 +169,7 @@ libscore_a_SOURCES += src/timespecaddto.c src/timespecfromticks.c \
## TOD_C_FILES ## TOD_C_FILES
libscore_a_SOURCES += src/coretod.c src/coretodset.c src/coretodget.c \ libscore_a_SOURCES += src/coretod.c src/coretodset.c src/coretodget.c \
src/coretodgetuptime.c src/coretodtickle.c src/coretodgetuptime.c src/coretodgetuptimetimespec.c src/coretodtickle.c
## WATCHDOG_C_FILES ## WATCHDOG_C_FILES
libscore_a_SOURCES += src/watchdog.c src/watchdogadjust.c \ libscore_a_SOURCES += src/watchdog.c src/watchdogadjust.c \

View File

@@ -36,6 +36,8 @@ extern "C" {
* resolution. * resolution.
*/ */
#ifndef __RTEMS_USE_TICKS_CPU_USAGE_STATISTICS__ #ifndef __RTEMS_USE_TICKS_CPU_USAGE_STATISTICS__
#include <rtems/score/timestamp.h>
/** /**
* This macro enables the nanosecond accurate statistics * This macro enables the nanosecond accurate statistics
* *
@@ -44,7 +46,7 @@ extern "C" {
*/ */
#define RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS #define RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
typedef struct timespec rtems_thread_cpu_usage_t; typedef Timestamp_Control rtems_thread_cpu_usage_t;
#else #else
typedef uint32_t rtems_thread_cpu_usage_t; typedef uint32_t rtems_thread_cpu_usage_t;
@@ -500,7 +502,7 @@ SCORE_EXTERN struct _reent **_Thread_libc_reent;
* system initialization and does not need to be known outside this * system initialization and does not need to be known outside this
* file. * file.
*/ */
SCORE_EXTERN struct timespec _Thread_Time_of_last_context_switch; SCORE_EXTERN Timestamp_Control _Thread_Time_of_last_context_switch;
#endif #endif
/** /**

View File

@@ -0,0 +1,305 @@
/**
* @file rtems/score/timestamp.h
*
* This include file contains helpers for manipulating timestamps.
*/
/*
* COPYRIGHT (c) 1989-2008.
* 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$
*/
#ifndef _RTEMS_SCORE_TIMESTAMP_H
#define _RTEMS_SCORE_TIMESTAMP_H
/**
* @defgroup SuperCore Timestamp
*
* This handler encapsulates functionality related to manipulating
* SuperCore Timestamps. SuperCore Timestamps may be used to
* represent time of day, uptime, or intervals.
*
* The key attribute of the SuperCore Timestamp handler is that it
* is a completely opaque handler. There can be multiple implementations
* of the required functionality and with a recompile, RTEMS can use
* any implementation. It is intended to be a simple wrapper.
*
* This handler can be implemented as either struct timespec or
* unsigned64 bit numbers. The use of a wrapper class allows the
* the implementation of timestamps to change on a per architecture
* basis. This is an important option as the performance of this
* handler is critical.
*/
/**@{*/
#ifdef __cplusplus
extern "C" {
#endif
#include <rtems/score/timespec.h>
#define RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC
/**
* Define the Timestamp control type.
*/
#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
typedef struct timespec Timestamp_Control;
#else
#error "No Alternative implementations for SuperCore Timestamp."
#endif
/** @brief Set Timestamp to Seconds Nanosecond
*
* This method sets the timestamp to the specified seconds and nanoseconds
* value.
*
* @param[in] _time points to the timestamp instance to validate.
* @param[in] _seconds is the seconds portion of the timestamp
* @param[in] _nanoseconds is the nanoseconds portion of the timestamp
*/
#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
#define _Timestamp_Set( _time, _seconds, _nanoseconds ) \
do { \
(_time)->tv_sec = (_seconds); \
(_time)->tv_nsec = (_nanoseconds); \
} while (0)
#endif
/** @brief Zero Timestamp
*
* This method sets the timestamp to zero.
* value.
*
* @param[in] _time points to the timestamp instance to zero.
*/
#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
#define _Timestamp_Set_to_zero( _time ) \
do { \
(_time)->tv_sec = 0; \
(_time)->tv_nsec = 0; \
} while (0)
#endif
/** @brief Is Timestamp Valid
*
* This method determines the validity of a timestamp.
*
* @param[in] time is the timestamp instance to validate.
*
* @return This method returns true if @a time is valid and
* false otherwise.
*/
#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
#define _Timestamp_Is_valid( _time ) \
_Timespec_Is_valid( _time )
#endif
/** @brief Timestamp Less Than Operator
*
* This method is the less than operator for timestamps.
*
* @param[in] lhs is the left hand side timestamp
* @param[in] rhs is the right hand side timestamp
*
* @return This method returns true if @a lhs is less than the @a rhs and
* false otherwise.
*/
#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
#define _Timestamp_Less_than( _lhs, _rhs ) \
_Timespec_Less_than( _lhs, _rhs )
#endif
/** @brief Timestamp Greater Than Operator
*
* This method is the greater than operator for timestamps.
*
* @param[in] lhs is the left hand side timestamp
* @param[in] rhs is the right hand side timestamp
*
* @return This method returns true if @a lhs is greater than the @a rhs and
* false otherwise.
*/
#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
#define _Timestamp_Greater_than( _lhs, _rhs ) \
_Timespec_Greater_than( _lhs, _rhs )
#endif
/** @brief Timestamp equal to Operator
*
* This method is the is equal to than operator for timestamps.
*
* @param[in] lhs is the left hand side timestamp
* @param[in] rhs is the right hand side timestamp
*
* @return This method returns true if @a lhs is equal to @a rhs and
* false otherwise.
*/
#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
#define _Timestamp_Equal_to( _lhs, _rhs ) \
_Timespec_Equal_to( _lhs, _rhs )
#endif
/** @brief Add to a Timestamp
*
* This routine adds two timestamps. The second argument is added
* to the first.
*
* @param[in] time points to the base time to be added to
* @param[in] add points to the timestamp to add to the first argument
*/
#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
#define _Timestamp_Add_to( _time, _add ) \
_Timespec_Add_to( _time, _add )
#endif
/** @brief Add to a Timestamp (At Clock Tick)
*
* This routine adds two timestamps. The second argument is added
* to the first.
*
* @node This routine places a special requirement on the addition
* operation. It must return the number of units that the
* seconds field changed as the result of the addition. Since this
* operation is ONLY used as part of processing a clock tick,
* it is generally safe to assume that only one second changed.
*
* @param[in] time points to the base time to be added to
* @param[in] add points to the timestamp to add to the first argument
*
* @return This method returns the number of seconds @a time increased by.
*/
#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
#define _Timestamp_Add_to_at_tick( _time, _add ) \
_Timespec_Add_to( _time, _add )
#endif
/** @brief Convert Timestamp to Number of Ticks
*
* This routine convert the @a time timestamp to the corresponding number
* of clock ticks.
*
* @param[in] time points to the time to be converted
*
* @return This method returns the number of ticks computed.
*/
#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
#define _Timestamp_To_ticks( _time ) \
_Timespec_To_ticks( _time )
#endif
/** @brief Convert Ticks to Timestamp
*
* This routine converts the @a ticks value to the corresponding
* timestamp format @a time.
*
* @param[in] time points to the timestamp format time result
* @param[in] ticks points to the the number of ticks to be filled in
*/
#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
#define _Timestamp_From_ticks( _ticks, _time ) \
_Timespec_From_ticks( _ticks, _time )
#endif
/** @brief Subtract Two Timestamp
*
* This routine subtracts two timestamps. @a result is set to
* @a end - @a start.
*
* @param[in] start points to the starting time
* @param[in] end points to the ending time
* @param[in] result points to the difference between starting and ending time.
*
* @return This method fills in @a result.
*/
#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
#define _Timestamp_Subtract( _start, _end, _result ) \
_Timespec_Subtract( _start, _end, _result )
#endif
/** @brief Divide Timestamp By Integer
*
* This routine divides a timestamp by an integer value. The expected
* use is to assist in benchmark calculations where you typically
* divide a duration by a number of iterations.
*
* @param[in] time points to the total
* @param[in] iterations is the number of iterations
* @param[in] result points to the average time.
*
* @return This method fills in @a result.
*/
#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
#define _Timestamp_Divide_by_integer( _time, _iterations, _result ) \
_Timespec_Divide_by_integer(_time, _iterations, _result )
#endif
/** @brief Divide Timestamp
*
* This routine divides a timestamp by another timestamp. The
* intended use is for calculating percentages to three decimal points.
*
* @param[in] lhs points to the left hand number
* @param[in] rhs points to the right hand number
* @param[in] ival_percentage is the integer portion of the average
* @param[in] fval_percentage is the thousandths of percentage
*
* @return This method fills in @a result.
*/
#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
#define _Timestamp_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage ) \
_Timespec_Divide( _lhs, _rhs, _ival_percentage, _fval_percentage )
#endif
/** @brief Get Seconds Portion of Timestamp
*
* This method returns the seconds portion of the specified timestamp
*
* @param[in] _time points to the timestamp
*
* @return The seconds portion of @a _time.
*/
#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
#define _Timestamp_Get_seconds( _time ) \
((_time)->tv_sec)
#endif
/** @brief Get Nanoseconds Portion of Timestamp
*
* This method returns the nanoseconds portion of the specified timestamp
*
* @param[in] _time points to the timestamp
*
* @return The nanoseconds portion of @a _time.
*/
#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
#define _Timestamp_Get_nanoseconds( _time ) \
((_time)->tv_nsec)
#endif
/** @brief Convert Timestamp to struct timespec
*
* This method returns the seconds portion of the specified timestamp
*
* @param[in] _timestamp points to the timestamp
* @param[in] _timespec points to the timespec
*/
#if defined(RTEMS_SCORE_TIMESTAMP_IS_STRUCT_SPEC)
#define _Timestamp_To_timespec( _timestamp, _timespec ) \
*(_timespec) = *(_timestamp)
#endif
#ifdef __cplusplus
}
#endif
/**@}*/
#endif
/* end of include file */

View File

@@ -23,7 +23,7 @@
extern "C" { extern "C" {
#endif #endif
#include <rtems/score/object.h> #include <rtems/score/timestamp.h>
#include <time.h> #include <time.h>
/** @defgroup ScoreTODConstants TOD Constants /** @defgroup ScoreTODConstants TOD Constants
@@ -134,18 +134,19 @@ SCORE_EXTERN bool _TOD_Is_set;
/** @brief Current Time of Day (Timespec) /** @brief Current Time of Day (Timespec)
* The following contains the current time of day. * The following contains the current time of day.
*/ */
SCORE_EXTERN struct timespec _TOD_Now; SCORE_EXTERN Timestamp_Control _TOD_Now;
/** @brief Current Time of Day (Timespec) /** @brief Current Time of Day (Timespec)
* The following contains the running uptime. * The following contains the running uptime.
*/ */
SCORE_EXTERN struct timespec _TOD_Uptime; SCORE_EXTERN Timestamp_Control _TOD_Uptime;
/** @brief Seconds Since RTEMS Epoch /** @brief Seconds Since RTEMS Epoch
* The following contains the number of seconds from 00:00:00 * The following contains the number of seconds from 00:00:00
* January 1, TOD_BASE_YEAR until the current time of day. * January 1, TOD_BASE_YEAR until the current time of day.
*/ */
#define _TOD_Seconds_since_epoch (_TOD_Now.tv_sec) #define _TOD_Seconds_since_epoch() \
_Timestamp_Get_seconds(&_TOD_Now)
/** @brief Microseconds per Clock Tick /** @brief Microseconds per Clock Tick
* *
@@ -189,6 +190,17 @@ void _TOD_Get(
* @param[in] time is a pointer to the uptime to be returned * @param[in] time is a pointer to the uptime to be returned
*/ */
void _TOD_Get_uptime( void _TOD_Get_uptime(
Timestamp_Control *time
);
/** @brief _TOD_Get_uptime_as_timespec
*
* This routine returns the system uptime with potential accuracy
* to the nanosecond.
*
* @param[in] time is a pointer to the uptime to be returned
*/
void _TOD_Get_uptime_as_timespec(
struct timespec *time struct timespec *time
); );

View File

@@ -139,6 +139,10 @@ $(PROJECT_INCLUDE)/rtems/score/timespec.h: include/rtems/score/timespec.h $(PROJ
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/timespec.h $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/timespec.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/timespec.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/timespec.h
$(PROJECT_INCLUDE)/rtems/score/timestamp.h: include/rtems/score/timestamp.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/timestamp.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/timestamp.h
$(PROJECT_INCLUDE)/rtems/score/tod.h: include/rtems/score/tod.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp) $(PROJECT_INCLUDE)/rtems/score/tod.h: include/rtems/score/tod.h $(PROJECT_INCLUDE)/rtems/score/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/tod.h $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/score/tod.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/tod.h PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/score/tod.h

View File

@@ -41,12 +41,10 @@ void _TOD_Handler_initialization(
_TOD_Microseconds_per_tick = microseconds_per_tick; _TOD_Microseconds_per_tick = microseconds_per_tick;
/* POSIX format TOD (timespec) */ /* POSIX format TOD (timespec) */
_TOD_Now.tv_sec = TOD_SECONDS_1970_THROUGH_1988; _Timestamp_Set( &_TOD_Now, TOD_SECONDS_1970_THROUGH_1988, 0 );
_TOD_Now.tv_nsec = 0;
/* Uptime (timespec) */ /* Uptime (timespec) */
_TOD_Uptime.tv_sec = 0; _Timestamp_Set_to_zero( &_TOD_Uptime );
_TOD_Uptime.tv_nsec = 0;
/* TOD has not been set */ /* TOD has not been set */
_TOD_Is_set = FALSE; _TOD_Is_set = FALSE;

View File

@@ -18,6 +18,7 @@
#include <rtems/system.h> #include <rtems/system.h>
#include <rtems/score/isr.h> #include <rtems/score/isr.h>
#include <rtems/score/timespec.h> #include <rtems/score/timespec.h>
#include <rtems/score/timestamp.h>
#include <rtems/score/tod.h> #include <rtems/score/tod.h>
#include <rtems/score/watchdog.h> #include <rtems/score/watchdog.h>
@@ -37,19 +38,21 @@ void _TOD_Get(
) )
{ {
ISR_Level level; ISR_Level level;
struct timespec offset; Timestamp_Control offset;
Timestamp_Control now;
long nanoseconds;
/* assume time checked by caller */ /* assume time checked for NULL by caller */
offset.tv_sec = 0; /* _TOD_Now is the native current time */
offset.tv_nsec = 0; nanoseconds = 0;
/* _TOD_Now is a proper POSIX time */
_ISR_Disable( level ); _ISR_Disable( level );
*time = _TOD_Now; now = _TOD_Now;
if ( _Watchdog_Nanoseconds_since_tick_handler ) if ( _Watchdog_Nanoseconds_since_tick_handler )
offset.tv_nsec = (*_Watchdog_Nanoseconds_since_tick_handler)(); nanoseconds = (*_Watchdog_Nanoseconds_since_tick_handler)();
_ISR_Enable( level ); _ISR_Enable( level );
_Timespec_Add_to( time, &offset ); _Timestamp_Set( &offset, 0, nanoseconds );
_Timestamp_Add_to( &now, &offset );
_Timestamp_To_timespec( &now, time );
} }

View File

@@ -18,7 +18,7 @@
#include <rtems/system.h> #include <rtems/system.h>
#include <rtems/score/isr.h> #include <rtems/score/isr.h>
#include <rtems/score/timespec.h> #include <rtems/score/timestamp.h>
#include <rtems/score/tod.h> #include <rtems/score/tod.h>
#include <rtems/score/watchdog.h> #include <rtems/score/watchdog.h>
@@ -28,28 +28,30 @@
* This routine is used to obtain the system uptime * This routine is used to obtain the system uptime
* *
* Input parameters: * Input parameters:
* time - pointer to the time and date structure * time - pointer to the timestamp structure
* *
* Output parameters: NONE * Output parameters: NONE
*/ */
void _TOD_Get_uptime( void _TOD_Get_uptime(
struct timespec *uptime Timestamp_Control *uptime
) )
{ {
ISR_Level level; ISR_Level level;
struct timespec offset; Timestamp_Control offset;
Timestamp_Control up;
long nanoseconds;
/* assume uptime checked by caller */ /* assume time checked for NULL by caller */
offset.tv_sec = 0;
offset.tv_nsec = 0;
/* _TOD_Uptime is in native timestamp format */
nanoseconds = 0;
_ISR_Disable( level ); _ISR_Disable( level );
*uptime = _TOD_Uptime; up= _TOD_Uptime;
if ( _Watchdog_Nanoseconds_since_tick_handler ) if ( _Watchdog_Nanoseconds_since_tick_handler )
offset.tv_nsec = (*_Watchdog_Nanoseconds_since_tick_handler)(); nanoseconds = (*_Watchdog_Nanoseconds_since_tick_handler)();
_ISR_Enable( level ); _ISR_Enable( level );
_Timespec_Add_to( uptime, &offset ); _Timestamp_Set( &offset, 0, nanoseconds );
_Timestamp_Add_to( &up, &offset );
} }

View File

@@ -0,0 +1,44 @@
/*
* Time of Day (TOD) Handler - get uptime
*/
/* COPYRIGHT (c) 1989-2008.
* 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/score/isr.h>
#include <rtems/score/timestamp.h>
#include <rtems/score/tod.h>
/*
* _TOD_Get_uptime_as_timespec
*
* This routine is used to obtain the system uptime
*
* Input parameters:
* time - pointer to the timestamp structure
*
* Output parameters: NONE
*/
void _TOD_Get_uptime_as_timespec(
struct timespec *uptime
)
{
Timestamp_Control uptime_ts;
/* assume time checked for NULL by caller */
_TOD_Get_uptime( &uptime_ts );
_Timestamp_To_timespec( &uptime_ts, uptime );
}

View File

@@ -19,6 +19,7 @@
#include <rtems/system.h> #include <rtems/system.h>
#include <rtems/score/object.h> #include <rtems/score/object.h>
#include <rtems/score/thread.h> #include <rtems/score/thread.h>
#include <rtems/score/timestamp.h>
#include <rtems/score/tod.h> #include <rtems/score/tod.h>
#include <rtems/score/watchdog.h> #include <rtems/score/watchdog.h>
@@ -39,18 +40,20 @@ void _TOD_Set(
const struct timespec *time const struct timespec *time
) )
{ {
long seconds;
_Thread_Disable_dispatch(); _Thread_Disable_dispatch();
_TOD_Deactivate(); _TOD_Deactivate();
if ( time->tv_sec < _TOD_Seconds_since_epoch ) seconds = _TOD_Seconds_since_epoch();
_Watchdog_Adjust_seconds( WATCHDOG_BACKWARD,
_TOD_Seconds_since_epoch - time->tv_sec ); if ( time->tv_sec < seconds )
_Watchdog_Adjust_seconds( WATCHDOG_BACKWARD, seconds - time->tv_sec );
else else
_Watchdog_Adjust_seconds( WATCHDOG_FORWARD, _Watchdog_Adjust_seconds( WATCHDOG_FORWARD, time->tv_sec - seconds );
time->tv_sec - _TOD_Seconds_since_epoch );
/* POSIX format TOD (timespec) */ /* POSIX format TOD (timespec) */
_TOD_Now = *time; _Timestamp_Set( &_TOD_Now, time->tv_sec, time->tv_nsec );
_TOD_Is_set = TRUE; _TOD_Is_set = TRUE;
_TOD_Activate(); _TOD_Activate();

View File

@@ -19,7 +19,7 @@
#include <rtems/system.h> #include <rtems/system.h>
#include <rtems/score/object.h> #include <rtems/score/object.h>
#include <rtems/score/thread.h> #include <rtems/score/thread.h>
#include <rtems/score/timespec.h> #include <rtems/score/timestamp.h>
#include <rtems/score/tod.h> #include <rtems/score/tod.h>
#include <rtems/score/watchdog.h> #include <rtems/score/watchdog.h>
@@ -36,22 +36,21 @@
void _TOD_Tickle_ticks( void ) void _TOD_Tickle_ticks( void )
{ {
struct timespec tick; Timestamp_Control tick;
uint32_t seconds; uint32_t seconds;
/* Convert the tick quantum to a timespec */ /* Convert the tick quantum to a timestamp */
tick.tv_nsec = _TOD_Microseconds_per_tick * 1000; _Timestamp_Set( &tick, 0, _TOD_Microseconds_per_tick * 1000 );
tick.tv_sec = 0;
/* Update the counter of ticks since boot */ /* Update the counter of ticks since boot */
_Watchdog_Ticks_since_boot += 1; _Watchdog_Ticks_since_boot += 1;
/* Update the timespec format uptime */ /* Update the timespec format uptime */
(void) _Timespec_Add_to( &_TOD_Uptime, &tick ); _Timestamp_Add_to( &_TOD_Uptime, &tick );
/* we do not care how much the uptime changed */ /* we do not care how much the uptime changed */
/* Update the timespec format TOD */ /* Update the timespec format TOD */
seconds = _Timespec_Add_to( &_TOD_Now, &tick ); seconds = _Timestamp_Add_to_at_tick( &_TOD_Now, &tick );
while ( seconds ) { while ( seconds ) {
_Watchdog_Tickle_seconds(); _Watchdog_Tickle_seconds();
seconds--; seconds--;

View File

@@ -31,7 +31,7 @@
#include <rtems/score/wkspace.h> #include <rtems/score/wkspace.h>
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
#include <rtems/score/timespec.h> #include <rtems/score/timestamp.h>
#endif #endif
/*PAGE /*PAGE
@@ -103,10 +103,14 @@ void _Thread_Dispatch( void )
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
{ {
struct timespec uptime, ran; Timestamp_Control uptime, ran;
_TOD_Get_uptime( &uptime ); _TOD_Get_uptime( &uptime );
_Timespec_Subtract(&_Thread_Time_of_last_context_switch, &uptime, &ran); _Timestamp_Subtract(
_Timespec_Add_to( &executing->cpu_time_used, &ran ); &_Thread_Time_of_last_context_switch,
&uptime,
&ran
);
_Timestamp_Add_to( &executing->cpu_time_used, &ran );
_Thread_Time_of_last_context_switch = uptime; _Thread_Time_of_last_context_switch = uptime;
} }
#else #else

View File

@@ -206,8 +206,7 @@ bool _Thread_Initialize(
*/ */
#ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS #ifdef RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
the_thread->cpu_time_used.tv_sec = 0; _Timestamp_Set_to_zero( &the_thread->cpu_time_used );
the_thread->cpu_time_used.tv_nsec = 0;
#else #else
the_thread->cpu_time_used = 0; the_thread->cpu_time_used = 0;
#endif #endif