From 9480815a222be61214b176836ef2b4ae4155ce84 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Thu, 21 Dec 2017 14:36:52 +0100 Subject: score: Introduce new monotonic clock Rename PER_CPU_WATCHDOG_MONOTONIC to PER_CPU_WATCHDOG_TICKS. Add new PER_CPU_WATCHDOG_MONOTONIC which is based on the system uptime (measured by timecounter). Close #3264. --- cpukit/include/rtems/score/percpu.h | 18 ++++-- cpukit/include/rtems/score/threadimpl.h | 13 +++-- cpukit/include/rtems/score/watchdog.h | 9 --- cpukit/include/rtems/score/watchdogimpl.h | 92 +++++-------------------------- 4 files changed, 34 insertions(+), 98 deletions(-) (limited to 'cpukit/include/rtems/score') diff --git a/cpukit/include/rtems/score/percpu.h b/cpukit/include/rtems/score/percpu.h index 00528b5ce3..7d0a6c06bf 100644 --- a/cpukit/include/rtems/score/percpu.h +++ b/cpukit/include/rtems/score/percpu.h @@ -248,14 +248,13 @@ typedef struct { */ typedef enum { /** - * @brief Index for monotonic clock per-CPU watchdog header. + * @brief Index for tick clock per-CPU watchdog header. * - * The reference time point for the monotonic clock is the system start. The + * The reference time point for the tick clock is the system start. The * clock resolution is one system clock tick. It is used for the system - * clock tick based time services and the POSIX services using - * CLOCK_MONOTONIC. + * clock tick based time services. */ - PER_CPU_WATCHDOG_MONOTONIC, + PER_CPU_WATCHDOG_TICKS, /** * @brief Index for realtime clock per-CPU watchdog header. @@ -266,6 +265,15 @@ typedef enum { */ PER_CPU_WATCHDOG_REALTIME, + /** + * @brief Index for monotonic clock per-CPU watchdog header. + * + * The reference time point for the monotonic clock is the system start. The + * clock resolution is one nanosecond. It is used for the POSIX services + * using CLOCK_MONOTONIC. + */ + PER_CPU_WATCHDOG_MONOTONIC, + /** * @brief Count of per-CPU watchdog headers. */ diff --git a/cpukit/include/rtems/score/threadimpl.h b/cpukit/include/rtems/score/threadimpl.h index b6722fae19..777158b77a 100644 --- a/cpukit/include/rtems/score/threadimpl.h +++ b/cpukit/include/rtems/score/threadimpl.h @@ -1864,7 +1864,7 @@ RTEMS_INLINE_ROUTINE void _Thread_Timer_initialize( ) { _ISR_lock_Initialize( &timer->Lock, "Thread Timer" ); - timer->header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_MONOTONIC ]; + timer->header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_TICKS ]; _Watchdog_Preinitialize( &timer->Watchdog, cpu ); } @@ -1879,7 +1879,7 @@ RTEMS_INLINE_ROUTINE void _Thread_Add_timeout_ticks( _ISR_lock_ISR_disable_and_acquire( &the_thread->Timer.Lock, &lock_context ); the_thread->Timer.header = - &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_MONOTONIC ]; + &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_TICKS ]; the_thread->Timer.Watchdog.routine = _Thread_Timeout; _Watchdog_Per_CPU_insert_ticks( &the_thread->Timer.Watchdog, cpu, ticks ); @@ -1893,14 +1893,15 @@ RTEMS_INLINE_ROUTINE void _Thread_Timer_insert_realtime( uint64_t expire ) { - ISR_lock_Context lock_context; + ISR_lock_Context lock_context; + Watchdog_Header *header; _ISR_lock_ISR_disable_and_acquire( &the_thread->Timer.Lock, &lock_context ); - the_thread->Timer.header = - &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_REALTIME ]; + header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_REALTIME ]; + the_thread->Timer.header = header; the_thread->Timer.Watchdog.routine = routine; - _Watchdog_Per_CPU_insert_realtime( &the_thread->Timer.Watchdog, cpu, expire ); + _Watchdog_Per_CPU_insert( &the_thread->Timer.Watchdog, cpu, header, expire ); _ISR_lock_Release_and_ISR_enable( &the_thread->Timer.Lock, &lock_context ); } diff --git a/cpukit/include/rtems/score/watchdog.h b/cpukit/include/rtems/score/watchdog.h index dbb092bbef..71126d3508 100644 --- a/cpukit/include/rtems/score/watchdog.h +++ b/cpukit/include/rtems/score/watchdog.h @@ -147,15 +147,6 @@ extern const uint32_t _Watchdog_Nanoseconds_per_tick; */ extern const uint32_t _Watchdog_Ticks_per_second; -/** - * @brief The maximum number of seconds representable in the monotonic watchdog - * format. - * - * This constant is defined by the application configuration via - * . - */ -extern const uint64_t _Watchdog_Monotonic_max_seconds; - /**@}*/ #ifdef __cplusplus diff --git a/cpukit/include/rtems/score/watchdogimpl.h b/cpukit/include/rtems/score/watchdogimpl.h index 9701fb772f..6fe9d5acf5 100644 --- a/cpukit/include/rtems/score/watchdogimpl.h +++ b/cpukit/include/rtems/score/watchdogimpl.h @@ -303,19 +303,19 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Next_first( * @brief The bits necessary to store 1000000000 * (= WATCHDOG_NANOSECONDS_PER_SECOND) nanoseconds. * - * The expiration time is an unsigned 64-bit integer. To store absolute + * The expiration time is an unsigned 64-bit integer. To store nanoseconds * timeouts we use 30 bits (2**30 == 1073741824) for the nanoseconds and 34 * bits for the seconds since UNIX Epoch. This leads to a year 2514 problem. */ #define WATCHDOG_BITS_FOR_1E9_NANOSECONDS 30 /** - * @brief The maximum number of seconds representable in the realtime watchdog - * format. + * @brief The maximum number of seconds representable in the nanoseconds + * watchdog format. * * We have 2**34 bits for the seconds part. */ -#define WATCHDOG_REALTIME_MAX_SECONDS 0x3ffffffff +#define WATCHDOG_MAX_SECONDS 0x3ffffffff RTEMS_INLINE_ROUTINE bool _Watchdog_Is_valid_timespec( const struct timespec *ts @@ -362,34 +362,11 @@ RTEMS_INLINE_ROUTINE const struct timespec * _Watchdog_Future_timespec( return now; } -RTEMS_INLINE_ROUTINE bool _Watchdog_Is_far_future_monotonic_timespec( +RTEMS_INLINE_ROUTINE bool _Watchdog_Is_far_future_timespec( const struct timespec *ts ) { - return ts->tv_sec >= _Watchdog_Monotonic_max_seconds; -} - -RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Monotonic_from_timespec( - const struct timespec *ts -) -{ - uint64_t ticks; - - _Assert( _Watchdog_Is_valid_timespec( ts ) ); - _Assert( ts->tv_sec >= 0 ); - _Assert( !_Watchdog_Is_far_future_monotonic_timespec( ts ) ); - - ticks = (uint64_t) ts->tv_sec * _Watchdog_Ticks_per_second; - ticks += (unsigned long) ts->tv_nsec / _Watchdog_Nanoseconds_per_tick; - - return ticks; -} - -RTEMS_INLINE_ROUTINE bool _Watchdog_Is_far_future_realtime_timespec( - const struct timespec *ts -) -{ - return ts->tv_sec > WATCHDOG_REALTIME_MAX_SECONDS; + return ts->tv_sec > WATCHDOG_MAX_SECONDS; } RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Ticks_from_seconds( @@ -411,7 +388,7 @@ RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Ticks_from_timespec( _Assert( _Watchdog_Is_valid_timespec( ts ) ); _Assert( ts->tv_sec >= 0 ); - _Assert( !_Watchdog_Is_far_future_realtime_timespec( ts ) ); + _Assert( !_Watchdog_Is_far_future_timespec( ts ) ); ticks = (uint64_t) ts->tv_sec; ticks <<= WATCHDOG_BITS_FOR_1E9_NANOSECONDS; @@ -457,7 +434,7 @@ RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Per_CPU_insert_ticks( Watchdog_Header *header; uint64_t expire; - header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_MONOTONIC ]; + header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_TICKS ]; _Watchdog_Set_CPU( the_watchdog, cpu ); @@ -468,46 +445,19 @@ RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Per_CPU_insert_ticks( return expire; } -RTEMS_INLINE_ROUTINE bool _Watchdog_Per_CPU_lazy_insert_monotonic( - Watchdog_Control *the_watchdog, - Per_CPU_Control *cpu, - uint64_t expire -) -{ - ISR_lock_Context lock_context; - Watchdog_Header *header; - bool insert; - - header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_MONOTONIC ]; - - _Watchdog_Set_CPU( the_watchdog, cpu ); - - _Watchdog_Per_CPU_acquire_critical( cpu, &lock_context ); - insert = ( expire > cpu->Watchdog.ticks ); - - if ( insert ) { - _Watchdog_Insert(header, the_watchdog, expire); - } - - _Watchdog_Per_CPU_release_critical( cpu, &lock_context ); - return insert; -} - -RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Per_CPU_insert_realtime( +RTEMS_INLINE_ROUTINE uint64_t _Watchdog_Per_CPU_insert( Watchdog_Control *the_watchdog, Per_CPU_Control *cpu, + Watchdog_Header *header, uint64_t expire ) { - ISR_lock_Context lock_context; - Watchdog_Header *header; - - header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_REALTIME ]; + ISR_lock_Context lock_context; _Watchdog_Set_CPU( the_watchdog, cpu ); _Watchdog_Per_CPU_acquire_critical( cpu, &lock_context ); - _Watchdog_Insert(header, the_watchdog, expire); + _Watchdog_Insert( header, the_watchdog, expire ); _Watchdog_Per_CPU_release_critical( cpu, &lock_context ); return expire; } @@ -528,21 +478,7 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Per_CPU_remove( _Watchdog_Per_CPU_release_critical( cpu, &lock_context ); } -RTEMS_INLINE_ROUTINE void _Watchdog_Per_CPU_remove_monotonic( - Watchdog_Control *the_watchdog -) -{ - Per_CPU_Control *cpu; - - cpu = _Watchdog_Get_CPU( the_watchdog ); - _Watchdog_Per_CPU_remove( - the_watchdog, - cpu, - &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_MONOTONIC ] - ); -} - -RTEMS_INLINE_ROUTINE void _Watchdog_Per_CPU_remove_realtime( +RTEMS_INLINE_ROUTINE void _Watchdog_Per_CPU_remove_ticks( Watchdog_Control *the_watchdog ) { @@ -552,7 +488,7 @@ RTEMS_INLINE_ROUTINE void _Watchdog_Per_CPU_remove_realtime( _Watchdog_Per_CPU_remove( the_watchdog, cpu, - &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_REALTIME ] + &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_TICKS ] ); } -- cgit v1.2.3