1 #include <lib/base/ioprio.h>
7 #include <sys/ptrace.h>
8 #include <asm/unistd.h>
10 #include <lib/base/eerror.h>
12 extern "C" int sys_ioprio_set(int, int, int);
13 extern "C" int sys_ioprio_get(int, int);
16 #define __NR_ioprio_set 289
17 #define __NR_ioprio_get 290
18 #elif defined(__ppc__) || defined(__powerpc__)
19 #define __NR_ioprio_set 273
20 #define __NR_ioprio_get 274
21 #elif defined(__x86_64__)
22 #define __NR_ioprio_set 251
23 #define __NR_ioprio_get 252
24 #elif defined(__ia64__)
25 #define __NR_ioprio_set 1274
26 #define __NR_ioprio_get 1275
27 #elif defined(__mips__)
28 #define __NR_ioprio_set 4284
29 #define __NR_ioprio_get 4285
31 #error "Unsupported arch"
34 #if defined(_syscall3) && defined(_syscall2)
36 _syscall3(int, ioprio_set, int, which, int, who, int, ioprio);
37 _syscall2(int, ioprio_get, int, which, int, who);
41 static inline int ioprio_set(int which, int who, int ioprio)
43 return syscall(__NR_ioprio_set, which, who, ioprio);
46 static inline int ioprio_get(int which, int who)
48 return syscall(__NR_ioprio_get, which, who);
53 #define IOPRIO_CLASS_SHIFT 13
56 IOPRIO_WHO_PROCESS = 1,
61 const char *to_prio[] = { "none", "realtime", "best-effort", "idle", };
63 void setIoPrio(int prio_class, int prio)
65 if (prio_class < 0 || prio_class > 3)
67 eDebug("prio class(%d) out of valid range (0..3)", prio_class);
70 if (prio < 0 || prio > 7)
72 eDebug("prio level(%d) out of range (0..7)", prio);
75 if (ioprio_set(IOPRIO_WHO_PROCESS, 0 /*pid 0 .. current process*/, prio | prio_class << IOPRIO_CLASS_SHIFT) == -1)
76 eDebug("setIoPrio failed (%m) !");
78 eDebug("setIoPrio %s level %d ok", to_prio[prio_class], prio);
83 int pid = 0, ioprio = ioprio_get(IOPRIO_WHO_PROCESS, pid);
85 eDebug("pid=%d, %d", pid, ioprio);
88 eDebug("ioprio_get(%m)");
90 int ioprio_class = ioprio >> IOPRIO_CLASS_SHIFT;
91 ioprio = ioprio & 0xff;
92 eDebug("%s: prio %d", to_prio[ioprio_class], ioprio);