2 * netsniff-ng - the packet sniffing beast
3 * Copyright 2009, 2010 Daniel Borkmann.
4 * Copyright 2010 Marek Polacek.
5 * Subject to the GPL, version 2.
8 #include <sys/syscall.h>
13 #define IOPRIO_CLASS_SHIFT 13
23 ioprio_who_process
= 1,
28 static const char *const to_prio
[] = {
35 static inline int ioprio_set(int which
, int who
, int ioprio
)
37 return syscall(SYS_ioprio_set
, which
, who
, ioprio
);
40 static inline int ioprio_get(int which
, int who
)
42 return syscall(SYS_ioprio_get
, which
, who
);
45 static void ioprio_setpid(pid_t pid
, int ioprio
, int ioclass
)
47 int ret
= ioprio_set(ioprio_who_process
, pid
,
48 ioprio
| ioclass
<< IOPRIO_CLASS_SHIFT
);
50 panic("Failed to set io prio for pid: %s\n", strerror(errno
));
53 void ioprio_print(void)
55 int ioprio
= ioprio_get(ioprio_who_process
, getpid());
57 panic("Failed to fetch io prio for pid!\n");
59 int ioclass
= ioprio
>> IOPRIO_CLASS_SHIFT
;
60 if (ioclass
!= ioprio_class_idle
) {
62 printf("%s: prio %d\n", to_prio
[ioclass
], ioprio
);
64 printf("%s\n", to_prio
[ioclass
]);
68 void set_ioprio_rt(void)
70 ioprio_setpid(getpid(), 4, ioprio_class_rt
);
73 void set_ioprio_be(void)
75 ioprio_setpid(getpid(), 4, ioprio_class_be
);