Debian Codegraph @

testsuite/systemtap.syscall/ioprio.c

raw
1 /* COVERAGE: ioprio_set ioprio_get */
2
3 #define _GNU_SOURCE
4 #include <unistd.h>
5 #include <sys/syscall.h>
6
7 #if !defined(__NR_ioprio_set) || !defined(__NR_ioprio_get)
8 #error "ioprio_[gs]et syscall numbers not defined"
9 #endif
10
11 // There aren't any glibc wrappers for these syscalls, so create our
12 // own.
13
14 static inline int __ioprio_set(int which, int who, int ioprio)
15 {
16 return syscall(__NR_ioprio_set, which, who, ioprio);
17 }
18
19 static inline int __ioprio_get(int which, int who)
20 {
21 return syscall(__NR_ioprio_get, which, who);
22 }
23
24 // These enums/defines were copied from the kernel's
25 // include/linux/ioprio.h file.
26 enum {
27 IOPRIO_CLASS_NONE,
28 IOPRIO_CLASS_RT,
29 IOPRIO_CLASS_BE,
30 IOPRIO_CLASS_IDLE,
31 };
32
33 enum {
34 IOPRIO_WHO_PROCESS = 1,
35 IOPRIO_WHO_PGRP,
36 IOPRIO_WHO_USER,
37 };
38
39 #define IOPRIO_CLASS_SHIFT (13)
40 #define IOPRIO_PRIO_VALUE(class, data) (((class) << IOPRIO_CLASS_SHIFT) | data)
41
42 int main()
43 {
44 __ioprio_get(IOPRIO_WHO_USER, 0);
45 //staptest// ioprio_get (IOPRIO_WHO_USER, 0) = NNNN
46
47 __ioprio_set(IOPRIO_WHO_PROCESS, 0, IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 7));
48 //staptest// ioprio_set (IOPRIO_WHO_PROCESS, 0, IOPRIO_CLASS_BE|7) = NNNN
49
50 /* Limits testing */
51
52 __ioprio_get(-1, 0);
53 //staptest// ioprio_get (-1, 0) = NNNN
54
55 __ioprio_get(IOPRIO_WHO_PGRP, -1);
56 //staptest// ioprio_get (IOPRIO_WHO_PGRP, -1) = NNNN
57
58 __ioprio_set(-1, 0, IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 7));
59 //staptest// ioprio_set (-1, 0, IOPRIO_CLASS_BE|7) = NNNN
60
61 __ioprio_set(IOPRIO_WHO_PROCESS, -1, IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 7));
62 //staptest// ioprio_set (IOPRIO_WHO_PROCESS, -1, IOPRIO_CLASS_BE|7) = NNNN
63
64 __ioprio_set(IOPRIO_WHO_PROCESS, 0, -1);
65 //staptest// ioprio_set (IOPRIO_WHO_PROCESS, 0, 0x7ffff|NNNN) = NNNN
66
67 return 0;
68 }