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/score/src/threadqtimeout.c | 128 +++++++++++++++----------------------- cpukit/score/src/watchdogtick.c | 16 ++++- 2 files changed, 66 insertions(+), 78 deletions(-) (limited to 'cpukit/score/src') diff --git a/cpukit/score/src/threadqtimeout.c b/cpukit/score/src/threadqtimeout.c index 691f643493..0993fd4fe7 100644 --- a/cpukit/score/src/threadqtimeout.c +++ b/cpukit/score/src/threadqtimeout.c @@ -34,50 +34,13 @@ void _Thread_queue_Add_timeout_ticks( } } -static bool _Thread_queue_Lazy_insert_monotonic_timespec( +static void _Thread_queue_Add_timeout_timespec( + Thread_queue_Queue *queue, Thread_Control *the_thread, Per_CPU_Control *cpu_self, - const struct timespec *abstime -) -{ - uint64_t expire; - ISR_lock_Context lock_context; - bool insert; - - if ( abstime->tv_sec < 0 ) { - expire = 0; - } else if ( _Watchdog_Is_far_future_monotonic_timespec( abstime ) ) { - expire = WATCHDOG_MAXIMUM_TICKS; - } else { - expire = _Watchdog_Monotonic_from_timespec( abstime ); - } - - _ISR_lock_ISR_disable_and_acquire( - &the_thread->Timer.Lock, - &lock_context - ); - - the_thread->Timer.header = - &cpu_self->Watchdog.Header[ PER_CPU_WATCHDOG_MONOTONIC ]; - the_thread->Timer.Watchdog.routine = _Thread_Timeout; - insert = _Watchdog_Per_CPU_lazy_insert_monotonic( - &the_thread->Timer.Watchdog, - cpu_self, - expire - ); - - _ISR_lock_Release_and_ISR_enable( - &the_thread->Timer.Lock, - &lock_context - ); - return insert; -} - -void _Thread_queue_Add_timeout_monotonic_timespec( - Thread_queue_Queue *queue, - Thread_Control *the_thread, - Per_CPU_Control *cpu_self, - Thread_queue_Context *queue_context + Thread_queue_Context *queue_context, + Watchdog_Header *header, + const struct timespec *now ) { const struct timespec *abstime; @@ -85,46 +48,17 @@ void _Thread_queue_Add_timeout_monotonic_timespec( abstime = queue_context->Timeout.arg; if ( _Watchdog_Is_valid_timespec( abstime ) ) { - if ( - !_Thread_queue_Lazy_insert_monotonic_timespec( - the_thread, - cpu_self, - abstime - ) - ) { - _Thread_Continue( the_thread, STATUS_TIMEOUT ); - } - } else { - _Thread_Continue( the_thread, STATUS_INVALID_NUMBER ); - } -} - -void _Thread_queue_Add_timeout_realtime_timespec( - Thread_queue_Queue *queue, - Thread_Control *the_thread, - Per_CPU_Control *cpu_self, - Thread_queue_Context *queue_context -) -{ - const struct timespec *abstime; - - abstime = queue_context->Timeout.arg; - - if ( _Watchdog_Is_valid_timespec( abstime ) ) { - uint64_t expire; - struct timespec now; + uint64_t expire; if ( abstime->tv_sec < 0 ) { expire = 0; - } else if ( _Watchdog_Is_far_future_realtime_timespec( abstime ) ) { + } else if ( _Watchdog_Is_far_future_timespec( abstime ) ) { expire = WATCHDOG_MAXIMUM_TICKS; } else { expire = _Watchdog_Ticks_from_timespec( abstime ); } - _Timecounter_Getnanotime( &now ); - - if ( expire > _Watchdog_Ticks_from_timespec( &now ) ) { + if ( expire > _Watchdog_Ticks_from_timespec( now ) ) { ISR_lock_Context lock_context; _ISR_lock_ISR_disable_and_acquire( @@ -132,12 +66,12 @@ void _Thread_queue_Add_timeout_realtime_timespec( &lock_context ); - the_thread->Timer.header = - &cpu_self->Watchdog.Header[ PER_CPU_WATCHDOG_REALTIME ]; + the_thread->Timer.header = header; the_thread->Timer.Watchdog.routine = _Thread_Timeout; - _Watchdog_Per_CPU_insert_realtime( + _Watchdog_Per_CPU_insert( &the_thread->Timer.Watchdog, cpu_self, + header, expire ); @@ -152,3 +86,43 @@ void _Thread_queue_Add_timeout_realtime_timespec( _Thread_Continue( the_thread, STATUS_INVALID_NUMBER ); } } + +void _Thread_queue_Add_timeout_monotonic_timespec( + Thread_queue_Queue *queue, + Thread_Control *the_thread, + Per_CPU_Control *cpu_self, + Thread_queue_Context *queue_context +) +{ + struct timespec now; + + _Timecounter_Getnanouptime( &now ); + _Thread_queue_Add_timeout_timespec( + queue, + the_thread, + cpu_self, + queue_context, + &cpu_self->Watchdog.Header[ PER_CPU_WATCHDOG_MONOTONIC ], + &now + ); +} + +void _Thread_queue_Add_timeout_realtime_timespec( + Thread_queue_Queue *queue, + Thread_Control *the_thread, + Per_CPU_Control *cpu_self, + Thread_queue_Context *queue_context +) +{ + struct timespec now; + + _Timecounter_Getnanotime( &now ); + _Thread_queue_Add_timeout_timespec( + queue, + the_thread, + cpu_self, + queue_context, + &cpu_self->Watchdog.Header[ PER_CPU_WATCHDOG_REALTIME ], + &now + ); +} diff --git a/cpukit/score/src/watchdogtick.c b/cpukit/score/src/watchdogtick.c index e9160f2ea1..2f11357019 100644 --- a/cpukit/score/src/watchdogtick.c +++ b/cpukit/score/src/watchdogtick.c @@ -70,7 +70,7 @@ void _Watchdog_Tick( Per_CPU_Control *cpu ) ++ticks; cpu->Watchdog.ticks = ticks; - header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_MONOTONIC ]; + header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_TICKS ]; first = _Watchdog_Header_first( header ); if ( first != NULL ) { @@ -83,6 +83,20 @@ void _Watchdog_Tick( Per_CPU_Control *cpu ) ); } + header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_MONOTONIC ]; + first = _Watchdog_Header_first( header ); + + if ( first != NULL ) { + _Timecounter_Getnanouptime( &now ); + _Watchdog_Tickle( + header, + first, + _Watchdog_Ticks_from_timespec( &now ), + &cpu->Watchdog.Lock, + &lock_context + ); + } + header = &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_REALTIME ]; first = _Watchdog_Header_first( header ); -- cgit v1.2.3