diff options
-rw-r--r-- | sys/alpha/alpha/trap.c | 1 | ||||
-rw-r--r-- | sys/alpha/include/cpu.h | 5 | ||||
-rw-r--r-- | sys/amd64/amd64/trap.c | 1 | ||||
-rw-r--r-- | sys/amd64/include/cpu.h | 5 | ||||
-rw-r--r-- | sys/i386/i386/trap.c | 1 | ||||
-rw-r--r-- | sys/i386/include/cpu.h | 5 | ||||
-rw-r--r-- | sys/kern/kern_synch.c | 58 | ||||
-rw-r--r-- | sys/kern/subr_trap.c | 1 | ||||
-rw-r--r-- | sys/sys/systm.h | 1 |
9 files changed, 61 insertions, 17 deletions
diff --git a/sys/alpha/alpha/trap.c b/sys/alpha/alpha/trap.c index 7e9b15e..b7c8b47 100644 --- a/sys/alpha/alpha/trap.c +++ b/sys/alpha/alpha/trap.c @@ -129,6 +129,7 @@ userret(p, pc, oticks) } curpriority = p->p_priority; + currtpriority = p->p_rtprio.prio; } static void diff --git a/sys/alpha/include/cpu.h b/sys/alpha/include/cpu.h index b6b5b41..c9a89d4 100644 --- a/sys/alpha/include/cpu.h +++ b/sys/alpha/include/cpu.h @@ -71,7 +71,7 @@ struct clockframe { * Preempt the current process if in interrupt from user mode, * or after the current trap/syscall if in system mode. */ -#define need_resched() { want_resched = 1; aston(); } +#define need_resched() do { want_resched = 1; aston(); } while (0) #define resched_wanted() want_resched @@ -80,7 +80,8 @@ struct clockframe { * buffer pages are invalid. On the hp300, request an ast to send us * through trap, marking the proc as needing a profiling tick. */ -#define need_proftick(p) { (p)->p_flag |= P_OWEUPC; aston(); } +#define need_proftick(p) \ + do { (p)->p_flag |= P_OWEUPC; aston(); } while (0) /* * Notify the current process (p) that it has a signal pending, diff --git a/sys/amd64/amd64/trap.c b/sys/amd64/amd64/trap.c index a8b73cf..836555c 100644 --- a/sys/amd64/amd64/trap.c +++ b/sys/amd64/amd64/trap.c @@ -196,6 +196,7 @@ userret(p, frame, oticks) (u_int)(p->p_sticks - oticks) * psratio); curpriority = p->p_priority; + currtpriority = p->p_rtprio.prio; } /* diff --git a/sys/amd64/include/cpu.h b/sys/amd64/include/cpu.h index 666af5c..18049d0 100644 --- a/sys/amd64/include/cpu.h +++ b/sys/amd64/include/cpu.h @@ -83,7 +83,7 @@ * Preempt the current process if in interrupt from user mode, * or after the current trap/syscall if in system mode. */ -#define need_resched() { want_resched = 1; aston(); } +#define need_resched() do { want_resched = 1; aston(); } while (0) #define resched_wanted() want_resched @@ -94,7 +94,8 @@ * single tick and the P_OWEUPC flag served as a counter. Now there is a * counter in the proc table and flag isn't really necessary. */ -#define need_proftick(p) { (p)->p_flag |= P_OWEUPC; aston(); } +#define need_proftick(p) \ + do { (p)->p_flag |= P_OWEUPC; aston(); } while (0) /* * Notify the current process (p) that it has a signal pending, diff --git a/sys/i386/i386/trap.c b/sys/i386/i386/trap.c index a8b73cf..836555c 100644 --- a/sys/i386/i386/trap.c +++ b/sys/i386/i386/trap.c @@ -196,6 +196,7 @@ userret(p, frame, oticks) (u_int)(p->p_sticks - oticks) * psratio); curpriority = p->p_priority; + currtpriority = p->p_rtprio.prio; } /* diff --git a/sys/i386/include/cpu.h b/sys/i386/include/cpu.h index 666af5c..18049d0 100644 --- a/sys/i386/include/cpu.h +++ b/sys/i386/include/cpu.h @@ -83,7 +83,7 @@ * Preempt the current process if in interrupt from user mode, * or after the current trap/syscall if in system mode. */ -#define need_resched() { want_resched = 1; aston(); } +#define need_resched() do { want_resched = 1; aston(); } while (0) #define resched_wanted() want_resched @@ -94,7 +94,8 @@ * single tick and the P_OWEUPC flag served as a counter. Now there is a * counter in the proc table and flag isn't really necessary. */ -#define need_proftick(p) { (p)->p_flag |= P_OWEUPC; aston(); } +#define need_proftick(p) \ + do { (p)->p_flag |= P_OWEUPC; aston(); } while (0) /* * Notify the current process (p) that it has a signal pending, diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index a21c515..8d0a8ee 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -65,11 +65,14 @@ static void sched_setup __P((void *dummy)); SYSINIT(sched_setup, SI_SUB_KICK_SCHEDULER, SI_ORDER_FIRST, sched_setup, NULL) u_char curpriority; +u_char currtpriority; int hogticks; int lbolt; int sched_quantum; /* Roundrobin scheduling quantum in ticks. */ +static int curpriority_cmp __P((struct proc *p)); static void endtsleep __P((void *)); +static void maybe_resched __P((struct proc *chk)); static void roundrobin __P((void *arg)); static void schedcpu __P((void *arg)); static void updatepri __P((struct proc *p)); @@ -93,28 +96,59 @@ sysctl_kern_quantum SYSCTL_HANDLER_ARGS SYSCTL_PROC(_kern, OID_AUTO, quantum, CTLTYPE_INT|CTLFLAG_RW, 0, sizeof sched_quantum, sysctl_kern_quantum, "I", ""); -/* maybe_resched: Decide if you need to reschedule or not - * taking the priorities and schedulers into account. +/*- + * Compare priorities. Return: + * <0: priority of p < current priority + * 0: priority of p == current priority + * >0: priority of p > current priority + * The priorities are the normal priorities or the normal realtime priorities + * if p is on the same scheduler as curproc. Otherwise the process on the + * more realtimeish scheduler has lowest priority. As usual, a higher + * priority really means a lower priority. */ -static void maybe_resched(struct proc *chk) +static int +curpriority_cmp(p) + struct proc *p; +{ + int c_class, p_class; + + if (curproc->p_rtprio.prio != currtpriority) + Debugger("currtprio"); + c_class = RTP_PRIO_BASE(curproc->p_rtprio.type); + p_class = RTP_PRIO_BASE(p->p_rtprio.type); + if (p_class != c_class) + return (p_class - c_class); + if (p_class == RTP_PRIO_NORMAL) + return (((int)p->p_priority - (int)curpriority) / PPQ); + return ((int)p->p_rtprio.prio - (int)currtpriority); +} + +/* + * Arrange to reschedule if necessary, taking the priorities and + * schedulers into account. + */ +static void +maybe_resched(chk) + struct proc *chk; { struct proc *p = curproc; /* XXX */ /* - * Compare priorities if the new process is on the same scheduler, - * otherwise the one on the more realtimeish scheduler wins. - * * XXX idle scheduler still broken because proccess stays on idle * scheduler during waits (such as when getting FS locks). If a * standard process becomes runaway cpu-bound, the system can lockup * due to idle-scheduler processes in wakeup never getting any cpu. */ - if (p == 0 || - (chk->p_priority < curpriority && RTP_PRIO_BASE(p->p_rtprio.type) == RTP_PRIO_BASE(chk->p_rtprio.type)) || - RTP_PRIO_BASE(chk->p_rtprio.type) < RTP_PRIO_BASE(p->p_rtprio.type) - ) { + if (p == NULL) { +#if 0 + need_resched(); +#endif + } else if (chk == p) { + /* We may need to yield if our priority has been raised. */ + if (curpriority_cmp(chk) > 0) + need_resched(); + } else if (curpriority_cmp(chk) < 0) need_resched(); - } } int @@ -437,6 +471,7 @@ tsleep(ident, priority, wmesg, timo) mi_switch(); resume: curpriority = p->p_usrpri; + currtpriority = p->p_rtprio.prio; splx(s); p->p_flag &= ~P_SINTR; if (p->p_flag & P_TIMEOUT) { @@ -576,6 +611,7 @@ await(int priority, int timo) mi_switch(); resume: curpriority = p->p_usrpri; + currtpriority = p->p_rtprio.prio; splx(s); p->p_flag &= ~P_SINTR; diff --git a/sys/kern/subr_trap.c b/sys/kern/subr_trap.c index a8b73cf..836555c 100644 --- a/sys/kern/subr_trap.c +++ b/sys/kern/subr_trap.c @@ -196,6 +196,7 @@ userret(p, frame, oticks) (u_int)(p->p_sticks - oticks) * psratio); curpriority = p->p_priority; + currtpriority = p->p_rtprio.prio; } /* diff --git a/sys/sys/systm.h b/sys/sys/systm.h index 3c2d784..2898389 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -59,6 +59,7 @@ extern int nswap; /* size of swap space */ extern int selwait; /* select timeout address */ extern u_char curpriority; /* priority of current process */ +extern u_char currtpriority; /* realtime priority of current process */ extern int physmem; /* physical memory */ |