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