diff options
author | San Mehat <san@google.com> | 2010-02-25 14:02:55 -0800 |
---|---|---|
committer | San Mehat <san@google.com> | 2010-02-25 14:02:55 -0800 |
commit | 10d469bff9031e857c7a290dae7d6ccf7b3a18f8 (patch) | |
tree | cfd47c56e88088785967417773a2380a81b9fb38 /toolbox/ionice.c | |
parent | d969faa161310d0a3792766320daa3200b84bd74 (diff) | |
download | system_core-10d469bff9031e857c7a290dae7d6ccf7b3a18f8.zip system_core-10d469bff9031e857c7a290dae7d6ccf7b3a18f8.tar.gz system_core-10d469bff9031e857c7a290dae7d6ccf7b3a18f8.tar.bz2 |
system: Add support for getting/setting i/o priorities and include a userspace tool
Signed-off-by: San Mehat <san@google.com>
Diffstat (limited to 'toolbox/ionice.c')
-rw-r--r-- | toolbox/ionice.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/toolbox/ionice.c b/toolbox/ionice.c new file mode 100644 index 0000000..4a182f2 --- /dev/null +++ b/toolbox/ionice.c @@ -0,0 +1,57 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <errno.h> + +#include <cutils/iosched_policy.h> + +static char *classes[] = {"none", "rt", "be", "idle", NULL}; + +int ionice_main(int argc, char *argv[]) +{ + IoSchedClass clazz = IoSchedClass_NONE; + int ioprio = 0; + int pid; + + if(argc != 2 && argc != 4) { + fprintf(stderr, "usage: ionice <pid> [none|rt|be|idle] [prio]\n"); + return 1; + } + + if (!(pid = atoi(argv[1]))) { + fprintf(stderr, "Invalid pid specified\n"); + return 1; + } + + if (argc == 2) { + if (android_get_ioprio(pid, &clazz, &ioprio)) { + fprintf(stderr, "Failed to read priority (%s)\n", strerror(errno)); + return 1; + } + fprintf(stdout, "Pid %d, class %s (%d), prio %d\n", pid, classes[clazz], clazz, ioprio); + return 0; + } + + if (!strcmp(argv[2], "none")) { + clazz = IoSchedClass_NONE; + } else if (!strcmp(argv[2], "rt")) { + clazz = IoSchedClass_RT; + } else if (!strcmp(argv[2], "be")) { + clazz = IoSchedClass_BE; + } else if (!strcmp(argv[2], "idle")) { + clazz = IoSchedClass_IDLE; + } else { + fprintf(stderr, "Unsupported class '%s'\n", argv[2]); + return 1; + } + + ioprio = atoi(argv[3]); + + printf("Setting pid %d i/o class to %d, prio %d\n", pid, clazz, ioprio); + if (android_set_ioprio(pid, clazz, ioprio)) { + fprintf(stderr, "Failed to set priority (%s)\n", strerror(errno)); + return 1; + } + + return 0; +} |