[rtems commit] score: Add _Watchdog_Ticks_per_second

Sebastian Huber sebh at rtems.org
Tue Oct 24 08:20:30 UTC 2017


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

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Oct 20 08:31:36 2017 +0200

score: Add _Watchdog_Ticks_per_second

This value is frequently used.  Avoid the function call overhead and the
integer division at run-time.

Update #3117.
Update #3182.

---

 cpukit/rtems/src/clockgettickspersecond.c   | 5 +----
 cpukit/sapi/include/confdefs.h              | 4 ++++
 cpukit/score/include/rtems/score/watchdog.h | 8 ++++++++
 testsuites/sptests/spwatchdog/init.c        | 6 ++++++
 4 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/cpukit/rtems/src/clockgettickspersecond.c b/cpukit/rtems/src/clockgettickspersecond.c
index f49c91c..a2f78eb 100644
--- a/cpukit/rtems/src/clockgettickspersecond.c
+++ b/cpukit/rtems/src/clockgettickspersecond.c
@@ -19,11 +19,8 @@
 #endif
 
 #include <rtems/rtems/clock.h>
-#include <rtems/score/todimpl.h>
-#include <rtems/config.h>
 
 rtems_interval rtems_clock_get_ticks_per_second(void)
 {
-  return TOD_MICROSECONDS_PER_SECOND /
-    rtems_configuration_get_microseconds_per_tick();
+  return _Watchdog_Ticks_per_second;
 }
diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index a64170b..3dfcf9b 100755
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -2287,6 +2287,8 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
             RTEMS_MILLISECONDS_TO_MICROSECONDS(10)
   #endif
 
+  #define _CONFIGURE_TICKS_PER_SECOND (1000000 / CONFIGURE_MICROSECONDS_PER_TICK)
+
   /** The configures the number of clock ticks per timeslice. */
   #ifndef CONFIGURE_TICKS_PER_TIMESLICE
     #define CONFIGURE_TICKS_PER_TIMESLICE        50
@@ -3102,6 +3104,8 @@ extern rtems_initialization_tasks_table Initialization_tasks[];
   const size_t _Thread_Control_add_on_count =
     RTEMS_ARRAY_SIZE( _Thread_Control_add_ons );
 
+  const uint32_t _Watchdog_Ticks_per_second = _CONFIGURE_TICKS_PER_SECOND;
+
   /**
    * This is the Classic API Configuration Table.
    */
diff --git a/cpukit/score/include/rtems/score/watchdog.h b/cpukit/score/include/rtems/score/watchdog.h
index 11a5974..bbe2a93 100644
--- a/cpukit/score/include/rtems/score/watchdog.h
+++ b/cpukit/score/include/rtems/score/watchdog.h
@@ -158,6 +158,14 @@ struct Watchdog_Control {
  */
 extern volatile Watchdog_Interval _Watchdog_Ticks_since_boot;
 
+/**
+ * @brief The watchdog ticks per second.
+ *
+ * This constant is defined by the application configuration via
+ * <rtems/confdefs.h>.
+ */
+extern const uint32_t _Watchdog_Ticks_per_second;
+
 /**@}*/
 
 #ifdef __cplusplus
diff --git a/testsuites/sptests/spwatchdog/init.c b/testsuites/sptests/spwatchdog/init.c
index 6e5e155..f027236 100644
--- a/testsuites/sptests/spwatchdog/init.c
+++ b/testsuites/sptests/spwatchdog/init.c
@@ -57,6 +57,11 @@ static void test_watchdog_static_init( void )
   rtems_test_assert( memcmp( &a, &b, sizeof( a ) ) == 0 );
 }
 
+static void test_watchdog_config( void )
+{
+  rtems_test_assert( _Watchdog_Ticks_per_second == 100 );
+}
+
 static bool test_watchdog_is_inactive( test_watchdog *watchdog )
 {
   return _Watchdog_Get_state( &watchdog->Base ) == WATCHDOG_INACTIVE;
@@ -227,6 +232,7 @@ rtems_task Init(
 
   test_watchdog_operations();
   test_watchdog_static_init();
+  test_watchdog_config();
 
   build_time( &time, 12, 31, 1988, 9, 0, 0, 0 );
 



More information about the vc mailing list