From af1d1167e998eab1e056a49d07f900c830644c1d Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Wed, 24 Oct 2012 23:00:40 +0200 Subject: [PATCH] src: general cleanups, make pcap ops const Signed-off-by: Daniel Borkmann --- src/built_in.h | 20 -------------------- src/pcap.c | 4 ++-- src/pcap.h | 6 +++--- src/pcap_mmap.c | 2 +- src/pcap_rw.c | 2 +- src/pcap_sg.c | 2 +- src/ring.h | 5 +++++ 7 files changed, 13 insertions(+), 28 deletions(-) diff --git a/src/built_in.h b/src/built_in.h index 8ab36e6e..f3b4cbfc 100644 --- a/src/built_in.h +++ b/src/built_in.h @@ -104,22 +104,6 @@ typedef uint8_t u8; # define constant(x) __builtin_constant_p(x) #endif -#ifndef prefetch_rd_hi -# define prefetch_rd_hi(addr) __builtin_prefetch(addr, 0, 3) -#endif - -#ifndef prefetch_rd_lo -# define prefetch_rd_lo(addr) __builtin_prefetch(addr, 0, 0) -#endif - -#ifndef prefetch_wr_hi -# define prefetch_wr_hi(addr) __builtin_prefetch(addr, 1, 3) -#endif - -#ifndef prefetch_wr_lo -# define prefetch_wr_lo(addr) __builtin_prefetch(addr, 1, 0) -#endif - #ifndef fmemset # define fmemset __builtin_memset #endif @@ -144,10 +128,6 @@ typedef uint8_t u8; # define unreachable() do { } while (1) #endif -#ifndef __read_mostly -# define __read_mostly __attribute__((__section__(".data.read_mostly"))) -#endif - #ifndef __unused # define __unused __attribute__ ((__unused__)) #endif diff --git a/src/pcap.c b/src/pcap.c index ce04e82a..481ccb43 100644 --- a/src/pcap.c +++ b/src/pcap.c @@ -8,9 +8,9 @@ #include #include "pcap.h" -struct pcap_file_ops *pcap_ops[PCAP_OPS_SIZ] = {0}; +const struct pcap_file_ops *pcap_ops[PCAP_OPS_SIZ] = {0}; -int pcap_ops_group_register(struct pcap_file_ops *ops, +int pcap_ops_group_register(const struct pcap_file_ops *ops, enum pcap_ops_groups group) { if (!ops) diff --git a/src/pcap.h b/src/pcap.h index 0a7b0d63..293dc8ae 100644 --- a/src/pcap.h +++ b/src/pcap.h @@ -114,13 +114,13 @@ struct pcap_file_ops { void (*prepare_close_pcap)(int fd, enum pcap_mode mode); }; -extern struct pcap_file_ops *pcap_ops[PCAP_OPS_SIZ]; +extern const struct pcap_file_ops *pcap_ops[PCAP_OPS_SIZ]; -extern int pcap_ops_group_register(struct pcap_file_ops *ops, +extern int pcap_ops_group_register(const struct pcap_file_ops *ops, enum pcap_ops_groups group); extern void pcap_ops_group_unregister(enum pcap_ops_groups group); -static inline struct pcap_file_ops * +static inline const struct pcap_file_ops * pcap_ops_group_get(enum pcap_ops_groups group) { return pcap_ops[group]; diff --git a/src/pcap_mmap.c b/src/pcap_mmap.c index 583c5375..6f762700 100644 --- a/src/pcap_mmap.c +++ b/src/pcap_mmap.c @@ -250,7 +250,7 @@ static void pcap_mmap_prepare_close_pcap(int fd, enum pcap_mode mode) spinlock_unlock(&lock); } -struct pcap_file_ops pcap_mmap_ops __read_mostly = { +const struct pcap_file_ops pcap_mmap_ops = { .name = "mmap", .pull_file_header = pcap_mmap_pull_file_header, .push_file_header = pcap_mmap_push_file_header, diff --git a/src/pcap_rw.c b/src/pcap_rw.c index 4f08f931..baff0a11 100644 --- a/src/pcap_rw.c +++ b/src/pcap_rw.c @@ -105,7 +105,7 @@ static int pcap_rw_prepare_reading_pcap(int fd) return 0; } -struct pcap_file_ops pcap_rw_ops __read_mostly = { +const struct pcap_file_ops pcap_rw_ops = { .name = "read-write", .pull_file_header = pcap_rw_pull_file_header, .push_file_header = pcap_rw_push_file_header, diff --git a/src/pcap_sg.c b/src/pcap_sg.c index 236bca90..afc24676 100644 --- a/src/pcap_sg.c +++ b/src/pcap_sg.c @@ -222,7 +222,7 @@ static void pcap_sg_fsync_pcap(int fd) spinlock_unlock(&lock); } -struct pcap_file_ops pcap_sg_ops __read_mostly = { +const struct pcap_file_ops pcap_sg_ops = { .name = "scatter-gather", .pull_file_header = pcap_sg_pull_file_header, .push_file_header = pcap_sg_push_file_header, diff --git a/src/ring.h b/src/ring.h index 925e5351..4d2b485f 100644 --- a/src/ring.h +++ b/src/ring.h @@ -54,6 +54,7 @@ static inline void next_slot(unsigned int *it, struct ring *ring) atomic_cmp_swp(it, ring->layout.tp_frame_nr, 0); } +#if 0 static inline void next_slot_prerd(unsigned int *it, struct ring *ring) { (*it)++; @@ -67,6 +68,10 @@ static inline void next_slot_prewr(unsigned int *it, struct ring *ring) atomic_cmp_swp(it, ring->layout.tp_frame_nr, 0); prefetch_wr_hi(ring->frames[*it].iov_base); } +#else +# define next_slot_prerd next_slot +# define next_slot_prewr next_slot +#endif static inline void next_rnd_slot(unsigned int *it, struct ring *ring) { -- 2.11.4.GIT