DPDK  23.03.0
rte_member.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4 
57 #ifndef _RTE_MEMBER_H_
58 #define _RTE_MEMBER_H_
59 
60 #ifdef __cplusplus
61 extern "C" {
62 #endif
63 
64 #include <stdint.h>
65 #include <stdbool.h>
66 #include <inttypes.h>
67 
68 #include <rte_compat.h>
69 #include <rte_common.h>
70 
72 typedef uint16_t member_set_t;
74 #define RTE_MEMBER_NO_MATCH 0
75 
76 #define RTE_MEMBER_ENTRIES_MAX (1 << 30)
77 
78 #define RTE_MEMBER_LOOKUP_BULK_MAX 64
79 
80 #define RTE_MEMBER_BUCKET_ENTRIES 16
81 
82 #define RTE_MEMBER_NAMESIZE 32
83 
84 #define RTE_RAND_MAX ~0LLU
85 
94 #define RTE_MEMBER_SKETCH_ALWAYS_BOUNDED 0x01
95 
96 #define RTE_MEMBER_SKETCH_COUNT_BYTE 0x02
97 
99 #if defined(RTE_ARCH_X86) || defined(__ARM_FEATURE_CRC32)
100 #include <rte_hash_crc.h>
101 #define MEMBER_HASH_FUNC rte_hash_crc
102 #else
103 #include <rte_jhash.h>
104 #define MEMBER_HASH_FUNC rte_jhash
105 #endif
106 
107 extern int librte_member_logtype;
108 
109 #define RTE_MEMBER_LOG(level, ...) \
110  rte_log(RTE_LOG_ ## level, \
111  librte_member_logtype, \
112  RTE_FMT("%s(): " RTE_FMT_HEAD(__VA_ARGS__,), \
113  __func__, \
114  RTE_FMT_TAIL(__VA_ARGS__,)))
115 
117 struct rte_member_setsum;
118 
125 struct rte_member_parameters;
126 
136  RTE_MEMBER_TYPE_SKETCH,
137  RTE_MEMBER_NUM_TYPE
138 };
139 
141 enum rte_member_sig_compare_function {
142  RTE_MEMBER_COMPARE_SCALAR = 0,
143  RTE_MEMBER_COMPARE_AVX2,
144  RTE_MEMBER_COMPARE_NUM
145 };
146 
147 /* sketch update function with different implementations. */
148 typedef void (*sketch_update_fn_t)(const struct rte_member_setsum *ss,
149  const void *key,
150  uint32_t count);
151 
152 /* sketch lookup function with different implementations. */
153 typedef uint64_t (*sketch_lookup_fn_t)(const struct rte_member_setsum *ss,
154  const void *key);
155 
156 /* sketch delete function with different implementations. */
157 typedef void (*sketch_delete_fn_t)(const struct rte_member_setsum *ss,
158  const void *key);
159 
161 struct rte_member_setsum {
162  enum rte_member_setsum_type type; /* Type of the set summary. */
163  uint32_t key_len; /* Length of key. */
164  uint32_t prim_hash_seed; /* Primary hash function seed. */
165  uint32_t sec_hash_seed; /* Secondary hash function seed. */
166 
167  /* Hash table based. */
168  uint32_t bucket_cnt; /* Number of buckets. */
169  uint32_t bucket_mask; /* Bit mask to get bucket index. */
170  /* For runtime selecting AVX, scalar, etc for signature comparison. */
171  enum rte_member_sig_compare_function sig_cmp_fn;
172  uint8_t cache; /* If it is cache mode for ht based. */
173 
174  /* Vector bloom filter. */
175  uint32_t num_set; /* Number of set (bf) in vbf. */
176  uint32_t bits; /* Number of bits in each bf. */
177  uint32_t bit_mask; /* Bit mask to get bit location in bf. */
178  uint32_t num_hashes; /* Number of hash values to index bf. */
179 
180  /* Parameters for sketch */
181  float error_rate;
182  float sample_rate;
183  uint32_t num_col;
184  uint32_t num_row;
185  int always_bounded;
186  double converge_thresh;
187  uint32_t topk;
188  uint32_t count_byte;
189  uint64_t *hash_seeds;
190  sketch_update_fn_t sketch_update; /* Pointer to the sketch update function */
191  sketch_lookup_fn_t sketch_lookup; /* Pointer to the sketch lookup function */
192  sketch_delete_fn_t sketch_delete; /* Pointer to the sketch delete function */
193 
194  void *runtime_var;
195  uint32_t mul_shift; /* vbf internal variable used during bit test. */
196  uint32_t div_shift; /* vbf internal variable used during bit test. */
197 
198  void *table; /* This is the handler of hash table or vBF array. */
199 
200 
201  /* Second cache line should start here. */
202  uint32_t socket_id; /* NUMA Socket ID for memory. */
203  char name[RTE_MEMBER_NAMESIZE]; /* Name of this set summary. */
204 #ifdef RTE_ARCH_X86
205  bool use_avx512;
206 #endif
208 
219  const char *name;
232 
252  uint8_t is_cache;
253 
270  uint32_t num_keys;
271 
276  uint32_t key_len;
277 
287  uint32_t num_set;
288 
309 
318  uint32_t prim_hash_seed;
319 
323  uint32_t sec_hash_seed;
324 
330  float error_rate;
331 
337  float sample_rate;
338 
343  uint32_t top_k;
344 
348  uint32_t extra_flag;
349 
350  int socket_id;
352 
366 struct rte_member_setsum *
367 rte_member_find_existing(const char *name);
368 
381 struct rte_member_setsum *
382 rte_member_create(const struct rte_member_parameters *params);
383 
400 int
401 rte_member_lookup(const struct rte_member_setsum *setsum, const void *key,
402  member_set_t *set_id);
403 
424 int
425 rte_member_lookup_bulk(const struct rte_member_setsum *setsum,
426  const void **keys, uint32_t num_keys,
427  member_set_t *set_ids);
428 
453 int
454 rte_member_lookup_multi(const struct rte_member_setsum *setsum,
455  const void *key, uint32_t max_match_per_key,
456  member_set_t *set_id);
457 
484 int
485 rte_member_lookup_multi_bulk(const struct rte_member_setsum *setsum,
486  const void **keys, uint32_t num_keys,
487  uint32_t max_match_per_key,
488  uint32_t *match_count,
489  member_set_t *set_ids);
490 
520 int
521 rte_member_add(const struct rte_member_setsum *setsum, const void *key,
522  member_set_t set_id);
523 
539 __rte_experimental
540 int
541 rte_member_add_byte_count(const struct rte_member_setsum *setsum,
542  const void *key, uint32_t byte_count);
543 
559 __rte_experimental
560 int
561 rte_member_query_count(const struct rte_member_setsum *setsum,
562  const void *key, uint64_t *count);
563 
564 
581 __rte_experimental
582 int
583 rte_member_report_heavyhitter(const struct rte_member_setsum *setsum,
584  void **keys, uint64_t *counts);
585 
586 
597 void
598 rte_member_free(struct rte_member_setsum *setsum);
599 
610 void
611 rte_member_reset(const struct rte_member_setsum *setsum);
612 
631 int
632 rte_member_delete(const struct rte_member_setsum *setsum, const void *key,
633  member_set_t set_id);
634 
635 #ifdef __cplusplus
636 }
637 #endif
638 
639 #endif /* _RTE_MEMBER_H_ */
const char * name
Definition: rte_member.h:219
#define RTE_MEMBER_NAMESIZE
Definition: rte_member.h:82
int rte_member_delete(const struct rte_member_setsum *setsum, const void *key, member_set_t set_id)
int rte_member_add(const struct rte_member_setsum *setsum, const void *key, member_set_t set_id)
int rte_member_lookup_multi(const struct rte_member_setsum *setsum, const void *key, uint32_t max_match_per_key, member_set_t *set_id)
int rte_member_lookup_multi_bulk(const struct rte_member_setsum *setsum, const void **keys, uint32_t num_keys, uint32_t max_match_per_key, uint32_t *match_count, member_set_t *set_ids)
__rte_experimental int rte_member_add_byte_count(const struct rte_member_setsum *setsum, const void *key, uint32_t byte_count)
__rte_experimental int rte_member_report_heavyhitter(const struct rte_member_setsum *setsum, void **keys, uint64_t *counts)
uint16_t member_set_t
Definition: rte_member.h:72
void rte_member_free(struct rte_member_setsum *setsum)
#define __rte_cache_aligned
Definition: rte_common.h:440
int rte_member_lookup_bulk(const struct rte_member_setsum *setsum, const void **keys, uint32_t num_keys, member_set_t *set_ids)
__rte_experimental int rte_member_query_count(const struct rte_member_setsum *setsum, const void *key, uint64_t *count)
struct rte_member_setsum * rte_member_find_existing(const char *name)
rte_member_setsum_type
Definition: rte_member.h:133
int rte_member_lookup(const struct rte_member_setsum *setsum, const void *key, member_set_t *set_id)
void rte_member_reset(const struct rte_member_setsum *setsum)
struct rte_member_setsum * rte_member_create(const struct rte_member_parameters *params)