[rtems commit] score: Change Timestamp_Control to sbintime_t

Sebastian Huber sebh at rtems.org
Mon Oct 9 12:16:12 UTC 2017


Module:    rtems
Branch:    master
Commit:    65012bfebbc03088f0740b086abb26d2ff6ebd8b
Changeset: http://git.rtems.org/rtems/commit/?id=65012bfebbc03088f0740b086abb26d2ff6ebd8b

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Oct  6 15:41:46 2017 +0200

score: Change Timestamp_Control to sbintime_t

The timestamp are based on the uptime.  There is no need for a 64-bit
seconds part.  The signed 32-bit seconds part of the sbintime_t limits
the uptime to roughly 68 years.

Close #2740.

---

 cpukit/score/include/rtems/score/timecounter.h |  7 ++++
 cpukit/score/include/rtems/score/timestamp.h   | 46 +++++++++-----------------
 cpukit/score/include/rtems/score/todimpl.h     |  5 ++-
 cpukit/score/src/kern_tc.c                     | 19 +++++++++++
 4 files changed, 43 insertions(+), 34 deletions(-)

diff --git a/cpukit/score/include/rtems/score/timecounter.h b/cpukit/score/include/rtems/score/timecounter.h
index f00a33b..f7912a5 100644
--- a/cpukit/score/include/rtems/score/timecounter.h
+++ b/cpukit/score/include/rtems/score/timecounter.h
@@ -69,6 +69,13 @@ void _Timecounter_Microtime( struct timeval *tv );
 void _Timecounter_Binuptime( struct bintime *bt );
 
 /**
+ * @brief Returns the uptime in the sbintime_t format.
+ *
+ * @return Returns the uptime.
+ */
+sbintime_t _Timecounter_Sbinuptime( void );
+
+/**
  * @brief Returns the uptime in the timespec format.
  *
  * @param[out] ts Returns the uptime.
diff --git a/cpukit/score/include/rtems/score/timestamp.h b/cpukit/score/include/rtems/score/timestamp.h
index ec297f9..6fc17ce 100644
--- a/cpukit/score/include/rtems/score/timestamp.h
+++ b/cpukit/score/include/rtems/score/timestamp.h
@@ -52,7 +52,7 @@ extern "C" {
 /**
  *   Define the Timestamp control type.
  */
