summaryrefslogtreecommitdiffstats
path: root/cpukit/score/include/rtems/score
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2008-12-08 19:41:31 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2008-12-08 19:41:31 +0000
commitc16bcc009b3bec9f653cefbe5247ef9d74352833 (patch)
treebbe12a1ed854be9a8ab090f774b0fc096bb76cc9 /cpukit/score/include/rtems/score
parent2008-12-08 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-c16bcc009b3bec9f653cefbe5247ef9d74352833.tar.bz2
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.
Diffstat (limited to 'cpukit/score/include/rtems/score')
-rw-r--r--cpukit/score/include/rtems/score/thread.h6
-rw-r--r--cpukit/score/include/rtems/score/timestamp.h305
-rw-r--r--cpukit/score/include/rtems/score/tod.h20
3 files changed, 325 insertions, 6 deletions
diff --git a/cpukit/score/include/rtems/score/thread.h b/cpukit/score/include/rtems/score/thread.h
index fbfd971b23..ccdeb3df27 100644
--- a/cpukit/score/include/rtems/score/thread.h
+++ b/cpukit/score/include/rtems/score/thread.h
@@ -36,6 +36,8 @@ extern "C" {
* resolution.
*/
#ifndef __RTEMS_USE_TICKS_CPU_USAGE_STATISTICS__
+ #include <rtems/score/timestamp.h>
+
/**
* This macro enables the nanosecond accurate statistics
*
@@ -44,7 +46,7 @@ extern "C" {
*/
#define RTEMS_ENABLE_NANOSECOND_CPU_USAGE_STATISTICS
- typedef struct timespec rtems_thread_cpu_usage_t;
+ typedef Timestamp_Control rtems_thread_cpu_usage_t;
#else
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
* file.
*/
- SCORE_EXTERN struct timespec _Thread_Time_of_last_context_switch;
+ SCORE_EXTERN Timestamp_Control _Thread_Time_of_last_context_switch;
#endif
/**
diff --git a/cpukit/score/include/rtems/score/timestamp.h b/cpukit/score/include/rtems/score/timestamp.h
new file mode 100644
index 0000000000..0602c8d916
--- /dev/null
+++ b/cpukit/score/include/rtems/score/timestamp.h
@@ -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 */
diff --git a/cpukit/score/include/rtems/score/tod.h b/cpukit/score/include/rtems/score/tod.h
index 6038b686d5..44d4df862e 100644
--- a/cpukit/score/include/rtems/score/tod.h
+++ b/cpukit/score/include/rtems/score/tod.h
@@ -23,7 +23,7 @@
extern "C" {
#endif
-#include <rtems/score/object.h>
+#include <rtems/score/timestamp.h>
#include <time.h>
/** @defgroup ScoreTODConstants TOD Constants
@@ -134,18 +134,19 @@ SCORE_EXTERN bool _TOD_Is_set;
/** @brief Current Time of Day (Timespec)
* 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)
* The following contains the running uptime.
*/
-SCORE_EXTERN struct timespec _TOD_Uptime;
+SCORE_EXTERN Timestamp_Control _TOD_Uptime;
/** @brief Seconds Since RTEMS Epoch
* The following contains the number of seconds from 00:00:00
* 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
*
@@ -189,6 +190,17 @@ void _TOD_Get(
* @param[in] time is a pointer to the uptime to be returned
*/
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
);