Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2017 Intel Corporation
3 : : */
4 : :
5 : : #include <stdalign.h>
6 : : #include <stdio.h>
7 : : #include <string.h>
8 : :
9 : : #include <eal_export.h>
10 : : #include <rte_common.h>
11 : : #include <rte_malloc.h>
12 : : #include <rte_log.h>
13 : :
14 : : #include "rte_table_hash.h"
15 : : #include "rte_lru.h"
16 : :
17 : : #include "table_log.h"
18 : :
19 : : #define KEY_SIZE 8
20 : :
21 : : #define KEYS_PER_BUCKET 4
22 : :
23 : : #ifdef RTE_TABLE_STATS_COLLECT
24 : :
25 : : #define RTE_TABLE_HASH_KEY8_STATS_PKTS_IN_ADD(table, val) \
26 : : table->stats.n_pkts_in += val
27 : : #define RTE_TABLE_HASH_KEY8_STATS_PKTS_LOOKUP_MISS(table, val) \
28 : : table->stats.n_pkts_lookup_miss += val
29 : :
30 : : #else
31 : :
32 : : #define RTE_TABLE_HASH_KEY8_STATS_PKTS_IN_ADD(table, val)
33 : : #define RTE_TABLE_HASH_KEY8_STATS_PKTS_LOOKUP_MISS(table, val)
34 : :
35 : : #endif
36 : :
37 : : #ifdef RTE_ARCH_64
38 : : struct rte_bucket_4_8 {
39 : : /* Cache line 0 */
40 : : uint64_t signature;
41 : : uint64_t lru_list;
42 : : struct rte_bucket_4_8 *next;
43 : : uint64_t next_valid;
44 : :
45 : : uint64_t key[4];
46 : :
47 : : /* Cache line 1 */
48 : : uint8_t data[];
49 : : };
50 : : #else
51 : : struct rte_bucket_4_8 {
52 : : /* Cache line 0 */
53 : : uint64_t signature;
54 : : uint64_t lru_list;
55 : : struct rte_bucket_4_8 *next;
56 : : uint32_t pad;
57 : : uint64_t next_valid;
58 : :
59 : : uint64_t key[4];
60 : :
61 : : /* Cache line 1 */
62 : : uint8_t data[];
63 : : };
64 : : #endif
65 : :
66 : : struct rte_table_hash {
67 : : struct rte_table_stats stats;
68 : :
69 : : /* Input parameters */
70 : : uint32_t n_buckets;
71 : : uint32_t key_size;
72 : : uint32_t entry_size;
73 : : uint32_t bucket_size;
74 : : uint32_t key_offset;
75 : : uint64_t key_mask;
76 : : rte_table_hash_op_hash f_hash;
77 : : uint64_t seed;
78 : :
79 : : /* Extendible buckets */
80 : : uint32_t n_buckets_ext;
81 : : uint32_t stack_pos;
82 : : uint32_t *stack;
83 : :
84 : : /* Lookup table */
85 : : alignas(RTE_CACHE_LINE_SIZE) uint8_t memory[];
86 : : };
87 : :
88 : : static int
89 : : keycmp(void *a, void *b, void *b_mask)
90 : : {
91 : : uint64_t *a64 = a, *b64 = b, *b_mask64 = b_mask;
92 : :
93 : 6 : return a64[0] != (b64[0] & b_mask64[0]);
94 : : }
95 : :
96 : : static void
97 : : keycpy(void *dst, void *src, void *src_mask)
98 : : {
99 : : uint64_t *dst64 = dst, *src64 = src, *src_mask64 = src_mask;
100 : :
101 : 6 : dst64[0] = src64[0] & src_mask64[0];
102 : : }
103 : :
104 : : static int
105 : 15 : check_params_create(struct rte_table_hash_params *params)
106 : : {
107 : : /* name */
108 [ - + ]: 15 : if (params->name == NULL) {
109 : 0 : TABLE_LOG(ERR, "%s: name invalid value", __func__);
110 : 0 : return -EINVAL;
111 : : }
112 : :
113 : : /* key_size */
114 [ - + ]: 15 : if (params->key_size != KEY_SIZE) {
115 : 0 : TABLE_LOG(ERR, "%s: key_size invalid value", __func__);
116 : 0 : return -EINVAL;
117 : : }
118 : :
119 : : /* n_keys */
120 [ + + ]: 15 : if (params->n_keys == 0) {
121 : 4 : TABLE_LOG(ERR, "%s: n_keys is zero", __func__);
122 : 4 : return -EINVAL;
123 : : }
124 : :
125 : : /* n_buckets */
126 [ + - ]: 11 : if ((params->n_buckets == 0) ||
127 : : (!rte_is_power_of_2(params->n_buckets))) {
128 : 0 : TABLE_LOG(ERR, "%s: n_buckets invalid value", __func__);
129 : 0 : return -EINVAL;
130 : : }
131 : :
132 : : /* f_hash */
133 [ + + ]: 11 : if (params->f_hash == NULL) {
134 : 4 : TABLE_LOG(ERR, "%s: f_hash function pointer is NULL",
135 : : __func__);
136 : 4 : return -EINVAL;
137 : : }
138 : :
139 : : return 0;
140 : : }
141 : :
142 : : static void *
143 : 7 : rte_table_hash_create_key8_lru(void *params, int socket_id, uint32_t entry_size)
144 : : {
145 : : struct rte_table_hash_params *p = params;
146 : : struct rte_table_hash *f;
147 : : uint64_t bucket_size, total_size;
148 : : uint32_t n_buckets, i;
149 : :
150 : : /* Check input parameters */
151 [ + + ]: 7 : if ((check_params_create(p) != 0) ||
152 : : ((sizeof(struct rte_table_hash) % RTE_CACHE_LINE_SIZE) != 0) ||
153 : : ((sizeof(struct rte_bucket_4_8) % 64) != 0))
154 : : return NULL;
155 : :
156 : : /*
157 : : * Table dimensioning
158 : : *
159 : : * Objective: Pick the number of buckets (n_buckets) so that there a chance
160 : : * to store n_keys keys in the table.
161 : : *
162 : : * Note: Since the buckets do not get extended, it is not possible to
163 : : * guarantee that n_keys keys can be stored in the table at any time. In the
164 : : * worst case scenario when all the n_keys fall into the same bucket, only
165 : : * a maximum of KEYS_PER_BUCKET keys will be stored in the table. This case
166 : : * defeats the purpose of the hash table. It indicates unsuitable f_hash or
167 : : * n_keys to n_buckets ratio.
168 : : *
169 : : * MIN(n_buckets) = (n_keys + KEYS_PER_BUCKET - 1) / KEYS_PER_BUCKET
170 : : */
171 : 3 : n_buckets = rte_align32pow2(
172 : 3 : (p->n_keys + KEYS_PER_BUCKET - 1) / KEYS_PER_BUCKET);
173 : 3 : n_buckets = RTE_MAX(n_buckets, p->n_buckets);
174 : :
175 : : /* Memory allocation */
176 : 3 : bucket_size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct rte_bucket_4_8) +
177 : : KEYS_PER_BUCKET * entry_size);
178 : 3 : total_size = sizeof(struct rte_table_hash) + n_buckets * bucket_size;
179 : :
180 : : if (total_size > SIZE_MAX) {
181 : : TABLE_LOG(ERR, "%s: Cannot allocate %" PRIu64 " bytes"
182 : : " for hash table %s",
183 : : __func__, total_size, p->name);
184 : : return NULL;
185 : : }
186 : :
187 : 3 : f = rte_zmalloc_socket(p->name,
188 : : (size_t)total_size,
189 : : RTE_CACHE_LINE_SIZE,
190 : : socket_id);
191 [ - + ]: 3 : if (f == NULL) {
192 : 0 : TABLE_LOG(ERR, "%s: Cannot allocate %" PRIu64 " bytes"
193 : : " for hash table %s",
194 : : __func__, total_size, p->name);
195 : 0 : return NULL;
196 : : }
197 : :
198 : 3 : TABLE_LOG(INFO, "%s: Hash table %s memory footprint "
199 : : "is %" PRIu64 " bytes",
200 : : __func__, p->name, total_size);
201 : :
202 : : /* Memory initialization */
203 : 3 : f->n_buckets = n_buckets;
204 : 3 : f->key_size = KEY_SIZE;
205 : 3 : f->entry_size = entry_size;
206 : 3 : f->bucket_size = bucket_size;
207 : 3 : f->key_offset = p->key_offset;
208 : 3 : f->f_hash = p->f_hash;
209 : 3 : f->seed = p->seed;
210 : :
211 [ - + ]: 3 : if (p->key_mask != NULL)
212 : 0 : f->key_mask = ((uint64_t *)p->key_mask)[0];
213 : : else
214 : 3 : f->key_mask = 0xFFFFFFFFFFFFFFFFLLU;
215 : :
216 [ + + ]: 67587 : for (i = 0; i < n_buckets; i++) {
217 : : struct rte_bucket_4_8 *bucket;
218 : :
219 : 67584 : bucket = (struct rte_bucket_4_8 *) &f->memory[i *
220 : : f->bucket_size];
221 : 67584 : bucket->lru_list = 0x0000000100020003LLU;
222 : : }
223 : :
224 : : return f;
225 : : }
226 : :
227 : : static int
228 : 4 : rte_table_hash_free_key8_lru(void *table)
229 : : {
230 : : struct rte_table_hash *f = table;
231 : :
232 : : /* Check input parameters */
233 [ + + ]: 4 : if (f == NULL) {
234 : 1 : TABLE_LOG(ERR, "%s: table parameter is NULL", __func__);
235 : 1 : return -EINVAL;
236 : : }
237 : :
238 : 3 : rte_free(f);
239 : 3 : return 0;
240 : : }
241 : :
242 : : static int
243 : 4 : rte_table_hash_entry_add_key8_lru(
244 : : void *table,
245 : : void *key,
246 : : void *entry,
247 : : int *key_found,
248 : : void **entry_ptr)
249 : : {
250 : : struct rte_table_hash *f = table;
251 : : struct rte_bucket_4_8 *bucket;
252 : : uint64_t signature, mask, pos;
253 : : uint32_t bucket_index, i;
254 : :
255 : 4 : signature = f->f_hash(key, &f->key_mask, f->key_size, f->seed);
256 : 4 : bucket_index = signature & (f->n_buckets - 1);
257 : 4 : bucket = (struct rte_bucket_4_8 *)
258 : 4 : &f->memory[bucket_index * f->bucket_size];
259 : :
260 : : /* Key is present in the bucket */
261 [ + + ]: 16 : for (i = 0, mask = 1LLU; i < 4; i++, mask <<= 1) {
262 : 13 : uint64_t bucket_signature = bucket->signature;
263 : : uint64_t *bucket_key = &bucket->key[i];
264 : :
265 [ + + + - ]: 13 : if ((bucket_signature & mask) &&
266 : : (keycmp(bucket_key, key, &f->key_mask) == 0)) {
267 : 1 : uint8_t *bucket_data = &bucket->data[i * f->entry_size];
268 : :
269 : 1 : memcpy(bucket_data, entry, f->entry_size);
270 : 1 : lru_update(bucket, i);
271 : 1 : *key_found = 1;
272 : 1 : *entry_ptr = (void *) bucket_data;
273 : 1 : return 0;
274 : : }
275 : : }
276 : :
277 : : /* Key is not present in the bucket */
278 [ + - ]: 3 : for (i = 0, mask = 1LLU; i < 4; i++, mask <<= 1) {
279 : 3 : uint64_t bucket_signature = bucket->signature;
280 : :
281 [ + - ]: 3 : if ((bucket_signature & mask) == 0) {
282 : 3 : uint8_t *bucket_data = &bucket->data[i * f->entry_size];
283 : :
284 : 3 : bucket->signature |= mask;
285 : : keycpy(&bucket->key[i], key, &f->key_mask);
286 : 3 : memcpy(bucket_data, entry, f->entry_size);
287 : 3 : lru_update(bucket, i);
288 : 3 : *key_found = 0;
289 : 3 : *entry_ptr = (void *) bucket_data;
290 : :
291 : 3 : return 0;
292 : : }
293 : : }
294 : :
295 : : /* Bucket full: replace LRU entry */
296 : 0 : pos = lru_pos(bucket);
297 : : keycpy(&bucket->key[pos], key, &f->key_mask);
298 : 0 : memcpy(&bucket->data[pos * f->entry_size], entry, f->entry_size);
299 : 0 : lru_update(bucket, pos);
300 : 0 : *key_found = 0;
301 : 0 : *entry_ptr = (void *) &bucket->data[pos * f->entry_size];
302 : :
303 : 0 : return 0;
304 : : }
305 : :
306 : : static int
307 : 3 : rte_table_hash_entry_delete_key8_lru(
308 : : void *table,
309 : : void *key,
310 : : int *key_found,
311 : : void *entry)
312 : : {
313 : : struct rte_table_hash *f = table;
314 : : struct rte_bucket_4_8 *bucket;
315 : : uint64_t signature, mask;
316 : : uint32_t bucket_index, i;
317 : :
318 : 3 : signature = f->f_hash(key, &f->key_mask, f->key_size, f->seed);
319 : 3 : bucket_index = signature & (f->n_buckets - 1);
320 : 3 : bucket = (struct rte_bucket_4_8 *)
321 : 3 : &f->memory[bucket_index * f->bucket_size];
322 : :
323 : : /* Key is present in the bucket */
324 [ + + ]: 7 : for (i = 0, mask = 1LLU; i < 4; i++, mask <<= 1) {
325 : 6 : uint64_t bucket_signature = bucket->signature;
326 : : uint64_t *bucket_key = &bucket->key[i];
327 : :
328 [ + + + - ]: 6 : if ((bucket_signature & mask) &&
329 : : (keycmp(bucket_key, key, &f->key_mask) == 0)) {
330 : 2 : uint8_t *bucket_data = &bucket->data[i * f->entry_size];
331 : :
332 : 2 : bucket->signature &= ~mask;
333 : 2 : *key_found = 1;
334 [ - + ]: 2 : if (entry)
335 : 0 : memcpy(entry, bucket_data, f->entry_size);
336 : :
337 : 2 : return 0;
338 : : }
339 : : }
340 : :
341 : : /* Key is not present in the bucket */
342 : 1 : *key_found = 0;
343 : 1 : return 0;
344 : : }
345 : :
346 : : static void *
347 : 8 : rte_table_hash_create_key8_ext(void *params, int socket_id, uint32_t entry_size)
348 : : {
349 : : struct rte_table_hash_params *p = params;
350 : : struct rte_table_hash *f;
351 : : uint64_t bucket_size, stack_size, total_size;
352 : : uint32_t n_buckets_ext, i;
353 : :
354 : : /* Check input parameters */
355 [ + + ]: 8 : if ((check_params_create(p) != 0) ||
356 : : ((sizeof(struct rte_table_hash) % RTE_CACHE_LINE_SIZE) != 0) ||
357 : : ((sizeof(struct rte_bucket_4_8) % 64) != 0))
358 : : return NULL;
359 : :
360 : : /*
361 : : * Table dimensioning
362 : : *
363 : : * Objective: Pick the number of bucket extensions (n_buckets_ext) so that
364 : : * it is guaranteed that n_keys keys can be stored in the table at any time.
365 : : *
366 : : * The worst case scenario takes place when all the n_keys keys fall into
367 : : * the same bucket. Actually, due to the KEYS_PER_BUCKET scheme, the worst
368 : : * case takes place when (n_keys - KEYS_PER_BUCKET + 1) keys fall into the
369 : : * same bucket, while the remaining (KEYS_PER_BUCKET - 1) keys each fall
370 : : * into a different bucket. This case defeats the purpose of the hash table.
371 : : * It indicates unsuitable f_hash or n_keys to n_buckets ratio.
372 : : *
373 : : * n_buckets_ext = n_keys / KEYS_PER_BUCKET + KEYS_PER_BUCKET - 1
374 : : */
375 : 4 : n_buckets_ext = p->n_keys / KEYS_PER_BUCKET + KEYS_PER_BUCKET - 1;
376 : :
377 : : /* Memory allocation */
378 : 4 : bucket_size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct rte_bucket_4_8) +
379 : : KEYS_PER_BUCKET * entry_size);
380 : 4 : stack_size = RTE_CACHE_LINE_ROUNDUP(n_buckets_ext * sizeof(uint32_t));
381 : 4 : total_size = sizeof(struct rte_table_hash) +
382 : 4 : (p->n_buckets + n_buckets_ext) * bucket_size + stack_size;
383 : :
384 : : if (total_size > SIZE_MAX) {
385 : : TABLE_LOG(ERR, "%s: Cannot allocate %" PRIu64 " bytes "
386 : : "for hash table %s",
387 : : __func__, total_size, p->name);
388 : : return NULL;
389 : : }
390 : :
391 : 4 : f = rte_zmalloc_socket(p->name,
392 : : (size_t)total_size,
393 : : RTE_CACHE_LINE_SIZE,
394 : : socket_id);
395 [ - + ]: 4 : if (f == NULL) {
396 : 0 : TABLE_LOG(ERR,
397 : : "%s: Cannot allocate %" PRIu64 " bytes "
398 : : "for hash table %s",
399 : : __func__, total_size, p->name);
400 : 0 : return NULL;
401 : : }
402 : 4 : TABLE_LOG(INFO, "%s: Hash table %s memory footprint "
403 : : "is %" PRIu64 " bytes",
404 : : __func__, p->name, total_size);
405 : :
406 : : /* Memory initialization */
407 : 4 : f->n_buckets = p->n_buckets;
408 : 4 : f->key_size = KEY_SIZE;
409 : 4 : f->entry_size = entry_size;
410 : 4 : f->bucket_size = bucket_size;
411 : 4 : f->key_offset = p->key_offset;
412 : 4 : f->f_hash = p->f_hash;
413 : 4 : f->seed = p->seed;
414 : :
415 : 4 : f->n_buckets_ext = n_buckets_ext;
416 : 4 : f->stack_pos = n_buckets_ext;
417 : 4 : f->stack = (uint32_t *)
418 : 4 : &f->memory[(p->n_buckets + n_buckets_ext) * f->bucket_size];
419 : :
420 [ - + ]: 4 : if (p->key_mask != NULL)
421 : 0 : f->key_mask = ((uint64_t *)p->key_mask)[0];
422 : : else
423 : 4 : f->key_mask = 0xFFFFFFFFFFFFFFFFLLU;
424 : :
425 [ + + ]: 17168 : for (i = 0; i < n_buckets_ext; i++)
426 : 17164 : f->stack[i] = i;
427 : :
428 : : return f;
429 : : }
430 : :
431 : : static int
432 : 4 : rte_table_hash_free_key8_ext(void *table)
433 : : {
434 : : struct rte_table_hash *f = table;
435 : :
436 : : /* Check input parameters */
437 [ + + ]: 4 : if (f == NULL) {
438 : 1 : TABLE_LOG(ERR, "%s: table parameter is NULL", __func__);
439 : 1 : return -EINVAL;
440 : : }
441 : :
442 : 3 : rte_free(f);
443 : 3 : return 0;
444 : : }
445 : :
446 : : static int
447 : 4 : rte_table_hash_entry_add_key8_ext(
448 : : void *table,
449 : : void *key,
450 : : void *entry,
451 : : int *key_found,
452 : : void **entry_ptr)
453 : : {
454 : : struct rte_table_hash *f = table;
455 : : struct rte_bucket_4_8 *bucket0, *bucket, *bucket_prev;
456 : : uint64_t signature;
457 : : uint32_t bucket_index, i;
458 : :
459 : 4 : signature = f->f_hash(key, &f->key_mask, f->key_size, f->seed);
460 : 4 : bucket_index = signature & (f->n_buckets - 1);
461 : 4 : bucket0 = (struct rte_bucket_4_8 *)
462 : 4 : &f->memory[bucket_index * f->bucket_size];
463 : :
464 : : /* Key is present in the bucket */
465 [ + + ]: 7 : for (bucket = bucket0; bucket != NULL; bucket = bucket->next) {
466 : : uint64_t mask;
467 : :
468 [ + + ]: 16 : for (i = 0, mask = 1LLU; i < 4; i++, mask <<= 1) {
469 : 13 : uint64_t bucket_signature = bucket->signature;
470 : : uint64_t *bucket_key = &bucket->key[i];
471 : :
472 [ + + + - ]: 13 : if ((bucket_signature & mask) &&
473 : : (keycmp(bucket_key, key, &f->key_mask) == 0)) {
474 : 1 : uint8_t *bucket_data = &bucket->data[i *
475 : 1 : f->entry_size];
476 : :
477 : 1 : memcpy(bucket_data, entry, f->entry_size);
478 : 1 : *key_found = 1;
479 : 1 : *entry_ptr = (void *) bucket_data;
480 : 1 : return 0;
481 : : }
482 : : }
483 : : }
484 : :
485 : : /* Key is not present in the bucket */
486 : : for (bucket_prev = NULL, bucket = bucket0;
487 [ + - ]: 3 : bucket != NULL; bucket_prev = bucket, bucket = bucket->next) {
488 : : uint64_t mask;
489 : :
490 [ + - ]: 3 : for (i = 0, mask = 1LLU; i < 4; i++, mask <<= 1) {
491 : 3 : uint64_t bucket_signature = bucket->signature;
492 : :
493 [ + - ]: 3 : if ((bucket_signature & mask) == 0) {
494 : 3 : uint8_t *bucket_data = &bucket->data[i *
495 : 3 : f->entry_size];
496 : :
497 : 3 : bucket->signature |= mask;
498 : : keycpy(&bucket->key[i], key, &f->key_mask);
499 : 3 : memcpy(bucket_data, entry, f->entry_size);
500 : 3 : *key_found = 0;
501 : 3 : *entry_ptr = (void *) bucket_data;
502 : :
503 : 3 : return 0;
504 : : }
505 : : }
506 : : }
507 : :
508 : : /* Bucket full: extend bucket */
509 [ # # ]: 0 : if (f->stack_pos > 0) {
510 : 0 : bucket_index = f->stack[--f->stack_pos];
511 : :
512 : 0 : bucket = (struct rte_bucket_4_8 *) &f->memory[(f->n_buckets +
513 : 0 : bucket_index) * f->bucket_size];
514 : 0 : bucket_prev->next = bucket;
515 : 0 : bucket_prev->next_valid = 1;
516 : :
517 : 0 : bucket->signature = 1;
518 : : keycpy(&bucket->key[0], key, &f->key_mask);
519 : 0 : memcpy(&bucket->data[0], entry, f->entry_size);
520 : 0 : *key_found = 0;
521 : 0 : *entry_ptr = (void *) &bucket->data[0];
522 : 0 : return 0;
523 : : }
524 : :
525 : : return -ENOSPC;
526 : : }
527 : :
528 : : static int
529 : 3 : rte_table_hash_entry_delete_key8_ext(
530 : : void *table,
531 : : void *key,
532 : : int *key_found,
533 : : void *entry)
534 : : {
535 : : struct rte_table_hash *f = table;
536 : : struct rte_bucket_4_8 *bucket0, *bucket, *bucket_prev;
537 : : uint64_t signature;
538 : : uint32_t bucket_index, i;
539 : :
540 : 3 : signature = f->f_hash(key, &f->key_mask, f->key_size, f->seed);
541 : 3 : bucket_index = signature & (f->n_buckets - 1);
542 : 3 : bucket0 = (struct rte_bucket_4_8 *)
543 : 3 : &f->memory[bucket_index * f->bucket_size];
544 : :
545 : : /* Key is present in the bucket */
546 [ + + ]: 4 : for (bucket_prev = NULL, bucket = bucket0; bucket != NULL;
547 : 1 : bucket_prev = bucket, bucket = bucket->next) {
548 : : uint64_t mask;
549 : :
550 [ + + ]: 7 : for (i = 0, mask = 1LLU; i < 4; i++, mask <<= 1) {
551 : 6 : uint64_t bucket_signature = bucket->signature;
552 : : uint64_t *bucket_key = &bucket->key[i];
553 : :
554 [ + + + - ]: 6 : if ((bucket_signature & mask) &&
555 : : (keycmp(bucket_key, key, &f->key_mask) == 0)) {
556 : 2 : uint8_t *bucket_data = &bucket->data[i *
557 : 2 : f->entry_size];
558 : :
559 : 2 : bucket->signature &= ~mask;
560 : 2 : *key_found = 1;
561 [ - + ]: 2 : if (entry)
562 : 0 : memcpy(entry, bucket_data,
563 : 0 : f->entry_size);
564 : :
565 [ + - - + ]: 2 : if ((bucket->signature == 0) &&
566 : : (bucket_prev != NULL)) {
567 : 0 : bucket_prev->next = bucket->next;
568 : 0 : bucket_prev->next_valid =
569 : 0 : bucket->next_valid;
570 : :
571 : : memset(bucket, 0,
572 : : sizeof(struct rte_bucket_4_8));
573 : 0 : bucket_index = (((uint8_t *)bucket -
574 : 0 : (uint8_t *)f->memory)/f->bucket_size) - f->n_buckets;
575 : 0 : f->stack[f->stack_pos++] = bucket_index;
576 : : }
577 : :
578 : 2 : return 0;
579 : : }
580 : : }
581 : : }
582 : :
583 : : /* Key is not present in the bucket */
584 : 1 : *key_found = 0;
585 : 1 : return 0;
586 : : }
587 : :
588 : : #define lookup_key8_cmp(key_in, bucket, pos, f) \
589 : : { \
590 : : uint64_t xor[4], signature, k; \
591 : : \
592 : : signature = ~bucket->signature; \
593 : : \
594 : : k = key_in[0] & f->key_mask; \
595 : : xor[0] = (k ^ bucket->key[0]) | (signature & 1); \
596 : : xor[1] = (k ^ bucket->key[1]) | (signature & 2); \
597 : : xor[2] = (k ^ bucket->key[2]) | (signature & 4); \
598 : : xor[3] = (k ^ bucket->key[3]) | (signature & 8); \
599 : : \
600 : : pos = 4; \
601 : : if (xor[0] == 0) \
602 : : pos = 0; \
603 : : if (xor[1] == 0) \
604 : : pos = 1; \
605 : : if (xor[2] == 0) \
606 : : pos = 2; \
607 : : if (xor[3] == 0) \
608 : : pos = 3; \
609 : : }
610 : :
611 : : #define lookup1_stage0(pkt0_index, mbuf0, pkts, pkts_mask, f) \
612 : : { \
613 : : uint64_t pkt_mask; \
614 : : uint32_t key_offset = f->key_offset;\
615 : : \
616 : : pkt0_index = rte_ctz64(pkts_mask); \
617 : : pkt_mask = 1LLU << pkt0_index; \
618 : : pkts_mask &= ~pkt_mask; \
619 : : \
620 : : mbuf0 = pkts[pkt0_index]; \
621 : : rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf0, key_offset)); \
622 : : }
623 : :
624 : : #define lookup1_stage1(mbuf1, bucket1, f) \
625 : : { \
626 : : uint64_t *key; \
627 : : uint64_t signature; \
628 : : uint32_t bucket_index; \
629 : : \
630 : : key = RTE_MBUF_METADATA_UINT64_PTR(mbuf1, f->key_offset);\
631 : : signature = f->f_hash(key, &f->key_mask, KEY_SIZE, f->seed); \
632 : : bucket_index = signature & (f->n_buckets - 1); \
633 : : bucket1 = (struct rte_bucket_4_8 *) \
634 : : &f->memory[bucket_index * f->bucket_size]; \
635 : : rte_prefetch0(bucket1); \
636 : : }
637 : :
638 : : #define lookup1_stage2_lru(pkt2_index, mbuf2, bucket2, \
639 : : pkts_mask_out, entries, f) \
640 : : { \
641 : : void *a; \
642 : : uint64_t pkt_mask; \
643 : : uint64_t *key; \
644 : : uint32_t pos; \
645 : : \
646 : : key = RTE_MBUF_METADATA_UINT64_PTR(mbuf2, f->key_offset);\
647 : : lookup_key8_cmp(key, bucket2, pos, f); \
648 : : \
649 : : pkt_mask = ((bucket2->signature >> pos) & 1LLU) << pkt2_index;\
650 : : pkts_mask_out |= pkt_mask; \
651 : : \
652 : : a = (void *) &bucket2->data[pos * f->entry_size]; \
653 : : rte_prefetch0(a); \
654 : : entries[pkt2_index] = a; \
655 : : lru_update(bucket2, pos); \
656 : : }
657 : :
658 : : #define lookup1_stage2_ext(pkt2_index, mbuf2, bucket2, pkts_mask_out,\
659 : : entries, buckets_mask, buckets, keys, f) \
660 : : { \
661 : : struct rte_bucket_4_8 *bucket_next; \
662 : : void *a; \
663 : : uint64_t pkt_mask, bucket_mask; \
664 : : uint64_t *key; \
665 : : uint32_t pos; \
666 : : \
667 : : key = RTE_MBUF_METADATA_UINT64_PTR(mbuf2, f->key_offset);\
668 : : lookup_key8_cmp(key, bucket2, pos, f); \
669 : : \
670 : : pkt_mask = ((bucket2->signature >> pos) & 1LLU) << pkt2_index;\
671 : : pkts_mask_out |= pkt_mask; \
672 : : \
673 : : a = (void *) &bucket2->data[pos * f->entry_size]; \
674 : : rte_prefetch0(a); \
675 : : entries[pkt2_index] = a; \
676 : : \
677 : : bucket_mask = (~pkt_mask) & (bucket2->next_valid << pkt2_index);\
678 : : buckets_mask |= bucket_mask; \
679 : : bucket_next = bucket2->next; \
680 : : buckets[pkt2_index] = bucket_next; \
681 : : keys[pkt2_index] = key; \
682 : : }
683 : :
684 : : #define lookup_grinder(pkt_index, buckets, keys, pkts_mask_out, entries,\
685 : : buckets_mask, f) \
686 : : { \
687 : : struct rte_bucket_4_8 *bucket, *bucket_next; \
688 : : void *a; \
689 : : uint64_t pkt_mask, bucket_mask; \
690 : : uint64_t *key; \
691 : : uint32_t pos; \
692 : : \
693 : : bucket = buckets[pkt_index]; \
694 : : key = keys[pkt_index]; \
695 : : lookup_key8_cmp(key, bucket, pos, f); \
696 : : \
697 : : pkt_mask = ((bucket->signature >> pos) & 1LLU) << pkt_index;\
698 : : pkts_mask_out |= pkt_mask; \
699 : : \
700 : : a = (void *) &bucket->data[pos * f->entry_size]; \
701 : : rte_prefetch0(a); \
702 : : entries[pkt_index] = a; \
703 : : \
704 : : bucket_mask = (~pkt_mask) & (bucket->next_valid << pkt_index);\
705 : : buckets_mask |= bucket_mask; \
706 : : bucket_next = bucket->next; \
707 : : rte_prefetch0(bucket_next); \
708 : : buckets[pkt_index] = bucket_next; \
709 : : keys[pkt_index] = key; \
710 : : }
711 : :
712 : : #define lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01,\
713 : : pkts, pkts_mask, f) \
714 : : { \
715 : : uint64_t pkt00_mask, pkt01_mask; \
716 : : uint32_t key_offset = f->key_offset; \
717 : : \
718 : : pkt00_index = rte_ctz64(pkts_mask); \
719 : : pkt00_mask = 1LLU << pkt00_index; \
720 : : pkts_mask &= ~pkt00_mask; \
721 : : \
722 : : mbuf00 = pkts[pkt00_index]; \
723 : : rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf00, key_offset));\
724 : : \
725 : : pkt01_index = rte_ctz64(pkts_mask); \
726 : : pkt01_mask = 1LLU << pkt01_index; \
727 : : pkts_mask &= ~pkt01_mask; \
728 : : \
729 : : mbuf01 = pkts[pkt01_index]; \
730 : : rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf01, key_offset));\
731 : : }
732 : :
733 : : #define lookup2_stage0_with_odd_support(pkt00_index, pkt01_index,\
734 : : mbuf00, mbuf01, pkts, pkts_mask, f) \
735 : : { \
736 : : uint64_t pkt00_mask, pkt01_mask; \
737 : : uint32_t key_offset = f->key_offset; \
738 : : \
739 : : pkt00_index = rte_ctz64(pkts_mask); \
740 : : pkt00_mask = 1LLU << pkt00_index; \
741 : : pkts_mask &= ~pkt00_mask; \
742 : : \
743 : : mbuf00 = pkts[pkt00_index]; \
744 : : rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf00, key_offset));\
745 : : \
746 : : pkt01_index = rte_ctz64(pkts_mask); \
747 : : if (pkts_mask == 0) \
748 : : pkt01_index = pkt00_index; \
749 : : \
750 : : pkt01_mask = 1LLU << pkt01_index; \
751 : : pkts_mask &= ~pkt01_mask; \
752 : : \
753 : : mbuf01 = pkts[pkt01_index]; \
754 : : rte_prefetch0(RTE_MBUF_METADATA_UINT8_PTR(mbuf01, key_offset));\
755 : : }
756 : :
757 : : #define lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f)\
758 : : { \
759 : : uint64_t *key10, *key11; \
760 : : uint64_t signature10, signature11; \
761 : : uint32_t bucket10_index, bucket11_index; \
762 : : rte_table_hash_op_hash f_hash = f->f_hash; \
763 : : uint64_t seed = f->seed; \
764 : : uint32_t key_offset = f->key_offset; \
765 : : \
766 : : key10 = RTE_MBUF_METADATA_UINT64_PTR(mbuf10, key_offset);\
767 : : key11 = RTE_MBUF_METADATA_UINT64_PTR(mbuf11, key_offset);\
768 : : \
769 : : signature10 = f_hash(key10, &f->key_mask, KEY_SIZE, seed); \
770 : : bucket10_index = signature10 & (f->n_buckets - 1); \
771 : : bucket10 = (struct rte_bucket_4_8 *) \
772 : : &f->memory[bucket10_index * f->bucket_size]; \
773 : : rte_prefetch0(bucket10); \
774 : : \
775 : : signature11 = f_hash(key11, &f->key_mask, KEY_SIZE, seed); \
776 : : bucket11_index = signature11 & (f->n_buckets - 1); \
777 : : bucket11 = (struct rte_bucket_4_8 *) \
778 : : &f->memory[bucket11_index * f->bucket_size]; \
779 : : rte_prefetch0(bucket11); \
780 : : }
781 : :
782 : : #define lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,\
783 : : bucket20, bucket21, pkts_mask_out, entries, f) \
784 : : { \
785 : : void *a20, *a21; \
786 : : uint64_t pkt20_mask, pkt21_mask; \
787 : : uint64_t *key20, *key21; \
788 : : uint32_t pos20, pos21; \
789 : : \
790 : : key20 = RTE_MBUF_METADATA_UINT64_PTR(mbuf20, f->key_offset);\
791 : : key21 = RTE_MBUF_METADATA_UINT64_PTR(mbuf21, f->key_offset);\
792 : : \
793 : : lookup_key8_cmp(key20, bucket20, pos20, f); \
794 : : lookup_key8_cmp(key21, bucket21, pos21, f); \
795 : : \
796 : : pkt20_mask = ((bucket20->signature >> pos20) & 1LLU) << pkt20_index;\
797 : : pkt21_mask = ((bucket21->signature >> pos21) & 1LLU) << pkt21_index;\
798 : : pkts_mask_out |= pkt20_mask | pkt21_mask; \
799 : : \
800 : : a20 = (void *) &bucket20->data[pos20 * f->entry_size]; \
801 : : a21 = (void *) &bucket21->data[pos21 * f->entry_size]; \
802 : : rte_prefetch0(a20); \
803 : : rte_prefetch0(a21); \
804 : : entries[pkt20_index] = a20; \
805 : : entries[pkt21_index] = a21; \
806 : : lru_update(bucket20, pos20); \
807 : : lru_update(bucket21, pos21); \
808 : : }
809 : :
810 : : #define lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21, bucket20, \
811 : : bucket21, pkts_mask_out, entries, buckets_mask, buckets, keys, f)\
812 : : { \
813 : : struct rte_bucket_4_8 *bucket20_next, *bucket21_next; \
814 : : void *a20, *a21; \
815 : : uint64_t pkt20_mask, pkt21_mask, bucket20_mask, bucket21_mask;\
816 : : uint64_t *key20, *key21; \
817 : : uint32_t pos20, pos21; \
818 : : \
819 : : key20 = RTE_MBUF_METADATA_UINT64_PTR(mbuf20, f->key_offset);\
820 : : key21 = RTE_MBUF_METADATA_UINT64_PTR(mbuf21, f->key_offset);\
821 : : \
822 : : lookup_key8_cmp(key20, bucket20, pos20, f); \
823 : : lookup_key8_cmp(key21, bucket21, pos21, f); \
824 : : \
825 : : pkt20_mask = ((bucket20->signature >> pos20) & 1LLU) << pkt20_index;\
826 : : pkt21_mask = ((bucket21->signature >> pos21) & 1LLU) << pkt21_index;\
827 : : pkts_mask_out |= pkt20_mask | pkt21_mask; \
828 : : \
829 : : a20 = (void *) &bucket20->data[pos20 * f->entry_size]; \
830 : : a21 = (void *) &bucket21->data[pos21 * f->entry_size]; \
831 : : rte_prefetch0(a20); \
832 : : rte_prefetch0(a21); \
833 : : entries[pkt20_index] = a20; \
834 : : entries[pkt21_index] = a21; \
835 : : \
836 : : bucket20_mask = (~pkt20_mask) & (bucket20->next_valid << pkt20_index);\
837 : : bucket21_mask = (~pkt21_mask) & (bucket21->next_valid << pkt21_index);\
838 : : buckets_mask |= bucket20_mask | bucket21_mask; \
839 : : bucket20_next = bucket20->next; \
840 : : bucket21_next = bucket21->next; \
841 : : buckets[pkt20_index] = bucket20_next; \
842 : : buckets[pkt21_index] = bucket21_next; \
843 : : keys[pkt20_index] = key20; \
844 : : keys[pkt21_index] = key21; \
845 : : }
846 : :
847 : : static int
848 [ + + ]: 7 : rte_table_hash_lookup_key8_lru(
849 : : void *table,
850 : : struct rte_mbuf **pkts,
851 : : uint64_t pkts_mask,
852 : : uint64_t *lookup_hit_mask,
853 : : void **entries)
854 : : {
855 : : struct rte_table_hash *f = (struct rte_table_hash *) table;
856 : : struct rte_bucket_4_8 *bucket10, *bucket11, *bucket20, *bucket21;
857 : : struct rte_mbuf *mbuf00, *mbuf01, *mbuf10, *mbuf11, *mbuf20, *mbuf21;
858 : : uint32_t pkt00_index, pkt01_index, pkt10_index;
859 : : uint32_t pkt11_index, pkt20_index, pkt21_index;
860 : : uint64_t pkts_mask_out = 0;
861 : :
862 : : __rte_unused uint32_t n_pkts_in = rte_popcount64(pkts_mask);
863 : : RTE_TABLE_HASH_KEY8_STATS_PKTS_IN_ADD(f, n_pkts_in);
864 : :
865 : : /* Cannot run the pipeline with less than 5 packets */
866 [ + + ]: 7 : if (rte_popcount64(pkts_mask) < 5) {
867 [ + + ]: 4 : for ( ; pkts_mask; ) {
868 : : struct rte_bucket_4_8 *bucket;
869 : : struct rte_mbuf *mbuf;
870 : : uint32_t pkt_index;
871 : :
872 : 2 : lookup1_stage0(pkt_index, mbuf, pkts, pkts_mask, f);
873 : 2 : lookup1_stage1(mbuf, bucket, f);
874 [ + + - + : 3 : lookup1_stage2_lru(pkt_index, mbuf, bucket,
- + - + ]
875 : : pkts_mask_out, entries, f);
876 : : }
877 : :
878 : 2 : *lookup_hit_mask = pkts_mask_out;
879 : : RTE_TABLE_HASH_KEY8_STATS_PKTS_LOOKUP_MISS(f, n_pkts_in - rte_popcount64(pkts_mask_out));
880 : 2 : return 0;
881 : : }
882 : :
883 : : /*
884 : : * Pipeline fill
885 : : *
886 : : */
887 : : /* Pipeline stage 0 */
888 : 5 : lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
889 : : pkts_mask, f);
890 : :
891 : : /* Pipeline feed */
892 : : mbuf10 = mbuf00;
893 : : mbuf11 = mbuf01;
894 : : pkt10_index = pkt00_index;
895 : : pkt11_index = pkt01_index;
896 : :
897 : : /* Pipeline stage 0 */
898 : 5 : lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
899 : : pkts_mask, f);
900 : :
901 : : /* Pipeline stage 1 */
902 : 5 : lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
903 : :
904 : : /*
905 : : * Pipeline run
906 : : *
907 : : */
908 [ + + ]: 127 : for ( ; pkts_mask; ) {
909 : : /* Pipeline feed */
910 : : bucket20 = bucket10;
911 : : bucket21 = bucket11;
912 : : mbuf20 = mbuf10;
913 : : mbuf21 = mbuf11;
914 : : mbuf10 = mbuf00;
915 : : mbuf11 = mbuf01;
916 : : pkt20_index = pkt10_index;
917 : : pkt21_index = pkt11_index;
918 : : pkt10_index = pkt00_index;
919 : : pkt11_index = pkt01_index;
920 : :
921 : : /* Pipeline stage 0 */
922 [ - + ]: 122 : lookup2_stage0_with_odd_support(pkt00_index, pkt01_index,
923 : : mbuf00, mbuf01, pkts, pkts_mask, f);
924 : :
925 : : /* Pipeline stage 1 */
926 : 122 : lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
927 : :
928 : : /* Pipeline stage 2 */
929 [ + + - + : 391 : lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,
- + - + +
+ - + - +
- + ]
930 : : bucket20, bucket21, pkts_mask_out, entries, f);
931 : : }
932 : :
933 : : /*
934 : : * Pipeline flush
935 : : *
936 : : */
937 : : /* Pipeline feed */
938 : : bucket20 = bucket10;
939 : : bucket21 = bucket11;
940 : : mbuf20 = mbuf10;
941 : : mbuf21 = mbuf11;
942 : : mbuf10 = mbuf00;
943 : : mbuf11 = mbuf01;
944 : : pkt20_index = pkt10_index;
945 : : pkt21_index = pkt11_index;
946 : : pkt10_index = pkt00_index;
947 : : pkt11_index = pkt01_index;
948 : :
949 : : /* Pipeline stage 1 */
950 : 5 : lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
951 : :
952 : : /* Pipeline stage 2 */
953 [ + + - + : 15 : lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,
- + - + +
+ - + - +
- + + + ]
954 : : bucket20, bucket21, pkts_mask_out, entries, f);
955 : :
956 : : /* Pipeline feed */
957 : : bucket20 = bucket10;
958 : : bucket21 = bucket11;
959 : : mbuf20 = mbuf10;
960 : : mbuf21 = mbuf11;
961 : : pkt20_index = pkt10_index;
962 : : pkt21_index = pkt11_index;
963 : :
964 : : /* Pipeline stage 2 */
965 [ + + - + : 15 : lookup2_stage2_lru(pkt20_index, pkt21_index, mbuf20, mbuf21,
- + - + +
+ - + - +
- + ]
966 : : bucket20, bucket21, pkts_mask_out, entries, f);
967 : :
968 : 5 : *lookup_hit_mask = pkts_mask_out;
969 : : RTE_TABLE_HASH_KEY8_STATS_PKTS_LOOKUP_MISS(f, n_pkts_in - rte_popcount64(pkts_mask_out));
970 : 5 : return 0;
971 : : } /* lookup LRU */
972 : :
973 : : static int
974 [ + + ]: 7 : rte_table_hash_lookup_key8_ext(
975 : : void *table,
976 : : struct rte_mbuf **pkts,
977 : : uint64_t pkts_mask,
978 : : uint64_t *lookup_hit_mask,
979 : : void **entries)
980 : : {
981 : : struct rte_table_hash *f = (struct rte_table_hash *) table;
982 : : struct rte_bucket_4_8 *bucket10, *bucket11, *bucket20, *bucket21;
983 : : struct rte_mbuf *mbuf00, *mbuf01, *mbuf10, *mbuf11, *mbuf20, *mbuf21;
984 : : uint32_t pkt00_index, pkt01_index, pkt10_index;
985 : : uint32_t pkt11_index, pkt20_index, pkt21_index;
986 : : uint64_t pkts_mask_out = 0, buckets_mask = 0;
987 : : struct rte_bucket_4_8 *buckets[RTE_PORT_IN_BURST_SIZE_MAX];
988 : : uint64_t *keys[RTE_PORT_IN_BURST_SIZE_MAX];
989 : :
990 : : __rte_unused uint32_t n_pkts_in = rte_popcount64(pkts_mask);
991 : : RTE_TABLE_HASH_KEY8_STATS_PKTS_IN_ADD(f, n_pkts_in);
992 : :
993 : : /* Cannot run the pipeline with less than 5 packets */
994 [ + + ]: 7 : if (rte_popcount64(pkts_mask) < 5) {
995 [ + + ]: 4 : for ( ; pkts_mask; ) {
996 : : struct rte_bucket_4_8 *bucket;
997 : : struct rte_mbuf *mbuf;
998 : : uint32_t pkt_index;
999 : :
1000 : 2 : lookup1_stage0(pkt_index, mbuf, pkts, pkts_mask, f);
1001 : 2 : lookup1_stage1(mbuf, bucket, f);
1002 [ + + - + : 3 : lookup1_stage2_ext(pkt_index, mbuf, bucket,
- + - + ]
1003 : : pkts_mask_out, entries, buckets_mask,
1004 : : buckets, keys, f);
1005 : : }
1006 : :
1007 : 2 : goto grind_next_buckets;
1008 : : }
1009 : :
1010 : : /*
1011 : : * Pipeline fill
1012 : : *
1013 : : */
1014 : : /* Pipeline stage 0 */
1015 : 5 : lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
1016 : : pkts_mask, f);
1017 : :
1018 : : /* Pipeline feed */
1019 : : mbuf10 = mbuf00;
1020 : : mbuf11 = mbuf01;
1021 : : pkt10_index = pkt00_index;
1022 : : pkt11_index = pkt01_index;
1023 : :
1024 : : /* Pipeline stage 0 */
1025 : 5 : lookup2_stage0(pkt00_index, pkt01_index, mbuf00, mbuf01, pkts,
1026 : : pkts_mask, f);
1027 : :
1028 : : /* Pipeline stage 1 */
1029 : 5 : lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
1030 : :
1031 : : /*
1032 : : * Pipeline run
1033 : : *
1034 : : */
1035 [ + + ]: 127 : for ( ; pkts_mask; ) {
1036 : : /* Pipeline feed */
1037 : : bucket20 = bucket10;
1038 : : bucket21 = bucket11;
1039 : : mbuf20 = mbuf10;
1040 : : mbuf21 = mbuf11;
1041 : : mbuf10 = mbuf00;
1042 : : mbuf11 = mbuf01;
1043 : : pkt20_index = pkt10_index;
1044 : : pkt21_index = pkt11_index;
1045 : : pkt10_index = pkt00_index;
1046 : : pkt11_index = pkt01_index;
1047 : :
1048 : : /* Pipeline stage 0 */
1049 [ - + ]: 122 : lookup2_stage0_with_odd_support(pkt00_index, pkt01_index,
1050 : : mbuf00, mbuf01, pkts, pkts_mask, f);
1051 : :
1052 : : /* Pipeline stage 1 */
1053 : 122 : lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
1054 : :
1055 : : /* Pipeline stage 2 */
1056 [ + + - + : 391 : lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21,
- + - + +
+ - + - +
- + ]
1057 : : bucket20, bucket21, pkts_mask_out, entries,
1058 : : buckets_mask, buckets, keys, f);
1059 : : }
1060 : :
1061 : : /*
1062 : : * Pipeline flush
1063 : : *
1064 : : */
1065 : : /* Pipeline feed */
1066 : : bucket20 = bucket10;
1067 : : bucket21 = bucket11;
1068 : : mbuf20 = mbuf10;
1069 : : mbuf21 = mbuf11;
1070 : : mbuf10 = mbuf00;
1071 : : mbuf11 = mbuf01;
1072 : : pkt20_index = pkt10_index;
1073 : : pkt21_index = pkt11_index;
1074 : : pkt10_index = pkt00_index;
1075 : : pkt11_index = pkt01_index;
1076 : :
1077 : : /* Pipeline stage 1 */
1078 : 5 : lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f);
1079 : :
1080 : : /* Pipeline stage 2 */
1081 [ + + - + : 10 : lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21,
- + - + +
+ - + - +
- + ]
1082 : : bucket20, bucket21, pkts_mask_out, entries,
1083 : : buckets_mask, buckets, keys, f);
1084 : :
1085 : : /* Pipeline feed */
1086 : : bucket20 = bucket10;
1087 : : bucket21 = bucket11;
1088 : : mbuf20 = mbuf10;
1089 : : mbuf21 = mbuf11;
1090 : : pkt20_index = pkt10_index;
1091 : : pkt21_index = pkt11_index;
1092 : :
1093 : : /* Pipeline stage 2 */
1094 [ + + - + : 15 : lookup2_stage2_ext(pkt20_index, pkt21_index, mbuf20, mbuf21,
- + - + +
+ - + - +
- + ]
1095 : : bucket20, bucket21, pkts_mask_out, entries,
1096 : : buckets_mask, buckets, keys, f);
1097 : :
1098 : : grind_next_buckets:
1099 : : /* Grind next buckets */
1100 [ - + ]: 7 : for ( ; buckets_mask; ) {
1101 : : uint64_t buckets_mask_next = 0;
1102 : :
1103 [ # # ]: 0 : for ( ; buckets_mask; ) {
1104 : : uint64_t pkt_mask;
1105 : : uint32_t pkt_index;
1106 : :
1107 : : pkt_index = rte_ctz64(buckets_mask);
1108 : 0 : pkt_mask = 1LLU << pkt_index;
1109 : 0 : buckets_mask &= ~pkt_mask;
1110 : :
1111 [ # # # # : 0 : lookup_grinder(pkt_index, buckets, keys, pkts_mask_out,
# # # # ]
1112 : : entries, buckets_mask_next, f);
1113 : : }
1114 : :
1115 : : buckets_mask = buckets_mask_next;
1116 : : }
1117 : :
1118 : 7 : *lookup_hit_mask = pkts_mask_out;
1119 : : RTE_TABLE_HASH_KEY8_STATS_PKTS_LOOKUP_MISS(f, n_pkts_in - rte_popcount64(pkts_mask_out));
1120 : 7 : return 0;
1121 : : } /* lookup EXT */
1122 : :
1123 : : static int
1124 : 0 : rte_table_hash_key8_stats_read(void *table, struct rte_table_stats *stats, int clear)
1125 : : {
1126 : : struct rte_table_hash *t = table;
1127 : :
1128 [ # # ]: 0 : if (stats != NULL)
1129 : 0 : memcpy(stats, &t->stats, sizeof(t->stats));
1130 : :
1131 [ # # ]: 0 : if (clear)
1132 : 0 : memset(&t->stats, 0, sizeof(t->stats));
1133 : :
1134 : 0 : return 0;
1135 : : }
1136 : :
1137 : : RTE_EXPORT_SYMBOL(rte_table_hash_key8_lru_ops)
1138 : : struct rte_table_ops rte_table_hash_key8_lru_ops = {
1139 : : .f_create = rte_table_hash_create_key8_lru,
1140 : : .f_free = rte_table_hash_free_key8_lru,
1141 : : .f_add = rte_table_hash_entry_add_key8_lru,
1142 : : .f_delete = rte_table_hash_entry_delete_key8_lru,
1143 : : .f_add_bulk = NULL,
1144 : : .f_delete_bulk = NULL,
1145 : : .f_lookup = rte_table_hash_lookup_key8_lru,
1146 : : .f_stats = rte_table_hash_key8_stats_read,
1147 : : };
1148 : :
1149 : : RTE_EXPORT_SYMBOL(rte_table_hash_key8_ext_ops)
1150 : : struct rte_table_ops rte_table_hash_key8_ext_ops = {
1151 : : .f_create = rte_table_hash_create_key8_ext,
1152 : : .f_free = rte_table_hash_free_key8_ext,
1153 : : .f_add = rte_table_hash_entry_add_key8_ext,
1154 : : .f_delete = rte_table_hash_entry_delete_key8_ext,
1155 : : .f_add_bulk = NULL,
1156 : : .f_delete_bulk = NULL,
1157 : : .f_lookup = rte_table_hash_lookup_key8_ext,
1158 : : .f_stats = rte_table_hash_key8_stats_read,
1159 : : };
|