From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM02-CY1-obe.outbound.protection.outlook.com (mail-cys01nam02on0081.outbound.protection.outlook.com [104.47.37.81]) by dpdk.org (Postfix) with ESMTP id 1AC5F23D; Wed, 8 Aug 2018 05:07:53 +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=N+ivfVP6LTj1zDku7ASSK8oYMxTu4Ze4Kp7OpH1X9Ho=; b=L5rTICYGECW94rvsS8YkjjJLlTdo/rsRBYpq4bpH2drSBhKIABw+6YDhHVLPeXpqGGegpuhrfGqLyzyDH1wjKXc903X4OBvDgWaFHzhf0yqbBfcXbJFXXKSZukUjIq71mY79rny4Cy48Z6/k+NwGwuGo2GuzkZ+Yh+MN7/luyyk= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jerin.JacobKollanukkaran@cavium.com; Received: from jerin (115.113.156.3) by BYAPR07MB4997.namprd07.prod.outlook.com (2603:10b6:a03:5b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1017.15; Wed, 8 Aug 2018 03:07:47 +0000 Date: Wed, 8 Aug 2018 08:37:31 +0530 From: Jerin Jacob To: Gavin Hu Cc: "He, Jia" , "dev@dpdk.org" , Honnappa Nagarahalli , Steve Capper , Ola Liljedahl , "hemant.agrawal@nxp.com" , "stable@dpdk.org" Message-ID: <20180808030730.GA19236@jerin> References: <20180806011805.7857-1-gavin.hu@arm.com> <20180807031943.5331-1-gavin.hu@arm.com> <88b4421b63ec4802892f3fc40d457f03@HXTBJIDCEMVIW01.hxtcorp.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Originating-IP: [115.113.156.3] X-ClientProxiedBy: PN1PR01CA0077.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:1::17) To BYAPR07MB4997.namprd07.prod.outlook.com (2603:10b6:a03:5b::22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d6821e1f-546c-4c21-6324-08d5fcdc20bd X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:BYAPR07MB4997; X-Microsoft-Exchange-Diagnostics: 1; BYAPR07MB4997; 3:tm1oSTTSWdQZRVih7zsG1xtFEytYOi/m/Y+OIboJk3YKMhnpezMsKuj/X5pFuJ/ruhU6EAu3MWBGfTI17tkrPpPVzYnYXQoJeblumD/N8wJjzuTLstzG5g3GCJxIK8ixZnBfQdyaEPEbSt3nRaGREwc6xWVRA674pxv37sQVM/Cd6bhIsrt9mO7ih4cSgVTOhArHVyhcv6j3DvndxDb9M66pP2S3cD2t+NyiEYigHdZzhs08gg4AFNAJM4CMfKvJ; 25:T2BFZxaVeBjxZgB+3xx/1fh0+Tkf/uAyNjfJivIYQhIdhpMNYIbek2cKnjBnw70ptYxglw9hl/qpNx2/wDd3cDCr4BU9T+ZIzUJqNCiWH5DQKo/F1mS2tm9ePXnpvWdorYnHlxlkPAnX38mzMJOrLC8i5CiPDf7rXV//wih0TF5lkTh9VgjbnfUBaXzVGR8Fw5I61yy7TKzSUo1x/TWEBnXLJljG5KqWwwCjgP0/UAY+T4Jg0WjGafyslIAAJCzYXDFAFe/8g0kG5JBmfqG6NE0BohWqMCiRTlOtCYRvJnKFg0wfjDFx9nOGZTSJyKMup9UCDtBanlWKNwrJZDu3Ew==; 31:DRQCzkC91/tT179r562qZJ2Ppr/UpC0OcL5V2Bx+HQyDWaktLt5+S2DYygvafVKWBKc6TviEdXt7cMBWK9iEQhQP8KLpZ968lPb8dOugy4REWxD5OIML3C2UYy4aJ45GB75ssoyOEB7KFVNoonEDIKrudg/NCMYL4h4n/ZKLSxhJtU2pr69XND2VbtGGehXSnOiPgChGL1VNj1nuldG1GZ9frxvndKQQEGVulC74zPE= X-MS-TrafficTypeDiagnostic: BYAPR07MB4997: X-Microsoft-Exchange-Diagnostics: 1; BYAPR07MB4997; 20:p52RkVs2vuPxaidoTTtr/uiiQN0oXSPNBjyfFCSBjECv8klkC/sKQmabHAIOPNf1FUx7V/uLlyXBjqyKB7KKbmq+dVjbkQ7K3Xe2jomJzdQ5R2ucAGepb5DSUPcjAUlE9vFZjROMFj/+wDlPoLEAcN3btgts9G4y7ob/ZK/vY39HrgkRc274ucI2+EZVwFjTmB5eJ7kAj5+knpVMTDRQe3isX3D58bNR963RTo2TmAvd9x3MEnnFq//8qw3/G29cBaKmoIk1JT8RNXXrd0DTH+PgLUppNJdvWm9Tau5zzVCT2xu7ELYtn8tpGjwo5WUAFyRkRKoB2+aZSuSvc0De1vAVXtjOewxz712634CvWLBcQKaA3A771W3Gmo0zC4bRahLvyt+fgjUmjVU+2cfwG0/82DGPFejl0e+fpIBD5HhYdR2IT7tVA0BSgazSffDaeGdaKcFrob+vIvJCWe67uC+zMN2fhuRfHUJpK+vgi4GukAu1BegKudxFP0KgAImMGq53NRhr32oI3pQ1Xroll8Qnjzkp8nDatu+fOStGOrCfoGU4Ud5lGqJUxrOoXk/fnUJFRCL/wQwMzC17N4RnuZ8nJxGjylXK5IkvWdkQbns= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(185117386973197)(223705240517415); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(3002001)(10201501046)(93006095)(3231311)(944501410)(52105095)(149027)(150027)(6041310)(20161123558120)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(6072148)(201708071742011)(7699016); SRVR:BYAPR07MB4997; BCL:0; PCL:0; RULEID:; SRVR:BYAPR07MB4997; X-Microsoft-Exchange-Diagnostics: 1; BYAPR07MB4997; 4:ycTs9MNex3pb6IpZRAjN3w7uAcMKaAF+Fve9kQvrlBwQj3I8phHHzqCJ3soWkAHiHkTmXjPZvYfkK/54zhRrp76OC/NxmQva4ejQzqBgKGn20obQxzEPlWotRsKXA7XFddCu94SVTYVgiZw+Fq2AxrfDYRA1IkZyxwvPjhC9GWi22WDeygIbmnhoBlWnnuak1A97FaXz916drkNBEECnBEshY5QVtfSFIPVrVV7aggSz9poTZFDZwAogg3t38gSSeg1Gym2S6xgPOFbI0X0GVAu42FD81j8z0EP99TbTEfh3m7E5jkvIPTHgzeamE/2yZz12bpXDsbTURE0oexaHjky+ZZ7PnpChoLED0fSPxBQRtm23Q/3RvxdIFPkuZrDu X-Forefront-PRVS: 07584EDBCD X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(979002)(396003)(376002)(39850400004)(366004)(346002)(136003)(189003)(40434004)(199004)(13464003)(8936002)(6246003)(72206003)(14444005)(5024004)(4326008)(8676002)(6916009)(305945005)(81156014)(5660300001)(81166006)(47776003)(68736007)(478600001)(7736002)(6666003)(93886005)(25786009)(229853002)(2870700001)(2906002)(55016002)(50466002)(9686003)(33656002)(53936002)(66066001)(44832011)(6496006)(23676004)(52146003)(6116002)(33716001)(186003)(16526019)(3846002)(52116002)(76176011)(446003)(486006)(33896004)(55236004)(53546011)(956004)(476003)(386003)(316002)(97736004)(26005)(1076002)(105586002)(106356001)(58126008)(54906003)(42882007)(2486003)(11346002)(18370500001)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR07MB4997; H:jerin; 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) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCWU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DKudRfH6UbE6UjpAmbIL6Bvhw+XHTnP8WA5yzxM/CI6NkSynQsM4jkZ8aPqbC4PXaP+gv0PMKPD+TE99xClWMOzL5kYVxvLEVQksrJsxGnZv2N9HFIIixjxRFsuAIUydi5jYsNbM4BrZ/wyeibIO1i+4WHzTYX43LGRUDTH7KZncf6GuTlPAsPBJ88ce2xmvY5Bp02ficUD3CU0jJemCzcYEq/MU1JAu/efKqT76Abwa4/Q7+dyxI8y06nKyMhk/8OsJWfnSeyd/eEWsrtooFZyGKwxeeNMbepfRcscJvpRgTD9Rm7y/3c3Ug==; 5:J1hE0xQb6OiDgFs9igYpc+L3Pkc1peBWjIUmB5/7SC2+08WmOywW4nHohY6gf1BHTPjL3HOVewXjxLfS6qNfTa7kAoxrig4v/NaveTkAHaV4k2DiUZUTUlYsT+X6tt08U17nClMevKyYgz9uHio1Es05r6YkCrJtjvv8krgICJU=; 7:qadoCvxso41O+5+emLzsUz0k5KDUouqf2HEIkjYU/no2uAMXw/weguMFy9NgkKu/Du9D6tKNXgpWm4mAmaOxhC5Hkc5UT44JzrW1YQSMT+1IK6OZWT/u/eaOZHpCLCbv3JTkLZV60pMZivyD944Ny2HqeofpqO587NVpdS8ma3O3VihufbGgq/vTJncigTD1K2k4IsHqP9xF556VxmQymiMMl2VgBd/wItGgfcMUVjkUM03fYoz1k8Qbgao1XWCa SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Aug 2018 03:07:47.5342 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d6821e1f-546c-4c21-6324-08d5fcdc20bd X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR07MB4997 Subject: Re: [dpdk-stable] [PATCH v2] ring: fix c11 memory ordering issue X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Aug 2018 03:07:54 -0000 -----Original Message----- > Date: Tue, 7 Aug 2018 07:56:08 +0000 > From: Gavin Hu > To: "He, Jia" , "dev@dpdk.org" > CC: Honnappa Nagarahalli , Steve Capper > , Ola Liljedahl , > "jerin.jacob@caviumnetworks.com" , > "hemant.agrawal@nxp.com" , "stable@dpdk.org" > > Subject: RE: [PATCH v2] ring: fix c11 memory ordering issue > > > Hi Jia, > > Thanks for your feedback, let's see if there are requests from others to split the fix. +1 to split it as small patches. If possible, 4 patches, 2 for bug fix and 2 for optimization. Like you mentioned over all performance improvement data, Please add it per optimization patch if possible. > > The is a race condition between updating the tail and getting free/avail_entries, which is dependent on the tails. > Which should be synchronized by load-acquire and store-release. In simple words below, step #1 and #5 should be synchronized with each other, mutually, otherwise the free_/avail_entries calculation possibly get wrong. > > On each locre, either enque or deque, step #1 and #2 order should be maintained as #2 has dependency on #1, > That's why Acquire ordering is necessary. > > Please raise new questions if I don't get across this clearly. > > Ring enqueue / lcore #0 Ring deque / lcore #1 > 1. load-acquire prod_tail 1. Load-acquire cons_tail > 2. get free_entries 2. Get avail_entries > 3. move prod_head accordingly 3. Move cons_head accordingly > 4. do enqueue operations 4. Do dequeue operations > 5. store-release prod_tail 5. Store-release cons_tail > > Best Regards, > Gavin > -----Original Message----- > From: He, Jia > Sent: Tuesday, August 7, 2018 1:57 PM > To: Gavin Hu ; dev@dpdk.org > Cc: Honnappa Nagarahalli ; Steve Capper ; Ola Liljedahl ; jerin.jacob@caviumnetworks.com; hemant.agrawal@nxp.com; stable@dpdk.org > Subject: RE: [PATCH v2] ring: fix c11 memory ordering issue > > Hi Gavin > > -----Original Message----- > > From: Gavin Hu [mailto:gavin.hu@arm.com] > > Sent: 2018年8月7日 11:20 > > To: dev@dpdk.org > > Cc: gavin.hu@arm.com; Honnappa.Nagarahalli@arm.com; > > steve.capper@arm.com; Ola.Liljedahl@arm.com; > > jerin.jacob@caviumnetworks.com; hemant.agrawal@nxp.com; He, Jia > > ; stable@dpdk.org > > Subject: [PATCH v2] ring: fix c11 memory ordering issue > > > > This patch includes two bug fixes(#1 and 2) and two optimisations(#3 and #4). > > Maybe you need to split this into small parts. > > > 1) In update_tail, read ht->tail using __atomic_load.Although the > > compiler currently seems to be doing the right thing even without > > _atomic_load, we don't want to give the compiler freedom to optimise > > what should be an atomic load, it should not be arbitarily moved > > around. > > 2) Synchronize the load-acquire of the tail and the store-release > > within update_tail, the store release ensures all the ring operations, > > engqueu or dequeue are seen by the observers as soon as they see > > the updated tail. The load-acquire is required for correctly compu- > > tate the free_entries or avail_entries, respectively for enqueue and > > dequeue operations, the data dependency is not reliable for ordering > > as the compiler might break it by saving to temporary values to boost > > performance. > > Could you describe the race condition in details? > e.g. > cpu 1cpu2 > code1 > code2 > > Cheers, > Jia > > 3) In __rte_ring_move_prod_head, move the __atomic_load_n up and out of > > the do {} while loop as upon failure the old_head will be updated, > > another load is costy and not necessary. > > 4) When calling __atomic_compare_exchange_n, relaxed ordering for both > > success and failure, as multiple threads can work independently on > > the same end of the ring (either enqueue or dequeue) without > > synchronization, not as operating on tail, which has to be finished > > in sequence. > > > > The patch was benchmarked with test/ring_perf_autotest and it > > decreases the enqueue/dequeue latency by 5% ~ 24.6% with two lcores, > > the real gains are dependent on the number of lcores, depth of the ring, SPSC or MPMC. > > For 1 lcore, it also improves a little, about 3 ~ 4%. > > It is a big improvement, in case of MPMC, with rings size of 32, it > > saves latency up to (6.90-5.20)/6.90 = 24.6%. > > > > Test result data: > > > > SP/SC bulk enq/dequeue (size: 8): 13.19 MP/MC bulk enq/dequeue (size: > > 8): 25.79 SP/SC bulk enq/dequeue (size: 32): 3.85 MP/MC bulk > > enq/dequeue (size: 32): 6.90 > > > > SP/SC bulk enq/dequeue (size: 8): 12.05 MP/MC bulk enq/dequeue (size: > > 8): 23.06 SP/SC bulk enq/dequeue (size: 32): 3.62 MP/MC bulk > > enq/dequeue (size: 32): 5.20 > > > > Fixes: 39368ebfc6 ("ring: introduce C11 memory model barrier option") > > Cc: stable@dpdk.org > > > > Signed-off-by: Gavin Hu > > Reviewed-by: Honnappa Nagarahalli > > Reviewed-by: Steve Capper > > Reviewed-by: Ola Liljedahl > > --- > > lib/librte_ring/rte_ring_c11_mem.h | 38 > > +++++++++++++++++++++++++------------- > > 1 file changed, 25 insertions(+), 13 deletions(-) > > > > diff --git a/lib/librte_ring/rte_ring_c11_mem.h > > b/lib/librte_ring/rte_ring_c11_mem.h > > index 94df3c4a6..cfa3be4a7 100644 > > --- a/lib/librte_ring/rte_ring_c11_mem.h > > +++ b/lib/librte_ring/rte_ring_c11_mem.h > > @@ -21,7 +21,8 @@ update_tail(struct rte_ring_headtail *ht, uint32_t > > old_val, uint32_t new_val, > > * we need to wait for them to complete > > */ > > if (!single) > > -while (unlikely(ht->tail != old_val)) > > +while (unlikely(old_val != __atomic_load_n(&ht->tail, > > +__ATOMIC_RELAXED))) > > rte_pause(); > > > > __atomic_store_n(&ht->tail, new_val, __ATOMIC_RELEASE); @@ -60,20 > > +61,24 @@ __rte_ring_move_prod_head(struct rte_ring *r, unsigned int > > +is_sp, > > unsigned int max = n; > > int success; > > > > +*old_head = __atomic_load_n(&r->prod.head, __ATOMIC_RELAXED); > > do { > > /* Reset n to the initial burst count */ > > n = max; > > > > -*old_head = __atomic_load_n(&r->prod.head, > > -__ATOMIC_ACQUIRE); > > > > -/* > > - * The subtraction is done between two unsigned 32bits value > > +/* load-acquire synchronize with store-release of ht->tail > > + * in update_tail. > > + */ > > +const uint32_t cons_tail = __atomic_load_n(&r->cons.tail, > > +__ATOMIC_ACQUIRE); > > + > > +/* The subtraction is done between two unsigned 32bits value > > * (the result is always modulo 32 bits even if we have > > * *old_head > cons_tail). So 'free_entries' is always between 0 > > * and capacity (which is < size). > > */ > > -*free_entries = (capacity + r->cons.tail - *old_head); > > +*free_entries = (capacity + cons_tail - *old_head); > > > > /* check that we have enough room in ring */ > > if (unlikely(n > *free_entries)) > > @@ -87,9 +92,10 @@ __rte_ring_move_prod_head(struct rte_ring *r, > > unsigned int is_sp, > > if (is_sp) > > r->prod.head = *new_head, success = 1; > > else > > +/* on failure, *old_head is updated */ > > success = __atomic_compare_exchange_n(&r->prod.head, > > old_head, *new_head, > > -0, __ATOMIC_ACQUIRE, > > +/*weak=*/0, __ATOMIC_RELAXED, > > __ATOMIC_RELAXED); > > } while (unlikely(success == 0)); > > return n; > > @@ -128,18 +134,23 @@ __rte_ring_move_cons_head(struct rte_ring *r, > > int is_sc, > > int success; > > > > /* move cons.head atomically */ > > +*old_head = __atomic_load_n(&r->cons.head, __ATOMIC_RELAXED); > > do { > > /* Restore n as it may change every loop */ > > n = max; > > -*old_head = __atomic_load_n(&r->cons.head, > > -__ATOMIC_ACQUIRE); > > + > > +/* this load-acquire synchronize with store-release of ht->tail > > + * in update_tail. > > + */ > > +const uint32_t prod_tail = __atomic_load_n(&r->prod.tail, > > +__ATOMIC_ACQUIRE); > > > > /* The subtraction is done between two unsigned 32bits value > > * (the result is always modulo 32 bits even if we have > > * cons_head > prod_tail). So 'entries' is always between 0 > > * and size(ring)-1. > > */ > > -*entries = (r->prod.tail - *old_head); > > +*entries = (prod_tail - *old_head); > > > > /* Set the actual entries for dequeue */ > > if (n > *entries) > > @@ -152,10 +163,11 @@ __rte_ring_move_cons_head(struct rte_ring *r, > > int is_sc, > > if (is_sc) > > r->cons.head = *new_head, success = 1; > > else > > +/* on failure, *old_head will be updated */ > > success = __atomic_compare_exchange_n(&r->cons.head, > > -old_head, *new_head, > > -0, __ATOMIC_ACQUIRE, > > -__ATOMIC_RELAXED); > > +old_head, *new_head, > > +/*weak=*/0, __ATOMIC_RELAXED, > > +__ATOMIC_RELAXED); > > } while (unlikely(success == 0)); > > return n; > > } > > -- > > 2.11.0 > > IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.