table: add key mask to 8 and 16-byte hash parameters
authorFan Zhang <roy.fan.zhang@intel.com>
Wed, 28 Oct 2015 17:11:16 +0000 (17:11 +0000)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 25 Nov 2015 23:45:50 +0000 (00:45 +0100)
This patch relates to ABI change proposed for librte_table.
The key_mask parameter is added for 8-byte and 16-byte
key extendible bucket and LRU tables.The release notes
is updated and the deprecation notice is removed.

Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>
Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
app/test-pipeline/pipeline_hash.c
app/test/test_table_combined.c
app/test/test_table_tables.c
doc/guides/rel_notes/deprecation.rst
doc/guides/rel_notes/release_2_2.rst
lib/librte_table/rte_table_hash.h
lib/librte_table/rte_table_hash_key16.c
lib/librte_table/rte_table_hash_key8.c
lib/librte_table/rte_table_version.map

index 5e4e17f..8b888d7 100644 (file)
@@ -216,6 +216,7 @@ app_main_loop_worker_pipeline_hash(void) {
                        .n_entries_ext = 1 << 23,
                        .signature_offset = APP_METADATA_OFFSET(0),
                        .key_offset = APP_METADATA_OFFSET(32),
+                       .key_mask = NULL,
                        .f_hash = test_hash,
                        .seed = 0,
                };
@@ -240,6 +241,7 @@ app_main_loop_worker_pipeline_hash(void) {
                        .n_entries = 1 << 24,
                        .signature_offset = APP_METADATA_OFFSET(0),
                        .key_offset = APP_METADATA_OFFSET(32),
+                       .key_mask = NULL,
                        .f_hash = test_hash,
                        .seed = 0,
                };
@@ -267,6 +269,7 @@ app_main_loop_worker_pipeline_hash(void) {
                        .key_offset = APP_METADATA_OFFSET(32),
                        .f_hash = test_hash,
                        .seed = 0,
+                       .key_mask = NULL,
                };
 
                struct rte_pipeline_table_params table_params = {
@@ -291,6 +294,7 @@ app_main_loop_worker_pipeline_hash(void) {
                        .key_offset = APP_METADATA_OFFSET(32),
                        .f_hash = test_hash,
                        .seed = 0,
+                       .key_mask = NULL,
                };
 
                struct rte_pipeline_table_params table_params = {
index 18daeec..8bf4aeb 100644 (file)
@@ -418,9 +418,9 @@ test_table_hash8lru(void)
        struct rte_table_hash_key8_lru_params key8lru_params = {
                .n_entries = 1<<24,
                .f_hash = pipeline_test_hash,
-               .seed = 0,
                .signature_offset = APP_METADATA_OFFSET(0),
                .key_offset = APP_METADATA_OFFSET(32),
+               .key_mask = NULL,
        };
 
        uint8_t key8lru[8];
@@ -479,6 +479,7 @@ test_table_hash16lru(void)
                .seed = 0,
                .signature_offset = APP_METADATA_OFFSET(0),
                .key_offset = APP_METADATA_OFFSET(32),
+               .key_mask = NULL,
        };
 
        uint8_t key16lru[16];
@@ -596,6 +597,7 @@ test_table_hash8ext(void)
                .seed = 0,
                .signature_offset = APP_METADATA_OFFSET(0),
                .key_offset = APP_METADATA_OFFSET(32),
+               .key_mask = NULL,
        };
 
        uint8_t key8ext[8];
@@ -662,6 +664,7 @@ test_table_hash16ext(void)
                .seed = 0,
                .signature_offset = APP_METADATA_OFFSET(0),
                .key_offset = APP_METADATA_OFFSET(32),
+               .key_mask = NULL,
        };
 
        uint8_t key16ext[16];
index cf7c62d..b6364c4 100644 (file)
@@ -669,7 +669,8 @@ test_table_hash_lru_generic(struct rte_table_ops *ops)
                .f_hash = pipeline_test_hash,
                .seed = 0,
                .signature_offset = APP_METADATA_OFFSET(1),
-               .key_offset = APP_METADATA_OFFSET(32)
+               .key_offset = APP_METADATA_OFFSET(32),
+               .key_mask = NULL,
        };
 
        hash_params.n_entries = 0;
@@ -784,7 +785,8 @@ test_table_hash_ext_generic(struct rte_table_ops *ops)
                .f_hash = pipeline_test_hash,
                .seed = 0,
                .signature_offset = APP_METADATA_OFFSET(1),
-               .key_offset = APP_METADATA_OFFSET(32)
+               .key_offset = APP_METADATA_OFFSET(32),
+               .key_mask = NULL,
        };
 
        hash_params.n_entries = 0;
index 64e3aa4..1c7ab01 100644 (file)
@@ -15,10 +15,6 @@ Deprecation Notices
 * The scheduler statistics structure will change to allow keeping track of
   RED actions.
 