-typedef struct bintime Timestamp_Control;
+typedef sbintime_t Timestamp_Control;
 
 /**
  *  @brief Set timestamp to specified seconds and nanoseconds.
@@ -75,7 +75,7 @@ RTEMS_INLINE_ROUTINE void _Timestamp_Set(
   _ts.tv_sec = _seconds;
   _ts.tv_nsec = _nanoseconds;
 
-  timespec2bintime( &_ts, _time );
+  *_time = tstosbt(_ts);
 }
 
 /**
@@ -91,8 +91,7 @@ RTEMS_INLINE_ROUTINE void _Timestamp_Set_to_zero(
   Timestamp_Control *_time
 )
 {
-  _time->sec = 0;
-  _time->frac = 0;
+  *_time = 0;
 }
 
 /**
@@ -112,13 +111,7 @@ RTEMS_INLINE_ROUTINE bool _Timestamp_Less_than(
   const Timestamp_Control *_rhs
 )
 {
-  if ( _lhs->sec < _rhs->sec )
-    return true;
-
-  if ( _lhs->sec > _rhs->sec )
-    return false;
-
-  return _lhs->frac < _rhs->frac;
+  return *_lhs < *_rhs;
 }
 
 /**
@@ -138,13 +131,7 @@ RTEMS_INLINE_ROUTINE bool _Timestamp_Greater_than(
   const Timestamp_Control *_rhs
 )
 {
-  if ( _lhs->sec > _rhs->sec )
-    return true;
-
-  if ( _lhs->sec < _rhs->sec )
-    return false;
-
-  return _lhs->frac > _rhs->frac;
+  return *_lhs > *_rhs;
 }
 
 /**
@@ -164,7 +151,7 @@ RTEMS_INLINE_ROUTINE bool _Timestamp_Equal_to(
   const Timestamp_Control *_rhs
 )
 {
-  return _lhs->sec == _rhs->sec && _lhs->frac == _rhs->frac;
+  return *_lhs == *_rhs;
 }
 
 /**
@@ -181,7 +168,7 @@ RTEMS_INLINE_ROUTINE void _Timestamp_Add_to(
   const Timestamp_Control *_add
 )
 {
-  bintime_add( _time, _add );
+  *_time += *_add;
 }
 
 /**
@@ -203,10 +190,7 @@ RTEMS_INLINE_ROUTINE void _Timestamp_Subtract(
   Timestamp_Control       *_result
 )
 {
-  _result->sec = _end->sec;
-  _result->frac = _end->frac;
-
-  bintime_sub( _result, _start );
+  *_result = *_end - *_start;
 }
 
 /**
@@ -232,8 +216,8 @@ RTEMS_INLINE_ROUTINE void _Timestamp_Divide(
   struct timespec _ts_left;
   struct timespec _ts_right;
 
-  bintime2timespec( _lhs, &_ts_left );
-  bintime2timespec( _rhs, &_ts_right );
+  _ts_left = sbttots( *_lhs );
+  _ts_right = sbttots( *_rhs );
 
   _Timespec_Divide(
     &_ts_left,
@@ -256,7 +240,7 @@ RTEMS_INLINE_ROUTINE time_t _Timestamp_Get_seconds(
   const Timestamp_Control *_time
 )
 {
-  return _time->sec;
+  return (*_time >> 32);
 }
 
 /**
@@ -274,7 +258,7 @@ RTEMS_INLINE_ROUTINE uint32_t _Timestamp_Get_nanoseconds(
 {
   struct timespec _ts;
 
-  bintime2timespec( _time, &_ts );
+  _ts = sbttots( *_time );
 
   return (uint32_t) _ts.tv_nsec;
 }
@@ -294,7 +278,7 @@ RTEMS_INLINE_ROUTINE uint64_t _Timestamp_Get_as_nanoseconds(
 {
   struct timespec _ts;
 
-  bintime2timespec( _time, &_ts );
+  _ts = sbttots( *_time );
 
   return _Timespec_Get_as_nanoseconds( &_ts );
 }
@@ -312,7 +296,7 @@ RTEMS_INLINE_ROUTINE void _Timestamp_To_timespec(
   struct timespec         *_timespec
 )
 {
-  bintime2timespec( _timestamp, _timespec );
+  *_timespec = sbttots( *_timestamp );
 }
 
 /**
@@ -326,7 +310,7 @@ RTEMS_INLINE_ROUTINE void _Timestamp_To_timeval(
   struct timeval          *_timeval
 )
 {
-  bintime2timeval( _timestamp, _timeval );
+  *_timeval = sbttotv( *_timestamp );
 }
 
 #ifdef __cplusplus
diff --git a/cpukit/score/include/rtems/score/todimpl.h b/cpukit/score/include/rtems/score/todimpl.h
index f5dba85..de4dc93 100644
--- a/cpukit/score/include/rtems/score/todimpl.h
+++ b/cpukit/score/include/rtems/score/todimpl.h
@@ -201,7 +201,7 @@ static inline void _TOD_Get_uptime(
   Timestamp_Control *time
 )
 {
-  _Timecounter_Binuptime( time );
+  *time = _Timecounter_Sbinuptime();
 }
 
 /**
@@ -216,8 +216,7 @@ static inline void _TOD_Get_zero_based_uptime(
   Timestamp_Control *time
 )
 {
-  _Timecounter_Binuptime( time );
-  --time->sec;
+  *time = _Timecounter_Sbinuptime() - SBT_1S;
 }
 
 /**
diff --git a/cpukit/score/src/kern_tc.c b/cpukit/score/src/kern_tc.c
index f385e6d..242983b 100644
--- a/cpukit/score/src/kern_tc.c
+++ b/cpukit/score/src/kern_tc.c
@@ -66,6 +66,7 @@ __FBSDID("$FreeBSD r284178 2015-06-09T11:49:56Z$");
 #endif /* __rtems__ */
 #ifdef __rtems__
 #include <limits.h>
+#include <string.h>
 #include <rtems.h>
 ISR_LOCK_DEFINE(, _Timecounter_Lock, "Timecounter")
 #define _Timecounter_Release(lock_context) \
@@ -469,6 +470,24 @@ binuptime(struct bintime *bt)
 		bintime_addx(bt, th->th_scale * tc_delta(th));
 	} while (gen == 0 || gen != tc_getgen(th));
 }
+#ifdef __rtems__
+sbintime_t
+_Timecounter_Sbinuptime(void)
+{
+	struct timehands *th;
+	uint32_t gen;
+	sbintime_t sbt;
+
+	do {
+		th = timehands;
+		gen = tc_getgen(th);
+		sbt = bttosbt(th->th_offset);
+		sbt += (th->th_scale * tc_delta(th)) >> 32;
+	} while (gen == 0 || gen != tc_getgen(th));
+
+	return (sbt);
+}
+#endif /* __rtems__ */
 
 void
 nanouptime(struct timespec *tsp)




More information about the vc mailing list