diff options
author | Arkadiusz MiĆkiewicz | 2005-10-02 15:24:48 (GMT) |
---|---|---|
committer | cvs2git | 2012-06-24 12:13:13 (GMT) |
commit | 8dd93674562ab7fe85c73725419810cf974376b2 (patch) | |
tree | 2eb99eefb497c84612a256d978f8ba876aeb00b0 | |
download | ionice-8dd93674562ab7fe85c73725419810cf974376b2.zip ionice-8dd93674562ab7fe85c73725419810cf974376b2.tar.gz |
- initial
Changed files:
ionice.c -> 1.1
-rw-r--r-- | ionice.c | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/ionice.c b/ionice.c new file mode 100644 index 0000000..63c198b --- /dev/null +++ b/ionice.c @@ -0,0 +1,94 @@ +#include <stdio.h> +#include <stdlib.h> +#include <errno.h> +#include <getopt.h> +#include <unistd.h> +#include <sys/ptrace.h> +#include <asm/unistd.h> + +extern int sys_ioprio_set(int); +extern int sys_ioprio_get(void); + +#if defined(__i386__) +#define __NR_ioprio_set 289 +#define __NR_ioprio_get 290 +#elif defined(__ppc__) +#define __NR_ioprio_set 273 +#define __NR_ioprio_get 274 +#elif defined(__x86_64__) +#define __NR_ioprio_set 251 +#define __NR_ioprio_get 252 +#elif defined(__ia64__) +#define __NR_ioprio_set 1274 +#define __NR_ioprio_get 1275 +#else +#error "Unsupported arch" +#endif + +_syscall1(int, ioprio_set, int, ioprio); +_syscall0(int, ioprio_get); + +enum { + IOPRIO_CLASS_NONE, + IOPRIO_CLASS_RT, + IOPRIO_CLASS_BE, + IOPRIO_CLASS_IDLE, +}; + +const char *to_prio[] = { "none", "realtime", "best-effort", "idle", }; + +int main(int argc, char *argv[]) +{ + int ioprio = 4, set = 0, ioprio_class = IOPRIO_CLASS_BE; + int c; + + while ((c = getopt(argc, argv, "+n:c:")) != EOF) { + switch (c) { + case 'n': + ioprio = strtol(optarg, NULL, 10); + set = 1; + break; + case 'c': + ioprio_class = strtol(optarg, NULL, 10); + set = 1; + break; + } + } + + switch (ioprio_class) { + case IOPRIO_CLASS_NONE: + ioprio_class = IOPRIO_CLASS_BE; + break; + case IOPRIO_CLASS_RT: + case IOPRIO_CLASS_BE: + break; + case IOPRIO_CLASS_IDLE: + ioprio = 7; + break; + default: + printf("bad prio class %d\n", ioprio_class); + return 1; + } + + if (!set) { + ioprio = ioprio_get(); + + if (ioprio == -1) + perror("ioprio_get"); + else { + ioprio_class = ioprio >> 24; + ioprio = ioprio & 0xff; + printf("%s: prio %d\n", to_prio[ioprio_class], ioprio); + } + } else if (argv[optind]) { + printf("%s: prio %d\n", to_prio[ioprio_class], ioprio); + if (ioprio_set(ioprio | ioprio_class << 24) == -1) { + perror("ioprio_set"); + return 1; + } + execvp(argv[optind], &argv[optind]); + } + + return 0; +} + |