From patchwork Mon Oct 23 08:29:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QWJkdWxsYWggw5ZtZXIgWWFtYcOn?= X-Patchwork-Id: 133162 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: 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]) by inbox.dpdk.org (Postfix) with ESMTP id 87337431E0; Mon, 23 Oct 2023 10:29:33 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1175040270; Mon, 23 Oct 2023 10:29:33 +0200 (CEST) Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by mails.dpdk.org (Postfix) with ESMTP id 5443C40262 for ; Mon, 23 Oct 2023 10:29:31 +0200 (CEST) Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-407c3adef8eso26081165e9.2 for ; Mon, 23 Oct 2023 01:29:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698049770; x=1698654570; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WKbh1IAKSTAEZxBGJGYhjllWvUJ292nR26+w+5vlF7A=; b=XuuTATow3lKeVuHA39rwq0parYl+/rMqbtnOhsMw4DEm3suk41zB+BgiSreYyMG/p6 1ABRmEu0VN0fYywo8c0iMvnVPvV/R1mlHH4+J6pT0Txp1e8f2Rn8MGy7CIObtHMOd2Ld 45xB650aFtUWviuRdXIQakFgqAenhtEdP4MMNhdd7iYOanPXhEcUWkw1r7rkT9qWngna LXHefETXTGW/k7c280phu+00yw5YLM1ThF1B6WRuiYEWrnJ4ExBdp3kNeMZi0O0XUuZD bTRX16trCtfUw+0xZYwic88KQeSSM61YoRIzqLbhOphY7xgRsEL0NcQQVItdt6dA8BSC VL9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698049770; x=1698654570; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WKbh1IAKSTAEZxBGJGYhjllWvUJ292nR26+w+5vlF7A=; b=s0mWR+lN+OJIemN1HkoH4QCzFY5cKPHmg75L7icnEkONlfcs9LjOdOidLJZS/sGH2k nbdtLL1brKCJU0aPTNUlABnazj8Og9FBN2lvxr/eALKy7zNh5GcaRkfx1qO7WMVZEGM4 nBrqYny/4IOln8NbftDUolfbB7+UpPW3wBHMfsZu8EYhhaNCv9tAYWNpOGJluTh6vlcX Z0VNyGRg0UWtbFGIewmDWgCR8sB+qSBS2TgiyA1YC+r+Fj8bqJbjhEBTS8l3DKWlkLNU kDpdNBabPOQbK5wmm/cMr58lfFb/vXnymM2CQ+iiAB76UvNyq99OTMyhB9UCQqPX0fTp ehJQ== X-Gm-Message-State: AOJu0YwjPprtL4VztIPr06pJtFG79wh3GOiOf9xkQjQwWb+3Qh0HOHNU 1RkyYG1iTALxZUksN7fy5YbP+fqTi0HwxE6C X-Google-Smtp-Source: AGHT+IHfxQpaKw4Vu8KNfx9GSzTE14aWj5Tk17xUSuOTS8Z8N0p8HA18zlbADSf6EGSJTskysdOQEQ== X-Received: by 2002:a05:600c:35ca:b0:405:3955:5872 with SMTP id r10-20020a05600c35ca00b0040539555872mr7247607wmq.18.1698049770365; Mon, 23 Oct 2023 01:29:30 -0700 (PDT) Received: from dcu.otaknetworks.com ([212.156.37.190]) by smtp.gmail.com with ESMTPSA id o27-20020a05600c511b00b004067e905f44sm8921007wms.9.2023.10.23.01.29.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 01:29:29 -0700 (PDT) From: =?utf-8?b?QWJkdWxsYWggw5ZtZXIgWWFtYcOn?= To: dev@dpdk.org Cc: =?utf-8?b?QWJkdWxsYWggw5ZtZXIgWWFtYcOn?= , Yipeng Wang , Sameh Gobriel , Bruce Richardson , Vladimir Medvedkin , David Marchand Subject: [PATCH v2] lib/hash: new feature adding existing key Date: Mon, 23 Oct 2023 08:29:25 +0000 Message-Id: <20231023082925.256141-1-aomeryamac@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Abdullah Ömer Yamaç In some use cases inserting data with the same key shouldn't be overwritten. We use a new flag in this patch to disable overwriting data for the same key. Signed-off-by: Abdullah Ömer Yamaç --- Cc: Yipeng Wang Cc: Sameh Gobriel Cc: Bruce Richardson Cc: Vladimir Medvedkin Cc: David Marchand --- lib/hash/rte_cuckoo_hash.c | 10 +++++++++- lib/hash/rte_cuckoo_hash.h | 2 ++ lib/hash/rte_hash.h | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/hash/rte_cuckoo_hash.c b/lib/hash/rte_cuckoo_hash.c index 19b23f2a97..fe8f21bee4 100644 --- a/lib/hash/rte_cuckoo_hash.c +++ b/lib/hash/rte_cuckoo_hash.c @@ -32,7 +32,8 @@ RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY | \ RTE_HASH_EXTRA_FLAGS_EXT_TABLE | \ RTE_HASH_EXTRA_FLAGS_NO_FREE_ON_DEL | \ - RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF) + RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF | \ + RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY) #define FOR_EACH_BUCKET(CURRENT_BKT, START_BUCKET) \ for (CURRENT_BKT = START_BUCKET; \ @@ -148,6 +149,7 @@ rte_hash_create(const struct rte_hash_parameters *params) unsigned int readwrite_concur_support = 0; unsigned int writer_takes_lock = 0; unsigned int no_free_on_del = 0; + unsigned int no_update_data = 0; uint32_t *ext_bkt_to_free = NULL; uint32_t *tbl_chng_cnt = NULL; struct lcore_cache *local_free_slots = NULL; @@ -216,6 +218,9 @@ rte_hash_create(const struct rte_hash_parameters *params) no_free_on_del = 1; } + if (params->extra_flag & RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY) + no_update_data = 1; + /* Store all keys and leave the first entry as a dummy entry for lookup_bulk */ if (use_local_cache) /* @@ -428,6 +433,7 @@ rte_hash_create(const struct rte_hash_parameters *params) h->ext_table_support = ext_table_support; h->writer_takes_lock = writer_takes_lock; h->no_free_on_del = no_free_on_del; + h->no_update_data = no_update_data; h->readwrite_concur_lf_support = readwrite_concur_lf_support; #if defined(RTE_ARCH_X86) @@ -707,6 +713,8 @@ search_and_update(const struct rte_hash *h, void *data, const void *key, 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 (h->no_update_data == 1) + return -EINVAL; /* The store to application data at *data * should not leak after the store to pdata * in the key store. i.e. pdata is the guard diff --git a/lib/hash/rte_cuckoo_hash.h b/lib/hash/rte_cuckoo_hash.h index eb2644f74b..e8b7283ec2 100644 --- a/lib/hash/rte_cuckoo_hash.h +++ b/lib/hash/rte_cuckoo_hash.h @@ -193,6 +193,8 @@ struct rte_hash { /**< If read-write concurrency support is enabled */ uint8_t ext_table_support; /**< Enable extendable bucket table */ uint8_t no_free_on_del; + /**< If update is prohibited on adding same key */ + uint8_t no_update_data; /**< If key index should be freed on calling rte_hash_del_xxx APIs. * If this is set, rte_hash_free_key_with_position must be called to * free the key index associated with the deleted entry. diff --git a/lib/hash/rte_hash.h b/lib/hash/rte_hash.h index 7ecc021111..ca5b4841d2 100644 --- a/lib/hash/rte_hash.h +++ b/lib/hash/rte_hash.h @@ -55,6 +55,10 @@ extern "C" { */ #define RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF 0x20 +/** Flag to disable updating data of existing key + */ +#define RTE_HASH_EXTRA_FLAGS_DISABLE_UPDATE_EXISTING_KEY 0x40 + /** * The type of hash value of a key. * It should be a value of at least 32bit with fully random pattern.