Hi Christian,
we're currently in a feature freeze for v2.13. I'll postpone this to
util-linux-ng-v2.14 (later on we'll backport it from 2.14 to 2.13.x
when it will be really necessary for stable linux-2.6.23).
Thanks!
Karel
On Sat, Jul 21, 2007 at 07:46:27PM +0200, Christian Casteyde wrote:
>
> I've made a little patch to take new schedulers policy in chrt.
> This will obviously be usefull, since CFS has been integrated
> in the upcoming 2.6.23.
>
> Really simple changes + some options reordered. I had to resolve
> a conflict in short options between iso and idle (I took s for iSo and kept
> i for Idle).
>
> I also add two lines to fix user and group ids, just in case the process
> is installed setuid (as it would be able to exec a shell and modify any
> process priorities). Ok, this should not be done, but let's be secure
> in depth. This fix should also be applied to other tools, such as ionice btw
> (there are distros who patch ionice themselves, and they do things
> in the complex way).
>
> Regards,
> CC
> --- chrt.c.orig 2007-07-16 15:21:29.000000000 +0200
> +++ chrt.c 2007-07-21 19:36:34.000000000 +0200
> @@ -26,6 +26,7 @@
> #include <stdio.h>
> #include <stdlib.h>
> #include <sched.h>
> +#include <sys/types.h>
> #include <unistd.h>
> #include <getopt.h>
> #include <errno.h>
> @@ -37,24 +38,39 @@
> # define SCHED_BATCH 3
> #endif
>
> +/* We have more scheduling classes since Linux 2.6.23
> + * these may not be defined so use the same temporary hack
> + */
> +
> +#ifndef SCHED_ISO
> +# define SCHED_ISO 4
> +#endif
> +#ifndef SCHED_IDLE
> +# define SCHED_IDLE 5
> +#endif
> +
> static void show_usage(const char *cmd)
> {
> fprintf(stderr, "chrt (%s)\n", PACKAGE_STRING);
> fprintf(stderr, "usage: %s [options] [prio] [pid | cmd [args...]]\n",
> cmd);
> fprintf(stderr, "manipulate real-time attributes of a process\n");
> - fprintf(stderr, " -b, --batch "
> - "set policy to SCHED_BATCH\n");
> fprintf(stderr, " -f, --fifo "
> "set policy to SCHED_FIFO\n");
> + fprintf(stderr, " -r, --rr "
> + "set policy to SCHED_RR (default)\n");
> + fprintf(stderr, " -b, --batch "
> + "set policy to SCHED_BATCH\n");
> + fprintf(stderr, " -s, --iso "
> + "set policy to SCHED_ISO\n");
> + fprintf(stderr, " -i, --idle "
> + "set policy to SCHED_IDLE\n");
> + fprintf(stderr, " -o, --other "
> + "set policy to SCHED_OTHER (SCHED_NORMAL)\n");
> fprintf(stderr, " -p, --pid "
> "operate on existing given pid\n");
> fprintf(stderr, " -m, --max "
> "show min and max valid priorities\n");
> - fprintf(stderr, " -o, --other "
> - "set policy to SCHED_OTHER\n");
> - fprintf(stderr, " -r, --rr "
> - "set policy to SCHED_RR (default)\n");
> fprintf(stderr, " -h, --help "
> "display this help\n");
> fprintf(stderr, " -v, --verbose "
> @@ -95,6 +111,12 @@
> case SCHED_BATCH:
> printf("SCHED_BATCH\n");
> break;
> + case SCHED_ISO:
> + printf("SCHED_ISO\n");
> + break;
> + case SCHED_IDLE:
> + printf("SCHED_IDLE\n");
> + break;
> default:
> printf("unknown\n");
> }
> @@ -140,6 +162,20 @@
> printf("SCHED_BATCH min/max priority\t: %d/%d\n", min, max);
> else
> printf("SCHED_BATCH not supported?\n");
> +
> + max = sched_get_priority_max(SCHED_ISO);
> + min = sched_get_priority_min(SCHED_ISO);
> + if (max >= 0 && min >= 0)
> + printf("SCHED_ISO min/max priority\t: %d/%d\n", min, max);
> + else
> + printf("SCHED_ISO not supported?\n");
> +
> + max = sched_get_priority_max(SCHED_IDLE);
> + min = sched_get_priority_min(SCHED_IDLE);
> + if (max >= 0 && min >= 0)
> + printf("SCHED_IDLE min/max priority\t: %d/%d\n", min, max);
> + else
> + printf("SCHED_IDLE not supported?\n");
> }
>
> int main(int argc, char *argv[])
> @@ -151,17 +187,25 @@
> struct option longopts[] = {
> { "batch", 0, NULL, 'b' },
> { "fifo", 0, NULL, 'f' },
> + { "rr", 0, NULL, 'r' },
> + { "iso", 0, NULL, 's' },
> + { "idle", 0, NULL, 'i' },
> + { "other", 0, NULL, 'o' },
> { "pid", 0, NULL, 'p' },
> { "help", 0, NULL, 'h' },
> { "max", 0, NULL, 'm' },
> - { "other", 0, NULL, 'o' },
> - { "rr", 0, NULL, 'r' },
> { "verbose", 0, NULL, 'v' },
> { "version", 0, NULL, 'V' },
> { NULL, 0, NULL, 0 }
> };
>
> - while((i = getopt_long(argc, argv, "+bfphmorvV", longopts, NULL)) != -1)
> + /*
> + * Just in case we are setuid or setgid, drop all priviledges:
> + */
> + seteuid(getuid());
> + setgid(getgid());
> +
> + while((i = getopt_long(argc, argv, "+bfrsiophmvV", longopts, NULL)) !=
> -1)
> {
> int ret = 1;
>
> @@ -172,9 +216,15 @@
> case 'f':
> policy = SCHED_FIFO;
> break;
> - case 'm':
> - show_min_max();
> - return 0;
> + case 'r':
> + policy = SCHED_RR;
> + break;
> + case 's':
> + policy = SCHED_ISO;
> + break;
> + case 'i':
> + policy = SCHED_IDLE;
> + break;
> case 'o':
> policy = SCHED_OTHER;
> break;
> @@ -187,9 +237,9 @@
> return 1;
> }
> break;
> - case 'r':
> - policy = SCHED_RR;
> - break;
> + case 'm':
> + show_min_max();
> + return 0;
> case 'v':
> verbose = 1;
> break;
--
Karel Zak <[EMAIL PROTECTED]>
-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html