The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/kernel/system/do_nice.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    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 

Cache object: ff5c179fb9dd3e9912910a871b085749


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.