San Mehat | 10d469b | 2010-02-25 14:02:55 -0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
Elliott Hughes | a744b05 | 2015-01-28 11:37:57 -0800 | [diff] [blame] | 3 | #include <string.h> |
San Mehat | 10d469b | 2010-02-25 14:02:55 -0800 | [diff] [blame] | 4 | #include <unistd.h> |
| 5 | #include <errno.h> |
| 6 | |
| 7 | #include <cutils/iosched_policy.h> |
| 8 | |
| 9 | static char *classes[] = {"none", "rt", "be", "idle", NULL}; |
| 10 | |
| 11 | int ionice_main(int argc, char *argv[]) |
| 12 | { |
| 13 | IoSchedClass clazz = IoSchedClass_NONE; |
| 14 | int ioprio = 0; |
| 15 | int pid; |
| 16 | |
| 17 | if(argc != 2 && argc != 4) { |
| 18 | fprintf(stderr, "usage: ionice <pid> [none|rt|be|idle] [prio]\n"); |
| 19 | return 1; |
| 20 | } |
| 21 | |
| 22 | if (!(pid = atoi(argv[1]))) { |
| 23 | fprintf(stderr, "Invalid pid specified\n"); |
| 24 | return 1; |
| 25 | } |
| 26 | |
| 27 | if (argc == 2) { |
| 28 | if (android_get_ioprio(pid, &clazz, &ioprio)) { |
| 29 | fprintf(stderr, "Failed to read priority (%s)\n", strerror(errno)); |
| 30 | return 1; |
| 31 | } |
| 32 | fprintf(stdout, "Pid %d, class %s (%d), prio %d\n", pid, classes[clazz], clazz, ioprio); |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | if (!strcmp(argv[2], "none")) { |
| 37 | clazz = IoSchedClass_NONE; |
| 38 | } else if (!strcmp(argv[2], "rt")) { |
| 39 | clazz = IoSchedClass_RT; |
| 40 | } else if (!strcmp(argv[2], "be")) { |
| 41 | clazz = IoSchedClass_BE; |
| 42 | } else if (!strcmp(argv[2], "idle")) { |
| 43 | clazz = IoSchedClass_IDLE; |
| 44 | } else { |
| 45 | fprintf(stderr, "Unsupported class '%s'\n", argv[2]); |
| 46 | return 1; |
| 47 | } |
| 48 | |
| 49 | ioprio = atoi(argv[3]); |
| 50 | |
| 51 | printf("Setting pid %d i/o class to %d, prio %d\n", pid, clazz, ioprio); |
| 52 | if (android_set_ioprio(pid, clazz, ioprio)) { |
| 53 | fprintf(stderr, "Failed to set priority (%s)\n", strerror(errno)); |
| 54 | return 1; |
| 55 | } |
| 56 | |
| 57 | return 0; |
| 58 | } |