From mboxrd@z Thu Jan 1 00:00:00 1970 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) 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=rWf3QAkjOl84mOWMNBnc1L0Ed3aUpdsE4l6DiZHHTpc=; b=bTmM0bKgXHz+8XoRZaUEwTZENbtpPa4haf7fTzc3dcw1j+2OCUTLdAYl0bKa2Oikj938z/p3TC/j4awAmoYe8ANCxn2qnWNF97VgheGmTGK8BdL4EZyAGUuwW8ZxMoPFWOaeH75M/zDXx7p5kNcS/LzfSuKmpDck5O01J5ng2Ho= Received: from SN6PR07MB5008.namprd07.prod.outlook.com (52.135.121.74) by SN6PR07MB4797.namprd07.prod.outlook.com (52.135.77.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1294.25; Sat, 10 Nov 2018 08:51:30 +0000 Received: from SN6PR07MB5008.namprd07.prod.outlook.com ([fe80::913d:1a21:cb40:16de]) by SN6PR07MB5008.namprd07.prod.outlook.com ([fe80::913d:1a21:cb40:16de%3]) with mapi id 15.20.1294.040; Sat, 10 Nov 2018 08:51:30 +0000 From: Jerin Jacob To: Honnappa Nagarahalli 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" Thread-Topic: [PATCH 3/4] hash: remove memory orderings from rw-lock lookup fns Thread-Index: AQHUeErTFUdnjBzv9kCkg6bqE8aAHKVItH2A 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> In-Reply-To: <20181109163917.16845-4-honnappa.nagarahalli@arm.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [115.113.156.3] x-clientproxiedby: PN1PR01CA0076.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:1::16) To SN6PR07MB5008.namprd07.prod.outlook.com (2603:10b6:805:ad::10) x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; SN6PR07MB4797; 6:1qk4sIeLvPSqzYSuJdgNv+rkPw8UyZ3MFCvWAwl/1pYNpwvVHsYWBDd5S5ZKF3BR2bd+uLUnPL64lDmq8V3miORMQ15UalHRXfiOIwYExcOXphuPq7UkTE/apCC2qzW5OTEb2MQ6J8EZMpZLH00ETgPyGU2M5t6gs0XMjQTvSpQOBZY2R90moo2khWUHg62V6OeFXVSj+zGV5dPWgCptO+TA5/jyioLWrTWX6f1MF96E9PbS/BecUBeDKit1tA284U6rjtRDtQxFEju4cyVDiza8rCp2ZcTmJvcCF1SsTU2QhtX/SeSyr1g/X1hWjvzIMDj/Rehen1+Am1jit/ZWDa6tH3KSRH5xH27ZP9VSC0myaM/4/m6Oe2cMEhvZATn+/MbDE1BGnsYZIhEpNJGl3Ci+wYLwGzIMrXpxmCaQiHfJvhfNiP8yeexxayKfKiZiOedswa+QhgT5wFplni0kpQ==; 5:pW5ZgQty7EmZHV+tFLHayF4IzWj/cvJgclD1k1Gh9cMEB2lufqNjEJcNFn+yAkRfwenLSI4oRVuHwB3YCDCIhtPkqYMacTveBc9ShczVqxPPmECD9D+nTDMtsT1ZJ4E9KWeSATmiGwmqVHSQQuLyFNQt2FQ7lVYKSKUD5Ldh+As=; 7:KreBJaTNjb+nkxRTVlTWb3j/34aUgk09nQDVYRIewCnme7lwKv7HmJhn4sQOSDEY3Nmtd8FoLFPDUMyFiXmzTfAkUH1PH4ZDuPPXQGfBjvFB4o56TLd9JqsfEoVv1y4SSx/faoE7yDOxUKu0rfz9EA== x-ms-office365-filtering-correlation-id: 23ecc439-5588-448a-5410-08d646e9b4d2 x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390040)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:SN6PR07MB4797; x-ms-traffictypediagnostic: SN6PR07MB4797: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(228905959029699)(185117386973197)(104084551191319)(180628864354917)(163750095850); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(3231402)(944501410)(52105095)(93006095)(3002001)(148016)(149066)(150057)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123558120)(20161123560045)(201708071742011)(7699051)(76991095); SRVR:SN6PR07MB4797; BCL:0; PCL:0; RULEID:; SRVR:SN6PR07MB4797; x-forefront-prvs: 0852EB6797 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(7916004)(366004)(346002)(376002)(136003)(39850400004)(396003)(13464003)(189003)(199004)(478600001)(97736004)(71200400001)(71190400001)(7736002)(8676002)(81156014)(305945005)(106356001)(8936002)(575784001)(81166006)(72206003)(5660300001)(6916009)(7416002)(2906002)(105586002)(14454004)(54906003)(14444005)(42882007)(66066001)(476003)(11346002)(446003)(256004)(33656002)(316002)(52116002)(76176011)(26005)(6346003)(486006)(102836004)(386003)(6506007)(68736007)(55236004)(33896004)(6116002)(99286004)(33716001)(3846002)(6246003)(9686003)(6512007)(53936002)(229853002)(186003)(25786009)(1076002)(2900100001)(6486002)(4326008)(6436002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN6PR07MB4797; H:SN6PR07MB5008.namprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Jerin.JacobKollanukkaran@cavium.com; x-microsoft-antispam-message-info: 0yX3lrWoo4Y9CLxaZyQQ1UIA3nb0Fv6mH4onlWzDrgxCX1MT+hc8MvDPw4ieTrREjlvP0tKL/kroqUbF/MOPp5bHwQ90EcSRER2Ej7KifW00ohrkRA8dKuuQuxfn9FO+fK9oZ/TZ9+eBL3gqjP6vdDyNxy5SsjmevpDbDQIBrl8mdXwJy36PQe1K1nr1ZkSjLKo7+NgM8DPTkgdLLEa8/hoKNF5eLPH7wrRhrWsoBbS15QZjjIJFWvlDyeVwop5A0L38W4sb5BjXVDfu6LW9Mtf+UQOdDssHc5/0MdpWp9Qy6cSZFZY1UDRgjR6VJj1ZeG4wqgLUh8waHtRBegZ7FIl9WCF0c/iRWBhBN3wuejA= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-ID: <8F8061C9277A5944BABB2264EA9B3B0B@namprd07.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-Network-Message-Id: 23ecc439-5588-448a-5410-08d646e9b4d2 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Nov 2018 08:51:29.9614 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR07MB4797 Subject: Re: [dpdk-dev] [PATCH 3/4] hash: remove memory orderings from rw-lock lookup fns 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: Sat, 10 Nov 2018 08:51:34 -0000 -----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.