diff options
| -rw-r--r-- | iosched.c | 76 | ||||
| -rw-r--r-- | iosched.h | 8 | ||||
| -rw-r--r-- | netsniff-ng/Makefile | 1 | ||||
| -rw-r--r-- | pcap_mm.c | 1 | ||||
| -rw-r--r-- | pcap_rw.c | 1 | ||||
| -rw-r--r-- | pcap_sg.c | 1 | ||||
| -rw-r--r-- | xutils.c | 59 | ||||
| -rw-r--r-- | xutils.h | 3 | 
8 files changed, 88 insertions, 62 deletions
| diff --git a/iosched.c b/iosched.c new file mode 100644 index 0000000..7417973 --- /dev/null +++ b/iosched.c @@ -0,0 +1,76 @@ +/* + * netsniff-ng - the packet sniffing beast + * Copyright 2009, 2010 Daniel Borkmann. + * Copyright 2010 Marek Polacek. + * Subject to the GPL, version 2. + */ + +#include <sys/syscall.h> + +#include "iosched.h" +#include "die.h" + +#define IOPRIO_CLASS_SHIFT      13 + +enum { +	ioprio_class_none, +	ioprio_class_rt, +	ioprio_class_be, +	ioprio_class_idle, +}; + +enum { +	ioprio_who_process = 1, +	ioprio_who_pgrp, +	ioprio_who_user, +}; + +static const char *const to_prio[] = { +	"none", +	"realtime", +	"best-effort", +	"idle", +}; + +static inline int ioprio_set(int which, int who, int ioprio) +{ +	return syscall(SYS_ioprio_set, which, who, ioprio); +} + +static inline int ioprio_get(int which, int who) +{ +	return syscall(SYS_ioprio_get, which, who); +} + +static void ioprio_setpid(pid_t pid, int ioprio, int ioclass) +{ +	int ret = ioprio_set(ioprio_who_process, pid, +			     ioprio | ioclass << IOPRIO_CLASS_SHIFT); +	if (ret < 0) +		panic("Failed to set io prio for pid!\n"); +} + +void ioprio_print(void) +{ +	int ioprio = ioprio_get(ioprio_who_process, getpid()); +	if (ioprio < 0) +		panic("Failed to fetch io prio for pid!\n"); +	else { +		int ioclass = ioprio >> IOPRIO_CLASS_SHIFT; +		if (ioclass != ioprio_class_idle) { +			ioprio &= 0xff; +			printf("%s: prio %d\n", to_prio[ioclass], ioprio); +		} else +			printf("%s\n", to_prio[ioclass]); +	} +} + +void set_ioprio_rt(void) +{ +	ioprio_setpid(getpid(), 4, ioprio_class_rt); +} + +void set_ioprio_be(void) +{ +	ioprio_setpid(getpid(), 4, ioprio_class_be); +} diff --git a/iosched.h b/iosched.h new file mode 100644 index 0000000..19ff1ff --- /dev/null +++ b/iosched.h @@ -0,0 +1,8 @@ +#ifndef IOSCHED_H +#define IOSCHED_H + +extern void ioprio_print(void); +extern void set_ioprio_rt(void); +extern void set_ioprio_be(void); + +#endif /* IOSCHED_H */ diff --git a/netsniff-ng/Makefile b/netsniff-ng/Makefile index 7d5f89c..53f1fea 100644 --- a/netsniff-ng/Makefile +++ b/netsniff-ng/Makefile @@ -33,6 +33,7 @@ netsniff-ng-objs =	dissector.o \  			proto_mpls_unicast.o \  			proto_80211_mac_hdr.o \  			irq.o \ +			iosched.o \  			xio.o \  			xutils.o \  			xmalloc.o \ @@ -17,6 +17,7 @@  #include "xio.h"  #include "xutils.h"  #include "built_in.h" +#include "iosched.h"  static size_t map_size = 0;  static char *ptr_va_start, *ptr_va_curr; @@ -16,6 +16,7 @@  #include "xutils.h"  #include "xio.h"  #include "die.h" +#include "iosched.h"  static ssize_t pcap_rw_write(int fd, pcap_pkthdr_t *phdr, enum pcap_type type,  			     const uint8_t *packet, size_t len) @@ -16,6 +16,7 @@  #include "xio.h"  #include "xutils.h"  #include "built_in.h" +#include "iosched.h"  static struct iovec iov[1024] __cacheline_aligned;  static off_t iov_off_rd = 0, iov_slot = 0; @@ -2,7 +2,6 @@   * netsniff-ng - the packet sniffing beast   * Copyright 2009, 2010 Daniel Borkmann.   * Copyright 2009, 2010 Emmanuel Roullit. - * Copyright 2010 Marek Polacek.   * Subject to the GPL, version 2.   */ @@ -46,21 +45,6 @@  #include "ring.h"  #include "built_in.h" -#define IOPRIO_CLASS_SHIFT      13 - -enum { -	ioprio_class_none, -	ioprio_class_rt, -	ioprio_class_be, -	ioprio_class_idle, -}; - -enum { -	ioprio_who_process = 1, -	ioprio_who_pgrp, -	ioprio_who_user, -}; -  enum {  	sock_rmem_max = 0,  	sock_rmem_def, @@ -723,49 +707,6 @@ int set_sched_status(int policy, int priority)  	return 0;  } -static inline int ioprio_set(int which, int who, int ioprio) -{ -	return syscall(SYS_ioprio_set, which, who, ioprio); -} - -static inline int ioprio_get(int which, int who) -{ -	return syscall(SYS_ioprio_get, which, who); -} - -static void ioprio_setpid(pid_t pid, int ioprio, int ioclass) -{ -	int ret = ioprio_set(ioprio_who_process, pid, -			     ioprio | ioclass << IOPRIO_CLASS_SHIFT); -	if (ret < 0) -		panic("Failed to set io prio for pid!\n"); -} - -void ioprio_print(void) -{ -	int ioprio = ioprio_get(ioprio_who_process, getpid()); -	if (ioprio < 0) -		panic("Failed to fetch io prio for pid!\n"); -	else { -		int ioclass = ioprio >> IOPRIO_CLASS_SHIFT; -		if (ioclass != ioprio_class_idle) { -			ioprio &= 0xff; -			printf("%s: prio %d\n", to_prio[ioclass], ioprio); -		} else -			printf("%s\n", to_prio[ioclass]); -	} -} - -void set_ioprio_rt(void) -{ -	ioprio_setpid(getpid(), 4, ioprio_class_rt); -} - -void set_ioprio_be(void) -{ -	ioprio_setpid(getpid(), 4, ioprio_class_be); -} -  void xlockme(void)  {  	if (mlockall(MCL_CURRENT | MCL_FUTURE) != 0) @@ -69,9 +69,6 @@ extern void cpu_affinity(int cpu);  extern int set_cpu_affinity(char *str, int inverted);  extern int set_proc_prio(int prio);  extern int set_sched_status(int policy, int priority); -extern void ioprio_print(void); -extern void set_ioprio_rt(void); -extern void set_ioprio_be(void);  extern size_t strlcpy(char *dest, const char *src, size_t size);  extern int slprintf(char *dst, size_t size, const char *fmt, ...)  __check_format_printf(3, 4);  extern int slprintf_nocheck(char *dst, size_t size, const char *fmt, ...); | 
