Cleanup of PM.

This commit is contained in:
Jorrit Herder 2005-08-05 10:45:54 +00:00
parent e21c135fe5
commit 7e74927cdc
5 changed files with 47 additions and 46 deletions

View file

@ -17,8 +17,6 @@
*/ */
#define PM_PID 0 /* PM's process id number */ #define PM_PID 0 /* PM's process id number */
#define INIT_PID 1 /* INIT's process id number */ #define INIT_PID 1 /* INIT's process id number */
#define DEBUG(x,y) if ((x)) { (y); }

View file

@ -51,14 +51,12 @@ PUBLIC void main()
get_work(); /* wait for an PM system call */ get_work(); /* wait for an PM system call */
/* Check for system notifications first. Special cases. */ /* Check for system notifications first. Special cases. */
if (call_nr == SYN_ALARM) { if (call_nr == SYN_ALARM) {
pm_expire_timers(m_in.NOTIFY_TIMESTAMP); pm_expire_timers(m_in.NOTIFY_TIMESTAMP);
result = SUSPEND; /* don't reply */ result = SUSPEND; /* don't reply */
} else if (call_nr == SYS_SIG) { /* signals pending */ } else if (call_nr == SYS_SIG) { /* signals pending */
sigset = m_in.NOTIFY_ARG; sigset = m_in.NOTIFY_ARG;
if (sigismember(&sigset, SIGKSIG)) { if (sigismember(&sigset, SIGKSIG)) (void) ksig_pending();
(void) ksig_pending();
}
result = SUSPEND; /* don't reply */ result = SUSPEND; /* don't reply */
} }
/* Else, if the system call number is valid, perform the call. */ /* Else, if the system call number is valid, perform the call. */
@ -181,7 +179,7 @@ PRIVATE void pm_init()
/* Get the memory map of the kernel to see how much memory it uses. */ /* Get the memory map of the kernel to see how much memory it uses. */
if ((s=get_mem_map(SYSTASK, mem_map)) != OK) if ((s=get_mem_map(SYSTASK, mem_map)) != OK)
panic(__FILE__,"PM couldn't get memory map of SYSTASK",s); panic(__FILE__,"couldn't get memory map of SYSTASK",s);
minix_clicks = (mem_map[S].mem_phys+mem_map[S].mem_len)-mem_map[T].mem_phys; minix_clicks = (mem_map[S].mem_phys+mem_map[S].mem_len)-mem_map[T].mem_phys;
patch_mem_chunks(mem_chunks, mem_map); patch_mem_chunks(mem_chunks, mem_map);
@ -189,7 +187,7 @@ PRIVATE void pm_init()
* that is defined at the kernel level to see which slots to fill in. * that is defined at the kernel level to see which slots to fill in.
*/ */
if (OK != (s=sys_getimage(image))) if (OK != (s=sys_getimage(image)))
panic(__FILE__,"PM: warning, couldn't get image table: %d\n", s); panic(__FILE__,"couldn't get image table: %d\n", s);
procs_in_use = 0; /* start populating table */ procs_in_use = 0; /* start populating table */
printf("Building process table:"); /* show what's happening */ printf("Building process table:"); /* show what's happening */
for (ip = &image[0]; ip < &image[NR_BOOT_PROCS]; ip++) { for (ip = &image[0]; ip < &image[NR_BOOT_PROCS]; ip++) {
@ -228,7 +226,7 @@ PRIVATE void pm_init()
mess.PR_PROC_NR = ip->proc_nr; mess.PR_PROC_NR = ip->proc_nr;
mess.PR_PID = rmp->mp_pid; mess.PR_PID = rmp->mp_pid;
if (OK != (s=send(FS_PROC_NR, &mess))) if (OK != (s=send(FS_PROC_NR, &mess)))
panic(__FILE__,"PM can't sync up with FS", s); panic(__FILE__,"can't sync up with FS", s);
printf(" %s", ip->proc_name); /* display process name */ printf(" %s", ip->proc_name); /* display process name */
} }
} }
@ -244,7 +242,7 @@ PRIVATE void pm_init()
/* Tell FS that no more system processes follow and synchronize. */ /* Tell FS that no more system processes follow and synchronize. */
mess.PR_PROC_NR = NONE; mess.PR_PROC_NR = NONE;
if (sendrec(FS_PROC_NR, &mess) != OK || mess.m_type != OK) if (sendrec(FS_PROC_NR, &mess) != OK || mess.m_type != OK)
panic(__FILE__,"PM can't sync up with FS", NO_NUM); panic(__FILE__,"can't sync up with FS", NO_NUM);
/* Possibly we must correct the memory chunks for the boot device. */ /* Possibly we must correct the memory chunks for the boot device. */
if (kinfo.bootdev_size > 0) { if (kinfo.bootdev_size > 0) {
@ -255,7 +253,7 @@ PRIVATE void pm_init()
} }
/* Initialize tables to all physical memory and print memory information. */ /* Initialize tables to all physical memory and print memory information. */
printf("Parsing memory:"); printf("Gathering memory:");
mem_init(mem_chunks, &free_clicks); mem_init(mem_chunks, &free_clicks);
total_clicks = minix_clicks + free_clicks; total_clicks = minix_clicks + free_clicks;
printf(" total %u KB,", click_to_round_k(total_clicks)); printf(" total %u KB,", click_to_round_k(total_clicks));

