From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jerin Jacob Subject: Re: [PATCH 3/4] hash: remove memory orderings from rw-lock lookup fns Date: Sat, 10 Nov 2018 08:51:29 +0000 Message-ID: <20181110085100.GA14682@jerin> References: <20181109163917.16845-1-honnappa.nagarahalli@arm.com> <20181109163917.16845-4-honnappa.nagarahalli@arm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Cc: "bruce.richardson@intel.com" , "pablo.de.lara.guarch@intel.com" , "dev@dpdk.org" , "hemant.agrawal@nxp.com" , "chaozhu@linux.vnet.ibm.com" , "yipeng1.wang@intel.com" , "dharmik.thakkar@arm.com" , "gavin.hu@arm.com" , "nd@arm.com" To: Honnappa Nagarahalli Return-path: Received: from NAM04-CO1-obe.outbound.protection.outlook.com (mail-eopbgr690052.outbound.protection.outlook.com [40.107.69.52]) by dpdk.org (Postfix) with ESMTP id 6A478201 for ; Sat, 10 Nov 2018 09:51:33 +0100 (CET) In-Reply-To: <20181109163917.16845-4-honnappa.nagarahalli@arm.com> Content-Language: en-US Content-ID: <8F8061C9277A5944BABB2264EA9B3B0B@namprd07.prod.outlook.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" -----Original Message----- > Date: Fri, 9 Nov 2018 10:39:16 -0600 > From: Honnappa Nagarahalli > To: bruce.richardson@intel.com, pablo.de.lara.guarch@intel.com > CC: dev@dpdk.org, jerin.jacob@caviumnetworks.com, hemant.agrawal@nxp.com, > chaozhu@linux.vnet.ibm.com, yipeng1.wang@intel.com, > dharmik.thakkar@arm.com, gavin.hu@arm.com, honnappa.nagarahalli@arm.com, > nd@arm.com > Subject: [PATCH 3/4] hash: remove memory orderings from rw-lock lookup fn= s > X-Mailer: git-send-email 2.17.1 >=20 >=20 > Remove the memory orderings from lookup functions using > rw-lock. > This is an intermediate commit meant to ease the > review process. >=20 > Fixes: e605a1d36 ("hash: add lock-free r/w concurrency") > Cc: honnappa.nagarahalli@arm.com >=20 > Suggested-by: Jerin Jacob > Signed-off-by: Honnappa Nagarahalli > Reviewed-by: Ola Liljedahl > Reviewed-by: Gavin Hu > --- > lib/librte_hash/rte_cuckoo_hash.c | 277 +++++++++++------------------- > 1 file changed, 105 insertions(+), 172 deletions(-) >=20 > diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuck= oo_hash.c > index e6b84c6bc..9390dc5e4 100644 > --- a/lib/librte_hash/rte_cuckoo_hash.c > +++ b/lib/librte_hash/rte_cuckoo_hash.c > @@ -1135,27 +1135,22 @@ search_one_bucket(const struct rte_hash *h, const= void *key, uint16_t sig, > void **data, const struct rte_hash_bucket *bkt) > { > int i; > - uint32_t key_idx; > - void *pdata; > struct rte_hash_key *k, *keys =3D h->key_store; >=20 > for (i =3D 0; i < RTE_HASH_BUCKET_ENTRIES; i++) { > - key_idx =3D __atomic_load_n(&bkt->key_idx[i], > - __ATOMIC_ACQUIRE); > - if (bkt->sig_current[i] =3D=3D sig && key_idx !=3D EMPTY_= SLOT) { > + if (bkt->sig_current[i] =3D=3D sig && > + bkt->key_idx[i] !=3D EMPTY_SLOT) { > k =3D (struct rte_hash_key *) ((char *)keys + > - key_idx * h->key_entry_size); > - pdata =3D __atomic_load_n(&k->pdata, > - __ATOMIC_ACQUIRE); > + bkt->key_idx[i] * h->key_entry_si= ze); >=20 > if (rte_hash_cmp_eq(key, k->key, h) =3D=3D 0) { > if (data !=3D NULL) > - *data =3D pdata; > + *data =3D k->pdata; > /* > * Return index where key is stored, > * subtracting the first dummy index > */ > - return key_idx - 1; > + return bkt->key_idx[i] - 1; > } > } > } > @@ -1201,7 +1196,6 @@ __rte_hash_lookup_with_hash(const struct rte_hash *= h, const void *key, > { > uint32_t prim_bucket_idx, sec_bucket_idx; > struct rte_hash_bucket *bkt, *cur_bkt; > - uint32_t cnt_b, cnt_a; > int ret; > uint16_t short_sig; >=20 > @@ -1211,49 +1205,25 @@ __rte_hash_lookup_with_hash(const struct rte_hash= *h, const void *key, >=20 > __hash_rw_reader_lock(h); >=20 > - do { > - /* Load the table change counter before the lookup > - * starts. Acquire semantics will make sure that > - * loads in search_one_bucket are not hoisted. > - */ > - cnt_b =3D __atomic_load_n(h->tbl_chng_cnt, > - __ATOMIC_ACQUIRE); > + /* Check if key is in primary location */ > + bkt =3D &h->buckets[prim_bucket_idx]; In original version, this bkt assignment is before to __hash_rw_reader_lock= (). This causing performance issue in lookup 'hit' case. Following change is fixing it.i.e bringing back to orginal version. [master]83xx1.2[dpdk]# git diff diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c index 7e1a9ac96..bc8a55f0f 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -1204,10 +1204,11 @@ __rte_hash_lookup_with_hash_l(const struct rte_hash *h, const void *key, prim_bucket_idx =3D get_prim_bucket_index(h, sig); sec_bucket_idx =3D get_alt_bucket_index(h, prim_bucket_idx, short_sig); =20 - __hash_rw_reader_lock(h); - /* Check if key is in primary location */ bkt =3D &h->buckets[prim_bucket_idx]; + + __hash_rw_reader_lock(h); + ret =3D search_one_bucket_l(h, key, short_sig, data, bkt); if (ret !=3D -1) { __hash_rw_reader_unlock(h); Could you send the final version that needs to taken into tree. i.e remove intermediate commits only for review purpose. I can test it finally with that.