DPDK  24.07.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 
54 #ifndef _RTE_MEMBER_H_
55 #define _RTE_MEMBER_H_
56 
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60 
61 #include <stdint.h>
62 #include <stdbool.h>
63 #include <inttypes.h>
64 
65 #include <rte_common.h>
66 
68 typedef uint16_t member_set_t;
70 #define RTE_MEMBER_NO_MATCH 0
71 
72 #define RTE_MEMBER_ENTRIES_MAX (1 << 30)
73 
74 #define RTE_MEMBER_LOOKUP_BULK_MAX 64
75 
76 #define RTE_MEMBER_BUCKET_ENTRIES 16
77 
78 #define RTE_MEMBER_NAMESIZE 32
79 
80 #define RTE_RAND_MAX ~0LLU
81 
90 #define RTE_MEMBER_SKETCH_ALWAYS_BOUNDED 0x01
91 
92 #define RTE_MEMBER_SKETCH_COUNT_BYTE 0x02
93 
95 #if defined(RTE_ARCH_X86) || defined(__ARM_FEATURE_CRC32)
96 #include <rte_hash_crc.h>
97 #define MEMBER_HASH_FUNC rte_hash_crc
98 #else
99 #include <rte_jhash.h>
100 #define MEMBER_HASH_FUNC rte_jhash
101 #endif
102 
104 struct rte_member_setsum;
105 
109 struct rte_member_parameters;
110 
117  RTE_MEMBER_TYPE_SKETCH,
118  RTE_MEMBER_NUM_TYPE
119 };
120 
122 enum rte_member_sig_compare_function {
123  RTE_MEMBER_COMPARE_SCALAR = 0,
124  RTE_MEMBER_COMPARE_AVX2,
125  RTE_MEMBER_COMPARE_NUM
126 };
127 
128 /* sketch update function with different implementations. */
129 typedef void (*sketch_update_fn_t)(const struct rte_member_setsum *ss,
130  const void *key,
131  uint32_t count);
132 
133 /* sketch lookup function with different implementations. */
134 typedef uint64_t (*sketch_lookup_fn_t)(const struct rte_member_setsum *ss,
135  const void *key);
136 
137 /* sketch delete function with different implementations. */
138 typedef void (*sketch_delete_fn_t)(const struct rte_member_setsum *ss,
139  const void *key);
140 
142 struct __rte_cache_aligned rte_member_setsum {
143  enum rte_member_setsum_type type; /* Type of the set summary. */
144  uint32_t key_len; /* Length of key. */
145  uint32_t prim_hash_seed; /* Primary hash function seed. */
146  uint32_t sec_hash_seed; /* Secondary hash function seed. */
147 
148  /* Hash table based. */
149  uint32_t bucket_cnt; /* Number of buckets. */
150  uint32_t bucket_mask; /* Bit mask to get bucket index. */
151  /* For runtime selecting AVX, scalar, etc for signature comparison. */
152  enum rte_member_sig_compare_function sig_cmp_fn;
153  uint8_t cache; /* If it is cache mode for ht based. */
154 
155  /* Vector bloom filter. */
156  uint32_t num_set; /* Number of set (bf) in vbf. */
157  uint32_t bits; /* Number of bits in each bf. */
158  uint32_t bit_mask; /* Bit mask to get bit location in bf. */
159  uint32_t num_hashes; /* Number of hash values to index bf. */
160 
161  /* Parameters for sketch */
162  float error_rate;
163  float sample_rate;
164  uint32_t num_col;
165  uint32_t num_row;
166  int always_bounded;
167  double converge_thresh;
168  uint32_t topk;
169  uint32_t count_byte;
170  uint64_t *hash_seeds;
171  sketch_update_fn_t sketch_update; /* Pointer to the sketch update function */
172  sketch_lookup_fn_t sketch_lookup; /* Pointer to the sketch lookup function */
173  sketch_delete_fn_t sketch_delete; /* Pointer to the sketch delete function */
174 
175  void *runtime_var;
176  uint32_t mul_shift; /* vbf internal variable used during bit test. */
177  uint32_t div_shift; /* vbf internal variable used during bit test. */
178 
179  void *table; /* This is the handler of hash table or vBF array. */
180 
181 
182  /* Second cache line should start here. */
183  uint32_t socket_id; /* NUMA Socket ID for memory. */
184  char name[RTE_MEMBER_NAMESIZE]; /* Name of this set summary. */
185 #ifdef RTE_ARCH_X86
186  bool use_avx512;
187 #endif
188 };
189 
196  const char *name;
209 
229  uint8_t is_cache;
230 
247  uint32_t num_keys;
248 
253  uint32_t key_len;
254 
264  uint32_t num_set;
265 
286 
296  uint32_t prim_hash_seed;
297 
301  uint32_t sec_hash_seed;
302 
308  float error_rate;
309 
315  float sample_rate;
316 
321  uint32_t top_k;
322 
326  uint32_t extra_flag;
327 
328  int socket_id;
329 };
330 
341 struct rte_member_setsum *
342 rte_member_find_existing(const char *name);
343 
353 struct rte_member_setsum *
354 rte_member_create(const struct rte_member_parameters *params);
355 
369 int
370 rte_member_lookup(const struct rte_member_setsum *setsum, const void *key,
371  member_set_t *set_id);
372 
390 int
391 rte_member_lookup_bulk(const struct rte_member_setsum *setsum,
392  const void **keys, uint32_t num_keys,
393  member_set_t *set_ids);
394 
416 int
417 rte_member_lookup_multi(const struct rte_member_setsum *setsum,
418  const void *key, uint32_t max_match_per_key,
419  member_set_t *set_id);
420 
444 int
445 rte_member_lookup_multi_bulk(const struct rte_member_setsum *setsum,
446  const void **keys, uint32_t num_keys,
447  uint32_t max_match_per_key,
448  uint32_t *match_count,
449  member_set_t *set_ids);
450 
477 int
478 rte_member_add(const struct rte_member_setsum *setsum, const void *key,
479  member_set_t set_id);
480 
493 int
494 rte_member_add_byte_count(const struct rte_member_setsum *setsum,
495  const void *key, uint32_t byte_count);
496 
509 int
510 rte_member_query_count(const struct rte_member_setsum *setsum,
511  const void *key, uint64_t *count);
512 
513 
527 int
528 rte_member_report_heavyhitter(const struct rte_member_setsum *setsum,
529  void **keys, uint64_t *counts);
530 
531 
539 void
540 rte_member_free(struct rte_member_setsum *setsum);
541 
549 void
550 rte_member_reset(const struct rte_member_setsum *setsum);
551 
567 int
568 rte_member_delete(const struct rte_member_setsum *setsum, const void *key,
569  member_set_t set_id);
570 
571 #ifdef __cplusplus
572 }
573 #endif
574 
575 #endif /* _RTE_MEMBER_H_ */
const char * name
Definition: rte_member.h:196
#define RTE_MEMBER_NAMESIZE
Definition: rte_member.h:78
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)
#define __rte_cache_aligned
Definition: rte_common.h:568
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)
int rte_member_add_byte_count(const struct rte_member_setsum *setsum, const void *key, uint32_t byte_count)
uint16_t member_set_t
Definition: rte_member.h:68
int rte_member_report_heavyhitter(const struct rte_member_setsum *setsum, void **keys, uint64_t *counts)
void rte_member_free(struct rte_member_setsum *setsum)
int rte_member_lookup_bulk(const struct rte_member_setsum *setsum, const void **keys, uint32_t num_keys, member_set_t *set_ids)
struct rte_member_setsum * rte_member_find_existing(const char *name)
rte_member_setsum_type
Definition: rte_member.h:114
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)
int rte_member_query_count(const struct rte_member_setsum *setsum, const void *key, uint64_t *count)