View file

@ -3,7 +3,7 @@
* The entry points into this file are * The entry points into this file are
* do_time: perform the TIME system call * do_time: perform the TIME system call
* do_stime: perform the STIME system call * do_stime: perform the STIME system call
* do_tims: perform the TIMES system call * do_times: perform the TIMES system call
*/ */
#include "pm.h" #include "pm.h"

View file

@ -1,77 +1,82 @@
/* PM watchdog timer management. /* 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 "pm.h"
#define VERBOSE 0
#include <timers.h> #include <timers.h>
#include <minix/syslib.h> #include <minix/syslib.h>
#include <minix/com.h> #include <minix/com.h>
PRIVATE timer_t *pm_timers = NULL; PRIVATE timer_t *pm_timers = NULL;
/*===========================================================================*
* pm_set_timer *
*===========================================================================*/
PUBLIC void pm_set_timer(timer_t *tp, int ticks, tmr_func_t watchdog, int arg) PUBLIC void pm_set_timer(timer_t *tp, int ticks, tmr_func_t watchdog, int arg)
{ {
int r; int r;
clock_t now, prev_time = 0, next_time; clock_t now, prev_time = 0, next_time;
if((r = getuptime(&now)) != OK) if((r = getuptime(&now)) != OK)
panic(__FILE__, "PM couldn't get uptime from system task.", NO_NUM); panic(__FILE__, "PM couldn't get uptime", NO_NUM);
/* Set timer argument. */ /* Set timer argument and add timer to the list. */
tmr_arg(tp)->ta_int = arg; tmr_arg(tp)->ta_int = arg;
prev_time = tmrs_settimer(&pm_timers,tp,now+ticks,watchdog,&next_time);
prev_time = tmrs_settimer(&pm_timers, tp, now+ticks, watchdog, &next_time); /* Reschedule our synchronous alarm if necessary. */
/* reschedule our synchronous alarm if necessary */
if(! prev_time || prev_time > next_time) { if(! prev_time || prev_time > next_time) {
if(sys_setalarm(next_time, 1) != OK) if(sys_setalarm(next_time, 1) != OK)
panic(__FILE__, "PM set timer couldn't set synchronous alarm.", NO_NUM); panic(__FILE__, "PM set timer couldn't set alarm.", NO_NUM);
#if VERBOSE
else
printf("timers: after setting, set synalarm to %d -> %d\n", prev_time, next_time);
#endif
} }
return; return;
} }
/*===========================================================================*
* pm_expire_timers *
*===========================================================================*/
PUBLIC void pm_expire_timers(clock_t now) PUBLIC void pm_expire_timers(clock_t now)
{ {
clock_t next_time; clock_t next_time;
/* Check for expired timers and possibly reschedule an alarm. */
tmrs_exptimers(&pm_timers, now, &next_time); tmrs_exptimers(&pm_timers, now, &next_time);
if(next_time > 0) { if(next_time > 0) {
if(sys_setalarm(next_time, 1) != OK) if(sys_setalarm(next_time, 1) != OK)
panic(__FILE__, "PM expire timer couldn't set synchronous alarm.", NO_NUM); panic(__FILE__, "PM expire timer couldn't set alarm.", NO_NUM);
#if VERBOSE
else
printf("timers: after expiry, set synalarm to %d\n", next_time);
#endif
} }
#if VERBOSE
else printf("after expiry, no new timer set\n");
#endif
} }
/*===========================================================================*
* pm_cancel_timer *
*===========================================================================*/
PUBLIC void pm_cancel_timer(timer_t *tp) PUBLIC void pm_cancel_timer(timer_t *tp)
{ {
clock_t next_time, prev_time; clock_t next_time, prev_time;
prev_time = tmrs_clrtimer(&pm_timers, tp, &next_time); prev_time = tmrs_clrtimer(&pm_timers, tp, &next_time);
/* if the earliest timer has been removed, we have to set /* If the earliest timer has been removed, we have to set the alarm to
* the synalarm to the next timer, or cancel the synalarm * the next timer, or cancel the alarm altogether if the last timer has
* altogether if th last time has been cancelled (next_time * been cancelled (next_time will be 0 then).
* will be 0 then).
*/ */
if(prev_time < next_time || ! next_time) { if(prev_time < next_time || ! next_time) {
if(sys_setalarm(next_time, 1) != OK) if(sys_setalarm(next_time, 1) != OK)
panic(__FILE__, "PM expire timer couldn't set synchronous alarm.", NO_NUM); panic(__FILE__, "PM expire timer couldn't set alarm.", NO_NUM);
#if VERBOSE
printf("timers: after cancelling, set synalarm to %d -> %d\n", prev_time, next_time);
#endif
} }
#if VERBOSE
else printf("timers: after cancelling no new timer\n");
#endif
} }

View file

@ -99,7 +99,7 @@ PUBLIC int no_sys()
{ {
/* A system call number not implemented by PM has been requested. */ /* A system call number not implemented by PM has been requested. */
return(EINVAL); return(ENOSYS);
} }