Understand process priority
Unga
unga888 at yahoo.com
Sun Dec 23 09:42:32 PST 2007
--- Erik Trulsson <ertr1013 at student.uu.se> wrote:
> On Sat, Dec 22, 2007 at 07:09:47PM -0800, Unga
> wrote:
> > Hi all
> >
> > $ ps -o pri,ni,rtprio,command -p `pgrep amarok`
> > PRI NI RTPRIO COMMAND
> > 20 0 normal amarokapp
> >
> > 1) Are there are 3 priority values per process, or
> > just one?
>
> There is really only one priority that is used when
> scheduling
> processes. The other two fields (nice and rtprio)
> modifies how
> the priority is set, but do not directly affect the
> priority.
>
> The actual priority is handled internally in the
> kernel and cannot
> be modified directly from userland.
>
>
> It is always the case that if two (or more)
> processes both want
> to use the CPU at the same time, then it is the one
> with the highest
> priority which gets to use it.
>
> (The term 'highest priority' can be slightly
> confusing, since it is normally
> the process with the lowest value in the 'PRI'
> field which has the highest
> priority.)
>
> For those processes that has a real time priority
> (rtprio) of 'normal',
> i.e. most normal processes, the priority is adjusted
> dynamically
> depending on how long it has waited for CPU, and how
> much CPU it used the
> last time it ran, etc. The 'nice' value affects how
> quickly the priority
> is adjusted up or down. A high nice value means
> that the priority will
> only increase slowly and decrease quickly, while it
> is the other way around
> for processes with a low nice value.
> Note however that even a process with a high nice
> value will get at least a
> little CPU time now and then, even if there are
> processes around that are
> much less nice that want the CPU too.
>
>
> For processes with a real time priority of something
> other than 'normal' the
> priority is not adjusted dynamically.
> Processes with rtprio=idle always have lower
> priority than all other
> processes.
> Processes with an actual real time priority set will
> always have higher
> priority than non-real time processes.
>
>
>
> >
> > 2) How should I read above? Is it Priority=20, ie.
> > NI=0, RTPRIO=normal?
>
> It is: Priority=20; Nice=0; Real time
> priority=normal
>
>
> > Does it all mean the same thing,
> > like the bytes=1048576 and KB=1024 and MB=1?
>
> No.
>
> >
> > 3) The rtprio(1) says "Priority is an integer
> between
> > 0 and RTP_PRIO_MAX (usually 31). 0 is the highest
> > priority". But when I run following command:
> >
> > $ ps aux -o pri,ni,rtprio,command
> >
> > USER PID %CPU %MEM VSZ RSS TT STAT
> STARTED
> > TIME COMMAND PRI NI RTPRIO COMMAND
> >
> > root 10 99.2 0.0 0 8 ?? RL
> 7:40PM
> > 0:00.00 [idle: cpu1] 171 0 idle:25 [idle:
> cpu1]
> >
> > root 26 0.0 0.0 0 8 ?? WL
> 7:40PM
> > 0:00.02 [irq18: envy24ht -80 0 intr:4 [irq18:
> > envy24ht
> >
> > test 1212 0.0 9.3 58544 48176 ?? S 8:06PM
>
> > 0:06.15 amarokapp 20 0 normal amarokapp
> >
> > That is,
> > PID PRI NI RTPRIO
> > 10 171 0 idle:25
> > 26 -80 0 intr:4
> > 1212 20 0 normal
> >
> > This shows priority ranges at least from -80 to
> 171
> > contrary to the range mentioned in rtprio(1). Does
> > this means PID=26 has a higher priority than
> PID=1212?
>
> rtprio(1) does not set the PRI field directly. It
> sets the RTPRIO
> field. In your example these are 'idle:25' 'intr:4'
> and 'normal'
> indicating that these are run with idle priority,
> interrupt priority,
> and normal priority respectively. (The 'intr' value
> in the rtprio field
> can probably only be set directly by the kernel for
> interrupt threads, and
> is a bit outside the normal real time priorities.)
>
> The actual idel/real time priority value set by
> rtprio(1)/idprio(1) is not
> displayed by ps(1), but can be shown by
> rtprio(1)/idprio(1).
>
>
> Yes, PID=26 has a much higher priority than
> PID=1212, as it should
> considering that PID=26 is an interrupt thread,
> while PID=1212 is just
> an ordinary, non-real time, process.
>
>
> >
> > 4) Can a PRI=0 be considered Realtime?
>
> No, not really. If a process does not have rtprio
> set to something
> other than 'normal' or 'idle' it is not a real time
> process.
>
> >
> > 5) What is the meaning of priority=0 in
> > /etc/login.conf? Is it Realtime?
>
> No, the 'priority' field in /etc/login.conf sets the
> nice value.
>
> >
> > 6) What is the value should I set for priority in
> > /etc/login.conf if I want Realtime?
>
> You can't do that.
>
> You should also not set any process to a real-time
> priority unless
> you know exactly what you are doing and why you are
> doing it.
>
> The normal way of setting the relative priorities of
> processes on Unix
> systems is by setting the nice value (and only root
> is allowed to lower the
> nice value.)
>
>
Thanks for the detailed explanation.
Following is from /usr/include/sys/priority.h:
/*
* Priorities range from 0 to 255, but differences of
less then 4 (RQ_PPQ)
* are insignificant. Ranges are as follows:
*
* Interrupt threads: 0 - 63
* Top half kernel threads: 64 - 127
* Realtime user threads: 128 - 159
* Time sharing user threads: 160 - 223
* Idle user threads: 224 - 255
*
* XXX If/When the specific interrupt thread and top
half thread ranges
* disappear, a larger range can be used for user
processes.
*/
ps aux -o pri,ni,rtprio,command shows following:
USER PID %CPU %MEM VSZ RSS TT STAT STARTED
TIME COMMAND PRI NI RTPRIO COMMAND
root 12 91.0 0.0 0 8 ?? RL 9:50AM
830:41.81 [idle: cpu0] 171 0 idle:25 [idle: cpu0]
root 13 0.0 0.0 0 8 ?? WL 9:50AM
3:28.96 [swi4: clock sio -32 0 intr:52 [swi4: clock
sio
root 696 0.0 0.1 3240 764 ?? Is 9:51AM
0:00.06 /usr/sbin/moused 96 0 normal
/usr/sbin/moused
1. Can I further understand how to interpret above
numbers?
1a) 171 0 idle:25
What is 171? Has is upgraded to Time sharing user
threads range to be executed? What is idle:25? Is it
its default priority 224+25=249?
1b) -32 0 intr:52
What is -32? What is 52? Is it its default
priority 52 in the Interrupt threads range?
1c) 96 0 normal
The normal is what? Is it priority 160 or 223?
2. What is the value range can be specified for
priority in /etc/login.conf?
Regards
Unga
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
More information about the freebsd-questions
mailing list