1 | /* The kernel call implemented in this file:
|
---|
2 | * m_type: SYS_NICE
|
---|
3 | *
|
---|
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 | */
|
---|
8 |
|
---|
9 | #include "../system.h"
|
---|
10 | #include <minix/type.h>
|
---|
11 | #include <sys/resource.h>
|
---|
12 |
|
---|
13 | #if USE_NICE
|
---|
14 |
|
---|
15 | /*===========================================================================*
|
---|
16 | * do_nice *
|
---|
17 | *===========================================================================*/
|
---|
18 | PUBLIC int do_nice(message *m_ptr)
|
---|
19 | {
|
---|
20 | /* Change process priority or stop the process. */
|
---|
21 | int proc_nr, pri, new_q ;
|
---|
22 | register struct proc *rp;
|
---|
23 |
|
---|
24 | /* Extract the message parameters and do sanity checking. */
|
---|
25 | if(!isokendpt(m_ptr->PR_ENDPT, &proc_nr)) return EINVAL;
|
---|
26 | if (iskerneln(proc_nr)) return(EPERM);
|
---|
27 | pri = m_ptr->PR_PRIORITY;
|
---|
28 | rp = proc_addr(proc_nr);
|
---|
29 |
|
---|
30 | if (pri == PRIO_STOP) {
|
---|
31 |
|
---|
32 | /* Take process off the scheduling queues. */
|
---|
33 | lock_dequeue(rp);
|
---|
34 | rp->p_rts_flags |= NO_PRIORITY;
|
---|
35 | return(OK);
|
---|
36 | }
|
---|
37 | else if (pri >= PRIO_MIN && pri <= PRIO_MAX) {
|
---|
38 |
|
---|
39 | /* The value passed in is currently between PRIO_MIN and PRIO_MAX.
|
---|
40 | * We have to scale this between MIN_USER_Q and MAX_USER_Q to match
|
---|
41 | * the kernel's scheduling queues.
|
---|
42 | */
|
---|
43 | new_q = MAX_USER_Q + (pri-PRIO_MIN) * (MIN_USER_Q-MAX_USER_Q+1) /
|
---|
44 | (PRIO_MAX-PRIO_MIN+1);
|
---|
45 | if (new_q < MAX_USER_Q) new_q = MAX_USER_Q; /* shouldn't happen */
|
---|
46 | if (new_q > MIN_USER_Q) new_q = MIN_USER_Q; /* shouldn't happen */
|
---|
47 |
|
---|
48 | /* Make sure the process is not running while changing its priority.
|
---|
49 | * Put the process back in its new queue if it is runnable.
|
---|
50 | */
|
---|
51 | lock_dequeue(rp);
|
---|
52 | rp->p_max_priority = rp->p_priority = new_q;
|
---|
53 | if (! rp->p_rts_flags) lock_enqueue(rp);
|
---|
54 |
|
---|
55 | return(OK);
|
---|
56 | }
|
---|
57 | return(EINVAL);
|
---|
58 | }
|
---|
59 |
|
---|
60 | #endif /* USE_NICE */
|
---|
61 |
|
---|