minix/servers/pm/timers.c
Ben Gras 35a108b911 panic() cleanup.
this change
   - makes panic() variadic, doing full printf() formatting -
     no more NO_NUM, and no more separate printf() statements
     needed to print extra info (or something in hex) before panicing
   - unifies panic() - same panic() name and usage for everyone -
     vm, kernel and rest have different names/syntax currently
     in order to implement their own luxuries, but no longer
   - throws out the 1st argument, to make source less noisy.
     the panic() in syslib retrieves the server name from the kernel
     so it should be clear enough who is panicing; e.g.
         panic("sigaction failed: %d", errno);
     looks like:
         at_wini(73130): panic: sigaction failed: 0
         syslib:panic.c: stacktrace: 0x74dc 0x2025 0x100a
   - throws out report() - printf() is more convenient and powerful
   - harmonizes/fixes the use of panic() - there were a few places
     that used printf-style formatting (didn't work) and newlines
     (messes up the formatting) in panic()
   - throws out a few per-server panic() functions
   - cleans up a tie-in of tty with panic()

merging printf() and panic() statements to be done incrementally.
2010-03-05 15:05:11 +00:00

87 lines
3 KiB
C

/* 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");
}
}