table: rework 16-byte key hash tables

Rework for the 16-byte key hash tables (both the extendible
bucket and LRU)to use the mask-based hash function and the
unified parameter structure.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
This commit is contained in:
Cristian Dumitrescu 2017-10-18 16:03:47 +01:00
parent 36842d0aee
commit fc972a1305
6 changed files with 235 additions and 276 deletions

View File

@ -492,18 +492,6 @@ static void *pipeline_fc_init(struct pipeline_params *params,
/* Tables */
p->n_tables = 1;
{
struct rte_table_hash_key16_ext_params
table_hash_key16_params = {
.n_entries = p_fc->n_flows,
.n_entries_ext = p_fc->n_flows,
.signature_offset = p_fc->hash_offset,
.key_offset = p_fc->key_offset,
.f_hash = hash_func[(p_fc->key_size / 8) - 1],
.key_mask = (p_fc->key_mask_present) ?
p_fc->key_mask : NULL,
.seed = 0,
};
struct rte_table_hash_params table_hash_params = {
.name = p->name,
.key_size = p_fc->key_size,
@ -536,7 +524,7 @@ static void *pipeline_fc_init(struct pipeline_params *params,
case 16:
table_params.ops = &rte_table_hash_key16_ext_ops;
table_params.arg_create = &table_hash_key16_params;
table_params.arg_create = &table_hash_params;
break;
default:

View File

@ -143,62 +143,8 @@ extern struct rte_table_ops rte_table_hash_key8_lru_ops;
extern struct rte_table_ops rte_table_hash_key8_ext_ops;
/**
* 16-byte key hash tables
*
*/
/** LRU hash table parameters */
struct rte_table_hash_key16_lru_params {
/** Maximum number of entries (and keys) in the table */
uint32_t n_entries;
/** Hash function */
rte_table_hash_op_hash_nomask f_hash;
/** Seed for the hash function */
uint64_t seed;
/** Byte offset within packet meta-data where the 4-byte key signature
is located. Valid for pre-computed key signature tables, ignored for
do-sig tables. */
uint32_t signature_offset;
/** Byte offset within packet meta-data where the key is located */
uint32_t key_offset;
/** Bit-mask to be AND-ed to the key on lookup */
uint8_t *key_mask;
};
extern struct rte_table_ops rte_table_hash_key16_lru_ops;
/** Extendible bucket hash table parameters */
struct rte_table_hash_key16_ext_params {
/** Maximum number of entries (and keys) in the table */
uint32_t n_entries;
/** Number of entries (and keys) for hash table bucket extensions. Each
bucket is extended in increments of 4 keys. */
uint32_t n_entries_ext;
/** Hash function */
rte_table_hash_op_hash_nomask f_hash;
/** Seed for the hash function */
uint64_t seed;
/** Byte offset within packet meta-data where the 4-byte key signature
is located. Valid for pre-computed key signature tables, ignored for
do-sig tables. */
uint32_t signature_offset;
/** Byte offset within packet meta-data where the key is located */
uint32_t key_offset;
/** Bit-mask to be AND-ed to the key on lookup */
uint8_t *key_mask;
};
extern struct rte_table_ops rte_table_hash_key16_ext_ops;
/**

View File

@ -42,7 +42,9 @@
#include "rte_table_hash.h"
#include "rte_lru.h"
#define RTE_TABLE_HASH_KEY_SIZE 16
#define KEY_SIZE 16
#define KEYS_PER_BUCKET 4
#define RTE_BUCKET_ENTRY_VALID 0x1LLU
@ -79,14 +81,12 @@ struct rte_table_hash {
/* Input parameters */
uint32_t n_buckets;
uint32_t n_entries_per_bucket;
uint32_t key_size;
uint32_t entry_size;
uint32_t bucket_size;
uint32_t signature_offset;
uint32_t key_offset;
uint64_t key_mask[2];
rte_table_hash_op_hash_nomask f_hash;
rte_table_hash_op_hash f_hash;
uint64_t seed;
/* Extendible buckets */
@ -99,17 +99,55 @@ struct rte_table_hash {
};
static int
check_params_create_lru(struct rte_table_hash_key16_lru_params *params) {
/* n_entries */
if (params->n_entries == 0) {
RTE_LOG(ERR, TABLE, "%s: n_entries is zero\n", __func__);
keycmp(void *a, void *b, void *b_mask)
{
uint64_t *a64 = a, *b64 = b, *b_mask64 = b_mask;
return (a64[0] != (b64[0] & b_mask64[0])) ||
(a64[1] != (b64[1] & b_mask64[1]));
}
static void
keycpy(void *dst, void *src, void *src_mask)
{
uint64_t *dst64 = dst, *src64 = src, *src_mask64 = src_mask;
dst64[0] = src64[0] & src_mask64[0];
dst64[1] = src64[1] & src_mask64[1];
}
static int
check_params_create(struct rte_table_hash_params *params)
{
/* name */
if (params->name == NULL) {
RTE_LOG(ERR, TABLE, "%s: name invalid value\n", __func__);
return -EINVAL;
}
/* key_size */
if (params->key_size != KEY_SIZE) {
RTE_LOG(ERR, TABLE, "%s: key_size invalid value\n", __func__);
return -EINVAL;
}
/* n_keys */
if (params->n_keys == 0) {
RTE_LOG(ERR, TABLE, "%s: n_keys is zero\n", __func__);
return -EINVAL;
}
/* n_buckets */
if ((params->n_buckets == 0) ||
(!rte_is_power_of_2(params->n_buckets))) {
RTE_LOG(ERR, TABLE, "%s: n_buckets invalid value\n", __func__);
return -EINVAL;
}
/* f_hash */
if (params->f_hash == NULL) {
RTE_LOG(ERR, TABLE,
"%s: f_hash function pointer is NULL\n", __func__);
RTE_LOG(ERR, TABLE, "%s: f_hash function pointer is NULL\n",
__func__);
return -EINVAL;
}
@ -121,46 +159,67 @@ rte_table_hash_create_key16_lru(void *params,
int socket_id,
uint32_t entry_size)
{
struct rte_table_hash_key16_lru_params *p =
(struct rte_table_hash_key16_lru_params *) params;
struct rte_table_hash_params *p = params;
struct rte_table_hash *f;
uint32_t n_buckets, n_entries_per_bucket,
key_size, bucket_size_cl, total_size, i;
uint64_t bucket_size, total_size;
uint32_t n_buckets, i;
/* Check input parameters */
if ((check_params_create_lru(p) != 0) ||
if ((check_params_create(p) != 0) ||
((sizeof(struct rte_table_hash) % RTE_CACHE_LINE_SIZE) != 0) ||
((sizeof(struct rte_bucket_4_16) % 64) != 0))
return NULL;
n_entries_per_bucket = 4;
key_size = 16;
/*
* Table dimensioning
*
* Objective: Pick the number of buckets (n_buckets) so that there a chance
* to store n_keys keys in the table.
*
* Note: Since the buckets do not get extended, it is not possible to
* guarantee that n_keys keys can be stored in the table at any time. In the
* worst case scenario when all the n_keys fall into the same bucket, only
* a maximum of KEYS_PER_BUCKET keys will be stored in the table. This case
* defeats the purpose of the hash table. It indicates unsuitable f_hash or
* n_keys to n_buckets ratio.
*
* MIN(n_buckets) = (n_keys + KEYS_PER_BUCKET - 1) / KEYS_PER_BUCKET
*/
n_buckets = rte_align32pow2(
(p->n_keys + KEYS_PER_BUCKET - 1) / KEYS_PER_BUCKET);
n_buckets = RTE_MAX(n_buckets, p->n_buckets);
/* Memory allocation */
n_buckets = rte_align32pow2((p->n_entries + n_entries_per_bucket - 1) /
n_entries_per_bucket);
bucket_size_cl = (sizeof(struct rte_bucket_4_16) + n_entries_per_bucket
* entry_size + RTE_CACHE_LINE_SIZE - 1) / RTE_CACHE_LINE_SIZE;
total_size = sizeof(struct rte_table_hash) + n_buckets *
bucket_size_cl * RTE_CACHE_LINE_SIZE;
bucket_size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct rte_bucket_4_16) +
KEYS_PER_BUCKET * entry_size);
total_size = sizeof(struct rte_table_hash) + n_buckets * bucket_size;
f = rte_zmalloc_socket("TABLE", total_size, RTE_CACHE_LINE_SIZE, socket_id);
if (f == NULL) {
RTE_LOG(ERR, TABLE,
"%s: Cannot allocate %u bytes for hash table\n",
__func__, total_size);
if (total_size > SIZE_MAX) {
RTE_LOG(ERR, TABLE, "%s: Cannot allocate %" PRIu64 " bytes "
"for hash table %s\n",
__func__, total_size, p->name);
return NULL;
}
RTE_LOG(INFO, TABLE,
"%s: Hash table memory footprint is %u bytes\n",
__func__, total_size);
f = rte_zmalloc_socket(p->name,
(size_t)total_size,
RTE_CACHE_LINE_SIZE,
socket_id);
if (f == NULL) {
RTE_LOG(ERR, TABLE, "%s: Cannot allocate %" PRIu64 " bytes "
"for hash table %s\n",
__func__, total_size, p->name);
return NULL;
}
RTE_LOG(INFO, TABLE, "%s: Hash table %s memory footprint "
"is %" PRIu64 " bytes\n",
__func__, p->name, total_size);
/* Memory initialization */
f->n_buckets = n_buckets;
f->n_entries_per_bucket = n_entries_per_bucket;
f->key_size = key_size;
f->key_size = KEY_SIZE;
f->entry_size = entry_size;
f->bucket_size = bucket_size_cl * RTE_CACHE_LINE_SIZE;
f->signature_offset = p->signature_offset;
f->bucket_size = bucket_size;
f->key_offset = p->key_offset;
f->f_hash = p->f_hash;
f->seed = p->seed;
@ -212,19 +271,19 @@ rte_table_hash_entry_add_key16_lru(
uint64_t signature, pos;
uint32_t bucket_index, i;
signature = f->f_hash(key, f->key_size, f->seed);
signature = f->f_hash(key, f->key_mask, f->key_size, f->seed);
bucket_index = signature & (f->n_buckets - 1);
bucket = (struct rte_bucket_4_16 *)
&f->memory[bucket_index * f->bucket_size];
&f->memory[bucket_index * f->bucket_size];
signature |= RTE_BUCKET_ENTRY_VALID;
/* Key is present in the bucket */
for (i = 0; i < 4; i++) {
uint64_t bucket_signature = bucket->signature[i];
uint8_t *bucket_key = (uint8_t *) bucket->key[i];
uint8_t *bucket_key = (uint8_t *) &bucket->key[i];
if ((bucket_signature == signature) &&
(memcmp(key, bucket_key, f->key_size) == 0)) {
(keycmp(bucket_key, key, f->key_mask) == 0)) {
uint8_t *bucket_data = &bucket->data[i * f->entry_size];
memcpy(bucket_data, entry, f->entry_size);
@ -238,13 +297,13 @@ rte_table_hash_entry_add_key16_lru(
/* Key is not present in the bucket */
for (i = 0; i < 4; i++) {
uint64_t bucket_signature = bucket->signature[i];
uint8_t *bucket_key = (uint8_t *) bucket->key[i];
uint8_t *bucket_key = (uint8_t *) &bucket->key[i];
if (bucket_signature == 0) {
uint8_t *bucket_data = &bucket->data[i * f->entry_size];
bucket->signature[i] = signature;
memcpy(bucket_key, key, f->key_size);
keycpy(bucket_key, key, f->key_mask);
memcpy(bucket_data, entry, f->entry_size);
lru_update(bucket, i);
*key_found = 0;
@ -257,7 +316,7 @@ rte_table_hash_entry_add_key16_lru(
/* Bucket full: replace LRU entry */
pos = lru_pos(bucket);
bucket->signature[pos] = signature;
memcpy(bucket->key[pos], key, f->key_size);
keycpy(&bucket->key[pos], key, f->key_mask);
memcpy(&bucket->data[pos * f->entry_size], entry, f->entry_size);
lru_update(bucket, pos);
*key_found = 0;
@ -278,19 +337,19 @@ rte_table_hash_entry_delete_key16_lru(
uint64_t signature;
uint32_t bucket_index, i;
signature = f->f_hash(key, f->key_size, f->seed);
signature = f->f_hash(key, f->key_mask, f->key_size, f->seed);
bucket_index = signature & (f->n_buckets - 1);
bucket = (struct rte_bucket_4_16 *)
&f->memory[bucket_index * f->bucket_size];
&f->memory[bucket_index * f->bucket_size];
signature |= RTE_BUCKET_ENTRY_VALID;
/* Key is present in the bucket */
for (i = 0; i < 4; i++) {
uint64_t bucket_signature = bucket->signature[i];
uint8_t *bucket_key = (uint8_t *) bucket->key[i];
uint8_t *bucket_key = (uint8_t *) &bucket->key[i];
if ((bucket_signature == signature) &&
(memcmp(key, bucket_key, f->key_size) == 0)) {
(keycmp(bucket_key, key, f->key_mask) == 0)) {
uint8_t *bucket_data = &bucket->data[i * f->entry_size];
bucket->signature[i] = 0;
@ -306,81 +365,71 @@ rte_table_hash_entry_delete_key16_lru(
return 0;
}
static int
check_params_create_ext(struct rte_table_hash_key16_ext_params *params) {
/* n_entries */
if (params->n_entries == 0) {
RTE_LOG(ERR, TABLE, "%s: n_entries is zero\n", __func__);
return -EINVAL;
}
/* n_entries_ext */
if (params->n_entries_ext == 0) {
RTE_LOG(ERR, TABLE, "%s: n_entries_ext is zero\n", __func__);
return -EINVAL;
}
/* f_hash */
if (params->f_hash == NULL) {
RTE_LOG(ERR, TABLE,
"%s: f_hash function pointer is NULL\n", __func__);
return -EINVAL;
}
return 0;
}
static void *
rte_table_hash_create_key16_ext(void *params,
int socket_id,
uint32_t entry_size)
{
struct rte_table_hash_key16_ext_params *p =
(struct rte_table_hash_key16_ext_params *) params;
struct rte_table_hash_params *p = params;
struct rte_table_hash *f;
uint32_t n_buckets, n_buckets_ext, n_entries_per_bucket, key_size,
bucket_size_cl, stack_size_cl, total_size, i;
uint64_t bucket_size, stack_size, total_size;
uint32_t n_buckets_ext, i;
/* Check input parameters */
if ((check_params_create_ext(p) != 0) ||
if ((check_params_create(p) != 0) ||
((sizeof(struct rte_table_hash) % RTE_CACHE_LINE_SIZE) != 0) ||
((sizeof(struct rte_bucket_4_16) % 64) != 0))
return NULL;
n_entries_per_bucket = 4;
key_size = 16;
/*
* Table dimensioning
*
* Objective: Pick the number of bucket extensions (n_buckets_ext) so that
* it is guaranteed that n_keys keys can be stored in the table at any time.
*
* The worst case scenario takes place when all the n_keys keys fall into
* the same bucket. Actually, due to the KEYS_PER_BUCKET scheme, the worst
* case takes place when (n_keys - KEYS_PER_BUCKET + 1) keys fall into the
* same bucket, while the remaining (KEYS_PER_BUCKET - 1) keys each fall
* into a different bucket. This case defeats the purpose of the hash table.
* It indicates unsuitable f_hash or n_keys to n_buckets ratio.
*
* n_buckets_ext = n_keys / KEYS_PER_BUCKET + KEYS_PER_BUCKET - 1
*/
n_buckets_ext = p->n_keys / KEYS_PER_BUCKET + KEYS_PER_BUCKET - 1;
/* Memory allocation */
n_buckets = rte_align32pow2((p->n_entries + n_entries_per_bucket - 1) /
n_entries_per_bucket);
n_buckets_ext = (p->n_entries_ext + n_entries_per_bucket - 1) /
n_entries_per_bucket;
bucket_size_cl = (sizeof(struct rte_bucket_4_16) + n_entries_per_bucket
* entry_size + RTE_CACHE_LINE_SIZE - 1) / RTE_CACHE_LINE_SIZE;
stack_size_cl = (n_buckets_ext * sizeof(uint32_t) + RTE_CACHE_LINE_SIZE - 1)
/ RTE_CACHE_LINE_SIZE;
bucket_size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct rte_bucket_4_16) +
KEYS_PER_BUCKET * entry_size);
stack_size = RTE_CACHE_LINE_ROUNDUP(n_buckets_ext * sizeof(uint32_t));
total_size = sizeof(struct rte_table_hash) +
((n_buckets + n_buckets_ext) * bucket_size_cl + stack_size_cl) *
RTE_CACHE_LINE_SIZE;
f = rte_zmalloc_socket("TABLE", total_size, RTE_CACHE_LINE_SIZE, socket_id);
if (f == NULL) {
RTE_LOG(ERR, TABLE,
"%s: Cannot allocate %u bytes for hash table\n",
__func__, total_size);
(p->n_buckets + n_buckets_ext) * bucket_size + stack_size;
if (total_size > SIZE_MAX) {
RTE_LOG(ERR, TABLE, "%s: Cannot allocate %" PRIu64 " bytes "
"for hash table %s\n",
__func__, total_size, p->name);
return NULL;
}
RTE_LOG(INFO, TABLE,
"%s: Hash table memory footprint is %u bytes\n",
__func__, total_size);
f = rte_zmalloc_socket(p->name,
(size_t)total_size,
RTE_CACHE_LINE_SIZE,
socket_id);
if (f == NULL) {
RTE_LOG(ERR, TABLE, "%s: Cannot allocate %" PRIu64 " bytes "
"for hash table %s\n",
__func__, total_size, p->name);
return NULL;
}
RTE_LOG(INFO, TABLE, "%s: Hash table %s memory footprint "
"is %" PRIu64 " bytes\n",
__func__, p->name, total_size);
/* Memory initialization */
f->n_buckets = n_buckets;
f->n_entries_per_bucket = n_entries_per_bucket;
f->key_size = key_size;
f->n_buckets = p->n_buckets;
f->key_size = KEY_SIZE;
f->entry_size = entry_size;
f->bucket_size = bucket_size_cl * RTE_CACHE_LINE_SIZE;
f->signature_offset = p->signature_offset;
f->bucket_size = bucket_size;
f->key_offset = p->key_offset;
f->f_hash = p->f_hash;
f->seed = p->seed;
@ -388,10 +437,7 @@ rte_table_hash_create_key16_ext(void *params,
f->n_buckets_ext = n_buckets_ext;
f->stack_pos = n_buckets_ext;
f->stack = (uint32_t *)
&f->memory[(n_buckets + n_buckets_ext) * f->bucket_size];
for (i = 0; i < n_buckets_ext; i++)
f->stack[i] = i;
&f->memory[(p->n_buckets + n_buckets_ext) * f->bucket_size];
if (p->key_mask != NULL) {
f->key_mask[0] = (((uint64_t *)p->key_mask)[0]);
@ -401,6 +447,9 @@ rte_table_hash_create_key16_ext(void *params,
f->key_mask[1] = 0xFFFFFFFFFFFFFFFFLLU;
}
for (i = 0; i < n_buckets_ext; i++)
f->stack[i] = i;
return f;
}
@ -432,20 +481,20 @@ rte_table_hash_entry_add_key16_ext(
uint64_t signature;
uint32_t bucket_index, i;
signature = f->f_hash(key, f->key_size, f->seed);
signature = f->f_hash(key, f->key_mask, f->key_size, f->seed);
bucket_index = signature & (f->n_buckets - 1);
bucket0 = (struct rte_bucket_4_16 *)
&f->memory[bucket_index * f->bucket_size];
&f->memory[bucket_index * f->bucket_size];
signature |= RTE_BUCKET_ENTRY_VALID;
/* Key is present in the bucket */
for (bucket = bucket0; bucket != NULL; bucket = bucket->next)
for (i = 0; i < 4; i++) {
uint64_t bucket_signature = bucket->signature[i];
uint8_t *bucket_key = (uint8_t *) bucket->key[i];
uint8_t *bucket_key = (uint8_t *) &bucket->key[i];
if ((bucket_signature == signature) &&
(memcmp(key, bucket_key, f->key_size) == 0)) {
(keycmp(bucket_key, key, f->key_mask) == 0)) {
uint8_t *bucket_data = &bucket->data[i *
f->entry_size];
@ -458,17 +507,17 @@ rte_table_hash_entry_add_key16_ext(
/* Key is not present in the bucket */
for (bucket_prev = NULL, bucket = bucket0; bucket != NULL;
bucket_prev = bucket, bucket = bucket->next)
bucket_prev = bucket, bucket = bucket->next)
for (i = 0; i < 4; i++) {
uint64_t bucket_signature = bucket->signature[i];
uint8_t *bucket_key = (uint8_t *) bucket->key[i];
uint8_t *bucket_key = (uint8_t *) &bucket->key[i];
if (bucket_signature == 0) {
uint8_t *bucket_data = &bucket->data[i *
f->entry_size];
bucket->signature[i] = signature;
memcpy(bucket_key, key, f->key_size);
keycpy(bucket_key, key, f->key_mask);
memcpy(bucket_data, entry, f->entry_size);
*key_found = 0;
*entry_ptr = (void *) bucket_data;
@ -487,7 +536,7 @@ rte_table_hash_entry_add_key16_ext(
bucket_prev->next_valid = 1;
bucket->signature[0] = signature;
memcpy(bucket->key[0], key, f->key_size);
keycpy(&bucket->key[0], key, f->key_mask);
memcpy(&bucket->data[0], entry, f->entry_size);
*key_found = 0;
*entry_ptr = (void *) &bucket->data[0];
@ -509,7 +558,7 @@ rte_table_hash_entry_delete_key16_ext(
uint64_t signature;
uint32_t bucket_index, i;
signature = f->f_hash(key, f->key_size, f->seed);
signature = f->f_hash(key, f->key_mask, f->key_size, f->seed);
bucket_index = signature & (f->n_buckets - 1);
bucket0 = (struct rte_bucket_4_16 *)
&f->memory[bucket_index * f->bucket_size];
@ -520,18 +569,17 @@ rte_table_hash_entry_delete_key16_ext(
bucket_prev = bucket, bucket = bucket->next)
for (i = 0; i < 4; i++) {
uint64_t bucket_signature = bucket->signature[i];
uint8_t *bucket_key = (uint8_t *) bucket->key[i];
uint8_t *bucket_key = (uint8_t *) &bucket->key[i];
if ((bucket_signature == signature) &&
(memcmp(key, bucket_key, f->key_size) == 0)) {
(keycmp(bucket_key, key, f->key_mask) == 0)) {
uint8_t *bucket_data = &bucket->data[i *
f->entry_size];
bucket->signature[i] = 0;
*key_found = 1;
if (entry)
memcpy(entry, bucket_data,
f->entry_size);
memcpy(entry, bucket_data, f->entry_size);
if ((bucket->signature[0] == 0) &&
(bucket->signature[1] == 0) &&
@ -558,26 +606,28 @@ rte_table_hash_entry_delete_key16_ext(
return 0;
}
#define lookup_key16_cmp(key_in, bucket, pos) \
#define lookup_key16_cmp(key_in, bucket, pos, f) \
{ \
uint64_t xor[4][2], or[4], signature[4]; \
uint64_t xor[4][2], or[4], signature[4], k[2]; \
\
k[0] = key_in[0] & f->key_mask[0]; \
k[1] = key_in[1] & f->key_mask[1]; \
signature[0] = (~bucket->signature[0]) & 1; \
signature[1] = (~bucket->signature[1]) & 1; \
signature[2] = (~bucket->signature[2]) & 1; \
signature[3] = (~bucket->signature[3]) & 1; \
\
xor[0][0] = key_in[0] ^ bucket->key[0][0]; \
xor[0][1] = key_in[1] ^ bucket->key[0][1]; \
xor[0][0] = k[0] ^ bucket->key[0][0]; \
xor[0][1] = k[1] ^ bucket->key[0][1]; \
\
xor[1][0] = key_in[0] ^ bucket->key[1][0]; \
xor[1][1] = key_in[1] ^ bucket->key[1][1]; \
xor[1][0] = k[0] ^ bucket->key[1][0]; \
xor[1][1] = k[1] ^ bucket->key[1][1]; \
\
xor[2][0] = key_in[0] ^ bucket->key[2][0]; \
xor[2][1] = key_in[1] ^ bucket->key[2][1]; \
xor[2][0] = k[0] ^ bucket->key[2][0]; \
xor[2][1] = k[1] ^ bucket->key[2][1]; \
\
xor[3][0] = key_in[0] ^ bucket->key[3][0]; \
xor[3][1] = key_in[1] ^ bucket->key[3][1]; \
xor[3][0] = k[0] ^ bucket->key[3][0]; \
xor[3][1] = k[1] ^ bucket->key[3][1]; \
\
or[0] = xor[0][0] | xor[0][1] | signature[0]; \
or[1] = xor[1][0] | xor[1][1] | signature[1]; \
@ -613,14 +663,9 @@ rte_table_hash_entry_delete_key16_ext(
uint64_t *key; \
uint64_t signature = 0; \
uint32_t bucket_index; \
uint64_t hash_key_buffer[2]; \
\
key = RTE_MBUF_METADATA_UINT64_PTR(mbuf1, f->key_offset);\
\
hash_key_buffer[0] = key[0] & f->key_mask[0]; \
hash_key_buffer[1] = key[1] & f->key_mask[1]; \
signature = f->f_hash(hash_key_buffer, \
RTE_TABLE_HASH_KEY_SIZE, f->seed); \
signature = f->f_hash(key, f->key_mask, KEY_SIZE, f->seed); \
\
bucket_index = signature & (f->n_buckets - 1); \
bucket1 = (struct rte_bucket_4_16 *) \
@ -635,14 +680,10 @@ rte_table_hash_entry_delete_key16_ext(
void *a; \
uint64_t pkt_mask; \
uint64_t *key; \
uint64_t hash_key_buffer[2]; \
uint32_t pos; \
\
key = RTE_MBUF_METADATA_UINT64_PTR(mbuf2, f->key_offset);\
hash_key_buffer[0] = key[0] & f->key_mask[0]; \
hash_key_buffer[1] = key[1] & f->key_mask[1]; \
\
lookup_key16_cmp(hash_key_buffer, bucket2, pos); \
lookup_key16_cmp(key, bucket2, pos, f); \
\
pkt_mask = (bucket2->signature[pos] & 1LLU) << pkt2_index;\
pkts_mask_out |= pkt_mask; \
@ -660,14 +701,10 @@ rte_table_hash_entry_delete_key16_ext(
void *a; \
uint64_t pkt_mask, bucket_mask; \
uint64_t *key; \
uint64_t hash_key_buffer[2]; \
uint32_t pos; \
\
key = RTE_MBUF_METADATA_UINT64_PTR(mbuf2, f->key_offset);\
hash_key_buffer[0] = key[0] & f->key_mask[0]; \
hash_key_buffer[1] = key[1] & f->key_mask[1]; \
\
lookup_key16_cmp(hash_key_buffer, bucket2, pos); \
lookup_key16_cmp(key, bucket2, pos, f); \
\
pkt_mask = (bucket2->signature[pos] & 1LLU) << pkt2_index;\
pkts_mask_out |= pkt_mask; \
@ -690,15 +727,11 @@ rte_table_hash_entry_delete_key16_ext(
void *a; \
uint64_t pkt_mask, bucket_mask; \
uint64_t *key; \
uint64_t hash_key_buffer[2]; \
uint32_t pos; \
\
bucket = buckets[pkt_index]; \
key = keys[pkt_index]; \
hash_key_buffer[0] = key[0] & f->key_mask[0]; \
hash_key_buffer[1] = key[1] & f->key_mask[1]; \
\
lookup_key16_cmp(hash_key_buffer, bucket, pos); \
lookup_key16_cmp(key, bucket, pos, f); \
\
pkt_mask = (bucket->signature[pos] & 1LLU) << pkt_index;\
pkts_mask_out |= pkt_mask; \
@ -763,15 +796,11 @@ rte_table_hash_entry_delete_key16_ext(
#define lookup2_stage1(mbuf10, mbuf11, bucket10, bucket11, f) \
{ \
uint64_t *key10, *key11; \
uint64_t hash_offset_buffer[2]; \
uint64_t signature10, signature11; \
uint32_t bucket10_index, bucket11_index; \
\
key10 = RTE_MBUF_METADATA_UINT64_PTR(mbuf10, f->key_offset);\
hash_offset_buffer[0] = key10[0] & f->key_mask[0]; \
hash_offset_buffer[1] = key10[1] & f->key_mask[1]; \
signature10 = f->f_hash(hash_offset_buffer, \
RTE_TABLE_HASH_KEY_SIZE, f->seed);\
signature10 = f->f_hash(key10, f->key_mask, KEY_SIZE, f->seed);\
bucket10_index = signature10 & (f->n_buckets - 1); \
bucket10 = (struct rte_bucket_4_16 *) \
&f->memory[bucket10_index * f->bucket_size]; \
@ -779,10 +808,7 @@ rte_table_hash_entry_delete_key16_ext(
rte_prefetch0((void *)(((uintptr_t) bucket10) + RTE_CACHE_LINE_SIZE));\
\
key11 = RTE_MBUF_METADATA_UINT64_PTR(mbuf11, f->key_offset);\
hash_offset_buffer[0] = key11[0] & f->key_mask[0]; \
hash_offset_buffer[1] = key11[1] & f->key_mask[1]; \
signature11 = f->f_hash(hash_offset_buffer, \
RTE_TABLE_HASH_KEY_SIZE, f->seed);\
signature11 = f->f_hash(key11, f->key_mask, KEY_SIZE, f->seed);\
bucket11_index = signature11 & (f->n_buckets - 1); \
bucket11 = (struct rte_bucket_4_16 *) \
&f->memory[bucket11_index * f->bucket_size]; \
@ -796,19 +822,13 @@ rte_table_hash_entry_delete_key16_ext(
void *a20, *a21; \
uint64_t pkt20_mask, pkt21_mask; \
uint64_t *key20, *key21; \
uint64_t hash_key_buffer20[2]; \
uint64_t hash_key_buffer21[2]; \
uint32_t pos20, pos21; \
\
key20 = RTE_MBUF_METADATA_UINT64_PTR(mbuf20, f->key_offset);\
key21 = RTE_MBUF_METADATA_UINT64_PTR(mbuf21, f->key_offset);\
hash_key_buffer20[0] = key20[0] & f->key_mask[0]; \
hash_key_buffer20[1] = key20[1] & f->key_mask[1]; \
hash_key_buffer21[0] = key21[0] & f->key_mask[0]; \
hash_key_buffer21[1] = key21[1] & f->key_mask[1]; \
\
lookup_key16_cmp(hash_key_buffer20, bucket20, pos20); \
lookup_key16_cmp(hash_key_buffer21, bucket21, pos21); \
lookup_key16_cmp(key20, bucket20, pos20, f); \
lookup_key16_cmp(key21, bucket21, pos21, f); \
\
pkt20_mask = (bucket20->signature[pos20] & 1LLU) << pkt20_index;\
pkt21_mask = (bucket21->signature[pos21] & 1LLU) << pkt21_index;\
@ -831,19 +851,13 @@ rte_table_hash_entry_delete_key16_ext(
void *a20, *a21; \
uint64_t pkt20_mask, pkt21_mask, bucket20_mask, bucket21_mask;\
uint64_t *key20, *key21; \
uint64_t hash_key_buffer20[2]; \
uint64_t hash_key_buffer21[2]; \
uint32_t pos20, pos21; \
\
key20 = RTE_MBUF_METADATA_UINT64_PTR(mbuf20, f->key_offset);\
key21 = RTE_MBUF_METADATA_UINT64_PTR(mbuf21, f->key_offset);\
hash_key_buffer20[0] = key20[0] & f->key_mask[0]; \
hash_key_buffer20[1] = key20[1] & f->key_mask[1]; \
hash_key_buffer21[0] = key21[0] & f->key_mask[0]; \
hash_key_buffer21[1] = key21[1] & f->key_mask[1]; \
\
lookup_key16_cmp(hash_key_buffer20, bucket20, pos20); \
lookup_key16_cmp(hash_key_buffer21, bucket21, pos21); \
lookup_key16_cmp(key20, bucket20, pos20, f); \
lookup_key16_cmp(key21, bucket21, pos21, f); \
\
pkt20_mask = (bucket20->signature[pos20] & 1LLU) << pkt20_index;\
pkt21_mask = (bucket21->signature[pos21] & 1LLU) << pkt21_index;\
@ -994,7 +1008,7 @@ rte_table_hash_lookup_key16_lru(
RTE_TABLE_HASH_KEY16_STATS_PKTS_LOOKUP_MISS(f, n_pkts_in -
__builtin_popcountll(pkts_mask_out));
return 0;
} /* rte_table_hash_lookup_key16_lru() */
} /* lookup LRU */
static int
rte_table_hash_lookup_key16_ext(
@ -1146,7 +1160,7 @@ rte_table_hash_lookup_key16_ext(
RTE_TABLE_HASH_KEY16_STATS_PKTS_LOOKUP_MISS(f, n_pkts_in -
__builtin_popcountll(pkts_mask_out));
return 0;
} /* rte_table_hash_lookup_key16_ext() */
} /* lookup EXT */
static int
rte_table_hash_key16_stats_read(void *table, struct rte_table_stats *stats, int clear)
@ -1167,6 +1181,8 @@ struct rte_table_ops rte_table_hash_key16_lru_ops = {
.f_free = rte_table_hash_free_key16_lru,
.f_add = rte_table_hash_entry_add_key16_lru,
.f_delete = rte_table_hash_entry_delete_key16_lru,
.f_add_bulk = NULL,
.f_delete_bulk = NULL,
.f_lookup = rte_table_hash_lookup_key16_lru,
.f_stats = rte_table_hash_key16_stats_read,
};
@ -1176,6 +1192,8 @@ struct rte_table_ops rte_table_hash_key16_ext_ops = {
.f_free = rte_table_hash_free_key16_ext,
.f_add = rte_table_hash_entry_add_key16_ext,
.f_delete = rte_table_hash_entry_delete_key16_ext,
.f_add_bulk = NULL,
.f_delete_bulk = NULL,
.f_lookup = rte_table_hash_lookup_key16_ext,
.f_stats = rte_table_hash_key16_stats_read,
};

View File

@ -285,14 +285,15 @@ app_main_loop_worker_pipeline_hash(void) {
case e_APP_PIPELINE_HASH_SPEC_KEY16_EXT:
{
struct rte_table_hash_key16_ext_params table_hash_params = {
.n_entries = 1 << 24,
.n_entries_ext = 1 << 23,
.signature_offset = APP_METADATA_OFFSET(0),
struct rte_table_hash_params table_hash_params = {
.name = "TABLE",
.key_size = key_size,
.key_offset = APP_METADATA_OFFSET(32),
.f_hash = test_hash,
.seed = 0,
.key_mask = NULL,
.n_keys = 1 << 24,
.n_buckets = 1 << 22,
.f_hash = (rte_table_hash_op_hash)test_hash,
.seed = 0,
};
struct rte_pipeline_table_params table_params = {
@ -311,13 +312,15 @@ app_main_loop_worker_pipeline_hash(void) {
case e_APP_PIPELINE_HASH_SPEC_KEY16_LRU:
{
struct rte_table_hash_key16_lru_params table_hash_params = {
.n_entries = 1 << 24,
.signature_offset = APP_METADATA_OFFSET(0),
struct rte_table_hash_params table_hash_params = {
.name = "TABLE",
.key_size = key_size,
.key_offset = APP_METADATA_OFFSET(32),
.f_hash = test_hash,
.seed = 0,
.key_mask = NULL,
.n_keys = 1 << 24,
.n_buckets = 1 << 22,
.f_hash = (rte_table_hash_op_hash)test_hash,
.seed = 0,
};
struct rte_pipeline_table_params table_params = {

View File

@ -502,13 +502,15 @@ test_table_hash16lru(void)
int status, i;
/* Traffic flow */
struct rte_table_hash_key16_lru_params key16lru_params = {
.n_entries = 1<<16,
.f_hash = pipeline_test_hash,
.seed = 0,
.signature_offset = APP_METADATA_OFFSET(0),
struct rte_table_hash_params key16lru_params = {
.name = "TABLE",
.key_size = 16,
.key_offset = APP_METADATA_OFFSET(32),
.key_mask = NULL,
.n_keys = 1 << 16,
.n_buckets = 1 << 16,
.f_hash = (rte_table_hash_op_hash)pipeline_test_hash,
.seed = 0,
};
uint8_t key16lru[16];
@ -537,14 +539,14 @@ test_table_hash16lru(void)
VERIFY(status, CHECK_TABLE_OK);
/* Invalid parameters */
key16lru_params.n_entries = 0;
key16lru_params.n_keys = 0;
status = test_table_type(&rte_table_hash_key16_lru_ops,
(void *)&key16lru_params, (void *)key16lru, &table_packets,
NULL, 0);
VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
key16lru_params.n_entries = 1<<16;
key16lru_params.n_keys = 1<<16;
key16lru_params.f_hash = NULL;
status = test_table_type(&rte_table_hash_key16_lru_ops,
@ -680,14 +682,15 @@ test_table_hash16ext(void)
int status, i;
/* Traffic flow */
struct rte_table_hash_key16_ext_params key16ext_params = {
.n_entries = 1<<16,
.n_entries_ext = 1<<15,
.f_hash = pipeline_test_hash,
.seed = 0,
.signature_offset = APP_METADATA_OFFSET(0),
struct rte_table_hash_params key16ext_params = {
.name = "TABLE",
.key_size = 16,
.key_offset = APP_METADATA_OFFSET(32),
.key_mask = NULL,
.n_keys = 1 << 16,
.n_buckets = 1 << 16,
.f_hash = (rte_table_hash_op_hash)pipeline_test_hash,
.seed = 0,
};
uint8_t key16ext[16];
@ -716,14 +719,14 @@ test_table_hash16ext(void)
VERIFY(status, CHECK_TABLE_OK);
/* Invalid parameters */
key16ext_params.n_entries = 0;
key16ext_params.n_keys = 0;
status = test_table_type(&rte_table_hash_key16_ext_ops,
(void *)&key16ext_params, (void *)key16ext, &table_packets,
NULL, 0);
VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
key16ext_params.n_entries = 1<<16;
key16ext_params.n_keys = 1<<16;
key16ext_params.f_hash = NULL;
status = test_table_type(&rte_table_hash_key16_ext_ops,
@ -731,13 +734,6 @@ test_table_hash16ext(void)
NULL, 0);
VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
key16ext_params.f_hash = pipeline_test_hash;
key16ext_params.n_entries_ext = 0;
status = test_table_type(&rte_table_hash_key16_ext_ops,
(void *)&key16ext_params, (void *)key16ext, &table_packets, NULL, 0);
VERIFY(status, CHECK_TABLE_TABLE_CONFIG);
return 0;
}

View File

@ -878,6 +878,11 @@ test_table_hash_lru(void)
if (status < 0)
return status;
status = test_table_hash_lru_generic(
&rte_table_hash_key16_lru_ops,
16);
if (status < 0)
return status;
status = test_lru_update();
if (status < 0)
return status;
@ -894,6 +899,9 @@ test_table_hash_ext(void)
if (status < 0)
return status;
status = test_table_hash_ext_generic(&rte_table_hash_key16_ext_ops, 16);
if (status < 0)
return status;
return 0;
}