[rtems commit] Add _TOD_Adjust to SCORE TOD Handler.

Joel Sherrill joel at rtems.org
Thu Jul 24 21:43:48 UTC 2014


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

Author:    Joel Sherrill <joel.sherrill at oarcorp.com>
Date:      Wed Jul 23 15:35:35 2014 -0500

Add _TOD_Adjust to SCORE TOD Handler.

This lays the proper structure for doing future work on
time adjustment algorithms. Any TOD adjustments should be
requested at the API level and performed at the SCORE level.

Additionally updated a test.

---

 cpukit/posix/src/adjtime.c                 |   30 ++++++++---------
 cpukit/score/Makefile.am                   |    4 +-
 cpukit/score/include/rtems/score/todimpl.h |   12 ++++++
 cpukit/score/src/coretodadjust.c           |   51 ++++++++++++++++++++++++++++
 testsuites/psxtests/psxtime/psxtime.scn    |    1 +
 testsuites/psxtests/psxtime/test.c         |   21 +++++++++--
 6 files changed, 97 insertions(+), 22 deletions(-)

diff --git a/cpukit/posix/src/adjtime.c b/cpukit/posix/src/adjtime.c
index d5a5589..1ebecce 100644
--- a/cpukit/posix/src/adjtime.c
+++ b/cpukit/posix/src/adjtime.c
@@ -44,8 +44,6 @@ int adjtime(
 )
 {
   Timestamp_Control  delta_as_timestamp;
-  Timestamp_Control  tod_as_timestamp;
-  Timestamp_Control *tod_as_timestamp_ptr;
 
   /*
    * Simple validations
@@ -53,8 +51,19 @@ int adjtime(
   if ( !delta )
     rtems_set_errno_and_return_minus_one( EINVAL );
 
+  if ( delta->tv_usec >= TOD_MICROSECONDS_PER_SECOND )
+    rtems_set_errno_and_return_minus_one( EINVAL );
+
+  /*
+   * An adjustment of zero is pretty easy.
+   */
+  if ( delta->tv_sec == 0 && delta->tv_usec == 0 )
+    return 0;
+
   /*
-   * Currently, RTEMS does the adjustment in one movement.
+   * Currently, RTEMS does the adjustment in one movement so there
+   * is no way an adjustment was currently underway.
+   *
    * Given interest, requirements, and sponsorship, a future
    * enhancement would be to adjust the time in smaller increments
    * at each clock tick. Until then, there is no outstanding
@@ -71,20 +80,9 @@ int adjtime(
   _Timestamp_Set( &delta_as_timestamp, delta->tv_sec, delta->tv_usec * 1000 );
 
   /*
-   * This prevents context switches while we are adjusting the TOD
+   * Now apply the adjustment
    */
-
-  _Thread_Disable_dispatch();
-
-    tod_as_timestamp_ptr =
-      _TOD_Get_with_nanoseconds( &tod_as_timestamp, &_TOD.now );
-
-
-    _Timestamp_Add_to( tod_as_timestamp_ptr, &delta_as_timestamp );
-
-    _TOD_Set_with_timestamp( tod_as_timestamp_ptr );
-
-  _Thread_Enable_dispatch();
+  _TOD_Adjust( delta_as_timestamp );
 
   return 0;
 }
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index 431dade..55e10e9 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -319,8 +319,8 @@ libscore_a_SOURCES += src/ts64addto.c src/ts64dividebyinteger.c \
 ## TOD_C_FILES
 libscore_a_SOURCES += src/coretod.c src/coretodset.c src/coretodget.c \
     src/coretodgetuptimetimespec.c src/coretodtickle.c \
-    src/coretodsecondssinceepoch.c \
-    src/coretodtickspersec.c
+    src/coretodsecondssinceepoch.c src/coretodtickspersec.c \
+    src/coretodadjust.c
 
 ## WATCHDOG_C_FILES
 libscore_a_SOURCES += src/watchdog.c src/watchdogadjust.c \
diff --git a/cpukit/score/include/rtems/score/todimpl.h b/cpukit/score/include/rtems/score/todimpl.h
index 9284d45..68a2d15 100644
--- a/cpukit/score/include/rtems/score/todimpl.h
+++ b/cpukit/score/include/rtems/score/todimpl.h
@@ -322,6 +322,18 @@ RTEMS_INLINE_ROUTINE void _TOD_Get_timeval(
   _Timestamp_To_timeval( snapshot_as_timestamp_ptr, time );
 }
 
