From 2256946e9c0bc452004521d7aeeb68b72f680f42 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Fri, 6 Oct 2017 15:30:47 +0200 Subject: score: Use struct timespec for TOD Use the timestamps only for uptime based values. Use struct timespec for the absolute time values (TOD). Update #2740. --- cpukit/posix/src/clockgettime.c | 2 +- cpukit/posix/src/clocksettime.c | 7 +++- cpukit/posix/src/timersettime.c | 4 +-- cpukit/rtems/src/clockset.c | 13 +++---- cpukit/score/include/rtems/score/todimpl.h | 54 +++++------------------------- cpukit/score/src/coretodabsolutetimeout.c | 2 +- cpukit/score/src/coretodadjust.c | 8 ++--- cpukit/score/src/coretodset.c | 12 +++---- 8 files changed, 33 insertions(+), 69 deletions(-) (limited to 'cpukit') diff --git a/cpukit/posix/src/clockgettime.c b/cpukit/posix/src/clockgettime.c index b3adbc4713..4f6c583ff1 100644 --- a/cpukit/posix/src/clockgettime.c +++ b/cpukit/posix/src/clockgettime.c @@ -37,7 +37,7 @@ int clock_gettime( rtems_set_errno_and_return_minus_one( EINVAL ); if ( clock_id == CLOCK_REALTIME ) { - _TOD_Get_as_timespec(tp); + _TOD_Get(tp); return 0; } #ifdef CLOCK_MONOTONIC diff --git a/cpukit/posix/src/clocksettime.c b/cpukit/posix/src/clocksettime.c index 8eb616c8b5..a0fdd9109f 100644 --- a/cpukit/posix/src/clocksettime.c +++ b/cpukit/posix/src/clocksettime.c @@ -36,10 +36,15 @@ int clock_settime( rtems_set_errno_and_return_minus_one( EINVAL ); if ( clock_id == CLOCK_REALTIME ) { + ISR_lock_Context lock_context; + if ( tp->tv_sec < TOD_SECONDS_1970_THROUGH_1988 ) rtems_set_errno_and_return_minus_one( EINVAL ); - _TOD_Set_with_timespec( tp ); + _TOD_Lock(); + _TOD_Acquire( &lock_context ); + _TOD_Set( tp, &lock_context ); + _TOD_Unlock(); } #ifdef _POSIX_CPUTIME else if ( clock_id == CLOCK_PROCESS_CPUTIME_ID ) diff --git a/cpukit/posix/src/timersettime.c b/cpukit/posix/src/timersettime.c index 698a47a6b7..1f98a7a08c 100644 --- a/cpukit/posix/src/timersettime.c +++ b/cpukit/posix/src/timersettime.c @@ -39,7 +39,7 @@ static void _POSIX_Timer_Insert( ptimer->state = POSIX_TIMER_STATE_CREATE_RUN; /* Store the time when the timer was started again */ - _TOD_Get_as_timespec( &ptimer->time ); + _TOD_Get( &ptimer->time ); _Watchdog_Insert( &cpu->Watchdog.Header[ PER_CPU_WATCHDOG_RELATIVE ], @@ -132,7 +132,7 @@ int timer_settime( /* Convert absolute to relative time */ if (flags == TIMER_ABSTIME) { struct timespec now; - _TOD_Get_as_timespec( &now ); + _TOD_Get( &now ); /* Check for seconds in the past */ if ( _Timespec_Greater_than( &now, &normalize.it_value ) ) rtems_set_errno_and_return_minus_one( EINVAL ); diff --git a/cpukit/rtems/src/clockset.c b/cpukit/rtems/src/clockset.c index f0300cc76a..d77268211b 100644 --- a/cpukit/rtems/src/clockset.c +++ b/cpukit/rtems/src/clockset.c @@ -30,19 +30,16 @@ rtems_status_code rtems_clock_set( return RTEMS_INVALID_ADDRESS; if ( _TOD_Validate( tod ) ) { - Timestamp_Control tod_as_timestamp; - uint32_t seconds; - uint32_t nanoseconds; - ISR_lock_Context lock_context; + struct timespec tod_as_timespec; + ISR_lock_Context lock_context; - seconds = _TOD_To_seconds( tod ); - nanoseconds = tod->ticks + tod_as_timespec.tv_sec = _TOD_To_seconds( tod ); + tod_as_timespec.tv_nsec = tod->ticks * rtems_configuration_get_nanoseconds_per_tick(); - _Timestamp_Set( &tod_as_timestamp, seconds, nanoseconds ); _TOD_Lock(); _TOD_Acquire( &lock_context ); - _TOD_Set( &tod_as_timestamp, &lock_context ); + _TOD_Set( &tod_as_timespec, &lock_context ); _TOD_Unlock(); return RTEMS_SUCCESSFUL; diff --git a/cpukit/score/include/rtems/score/todimpl.h b/cpukit/score/include/rtems/score/todimpl.h index 03f25b5ae0..f5dba85f8c 100644 --- a/cpukit/score/include/rtems/score/todimpl.h +++ b/cpukit/score/include/rtems/score/todimpl.h @@ -164,65 +164,27 @@ static inline void _TOD_Acquire( ISR_lock_Context *lock_context ) * * The caller must be the owner of the TOD lock. * - * @param tod_as_timestamp The new time of day in timestamp format representing + * @param tod The new time of day in timespec format representing * the time since UNIX Epoch. * @param lock_context The ISR lock context used for the corresponding * _TOD_Acquire(). The caller must be the owner of the TOD lock. This * function will release the TOD lock. */ void _TOD_Set( - const Timestamp_Control *tod_as_timestamp, - ISR_lock_Context *lock_context + const struct timespec *tod, + ISR_lock_Context *lock_context ); -/** - * @brief Sets the time of day with timespec format. - * - * @param tod_as_timespec The new time of day in timespec format. - * - * @see _TOD_Set(). - */ -static inline void _TOD_Set_with_timespec( - const struct timespec *tod_as_timespec -) -{ - Timestamp_Control tod_as_timestamp; - ISR_lock_Context lock_context; - - _Timestamp_Set( - &tod_as_timestamp, - tod_as_timespec->tv_sec, - tod_as_timespec->tv_nsec - ); - - _TOD_Lock(); - _TOD_Acquire( &lock_context ); - _TOD_Set( &tod_as_timestamp, &lock_context ); - _TOD_Unlock(); -} - -/** - * @brief Gets the current time in the bintime format. - * - * @param[out] time is the value gathered by the bintime request - */ -static inline void _TOD_Get( - Timestamp_Control *time -) -{ - _Timecounter_Bintime(time); -} - /** * @brief Gets the current time in the timespec format. * - * @param[out] time is the value gathered by the nanotime request + * @param[out] time is the value gathered by the request */ -static inline void _TOD_Get_as_timespec( - struct timespec *time +static inline void _TOD_Get( + struct timespec *tod ) { - _Timecounter_Nanotime(time); + _Timecounter_Nanotime( tod ); } /** @@ -324,7 +286,7 @@ RTEMS_INLINE_ROUTINE void _TOD_Get_timeval( * @param[in] delta is the amount to adjust */ void _TOD_Adjust( - const Timestamp_Control *delta + const struct timespec *delta ); /** diff --git a/cpukit/score/src/coretodabsolutetimeout.c b/cpukit/score/src/coretodabsolutetimeout.c index fe74a6bbf2..d67b7c33c7 100644 --- a/cpukit/score/src/coretodabsolutetimeout.c +++ b/cpukit/score/src/coretodabsolutetimeout.c @@ -47,7 +47,7 @@ TOD_Absolute_timeout_conversion_results _TOD_Absolute_timeout_to_ticks( * Is the absolute time in the past? */ if ( clock == CLOCK_REALTIME ) { - _TOD_Get_as_timespec( ¤t_time ); + _TOD_Get( ¤t_time ); } else { _Assert( clock == CLOCK_MONOTONIC ); _TOD_Get_zero_based_uptime_as_timespec( ¤t_time ); diff --git a/cpukit/score/src/coretodadjust.c b/cpukit/score/src/coretodadjust.c index 5996565e5c..f493a40b9d 100644 --- a/cpukit/score/src/coretodadjust.c +++ b/cpukit/score/src/coretodadjust.c @@ -21,11 +21,11 @@ #include void _TOD_Adjust( - const Timestamp_Control *delta + const struct timespec *delta ) { - Timestamp_Control tod; - ISR_lock_Context lock_context; + ISR_lock_Context lock_context; + struct timespec tod; /* * Currently, RTEMS does the adjustment in one movement. @@ -38,7 +38,7 @@ void _TOD_Adjust( _TOD_Lock(); _TOD_Acquire( &lock_context ); _TOD_Get( &tod ); - _Timestamp_Add_to( &tod, delta ); + _Timespec_Add_to( &tod, delta ); _TOD_Set( &tod, &lock_context ); _TOD_Unlock(); } diff --git a/cpukit/score/src/coretodset.c b/cpukit/score/src/coretodset.c index f1d2e36eb0..80b0b762bd 100644 --- a/cpukit/score/src/coretodset.c +++ b/cpukit/score/src/coretodset.c @@ -23,21 +23,21 @@ #include void _TOD_Set( - const Timestamp_Control *tod_as_timestamp, - ISR_lock_Context *lock_context + const struct timespec *tod, + ISR_lock_Context *lock_context ) { - struct timespec tod_as_timespec; + struct bintime tod_as_bintime; uint64_t tod_as_ticks; uint32_t cpu_count; uint32_t cpu_index; _Assert( _API_Mutex_Is_owner( _Once_Mutex ) ); - _Timecounter_Set_clock( tod_as_timestamp, lock_context ); + timespec2bintime( tod, &tod_as_bintime ); + _Timecounter_Set_clock( &tod_as_bintime, lock_context ); - _Timestamp_To_timespec( tod_as_timestamp, &tod_as_timespec ); - tod_as_ticks = _Watchdog_Ticks_from_timespec( &tod_as_timespec ); + tod_as_ticks = _Watchdog_Ticks_from_timespec( tod ); cpu_count = _SMP_Get_processor_count(); for ( cpu_index = 0 ; cpu_index < cpu_count ; ++cpu_index ) { -- cgit v1.2.3