From 23d2e0b0b723b2cc64808fc2c21da27759e42c56 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Sun, 25 Sep 2011 05:15:43 -0400 Subject: [PATCH 1/7] tests: add SCHED_BATCH test Reference: https://bugzilla.redhat.com/show_bug.cgi?id=741090 Acked-by:: Jaromir Capik Acked-by: Sami Kerola Signed-off-by: Mike Fleetwood --- testsuite/.gitignore | 1 + testsuite/Makefile.am | 5 ++++ testsuite/ps.test/ps_sched_batch.exp | 12 +++++++++ testsuite/ps.test/test-schedbatch.c | 39 ++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 testsuite/ps.test/ps_sched_batch.exp create mode 100644 testsuite/ps.test/test-schedbatch.c diff --git a/testsuite/.gitignore b/testsuite/.gitignore index 96ef0306..b14d968d 100644 --- a/testsuite/.gitignore +++ b/testsuite/.gitignore @@ -2,3 +2,4 @@ *.sum site.bak site.exp +test-schedbatch diff --git a/testsuite/Makefile.am b/testsuite/Makefile.am index d1682ac1..3f795323 100644 --- a/testsuite/Makefile.am +++ b/testsuite/Makefile.am @@ -4,6 +4,10 @@ export DEJAGNU # Programs that are expected across the board. DEJATOOL = +noinst_PROGRAMS = test-schedbatch + +test_schedbatch_SOURCES = ps.test/test-schedbatch.c + if LINUX # These should be in defined in 'across the board' scope, but are # temporarily disabled on other than linux systems, see commit @@ -35,6 +39,7 @@ EXTRA_DIST = \ pmap.test/pmap.exp \ ps.test/ps_output.exp \ ps.test/ps_personality.exp \ + ps.test/ps_sched_batch.exp \ pwdx.test/pwdx.exp \ slabtop.test/slabtop.exp \ sysctl.test/sysctl_read.exp \ diff --git a/testsuite/ps.test/ps_sched_batch.exp b/testsuite/ps.test/ps_sched_batch.exp new file mode 100644 index 00000000..e0c31ffd --- /dev/null +++ b/testsuite/ps.test/ps_sched_batch.exp @@ -0,0 +1,12 @@ +# +# check the ps SCHED_BATCH scheduler policy output +# +set ps "${topdir}ps/pscommand" +set schedbatch "${topdir}testsuite/test-schedbatch" + +spawn $schedbatch 18 + +set test "ps SCHED_BATCH scheduler" +spawn $ps --no-header -o comm,cls,nice -a +expect_pass "$test" "\\s+test-schedbatch\\s+B\\s+18" +untested "$test" diff --git a/testsuite/ps.test/test-schedbatch.c b/testsuite/ps.test/test-schedbatch.c new file mode 100644 index 00000000..13cd6f33 --- /dev/null +++ b/testsuite/ps.test/test-schedbatch.c @@ -0,0 +1,39 @@ +/* test-schedbatch.c - Create a process using SCHED_BATCH scheduler + * policy and nice value. + * Compile: gcc -o test-schedbatch -Wall test-schedbatch.c + * Usage: ./test-schedbatch [ ] + * + * Author: Mike Fleetwood + * https://bugzilla.redhat.com/show_bug.cgi?id=741090 + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include + +int main(int argc, const char *argv[]) +{ + int nice = 19; + struct sched_param sp; + char msg[50]; + + if (argc >= 2) { + nice = atoi(argv[1]); + } + sp.sched_priority = 0; + if (sched_setscheduler(0, SCHED_BATCH, &sp)) { + perror("sched_setscheduler(0,SCHED_BATCH,{.sched_priority=0}"); + } + if (setpriority(PRIO_PROCESS, 0, nice) || errno) { + (void)snprintf(msg, sizeof(msg), + "setpriority(PRIO_PROCESS, 0, %d)", nice); + perror(msg); + } + while (1) { + getchar(); + } +} From 2bac5334b05554c186d36377f59b3c91c0258431 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Sun, 25 Sep 2011 05:17:06 -0400 Subject: [PATCH 2/7] 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); } From fc3bf171ff26ded103d05e855c16a763f72306a4 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 24 Jan 2012 12:56:33 -0500 Subject: [PATCH 3/7] pmap: fix const warning pmap.c:300:8: warning: assignment discards 'const' qualifier from pointer target type [enabled by default] Signed-off-by: Mike Frysinger --- pmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmap.c b/pmap.c index 3296ea70..1f42bec2 100644 --- a/pmap.c +++ b/pmap.c @@ -161,7 +161,7 @@ static int one_proc(proc_t * p) unsigned long total_private_writeable = 0ul; KLONG diff = 0; - char *cp2 = NULL; + const char *cp2 = NULL; unsigned long long rss = 0ull; unsigned long long private_dirty = 0ull; unsigned long long shared_dirty = 0ull; From 0da6537c5f5b6a742211100cb03d445b6fdb617a Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 24 Jan 2012 12:56:29 -0500 Subject: [PATCH 4/7] fix printf format warnings pgrep.c: In function 'main': pgrep.c:793:4: warning: format '%d' expects argument of type 'int', but argument 4 has type 'long int' [-Wformat] vmstat.c: In function 'diskpartition_format': vmstat.c:382:9: warning: format '%u' expects argument of type 'unsigned int', but argument 5 has type 'long long unsigned int' [-Wformat] vmstat.c:408:10: warning: format '%u' expects argument of type 'unsigned int', but argument 5 has type 'long long unsigned int' [-Wformat] w.c: In function 'main': w.c:394:4: warning: format '%d' expects argument of type 'int', but argument 4 has type 'long unsigned int' [-Wformat] Signed-off-by: Mike Frysinger --- pgrep.c | 2 +- vmstat.c | 2 +- w.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pgrep.c b/pgrep.c index 0c193093..9473a1ea 100644 --- a/pgrep.c +++ b/pgrep.c @@ -779,7 +779,7 @@ int main (int argc, char **argv) if (errno==ESRCH) // gone now, which is OK continue; - xwarn(_("killing pid %ld failed")); + xwarn(_("killing pid %ld failed"), procs[i].num); } } else { if (opt_count) { diff --git a/vmstat.c b/vmstat.c index 8fbe5455..5348cee5 100644 --- a/vmstat.c +++ b/vmstat.c @@ -356,7 +356,7 @@ static int diskpartition_format(const char *partition_name) struct disk_stat *disks; struct partition_stat *partitions, *current_partition = NULL; unsigned long ndisks, j, k, npartitions; - const char format[] = "%20u %10llu %10u %10u\n"; + const char format[] = "%20u %10llu %10u %10llu\n"; fDiskstat = fopen("/proc/diskstats", "rb"); if (!fDiskstat) diff --git a/w.c b/w.c index e3e9dbb0..072cdc09 100644 --- a/w.c +++ b/w.c @@ -392,7 +392,7 @@ int main(int argc, char **argv) userlen = atoi(env_var); if (userlen < 8 || userlen > USERSZ) { xwarnx - (_("User length environment PROCPS_USERLEN must be between 8 and %d, ignoring.\n"), + (_("User length environment PROCPS_USERLEN must be between 8 and %zu, ignoring.\n"), USERSZ); userlen = 8; } From 62c0cf67f665419b6169788b5996ad7238604281 Mon Sep 17 00:00:00 2001 From: Samuli Suominen Date: Tue, 24 Jan 2012 13:01:13 -0500 Subject: [PATCH 5/7] fix basic ncurses check The first check for ncurses is for the non-wide variant, so drop the "w". The wide version gets checked later on based on watch8bit. Signed-off-by: Samuli Suominen Signed-off-by: Mike Frysinger --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 709868a7..838d4a45 100644 --- a/configure.ac +++ b/configure.ac @@ -133,7 +133,7 @@ AC_ARG_WITH([ncurses], if test "x$with_ncurses" = xno; then AM_CONDITIONAL(WITH_NCURSES, false) else - AC_CHECK_LIB(ncursesw, initscr, [have_ncurses=yes], [have_ncurses=no]) + AC_CHECK_LIB(ncurses, initscr, [have_ncurses=yes], [have_ncurses=no]) AC_CHECK_HEADERS(curses.h ncurses.h term.h, [], [have_ncurses=no], AC_INCLUDES_DEFAULT) if test "x$have_ncurses" = xno; then AC_MSG_ERROR([ncurses support missing/incomplete (for partial build use --without-ncurses)]) From 061de22badc121227fdcb3720ef96087868bbe9e Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 24 Jan 2012 13:01:14 -0500 Subject: [PATCH 6/7] fix AC_ARG_WITH(ncurses) handling The third arg is for "the user has specified some flag", not "the user has disabled things", so use $withval. Signed-off-by: Mike Frysinger --- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 838d4a45..f6a24a64 100644 --- a/configure.ac +++ b/configure.ac @@ -127,7 +127,7 @@ AC_TRY_COMPILE([#include ], AC_ARG_WITH([ncurses], AS_HELP_STRING([--without-ncurses], [build only applications not needing ncurses]), - [with_ncurses=no], [with_ncurses=yes] + [with_ncurses=$withval], [with_ncurses=yes] ) if test "x$with_ncurses" = xno; then From 96e86ef1a0c9288711329761eccfb279fcd90790 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 24 Jan 2012 13:01:15 -0500 Subject: [PATCH 7/7] use pkg-config for ncurses by default Newer ncurses install pkg-config files, so search those first. If they aren't found, fall back to existing detection logic. Signed-off-by: Mike Frysinger --- configure.ac | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/configure.ac b/configure.ac index f6a24a64..792222cd 100644 --- a/configure.ac +++ b/configure.ac @@ -16,6 +16,7 @@ AC_PROG_CC AM_PROG_CC_C_O AC_PROG_INSTALL AC_PROG_LN_S +PKG_PROG_PKG_CONFIG AC_SUBST([WITH_WATCH8BIT]) AC_ARG_ENABLE([watch8bit], @@ -133,19 +134,23 @@ AC_ARG_WITH([ncurses], if test "x$with_ncurses" = xno; then AM_CONDITIONAL(WITH_NCURSES, false) else - AC_CHECK_LIB(ncurses, initscr, [have_ncurses=yes], [have_ncurses=no]) - AC_CHECK_HEADERS(curses.h ncurses.h term.h, [], [have_ncurses=no], AC_INCLUDES_DEFAULT) - if test "x$have_ncurses" = xno; then - AC_MSG_ERROR([ncurses support missing/incomplete (for partial build use --without-ncurses)]) - fi + PKG_CHECK_MODULES([NCURSES], [ncurses], [], [ + AC_CHECK_LIB(ncurses, initscr, [have_ncurses=yes], [have_ncurses=no]) + AC_CHECK_HEADERS(curses.h ncurses.h term.h, [], [have_ncurses=no], AC_INCLUDES_DEFAULT) + if test "x$have_ncurses" = xno; then + AC_MSG_ERROR([ncurses support missing/incomplete (for partial build use --without-ncurses)]) + fi + NCURSES_LIBS="-lncurses" + ]) AM_CONDITIONAL(WITH_NCURSES, true) if test "$enable_watch8bit" = yes; then - AC_CHECK_LIB([ncursesw], [addwstr], [WATCH_NCURSES_LIBS=-lncursesw], - [AC_MSG_ERROR([Cannot find ncurses wide library ncursesw with --enable-watch8bit])]) + PKG_CHECK_MODULES([NCURSESW], [ncursesw], [WATCH_NCURSES_LIBS="$NCURSESW_LIBS"], [ + AC_CHECK_LIB([ncursesw], [addwstr], [WATCH_NCURSES_LIBS=-lncursesw], + [AC_MSG_ERROR([Cannot find ncurses wide library ncursesw with --enable-watch8bit])]) + ]) else - WATCH_NCURSES_LIBS="-lncurses" + WATCH_NCURSES_LIBS="$NCURSES_LIBS" fi - NCURSES_LIBS="-lncurses" fi AC_SUBST([NCURSES_LIBS]) AC_SUBST([WATCH_NCURSES_LIBS])