From 422289e54424dee85744b4d00bea2d65355c87c6 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Tue, 29 Jan 2002 18:18:14 +0000 Subject: 2001-01-29 Joel Sherrill * Fixed bug where resetting a timer that was not at the head of one of the task timer chains resulted in the Timer Server task waking up too far in the future. * Added rtems_timer_get_information() directive to support testing. * src/timerserver.c, include/rtems/rtems/timer.h, * src/timergetinfo.c: New file. * src/Makefile.am: Modified to reflect above. --- c/src/exec/rtems/ChangeLog | 10 +++ c/src/exec/rtems/src/Makefile.am | 4 +- c/src/exec/rtems/src/timergetinfo.c | 70 +++++++++++++++++ c/src/exec/rtems/src/timerserver.c | 150 ++++++++++++++++++++++++------------ cpukit/rtems/ChangeLog | 10 +++ cpukit/rtems/src/Makefile.am | 4 +- cpukit/rtems/src/timergetinfo.c | 70 +++++++++++++++++ cpukit/rtems/src/timerserver.c | 150 ++++++++++++++++++++++++------------ 8 files changed, 368 insertions(+), 100 deletions(-) create mode 100644 c/src/exec/rtems/src/timergetinfo.c create mode 100644 cpukit/rtems/src/timergetinfo.c diff --git a/c/src/exec/rtems/ChangeLog b/c/src/exec/rtems/ChangeLog index d7c765775b..dc436ac762 100644 --- a/c/src/exec/rtems/ChangeLog +++ b/c/src/exec/rtems/ChangeLog @@ -1,3 +1,13 @@ +2001-01-29 Joel Sherrill + + * Fixed bug where resetting a timer that was not at the head + of one of the task timer chains resulted in the Timer Server + task waking up too far in the future. + * Added rtems_timer_get_information() directive to support testing. + * src/timerserver.c, include/rtems/rtems/timer.h, + * src/timergetinfo.c: New file. + * src/Makefile.am: Modified to reflect above. + 2001-01-22 Joel Sherrill * include/rtems/rtems/timer.h, src/timerserver.c: Add priority diff --git a/c/src/exec/rtems/src/Makefile.am b/c/src/exec/rtems/src/Makefile.am index f1402ef9de..0c2da2b3b2 100644 --- a/c/src/exec/rtems/src/Makefile.am +++ b/c/src/exec/rtems/src/Makefile.am @@ -26,8 +26,8 @@ INTR_C_FILES = intr.c intrbody.c intrcatch.c CLOCK_C_FILES = rtclock.c clockget.c clockset.c clocktick.c TIMER_C_FILES = rtemstimer.c timercancel.c timercreate.c timerdelete.c \ - timerfireafter.c timerfirewhen.c timerident.c timerreset.c timerserver.c \ - timerserverfireafter.c timerserverfirewhen.c + timerfireafter.c timerfirewhen.c timergetinfo.c timerident.c timerreset.c \ + timerserver.c timerserverfireafter.c timerserverfirewhen.c MESSAGE_QUEUE_C_FILES = msg.c msgqallocate.c msgqbroadcast.c msgqcreate.c \ msgqdelete.c msgqflush.c msgqgetnumberpending.c msgqident.c \ diff --git a/c/src/exec/rtems/src/timergetinfo.c b/c/src/exec/rtems/src/timergetinfo.c new file mode 100644 index 0000000000..efcd9c71a5 --- /dev/null +++ b/c/src/exec/rtems/src/timergetinfo.c @@ -0,0 +1,70 @@ +/* + * Timer Manager - rtems_timer_get_information directive + * + * + * COPYRIGHT (c) 1989-2002. + * 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.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * rtems_timer_get_information + * + * This directive allows a thread to obtain information about a timer. + * + * Input parameters: + * id - timer id + * the_info - pointer to timer information block + * + * Output parameters: + * *the_info - region information block filled in + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + * + */ + +rtems_status_code rtems_timer_get_information( + Objects_Id id, + rtems_timer_information *the_info +) +{ + Timer_Control *the_timer; + Objects_Locations location; + + if ( !the_info ) + return RTEMS_INVALID_ADDRESS; + + the_timer = _Timer_Get( id, &location ); + switch ( location ) { + case OBJECTS_REMOTE: /* should never return this */ + return RTEMS_INTERNAL_ERROR; + + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + + case OBJECTS_LOCAL: + the_info->the_class = the_timer->the_class; + the_info->initial = the_timer->Ticker.initial; + the_info->start_time = the_timer->Ticker.start_time; + the_info->stop_time = the_timer->Ticker.stop_time; + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} diff --git a/c/src/exec/rtems/src/timerserver.c b/c/src/exec/rtems/src/timerserver.c index 196cceb4f8..dace8f8c45 100644 --- a/c/src/exec/rtems/src/timerserver.c +++ b/c/src/exec/rtems/src/timerserver.c @@ -38,6 +38,14 @@ Chain_Control _Timer_Ticks_chain; Chain_Control _Timer_Seconds_chain; +/* + * These variables keep track of the last time the Timer Server actually + * processed the chain. + */ + +Watchdog_Interval _Timer_Server_seconds_last_time; +Watchdog_Interval _Timer_Server_ticks_last_time; + /* * The timer used to control when the Timer Server wakes up to service * "when" timers. @@ -47,6 +55,13 @@ Chain_Control _Timer_Seconds_chain; Watchdog_Control _Timer_Seconds_timer; +/* + * prototypes for support routines to process the chains + */ + +void _Timer_Process_ticks_chain(void); +void _Timer_Process_seconds_chain(void); + /*PAGE * * _Timer_Server_body @@ -66,18 +81,13 @@ Thread _Timer_Server_body( unsigned32 ignored ) { - Watchdog_Interval snapshot; - Watchdog_Interval ticks_last_time; - Watchdog_Interval seconds_last_time; - Watchdog_Interval ticks; - /* * Initialize the "last time" markers to indicate the timer that * the server was initiated. */ - ticks_last_time = _Watchdog_Ticks_since_boot; - seconds_last_time = _TOD_Seconds_since_epoch; + _Timer_Server_ticks_last_time = _Watchdog_Ticks_since_boot; + _Timer_Server_seconds_last_time = _TOD_Seconds_since_epoch; _Thread_Disable_dispatch(); while(1) { @@ -100,42 +110,8 @@ Thread _Timer_Server_body( */ _Thread_Disable_dispatch(); - - /* - * Process the ticks chain - */ - - snapshot = _Watchdog_Ticks_since_boot; - ticks = snapshot - ticks_last_time; - ticks_last_time = snapshot; - _Watchdog_Adjust( &_Timer_Ticks_chain, WATCHDOG_FORWARD, ticks ); - - /* - * Process the seconds chain. Start by checking that the Time - * of Day (TOD) has not been set backwards. If it has then - * we want to adjust the _Timer_Seconds_chain to indicate this. - */ - - snapshot = _TOD_Seconds_since_epoch; - if ( snapshot > seconds_last_time ) { - /* - * This path is for normal forward movement and cases where the - * TOD has been set forward. - */ - - ticks = snapshot - seconds_last_time; - _Watchdog_Adjust( &_Timer_Seconds_chain, WATCHDOG_FORWARD, ticks ); - - } else if ( snapshot < seconds_last_time ) { - /* - * The current TOD is before the last TOD which indicates that - * TOD has been set backwards. - */ - - ticks = seconds_last_time - snapshot; - _Watchdog_Adjust( &_Timer_Seconds_chain, WATCHDOG_BACKWARD, ticks ); - } - seconds_last_time = snapshot; + _Timer_Process_ticks_chain(); + _Timer_Process_seconds_chain(); } } @@ -289,15 +265,93 @@ void _Timer_Server_reset( switch ( reset_mode ) { case TIMER_SERVER_RESET_TICKS: - _Watchdog_Remove( &_Timer_Server->Timer ); - units = ((Watchdog_Control *)_Timer_Ticks_chain.first)->delta_interval; - _Watchdog_Insert_ticks( &_Timer_Server->Timer, units ); + _Watchdog_Remove( &_Timer_Server->Timer ); + _Timer_Process_ticks_chain(); + if ( !_Chain_Is_empty( &_Timer_Ticks_chain ) ) { + units = ((Watchdog_Control *)_Timer_Ticks_chain.first)->delta_interval; + _Watchdog_Insert_ticks( &_Timer_Server->Timer, units ); + } break; case TIMER_SERVER_RESET_SECONDS: _Watchdog_Remove( &_Timer_Seconds_timer ); - units = ((Watchdog_Control *)_Timer_Seconds_chain.first)->delta_interval; - _Watchdog_Insert_seconds( &_Timer_Seconds_timer, units ); + _Timer_Process_seconds_chain(); + if ( !_Chain_Is_empty( &_Timer_Seconds_chain ) ) { + units = ((Watchdog_Control *)_Timer_Seconds_chain.first)->delta_interval; + _Watchdog_Insert_seconds( &_Timer_Seconds_timer, units ); + } break; } } +/*PAGE + * + * _Timer_Server_Process_ticks_chain + * + * This routine is responsible for adjusting the list of task-based + * interval timers to reflect the passage of time. + * + * Input parameters: NONE + * + * Output parameters: NONE + */ + +void _Timer_Process_ticks_chain(void) +{ + Watchdog_Interval snapshot; + Watchdog_Interval ticks; + + snapshot = _Watchdog_Ticks_since_boot; + if ( snapshot >= _Timer_Server_ticks_last_time ) + ticks = snapshot - _Timer_Server_ticks_last_time; + else + ticks = (0xFFFFFFFF - _Timer_Server_ticks_last_time) + snapshot; + + _Timer_Server_ticks_last_time = snapshot; + _Watchdog_Adjust( &_Timer_Ticks_chain, WATCHDOG_FORWARD, ticks ); +} + +/*PAGE + * + * _Timer_Server_Process_seconds_chain + * + * This routine is responsible for adjusting the list of task-based + * time of day timers to reflect the passage of time. + * + * Input parameters: NONE + * + * Output parameters: NONE + */ + +void _Timer_Process_seconds_chain(void) +{ + Watchdog_Interval snapshot; + Watchdog_Interval ticks; + + /* + * Process the seconds chain. Start by checking that the Time + * of Day (TOD) has not been set backwards. If it has then + * we want to adjust the _Timer_Seconds_chain to indicate this. + */ + + snapshot = _TOD_Seconds_since_epoch; + if ( snapshot > _Timer_Server_seconds_last_time ) { + /* + * This path is for normal forward movement and cases where the + * TOD has been set forward. + */ + + ticks = snapshot - _Timer_Server_seconds_last_time; + _Watchdog_Adjust( &_Timer_Seconds_chain, WATCHDOG_FORWARD, ticks ); + + } else if ( snapshot < _Timer_Server_seconds_last_time ) { + /* + * The current TOD is before the last TOD which indicates that + * TOD has been set backwards. + */ + + ticks = _Timer_Server_seconds_last_time - snapshot; + _Watchdog_Adjust( &_Timer_Seconds_chain, WATCHDOG_BACKWARD, ticks ); + } + _Timer_Server_seconds_last_time = snapshot; +} + diff --git a/cpukit/rtems/ChangeLog b/cpukit/rtems/ChangeLog index d7c765775b..dc436ac762 100644 --- a/cpukit/rtems/ChangeLog +++ b/cpukit/rtems/ChangeLog @@ -1,3 +1,13 @@ +2001-01-29 Joel Sherrill + + * Fixed bug where resetting a timer that was not at the head + of one of the task timer chains resulted in the Timer Server + task waking up too far in the future. + * Added rtems_timer_get_information() directive to support testing. + * src/timerserver.c, include/rtems/rtems/timer.h, + * src/timergetinfo.c: New file. + * src/Makefile.am: Modified to reflect above. + 2001-01-22 Joel Sherrill * include/rtems/rtems/timer.h, src/timerserver.c: Add priority diff --git a/cpukit/rtems/src/Makefile.am b/cpukit/rtems/src/Makefile.am index f1402ef9de..0c2da2b3b2 100644 --- a/cpukit/rtems/src/Makefile.am +++ b/cpukit/rtems/src/Makefile.am @@ -26,8 +26,8 @@ INTR_C_FILES = intr.c intrbody.c intrcatch.c CLOCK_C_FILES = rtclock.c clockget.c clockset.c clocktick.c TIMER_C_FILES = rtemstimer.c timercancel.c timercreate.c timerdelete.c \ - timerfireafter.c timerfirewhen.c timerident.c timerreset.c timerserver.c \ - timerserverfireafter.c timerserverfirewhen.c + timerfireafter.c timerfirewhen.c timergetinfo.c timerident.c timerreset.c \ + timerserver.c timerserverfireafter.c timerserverfirewhen.c MESSAGE_QUEUE_C_FILES = msg.c msgqallocate.c msgqbroadcast.c msgqcreate.c \ msgqdelete.c msgqflush.c msgqgetnumberpending.c msgqident.c \ diff --git a/cpukit/rtems/src/timergetinfo.c b/cpukit/rtems/src/timergetinfo.c new file mode 100644 index 0000000000..efcd9c71a5 --- /dev/null +++ b/cpukit/rtems/src/timergetinfo.c @@ -0,0 +1,70 @@ +/* + * Timer Manager - rtems_timer_get_information directive + * + * + * COPYRIGHT (c) 1989-2002. + * 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.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/*PAGE + * + * rtems_timer_get_information + * + * This directive allows a thread to obtain information about a timer. + * + * Input parameters: + * id - timer id + * the_info - pointer to timer information block + * + * Output parameters: + * *the_info - region information block filled in + * RTEMS_SUCCESSFUL - if successful + * error code - if unsuccessful + * + */ + +rtems_status_code rtems_timer_get_information( + Objects_Id id, + rtems_timer_information *the_info +) +{ + Timer_Control *the_timer; + Objects_Locations location; + + if ( !the_info ) + return RTEMS_INVALID_ADDRESS; + + the_timer = _Timer_Get( id, &location ); + switch ( location ) { + case OBJECTS_REMOTE: /* should never return this */ + return RTEMS_INTERNAL_ERROR; + + case OBJECTS_ERROR: + return RTEMS_INVALID_ID; + + case OBJECTS_LOCAL: + the_info->the_class = the_timer->the_class; + the_info->initial = the_timer->Ticker.initial; + the_info->start_time = the_timer->Ticker.start_time; + the_info->stop_time = the_timer->Ticker.stop_time; + _Thread_Enable_dispatch(); + return RTEMS_SUCCESSFUL; + } + + return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ +} diff --git a/cpukit/rtems/src/timerserver.c b/cpukit/rtems/src/timerserver.c index 196cceb4f8..dace8f8c45 100644 --- a/cpukit/rtems/src/timerserver.c +++ b/cpukit/rtems/src/timerserver.c @@ -38,6 +38,14 @@ Chain_Control _Timer_Ticks_chain; Chain_Control _Timer_Seconds_chain; +/* + * These variables keep track of the last time the Timer Server actually + * processed the chain. + */ + +Watchdog_Interval _Timer_Server_seconds_last_time; +Watchdog_Interval _Timer_Server_ticks_last_time; + /* * The timer used to control when the Timer Server wakes up to service * "when" timers. @@ -47,6 +55,13 @@ Chain_Control _Timer_Seconds_chain; Watchdog_Control _Timer_Seconds_timer; +/* + * prototypes for support routines to process the chains + */ + +void _Timer_Process_ticks_chain(void); +void _Timer_Process_seconds_chain(void); + /*PAGE * * _Timer_Server_body @@ -66,18 +81,13 @@ Thread _Timer_Server_body( unsigned32 ignored ) { - Watchdog_Interval snapshot; - Watchdog_Interval ticks_last_time; - Watchdog_Interval seconds_last_time; - Watchdog_Interval ticks; - /* * Initialize the "last time" markers to indicate the timer that * the server was initiated. */ - ticks_last_time = _Watchdog_Ticks_since_boot; - seconds_last_time = _TOD_Seconds_since_epoch; + _Timer_Server_ticks_last_time = _Watchdog_Ticks_since_boot; + _Timer_Server_seconds_last_time = _TOD_Seconds_since_epoch; _Thread_Disable_dispatch(); while(1) { @@ -100,42 +110,8 @@ Thread _Timer_Server_body( */ _Thread_Disable_dispatch(); - - /* - * Process the ticks chain - */ - - snapshot = _Watchdog_Ticks_since_boot; - ticks = snapshot - ticks_last_time; - ticks_last_time = snapshot; - _Watchdog_Adjust( &_Timer_Ticks_chain, WATCHDOG_FORWARD, ticks ); - - /* - * Process the seconds chain. Start by checking that the Time - * of Day (TOD) has not been set backwards. If it has then - * we want to adjust the _Timer_Seconds_chain to indicate this. - */ - - snapshot = _TOD_Seconds_since_epoch; - if ( snapshot > seconds_last_time ) { - /* - * This path is for normal forward movement and cases where the - * TOD has been set forward. - */ - - ticks = snapshot - seconds_last_time; - _Watchdog_Adjust( &_Timer_Seconds_chain, WATCHDOG_FORWARD, ticks ); - - } else if ( snapshot < seconds_last_time ) { - /* - * The current TOD is before the last TOD which indicates that - * TOD has been set backwards. - */ - - ticks = seconds_last_time - snapshot; - _Watchdog_Adjust( &_Timer_Seconds_chain, WATCHDOG_BACKWARD, ticks ); - } - seconds_last_time = snapshot; + _Timer_Process_ticks_chain(); + _Timer_Process_seconds_chain(); } } @@ -289,15 +265,93 @@ void _Timer_Server_reset( switch ( reset_mode ) { case TIMER_SERVER_RESET_TICKS: - _Watchdog_Remove( &_Timer_Server->Timer ); - units = ((Watchdog_Control *)_Timer_Ticks_chain.first)->delta_interval; - _Watchdog_Insert_ticks( &_Timer_Server->Timer, units ); + _Watchdog_Remove( &_Timer_Server->Timer ); + _Timer_Process_ticks_chain(); + if ( !_Chain_Is_empty( &_Timer_Ticks_chain ) ) { + units = ((Watchdog_Control *)_Timer_Ticks_chain.first)->delta_interval; + _Watchdog_Insert_ticks( &_Timer_Server->Timer, units ); + } break; case TIMER_SERVER_RESET_SECONDS: _Watchdog_Remove( &_Timer_Seconds_timer ); - units = ((Watchdog_Control *)_Timer_Seconds_chain.first)->delta_interval; - _Watchdog_Insert_seconds( &_Timer_Seconds_timer, units ); + _Timer_Process_seconds_chain(); + if ( !_Chain_Is_empty( &_Timer_Seconds_chain ) ) { + units = ((Watchdog_Control *)_Timer_Seconds_chain.first)->delta_interval; + _Watchdog_Insert_seconds( &_Timer_Seconds_timer, units ); + } break; } } +/*PAGE + * + * _Timer_Server_Process_ticks_chain + * + * This routine is responsible for adjusting the list of task-based + * interval timers to reflect the passage of time. + * + * Input parameters: NONE + * + * Output parameters: NONE + */ + +void _Timer_Process_ticks_chain(void) +{ + Watchdog_Interval snapshot; + Watchdog_Interval ticks; + + snapshot = _Watchdog_Ticks_since_boot; + if ( snapshot >= _Timer_Server_ticks_last_time ) + ticks = snapshot - _Timer_Server_ticks_last_time; + else + ticks = (0xFFFFFFFF - _Timer_Server_ticks_last_time) + snapshot; + + _Timer_Server_ticks_last_time = snapshot; + _Watchdog_Adjust( &_Timer_Ticks_chain, WATCHDOG_FORWARD, ticks ); +} + +/*PAGE + * + * _Timer_Server_Process_seconds_chain + * + * This routine is responsible for adjusting the list of task-based + * time of day timers to reflect the passage of time. + * + * Input parameters: NONE + * + * Output parameters: NONE + */ + +void _Timer_Process_seconds_chain(void) +{ + Watchdog_Interval snapshot; + Watchdog_Interval ticks; + + /* + * Process the seconds chain. Start by checking that the Time + * of Day (TOD) has not been set backwards. If it has then + * we want to adjust the _Timer_Seconds_chain to indicate this. + */ + + snapshot = _TOD_Seconds_since_epoch; + if ( snapshot > _Timer_Server_seconds_last_time ) { + /* + * This path is for normal forward movement and cases where the + * TOD has been set forward. + */ + + ticks = snapshot - _Timer_Server_seconds_last_time; + _Watchdog_Adjust( &_Timer_Seconds_chain, WATCHDOG_FORWARD, ticks ); + + } else if ( snapshot < _Timer_Server_seconds_last_time ) { + /* + * The current TOD is before the last TOD which indicates that + * TOD has been set backwards. + */ + + ticks = _Timer_Server_seconds_last_time - snapshot; + _Watchdog_Adjust( &_Timer_Seconds_chain, WATCHDOG_BACKWARD, ticks ); + } + _Timer_Server_seconds_last_time = snapshot; +} + -- cgit v1.2.3