From 2bac5334b05554c186d36377f59b3c91c0258431 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Sun, 25 Sep 2011 05:17:06 -0400 Subject: [PATCH] ps: display the nice value for processes with the SCHED_BATCH scheduler policy Ps command does not display the nice value for processes with the SCHED_BATCH scheduler policy, only for SCHED_OTHER. Boinc (http://boinc.berkeley.edu/) client runs project processing jobs on Linux using SCHED_BATCH scheduler policy and nice value 19. The nice value is not displayable by ps. Steps to Reproduce: 1. Run process using SCHED_BATCH scheduler policy with nice value. ./test-schedbatch 18 & 2. Display process details: ps -o pid,ppid,user,comm,cls,nice Results before: [mike@rockover c]$ ps -o pid,ppid,user,comm,cls,nice PID PPID USER COMMAND CLS NI 18205 2540 mike bash TS 0 20552 18205 mike test-schedbatch B - 20553 18205 mike ps TS 0 [mike@rockover c]$ awk '{printf "%5d %-17s %1d %2d\n", $1, $2, $41, $19}' /proc/20552/stat 20552 (test-schedbatch) 3 18 Results after this patch: [mike@rockover c]$ ps -o pid,ppid,user,comm,cls,nice PID PPID USER COMMAND CLS NI 18205 2540 mike bash TS 0 20552 18205 mike test-schedbatch B 18 20553 18205 mike ps TS 0 Additional info: Here is the fragment from the sched_setscheduler(2) manual page on the subject: SCHED_BATCH: Scheduling batch processes (Since Linux 2.6.16.) SCHED_BATCH can only be used at static priority 0. This policy is similar to SCHED_OTHER in that it schedules the process according to its dynamic priority (based on the nice value). The difference is that this policy will cause the scheduler to always assume that the process is CPU-intensive. Consequently, the scheduler will apply a small scheduling penalty with respect to wakeup behaviour, so that this process is mildly disfavored in scheduling decisions. This policy is useful for workloads that are noninteractive, but do not want to lower their nice value, and for workloads that want a determin- istic scheduling policy without interactivity causing extra preemptions (between the workload's tasks). Reference: https://bugzilla.redhat.com/show_bug.cgi?id=741090 Acked-by: Jaromir Capik Acked-by: Sami Kerola Signed-off-by: Mike Fleetwood --- ps/output.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ps/output.c b/ps/output.c index 6880c8b7..b9e3bc59 100644 --- a/ps/output.c +++ b/ps/output.c @@ -624,8 +624,12 @@ static int pr_pri_api(char *restrict const outbuf, const proc_t *restrict const return snprintf(outbuf, COLWID, "%ld", -1 - pp->priority); } +// Linux applies nice value in the scheduling policies (classes) +// SCHED_OTHER(0) and SCHED_BATCH(3). Ref: sched_setscheduler(2). +// Also print nice value for old kernels which didn't use scheduling +// policies (-1). static int pr_nice(char *restrict const outbuf, const proc_t *restrict const pp){ - if(pp->sched!=0 && pp->sched!=(unsigned long)-1) return snprintf(outbuf, COLWID, "-"); + if(pp->sched!=0 && pp->sched!=3 && pp->sched!=-1) return snprintf(outbuf, COLWID, "-"); return snprintf(outbuf, COLWID, "%ld", pp->nice); }