get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/115301/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 115301,
    "url": "https://patches.dpdk.org/api/patches/115301/?format=api",
    "web_url": "https://patches.dpdk.org/project/dpdk/patch/20220819195225.1483020-6-cristian.dumitrescu@intel.com/",
    "project": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<20220819195225.1483020-6-cristian.dumitrescu@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/20220819195225.1483020-6-cristian.dumitrescu@intel.com",
    "date": "2022-08-19T19:52:24",
    "name": "[V2,5/6] table: configure the hash function for learner tables",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "0418d0dc89421ed9453b4c36a33f2d8e54328345",
    "submitter": {
        "id": 19,
        "url": "https://patches.dpdk.org/api/people/19/?format=api",
        "name": "Cristian Dumitrescu",
        "email": "cristian.dumitrescu@intel.com"
    },
    "delegate": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/users/1/?format=api",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "https://patches.dpdk.org/project/dpdk/patch/20220819195225.1483020-6-cristian.dumitrescu@intel.com/mbox/",
    "series": [
        {
            "id": 24366,
            "url": "https://patches.dpdk.org/api/series/24366/?format=api",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=24366",
            "date": "2022-08-19T19:52:19",
            "name": "pipeline: make the hash function configurable per table",
            "version": 2,
            "mbox": "https://patches.dpdk.org/series/24366/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/115301/comments/",
    "check": "success",
    "checks": "https://patches.dpdk.org/api/patches/115301/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 20ECEA034C;\n\tFri, 19 Aug 2022 21:53:00 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id 6D5F44280B;\n\tFri, 19 Aug 2022 21:52:36 +0200 (CEST)",
            "from mga02.intel.com (mga02.intel.com [134.134.136.20])\n by mails.dpdk.org (Postfix) with ESMTP id B05B1427F2\n for <dev@dpdk.org>; Fri, 19 Aug 2022 21:52:32 +0200 (CEST)",
            "from orsmga007.jf.intel.com ([10.7.209.58])\n by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 19 Aug 2022 12:52:32 -0700",
            "from silpixa00400573.ir.intel.com (HELO\n silpixa00400573.ger.corp.intel.com.) ([10.237.223.157])\n by orsmga007.jf.intel.com with ESMTP; 19 Aug 2022 12:52:31 -0700"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple;\n d=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n t=1660938752; x=1692474752;\n h=from:to:cc:subject:date:message-id:in-reply-to:\n references:mime-version:content-transfer-encoding;\n bh=Im2biz+3FTAqtawTMZMGrtj+VmxJW1usWt5PmxD960g=;\n b=HrC1xPpd9FxttS1EupGH2K9ZnZP14sAIWmJv6rnB7xXfiiKjFyCTpzRN\n E/3c8dRMH4IUEzLDpIg3t6Etgp8+M2Gb3Z3qIstL9tXz5yX3a0isyGfX3\n OU7R7bFGWS3E4D6k+MQ2/LI92NRN1Fv3cpi9Th9rJ7nm7dCarauW+avm3\n LcozcyJ8zv9syhrhJjc/rqt5vq5RYRKRatwOiz4De8EeG2ipnPd9QPQcO\n LNQMPLFkd/Cy8pL8XLfytSJmzGrjXws7Ed5DRsgBb505UqIGlzhe1LKM5\n 8hxuOFebcy858ieSSOv6XQpk3eEb+7f8p7OKqwasaYs+JsQEo6rEdwor/ Q==;",
        "X-IronPort-AV": [
            "E=McAfee;i=\"6500,9779,10444\"; a=\"280047524\"",
            "E=Sophos;i=\"5.93,249,1654585200\"; d=\"scan'208\";a=\"280047524\"",
            "E=Sophos;i=\"5.93,248,1654585200\"; d=\"scan'208\";a=\"604695962\""
        ],
        "X-ExtLoop1": "1",
        "From": "Cristian Dumitrescu <cristian.dumitrescu@intel.com>",
        "To": "dev@dpdk.org",
        "Cc": "\"Kamalakannan R .\" <kamalakannan.r@intel.com>",
        "Subject": "[PATCH V2 5/6] table: configure the hash function for learner tables",
        "Date": "Fri, 19 Aug 2022 19:52:24 +0000",
        "Message-Id": "<20220819195225.1483020-6-cristian.dumitrescu@intel.com>",
        "X-Mailer": "git-send-email 2.34.1",
        "In-Reply-To": "<20220819195225.1483020-1-cristian.dumitrescu@intel.com>",
        "References": "<20220818114449.1408226-1-cristian.dumitrescu@intel.com>\n <20220819195225.1483020-1-cristian.dumitrescu@intel.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org"
    },
    "content": "Make the hash function configurable. The internal hash function that\nwas not configurable, mask-based and limited to 64 bytes is removed.\n\nSigned-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>\nSigned-off-by: Kamalakannan R. <kamalakannan.r@intel.com>\n---\n lib/table/rte_swx_table_learner.c | 220 ++++--------------------------\n lib/table/rte_swx_table_learner.h |   6 +\n 2 files changed, 34 insertions(+), 192 deletions(-)",
    "diff": "diff --git a/lib/table/rte_swx_table_learner.c b/lib/table/rte_swx_table_learner.c\nindex f7f8e8aea9..c1045a1082 100644\n--- a/lib/table/rte_swx_table_learner.c\n+++ b/lib/table/rte_swx_table_learner.c\n@@ -8,7 +8,10 @@\n #include <rte_common.h>\n #include <rte_cycles.h>\n #include <rte_prefetch.h>\n+#include <rte_jhash.h>\n+#include <rte_hash_crc.h>\n \n+#include \"rte_swx_keycmp.h\"\n #include \"rte_swx_table_learner.h\"\n \n #ifndef RTE_SWX_TABLE_LEARNER_USE_HUGE_PAGES\n@@ -62,181 +65,10 @@ env_free(void *start, size_t size)\n \n #endif\n \n-#if defined(RTE_ARCH_X86_64)\n-\n-#include <x86intrin.h>\n-\n-#define crc32_u64(crc, v) _mm_crc32_u64(crc, v)\n-\n-#else\n-\n-static inline uint64_t\n-crc32_u64_generic(uint64_t crc, uint64_t value)\n-{\n-\tint i;\n-\n-\tcrc = (crc & 0xFFFFFFFFLLU) ^ value;\n-\tfor (i = 63; i >= 0; i--) {\n-\t\tuint64_t mask;\n-\n-\t\tmask = -(crc & 1LLU);\n-\t\tcrc = (crc >> 1LLU) ^ (0x82F63B78LLU & mask);\n-\t}\n-\n-\treturn crc;\n-}\n-\n-#define crc32_u64(crc, v) crc32_u64_generic(crc, v)\n-\n-#endif\n-\n-/* Key size needs to be one of: 8, 16, 32 or 64. */\n-static inline uint32_t\n-hash(void *key, void *key_mask, uint32_t key_size, uint32_t seed)\n-{\n-\tuint64_t *k = key;\n-\tuint64_t *m = key_mask;\n-\tuint64_t k0, k2, k5, crc0, crc1, crc2, crc3, crc4, crc5;\n-\n-\tswitch (key_size) {\n-\tcase 8:\n-\t\tcrc0 = crc32_u64(seed, k[0] & m[0]);\n-\t\treturn crc0;\n-\n-\tcase 16:\n-\t\tk0 = k[0] & m[0];\n-\n-\t\tcrc0 = crc32_u64(k0, seed);\n-\t\tcrc1 = crc32_u64(k0 >> 32, k[1] & m[1]);\n-\n-\t\tcrc0 ^= crc1;\n-\n-\t\treturn crc0;\n-\n-\tcase 32:\n-\t\tk0 = k[0] & m[0];\n-\t\tk2 = k[2] & m[2];\n-\n-\t\tcrc0 = crc32_u64(k0, seed);\n-\t\tcrc1 = crc32_u64(k0 >> 32, k[1] & m[1]);\n-\n-\t\tcrc2 = crc32_u64(k2, k[3] & m[3]);\n-\t\tcrc3 = k2 >> 32;\n-\n-\t\tcrc0 = crc32_u64(crc0, crc1);\n-\t\tcrc1 = crc32_u64(crc2, crc3);\n-\n-\t\tcrc0 ^= crc1;\n-\n-\t\treturn crc0;\n-\n-\tcase 64:\n-\t\tk0 = k[0] & m[0];\n-\t\tk2 = k[2] & m[2];\n-\t\tk5 = k[5] & m[5];\n-\n-\t\tcrc0 = crc32_u64(k0, seed);\n-\t\tcrc1 = crc32_u64(k0 >> 32, k[1] & m[1]);\n-\n-\t\tcrc2 = crc32_u64(k2, k[3] & m[3]);\n-\t\tcrc3 = crc32_u64(k2 >> 32, k[4] & m[4]);\n-\n-\t\tcrc4 = crc32_u64(k5, k[6] & m[6]);\n-\t\tcrc5 = crc32_u64(k5 >> 32, k[7] & m[7]);\n-\n-\t\tcrc0 = crc32_u64(crc0, (crc1 << 32) ^ crc2);\n-\t\tcrc1 = crc32_u64(crc3, (crc4 << 32) ^ crc5);\n-\n-\t\tcrc0 ^= crc1;\n-\n-\t\treturn crc0;\n-\n-\tdefault:\n-\t\tcrc0 = 0;\n-\t\treturn crc0;\n-\t}\n-}\n-\n-/* n_bytes needs to be a multiple of 8 bytes. */\n static void\n-table_keycpy(void *dst, void *src, void *src_mask, uint32_t n_bytes)\n-{\n-\tuint64_t *dst64 = dst, *src64 = src, *src_mask64 = src_mask;\n-\tuint32_t i;\n-\n-\tfor (i = 0; i < n_bytes / sizeof(uint64_t); i++)\n-\t\tdst64[i] = src64[i] & src_mask64[i];\n-}\n-\n-/*\n- * Return: 0 = Keys are NOT equal; 1 = Keys are equal.\n- */\n-static inline uint32_t\n-table_keycmp(void *a, void *b, void *b_mask, uint32_t n_bytes)\n+table_keycpy(void *dst, void *src, uint32_t n_bytes)\n {\n-\tuint64_t *a64 = a, *b64 = b, *b_mask64 = b_mask;\n-\n-\tswitch (n_bytes) {\n-\tcase 8: {\n-\t\tuint64_t xor0 = a64[0] ^ (b64[0] & b_mask64[0]);\n-\t\tuint32_t result = 1;\n-\n-\t\tif (xor0)\n-\t\t\tresult = 0;\n-\t\treturn result;\n-\t}\n-\n-\tcase 16: {\n-\t\tuint64_t xor0 = a64[0] ^ (b64[0] & b_mask64[0]);\n-\t\tuint64_t xor1 = a64[1] ^ (b64[1] & b_mask64[1]);\n-\t\tuint64_t or = xor0 | xor1;\n-\t\tuint32_t result = 1;\n-\n-\t\tif (or)\n-\t\t\tresult = 0;\n-\t\treturn result;\n-\t}\n-\n-\tcase 32: {\n-\t\tuint64_t xor0 = a64[0] ^ (b64[0] & b_mask64[0]);\n-\t\tuint64_t xor1 = a64[1] ^ (b64[1] & b_mask64[1]);\n-\t\tuint64_t xor2 = a64[2] ^ (b64[2] & b_mask64[2]);\n-\t\tuint64_t xor3 = a64[3] ^ (b64[3] & b_mask64[3]);\n-\t\tuint64_t or = (xor0 | xor1) | (xor2 | xor3);\n-\t\tuint32_t result = 1;\n-\n-\t\tif (or)\n-\t\t\tresult = 0;\n-\t\treturn result;\n-\t}\n-\n-\tcase 64: {\n-\t\tuint64_t xor0 = a64[0] ^ (b64[0] & b_mask64[0]);\n-\t\tuint64_t xor1 = a64[1] ^ (b64[1] & b_mask64[1]);\n-\t\tuint64_t xor2 = a64[2] ^ (b64[2] & b_mask64[2]);\n-\t\tuint64_t xor3 = a64[3] ^ (b64[3] & b_mask64[3]);\n-\t\tuint64_t xor4 = a64[4] ^ (b64[4] & b_mask64[4]);\n-\t\tuint64_t xor5 = a64[5] ^ (b64[5] & b_mask64[5]);\n-\t\tuint64_t xor6 = a64[6] ^ (b64[6] & b_mask64[6]);\n-\t\tuint64_t xor7 = a64[7] ^ (b64[7] & b_mask64[7]);\n-\t\tuint64_t or = ((xor0 | xor1) | (xor2 | xor3)) |\n-\t\t\t      ((xor4 | xor5) | (xor6 | xor7));\n-\t\tuint32_t result = 1;\n-\n-\t\tif (or)\n-\t\t\tresult = 0;\n-\t\treturn result;\n-\t}\n-\n-\tdefault: {\n-\t\tuint32_t i;\n-\n-\t\tfor (i = 0; i < n_bytes / sizeof(uint64_t); i++)\n-\t\t\tif (a64[i] != (b64[i] & b_mask64[i]))\n-\t\t\t\treturn 0;\n-\t\treturn 1;\n-\t}\n-\t}\n+\tmemcpy(dst, src, n_bytes);\n }\n \n #define TABLE_KEYS_PER_BUCKET 4\n@@ -259,10 +91,7 @@ struct table_params {\n \t/* The real key size. Must be non-zero. */\n \tsize_t key_size;\n \n-\t/* They key size upgrated to the next power of 2. This used for hash generation (in\n-\t * increments of 8 bytes, from 8 to 64 bytes) and for run-time key comparison. This is why\n-\t * key sizes bigger than 64 bytes are not allowed.\n-\t */\n+\t/* The key size upgrated to the next power of 2. */\n \tsize_t key_size_pow2;\n \n \t/* log2(key_size_pow2). Purpose: avoid multiplication with non-power-of-2 numbers. */\n@@ -299,6 +128,12 @@ struct table_params {\n \t/* log2(bucket_size). Purpose: avoid multiplication with non-power of 2 numbers. */\n \tsize_t bucket_size_log2;\n \n+\t/* Hash function. */\n+\trte_swx_hash_func_t hash_func;\n+\n+\t/* Key comparison function. */\n+\trte_swx_keycmp_func_t keycmp_func;\n+\n \t/* Set of all possible key timeout values measured in CPU clock cycles. */\n \tuint64_t key_timeout[RTE_SWX_TABLE_LEARNER_N_KEY_TIMEOUTS_MAX];\n \n@@ -313,9 +148,6 @@ struct table {\n \t/* Table parameters. */\n \tstruct table_params params;\n \n-\t/* Key mask. Array of *key_size* bytes. */\n-\tuint8_t key_mask0[RTE_CACHE_LINE_SIZE];\n-\n \t/* Table buckets. */\n \tuint8_t buckets[];\n } __rte_cache_aligned;\n@@ -344,7 +176,6 @@ table_params_get(struct table_params *p, struct rte_swx_table_learner_params *pa\n \t/* Check input parameters. */\n \tif (!params ||\n \t    !params->key_size ||\n-\t    (params->key_size > 64) ||\n \t    !params->n_keys_max ||\n \t    (params->n_keys_max > 1U << 31) ||\n \t    !params->key_timeout ||\n@@ -352,6 +183,15 @@ table_params_get(struct table_params *p, struct rte_swx_table_learner_params *pa\n \t    (params->n_key_timeouts > RTE_SWX_TABLE_LEARNER_N_KEY_TIMEOUTS_MAX))\n \t\treturn -EINVAL;\n \n+\tif (params->key_mask0) {\n+\t\tfor (i = 0; i < params->key_size; i++)\n+\t\t\tif (params->key_mask0[i] != 0xFF)\n+\t\t\t\tbreak;\n+\n+\t\tif (i < params->key_size)\n+\t\t\treturn -EINVAL;\n+\t}\n+\n \tfor (i = 0; i < params->n_key_timeouts; i++)\n \t\tif (!params->key_timeout[i])\n \t\t\treturn -EINVAL;\n@@ -360,8 +200,6 @@ table_params_get(struct table_params *p, struct rte_swx_table_learner_params *pa\n \tp->key_size = params->key_size;\n \n \tp->key_size_pow2 = rte_align64pow2(p->key_size);\n-\tif (p->key_size_pow2 < 8)\n-\t\tp->key_size_pow2 = 8;\n \n \tp->key_size_log2 = __builtin_ctzll(p->key_size_pow2);\n \n@@ -387,6 +225,10 @@ table_params_get(struct table_params *p, struct rte_swx_table_learner_params *pa\n \n \tp->bucket_size_log2 = __builtin_ctzll(p->bucket_size);\n \n+\tp->hash_func = params->hash_func ? params->hash_func : rte_hash_crc;\n+\n+\tp->keycmp_func = rte_swx_keycmp_func_get(params->key_size);\n+\n \t/* Timeout. */\n \tfor (i = 0; i < params->n_key_timeouts; i++)\n \t\tp->key_timeout[i] = timeout_convert(params->key_timeout[i]);\n@@ -452,11 +294,6 @@ rte_swx_table_learner_create(struct rte_swx_table_learner_params *params, int nu\n \t/* Memory initialization. */\n \tmemcpy(&t->params, &p, sizeof(struct table_params));\n \n-\tif (params->key_mask0)\n-\t\tmemcpy(t->key_mask0, params->key_mask0, params->key_size);\n-\telse\n-\t\tmemset(t->key_mask0, 0xFF, params->key_size);\n-\n \treturn t;\n }\n \n@@ -534,7 +371,7 @@ rte_swx_table_learner_lookup(void *table,\n \t\tuint32_t input_sig;\n \n \t\tinput_key = &(*key)[t->params.key_offset];\n-\t\tinput_sig = hash(input_key, t->key_mask0, t->params.key_size_pow2, 0);\n+\t\tinput_sig = t->params.hash_func(input_key, t->params.key_size, 0);\n \t\tbucket_id = input_sig & t->params.bucket_mask;\n \t\tb = table_bucket_get(t, bucket_id);\n \n@@ -558,13 +395,12 @@ rte_swx_table_learner_lookup(void *table,\n \t\t\tuint64_t time = b->time[i];\n \t\t\tuint32_t sig = b->sig[i];\n \t\t\tuint8_t *key = table_bucket_key_get(t, b, i);\n-\t\t\tuint32_t key_size_pow2 = t->params.key_size_pow2;\n \n \t\t\ttime <<= 32;\n \n \t\t\tif ((time > input_time) &&\n \t\t\t    (sig == m->input_sig) &&\n-\t\t\t    table_keycmp(key, m->input_key, t->key_mask0, key_size_pow2)) {\n+\t\t\t    t->params.keycmp_func(key, m->input_key, t->params.key_size)) {\n \t\t\t\tuint64_t *data = table_bucket_data_get(t, b, i);\n \n \t\t\t\t/* Hit. */\n@@ -703,7 +539,7 @@ rte_swx_table_learner_add(void *table,\n \t\t\tb->time[i] = (input_time + key_timeout) >> 32;\n \t\t\tb->sig[i] = m->input_sig;\n \t\t\tb->key_timeout_id[i] = (uint8_t)key_timeout_id;\n-\t\t\ttable_keycpy(key, m->input_key, t->key_mask0, t->params.key_size_pow2);\n+\t\t\ttable_keycpy(key, m->input_key, t->params.key_size);\n \n \t\t\t/* Install the key data. */\n \t\t\tdata[0] = action_id;\ndiff --git a/lib/table/rte_swx_table_learner.h b/lib/table/rte_swx_table_learner.h\nindex 1fee306806..d72b6b88ff 100644\n--- a/lib/table/rte_swx_table_learner.h\n+++ b/lib/table/rte_swx_table_learner.h\n@@ -50,6 +50,8 @@ extern \"C\" {\n \n #include <rte_compat.h>\n \n+#include \"rte_swx_hash_func.h\"\n+\n /** Maximum number of key timeout values per learner table. */\n #ifndef RTE_SWX_TABLE_LEARNER_N_KEY_TIMEOUTS_MAX\n #define RTE_SWX_TABLE_LEARNER_N_KEY_TIMEOUTS_MAX 16\n@@ -77,6 +79,10 @@ struct rte_swx_table_learner_params {\n \t */\n \tuint32_t action_data_size;\n \n+\t/** Hash function. When NULL, the default hash function will be used.\n+\t */\n+\trte_swx_hash_func_t hash_func;\n+\n \t/** Maximum number of keys to be stored in the table together with their associated data. */\n \tuint32_t n_keys_max;\n \n",
    "prefixes": [
        "V2",
        "5/6"
    ]
}