Viewing SCHED_FIFO, SCHED_RR stats in /proc

Nigel Gamble (nigel@nrg.org)
Thu, 26 Apr 2001 16:54:32 -0700 (PDT)


I've just noticed that the priority and nice values listed in
/proc/<pid>/stat aren't very useful for SCHED_FIFO or SCHED_RR tasks.
I'd like to be able to distinguish tasks with these policies from
SCHED_OTHER tasks, and to view task->rt_priority.

Am I correct that this information is not currently available through
/proc?

Here is one way to expose this information that should be compatible
with existing tools like top and ps. For SCHED_OTHER, the values are
unchanged. For SCHED_RR and SCHED_FIFO, the priority value displayed is
(20 + task->rt_priority), which distinguishes them for SCHED_OTHER
priorities which can't be greater than 20. And SCHED_FIFO tasks, whose
nice value is ignored by the scheduler, are distinguished from SCHED_RR
tasks by begin displayed with a nice value of -99.

diff -u -r1.2 array.c
--- linux/fs/proc/array.c 2001/04/16 23:26:41 1.2
+++ linux/fs/proc/array.c 2001/04/26 22:37:56
@@ -336,11 +336,18 @@

collect_sigign_sigcatch(task, &sigign, &sigcatch);

- /* scale priority and nice values from timeslices to -20..20 */
- /* to make it look like a "normal" Unix priority/nice value */
- priority = task->counter;
- priority = 20 - (priority * 10 + DEF_COUNTER / 2) / DEF_COUNTER;
- nice = task->nice;
+ if (task->policy == SCHED_OTHER) {
+ /* scale priority and nice values from timeslices to -20..20 */
+ /* to make it look like a "normal" Unix priority/nice value */
+ priority = task->counter;
+ priority = 20 - (priority * 10 + DEF_COUNTER / 2) / DEF_COUNTER;
+ } else {
+ priority = 20 + task->rt_priority;
+ }
+ if (task->policy == SCHED_FIFO)
+ nice = -99;
+ else
+ nice = task->nice;

read_lock(&tasklist_lock);
ppid = task->p_opptr->pid;

Can anyone think of a better way of doing this?

Nigel Gamble nigel@nrg.org
Mountain View, CA, USA. http://www.nrg.org/

MontaVista Software nigel@mvista.com

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/