[4] | 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_PROC_NR 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 | int proc_nr, pri, new_q ;
|
---|
| 21 | register struct proc *rp;
|
---|
| 22 |
|
---|
| 23 | /* Extract the message parameters and do sanity checking. */
|
---|
| 24 | proc_nr = m_ptr->PR_PROC_NR;
|
---|
| 25 | if (! isokprocn(proc_nr)) return(EINVAL);
|
---|
| 26 | if (iskerneln(proc_nr)) return(EPERM);
|
---|
| 27 | pri = m_ptr->PR_PRIORITY;
|
---|
| 28 | if (pri < PRIO_MIN || pri > PRIO_MAX) return(EINVAL);
|
---|
| 29 |
|
---|
| 30 | /* The priority is currently between PRIO_MIN and PRIO_MAX. We have to
|
---|
| 31 | * scale this between MIN_USER_Q and MAX_USER_Q.
|
---|
| 32 | */
|
---|
| 33 | new_q = MAX_USER_Q + (pri-PRIO_MIN) * (MIN_USER_Q-MAX_USER_Q+1) /
|
---|
| 34 | (PRIO_MAX-PRIO_MIN+1);
|
---|
| 35 | if (new_q < MAX_USER_Q) new_q = MAX_USER_Q; /* shouldn't happen */
|
---|
| 36 | if (new_q > MIN_USER_Q) new_q = MIN_USER_Q; /* shouldn't happen */
|
---|
| 37 |
|
---|
| 38 | /* Make sure the process is not running while changing its priority; the
|
---|
| 39 | * max_priority is the base priority. Put the process back in its new
|
---|
| 40 | * queue if it is runnable.
|
---|
| 41 | */
|
---|
| 42 | rp = proc_addr(proc_nr);
|
---|
| 43 | lock_dequeue(rp);
|
---|
| 44 | rp->p_max_priority = rp->p_priority = new_q;
|
---|
| 45 | if (! rp->p_rts_flags) lock_enqueue(rp);
|
---|
| 46 |
|
---|
| 47 | return(OK);
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | #endif /* USE_NICE */
|
---|
| 51 |
|
---|