+/**
+ * @brief Adjust the Time of Time
+ *
+ * This method is used to adjust the current time of day by the
+ * specified amount.
+ *
+ * @param[in] delta is the amount to adjust
+ */
+void _TOD_Adjust(
+  const Timestamp_Control timestamp
+);
+
 RTEMS_INLINE_ROUTINE void _TOD_Set_nanoseconds_since_last_tick_handler(
   TOD_Nanoseconds_since_last_tick_routine routine
 )
diff --git a/cpukit/score/src/coretodadjust.c b/cpukit/score/src/coretodadjust.c
new file mode 100644
index 0000000..09cf01a
--- /dev/null
+++ b/cpukit/score/src/coretodadjust.c
@@ -0,0 +1,51 @@
+/**
+ * @file
+ *
+ * @brief Adjust the Time of Time
+ * @ingroup ScoreTOD
+ */
+
+/*
+ *  COPYRIGHT (c) 1989-2014.
+ *  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.org/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems/score/threaddispatch.h>
+#include <rtems/score/todimpl.h>
+
+void _TOD_Adjust(
+  const Timestamp_Control delta
+)
+{
+  Timestamp_Control  tod;
+  Timestamp_Control *tod_ptr;
+
+  /*
+   * Currently, RTEMS does the adjustment in one movement.
+   * Given interest, requirements, and sponsorship, a future
+   * enhancement would be to adjust the time in smaller increments
+   * at each clock tick. Until then, there is no outstanding
+   * adjustment.
+   */
+
+  /*
+   * This prevents context switches while we are adjusting the TOD
+   */
+  _Thread_Disable_dispatch();
+
+    tod_ptr = _TOD_Get_with_nanoseconds( &tod, &_TOD.now );
+
+    _Timestamp_Add_to( tod_ptr, &delta );
+
+    _TOD_Set_with_timestamp( tod_ptr );
+
+  _Thread_Enable_dispatch();
+}
diff --git a/testsuites/psxtests/psxtime/psxtime.scn b/testsuites/psxtests/psxtime/psxtime.scn
index 174f9d7..2d56b7d 100644
--- a/testsuites/psxtests/psxtime/psxtime.scn
+++ b/testsuites/psxtests/psxtime/psxtime.scn
@@ -5,6 +5,7 @@ _gettimeofday( NULL, NULL ) - EFAULT
 rtems_clock_set          12:45:00   01/01/1988
 adjtime - NULL delta - EINVAL
 adjtime - delta out of range - EINVAL
+adjtime - delta range of 0 - OK
 adjtime - delta too small - do nothing
 adjtime - delta too small - do nothing, olddelta=NULL
 adjtime - delta of one second forward, olddelta=NULL
diff --git a/testsuites/psxtests/psxtime/test.c b/testsuites/psxtests/psxtime/test.c
index 58484e9..7620d56 100644
--- a/testsuites/psxtests/psxtime/test.c
+++ b/testsuites/psxtests/psxtime/test.c
@@ -1,8 +1,14 @@
-/*
- *  This test exercises the time of day services via the Classic
- *  and POSIX APIs to make sure they are consistent.
+/**
+ * @file
  *
- *  COPYRIGHT (c) 1989-2009.
+ * This test exercises the time of day services via the Classic
+ * and POSIX APIs to make sure they are consistent. It additionally
+ * exericses the adjtime() method.
+ * 
+ */
+
+/*
+ *  COPYRIGHT (c) 1989-2014.
  *  On-Line Applications Research Corporation (OAR).
  *
  *  The license and distribution terms for this file may be
@@ -128,11 +134,18 @@ void test_adjtime(void)
   rtems_test_assert( errno == EINVAL );
 
   puts( "adjtime - delta out of range - EINVAL" );
+  delta.tv_sec = 0;
   delta.tv_usec = 1000000000; /* 100 seconds worth */
   sc = adjtime( &delta, &olddelta );
   rtems_test_assert( sc == -1 );
   rtems_test_assert( errno == EINVAL );
 
+  puts( "adjtime - delta range of 0 - OK" );
+  delta.tv_sec = 0;
+  delta.tv_usec = 0;
+  sc = adjtime( &delta, &olddelta );
+  rtems_test_assert( sc == 0 );
+
   puts( "adjtime - delta too small - do nothing" );
   delta.tv_sec = 0;
   delta.tv_usec = 1;



More information about the vc mailing list