LCOV - code coverage report
Current view: top level - lib/table - rte_table_hash_key32.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 220 276 79.7 %
Date: 2025-05-01 17:49:45 Functions: 11 12 91.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 162 258 62.8 %

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

Generated by: LCOV version 1.14