slight tuning of /etc/mk situation when making release.
[minix.git] / kernel / system / do_nice.c
blob3fb29736aac36366bc4ba0fb668449d30839292c
1 /* The kernel call implemented in this file:
2 * m_type: SYS_NICE
4 * The parameters for this kernel call are:
5 * m1_i1: PR_ENDPT process number to change priority
6 * m1_i2: PR_PRIORITY the new priority
7 */
9 #include "../system.h"
10 #include <sys/resource.h>
12 #if USE_NICE
14 /*===========================================================================*
15 * do_nice *
16 *===========================================================================*/
17 PUBLIC int do_nice(struct proc * caller, message * m_ptr)
19 /* Change process priority or stop the process. */
20 int proc_nr, pri, new_q ;
21 register struct proc *rp;
23 /* Extract the message parameters and do sanity checking. */
24 if(!isokendpt(m_ptr->PR_ENDPT, &proc_nr)) return EINVAL;
25 if (iskerneln(proc_nr)) return(EPERM);
26 pri = m_ptr->PR_PRIORITY;
27 rp = proc_addr(proc_nr);
29 /* The value passed in is currently between PRIO_MIN and PRIO_MAX.
30 * We have to scale this between MIN_USER_Q and MAX_USER_Q to match
31 * the kernel's scheduling queues.
33 if (pri < PRIO_MIN || pri > PRIO_MAX) return(EINVAL);
35 new_q = MAX_USER_Q + (pri-PRIO_MIN) * (MIN_USER_Q-MAX_USER_Q+1) /
36 (PRIO_MAX-PRIO_MIN+1);
37 if (new_q < MAX_USER_Q) new_q = MAX_USER_Q; /* shouldn't happen */
38 if (new_q > MIN_USER_Q) new_q = MIN_USER_Q; /* shouldn't happen */
40 /* Dequeue the process and put it in its new queue if it is runnable. */
41 RTS_SET(rp, RTS_SYS_LOCK);
42 rp->p_max_priority = rp->p_priority = new_q;
43 RTS_UNSET(rp, RTS_SYS_LOCK);
45 return(OK);
48 #endif /* USE_NICE */