Bug 741090

Summary: ps not displaying nice value for processes with SCHED_BATCH scheduler policy
Product: [Fedora] Fedora Reporter: Mike Fleetwood <mike.fleetwood>
Component: procpsAssignee: Jaromír Cápík <jcapik>
Status: CLOSED RAWHIDE QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: unspecified    
Version: 16CC: fedora, jcapik, ovasik
Target Milestone: ---   
Target Release: ---   
Hardware: i686   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2012-01-30 14:33:20 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Test case program
none
Suggested patch none

Description Mike Fleetwood 2011-09-25 09:12:33 UTC
Description of problem:
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.

For easier testing I have written a small test program to demonstrate the
fault with ps which is attached.  test-schedbatch.c

Suggested patch to fix ps attached.  procps-3.2.8-ps-schedbatch.patch



Version-Release number of selected component (if applicable):
procps-3.2.8-15.fc14

(Expect procps in Fedora 15 & Rawhide and Red Hat Enterprise 5.x and 6.x
are also effected).



How reproducible:
Always.



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
3.


  
Actual results:
# Using ps command
[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
# Querying kernel directly
[mike@rockover c]$ awk '{printf "%5d %-17s %1d %2d\n", $1, $2, $41, $19}' /proc/20552/stat
20552 (test-schedbatch) 3 18



Expected results:
[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).

Actual results looking at boinc client:
# Using ps command
[mike@rockover ~]$ ps -u boinc -o pid,ppid,user,comm,cls,nice
  PID  PPID USER     COMMAND         CLS  NI
18300     1 boinc    boinc_client     TS  19
18342 18300 boinc    hadcm3n_6.07_i6   B   -
18346 18342 boinc    hadcm3n_um_6.07   B   -
32701 18300 boinc    einstein_S6Buck   B   -
# Querying kernel directly
[mike@rockover ~]$ awk '{printf "%5d %-17s %1d %2d\n", $1, $2, $41, $19}' /proc/{18300,18342,18346,32701}/stat
18300 (boinc_client)    0 19
18342 (hadcm3n_6.07_i6) 3 19
18346 (hadcm3n_um_6.07) 3 19
32701 (einstein_S6Buck) 3 19

Expected results looking at boinc client:
[mike@rockover ~]$ ps -u boinc -o pid,ppid,user,comm,cls,nice
  PID  PPID USER     COMMAND         CLS  NI
18300     1 boinc    boinc_client     TS  19
18342 18300 boinc    hadcm3n_6.07_i6   B  19
18346 18342 boinc    hadcm3n_um_6.07   B  19
32701 18300 boinc    einstein_S6Buck   B  19

Comment 1 Mike Fleetwood 2011-09-25 09:15:43 UTC
Created attachment 524774 [details]
Test case program

Comment 2 Mike Fleetwood 2011-09-25 09:17:06 UTC
Created attachment 524775 [details]
Suggested patch

Comment 3 Mike Fleetwood 2011-11-12 16:09:19 UTC
Tested ps in a few other version of Fedora / Red Hat and confirmed they have fault too:
procps-3.2.7-16.el5  (RHEL 5.5)
procps-3.2.7-17.el5  (RHEL 5.7)
procps-3.2.8-17.el6.i686  (RHEL 6.1)
procps-3.2.8-21.20110302git.fc15.i686  (Fedora 15)
procps-3.2.8-23.20110302git.fc16.i686  (Fedora 16)

Moving bug to against Fedora 16.

Comment 4 Jaromír Cápík 2012-01-30 14:33:20 UTC
Hello Mike.

I just applied Your patch in Fedora Rawhide without any modifications.

Thank You.

Regards,
Jaromir.