2001-01-29 Joel Sherrill <joel@OARcorp.com>

* 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.
This commit is contained in:
Joel Sherrill
2002-01-29 18:18:14 +00:00
parent 49d0704a0a
commit 422289e544
8 changed files with 368 additions and 100 deletions

View File

@@ -1,3 +1,13 @@
2001-01-29 Joel Sherrill <joel@OARcorp.com>
* 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 <joel@OARcorp.com>
* include/rtems/rtems/timer.h, src/timerserver.c: Add priority

View File

@@ -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 \

View File

@@ -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 <rtems/system.h>
#include <rtems/rtems/status.h>
#include <rtems/rtems/support.h>
#include <rtems/score/object.h>
#include <rtems/score/thread.h>
#include <rtems/rtems/timer.h>
#include <rtems/score/tod.h>
#include <rtems/score/watchdog.h>
/*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 */
}

View File

@@ -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;
}