move timers code to libsys
This commit is contained in:
parent
8c925134f9
commit
895850b8cf
34 changed files with 168 additions and 509 deletions
|
@ -238,12 +238,8 @@ PRIVATE u8_t f_results[MAX_RESULTS];/* the controller can give lots of output */
|
|||
* floppy disk drive contains a 'fl_tmr_stop' timer.
|
||||
*/
|
||||
PRIVATE timer_t f_tmr_timeout; /* timer for various timeouts */
|
||||
PRIVATE timer_t *f_timers; /* queue of floppy timers */
|
||||
PRIVATE clock_t f_next_timeout; /* the next timeout time */
|
||||
PRIVATE u32_t system_hz; /* system clock frequency */
|
||||
FORWARD _PROTOTYPE( void f_expire_tmrs, (struct driver *dp, message *m_ptr) );
|
||||
FORWARD _PROTOTYPE( void f_set_timer, (timer_t *tp, clock_t delta,
|
||||
tmr_func_t watchdog) );
|
||||
FORWARD _PROTOTYPE( void stop_motor, (timer_t *tp) );
|
||||
FORWARD _PROTOTYPE( void f_timeout, (timer_t *tp) );
|
||||
|
||||
|
@ -348,14 +344,13 @@ PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info)
|
|||
AC_LOWER16M | AC_ALIGN4K, &floppy_buf_phys)))
|
||||
panic("couldn't allocate dma buffer");
|
||||
|
||||
f_next_timeout = TMR_NEVER;
|
||||
tmr_inittimer(&f_tmr_timeout);
|
||||
init_timer(&f_tmr_timeout);
|
||||
|
||||
for (fp = &floppy[0]; fp < &floppy[NR_DRIVES]; fp++) {
|
||||
fp->fl_curcyl = NO_CYL;
|
||||
fp->fl_density = NO_DENS;
|
||||
fp->fl_class = ~0;
|
||||
tmr_inittimer(&fp->fl_tmr_stop);
|
||||
init_timer(&fp->fl_tmr_stop);
|
||||
}
|
||||
|
||||
/* Set IRQ policy, only request notifications, do not automatically
|
||||
|
@ -394,57 +389,11 @@ PRIVATE void sef_cb_signal_handler(int signo)
|
|||
*===========================================================================*/
|
||||
PRIVATE void f_expire_tmrs(struct driver *dp, message *m_ptr)
|
||||
{
|
||||
/* A synchronous alarm message was received. Check if there are any expired
|
||||
* timers. Possibly reschedule the next alarm.
|
||||
/* A synchronous alarm message was received. Call the watchdog function for
|
||||
* each expired timer, if any.
|
||||
*/
|
||||
clock_t now; /* current time */
|
||||
int s;
|
||||
|
||||
/* Get the current time to compare the timers against. */
|
||||
if ((s=getuptime(&now)) != OK)
|
||||
panic("Couldn't get uptime from clock: %d", s);
|
||||
|
||||
/* Scan the timers queue for expired timers. Dispatch the watchdog function
|
||||
* for each expired timers. FLOPPY watchdog functions are f_tmr_timeout()
|
||||
* and stop_motor(). Possibly a new alarm call must be scheduled.
|
||||
*/
|
||||
tmrs_exptimers(&f_timers, now, NULL);
|
||||
if (f_timers == NULL) {
|
||||
f_next_timeout = TMR_NEVER;
|
||||
} else { /* set new sync alarm */
|
||||
f_next_timeout = f_timers->tmr_exp_time;
|
||||
if ((s=sys_setalarm(f_next_timeout, 1)) != OK)
|
||||
panic("Couldn't set synchronous alarm: %d", s);
|
||||
}
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* f_set_timer *
|
||||
*===========================================================================*/
|
||||
PRIVATE void f_set_timer(tp, delta, watchdog)
|
||||
timer_t *tp; /* timer to be set */
|
||||
clock_t delta; /* in how many ticks */
|
||||
tmr_func_t watchdog; /* watchdog function to be called */
|
||||
{
|
||||
clock_t now; /* current time */
|
||||
int s;
|
||||
|
||||
/* Get the current time. */
|
||||
if ((s=getuptime(&now)) != OK)
|
||||
panic("Couldn't get uptime from clock: %d", s);
|
||||
|
||||
/* Add the timer to the local timer queue. */
|
||||
tmrs_settimer(&f_timers, tp, now + delta, watchdog, NULL);
|
||||
|
||||
/* Possibly reschedule an alarm call. This happens when the front of the
|
||||
* timers queue was reinserted at another position, i.e., when a timer was
|
||||
* reset, or when a new timer was added in front.
|
||||
*/
|
||||
if (f_timers->tmr_exp_time != f_next_timeout) {
|
||||
f_next_timeout = f_timers->tmr_exp_time;
|
||||
if ((s=sys_setalarm(f_next_timeout, 1)) != OK)
|
||||
panic("Couldn't set synchronous alarm: %d", s);
|
||||
}
|
||||
expire_timers(m_ptr->NOTIFY_TIMESTAMP);
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
|
@ -492,8 +441,7 @@ PRIVATE char *f_name(void)
|
|||
PRIVATE void f_cleanup(void)
|
||||
{
|
||||
/* Start a timer to turn the motor off in a few seconds. */
|
||||
tmr_arg(&f_fp->fl_tmr_stop)->ta_int = f_drive;
|
||||
f_set_timer(&f_fp->fl_tmr_stop, MOTOR_OFF, stop_motor);
|
||||
set_timer(&f_fp->fl_tmr_stop, MOTOR_OFF, stop_motor, f_drive);
|
||||
|
||||
/* Exiting the floppy driver, so forget where we are. */
|
||||
f_fp->fl_sector = NO_SECTOR;
|
||||
|
@ -818,7 +766,7 @@ PRIVATE void start_motor(void)
|
|||
/* Set an alarm timer to force a timeout if the hardware does not interrupt
|
||||
* in time. Expect an interrupt, but check for a timeout.
|
||||
*/
|
||||
f_set_timer(&f_tmr_timeout, f_dp->start_ms * system_hz / 1000, f_timeout);
|
||||
set_timer(&f_tmr_timeout, f_dp->start_ms * system_hz / 1000, f_timeout, 0);
|
||||
f_busy = BSY_IO;
|
||||
do {
|
||||
driver_receive(ANY, &mess, &ipc_status);
|
||||
|
@ -826,7 +774,7 @@ PRIVATE void start_motor(void)
|
|||
if (is_ipc_notify(ipc_status)) {
|
||||
switch (_ENDPOINT_P(mess.m_source)) {
|
||||
case CLOCK:
|
||||
f_expire_tmrs(NULL, NULL);
|
||||
f_expire_tmrs(NULL, &mess);
|
||||
break;
|
||||
default :
|
||||
f_busy = BSY_IDLE;
|
||||
|
@ -893,7 +841,7 @@ PRIVATE int seek(void)
|
|||
/* Set a synchronous alarm to force a timeout if the hardware does
|
||||
* not interrupt.
|
||||
*/
|
||||
f_set_timer(&f_tmr_timeout, system_hz/30, f_timeout);
|
||||
set_timer(&f_tmr_timeout, system_hz/30, f_timeout, 0);
|
||||
f_busy = BSY_IO;
|
||||
do {
|
||||
driver_receive(ANY, &mess, &ipc_status);
|
||||
|
@ -901,7 +849,7 @@ PRIVATE int seek(void)
|
|||
if (is_ipc_notify(ipc_status)) {
|
||||
switch (_ENDPOINT_P(mess.m_source)) {
|
||||
case CLOCK:
|
||||
f_expire_tmrs(NULL, NULL);
|
||||
f_expire_tmrs(NULL, &mess);
|
||||
break;
|
||||
default :
|
||||
f_busy = BSY_IDLE;
|
||||
|
@ -1057,7 +1005,7 @@ PRIVATE int fdc_command(
|
|||
* Note that the actual check is done by the code that issued the
|
||||
* fdc_command() call.
|
||||
*/
|
||||
f_set_timer(&f_tmr_timeout, WAKEUP, f_timeout);
|
||||
set_timer(&f_tmr_timeout, WAKEUP, f_timeout, 0);
|
||||
|
||||
f_busy = BSY_IO;
|
||||
while (len > 0) {
|
||||
|
@ -1183,7 +1131,7 @@ PRIVATE void f_reset(void)
|
|||
if (is_ipc_notify(ipc_status)) {
|
||||
switch (_ENDPOINT_P(mess.m_source)) {
|
||||
case CLOCK:
|
||||
f_expire_tmrs(NULL, NULL);
|
||||
f_expire_tmrs(NULL, &mess);
|
||||
break;
|
||||
default :
|
||||
f_busy = BSY_IDLE;
|
||||
|
@ -1233,7 +1181,7 @@ PRIVATE int f_intr_wait(void)
|
|||
if (is_ipc_notify(ipc_status)) {
|
||||
switch (_ENDPOINT_P(mess.m_source)) {
|
||||
case CLOCK:
|
||||
f_expire_tmrs(NULL, NULL);
|
||||
f_expire_tmrs(NULL, &mess);
|
||||
break;
|
||||
default :
|
||||
f_busy = BSY_IDLE;
|
||||
|
|
|
@ -20,8 +20,6 @@
|
|||
|
||||
#include <timers.h>
|
||||
|
||||
#define tmra_ut timer_t
|
||||
#define tmra_inittimer(tp) tmr_inittimer(tp)
|
||||
#define debug 0
|
||||
#define RAND_UPDATE /**/
|
||||
#define printW() ((void)0)
|
||||
|
@ -61,9 +59,6 @@ PRIVATE struct pcitab pcitab_fxp[]=
|
|||
|
||||
typedef int irq_hook_t;
|
||||
|
||||
static timer_t *fxp_timers= NULL;
|
||||
static clock_t fxp_next_timeout= 0;
|
||||
|
||||
/* ignore interrupt for the moment */
|
||||
#define interrupt(x) 0
|
||||
|
||||
|
@ -165,7 +160,7 @@ PRIVATE int fxp_instance;
|
|||
|
||||
PRIVATE fxp_t *fxp_state;
|
||||
|
||||
PRIVATE tmra_ut fxp_watchdog;
|
||||
PRIVATE timer_t fxp_watchdog;
|
||||
|
||||
PRIVATE u32_t system_hz;
|
||||
|
||||
|
@ -202,9 +197,6 @@ _PROTOTYPE( static void mess_reply, (message *req, message *reply) );
|
|||
_PROTOTYPE( static u16_t eeprom_read, (fxp_t *fp, int reg) );
|
||||
_PROTOTYPE( static void eeprom_addrsize, (fxp_t *fp) );
|
||||
_PROTOTYPE( static u16_t mii_read, (fxp_t *fp, int reg) );
|
||||
_PROTOTYPE( static void fxp_set_timer,(timer_t *tp, clock_t delta,
|
||||
tmr_func_t watchdog) );
|
||||
_PROTOTYPE( static void fxp_expire_timers,(void) );
|
||||
_PROTOTYPE( static u8_t do_inb, (port_t port) );
|
||||
_PROTOTYPE( static u32_t do_inl, (port_t port) );
|
||||
_PROTOTYPE( static void do_outb, (port_t port, u8_t v) );
|
||||
|
@ -266,7 +258,7 @@ int main(int argc, char *argv[])
|
|||
handle_hw_intr();
|
||||
break;
|
||||
case CLOCK:
|
||||
fxp_expire_timers();
|
||||
expire_timers(m.NOTIFY_TIMESTAMP);
|
||||
break;
|
||||
default:
|
||||
panic(" illegal notify from: %d", m.m_source);
|
||||
|
@ -382,9 +374,8 @@ message *mp;
|
|||
first_time= 0;
|
||||
fxp_pci_conf(); /* Configure PCI devices. */
|
||||
|
||||
tmra_inittimer(&fxp_watchdog);
|
||||
tmr_arg(&fxp_watchdog)->ta_int= 0;
|
||||
fxp_set_timer(&fxp_watchdog, system_hz, fxp_watchdog_f);
|
||||
init_timer(&fxp_watchdog);
|
||||
set_timer(&fxp_watchdog, system_hz, fxp_watchdog_f, 0);
|
||||
}
|
||||
|
||||
fp= fxp_state;
|
||||
|
@ -1771,8 +1762,7 @@ timer_t *tp;
|
|||
{
|
||||
fxp_t *fp;
|
||||
|
||||
tmr_arg(&fxp_watchdog)->ta_int= 0;
|
||||
fxp_set_timer(&fxp_watchdog, system_hz, fxp_watchdog_f);
|
||||
set_timer(&fxp_watchdog, system_hz, fxp_watchdog_f, 0);
|
||||
|
||||
fp= fxp_state;
|
||||
if (fp->fxp_mode != FM_ENABLED)
|
||||
|
@ -2260,73 +2250,6 @@ int reg;
|
|||
return v & CM_DATA_MASK;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* fxp_set_timer *
|
||||
*===========================================================================*/
|
||||
PRIVATE void fxp_set_timer(tp, delta, watchdog)
|
||||
timer_t *tp; /* timer to be set */
|
||||
clock_t delta; /* in how many ticks */
|
||||
tmr_func_t watchdog; /* watchdog function to be called */
|
||||
{
|
||||
clock_t now; /* current time */
|
||||
int r;
|
||||
|
||||
/* Get the current time. */
|
||||
r= getuptime(&now);
|
||||
if (r != OK)
|
||||
panic("unable to get uptime from clock: %d", r);
|
||||
|
||||
/* Add the timer to the local timer queue. */
|
||||
tmrs_settimer(&fxp_timers, tp, now + delta, watchdog, NULL);
|
||||
|
||||
/* Possibly reschedule an alarm call. This happens when a new timer
|
||||
* is added in front.
|
||||
*/
|
||||
if (fxp_next_timeout == 0 ||
|
||||
fxp_timers->tmr_exp_time < fxp_next_timeout)
|
||||
{
|
||||
fxp_next_timeout= fxp_timers->tmr_exp_time;
|
||||
#if VERBOSE
|
||||
printf("fxp_set_timer: calling sys_setalarm for %d (now+%d)\n",
|
||||
fxp_next_timeout, fxp_next_timeout-now);
|
||||
#endif
|
||||
r= sys_setalarm(fxp_next_timeout, 1);
|
||||
if (r != OK)
|
||||
panic("unable to set synchronous alarm: %d", r);
|
||||
}
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* fxp_expire_tmrs *
|
||||
*===========================================================================*/
|
||||
PRIVATE void fxp_expire_timers()
|
||||
{
|
||||
/* A synchronous alarm message was received. Check if there are any expired
|
||||
* timers. Possibly reschedule the next alarm.
|
||||
*/
|
||||
clock_t now; /* current time */
|
||||
int r;
|
||||
|
||||
/* Get the current time to compare the timers against. */
|
||||
r= getuptime(&now);
|
||||
if (r != OK)
|
||||
panic("Unable to get uptime from clock: %d", r);
|
||||
|
||||
/* Scan the timers queue for expired timers. Dispatch the watchdog function
|
||||
* for each expired timers. Possibly a new alarm call must be scheduled.
|
||||
*/
|
||||
tmrs_exptimers(&fxp_timers, now, NULL);
|
||||
if (fxp_timers == NULL)
|
||||
fxp_next_timeout= TMR_NEVER;
|
||||
else
|
||||
{ /* set new alarm */
|
||||
fxp_next_timeout = fxp_timers->tmr_exp_time;
|
||||
r= sys_setalarm(fxp_next_timeout, 1);
|
||||
if (r != OK)
|
||||
panic("Unable to set synchronous alarm: %d", r);
|
||||
}
|
||||
}
|
||||
|
||||
static u8_t do_inb(port_t port)
|
||||
{
|
||||
int r;
|
||||
|
|
|
@ -37,8 +37,6 @@ PRIVATE struct pcitab {
|
|||
};
|
||||
|
||||
|
||||
static timer_t or_watchdog;
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <minix/com.h>
|
||||
|
@ -437,7 +435,6 @@ static void or_init (message * mp) {
|
|||
first_time = 0;
|
||||
or_pci_conf (); /* Configure PCI devices. */
|
||||
|
||||
tmr_inittimer(&or_watchdog);
|
||||
/* Use a synchronous alarm instead of a watchdog timer. */
|
||||
sys_setalarm(system_hz, 0);
|
||||
}
|
||||
|
|
|
@ -50,8 +50,6 @@ PUBLIC re_t re_state;
|
|||
|
||||
static int re_instance;
|
||||
|
||||
static tmra_ut rl_watchdog;
|
||||
|
||||
static unsigned my_inb(u16_t port) {
|
||||
u32_t value;
|
||||
int s;
|
||||
|
@ -372,7 +370,6 @@ message *mp;
|
|||
first_time= 0;
|
||||
rl_pci_conf(); /* Configure PCI devices. */
|
||||
|
||||
tmra_inittimer(&rl_watchdog);
|
||||
/* Use a synchronous alarm instead of a watchdog timer. */
|
||||
sys_setalarm(system_hz, 0);
|
||||
}
|
||||
|
|
|
@ -453,8 +453,6 @@ d8 R/W Config5 Configuration register 5
|
|||
d9-ff reserved
|
||||
#endif
|
||||
|
||||
#define tmra_ut timer_t
|
||||
#define tmra_inittimer(tp) tmr_inittimer(tp)
|
||||
#define Proc_number(p) proc_number(p)
|
||||
#define debug 0
|
||||
#define printW() ((void)0)
|
||||
|
|
|
@ -179,8 +179,6 @@ static re_t re_state;
|
|||
|
||||
static int re_instance;
|
||||
|
||||
static timer_t rl_watchdog;
|
||||
|
||||
static unsigned my_inb(u16_t port)
|
||||
{
|
||||
u32_t value;
|
||||
|
@ -579,7 +577,6 @@ message *mp;
|
|||
first_time = 0;
|
||||
rl_pci_conf(); /* Configure PCI devices. */
|
||||
|
||||
tmr_inittimer(&rl_watchdog);
|
||||
/* Use a synchronous alarm instead of a watchdog timer. */
|
||||
sys_setalarm(system_hz, 0);
|
||||
}
|
||||
|
|
|
@ -771,9 +771,9 @@ PRIVATE void beep()
|
|||
unsigned long port_b_val;
|
||||
int s;
|
||||
|
||||
/* Fetch current time in advance to prevent beeping delay. */
|
||||
if ((s=getuptime(&now)) != OK)
|
||||
panic("Console couldn't get clock's uptime: %d", s);
|
||||
/* Set timer in advance to prevent beeping delay. */
|
||||
set_timer(&tmr_stop_beep, B_TIME, stop_beep, 0);
|
||||
|
||||
if (!beeping) {
|
||||
/* Set timer channel 2, square wave, with given frequency. */
|
||||
pv_set(char_out[0], TIMER_MODE, 0xB6);
|
||||
|
@ -785,13 +785,6 @@ PRIVATE void beep()
|
|||
beeping = TRUE;
|
||||
}
|
||||
}
|
||||
/* Add a timer to the timers list. Possibly reschedule the alarm. */
|
||||
tmrs_settimer(&tty_timers, &tmr_stop_beep, now+B_TIME, stop_beep, NULL);
|
||||
if (tty_timers->tmr_exp_time != tty_next_timeout) {
|
||||
tty_next_timeout = tty_timers->tmr_exp_time;
|
||||
if ((s=sys_setalarm(tty_next_timeout, 1)) != OK)
|
||||
panic("Console couldn't set alarm: %d", s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -898,9 +891,9 @@ clock_t dur;
|
|||
if (ival == 0 || ival > 0xffff)
|
||||
return; /* Frequency out of range */
|
||||
|
||||
/* Fetch current time in advance to prevent beeping delay. */
|
||||
if ((s=getuptime(&now)) != OK)
|
||||
panic("Console couldn't get clock's uptime: %d", s);
|
||||
/* Set timer in advance to prevent beeping delay. */
|
||||
set_timer(&tmr_stop_beep, dur, stop_beep, 0);
|
||||
|
||||
if (!beeping) {
|
||||
/* Set timer channel 2, square wave, with given frequency. */
|
||||
pv_set(char_out[0], TIMER_MODE, 0xB6);
|
||||
|
@ -912,13 +905,6 @@ clock_t dur;
|
|||
beeping = TRUE;
|
||||
}
|
||||
}
|
||||
/* Add a timer to the timers list. Possibly reschedule the alarm. */
|
||||
tmrs_settimer(&tty_timers, &tmr_stop_beep, now+dur, stop_beep, NULL);
|
||||
if (tty_timers->tmr_exp_time != tty_next_timeout) {
|
||||
tty_next_timeout = tty_timers->tmr_exp_time;
|
||||
if ((s=sys_setalarm(tty_next_timeout, 1)) != OK)
|
||||
panic("Console couldn't set alarm: %d", s);
|
||||
}
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
|
|
|
@ -706,18 +706,9 @@ PRIVATE void kbd_send()
|
|||
kbd_alive= 1;
|
||||
if (kbd_watchdog_set)
|
||||
{
|
||||
/* Add a timer to the timers list. Possibly reschedule the
|
||||
* alarm.
|
||||
*/
|
||||
if ((r= getuptime(&now)) != OK)
|
||||
panic("Keyboard couldn't get clock's uptime: %d", r);
|
||||
tmrs_settimer(&tty_timers, &tmr_kbd_wd, now+system_hz, kbd_watchdog,
|
||||
NULL);
|
||||
if (tty_timers->tmr_exp_time != tty_next_timeout) {
|
||||
tty_next_timeout = tty_timers->tmr_exp_time;
|
||||
if ((r= sys_setalarm(tty_next_timeout, 1)) != OK)
|
||||
panic("Keyboard couldn't set alarm: %d", r);
|
||||
}
|
||||
/* Set a watchdog timer for one second. */
|
||||
set_timer(&tmr_kbd_wd, system_hz, kbd_watchdog, 0);
|
||||
|
||||
kbd_watchdog_set= 1;
|
||||
}
|
||||
}
|
||||
|
@ -1320,14 +1311,7 @@ timer_t *tmrp;
|
|||
}
|
||||
kbd_alive= 0;
|
||||
|
||||
if ((r= getuptime(&now)) != OK)
|
||||
panic("Keyboard couldn't get clock's uptime: %d", r);
|
||||
tmrs_settimer(&tty_timers, &tmr_kbd_wd, now+system_hz, kbd_watchdog,
|
||||
NULL);
|
||||
if (tty_timers->tmr_exp_time != tty_next_timeout) {
|
||||
tty_next_timeout = tty_timers->tmr_exp_time;
|
||||
if ((r= sys_setalarm(tty_next_timeout, 1)) != OK)
|
||||
panic("Keyboard couldn't set alarm: %d", r);
|
||||
}
|
||||
set_timer(&tmr_kbd_wd, system_hz, kbd_watchdog, 0);
|
||||
|
||||
kbd_watchdog_set= 1;
|
||||
}
|
||||
|
|
|
@ -102,7 +102,6 @@ unsigned long rs_irq_set = 0;
|
|||
struct kmessages kmess;
|
||||
|
||||
FORWARD _PROTOTYPE( void tty_timed_out, (timer_t *tp) );
|
||||
FORWARD _PROTOTYPE( void expire_timers, (void) );
|
||||
FORWARD _PROTOTYPE( void settimer, (tty_t *tty_ptr, int enable) );
|
||||
FORWARD _PROTOTYPE( void do_cancel, (tty_t *tp, message *m_ptr) );
|
||||
FORWARD _PROTOTYPE( void do_ioctl, (tty_t *tp, message *m_ptr, int s) );
|
||||
|
@ -136,8 +135,6 @@ PRIVATE struct winsize winsize_defaults; /* = all zeroes */
|
|||
/* Global variables for the TTY task (declared extern in tty.h). */
|
||||
PUBLIC tty_t tty_table[NR_CONS+NR_RS_LINES+NR_PTYS];
|
||||
PUBLIC int ccurrent; /* currently active console */
|
||||
PUBLIC timer_t *tty_timers; /* queue of TTY timers */
|
||||
PUBLIC clock_t tty_next_timeout; /* time that the next alarm is due */
|
||||
PUBLIC struct machine machine; /* kernel environment variables */
|
||||
PUBLIC u32_t system_hz;
|
||||
|
||||
|
@ -187,7 +184,7 @@ PUBLIC int main(void)
|
|||
switch (_ENDPOINT_P(tty_mess.m_source)) {
|
||||
case CLOCK:
|
||||
/* run watchdogs of expired timers */
|
||||
expire_timers();
|
||||
expire_timers(tty_mess.NOTIFY_TIMESTAMP);
|
||||
break;
|
||||
case HARDWARE:
|
||||
/* hardware interrupt notification */
|
||||
|
@ -201,7 +198,7 @@ PUBLIC int main(void)
|
|||
rs_interrupt(&tty_mess);
|
||||
#endif
|
||||
/* run watchdogs of expired timers */
|
||||
expire_timers();
|
||||
expire_timers(tty_mess.NOTIFY_TIMESTAMP);
|
||||
break;
|
||||
default:
|
||||
/* do nothing */
|
||||
|
@ -1629,7 +1626,7 @@ PRIVATE void tty_init()
|
|||
|
||||
tp->tty_index = s;
|
||||
|
||||
tmr_inittimer(&tp->tty_tmr);
|
||||
init_timer(&tp->tty_tmr);
|
||||
|
||||
tp->tty_intail = tp->tty_inhead = tp->tty_inbuf;
|
||||
tp->tty_min = 1;
|
||||
|
@ -1667,33 +1664,6 @@ PRIVATE void tty_timed_out(timer_t *tp)
|
|||
tty_ptr->tty_events = 1;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* expire_timers *
|
||||
*===========================================================================*/
|
||||
PRIVATE void expire_timers(void)
|
||||
{
|
||||
/* A synchronous alarm message was received. Check if there are any expired
|
||||
* timers. Possibly set the event flag and reschedule another alarm.
|
||||
*/
|
||||
clock_t now; /* current time */
|
||||
int s;
|
||||
|
||||
/* Get the current time to compare the timers against. */
|
||||
if ((s=getuptime(&now)) != OK)
|
||||
panic("Couldn't get uptime from clock: %d", s);
|
||||
|
||||
/* Scan the queue of timers for expired timers. This dispatch the watchdog
|
||||
* functions of expired timers. Possibly a new alarm call must be scheduled.
|
||||
*/
|
||||
tmrs_exptimers(&tty_timers, now, NULL);
|
||||
if (tty_timers == NULL) tty_next_timeout = TMR_NEVER;
|
||||
else { /* set new sync alarm */
|
||||
tty_next_timeout = tty_timers->tmr_exp_time;
|
||||
if ((s=sys_setalarm(tty_next_timeout, 1)) != OK)
|
||||
panic("Couldn't set synchronous alarm: %d", s);
|
||||
}
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* settimer *
|
||||
*===========================================================================*/
|
||||
|
@ -1701,32 +1671,16 @@ PRIVATE void settimer(tty_ptr, enable)
|
|||
tty_t *tty_ptr; /* line to set or unset a timer on */
|
||||
int enable; /* set timer if true, otherwise unset */
|
||||
{
|
||||
clock_t now; /* current time */
|
||||
clock_t exp_time;
|
||||
int s;
|
||||
clock_t ticks;
|
||||
|
||||
/* Get the current time to calculate the timeout time. */
|
||||
if ((s=getuptime(&now)) != OK)
|
||||
panic("Couldn't get uptime from clock: %d", s);
|
||||
if (enable) {
|
||||
exp_time = now + tty_ptr->tty_termios.c_cc[VTIME] * (system_hz/10);
|
||||
ticks = tty_ptr->tty_termios.c_cc[VTIME] * (system_hz/10);
|
||||
|
||||
/* Set a new timer for enabling the TTY events flags. */
|
||||
tmrs_settimer(&tty_timers, &tty_ptr->tty_tmr,
|
||||
exp_time, tty_timed_out, NULL);
|
||||
set_timer(&tty_ptr->tty_tmr, ticks, tty_timed_out, 0);
|
||||
} else {
|
||||
/* Remove the timer from the active and expired lists. */
|
||||
tmrs_clrtimer(&tty_timers, &tty_ptr->tty_tmr, NULL);
|
||||
}
|
||||
|
||||
/* Now check if a new alarm must be scheduled. This happens when the front
|
||||
* of the timers queue was disabled or reinserted at another position, or
|
||||
* when a new timer was added to the front.
|
||||
*/
|
||||
if (tty_timers == NULL) tty_next_timeout = TMR_NEVER;
|
||||
else if (tty_timers->tmr_exp_time != tty_next_timeout) {
|
||||
tty_next_timeout = tty_timers->tmr_exp_time;
|
||||
if ((s=sys_setalarm(tty_next_timeout, 1)) != OK)
|
||||
panic("Couldn't set synchronous alarm: %d", s);
|
||||
cancel_timer(&tty_ptr->tty_tmr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -128,10 +128,6 @@ extern unsigned long rs_irq_set;
|
|||
/* Times and timeouts. */
|
||||
#define force_timeout() ((void) (0))
|
||||
|
||||
/* Memory allocated in tty.c, so extern here. */
|
||||
extern timer_t *tty_timers; /* queue of TTY timers */
|
||||
extern clock_t tty_next_timeout; /* next TTY timeout */
|
||||
|
||||
/* Number of elements and limit of a buffer. */
|
||||
#define buflen(buf) (sizeof(buf) / sizeof((buf)[0]))
|
||||
#define bufend(buf) ((buf) + buflen(buf))
|
||||
|
|
|
@ -23,7 +23,7 @@ INCS+= minix/a.out.h minix/bitmap.h minix/callnr.h minix/cdrom.h \
|
|||
minix/portio.h minix/profile.h minix/queryparam.h \
|
||||
minix/rs.h minix/safecopies.h minix/sched.h minix/sef.h minix/sound.h \
|
||||
minix/sys_config.h minix/sysinfo.h minix/syslib.h \
|
||||
minix/sysutil.h minix/tty.h minix/type.h minix/types.h \
|
||||
minix/sysutil.h minix/timers.h minix/tty.h minix/type.h minix/types.h \
|
||||
minix/u64.h minix/vfsif.h minix/vm.h \
|
||||
minix/compiler.h minix/compiler-ack.h minix/sha2.h
|
||||
INCS+= net/hton.h net/if.h net/ioctl.h net/netlib.h
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <minix/devio.h>
|
||||
#include <minix/syslib.h>
|
||||
#include <minix/sysutil.h>
|
||||
#include <minix/timers.h>
|
||||
#include <minix/bitmap.h>
|
||||
|
||||
#include <machine/interrupt.h> /* IRQ vectors and miscellaneous ports */
|
||||
|
|
16
include/minix/timers.h
Normal file
16
include/minix/timers.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef _MINIX_TIMERS_H
|
||||
#define _MINIX_TIMERS_H
|
||||
|
||||
/* Timers abstraction for system processes. This would be in minix/sysutil.h
|
||||
* if it weren't for naming conflicts.
|
||||
*/
|
||||
|
||||
#include <timers.h>
|
||||
|
||||
_PROTOTYPE( void init_timer, (timer_t *tp));
|
||||
_PROTOTYPE( void set_timer, (timer_t *tp, int ticks, tmr_func_t watchdog,
|
||||
int arg));
|
||||
_PROTOTYPE( void cancel_timer, (timer_t *tp));
|
||||
_PROTOTYPE( void expire_timers, (clock_t now));
|
||||
|
||||
#endif /* _MINIX_TIMERS_H */
|
|
@ -120,7 +120,8 @@ SRCS= \
|
|||
timing.c \
|
||||
profile_extern.c \
|
||||
profile.c \
|
||||
vprintf.c
|
||||
vprintf.c \
|
||||
timers.c
|
||||
|
||||
CPPFLAGS.sched_start.c+= -I${MINIXSRCDIR}
|
||||
|
||||
|
|
88
lib/libsys/timers.c
Normal file
88
lib/libsys/timers.c
Normal file
|
@ -0,0 +1,88 @@
|
|||
/* Watchdog timer management. These functions in this file provide a
|
||||
* convenient interface to the timers library that manages a list of
|
||||
* watchdog timers. All details of scheduling an alarm at the CLOCK task
|
||||
* are hidden behind this interface.
|
||||
*
|
||||
* The entry points into this file are:
|
||||
* init_timer: initialize a timer structure
|
||||
* set_timer: reset and existing or set a new watchdog timer
|
||||
* cancel_timer: remove a timer from the list of timers
|
||||
* expire_timers: check for expired timers and run watchdog functions
|
||||
*
|
||||
*/
|
||||
|
||||
#include "syslib.h"
|
||||
#include <timers.h>
|
||||
|
||||
PRIVATE timer_t *timers = NULL;
|
||||
PRIVATE int expiring = 0;
|
||||
|
||||
/*===========================================================================*
|
||||
* init_timer *
|
||||
*===========================================================================*/
|
||||
PUBLIC void init_timer(timer_t *tp)
|
||||
{
|
||||
tmr_inittimer(tp);
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* set_timer *
|
||||
*===========================================================================*/
|
||||
PUBLIC void set_timer(timer_t *tp, int ticks, tmr_func_t watchdog, int arg)
|
||||
{
|
||||
int r;
|
||||
clock_t now, prev_time = 0, next_time;
|
||||
|
||||
if ((r = getuptime(&now)) != OK)
|
||||
panic("set_timer: couldn't get uptime");
|
||||
|
||||
/* Set timer argument and add timer to the list. */
|
||||
tmr_arg(tp)->ta_int = arg;
|
||||
prev_time = tmrs_settimer(&timers, tp, now+ticks, watchdog, &next_time);
|
||||
|
||||
/* Reschedule our synchronous alarm if necessary. */
|
||||
if (expiring == 0 && (! prev_time || prev_time > next_time)) {
|
||||
if (sys_setalarm(next_time, 1) != OK)
|
||||
panic("set_timer: couldn't set alarm");
|
||||
}
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* cancel_timer *
|
||||
*===========================================================================*/
|
||||
PUBLIC void cancel_timer(timer_t *tp)
|
||||
{
|
||||
clock_t next_time, prev_time;
|
||||
prev_time = tmrs_clrtimer(&timers, tp, &next_time);
|
||||
|
||||
/* If the earliest timer has been removed, we have to set the alarm to
|
||||
* the next timer, or cancel the alarm altogether if the last timer
|
||||
* has been cancelled (next_time will be 0 then).
|
||||
*/
|
||||
if (expiring == 0 && (prev_time < next_time || ! next_time)) {
|
||||
if (sys_setalarm(next_time, 1) != OK)
|
||||
panic("cancel_timer: couldn't set alarm");
|
||||
}
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* expire_timers *
|
||||
*===========================================================================*/
|
||||
PUBLIC void expire_timers(clock_t now)
|
||||
{
|
||||
clock_t next_time;
|
||||
|
||||
/* Check for expired timers. Use a global variable to indicate that
|
||||
* watchdog functions are called, so that sys_setalarm() isn't called
|
||||
* more often than necessary when set_timer or cancel_timer are called
|
||||
* from these watchdog functions. */
|
||||
expiring = 1;
|
||||
tmrs_exptimers(&timers, now, &next_time);
|
||||
expiring = 0;
|
||||
|
||||
/* Reschedule an alarm if necessary. */
|
||||
if (next_time > 0) {
|
||||
if (sys_setalarm(next_time, 1) != OK)
|
||||
panic("expire_timers: couldn't set alarm");
|
||||
}
|
||||
}
|
|
@ -42,7 +42,6 @@ from DL_ETH:
|
|||
#include <sys/svrctl.h>
|
||||
#include <minix/ds.h>
|
||||
#include <minix/endpoint.h>
|
||||
#include <minix/drivers.h>
|
||||
#include <minix/driver.h>
|
||||
|
||||
#include "mq.h"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# Makefile for Process Manager (PM)
|
||||
PROG= pm
|
||||
SRCS= main.c forkexit.c break.c exec.c time.c timers.c alarm.c \
|
||||
SRCS= main.c forkexit.c break.c exec.c time.c alarm.c \
|
||||
signal.c utility.c table.c trace.c getset.c misc.c \
|
||||
profile.c dma.c mcontext.c schedule.c
|
||||
|
||||
|
|
|
@ -337,10 +337,10 @@ struct mproc *rmp; /* process that wants the alarm */
|
|||
clock_t ticks; /* how many ticks delay before the signal */
|
||||
{
|
||||
if (ticks > 0) {
|
||||
pm_set_timer(&rmp->mp_timer, ticks, cause_sigalrm, rmp->mp_endpoint);
|
||||
set_timer(&rmp->mp_timer, ticks, cause_sigalrm, rmp->mp_endpoint);
|
||||
rmp->mp_flags |= ALARM_ON;
|
||||
} else if (rmp->mp_flags & ALARM_ON) {
|
||||
pm_cancel_timer(&rmp->mp_timer);
|
||||
cancel_timer(&rmp->mp_timer);
|
||||
rmp->mp_flags &= ~ALARM_ON;
|
||||
}
|
||||
}
|
||||
|
@ -367,9 +367,10 @@ struct timer *tp;
|
|||
if ((rmp->mp_flags & ALARM_ON) == 0) return;
|
||||
|
||||
/* If an interval is set, set a new timer; otherwise clear the ALARM_ON flag.
|
||||
* The set_alarm call will be calling pm_set_timer from within this callback
|
||||
* from the pm_expire_timers function. This is safe, but we must not use the
|
||||
* "tp" structure below this point anymore. */
|
||||
* The set_alarm call will be calling set_timer from within this callback
|
||||
* from the expire_timers function. This is safe, but we must not use the
|
||||
* "tp" structure below this point anymore.
|
||||
*/
|
||||
if (rmp->mp_interval[ITIMER_REAL] > 0)
|
||||
set_alarm(rmp, rmp->mp_interval[ITIMER_REAL]);
|
||||
else rmp->mp_flags &= ~ALARM_ON;
|
||||
|
|
|
@ -94,7 +94,7 @@ PUBLIC int main()
|
|||
if (is_ipc_notify(ipc_status)) {
|
||||
switch(who_p) {
|
||||
case CLOCK:
|
||||
pm_expire_timers(m_in.NOTIFY_TIMESTAMP);
|
||||
expire_timers(m_in.NOTIFY_TIMESTAMP);
|
||||
result = SUSPEND; /* don't reply */
|
||||
break;
|
||||
default :
|
||||
|
@ -201,7 +201,7 @@ PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info)
|
|||
|
||||
/* Initialize process table, including timers. */
|
||||
for (rmp=&mproc[0]; rmp<&mproc[NR_PROCS]; rmp++) {
|
||||
tmr_inittimer(&rmp->mp_timer);
|
||||
init_timer(&rmp->mp_timer);
|
||||
}
|
||||
|
||||
/* Build the set of signals which cause core dumps, and the set of signals
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include <unistd.h>
|
||||
#include <minix/syslib.h>
|
||||
#include <minix/sysutil.h>
|
||||
#include <minix/timers.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
|
|
|
@ -92,12 +92,6 @@ _PROTOTYPE( int do_stime, (void) );
|
|||
_PROTOTYPE( int do_time, (void) );
|
||||
_PROTOTYPE( int do_times, (void) );
|
||||
|
||||
/* timers.c */
|
||||
_PROTOTYPE( void pm_set_timer, (timer_t *tp, int delta,
|
||||
tmr_func_t watchdog, int arg) );
|
||||
_PROTOTYPE( void pm_expire_timers, (clock_t now) );
|
||||
_PROTOTYPE( void pm_cancel_timer, (timer_t *tp) );
|
||||
|
||||
/* trace.c */
|
||||
_PROTOTYPE( int do_trace, (void) );
|
||||
_PROTOTYPE( void stop_proc, (struct mproc *rmp, int sig_nr) );
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
/* PM watchdog timer management. These functions in this file provide
|
||||
* a convenient interface to the timers library that manages a list of
|
||||
* watchdog timers. All details of scheduling an alarm at the CLOCK task
|
||||
* are hidden behind this interface.
|
||||
* Only system processes are allowed to set an alarm timer at the kernel.
|
||||
* Therefore, the PM maintains a local list of timers for user processes
|
||||
* that requested an alarm signal.
|
||||
*
|
||||
* The entry points into this file are:
|
||||
* pm_set_timer: reset and existing or set a new watchdog timer
|
||||
* pm_expire_timers: check for expired timers and run watchdog functions
|
||||
* pm_cancel_timer: remove a time from the list of timers
|
||||
*
|
||||
*/
|
||||
|
||||
#include "pm.h"
|
||||
|
||||
#include <timers.h>
|
||||
#include <minix/syslib.h>
|
||||
#include <minix/com.h>
|
||||
|
||||
PRIVATE timer_t *pm_timers = NULL;
|
||||
PRIVATE int pm_expiring = 0;
|
||||
|
||||
/*===========================================================================*
|
||||
* pm_set_timer *
|
||||
*===========================================================================*/
|
||||
PUBLIC void pm_set_timer(timer_t *tp, int ticks, tmr_func_t watchdog, int arg)
|
||||
{
|
||||
int r;
|
||||
clock_t now, prev_time = 0, next_time;
|
||||
|
||||
if ((r = getuptime(&now)) != OK)
|
||||
panic("PM couldn't get uptime");
|
||||
|
||||
/* Set timer argument and add timer to the list. */
|
||||
tmr_arg(tp)->ta_int = arg;
|
||||
prev_time = tmrs_settimer(&pm_timers,tp,now+ticks,watchdog,&next_time);
|
||||
|
||||
/* Reschedule our synchronous alarm if necessary. */
|
||||
if (pm_expiring == 0 && (! prev_time || prev_time > next_time)) {
|
||||
if (sys_setalarm(next_time, 1) != OK)
|
||||
panic("PM set timer couldn't set alarm");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* pm_expire_timers *
|
||||
*===========================================================================*/
|
||||
PUBLIC void pm_expire_timers(clock_t now)
|
||||
{
|
||||
clock_t next_time;
|
||||
|
||||
/* Check for expired timers. Use a global variable to indicate that
|
||||
* watchdog functions are called, so that sys_setalarm() isn't called
|
||||
* more often than necessary when pm_set_timer or pm_cancel_timer are
|
||||
* called from these watchdog functions. */
|
||||
pm_expiring = 1;
|
||||
tmrs_exptimers(&pm_timers, now, &next_time);
|
||||
pm_expiring = 0;
|
||||
|
||||
/* Reschedule an alarm if necessary. */
|
||||
if (next_time > 0) {
|
||||
if (sys_setalarm(next_time, 1) != OK)
|
||||
panic("PM expire timer couldn't set alarm");
|
||||
}
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* pm_cancel_timer *
|
||||
*===========================================================================*/
|
||||
PUBLIC void pm_cancel_timer(timer_t *tp)
|
||||
{
|
||||
clock_t next_time, prev_time;
|
||||
prev_time = tmrs_clrtimer(&pm_timers, tp, &next_time);
|
||||
|
||||
/* If the earliest timer has been removed, we have to set the alarm to
|
||||
* the next timer, or cancel the alarm altogether if the last timer has
|
||||
* been cancelled (next_time will be 0 then).
|
||||
*/
|
||||
if (pm_expiring == 0 && (prev_time < next_time || ! next_time)) {
|
||||
if (sys_setalarm(next_time, 1) != OK)
|
||||
panic("PM expire timer couldn't set alarm");
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
# Makefile for Scheduler (SCHED)
|
||||
PROG= sched
|
||||
SRCS= main.c schedule.c utility.c timers.c
|
||||
SRCS= main.c schedule.c utility.c
|
||||
|
||||
DPADD+= ${LIBSYS} ${LIBTIMERS}
|
||||
LDADD+= -lsys -ltimers
|
||||
|
|
|
@ -45,7 +45,7 @@ PUBLIC int main(void)
|
|||
if (is_ipc_notify(ipc_status)) {
|
||||
switch(who_e) {
|
||||
case CLOCK:
|
||||
sched_expire_timers(m_in.NOTIFY_TIMESTAMP);
|
||||
expire_timers(m_in.NOTIFY_TIMESTAMP);
|
||||
continue; /* don't reply */
|
||||
default :
|
||||
result = ENOSYS;
|
||||
|
|
|
@ -20,8 +20,3 @@ _PROTOTYPE( int no_sys, (int who_e, int call_nr) );
|
|||
_PROTOTYPE( int sched_isokendpt, (int ep, int *proc) );
|
||||
_PROTOTYPE( int sched_isemtyendpt, (int ep, int *proc) );
|
||||
_PROTOTYPE( int accept_message, (message *m_ptr) );
|
||||
|
||||
/* timers.c */
|
||||
_PROTOTYPE( void sched_set_timer, (timer_t *tp, int delta,
|
||||
tmr_func_t watchdog, int arg) );
|
||||
_PROTOTYPE( void sched_expire_timers, (clock_t now) );
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include <minix/syslib.h>
|
||||
#include <minix/sysutil.h>
|
||||
#include <minix/timers.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
|
|
|
@ -227,8 +227,8 @@ PRIVATE int schedule_process(struct schedproc * rmp)
|
|||
PUBLIC void init_scheduling(void)
|
||||
{
|
||||
balance_timeout = BALANCE_TIMEOUT * sys_hz();
|
||||
tmr_inittimer(&sched_timer);
|
||||
sched_set_timer(&sched_timer, balance_timeout, balance_queues, 0);
|
||||
init_timer(&sched_timer);
|
||||
set_timer(&sched_timer, balance_timeout, balance_queues, 0);
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
|
@ -255,5 +255,5 @@ PRIVATE void balance_queues(struct timer *tp)
|
|||
}
|
||||
}
|
||||
|
||||
sched_set_timer(&sched_timer, balance_timeout, balance_queues, 0);
|
||||
set_timer(&sched_timer, balance_timeout, balance_queues, 0);
|
||||
}
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
/* SCHED watchdog timer management, based on servers/pm/timers.c.
|
||||
*
|
||||
* The entry points into this file are:
|
||||
* sched_set_timer: reset and existing or set a new watchdog timer
|
||||
* sched_expire_timers: check for expired timers and run watchdog functions
|
||||
*
|
||||
*/
|
||||
|
||||
#include "sched.h"
|
||||
|
||||
#include <timers.h>
|
||||
#include <minix/syslib.h>
|
||||
#include <minix/com.h>
|
||||
|
||||
PRIVATE timer_t *sched_timers = NULL;
|
||||
PRIVATE int sched_expiring = 0;
|
||||
|
||||
/*===========================================================================*
|
||||
* pm_set_timer *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sched_set_timer(timer_t *tp, int ticks, tmr_func_t watchdog, int arg)
|
||||
{
|
||||
int r;
|
||||
clock_t now, prev_time = 0, next_time;
|
||||
|
||||
if ((r = getuptime(&now)) != OK)
|
||||
panic("SCHED couldn't get uptime");
|
||||
|
||||
/* Set timer argument and add timer to the list. */
|
||||
tmr_arg(tp)->ta_int = arg;
|
||||
prev_time = tmrs_settimer(&sched_timers,tp,now+ticks,watchdog,&next_time);
|
||||
|
||||
/* Reschedule our synchronous alarm if necessary. */
|
||||
if (sched_expiring == 0 && (! prev_time || prev_time > next_time)) {
|
||||
if (sys_setalarm(next_time, 1) != OK)
|
||||
panic("SCHED set timer couldn't set alarm");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*===========================================================================*
|
||||
* sched_expire_timers *
|
||||
*===========================================================================*/
|
||||
PUBLIC void sched_expire_timers(clock_t now)
|
||||
{
|
||||
clock_t next_time;
|
||||
|
||||
/* Check for expired timers. Use a global variable to indicate that
|
||||
* watchdog functions are called, so that sys_setalarm() isn't called
|
||||
* more often than necessary when sched_set_timer is
|
||||
* called from these watchdog functions. */
|
||||
sched_expiring = 1;
|
||||
tmrs_exptimers(&sched_timers, now, &next_time);
|
||||
sched_expiring = 0;
|
||||
|
||||
/* Reschedule an alarm if necessary. */
|
||||
if (next_time > 0) {
|
||||
if (sys_setalarm(next_time, 1) != OK)
|
||||
panic("SCHED expire timer couldn't set alarm");
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ PROG= vfs
|
|||
SRCS= main.c open.c read.c write.c pipe.c dmap.c \
|
||||
path.c device.c mount.c link.c exec.c \
|
||||
filedes.c stadir.c protect.c time.c \
|
||||
lock.c misc.c utility.c select.c timers.c table.c \
|
||||
lock.c misc.c utility.c select.c table.c \
|
||||
vnode.c vmnt.c request.c fscall.c
|
||||
|
||||
DPADD+= ${LIBSYS} ${LIBTIMERS}
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
|
||||
#include <minix/syslib.h>
|
||||
#include <minix/sysutil.h>
|
||||
#include <minix/timers.h>
|
||||
|
||||
#include "const.h"
|
||||
#include "dmap.h"
|
||||
|
|
|
@ -111,7 +111,7 @@ PUBLIC int main(void)
|
|||
/* Alarm timer expired. Used only for select().
|
||||
* Check it.
|
||||
*/
|
||||
fs_expire_timers(m_in.NOTIFY_TIMESTAMP);
|
||||
expire_timers(m_in.NOTIFY_TIMESTAMP);
|
||||
}
|
||||
else if(who_e == DS_PROC_NR)
|
||||
{
|
||||
|
|
|
@ -265,12 +265,3 @@ _PROTOTYPE( void select_timeout_check, (timer_t *) );
|
|||
_PROTOTYPE( void init_select, (void) );
|
||||
_PROTOTYPE( void select_unsuspend_by_endpt, (endpoint_t proc) );
|
||||
_PROTOTYPE( int select_notified, (int major, int minor, int ops) );
|
||||
|
||||
/* timers.c */
|
||||
_PROTOTYPE( void fs_set_timer, (timer_t *tp, int delta,
|
||||
tmr_func_t watchdog, int arg) );
|
||||
_PROTOTYPE( void fs_expire_timers, (clock_t now) );
|
||||
_PROTOTYPE( void fs_cancel_timer, (timer_t *tp) );
|
||||
_PROTOTYPE( void fs_init_timer, (timer_t *tp) );
|
||||
|
||||
|
||||
|
|
|
@ -235,7 +235,7 @@ PUBLIC int do_select(void)
|
|||
ticks = timeout.tv_sec * system_hz +
|
||||
(timeout.tv_usec * system_hz + USECPERSEC-1) / USECPERSEC;
|
||||
se->expiry = ticks;
|
||||
fs_set_timer(&se->timer, ticks, select_timeout_check, s);
|
||||
set_timer(&se->timer, ticks, select_timeout_check, s);
|
||||
}
|
||||
|
||||
/* if we're blocking, the table entry is now valid. */
|
||||
|
@ -456,7 +456,7 @@ PRIVATE void select_cancel_all(struct selectentry *e)
|
|||
#if DEBUG_SELECT
|
||||
printf("cancelling timer %d\n", e - selecttab);
|
||||
#endif
|
||||
fs_cancel_timer(&e->timer);
|
||||
cancel_timer(&e->timer);
|
||||
e->expiry = 0;
|
||||
}
|
||||
|
||||
|
@ -612,7 +612,7 @@ PUBLIC void init_select(void)
|
|||
int s;
|
||||
|
||||
for(s = 0; s < MAXSELECTS; s++)
|
||||
fs_init_timer(&selecttab[s].timer);
|
||||
init_timer(&selecttab[s].timer);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,61 +0,0 @@
|
|||
/* FS timers library
|
||||
*/
|
||||
|
||||
#include "fs.h"
|
||||
#include <timers.h>
|
||||
#include <minix/syslib.h>
|
||||
#include <minix/com.h>
|
||||
|
||||
PRIVATE timer_t *fs_timers = NULL;
|
||||
|
||||
PUBLIC void fs_set_timer(timer_t *tp, int ticks, tmr_func_t watchdog, int arg)
|
||||
{
|
||||
int r;
|
||||
clock_t now, old_head = 0, new_head;
|
||||
|
||||
if ((r = getuptime(&now)) != OK)
|
||||
panic("FS couldn't get uptime from system task");
|
||||
|
||||
tmr_arg(tp)->ta_int = arg;
|
||||
|
||||
old_head = tmrs_settimer(&fs_timers, tp, now+ticks, watchdog, &new_head);
|
||||
|
||||
/* reschedule our synchronous alarm if necessary */
|
||||
if (!old_head || old_head > new_head) {
|
||||
if (sys_setalarm(new_head, 1) != OK)
|
||||
panic("FS set timer couldn't set synchronous alarm");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PUBLIC void fs_expire_timers(clock_t now)
|
||||
{
|
||||
clock_t new_head;
|
||||
tmrs_exptimers(&fs_timers, now, &new_head);
|
||||
if (new_head > 0) {
|
||||
if (sys_setalarm(new_head, 1) != OK)
|
||||
panic("FS expire timer couldn't set synchronous alarm");
|
||||
}
|
||||
}
|
||||
|
||||
PUBLIC void fs_init_timer(timer_t *tp)
|
||||
{
|
||||
tmr_inittimer(tp);
|
||||
}
|
||||
|
||||
PUBLIC void fs_cancel_timer(timer_t *tp)
|
||||
{
|
||||
clock_t new_head, old_head;
|
||||
old_head = tmrs_clrtimer(&fs_timers, tp, &new_head);
|
||||
|
||||
/* if the earliest timer has been removed, we have to set
|
||||
* the synalarm to the next timer, or cancel the synalarm
|
||||
* altogether if th last time has been cancelled (new_head
|
||||
* will be 0 then).
|
||||
*/
|
||||
if (old_head < new_head || !new_head) {
|
||||
if (sys_setalarm(new_head, 1) != OK)
|
||||
panic("FS expire timer couldn't set synchronous alarm");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue