1 /* The kernel call implemented in this file:
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
10 #include <sys/resource.h>
14 /*===========================================================================*
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 /* Make sure the process is not running while changing its priority.
41 * Put the process back in its new queue if it is runnable.
43 RTS_LOCK_SET(rp
, RTS_SYS_LOCK
);
44 rp
->p_max_priority
= rp
->p_priority
= new_q
;
45 RTS_LOCK_UNSET(rp
, RTS_SYS_LOCK
);