-* librte_table hash: Key mask parameter will be added to the hash table
-  parameter structure for 8-byte key and 16-byte key extendible bucket and
-  LRU tables.
-
 * librte_pipeline: The prototype for the pipeline input port, output port
   and table action handlers will be updated:
   the pipeline parameter will be added, the packets mask parameter will be
index c4c2372..0c6aa04 100644 (file)
@@ -308,6 +308,10 @@ ABI Changes
 * librte_table LPM: A new parameter to hold the table name will be added to
   the LPM table parameter structure.
 
+* librte_table hash: The key mask parameter is added to the hash table
+  parameter structure for 8-byte key and 16-byte key extendible bucket
+  and LRU tables.
+
 * librte_port: Macros to access the packet meta-data stored within the packet
   buffer has been adjusted to cover the packet mbuf structure.
 
index 9181942..e2c60e1 100644 (file)
@@ -196,6 +196,9 @@ struct rte_table_hash_key8_lru_params {
 
        /** 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;
 };
 
 /** LRU hash table operations for pre-computed key signature */
@@ -226,6 +229,9 @@ struct rte_table_hash_key8_ext_params {
 
        /** 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;
 };
 
 /** Extendible bucket hash table operations for pre-computed key signature */
@@ -257,6 +263,9 @@ struct rte_table_hash_key16_lru_params {
 
        /** 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;
 };
 
 /** LRU hash table operations for pre-computed key signature */
@@ -284,6 +293,9 @@ struct rte_table_hash_key16_ext_params {
 
        /** 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;
 };
 
 /** Extendible bucket operations for pre-computed key signature */
index 35b7f10..5ad63bc 100644 (file)
@@ -85,6 +85,7 @@ struct rte_table_hash {
        uint32_t bucket_size;
        uint32_t signature_offset;
        uint32_t key_offset;
+       uint64_t key_mask[2];
        rte_table_hash_op_hash f_hash;
        uint64_t seed;
 
@@ -164,6 +165,14 @@ rte_table_hash_create_key16_lru(void *params,
        f->f_hash = p->f_hash;
        f->seed = p->seed;
 
+       if (p->key_mask != NULL) {
+               f->key_mask[0] = ((uint64_t *)p->key_mask)[0];
+               f->key_mask[1] = ((uint64_t *)p->key_mask)[1];
+       } else {
+               f->key_mask[0] = 0xFFFFFFFFFFFFFFFFLLU;
+               f->key_mask[1] = 0xFFFFFFFFFFFFFFFFLLU;
+       }
+
        for (i = 0; i < n_buckets; i++) {
                struct rte_bucket_4_16 *bucket;
 
@@ -384,6 +393,14 @@ rte_table_hash_create_key16_ext(void *params,
        for (i = 0; i < n_buckets_ext; i++)
                f->stack[i] = i;
 
+       if (p->key_mask != NULL) {
+               f->key_mask[0] = (((uint64_t *)p->key_mask)[0]);
+               f->key_mask[1] = (((uint64_t *)p->key_mask)[1]);
+       } else {
+               f->key_mask[0] = 0xFFFFFFFFFFFFFFFFLLU;
+               f->key_mask[1] = 0xFFFFFFFFFFFFFFFFLLU;
+       }
+
        return f;
 }
 
@@ -609,11 +626,14 @@ 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(key, bucket2, pos);                    \
+       lookup_key16_cmp(hash_key_buffer, bucket2, pos);        \
                                                                \
        pkt_mask = (bucket2->signature[pos] & 1LLU) << pkt2_index;\
        pkts_mask_out |= pkt_mask;                              \
@@ -631,11 +651,14 @@ 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(key, bucket2, pos);                    \
+       lookup_key16_cmp(hash_key_buffer, bucket2, pos);        \
                                                                \
        pkt_mask = (bucket2->signature[pos] & 1LLU) << pkt2_index;\
        pkts_mask_out |= pkt_mask;                              \
@@ -658,12 +681,15 @@ 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(key, bucket, pos);                     \
+       lookup_key16_cmp(hash_key_buffer, bucket, pos); \
                                                                \
        pkt_mask = (bucket->signature[pos] & 1LLU) << pkt_index;\
        pkts_mask_out |= pkt_mask;                              \
@@ -749,13 +775,19 @@ 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(key20, bucket20, pos20);               \
-       lookup_key16_cmp(key21, bucket21, pos21);               \
+       lookup_key16_cmp(hash_key_buffer20, bucket20, pos20);   \
+       lookup_key16_cmp(hash_key_buffer21, bucket21, pos21);   \
                                                                \
        pkt20_mask = (bucket20->signature[pos20] & 1LLU) << pkt20_index;\
        pkt21_mask = (bucket21->signature[pos21] & 1LLU) << pkt21_index;\
@@ -778,13 +810,19 @@ 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(key20, bucket20, pos20);               \
-       lookup_key16_cmp(key21, bucket21, pos21);               \
+       lookup_key16_cmp(hash_key_buffer20, bucket20, pos20);   \
+       lookup_key16_cmp(hash_key_buffer21, bucket21, pos21);   \
                                                                \
        pkt20_mask = (bucket20->signature[pos20] & 1LLU) << pkt20_index;\
        pkt21_mask = (bucket21->signature[pos21] & 1LLU) << pkt21_index;\
index 379748e..5f05903 100644 (file)
@@ -82,6 +82,7 @@ struct rte_table_hash {
        uint32_t bucket_size;
        uint32_t signature_offset;
        uint32_t key_offset;
+       uint64_t key_mask;
        rte_table_hash_op_hash f_hash;
        uint64_t seed;
 
@@ -160,6 +161,11 @@ rte_table_hash_create_key8_lru(void *params, int socket_id, uint32_t entry_size)
        f->f_hash = p->f_hash;
        f->seed = p->seed;
 
+       if (p->key_mask != NULL)
+               f->key_mask = ((uint64_t *)p->key_mask)[0];
+       else
+               f->key_mask = 0xFFFFFFFFFFFFFFFFLLU;
+
        for (i = 0; i < n_buckets; i++) {
                struct rte_bucket_4_8 *bucket;
 
@@ -372,6 +378,11 @@ rte_table_hash_create_key8_ext(void *params, int socket_id, uint32_t entry_size)
        f->stack = (uint32_t *)
                &f->memory[(n_buckets + n_buckets_ext) * f->bucket_size];
 
+       if (p->key_mask != NULL)
+               f->key_mask = ((uint64_t *)p->key_mask)[0];
+       else
+               f->key_mask = 0xFFFFFFFFFFFFFFFFLLU;
+
        for (i = 0; i < n_buckets_ext; i++)
                f->stack[i] = i;
 
@@ -586,9 +597,12 @@ rte_table_hash_entry_delete_key8_ext(
        uint64_t *key;                                          \
        uint64_t signature;                                     \
        uint32_t bucket_index;                                  \
+       uint64_t hash_key_buffer;                               \
                                                                \
        key = RTE_MBUF_METADATA_UINT64_PTR(mbuf1, f->key_offset);\
-       signature = f->f_hash(key, RTE_TABLE_HASH_KEY_SIZE, f->seed);\
+       hash_key_buffer = *key & f->key_mask;                   \
+       signature = f->f_hash(&hash_key_buffer,                 \
+               RTE_TABLE_HASH_KEY_SIZE, f->seed);              \
        bucket_index = signature & (f->n_buckets - 1);          \
        bucket1 = (struct rte_bucket_4_8 *)                     \
                &f->memory[bucket_index * f->bucket_size];      \
@@ -602,10 +616,12 @@ rte_table_hash_entry_delete_key8_ext(
        uint64_t pkt_mask;                                      \
        uint64_t *key;                                          \
        uint32_t pos;                                           \
+       uint64_t hash_key_buffer;                               \
                                                                \
        key = RTE_MBUF_METADATA_UINT64_PTR(mbuf2, f->key_offset);\
+       hash_key_buffer = key[0] & f->key_mask;                 \
                                                                \
-       lookup_key8_cmp(key, bucket2, pos);                     \
+       lookup_key8_cmp((&hash_key_buffer), bucket2, pos);      \
                                                                \
        pkt_mask = ((bucket2->signature >> pos) & 1LLU) << pkt2_index;\
        pkts_mask_out |= pkt_mask;                              \
@@ -624,10 +640,12 @@ rte_table_hash_entry_delete_key8_ext(
        uint64_t pkt_mask, bucket_mask;                         \
        uint64_t *key;                                          \
        uint32_t pos;                                           \
+       uint64_t hash_key_buffer;                               \
                                                                \
        key = RTE_MBUF_METADATA_UINT64_PTR(mbuf2, f->key_offset);\
+       hash_key_buffer = *key & f->key_mask;                   \
                                                                \
-       lookup_key8_cmp(key, bucket2, pos);                     \
+       lookup_key8_cmp((&hash_key_buffer), bucket2, pos);      \
                                                                \
        pkt_mask = ((bucket2->signature >> pos) & 1LLU) << pkt2_index;\
        pkts_mask_out |= pkt_mask;                              \
@@ -651,11 +669,13 @@ rte_table_hash_entry_delete_key8_ext(
        uint64_t pkt_mask, bucket_mask;                         \
        uint64_t *key;                                          \
        uint32_t pos;                                           \
+       uint64_t hash_key_buffer;                               \
                                                                \
        bucket = buckets[pkt_index];                            \
        key = keys[pkt_index];                                  \
+       hash_key_buffer = (*key) & f->key_mask;                 \
                                                                \
-       lookup_key8_cmp(key, bucket, pos);                      \
+       lookup_key8_cmp((&hash_key_buffer), bucket, pos);       \
                                                                \
        pkt_mask = ((bucket->signature >> pos) & 1LLU) << pkt_index;\
        pkts_mask_out |= pkt_mask;                              \
@@ -736,6 +756,8 @@ rte_table_hash_entry_delete_key8_ext(
 #define lookup2_stage1_dosig(mbuf10, mbuf11, bucket10, bucket11, f)\
 {                                                              \
        uint64_t *key10, *key11;                                \
+       uint64_t hash_offset_buffer10;                          \
+       uint64_t hash_offset_buffer11;                          \
        uint64_t signature10, signature11;                      \
        uint32_t bucket10_index, bucket11_index;                \
        rte_table_hash_op_hash f_hash = f->f_hash;              \
@@ -744,14 +766,18 @@ rte_table_hash_entry_delete_key8_ext(
                                                                \
        key10 = RTE_MBUF_METADATA_UINT64_PTR(mbuf10, key_offset);\
        key11 = RTE_MBUF_METADATA_UINT64_PTR(mbuf11, key_offset);\
+       hash_offset_buffer10 = *key10 & f->key_mask;            \
+       hash_offset_buffer11 = *key11 & f->key_mask;            \
                                                                \
-       signature10 = f_hash(key10, RTE_TABLE_HASH_KEY_SIZE, seed);\
+       signature10 = f_hash(&hash_offset_buffer10,             \
+               RTE_TABLE_HASH_KEY_SIZE, seed);                 \
        bucket10_index = signature10 & (f->n_buckets - 1);      \
        bucket10 = (struct rte_bucket_4_8 *)                    \
                &f->memory[bucket10_index * f->bucket_size];    \
        rte_prefetch0(bucket10);                                \
                                                                \
-       signature11 = f_hash(key11, RTE_TABLE_HASH_KEY_SIZE, seed);\
+       signature11 = f_hash(&hash_offset_buffer11,             \
+               RTE_TABLE_HASH_KEY_SIZE, seed);                 \
        bucket11_index = signature11 & (f->n_buckets - 1);      \
        bucket11 = (struct rte_bucket_4_8 *)                    \
                &f->memory[bucket11_index * f->bucket_size];    \
@@ -764,13 +790,17 @@ rte_table_hash_entry_delete_key8_ext(
        void *a20, *a21;                                        \
        uint64_t pkt20_mask, pkt21_mask;                        \
        uint64_t *key20, *key21;                                \
+       uint64_t hash_offset_buffer20;                          \
+       uint64_t hash_offset_buffer21;                          \
        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_offset_buffer20 = *key20 & f->key_mask;            \
+       hash_offset_buffer21 = *key21 & f->key_mask;            \
                                                                \
-       lookup_key8_cmp(key20, bucket20, pos20);                \
-       lookup_key8_cmp(key21, bucket21, pos21);                \
+       lookup_key8_cmp((&hash_offset_buffer20), bucket20, pos20);\
+       lookup_key8_cmp((&hash_offset_buffer21), bucket21, pos21);\
                                                                \
        pkt20_mask = ((bucket20->signature >> pos20) & 1LLU) << pkt20_index;\
        pkt21_mask = ((bucket21->signature >> pos21) & 1LLU) << pkt21_index;\
@@ -793,13 +823,17 @@ rte_table_hash_entry_delete_key8_ext(
        void *a20, *a21;                                        \
        uint64_t pkt20_mask, pkt21_mask, bucket20_mask, bucket21_mask;\
        uint64_t *key20, *key21;                                \
+       uint64_t hash_offset_buffer20;                          \
+       uint64_t hash_offset_buffer21;                          \
        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_offset_buffer20 = *key20 & f->key_mask;            \
+       hash_offset_buffer21 = *key21 & f->key_mask;            \
                                                                \
-       lookup_key8_cmp(key20, bucket20, pos20);                \
-       lookup_key8_cmp(key21, bucket21, pos21);                \
+       lookup_key8_cmp((&hash_offset_buffer20), bucket20, pos20);\
+       lookup_key8_cmp((&hash_offset_buffer21), bucket21, pos21);\
                                                                \
        pkt20_mask = ((bucket20->signature >> pos20) & 1LLU) << pkt20_index;\
        pkt21_mask = ((bucket21->signature >> pos21) & 1LLU) << pkt21_index;\
index d33f926..2138698 100644 (file)
@@ -19,3 +19,10 @@ DPDK_2.0 {
 
        local: *;
 };
+
+DPDK_2.2 {
+       global:
+
+       rte_table_hash_key16_ext_dosig_ops;
+
+} DPDK_2.0;