flowtop: Use one nfct handle for dump & refresh flows
[netsniff-ng.git] / iosched.c
blobff82126831210ff83bb118f84396adefe417f26b
1 /*
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.
6 */
8 #include <sys/syscall.h>
10 #include "iosched.h"
11 #include "die.h"
13 #define IOPRIO_CLASS_SHIFT 13
15 enum {
16 ioprio_class_none,
17 ioprio_class_rt,
18 ioprio_class_be,
19 ioprio_class_idle,
22 enum {
23 ioprio_who_process = 1,
24 ioprio_who_pgrp,
25 ioprio_who_user,
28 static const char *const to_prio[] = {
29 "none",
30 "realtime",
31 "best-effort",
32 "idle",
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);
49 if (ret < 0)
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());
56 if (ioprio < 0)
57 panic("Failed to fetch io prio for pid!\n");
58 else {
59 int ioclass = ioprio >> IOPRIO_CLASS_SHIFT;
60 if (ioclass != ioprio_class_idle) {
61 ioprio &= 0xff;
62 printf("%s: prio %d\n", to_prio[ioclass], ioprio);
63 } else
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);