From 7216391e4989b73d7794fefd88de3d13f3c9f075 Mon Sep 17 00:00:00 2001 From: David Greenman Date: Sun, 2 Oct 1994 04:48:21 +0000 Subject: [PATCH] "idle priority" support. Based on code from Henrik Vestergaard Draboel, but substantially rewritten by me. --- sys/amd64/amd64/cpu_switch.S | 107 +++++++++++++++++++--- sys/amd64/amd64/genassym.c | 5 +- sys/amd64/amd64/swtch.s | 107 +++++++++++++++++++--- sys/i386/i386/genassym.c | 5 +- sys/i386/i386/swtch.s | 107 +++++++++++++++++++--- sys/kern/init_main.c | 5 +- sys/kern/init_sysent.c | 4 +- sys/kern/kern_fork.c | 7 +- sys/kern/kern_proc.c | 3 +- sys/kern/kern_resource.c | 79 +++++++++------- sys/kern/kern_synch.c | 5 +- sys/kern/syscalls.c | 2 +- sys/kern/syscalls.master | 4 +- sys/sys/proc.h | 5 +- sys/sys/rtprio.h | 30 ++++-- sys/sys/syscall-hide.h | 2 +- sys/sys/syscall.h | 2 +- usr.sbin/rtprio/Makefile | 6 +- usr.sbin/rtprio/rtprio.1 | 92 +++++++++++++------ usr.sbin/rtprio/rtprio.2 | 106 ++++++++++++++++++++++ usr.sbin/rtprio/rtprio.c | 171 ++++++++++++++++++----------------- 21 files changed, 635 insertions(+), 219 deletions(-) create mode 100644 usr.sbin/rtprio/rtprio.2 diff --git a/sys/amd64/amd64/cpu_switch.S b/sys/amd64/amd64/cpu_switch.S index ad83a9a2e0c..ab405002e70 100644 --- a/sys/amd64/amd64/cpu_switch.S +++ b/sys/amd64/amd64/cpu_switch.S @@ -33,7 +33,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: swtch.s,v 1.13 1994/09/02 05:58:51 davidg Exp $ + * $Id: swtch.s,v 1.14 1994/10/01 02:56:03 davidg Exp $ */ #include "npx.h" /* for NNPX */ @@ -59,10 +59,11 @@ * queues. */ .data - .globl _curpcb, _whichqs, _whichrtqs + .globl _curpcb, _whichqs, _whichrtqs, _whichidqs _curpcb: .long 0 /* pointer to curproc's PCB area */ _whichqs: .long 0 /* which run queues have data */ _whichrtqs: .long 0 /* which realtime run queues have data */ +_whichidqs: .long 0 /* which idletime run queues have data */ .globl _qs,_cnt,_panic .comm _noproc,4 @@ -84,10 +85,15 @@ ENTRY(setrunqueue) pushl $set2 call _panic set1: - cmpl $RTPRIO_RTOFF,P_RTPRIO(%eax) /* Realtime process ? */ - je set1_nort + cmpw $RTP_PRIO_NORMAL,P_RTPRIO_TYPE(%eax) /* normal priority process? */ + je set_nort - movl P_RTPRIO(%eax),%edx + movzwl P_RTPRIO_PRIO(%eax),%edx + + cmpw $RTP_PRIO_REALTIME,P_RTPRIO_TYPE(%eax) /* realtime priority? */ + jne set_id /* must be idle priority */ + +set_rt: btsl %edx,_whichrtqs /* set q full bit */ shll $3,%edx addl $_rtqs,%edx /* locate q hdr */ @@ -97,7 +103,19 @@ set1: movl %eax,P_BACK(%edx) movl %eax,P_FORW(%ecx) ret -set1_nort: + +set_id: + btsl %edx,_whichidqs /* set q full bit */ + shll $3,%edx + addl $_idqs,%edx /* locate q hdr */ + movl %edx,P_FORW(%eax) /* link process on tail of q */ + movl P_BACK(%edx),%ecx + movl %ecx,P_BACK(%eax) + movl %eax,P_BACK(%edx) + movl %eax,P_FORW(%ecx) + ret + +set_nort: /* Normal (RTOFF) code */ movzbl P_PRI(%eax),%edx shrl $2,%edx btsl %edx,_whichqs /* set q full bit */ @@ -119,13 +137,17 @@ set2: .asciz "setrunqueue" */ ENTRY(remrq) movl 4(%esp),%eax - cmpl $RTPRIO_RTOFF,P_RTPRIO(%eax) /* Realtime process ? */ + cmpw $RTP_PRIO_NORMAL,P_RTPRIO_TYPE(%eax) /* normal priority process? */ je rem_nort - movl P_RTPRIO(%eax),%edx + movzwl P_RTPRIO_PRIO(%eax),%edx + + cmpw $RTP_PRIO_REALTIME,P_RTPRIO_TYPE(%eax) /* normal priority process? */ + jne rem_id + btrl %edx,_whichrtqs /* clear full bit, panic if clear already */ jb rem1rt - pushl $rem3 + pushl $rem3rt call _panic rem1rt: pushl %edx @@ -146,6 +168,31 @@ rem1rt: rem2rt: movl $0,P_BACK(%eax) /* zap reverse link to indicate off list */ ret +rem_id: + btrl %edx,_whichidqs /* clear full bit, panic if clear already */ + jb rem1id + pushl $rem3id + call _panic +rem1id: + pushl %edx + movl P_FORW(%eax),%ecx /* unlink process */ + movl P_BACK(%eax),%edx + movl %edx,P_BACK(%ecx) + movl P_BACK(%eax),%ecx + movl P_FORW(%eax),%edx + movl %edx,P_FORW(%ecx) + popl %edx + movl $_idqs,%ecx + shll $3,%edx + addl %edx,%ecx + cmpl P_FORW(%ecx),%ecx /* q still has something? */ + je rem2id + shrl $3,%edx /* yes, set bit as still full */ + btsl %edx,_whichidqs +rem2id: + movl $0,P_BACK(%eax) /* zap reverse link to indicate off list */ + ret + rem_nort: movzbl P_PRI(%eax),%edx shrl $2,%edx @@ -174,6 +221,8 @@ rem2: ret rem3: .asciz "remrq" +rem3rt: .asciz "remrq.rt" +rem3id: .asciz "remrq.id" sw0: .asciz "cpu_switch" /* @@ -200,10 +249,12 @@ _idle: ALIGN_TEXT idle_loop: cli - cmpl $0,_whichrtqs + cmpl $0,_whichrtqs /* real-time queue */ jne sw1a - cmpl $0,_whichqs + cmpl $0,_whichqs /* normal queue */ jne nortqr + cmpl $0,_whichidqs /* 'idle' queue */ + jne idqr #ifdef APM call _apm_cpu_idle call _apm_cpu_busy @@ -269,7 +320,6 @@ sw1a: testl %edi,%edi jz nortqr /* no realtime procs */ -rt2: /* XXX - bsf is sloow */ bsfl %edi,%ebx /* find a full q */ jz nortqr /* no proc on rt q - try normal ... */ @@ -298,12 +348,13 @@ rt3: jmp swtch_com /* old sw1a */ +/* Normal process priority's */ nortqr: movl _whichqs,%edi 2: /* XXX - bsf is sloow */ bsfl %edi,%ebx /* find a full q */ - jz _idle /* if none, idle */ + jz idqr /* if none, idle */ /* XX update whichqs? */ btrl %ebx,%edi /* clear q full status */ @@ -326,6 +377,36 @@ nortqr: btsl %ebx,%edi /* nope, set to indicate not empty */ 3: movl %edi,_whichqs /* update q status */ + jmp swtch_com + +idqr: /* was sw1a */ + movl _whichidqs,%edi /* pick next p. from idqs */ + + /* XXX - bsf is sloow */ + bsfl %edi,%ebx /* find a full q */ + jz _idle /* no proc, idle */ + + /* XX update whichqs? */ + btrl %ebx,%edi /* clear q full status */ + leal _idqs(,%ebx,8),%eax /* select q */ + movl %eax,%esi + +#ifdef DIAGNOSTIC + cmpl P_FORW(%eax),%eax /* linked to self? (e.g. not on list) */ + je badsw /* not possible */ +#endif + + movl P_FORW(%eax),%ecx /* unlink from front of process q */ + movl P_FORW(%ecx),%edx + movl %edx,P_FORW(%eax) + movl P_BACK(%ecx),%eax + movl %eax,P_BACK(%edx) + + cmpl P_FORW(%ecx),%esi /* q empty */ + je id3 + btsl %ebx,%edi /* nope, set to indicate not empty */ +id3: + movl %edi,_whichidqs /* update q status */ swtch_com: movl $0,%eax diff --git a/sys/amd64/amd64/genassym.c b/sys/amd64/amd64/genassym.c index c5685444d97..1ea7ba1e171 100644 --- a/sys/amd64/amd64/genassym.c +++ b/sys/amd64/amd64/genassym.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)genassym.c 5.11 (Berkeley) 5/10/91 - * $Id: genassym.c,v 1.11 1994/09/12 11:38:03 davidg Exp $ + * $Id: genassym.c,v 1.12 1994/10/02 01:28:38 rgrimes Exp $ */ #include @@ -78,7 +78,8 @@ main() printf("#define\tVM_PMAP %d\n", &vms->vm_pmap); printf("#define\tP_ADDR %d\n", &p->p_addr); printf("#define\tP_PRI %d\n", &p->p_priority); - printf("#define\tP_RTPRIO %d\n", &p->p_rtprio); + printf("#define\tP_RTPRIO_TYPE %d\n", &p->p_rtprio.type); + printf("#define\tP_RTPRIO_PRIO %d\n", &p->p_rtprio.prio); printf("#define\tP_STAT %d\n", &p->p_stat); printf("#define\tP_WCHAN %d\n", &p->p_wchan); printf("#define\tP_FLAG %d\n", &p->p_flag); diff --git a/sys/amd64/amd64/swtch.s b/sys/amd64/amd64/swtch.s index ad83a9a2e0c..ab405002e70 100644 --- a/sys/amd64/amd64/swtch.s +++ b/sys/amd64/amd64/swtch.s @@ -33,7 +33,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: swtch.s,v 1.13 1994/09/02 05:58:51 davidg Exp $ + * $Id: swtch.s,v 1.14 1994/10/01 02:56:03 davidg Exp $ */ #include "npx.h" /* for NNPX */ @@ -59,10 +59,11 @@ * queues. */ .data - .globl _curpcb, _whichqs, _whichrtqs + .globl _curpcb, _whichqs, _whichrtqs, _whichidqs _curpcb: .long 0 /* pointer to curproc's PCB area */ _whichqs: .long 0 /* which run queues have data */ _whichrtqs: .long 0 /* which realtime run queues have data */ +_whichidqs: .long 0 /* which idletime run queues have data */ .globl _qs,_cnt,_panic .comm _noproc,4 @@ -84,10 +85,15 @@ ENTRY(setrunqueue) pushl $set2 call _panic set1: - cmpl $RTPRIO_RTOFF,P_RTPRIO(%eax) /* Realtime process ? */ - je set1_nort + cmpw $RTP_PRIO_NORMAL,P_RTPRIO_TYPE(%eax) /* normal priority process? */ + je set_nort - movl P_RTPRIO(%eax),%edx + movzwl P_RTPRIO_PRIO(%eax),%edx + + cmpw $RTP_PRIO_REALTIME,P_RTPRIO_TYPE(%eax) /* realtime priority? */ + jne set_id /* must be idle priority */ + +set_rt: btsl %edx,_whichrtqs /* set q full bit */ shll $3,%edx addl $_rtqs,%edx /* locate q hdr */ @@ -97,7 +103,19 @@ set1: movl %eax,P_BACK(%edx) movl %eax,P_FORW(%ecx) ret -set1_nort: + +set_id: + btsl %edx,_whichidqs /* set q full bit */ + shll $3,%edx + addl $_idqs,%edx /* locate q hdr */ + movl %edx,P_FORW(%eax) /* link process on tail of q */ + movl P_BACK(%edx),%ecx + movl %ecx,P_BACK(%eax) + movl %eax,P_BACK(%edx) + movl %eax,P_FORW(%ecx) + ret + +set_nort: /* Normal (RTOFF) code */ movzbl P_PRI(%eax),%edx shrl $2,%edx btsl %edx,_whichqs /* set q full bit */ @@ -119,13 +137,17 @@ set2: .asciz "setrunqueue" */ ENTRY(remrq) movl 4(%esp),%eax - cmpl $RTPRIO_RTOFF,P_RTPRIO(%eax) /* Realtime process ? */ + cmpw $RTP_PRIO_NORMAL,P_RTPRIO_TYPE(%eax) /* normal priority process? */ je rem_nort - movl P_RTPRIO(%eax),%edx + movzwl P_RTPRIO_PRIO(%eax),%edx + + cmpw $RTP_PRIO_REALTIME,P_RTPRIO_TYPE(%eax) /* normal priority process? */ + jne rem_id + btrl %edx,_whichrtqs /* clear full bit, panic if clear already */ jb rem1rt - pushl $rem3 + pushl $rem3rt call _panic rem1rt: pushl %edx @@ -146,6 +168,31 @@ rem1rt: rem2rt: movl $0,P_BACK(%eax) /* zap reverse link to indicate off list */ ret +rem_id: + btrl %edx,_whichidqs /* clear full bit, panic if clear already */ + jb rem1id + pushl $rem3id + call _panic +rem1id: + pushl %edx + movl P_FORW(%eax),%ecx /* unlink process */ + movl P_BACK(%eax),%edx + movl %edx,P_BACK(%ecx) + movl P_BACK(%eax),%ecx + movl P_FORW(%eax),%edx + movl %edx,P_FORW(%ecx) + popl %edx + movl $_idqs,%ecx + shll $3,%edx + addl %edx,%ecx + cmpl P_FORW(%ecx),%ecx /* q still has something? */ + je rem2id + shrl $3,%edx /* yes, set bit as still full */ + btsl %edx,_whichidqs +rem2id: + movl $0,P_BACK(%eax) /* zap reverse link to indicate off list */ + ret + rem_nort: movzbl P_PRI(%eax),%edx shrl $2,%edx @@ -174,6 +221,8 @@ rem2: ret rem3: .asciz "remrq" +rem3rt: .asciz "remrq.rt" +rem3id: .asciz "remrq.id" sw0: .asciz "cpu_switch" /* @@ -200,10 +249,12 @@ _idle: ALIGN_TEXT idle_loop: cli - cmpl $0,_whichrtqs + cmpl $0,_whichrtqs /* real-time queue */ jne sw1a - cmpl $0,_whichqs + cmpl $0,_whichqs /* normal queue */ jne nortqr + cmpl $0,_whichidqs /* 'idle' queue */ + jne idqr #ifdef APM call _apm_cpu_idle call _apm_cpu_busy @@ -269,7 +320,6 @@ sw1a: testl %edi,%edi jz nortqr /* no realtime procs */ -rt2: /* XXX - bsf is sloow */ bsfl %edi,%ebx /* find a full q */ jz nortqr /* no proc on rt q - try normal ... */ @@ -298,12 +348,13 @@ rt3: jmp swtch_com /* old sw1a */ +/* Normal process priority's */ nortqr: movl _whichqs,%edi 2: /* XXX - bsf is sloow */ bsfl %edi,%ebx /* find a full q */ - jz _idle /* if none, idle */ + jz idqr /* if none, idle */ /* XX update whichqs? */ btrl %ebx,%edi /* clear q full status */ @@ -326,6 +377,36 @@ nortqr: btsl %ebx,%edi /* nope, set to indicate not empty */ 3: movl %edi,_whichqs /* update q status */ + jmp swtch_com + +idqr: /* was sw1a */ + movl _whichidqs,%edi /* pick next p. from idqs */ + + /* XXX - bsf is sloow */ + bsfl %edi,%ebx /* find a full q */ + jz _idle /* no proc, idle */ + + /* XX update whichqs? */ + btrl %ebx,%edi /* clear q full status */ + leal _idqs(,%ebx,8),%eax /* select q */ + movl %eax,%esi + +#ifdef DIAGNOSTIC + cmpl P_FORW(%eax),%eax /* linked to self? (e.g. not on list) */ + je badsw /* not possible */ +#endif + + movl P_FORW(%eax),%ecx /* unlink from front of process q */ + movl P_FORW(%ecx),%edx + movl %edx,P_FORW(%eax) + movl P_BACK(%ecx),%eax + movl %eax,P_BACK(%edx) + + cmpl P_FORW(%ecx),%esi /* q empty */ + je id3 + btsl %ebx,%edi /* nope, set to indicate not empty */ +id3: + movl %edi,_whichidqs /* update q status */ swtch_com: movl $0,%eax diff --git a/sys/i386/i386/genassym.c b/sys/i386/i386/genassym.c index c5685444d97..1ea7ba1e171 100644 --- a/sys/i386/i386/genassym.c +++ b/sys/i386/i386/genassym.c @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)genassym.c 5.11 (Berkeley) 5/10/91 - * $Id: genassym.c,v 1.11 1994/09/12 11:38:03 davidg Exp $ + * $Id: genassym.c,v 1.12 1994/10/02 01:28:38 rgrimes Exp $ */ #include @@ -78,7 +78,8 @@ main() printf("#define\tVM_PMAP %d\n", &vms->vm_pmap); printf("#define\tP_ADDR %d\n", &p->p_addr); printf("#define\tP_PRI %d\n", &p->p_priority); - printf("#define\tP_RTPRIO %d\n", &p->p_rtprio); + printf("#define\tP_RTPRIO_TYPE %d\n", &p->p_rtprio.type); + printf("#define\tP_RTPRIO_PRIO %d\n", &p->p_rtprio.prio); printf("#define\tP_STAT %d\n", &p->p_stat); printf("#define\tP_WCHAN %d\n", &p->p_wchan); printf("#define\tP_FLAG %d\n", &p->p_flag); diff --git a/sys/i386/i386/swtch.s b/sys/i386/i386/swtch.s index ad83a9a2e0c..ab405002e70 100644 --- a/sys/i386/i386/swtch.s +++ b/sys/i386/i386/swtch.s @@ -33,7 +33,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: swtch.s,v 1.13 1994/09/02 05:58:51 davidg Exp $ + * $Id: swtch.s,v 1.14 1994/10/01 02:56:03 davidg Exp $ */ #include "npx.h" /* for NNPX */ @@ -59,10 +59,11 @@ * queues. */ .data - .globl _curpcb, _whichqs, _whichrtqs + .globl _curpcb, _whichqs, _whichrtqs, _whichidqs _curpcb: .long 0 /* pointer to curproc's PCB area */ _whichqs: .long 0 /* which run queues have data */ _whichrtqs: .long 0 /* which realtime run queues have data */ +_whichidqs: .long 0 /* which idletime run queues have data */ .globl _qs,_cnt,_panic .comm _noproc,4 @@ -84,10 +85,15 @@ ENTRY(setrunqueue) pushl $set2 call _panic set1: - cmpl $RTPRIO_RTOFF,P_RTPRIO(%eax) /* Realtime process ? */ - je set1_nort + cmpw $RTP_PRIO_NORMAL,P_RTPRIO_TYPE(%eax) /* normal priority process? */ + je set_nort - movl P_RTPRIO(%eax),%edx + movzwl P_RTPRIO_PRIO(%eax),%edx + + cmpw $RTP_PRIO_REALTIME,P_RTPRIO_TYPE(%eax) /* realtime priority? */ + jne set_id /* must be idle priority */ + +set_rt: btsl %edx,_whichrtqs /* set q full bit */ shll $3,%edx addl $_rtqs,%edx /* locate q hdr */ @@ -97,7 +103,19 @@ set1: movl %eax,P_BACK(%edx) movl %eax,P_FORW(%ecx) ret -set1_nort: + +set_id: + btsl %edx,_whichidqs /* set q full bit */ + shll $3,%edx + addl $_idqs,%edx /* locate q hdr */ + movl %edx,P_FORW(%eax) /* link process on tail of q */ + movl P_BACK(%edx),%ecx + movl %ecx,P_BACK(%eax) + movl %eax,P_BACK(%edx) + movl %eax,P_FORW(%ecx) + ret + +set_nort: /* Normal (RTOFF) code */ movzbl P_PRI(%eax),%edx shrl $2,%edx btsl %edx,_whichqs /* set q full bit */ @@ -119,13 +137,17 @@ set2: .asciz "setrunqueue" */ ENTRY(remrq) movl 4(%esp),%eax - cmpl $RTPRIO_RTOFF,P_RTPRIO(%eax) /* Realtime process ? */ + cmpw $RTP_PRIO_NORMAL,P_RTPRIO_TYPE(%eax) /* normal priority process? */ je rem_nort - movl P_RTPRIO(%eax),%edx + movzwl P_RTPRIO_PRIO(%eax),%edx + + cmpw $RTP_PRIO_REALTIME,P_RTPRIO_TYPE(%eax) /* normal priority process? */ + jne rem_id + btrl %edx,_whichrtqs /* clear full bit, panic if clear already */ jb rem1rt - pushl $rem3 + pushl $rem3rt call _panic rem1rt: pushl %edx @@ -146,6 +168,31 @@ rem1rt: rem2rt: movl $0,P_BACK(%eax) /* zap reverse link to indicate off list */ ret +rem_id: + btrl %edx,_whichidqs /* clear full bit, panic if clear already */ + jb rem1id + pushl $rem3id + call _panic +rem1id: + pushl %edx + movl P_FORW(%eax),%ecx /* unlink process */ + movl P_BACK(%eax),%edx + movl %edx,P_BACK(%ecx) + movl P_BACK(%eax),%ecx + movl P_FORW(%eax),%edx + movl %edx,P_FORW(%ecx) + popl %edx + movl $_idqs,%ecx + shll $3,%edx + addl %edx,%ecx + cmpl P_FORW(%ecx),%ecx /* q still has something? */ + je rem2id + shrl $3,%edx /* yes, set bit as still full */ + btsl %edx,_whichidqs +rem2id: + movl $0,P_BACK(%eax) /* zap reverse link to indicate off list */ + ret + rem_nort: movzbl P_PRI(%eax),%edx shrl $2,%edx @@ -174,6 +221,8 @@ rem2: ret rem3: .asciz "remrq" +rem3rt: .asciz "remrq.rt" +rem3id: .asciz "remrq.id" sw0: .asciz "cpu_switch" /* @@ -200,10 +249,12 @@ _idle: ALIGN_TEXT idle_loop: cli - cmpl $0,_whichrtqs + cmpl $0,_whichrtqs /* real-time queue */ jne sw1a - cmpl $0,_whichqs + cmpl $0,_whichqs /* normal queue */ jne nortqr + cmpl $0,_whichidqs /* 'idle' queue */ + jne idqr #ifdef APM call _apm_cpu_idle call _apm_cpu_busy @@ -269,7 +320,6 @@ sw1a: testl %edi,%edi jz nortqr /* no realtime procs */ -rt2: /* XXX - bsf is sloow */ bsfl %edi,%ebx /* find a full q */ jz nortqr /* no proc on rt q - try normal ... */ @@ -298,12 +348,13 @@ rt3: jmp swtch_com /* old sw1a */ +/* Normal process priority's */ nortqr: movl _whichqs,%edi 2: /* XXX - bsf is sloow */ bsfl %edi,%ebx /* find a full q */ - jz _idle /* if none, idle */ + jz idqr /* if none, idle */ /* XX update whichqs? */ btrl %ebx,%edi /* clear q full status */ @@ -326,6 +377,36 @@ nortqr: btsl %ebx,%edi /* nope, set to indicate not empty */ 3: movl %edi,_whichqs /* update q status */ + jmp swtch_com + +idqr: /* was sw1a */ + movl _whichidqs,%edi /* pick next p. from idqs */ + + /* XXX - bsf is sloow */ + bsfl %edi,%ebx /* find a full q */ + jz _idle /* no proc, idle */ + + /* XX update whichqs? */ + btrl %ebx,%edi /* clear q full status */ + leal _idqs(,%ebx,8),%eax /* select q */ + movl %eax,%esi + +#ifdef DIAGNOSTIC + cmpl P_FORW(%eax),%eax /* linked to self? (e.g. not on list) */ + je badsw /* not possible */ +#endif + + movl P_FORW(%eax),%ecx /* unlink from front of process q */ + movl P_FORW(%ecx),%edx + movl %edx,P_FORW(%eax) + movl P_BACK(%ecx),%eax + movl %eax,P_BACK(%edx) + + cmpl P_FORW(%ecx),%esi /* q empty */ + je id3 + btsl %ebx,%edi /* nope, set to indicate not empty */ +id3: + movl %edi,_whichidqs /* update q status */ swtch_com: movl $0,%eax diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c index 41693b21ed1..44129c1d0f8 100644 --- a/sys/kern/init_main.c +++ b/sys/kern/init_main.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)init_main.c 8.9 (Berkeley) 1/21/94 - * $Id: init_main.c,v 1.10 1994/09/13 14:46:47 dfr Exp $ + * $Id: init_main.c,v 1.11 1994/09/25 19:33:33 phk Exp $ */ #include @@ -165,7 +165,8 @@ main(framep) p->p_flag = P_INMEM | P_SYSTEM; p->p_stat = SRUN; p->p_nice = NZERO; - p->p_rtprio = RTPRIO_RTOFF; + p->p_rtprio.type = RTP_PRIO_NORMAL; + p->p_rtprio.prio = 0; bcopy("swapper", p->p_comm, sizeof ("swapper")); diff --git a/sys/kern/init_sysent.c b/sys/kern/init_sysent.c index 8ac5eaef03a..15a3fb9f3c7 100644 --- a/sys/kern/init_sysent.c +++ b/sys/kern/init_sysent.c @@ -2,7 +2,7 @@ * System call switch table. * * DO NOT EDIT-- this file is automatically generated. - * created from $Id: syscalls.master,v 1.9 1994/09/18 20:39:50 wollman Exp $ + * created from $Id: syscalls.master,v 1.10 1994/09/28 22:44:47 wollman Exp $ */ #include @@ -446,7 +446,7 @@ struct sysent sysent[] = { { 2, setdomainname }, /* 163 = setdomainname */ { 1, uname }, /* 164 = uname */ { 2, sysarch }, /* 165 = sysarch */ - { 2, rtprio }, /* 166 = rtprio */ + { 3, rtprio }, /* 166 = rtprio */ { 0, nosys }, /* 167 = nosys */ { 0, nosys }, /* 168 = nosys */ #ifdef SYSVSEM diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index 61e2f50d7a0..94c9e223d47 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_fork.c 8.6 (Berkeley) 4/8/94 - * $Id: kern_fork.c,v 1.5 1994/08/18 22:35:00 wollman Exp $ + * $Id: kern_fork.c,v 1.6 1994/09/01 05:12:38 davidg Exp $ */ #include @@ -268,11 +268,6 @@ again: */ p2->p_estcpu = p1->p_estcpu; - /* - * copy the realtime attibute - */ - p2->p_rtprio = p1->p_rtprio; - /* * This begins the section where we must prevent the parent * from being swapped. diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index 989cf1cb410..f9c3d7b9a74 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -31,7 +31,7 @@ * SUCH DAMAGE. * * @(#)kern_proc.c 8.4 (Berkeley) 1/4/94 - * $Id: kern_proc.c,v 1.5 1994/09/01 05:12:39 davidg Exp $ + * $Id: kern_proc.c,v 1.6 1994/09/25 19:33:41 phk Exp $ */ #include @@ -53,6 +53,7 @@ struct prochd qs[NQS]; /* as good a place as any... */ struct prochd rtqs[NQS]; /* Space for REALTIME queues too */ +struct prochd idqs[NQS]; /* Space for IDLE queues too */ volatile struct proc *allproc; /* all processes */ struct proc *zombproc; /* just zombies */ diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index 704c5019cb6..6d2c27429ff 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_resource.c 8.5 (Berkeley) 1/21/94 - * $Id: kern_resource.c,v 1.4 1994/09/01 05:12:40 davidg Exp $ + * $Id: kern_resource.c,v 1.5 1994/09/25 19:33:42 phk Exp $ */ #include @@ -195,8 +195,9 @@ donice(curp, chgp, n) /* rtprio system call */ struct rtprio_args { - int who; - pid_t rtprio; + int function; + pid_t pid; + struct rtprio *rtprio; }; /* @@ -211,45 +212,55 @@ rtprio(curp, uap, retval) int *retval; { register struct proc *p; - register int n = uap->rtprio; register struct pcred *pcred = curp->p_cred; + struct rtprio rtp; + int error; - if (uap->who == 0) + error = copyin(uap->rtprio, &rtp, sizeof(struct rtprio)); + if (error) + return (error); + + if (uap->pid == 0) p = curp; else - p = pfind(uap->who); + p = pfind(uap->pid); if (p == 0) return (ESRCH); - if (n == RTPRIO_NOCHG) { - *retval = (int)p->p_rtprio; - return(0); } - - if (pcred->pc_ucred->cr_uid && pcred->p_ruid && - pcred->pc_ucred->cr_uid != p->p_ucred->cr_uid && - pcred->p_ruid != p->p_ucred->cr_uid) - return (EPERM); - - if (n == RTPRIO_RTOFF) { - if(suser(pcred->pc_ucred, &curp->p_acflag)&& !uap->who) - return (EPERM); - p->p_rtprio = RTPRIO_RTOFF; - *retval = RTPRIO_RTOFF; - return (0); } - - if (n > RTPRIO_MAX) - return (EINVAL); - if (n < RTPRIO_MIN) - return (EINVAL); - if (suser(pcred->pc_ucred, &curp->p_acflag)) - return (EPERM); - - p->p_rtprio = n; - - *retval = (int)p->p_rtprio; - return (0); -}; + switch (uap->function) { + case RTP_LOOKUP: + return (copyout(&p->p_rtprio, uap->rtprio, sizeof(struct rtprio))); + case RTP_SET: + if (pcred->pc_ucred->cr_uid && pcred->p_ruid && + pcred->pc_ucred->cr_uid != p->p_ucred->cr_uid && + pcred->p_ruid != p->p_ucred->cr_uid) + return (EPERM); + /* disallow setting rtprio in most cases if not superuser */ + if (suser(pcred->pc_ucred, &curp->p_acflag)) { + /* can't set someone else's */ + if (uap->pid) + return (EPERM); + /* can't set realtime priority */ + if (rtp.type == RTP_PRIO_REALTIME) + return (EPERM); + } + switch (rtp.type) { + case RTP_PRIO_REALTIME: + case RTP_PRIO_NORMAL: + case RTP_PRIO_IDLE: + if (rtp.prio > RTP_PRIO_MAX) + return (EINVAL); + p->p_rtprio = rtp; + return (0); + default: + return (EINVAL); + } + + default: + return (EINVAL); + } +} #if defined(COMPAT_43) || defined(COMPAT_SUNOS) struct setrlimit_args { diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index c74469f11a4..a7d3774f4dc 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)kern_synch.c 8.6 (Berkeley) 1/21/94 - * $Id: kern_synch.c,v 1.4 1994/09/01 05:12:41 davidg Exp $ + * $Id: kern_synch.c,v 1.5 1994/09/25 19:33:44 phk Exp $ */ #include @@ -609,6 +609,7 @@ rqinit() for (i = 0; i < NQS; i++) { qs[i].ph_link = qs[i].ph_rlink = (struct proc *)&qs[i]; rtqs[i].ph_link = rtqs[i].ph_rlink = (struct proc *)&rtqs[i]; + idqs[i].ph_link = idqs[i].ph_rlink = (struct proc *)&idqs[i]; } } @@ -662,7 +663,7 @@ resetpriority(p) { register unsigned int newpriority; - if (p->p_rtprio == RTPRIO_RTOFF) { + if (p->p_rtprio.type == RTP_PRIO_NORMAL) { newpriority = PUSER + p->p_estcpu / 4 + 2 * p->p_nice; newpriority = min(newpriority, MAXPRI); p->p_usrpri = newpriority; diff --git a/sys/kern/syscalls.c b/sys/kern/syscalls.c index 56eecbc3d49..eb9491c69dd 100644 --- a/sys/kern/syscalls.c +++ b/sys/kern/syscalls.c @@ -2,7 +2,7 @@ * System call names. * * DO NOT EDIT-- this file is automatically generated. - * created from $Id: syscalls.master,v 1.9 1994/09/18 20:39:50 wollman Exp $ + * created from $Id: syscalls.master,v 1.10 1994/09/28 22:44:47 wollman Exp $ */ char *syscallnames[] = { diff --git a/sys/kern/syscalls.master b/sys/kern/syscalls.master index d9a471e6de6..0e7c986a309 100644 --- a/sys/kern/syscalls.master +++ b/sys/kern/syscalls.master @@ -1,4 +1,4 @@ - $Id: syscalls.master,v 1.9 1994/09/18 20:39:50 wollman Exp $ + $Id: syscalls.master,v 1.10 1994/09/28 22:44:47 wollman Exp $ ; from: @(#)syscalls.master 8.2 (Berkeley) 1/13/94 ; ; System call name/number master file. @@ -219,7 +219,7 @@ 163 STD 2 BSD setdomainname 164 STD 1 BSD uname 165 STD 2 BSD sysarch -166 STD 2 BSD rtprio +166 STD 3 BSD rtprio 167 UNIMPL 0 NOHIDE nosys 168 UNIMPL 0 NOHIDE nosys #ifdef SYSVSEM diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 6155408a15b..541ef958165 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)proc.h 8.8 (Berkeley) 1/21/94 - * $Id: proc.h,v 1.7 1994/08/28 16:53:35 bde Exp $ + * $Id: proc.h,v 1.8 1994/09/01 05:12:52 davidg Exp $ */ #ifndef _SYS_PROC_H_ @@ -156,6 +156,7 @@ struct proc { struct sysentvec *p_sysent; /* System call dispatch information. */ + struct rtprio p_rtprio; /* realtime priority */ /* End area that is copied on creation. */ #define p_endcopy p_thread int p_thread; /* Id for this "thread"; Mach glue. XXX */ @@ -165,7 +166,6 @@ struct proc { u_short p_xstat; /* Exit status for wait; also stop signal. */ u_short p_acflag; /* Accounting flags. */ struct rusage *p_ru; /* Exit information. XXX */ - u_long p_rtprio; /* realtime priority */ }; #define p_session p_pgrp->pg_session @@ -248,6 +248,7 @@ extern struct proc *initproc, *pageproc; /* Process slots for init, pager. */ #define NQS 32 /* 32 run queues. */ extern struct prochd qs[]; extern struct prochd rtqs[]; +extern struct prochd idqs[]; extern int whichqs; /* Bit mask summary of non-empty Q's. */ struct prochd { struct proc *ph_link; /* Linked list of running processes. */ diff --git a/sys/sys/rtprio.h b/sys/sys/rtprio.h index 7638f9bb445..9a22a34806b 100644 --- a/sys/sys/rtprio.h +++ b/sys/sys/rtprio.h @@ -28,7 +28,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id$ + * $Id: rtprio.h,v 1.1 1994/09/01 05:12:53 davidg Exp $ */ #ifndef _SYS_RTPRIO_H_ @@ -37,16 +37,34 @@ /* * Process realtime-priority specifications to rtprio. */ -#define RTPRIO_MIN 0 /* relativ-FASTEST */ -#define RTPRIO_MAX 31 /* relativ-SLOWEST */ -#define RTPRIO_NOCHG 100 /* look only */ -#define RTPRIO_RTOFF 101 /* NON-realtime */ + +/* priority types */ +#define RTP_PRIO_REALTIME 0 +#define RTP_PRIO_NORMAL 1 +#define RTP_PRIO_IDLE 2 + +/* priority range */ +#define RTP_PRIO_MIN 0 /* Highest priority */ +#define RTP_PRIO_MAX 31 /* Lowest priority */ + +/* + * rtprio() syscall functions + */ +#define RTP_LOOKUP 0 +#define RTP_SET 1 + +#ifndef LOCORE +struct rtprio { + u_short type; + u_short prio; +}; +#endif #ifndef KERNEL #include __BEGIN_DECLS -int rtprio __P((int, int)); +int rtprio __P((int, pid_t, struct rtprio *)); __END_DECLS #endif /* !KERNEL */ #endif /* !_SYS_RTPRIO_H_ */ diff --git a/sys/sys/syscall-hide.h b/sys/sys/syscall-hide.h index e09c8934200..b326435f645 100644 --- a/sys/sys/syscall-hide.h +++ b/sys/sys/syscall-hide.h @@ -2,7 +2,7 @@ * System call hiders. * * DO NOT EDIT-- this file is automatically generated. - * created from $Id: syscalls.master,v 1.9 1994/09/18 20:39:50 wollman Exp $ + * created from $Id: syscalls.master,v 1.10 1994/09/28 22:44:47 wollman Exp $ */ HIDE_POSIX(fork) diff --git a/sys/sys/syscall.h b/sys/sys/syscall.h index 5d53601f562..c57bb7e2368 100644 --- a/sys/sys/syscall.h +++ b/sys/sys/syscall.h @@ -2,7 +2,7 @@ * System call numbers. * * DO NOT EDIT-- this file is automatically generated. - * created from $Id: syscalls.master,v 1.9 1994/09/18 20:39:50 wollman Exp $ + * created from $Id: syscalls.master,v 1.10 1994/09/28 22:44:47 wollman Exp $ */ #define SYS_syscall 0 diff --git a/usr.sbin/rtprio/Makefile b/usr.sbin/rtprio/Makefile index 2ca8da900be..af159bfe873 100644 --- a/usr.sbin/rtprio/Makefile +++ b/usr.sbin/rtprio/Makefile @@ -1,7 +1,11 @@ # from: @(#)Makefile 5.5 (Berkeley) 5/11/90 -# $Id: Makefile,v 1.2 1993/11/23 00:02:21 jtc Exp $ +# $Id: Makefile,v 1.1 1994/09/01 12:05:12 davidg Exp $ BINDIR=/usr/sbin PROG= rtprio +LINKS= ${BINDIR}/rtprio ${BINDIR}/idprio +MLINKS= rtprio.1 idprio.1 +MAN1= rtprio.1 +MAN2= rtprio.2 .include diff --git a/usr.sbin/rtprio/rtprio.1 b/usr.sbin/rtprio/rtprio.1 index a2cc7dcc369..5542f12e3c7 100644 --- a/usr.sbin/rtprio/rtprio.1 +++ b/usr.sbin/rtprio/rtprio.1 @@ -34,35 +34,50 @@ .Dt RTPRIO 1 .Os .Sh NAME -.Nm rtprio -.Nd execute, examine or modify a process's realtime scheduling priority +.Nm rtprio , +.Nm idprio +.Nd execute, examine or modify a utilitys or process realtime +or idletime scheduling priority .Sh SYNOPSIS -.Nm rtprio -.Nm rtprio +.Nm [id|rt]prio +.Nm [id|rt]prio .Ar pid -.Nm rtprio +.Nm [id|rt]prio .Ar priority .Ar command .Op args -.Nm rtprio +.Nm [id|rt]prio .Ar priority .Ar -pid -.Nm rtprio +.Nm [id|rt]prio .Ar -t .Ar command .Op args -.Nm rtprio +.Nm [id|rt]prio .Ar -t .Ar -pid .Sh DESCRIPTION .Nm Rtprio -is used for controlling realtime process scheduling. A process with a -realtime priority is not subject to priority degradation, and will only -be preempted by another process of equal or higher realtime priority. +is used for controlling realtime process scheduling. -.Nm Rtprio -called without arguments, will return the realtime priority +.Nm Idprio +is used for controlling idletime process scheduling, and can be called +with the same options as +.Nm Rtprio . + +A process with a realtime priority is not subject to priority +degradation, and will only be preempted by another process of equal or +higher realtime priority. + +A process with an idle priority will run only when no other +process is runnable and then only if it's idle priority is equal or +greater than all other runnable idle priority processes. + +.Nm Rtprio +or +.Nm Idprio +when called without arguments will return the realtime priority of the current process. If @@ -81,23 +96,27 @@ process. If .Ar -pid -is specified, the process with that pid will be modified, else -if +is specified, the process with the process identifier "pid" will be +modified, else if .Ar command is specified, that program is run with its arguments. .Ar Priority -is an integer between 0 (RTPRIO_MIN) and 31 (RTPRIO_MAX). 0 is the +is an integer between 0 and RTP_PRIO_MAX (usually 31). 0 is the highest priority .Ar Pid of 0 means "the current process". -Only root is allowed to set realtime priorities. +Only root is allowed to set realtime priorities. Non-root processes may +set idle priority levels for the current process only. .Sh RETURN VALUE +If .Nm rtprio -returns the (new) realtime priority of the process (see rtprio(2)), or --1 for all usage errors. +execute a command, the exit value is that of the command executed. +In all other cases, +.Nm +exits with 0 for success and 1 for all other errors. .Sh EXAMPLES .\LP @@ -131,16 +150,17 @@ To run \fItcpdump\fP without realtime priority: .Ed .\.LP -To change the realtime priority of process \fI1423\fP to RTRIO_RTOFF -(no realtime): +To change the realtime priority of process \fI1423\fP to RTP_PRIO_NORMAL +(non-realtime/"normal" priority): .Bd -literal -offset indent -compact \fBrtprio -t -1423\fP .Ed -.Sh DIAGNOSTICS -The -.Nm rtprio -utility shall exit with value of the (new) realtime priority of the -program. + +.\.LP +To make depend while not disturbing other machine usage: +.Bd -literal -offset indent -compact +\fBidprio 31 make depend\fP +.Ed .Sh SEE ALSO .Xr rtprio 2 , .Xr nice 1 , @@ -153,13 +173,25 @@ The utility appeared in FreeBSD 2.0, but is similar to the HP-UX version. +.Sh CAVEATS +You can lock yourself out of the system by placing a cpu-heavy +process in a realtime priority. .Sh BUGS -You can lock yourself out of the system by placing a cpu-intensive -process into realtime priority. - There is no way to set/view the realtime priority of process 0 (swapper) (see ps(1)). +There is in +FreeBSD +no way to ensure that a process page is present in memory therefore +the process may be stopped for pagein. (See mprotect(2), madvise(2)). + +Under +FreeBSD +system calls are currently never preempted, therefore non-realtime +processes can starve realtime procesess, or idletime processes can +starve normal priority processes. + Others ... .Sh AUTHOR -Henrik Vestergaard Draboel - hvd@terry.ping.dk +Henrik Vestergaard Draboel - hvd@terry.ping.dk is the original author. This +implementation in FreeBSD was substantially rewritten by David Greenman. diff --git a/usr.sbin/rtprio/rtprio.2 b/usr.sbin/rtprio/rtprio.2 new file mode 100644 index 00000000000..2c1b4c7f84e --- /dev/null +++ b/usr.sbin/rtprio/rtprio.2 @@ -0,0 +1,106 @@ +.\" Copyright (c) 1994, Henrik Vestergaard Draboel +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Henrik Vestergaard Draboel. +.\" 4. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $Id: rtprio.2,v 1.2 1994/09/01 12:09:17 davidg Exp $ +.\" +.Dd July 23, 1994 +.Dt RTPRIO 2 +.Sh NAME +.Nm rtprio +.Nd examine or modify a process realtime or idle priority +.Sh SYNOPSIS +.Fd #include +.Fd #include +.Ft int +.Fn rtprio "function" "pid_t pid" "struct rtprio *rtp" +.Sh DESCRIPTION +.Fn rtprio +is used to lookup or change the realtime or idle priority of a process. + +.Fa function +specifies the operation to be performed. RTP_LOOKUP to lookup the current priority, +and RTP_SET to set the priority. +.Fa pid +specifies the process to be used, 0 for the current process. + +.Fa *rtp +is a pointer to a struct rtprio which is used to specify the priority and priority type. +This structure has the following form: +.Bd -literal +struct rtprio { + u_short type; + u_short prio; +}; +.Ed +.Pp +The value of the +.Nm type +field may be RTP_PRIO_REALTIME for realtime priorities, +RTP_PRIO_NORMAL for normal priorities, and RTP_PRIO_IDLE for idle priorities. +The priority specified by the +.Nm prio +field ranges between 0 and +.Dv RTP_PRIO_MAX (usually 31) . +0 is the highest possible priority. + +Realtime and idle priority is inherited through fork() and exec(). + +A realtime process can only be preempted by a process of equal or +higher priority, or by an interrupt; idle priority processes will run only +when no other real/normal priority process is runnable. Higher real/idle priority processes +preempt lower real/idle priority processes. Processes of equal real/idle priority are run round-robin. +.Sh RETURN VALUES +.Fn rtprio +will return 0 for success and -1 for all errors. The global variable +.Va errno +will be set to indicate the error. +.Sh ERRORS +.Fn rtprio +will fail if +.Bl -tag -width Er +.It Bq Er EINVAL +The specified +.Fa prio +was out of range. +.It Bq Er EPERM +The calling process is not allowed to set the realtime priority. Only +root is allowed to change the realtime priority of any process, and non-root +may only change the idle priority of the current process. +.It Bq Er ESRCH +The specified process was not found. +.Sh AUTHOR +The original author was Henrik Vestergaard Draboel - hvd@terry.ping.dk. This +implementation in FreeBSD was substantially rewritten by David Greenman. +.Sh SEE ALSO +.Xr rtprio 1 , +.Xr nice 1 , +.Xr ps 1 , +.Xr nice 2 , +.Xr renice 8 + diff --git a/usr.sbin/rtprio/rtprio.c b/usr.sbin/rtprio/rtprio.c index cc66fd4c087..ab4d08513fb 100644 --- a/usr.sbin/rtprio/rtprio.c +++ b/usr.sbin/rtprio/rtprio.c @@ -1,5 +1,6 @@ /* - * Copyright (c) 1994 The Regents of the University of California. + * Copyright (c) 1994 David Greenman + * Copyright (c) 1994 Henrik Vestergaard Draboel (hvd@terry.ping.dk) * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -12,16 +13,16 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * This product includes software developed by Henrik Vestergaard Draboel. + * This product includes software developed by David Greenman. + * 4. Neither the names of the authors nor the names of contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) @@ -29,28 +30,15 @@ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. + * + * $Id$ */ -/* Copyright (c) 1994 Henrik Vestergaard Drabøl (hvd@terry.pping.dk) */ - -#ifndef lint -char copyright[] = -"@(#) Copyright (c) 1989 The Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)rtprio.c 5.4 (Berkeley) 6/1/90";*/ -static char rcsid[] = "$Id: rtprio.c,v 1.2 1993/11/23 00:02:23 jtc Exp $"; -#endif /* not lint */ - -#include -#include +#include #include -#include -#include -#include +#include +#include #include #include #include @@ -60,82 +48,95 @@ static void usage(); int main(argc, argv) - int argc; - char **argv; + int argc; + char **argv; { - int nrtprio = RTPRIO_RTOFF; - int proc=0; + char *p; + int proc = 0; + struct rtprio rtp; - setlocale(LC_ALL, ""); - errno = 0; + /* find basename */ + if ((p = rindex(argv[0], '/')) == NULL) + p = argv[0]; + else + ++p; + + if (!strcmp(p, "rtprio")) + rtp.type = RTP_PRIO_REALTIME; + else if (!strcmp(p, "idprio")) + rtp.type = RTP_PRIO_IDLE; switch (argc) { - case 2: - proc = abs(atoi(argv[1])); + case 2: + proc = abs(atoi(argv[1])); /* Should check if numeric + * arg! */ /* FALLTHROUGH */ - case 1: - nrtprio = rtprio(proc,RTPRIO_NOCHG); - fprintf(stderr,"rtprio: %d %s\n", - nrtprio, - nrtprio==RTPRIO_RTOFF?"(RTOFF)":""); - exit(nrtprio); - /* NOTREACHED */ - - default: { - switch (argv[1][0]) { - case '-': - if (strcmp(argv[1],"-t")==0) - nrtprio = RTPRIO_RTOFF; - else - usage(); - break; - - case '0':case '1':case '2':case '3':case '4': - case '5':case '6':case '7':case '8':case '9': - nrtprio = atoi (argv[1]); - - if (errno== ERANGE) usage(); - break; - + if (rtprio(RTP_LOOKUP, proc, &rtp) != 0) { + perror(argv[0]); + exit (1); + } + printf("%s: ", p); + switch (rtp.type) { + case RTP_PRIO_REALTIME: + printf("realtime priority %d\n", rtp.prio); + break; + case RTP_PRIO_NORMAL: + printf("normal priority\n"); + break; + case RTP_PRIO_IDLE: + printf("idle priority %d\n", rtp.prio); + break; default: - usage(); - break; + printf("invalid priority type %d\n", rtp.type); + break; } - switch (argv[2][0]) { - case '-': - proc = -atoi(argv[2]); - - break; + exit(0); + default: + if (argv[1][0] == '-' || isdigit(argv[1][0])) { + if (argv[1][0] == '-') { + if (strcmp(argv[1], "-t") == 0) { + rtp.type = RTP_PRIO_NORMAL; + rtp.prio = 0; + } else { + usage(p); + break; + } + } else { + rtp.prio = atoi(argv[1]); + } + } else { + usage(p); + break; } - - errno = 0; - nrtprio = rtprio(proc, nrtprio); + if (argv[2][0] == '-') + proc = -atoi(argv[2]); - if (errno) { - err (1, "rtprio"); - /* NOTREACHED */ + if (rtprio(RTP_SET, proc, &rtp) != 0) { + perror(argv[0]); + exit (1); + } + + if (proc == 0) { + execvp(argv[2], &argv[2]); + perror(argv[0]); + exit (1); + } } - - if (proc == 0) { - execvp(argv[2], &argv[2]); - err ((errno == ENOENT) ? 127 : 126, "%s", argv[2]);} - /* NOTREACHED */ - } - } -return(nrtprio); + exit (1); } static void -usage() +usage(basename) + char *basename; { - (void)fprintf(stderr, "usage: rtprio\n"); - (void)fprintf(stderr, "usage: rtprio [-] pid\n"); - (void)fprintf(stderr, "usage: rtprio priority command [ args ] \n"); - (void)fprintf(stderr, "usage: rtprio priority -pid \n"); - (void)fprintf(stderr, "usage: rtprio -t command [ args ] \n"); - (void)fprintf(stderr, "usage: rtprio -t -pid \n"); - + (void) fprintf(stderr, "usage: %s\n", basename); + (void) fprintf(stderr, "usage: %s [-]pid\n", basename); + (void) fprintf(stderr, "usage: %s priority command [ args ] \n", basename); + (void) fprintf(stderr, "usage: %s priority -pid \n", basename); + (void) fprintf(stderr, "usage: %s -t command [ args ] \n", basename); + (void) fprintf(stderr, "usage: %s -t -pid \n", basename); + exit(-1); }