From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0063.outbound.protection.outlook.com [104.47.34.63]) by dpdk.org (Postfix) with ESMTP id 1EB9D5F6E for ; Thu, 17 May 2018 03:27:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KYsiuDrBSj19NuJkqINeGyeqzOCmLuMmaAT1rXuoSPc=; b=AqRSriZ6V5rH4pXMu5SzgMAJaewjcNitlU688beq9DwHWS8D1FKPAPRsFksaQ2aRBN/hXEYg1wpwVO8cK2yztMtbNywnBOVq1d1eM91fau6x9yI0g2A+oYxHwyNlIOcqugTnUPzY+NPdlRMSJwFupb/nk1y9KWK9ob5A6FHaRHM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Vijaya.Guvva@cavium.com; Received: from vsr-t630.caveonetworks.com (50.233.148.156) by BN7PR07MB4881.namprd07.prod.outlook.com (2603:10b6:406:ef::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.776.11; Thu, 17 May 2018 01:27:08 +0000 From: Vijaya Mohan Guvva To: Bruce Richardson , Pablo de Lara Cc: dev@dpdk.org, Vijaya Mohan Guvva Date: Wed, 16 May 2018 18:26:33 -0700 Message-Id: <1526520393-19295-1-git-send-email-vguvva@caviumnetworks.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [50.233.148.156] X-ClientProxiedBy: CO1PR15CA0092.namprd15.prod.outlook.com (2603:10b6:101:21::12) To BN7PR07MB4881.namprd07.prod.outlook.com (2603:10b6:406:ef::22) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020); SRVR:BN7PR07MB4881; X-Microsoft-Exchange-Diagnostics: 1; BN7PR07MB4881; 3:3Y3+u1ynxH7K/yZwK8FdBtgl8g3cFs2TCPDWrdrFWhyAQEMqszIw/zdmADd/lN6UeMdh9x2ETsoiHFRPzsFlhHDwc/opYnectj/e4M4eJCesyuEZJeEZCWnS/HVKdrVSWXVgnlYEEnUZVPcu3AdaG8Ekz88gbS0IEqeM0+HgY2H5bS4iSmKsXvdxv1LT+vhRCeFZfX8H2JKqcWrPxyjhKprUbthKKvXvYvN2Oxe4Ffn2m3VppRiNeZxqS61b/XHP; 25:iVodNU+Xc1xvMgFMjJ0BmzOde2th4caFD5XGzgzhlIC5dZVTD+/8sL2+b7TLKCMBj5wxVCtfy5pZSv/46N0I1iGPmgVMyKcCx2ZAIi9kCKctKEnZIr7QHeOS8/WEpvcbh1yBxwPGKd2Jcu4DSTCiuMF8P5sSK9IilXzYNrxkdTCHyS1EBpgOHaMz/EEQ5yFzONXpeqQIzXhA5K0h81TSXkXasixajCSg8yWTgrAPwUWV9zqokeFwrbiauFM+IUuz1law56sgOhNXOoukYokfI0+dehS8gJ8I/0tXtmIDDSCDRRAjRi4hKEQqZmX9sVPa2WXMqEaufjYfOGuEpidtJQ==; 31:P+oClpNhB6m5k8MGnQEJQAOX/hlb7V1TscyLf8kZRFWZoj+6RLt9jolRjdXqpqq7H/G/dbKTM1f6jrn+weS61dBlLPVuQLFsNsIOd77j+r06Etg54HydNDWzvIeQocSB4y/HX/8Vmv8TD97RnTedol4gS1syBs/z1XVKLSewkxeD/y7cM2DCwxKRmA7KOdkIsoFGwdrOJkEmS8lphmCDm5iJZgkyBK0U8oWukn8YuUA= X-MS-TrafficTypeDiagnostic: BN7PR07MB4881: X-Microsoft-Exchange-Diagnostics: 1; BN7PR07MB4881; 20:k4yhRf79EIetmzDMq81hU5sABwmk12FSOmu9XyWWDoIDSjqwLDwiyaL1GhBnDZBDyAzeOptD7g2vfZysFwgUT37ObA+ZGfBem8VOOWNo9Fw/u5VAbumeiJnSOeU3IJym+Z+Y7LRzN6Gk7u/JD1eQ2nY+dwIVfPr25ibNlD05uZNteZZpabLbyHe12zgf2cuETUMvN4DPLKvOaJr35Jw1l/uEQXtPXQA72jHtbUnCDqFWjZu8OhT/O9ggX49Vs3i7fOPtwjeZCQ0EbuqlvZxPLtHG3XqDkdzpTO8MLRrF0fMMsOEkW5ohmMDFc2aZgMizyBzJDzdWLShnpXSNH6PhsokWGyJiDJIk2MPbvUyUDR9aexZ89w7D2fX3uGKlQnRvqpXjUxkNXoR+glzTTt9YAXeyRkzlD6HgA82mfMj0xt1vil9b8W7dmI1hSnyie98EM4S9HXH+kCddcRRuSyGp5qTMlB0UfWFVOSklejzSoMbdIhqWIL7Kf59hObYyY+lNKA6UpHdTHyntQLuqqyplzU+/Fi5pDbTNFOO/le9F10ffHX5EFaAEDBtEjwhqxe9eRZQlEP8w9Mtv+8hqktURFFNW6F7bppBXrc6aCRL33ec=; 4:Grn0zeyWKqAktMjAk2e9a/HZut9Q9M+un+4B6WxjNEDSpU7/ks9OEHHZ8ZLlgP3Xy6EAskk4CoSo/UKUuOKHYw2+z14LxiyZiRANzYX3Ex6zuQWDRioHKrBrYvcLIOcgJxl+0MK91xAnMsZd/89neTsY1k7xXwrHo0lw+SGQK7fT4nNurzXGKerkSK8Sc477RHAWNyxIIIz07eq62Zz+eT0CBRpc5J0CmNgrsGaEYYV0eDaB80+vaarLTHWagq0zuWRMhSxmEK250rStQwIDEg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3002001)(3231254)(944501410)(52105095)(93006095)(149027)(150027)(6041310)(20161123560045)(20161123562045)(20161123564045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011)(7699016); SRVR:BN7PR07MB4881; BCL:0; PCL:0; RULEID:; SRVR:BN7PR07MB4881; X-Forefront-PRVS: 067553F396 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(39860400002)(396003)(39380400002)(366004)(346002)(376002)(199004)(189003)(110136005)(51416003)(575784001)(2906002)(7736002)(4326008)(305945005)(6486002)(81156014)(81166006)(8676002)(52116002)(36756003)(48376002)(26005)(478600001)(6512007)(25786009)(6666003)(53936002)(50466002)(16526019)(186003)(16586007)(97736004)(66066001)(47776003)(106356001)(8936002)(316002)(72206003)(486006)(53416004)(59450400001)(956004)(476003)(105586002)(50226002)(2616005)(4720700003)(69596002)(6506007)(3846002)(5660300001)(107886003)(6116002)(386003)(68736007)(42882007); DIR:OUT; SFP:1101; SCL:1; SRVR:BN7PR07MB4881; H:vsr-t630.caveonetworks.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN7PR07MB4881; 23:CTdbkyEaizj8zC0DxE16a+W+1ZYBFZnITn91MBiDY?= =?us-ascii?Q?mEi7HRXa+oskR78EmC9ukQ38zq23+QMwnyn6jn35h7vhZRErA2yDB5bgrkjd?= =?us-ascii?Q?XpwZCpjte95QDHgyFzIb8v05ugje4lj3KRcmUeHOwjj4K1QN+Fim2GJIBrFT?= =?us-ascii?Q?72oAGGeXosSuv4MizEIahOOTjtMcL6DSfDg9cS9B7Z+hcFOdNiSGen1viecH?= =?us-ascii?Q?MBfc+TIOi5Y95j8jtFCxSgrodBZCT/hwGAs/ZeuL/hZcqhDb5cUdkc0G+6wm?= =?us-ascii?Q?7BCSWTGFD1zoOgf1PupWh1pnh8dZR2r3EtK45GmLhUdSp1GjggkG+M9THvyf?= =?us-ascii?Q?YifaWRTP4EHBk3E7ankbagNBr/u/qE+fnrFsfu3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8CCW2XFkUe7DlSmsSU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; BN7PR07MB4881; 7:Gu/u7RNwspO2NBhMcllc2bZ/C7i4g4kWsvp0eo+9SDbDHFNi8h5IpyeMhnnUUwrv4FA9Lj8Be/redp1LZ5uc3D43N4r0bwbrrN38HWVo6+6rS6MRaanokVQKLxZ261P0fwiwIhSbrgVD3NNzP0ma00glhbvI9JBz56o1lDs7GfmmByDAFihF/VdVwLzuNaWdvYdMh6jEG1p/WNMS8Gzp4B1lIdQ3irFQjm2InbWldtaPvgVTtbYI9dFTkbYNvoC8 X-MS-Office365-Filtering-Correlation-Id: 11cc476b-c95d-49c6-73d3-08d5bb954f07 X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2018 01:27:08.7421 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 11cc476b-c95d-49c6-73d3-08d5bb954f07 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR07MB4881 Subject: [dpdk-dev] [PATCH V2] librte_hash: new hash del abi to return stored value X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 May 2018 01:27:11 -0000 V2: Adding another new interface rte_hash_del_key_data to delete key from hash table and return stored data. V1: Add a new key delete interface rte_hash_del_key_with_hash_data to delete the key from hash and return the value stored. This is useful for hash users to free the data stored in the table after key delete and to avoid maintaining a user data array in the dpdk application. Signed-off-by: Vijaya Mohan Guvva --- lib/librte_hash/rte_cuckoo_hash.c | 30 +++++++++++++++++++++++--- lib/librte_hash/rte_hash.h | 45 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c index a07543a..6ea0ef0 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -808,7 +808,7 @@ struct rte_hash * static inline int32_t __rte_hash_del_key_with_hash(const struct rte_hash *h, const void *key, - hash_sig_t sig) + hash_sig_t sig, void **data) { uint32_t bucket_idx; hash_sig_t alt_hash; @@ -827,6 +827,8 @@ struct rte_hash * k = (struct rte_hash_key *) ((char *)keys + bkt->key_idx[i] * h->key_entry_size); if (rte_hash_cmp_eq(key, k->key, h) == 0) { + if (data != NULL) + *data = k->pdata; remove_entry(h, bkt, i); /* @@ -852,6 +854,8 @@ struct rte_hash * k = (struct rte_hash_key *) ((char *)keys + bkt->key_idx[i] * h->key_entry_size); if (rte_hash_cmp_eq(key, k->key, h) == 0) { + if (data != NULL) + *data = k->pdata; remove_entry(h, bkt, i); /* @@ -869,18 +873,38 @@ struct rte_hash * } int32_t +rte_hash_del_key_with_hash_data(const struct rte_hash *h, + const void *key, hash_sig_t sig, void **data) +{ + RETURN_IF_TRUE(((h == NULL) || (key == NULL) || + (data == NULL)), -EINVAL); + return __rte_hash_del_key_with_hash(h, key, sig, data); +} + +int32_t rte_hash_del_key_with_hash(const struct rte_hash *h, const void *key, hash_sig_t sig) { RETURN_IF_TRUE(((h == NULL) || (key == NULL)), -EINVAL); - return __rte_hash_del_key_with_hash(h, key, sig); + return __rte_hash_del_key_with_hash(h, key, sig, NULL); +} + +int32_t +rte_hash_del_key_data(const struct rte_hash *h, const void *key, + void **data) +{ + RETURN_IF_TRUE(((h == NULL) || (key == NULL) || + (data == NULL)), -EINVAL); + return __rte_hash_del_key_with_hash(h, key, + rte_hash_hash(h, key), data); } int32_t rte_hash_del_key(const struct rte_hash *h, const void *key) { RETURN_IF_TRUE(((h == NULL) || (key == NULL)), -EINVAL); - return __rte_hash_del_key_with_hash(h, key, rte_hash_hash(h, key)); + return __rte_hash_del_key_with_hash(h, key, + rte_hash_hash(h, key), NULL); } int diff --git a/lib/librte_hash/rte_hash.h b/lib/librte_hash/rte_hash.h index f71ca9f..e0c08e3 100644 --- a/lib/librte_hash/rte_hash.h +++ b/lib/librte_hash/rte_hash.h @@ -222,6 +222,51 @@ struct rte_hash * rte_hash_del_key(const struct rte_hash *h, const void *key); /** + * Remove a key from an existing hash table and return data stored. + * This operation is not multi-thread safe + * and should only be called from one thread. + * + * @param h + * Hash table to remove the key from. + * @param key + * Key to remove from the hash table. + * @param data + * Output with pointer to data returned from the hash table. + * @return + * - -EINVAL if the parameters are invalid. + * - -ENOENT if the key is not found. + * - A positive value that can be used by the caller as an offset into an + * array of user data. This value is unique for this key, and is the same + * value that was returned when the key was added. + */ +int32_t +rte_hash_del_key_data(const struct rte_hash *h, const void *key, void **data); + +/** + * Remove a key from an existing hash table and return data stored. + * This operation is not multi-thread safe + * and should only be called from one thread. + * + * @param h + * Hash table to remove the key from. + * @param key + * Key to remove from the hash table. + * @param sig + * Precomputed hash value for 'key'. + * @param data + * Output with pointer to data returned from the hash table. + * @return + * - -EINVAL if the parameters are invalid. + * - -ENOENT if the key is not found. + * - A positive value that can be used by the caller as an offset into an + * array of user data. This value is unique for this key, and is the same + * value that was returned when the key was added. + */ +int32_t +rte_hash_del_key_with_hash_data(const struct rte_hash *h, const void *key, + hash_sig_t sig, void **data); + +/** * Remove a key from an existing hash table. * This operation is not multi-thread safe * and should only be called from one thread. -- 1.8.3.1