From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 5815D1B148 for ; Fri, 28 Sep 2018 03:33:42 +0200 (CEST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Sep 2018 18:33:34 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,312,1534834800"; d="scan'208";a="267588039" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga006.fm.intel.com with ESMTP; 27 Sep 2018 18:33:31 -0700 Received: from fmsmsx112.amr.corp.intel.com (10.18.116.6) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 27 Sep 2018 18:33:31 -0700 Received: from fmsmsx151.amr.corp.intel.com ([169.254.7.87]) by FMSMSX112.amr.corp.intel.com ([169.254.5.184]) with mapi id 14.03.0319.002; Thu, 27 Sep 2018 18:33:30 -0700 From: "Wang, Yipeng1" To: Honnappa Nagarahalli , "Richardson, Bruce" , "De Lara Guarch, Pablo" CC: "dev@dpdk.org" , "gavin.hu@arm.com" , "steve.capper@arm.com" , "ola.liljedahl@arm.com" , "nd@arm.com" , "Gobriel, Sameh" Thread-Topic: [dpdk-dev] [PATCH 4/4] hash: enable lock-free reader-writer concurrency Thread-Index: AQHURgUYvD/59ef/50aa9CWNa3bnXaUFAShw Date: Fri, 28 Sep 2018 01:33:29 +0000 Message-ID: References: <1536253938-192391-1-git-send-email-honnappa.nagarahalli@arm.com> <1536253938-192391-5-git-send-email-honnappa.nagarahalli@arm.com> In-Reply-To: <1536253938-192391-5-git-send-email-honnappa.nagarahalli@arm.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiODI5MzJiYWItNGZkNi00MjgwLTkxNWYtYzFkY2NlZjUzYWMxIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoieTRGd2JFZ3o2VG8yZmx0NE5FcFpnc3phT1wvWVhjcUVlbHUwXC9aYk9UNllVN0xheVRXRTJnQ1NwZXNNWmJYNDFUIn0= x-originating-ip: [10.1.200.106] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH 4/4] hash: enable lock-free reader-writer concurrency 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: Fri, 28 Sep 2018 01:33:44 -0000 Reply inlined: >-----Original Message----- >From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Honnappa Nagarahalli >Sent: Thursday, September 6, 2018 10:12 AM >To: Richardson, Bruce ; De Lara Guarch, Pablo = >Cc: dev@dpdk.org; honnappa.nagarahalli@dpdk.org; gavin.hu@arm.com; steve.c= apper@arm.com; ola.liljedahl@arm.com; >nd@arm.com; Honnappa Nagarahalli >Subject: [dpdk-dev] [PATCH 4/4] hash: enable lock-free reader-writer concu= rrency > >Add the flag to enable reader-writer concurrency during >run time. The rte_hash_del_xxx APIs do not free the keystore >element when this flag is enabled. Hence a new API, >rte_hash_free_key_with_position, to free the key store element >is added. > >+/** Flag to support lock free reader writer concurrency */ >+#define RTE_HASH_EXTRA_FLAGS_RW_CONCURRENCY_LF 0x08 [Wang, Yipeng] It would be good to indicate that the lockless implementatio= n works for single writer multiple readers. Also, if people use a mix of the flags for example set both multiwriter and= LF flags, then I guess either we need to return an error or maybe multiwriter should have higher priority. Currently the RW_CONCURRENCY= will assume MULTI_WRITER_ADD I think. >+ > /** Signature of key that is stored internally. */ > typedef uint32_t hash_sig_t; > >@@ -143,6 +148,11 @@ rte_hash_count(const struct rte_hash *h); > * and should only be called from one thread by default. > * Thread safety can be enabled by setting flag during > * table creation. >+ * When lock free reader writer concurrency is enabled, >+ * if this API is called to update an existing entry, >+ * the application should free any memory allocated for >+ * previous 'data' only after all the readers have stopped >+ * using previous 'data'. [Wang, Yipeng] Could you be more specific on this description? When add_key API is called, the users do not know if it will update an existing entry or inserting a new one, do they? > * > * @param h > * Hash table to add the key to. >@@ -165,6 +175,11 @@ rte_hash_add_key_data(struct rte_hash *h, const void = *key, void *data); > * and should only be called from one thread by default. > * Thread safety can be enabled by setting flag during > * table creation. >+ * When lock free reader writer concurrency is enabled, >+ * if this API is called to update an existing entry, >+ * the application should free any memory allocated for >+ * previous 'data' only after all the readers have stopped >+ * using previous 'data'. > * > * @param h > * Hash table to add the key to. >@@ -230,6 +245,12 @@ rte_hash_add_key_with_hash(struct rte_hash *h, const = void *key, hash_sig_t sig); > * and should only be called from one thread by default. > * Thread safety can be enabled by setting flag during > * table creation. >+ * If lock free reader writer concurrency is enabled, >+ * the hash library's internal memory for the deleted >+ * key is not freed. It should be freed by calling >+ * rte_hash_free_key_with_position API after all >+ * the readers have stopped using the hash entry >+ * corresponding to this key. > * > * @param h > * Hash table to remove the key from. >@@ -241,6 +262,8 @@ rte_hash_add_key_with_hash(struct rte_hash *h, const v= oid *key, hash_sig_t sig); > * - 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. >+ * When lock free concurrency is enabled, this value should be used >+ * while calling the rte_hash_free_key_with_position API. > */ > int32_t > rte_hash_del_key(const struct rte_hash *h, const void *key); >@@ -251,6 +274,12 @@ rte_hash_del_key(const struct rte_hash *h, const void= *key); > * and should only be called from one thread by default. > * Thread safety can be enabled by setting flag during > * table creation. >+ * If lock free reader writer concurrency is enabled, >+ * the hash library's internal memory for the deleted >+ * key is not freed. It should be freed by calling >+ * rte_hash_free_key_with_position API after all >+ * the readers have stopped using the hash entry >+ * corresponding to this key. > * > * @param h > * Hash table to remove the key from. >@@ -264,6 +293,8 @@ rte_hash_del_key(const struct rte_hash *h, const void = *key); > * - 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. >+ * When lock free concurrency is enabled, this value should be used >+ * while calling the rte_hash_free_key_with_position API. > */ > int32_t > rte_hash_del_key_with_hash(const struct rte_hash *h, const void *key, has= h_sig_t sig); >@@ -290,6 +321,30 @@ rte_hash_get_key_with_position(const struct rte_hash = *h, const int32_t position, > void **key); > [Wang, Yipeng] If possible, how about having a new delete function instead = of modifying the current one? I think it does not need to be tied with the lockless implementation, it is= orthogonal to multi-threading implementation. people using locks may still want this new deletion behavior. If people want old behavior, they can call current API, otherwise they can = call the new deletion function, followed by=20 Rte_hash_free_key_with_position later.