Skip to content

Commit 7400b06

Browse files
sbrivio-rhummakynes
authored andcommitted
nft_set_pipapo: Introduce AVX2-based lookup implementation
If the AVX2 set is available, we can exploit the repetitive characteristic of this algorithm to provide a fast, vectorised version by using 256-bit wide AVX2 operations for bucket loads and bitwise intersections. In most cases, this implementation consistently outperforms rbtree set instances despite the fact they are configured to use a given, single, ranged data type out of the ones used for performance measurements by the nft_concat_range.sh kselftest. That script, injecting packets directly on the ingoing device path with pktgen, reports, averaged over five runs on a single AMD Epyc 7402 thread (3.35GHz, 768 KiB L1D$, 12 MiB L2$), the figures below. CONFIG_RETPOLINE was not set here. Note that this is not a fair comparison over hash and rbtree set types: non-ranged entries (used to have a reference for hash types) would be matched faster than this, and matching on a single field only (which is the case for rbtree) is also significantly faster. However, it's not possible at the moment to choose this set type for non-ranged entries, and the current implementation also needs a few minor adjustments in order to match on less than two fields. ---------------.-----------------------------------.------------. AMD Epyc 7402 | baselines, Mpps | this patch | 1 thread |___________________________________|____________| 3.35GHz | | | | | | 768KiB L1D$ | netdev | hash | rbtree | | | ---------------| hook | no | single | | pipapo | type entries | drop | ranges | field | pipapo | AVX2 | ---------------|--------|--------|--------|--------|------------| net,port | | | | | | 1000 | 19.0 | 10.4 | 3.8 | 4.0 | 7.5 +87% | ---------------|--------|--------|--------|--------|------------| port,net | | | | | | 100 | 18.8 | 10.3 | 5.8 | 6.3 | 8.1 +29% | ---------------|--------|--------|--------|--------|------------| net6,port | | | | | | 1000 | 16.4 | 7.6 | 1.8 | 2.1 | 4.8 +128% | ---------------|--------|--------|--------|--------|------------| port,proto | | | | | | 30000 | 19.6 | 11.6 | 3.9 | 0.5 | 2.6 +420% | ---------------|--------|--------|--------|--------|------------| net6,port,mac | | | | | | 10 | 16.5 | 5.4 | 4.3 | 3.4 | 4.7 +38% | ---------------|--------|--------|--------|--------|------------| net6,port,mac, | | | | | | proto 1000 | 16.5 | 5.7 | 1.9 | 1.4 | 3.6 +26% | ---------------|--------|--------|--------|--------|------------| net,mac | | | | | | 1000 | 19.0 | 8.4 | 3.9 | 2.5 | 6.4 +156% | ---------------'--------'--------'--------'--------'------------' A similar strategy could be easily reused to implement specialised versions for other SIMD sets, and I plan to post at least a NEON version at a later time. Signed-off-by: Stefano Brivio <sbrivio@redhat.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 8683f4b commit 7400b06

6 files changed

Lines changed: 1270 additions & 0 deletions

File tree

‎include/net/netfilter/nf_tables_core.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ extern const struct nft_set_type nft_set_hash_fast_type;
7575
extern const struct nft_set_type nft_set_rbtree_type;
7676
extern const struct nft_set_type nft_set_bitmap_type;
7777
extern const struct nft_set_type nft_set_pipapo_type;
78+
extern const struct nft_set_type nft_set_pipapo_avx2_type;
7879

7980
struct nft_expr;
8081
struct nft_regs;

‎net/netfilter/Makefile‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ nf_tables-objs := nf_tables_core.o nf_tables_api.o nft_chain_filter.o \
8282
nft_set_hash.o nft_set_bitmap.o nft_set_rbtree.o \
8383
nft_set_pipapo.o
8484

85+
ifdef CONFIG_X86_64
86+
ifneq (,$(findstring -DCONFIG_AS_AVX2=1,$(KBUILD_CFLAGS)))
87+
nf_tables-objs += nft_set_pipapo_avx2.o
88+
endif
89+
endif
90+
8591
obj-$(CONFIG_NF_TABLES) += nf_tables.o
8692
obj-$(CONFIG_NFT_COMPAT) += nft_compat.o
8793
obj-$(CONFIG_NFT_CONNLIMIT) += nft_connlimit.o

‎net/netfilter/nf_tables_api.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3272,6 +3272,9 @@ static const struct nft_set_type *nft_set_types[] = {
32723272
&nft_set_rhash_type,
32733273
&nft_set_bitmap_type,
32743274
&nft_set_rbtree_type,
3275+
#if defined(CONFIG_X86_64) && defined(CONFIG_AS_AVX2)
3276+
&nft_set_pipapo_avx2_type,
3277+
#endif
32753278
&nft_set_pipapo_type,
32763279
};
32773280

‎net/netfilter/nft_set_pipapo.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@
339339
#include <linux/bitmap.h>
340340
#include <linux/bitops.h>
341341

342+
#include "nft_set_pipapo_avx2.h"
342343
#include "nft_set_pipapo.h"
343344

344345
/* Current working bitmap index, toggled between field matches */
@@ -2174,3 +2175,26 @@ const struct nft_set_type nft_set_pipapo_type = {
21742175
.elemsize = offsetof(struct nft_pipapo_elem, ext),
21752176
},
21762177
};
2178+
2179+
#if defined(CONFIG_X86_64) && defined(CONFIG_AS_AVX2)
2180+
const struct nft_set_type nft_set_pipapo_avx2_type = {
2181+
.features = NFT_SET_INTERVAL | NFT_SET_MAP | NFT_SET_OBJECT |
2182+
NFT_SET_TIMEOUT,
2183+
.ops = {
2184+
.lookup = nft_pipapo_avx2_lookup,
2185+
.insert = nft_pipapo_insert,
2186+
.activate = nft_pipapo_activate,
2187+
.deactivate = nft_pipapo_deactivate,
2188+
.flush = nft_pipapo_flush,
2189+
.remove = nft_pipapo_remove,
2190+
.walk = nft_pipapo_walk,
2191+
.get = nft_pipapo_get,
2192+
.privsize = nft_pipapo_privsize,
2193+
.estimate = nft_pipapo_avx2_estimate,
2194+
.init = nft_pipapo_init,
2195+
.destroy = nft_pipapo_destroy,
2196+
.gc_init = nft_pipapo_gc_init,
2197+
.elemsize = offsetof(struct nft_pipapo_elem, ext),
2198+
},
2199+
};
2200+
#endif

0 commit comments

Comments
 (0)