[PATCH 02/12] score: Add ticks per second to configuration

Sebastian Huber sebastian.huber at embedded-brains.de
Fri Apr 8 06:49:17 UTC 2016


This avoids the calculation of this value at run-time, similar to
rtems_configuration_get_nanoseconds_per_tick().

Delete TOD_TICKS_PER_SECOND and replace it with
rtems_configuration_get_ticks_per_second().
---
 cpukit/posix/src/alarm.c                   |  3 ++-
 cpukit/sapi/include/confdefs.h             |  1 +
 cpukit/sapi/include/rtems/config.h         |  9 +++++++++
 cpukit/score/Makefile.am                   |  1 -
 cpukit/score/include/rtems/score/todimpl.h | 20 --------------------
 cpukit/score/src/coretodtickspersec.c      | 28 ----------------------------
 cpukit/score/src/timespectoticks.c         |  7 +++----
 7 files changed, 15 insertions(+), 54 deletions(-)
 delete mode 100644 cpukit/score/src/coretodtickspersec.c

diff --git a/cpukit/posix/src/alarm.c b/cpukit/posix/src/alarm.c
index 10443e4..6140095 100644
--- a/cpukit/posix/src/alarm.c
+++ b/cpukit/posix/src/alarm.c
@@ -26,6 +26,7 @@
 
 #include <rtems/score/todimpl.h>
 #include <rtems/score/watchdogimpl.h>
+#include <rtems/config.h>
 
 ISR_LOCK_DEFINE( static, _POSIX_signals_Alarm_lock, "POSIX Alarm" )
 
