sched: simplify

- do not use timers when there is only ever one timer;
- do not include kernel header files for no reason;
- do not reply to notifications ever.

Change-Id: I5817e22c1b46c4e30e5135069df318af0b4f87fd
This commit is contained in:
David van Moolenbroek 2015-08-24 09:20:26 +02:00
parent 736b88cf53
commit 6c31058de4
6 changed files with 20 additions and 27 deletions

View file

@ -2,11 +2,7 @@
PROG= sched
SRCS= main.c schedule.c utility.c
DPADD+= ${LIBSYS} ${LIBTIMERS}
LDADD+= -lsys -ltimers
CPPFLAGS.main.c+= -I${NETBSDSRCDIR}/minix
CPPFLAGS.schedule.c+= -I${NETBSDSRCDIR}/minix
CPPFLAGS.utility.c+= -I${NETBSDSRCDIR}/minix
DPADD+= ${LIBSYS}
LDADD+= -lsys
.include <minix.service.mk>

View file

@ -50,13 +50,13 @@ int main(void)
if (is_ipc_notify(ipc_status)) {
switch(who_e) {
case CLOCK:
expire_timers(m_in.m_notify.timestamp);
continue; /* don't reply */
balance_queues();
break;
default :
result = ENOSYS;
break;
}
goto sendreply;
continue; /* Don't reply. */
}
switch(call_nr) {
@ -91,7 +91,6 @@ int main(void)
result = no_sys(who_e, call_nr);
}
sendreply:
/* Send reply. */
if (result != SUSPEND) {
m_in.m_type = result; /* build reply message */

View file

@ -1,7 +1,6 @@
/* Function prototypes. */
struct schedproc;
#include <minix/timers.h>
/* main.c */
int main(void);
@ -13,6 +12,7 @@ int do_start_scheduling(message *m_ptr);
int do_stop_scheduling(message *m_ptr);
int do_nice(message *m_ptr);
void init_scheduling(void);
void balance_queues(void);
/* utility.c */
int no_sys(int who_e, int call_nr);

View file

@ -10,7 +10,6 @@
#include <minix/syslib.h>
#include <minix/sysutil.h>
#include <minix/timers.h>
#include <errno.h>

View file

@ -12,15 +12,12 @@
#include <assert.h>
#include <minix/com.h>
#include <machine/archtypes.h>
#include "kernel/proc.h" /* for queue constants */
static minix_timer_t sched_timer;
static unsigned balance_timeout;
#define BALANCE_TIMEOUT 5 /* how often to balance queues in seconds */
static int schedule_process(struct schedproc * rmp, unsigned flags);
static void balance_queues(minix_timer_t *tp);
#define SCHEDULE_CHANGE_PRIO 0x1
#define SCHEDULE_CHANGE_QUANTUM 0x2
@ -330,29 +327,31 @@ static int schedule_process(struct schedproc * rmp, unsigned flags)
/*===========================================================================*
* start_scheduling *
* init_scheduling *
*===========================================================================*/
void init_scheduling(void)
{
int r;
balance_timeout = BALANCE_TIMEOUT * sys_hz();
init_timer(&sched_timer);
set_timer(&sched_timer, balance_timeout, balance_queues, 0);
if ((r = sys_setalarm(balance_timeout, 0)) != OK)
panic("sys_setalarm failed: %d", r);
}
/*===========================================================================*
* balance_queues *
*===========================================================================*/
/* This function in called every 100 ticks to rebalance the queues. The current
/* This function in called every N ticks to rebalance the queues. The current
* scheduler bumps processes down one priority when ever they run out of
* quantum. This function will find all proccesses that have been bumped down,
* and pulls them back up. This default policy will soon be changed.
*/
static void balance_queues(minix_timer_t *tp)
void balance_queues(void)
{
struct schedproc *rmp;
int proc_nr;
int r, proc_nr;
for (proc_nr=0, rmp=schedproc; proc_nr < NR_PROCS; proc_nr++, rmp++) {
if (rmp->flags & IN_USE) {
@ -363,5 +362,6 @@ static void balance_queues(minix_timer_t *tp)
}
}
set_timer(&sched_timer, balance_timeout, balance_queues, 0);
if ((r = sys_setalarm(balance_timeout, 0)) != OK)
panic("sys_setalarm failed: %d", r);
}

View file

@ -10,7 +10,6 @@
#include "sched.h"
#include <machine/archtypes.h>
#include <sys/resource.h> /* for PRIO_MAX & PRIO_MIN */
#include "kernel/proc.h" /* for queue constants */
#include "schedproc.h"
/*===========================================================================*