@@ -64,7 +65,7 @@ unsigned int alarm(
   uint32_t          ticks;
 
   the_watchdog = &_POSIX_signals_Alarm_watchdog;
-  ticks_per_second = TOD_TICKS_PER_SECOND;
+  ticks_per_second = rtems_configuration_get_ticks_per_second();
   ticks = seconds * ticks_per_second;
 
   _ISR_lock_ISR_disable_and_acquire(
diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index e0b2a80..9e5bd14 100644
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -3413,6 +3413,7 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
     CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS,  /*   enabled */
     CONFIGURE_MICROSECONDS_PER_TICK,          /* microseconds per clock tick */
     1000 * CONFIGURE_MICROSECONDS_PER_TICK,   /* nanoseconds per clock tick */
+    1000000 / CONFIGURE_MICROSECONDS_PER_TICK,/* ticks per second */
     CONFIGURE_TICKS_PER_TIMESLICE,            /* ticks per timeslice quantum */
     CONFIGURE_IDLE_TASK_BODY,                 /* user's IDLE task */
     CONFIGURE_IDLE_TASK_STACK_SIZE,           /* IDLE task stack size */
diff --git a/cpukit/sapi/include/rtems/config.h b/cpukit/sapi/include/rtems/config.h
index 1b48ea9..a2fb833 100644
--- a/cpukit/sapi/include/rtems/config.h
+++ b/cpukit/sapi/include/rtems/config.h
@@ -173,6 +173,13 @@ typedef struct {
   uint32_t                       nanoseconds_per_tick;
 
   /** 
+   * This field specifies the number of clock ticks per second.  This value is
+   * derived from the microseconds_per_tick field and provided to avoid
+   * calculation at run-time.
+   */
+  uint32_t                       ticks_per_second;
+
+  /** 
    * This field specifies the number of ticks in each task's timeslice.
    */
   uint32_t                       ticks_per_timeslice;
@@ -309,6 +316,8 @@ extern const rtems_configuration_table Configuration;
         (Configuration.microseconds_per_tick / 1000)
 #define rtems_configuration_get_nanoseconds_per_tick() \
         (Configuration.nanoseconds_per_tick)
+#define rtems_configuration_get_ticks_per_second() \
+        (Configuration.ticks_per_second)
 
 #define rtems_configuration_get_ticks_per_timeslice() \
         (Configuration.ticks_per_timeslice)
diff --git a/cpukit/score/Makefile.am b/cpukit/score/Makefile.am
index 455c99d..f7affdf 100644
--- a/cpukit/score/Makefile.am
+++ b/cpukit/score/Makefile.am
@@ -330,7 +330,6 @@ libscore_a_SOURCES += src/timespecaddto.c src/timespecfromticks.c \
 
 ## TOD_C_FILES
 libscore_a_SOURCES += src/coretod.c src/coretodset.c \
-    src/coretodtickspersec.c \
     src/coretodadjust.c
 libscore_a_SOURCES += src/coretodabsolutetimeout.c
 
diff --git a/cpukit/score/include/rtems/score/todimpl.h b/cpukit/score/include/rtems/score/todimpl.h
index b1f8a6d..2968bf6 100644
--- a/cpukit/score/include/rtems/score/todimpl.h
+++ b/cpukit/score/include/rtems/score/todimpl.h
@@ -264,26 +264,6 @@ static inline uint32_t _TOD_Seconds_since_epoch( void )
 }
 
 /**
- *  @brief Gets number of ticks in a second.
- *
- *  This method returns the number of ticks in a second.
- *
- *  @note If the clock tick value does not multiply evenly into a second
- *        then this number of ticks will be slightly shorter than a second.
- */
-uint32_t TOD_TICKS_PER_SECOND_method(void);
-
-/**
- *  @brief Gets number of ticks in a second.
- *
- *  This method exists to hide the fact that TOD_TICKS_PER_SECOND can not
- *  be implemented as a macro in a .h file due to visibility issues.
- *  The Configuration Table is not available to SuperCore .h files but
- *  is available to their .c files.
- */
-#define TOD_TICKS_PER_SECOND TOD_TICKS_PER_SECOND_method()
-
-/**
  * This routine returns a timeval based upon the internal timespec format TOD.
  */
 
diff --git a/cpukit/score/src/coretodtickspersec.c b/cpukit/score/src/coretodtickspersec.c
deleted file mode 100644
index cfe53ce..0000000
--- a/cpukit/score/src/coretodtickspersec.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * @file
- *
- * @brief Convert Ticks To Seconds
- * @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/todimpl.h>
-#include <rtems/config.h>
-
-uint32_t TOD_TICKS_PER_SECOND_method(void)
-{
-  return (TOD_MICROSECONDS_PER_SECOND /
-      rtems_configuration_get_microseconds_per_tick());
-}
diff --git a/cpukit/score/src/timespectoticks.c b/cpukit/score/src/timespectoticks.c
index fb57532..d02a350 100644
--- a/cpukit/score/src/timespectoticks.c
+++ b/cpukit/score/src/timespectoticks.c
@@ -16,7 +16,6 @@
 #endif
 
 #include <rtems/score/timespec.h>
-#include <rtems/score/todimpl.h>
 #include <rtems/config.h>
 
 /**
@@ -28,8 +27,8 @@ uint32_t _Timespec_To_ticks(
   const struct timespec *time
 )
 {
-  uint32_t  ticks;
-  uint32_t  nanoseconds_per_tick;
+  uint32_t ticks;
+  uint32_t nanoseconds_per_tick;
 
   if ( (time->tv_sec == 0) && (time->tv_nsec == 0) )
     return 0;
@@ -39,7 +38,7 @@ uint32_t _Timespec_To_ticks(
    *  need to have it be greater than or equal to the requested time.  It
    *  should not be shorter.
    */
-  ticks                 = time->tv_sec * TOD_TICKS_PER_SECOND;
+  ticks = time->tv_sec * rtems_configuration_get_ticks_per_second();
   nanoseconds_per_tick  = rtems_configuration_get_nanoseconds_per_tick();
   ticks                += time->tv_nsec / nanoseconds_per_tick;
 
-- 
1.8.4.5




More information about the devel mailing list