From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on0073.outbound.protection.outlook.com [104.47.2.73]) by dpdk.org (Postfix) with ESMTP id 66C21201 for ; Tue, 25 Sep 2018 06:44:27 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=SjbkiWWoFDumGNJB2B6yLfYUeg5YSyxN5vS5Pn8ptzk=; b=NHNRf4/4Ly4UcmdkUi345crpGoqC9W+V2DuPI3AXgsuZQ9W9DEbOTvRkkefwTuX0WZ7ccfN1how8tgbqcESg2oUV6m8EmFxZ7xAAK6UGMQbQjpadiLK02hbiAye2GW7AlowaRA0Zks92WERsSP4JU0b2+iHYw/MqtwAM3VEnjFI= Received: from AM6PR08MB3672.eurprd08.prod.outlook.com (20.177.115.29) by AM6PR08MB2968.eurprd08.prod.outlook.com (52.135.163.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.15; Tue, 25 Sep 2018 04:44:26 +0000 Received: from AM6PR08MB3672.eurprd08.prod.outlook.com ([fe80::589e:d3cf:9777:5ff9]) by AM6PR08MB3672.eurprd08.prod.outlook.com ([fe80::589e:d3cf:9777:5ff9%2]) with mapi id 15.20.1164.024; Tue, 25 Sep 2018 04:44:26 +0000 From: Honnappa Nagarahalli To: Honnappa Nagarahalli , Jerin Jacob CC: "Phil Yang (Arm Technology China)" , "dev@dpdk.org" , nd , "kkokkilagadda@caviumnetworks.com" , "Gavin Hu (Arm Technology China)" , "ferruh.yigit@intel.com" Thread-Topic: [PATCH v2 2/3] kni: fix kni fifo synchronization Thread-Index: AQHUULwDi5PFjJpIFUyDUdvyMo0oh6T5RIGggAAJlACAAOYDgIAACdiAgAACrDCABjJlgA== Date: Tue, 25 Sep 2018 04:44:26 +0000 Message-ID: References: <1537363820-3827-1-git-send-email-phil.yang@arm.com> <1537364560-4124-1-git-send-email-phil.yang@arm.com> <1537364560-4124-2-git-send-email-phil.yang@arm.com> <20180920082846.GB19425@jerin> <20180920153700.GA9459@jerin> <20180921055529.GA15861@jerin> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Honnappa.Nagarahalli@arm.com; x-originating-ip: [217.140.111.135] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM6PR08MB2968; 6:ejrDnueKmpmw7UQ2acM3sRMKOBsq7gB9Ms38oZ+CycY5zO715znrmvAGo+YAktQW75LlHaevvCUf2syDZSdW95obW8hPHBJgg3tVM87j4ra6BzRzKbKZaUjJOoZkdY5sGNXwumYe2BFkoQTl7ArE/cQgjoyGAZchPJqLMyhOT0Us+fYgjLfPK23luwZz3ULpM7lGDEEq3s6O9+XbVKjdspAsieoAgdeE5y3p5Av/JXYBX+PDpnDBSq5FKeuZxpA8LjEj7VhpHGCbl6mYKozMl+/V13PYLzjDv04Z+qOSF1FJClDJnDRnhuS6GRx6T0NyoKctp78qcpsroZ6xn4B4+M6ubun8iefkYVQati2gMPBw8mDuWEbkKt+cpN+Vs3c/V9rkH22PMuy76wAIGpwfAZ0G8mphzqeAAlcIA6hSAaGyQe8/dbSFKAh8UdFq9IJfG2cnIY8QmbJTJNuAbA1B3g==; 5:KRjC+jehKCsxeXU7ljGC2p/GGyXbQ0Pfz3Elnc7usatmCACc27/G4AjMDgBgXxQX2WcJ40YNqi0s14CpuRRbe0uFUPTPgzBXMxmtUghVflBB5Bg+icBvs+ZgBJZHXpUdxR6dWpRiKXN0iBe+wn2o7pnjfl6L7hZh1LHtE8fAPNg=; 7:7XjqhfvkdG8THMRY1D/8qWhYorWCkRQLSyUr3yOetFmxdSJQ8TPd4m0Jlj1h8U4rSsb999GxkwrNUmVl9rkIohy55ovtlVb1MVozgk72J1KgYk2XjU3D0TV9gu5kY+2WSvX8iunwqMsyy0tD1AZ5uR7AHpjP8qCgZYQmRhof6VPWgVQZtgH2UzkpdbRc1PFoDYX6NHz6LcQinHIgnAUPxldQJ70hCb/aYlgTKxclZHrZ3W4j4+Qk+wP4HMeI1MND x-ms-exchange-antispam-srfa-diagnostics: SOS;SOR; x-ms-office365-filtering-correlation-id: fece2cdb-5337-4b2a-6560-08d622a1928a x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(5600074)(711020)(4618075)(2017052603328)(7153060)(7193020); SRVR:AM6PR08MB2968; x-ms-traffictypediagnostic: AM6PR08MB2968: nodisclaimer: True x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(228905959029699)(163750095850)(180628864354917); x-ms-exchange-senderadcheck: 1 x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(10201501046)(93006095)(93001095)(3002001)(3231355)(944501410)(52105095)(6055026)(149066)(150027)(6041310)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(201708071742011)(7699051); SRVR:AM6PR08MB2968; BCL:0; PCL:0; RULEID:; SRVR:AM6PR08MB2968; x-forefront-prvs: 08062C429B x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(376002)(136003)(366004)(39860400002)(396003)(346002)(57704003)(189003)(13464003)(199004)(476003)(305945005)(11346002)(54906003)(72206003)(74316002)(110136005)(486006)(6116002)(229853002)(66066001)(55016002)(71190400001)(53936002)(8936002)(71200400001)(5250100002)(33656002)(105586002)(99286004)(6506007)(446003)(3846002)(6436002)(8676002)(14454004)(81156014)(316002)(25786009)(4326008)(2906002)(26005)(5660300001)(53546011)(102836004)(2900100001)(9686003)(86362001)(6246003)(93886005)(7736002)(7696005)(14444005)(256004)(68736007)(76176011)(478600001)(81166006)(106356001)(97736004); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR08MB2968; H:AM6PR08MB3672.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: GkAYCfUoayiu/42lAwsmjQUSU7RWwY5Hq098pBb1SitrHc0Kr8BkSV68Dv37O73oBLUKu5qLrvRPWmRS0EeaTIYsUiRNvNm/Yqys2tRVY3PDrmcjz84/5alzVk/JMCaCDzPCRi41IJu+/JGKcdSlU/PVWL3QxViiPKVBNeGTh83w13c+kaaBgbVlKhmWIMuUqN2lQ7P3sEnOh6r7iAp7IGlw8U3qmFCwMOzNQxTo9sDV2ctpnZ1IK3WnnPfKISas5q6LoUC5BMHcklZc4V2kt4DBTY6u4/+l9XP5DjfDfUze7/+xzq33tNBOAm9SYL45W0gqQ0XsvHoG/pVBPdhG7m1GEzfspls8QRi54CdJ5gc= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: fece2cdb-5337-4b2a-6560-08d622a1928a X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Sep 2018 04:44:26.2155 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR08MB2968 Subject: Re: [dpdk-dev] [PATCH v2 2/3] kni: fix kni fifo synchronization 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: Tue, 25 Sep 2018 04:44:27 -0000 Hi Ferruh, Just wanted to get your attention to this conversation. Appreciate your fe= edback on handling the #ifdef clutter. Thank you, Honnappa > -----Original Message----- > From: dev On Behalf Of Honnappa Nagarahalli > Sent: Friday, September 21, 2018 1:37 AM > To: Jerin Jacob > Cc: Phil Yang (Arm Technology China) ; dev@dpdk.org; > nd ; kkokkilagadda@caviumnetworks.com; Gavin Hu (Arm > Technology China) ; ferruh.yigit@intel.com > Subject: Re: [dpdk-dev] [PATCH v2 2/3] kni: fix kni fifo synchronization >=20 > > > > > > > > > > > > > > @@ -69,5 +89,13 @@ kni_fifo_get(struct rte_kni_fifo *fifo, > > > > > > > void **data, unsigned num) static inline uint32_t > > > > > > > kni_fifo_count(struct rte_kni_fifo *fifo) { > > > > > > > +#ifdef RTE_USE_C11_MEM_MODEL > > > > > > > + unsigned fifo_write =3D __atomic_load_n(&fifo->write, > > > > > > > + __ATOMIC_AC= QUIRE); > > > > > > > + unsigned fifo_read =3D __atomic_load_n(&fifo->read, > > > > > > > + > > > > > > > +__ATOMIC_ACQUIRE); > > > > > > > > > > > > Isn't too heavy to have two __ATOMIC_ACQUIREs? a simple > > > > > > rte_smp_rmb() would be enough here. Right? > > > > > > or > > > > > > Do we need __ATOMIC_ACQUIRE for fifo_write case? > > > > > > > > > > > We also had some amount of debate internally on this: > > > > > 1) We do not want to use rte_smp_rmb() as we want to keep the > > > > > memory > > > > models separated (for ex: while using C11, use C11 everywhere). It > > > > is also not sufficient, please see 3) below. > > > > > > > > But Nothing technically wrong in using rte_smp_rmb() here in terms > > > > functionally and code generated by the compiler. > > > > > > rte_smp_rmb() generates 'DMB ISHLD'. This works fine, but it is not > optimal. > > 'LDAR' is a better option which is generated when C11 atomics are used. > > > > Yes. But which one is optimal 1 x DMB ISHLD vs 2 x LDAR ? >=20 > Good point. I am not sure which one is optimal, it needs to be measured. > 'DMB ISHLD' orders 'all' earlier loads against 'all' later loads and stor= es. > 'LDAR' orders the 'specific' load with 'all' later loads and stores. >=20 > > > > > > > > > > > > > > 2) This API can get called from writer or reader, so both the > > > > > loads have to be __ATOMIC_ACQUIRE > > > > > 3) Other option is to use __ATOMIC_RELAXED. That would allow any > > > > loads/stores around of this API to get reordered, especially since > > > > this is an inline function. This would put burden on the > > > > application to manage the ordering depending on its usage. It will > > > > also require the application to understand the implementation of th= is > API. > > > > > > > > __ATOMIC_RELAXED may be fine too for _count() case as it may not > > > > very important to get the exact count for the exact very moment, > > > > Application can retry. > > > > > > > > I am in favor of performance effective implementation. > > > > > > The requirement on the correctness of the count depends on the usage > > > of > > this function. I see the following usage: > > > > > > In the file kni_net.c, function: kni_net_tx: > > > > > > if (kni_fifo_free_count(kni->tx_q) =3D=3D 0 || > > > kni_fifo_count(kni->alloc_q) =3D=3D 0) { > > > /** > > > * If no free entry in tx_q or no entry in alloc_q, > > > * drops skb and goes out. > > > */ > > > goto drop; > > > } > > > > > > There is no retry here, the packet is dropped. > > > > OK. Then pick an implementation which is an optimal this case. > > I think, then rte_smp_rmb() makes sense here as > > a) no #ifdef clutter > > b) it is optimal compared to 2 x LDAR > > > As I understand, one of the principals of using C11 model is to match the= store > releases and load acquires. IMO, combining C11 memory model with barrier > based functions makes the code unreadable. > I realized rte_smp_rmb() is required for x86 as well to prevent compiler > reordering. We can add that in the non-C11 case. This way, we will have c= lean > code for both the options (similar to rte_ring). > So, if 'RTE_USE_C11_MEM_MODEL' is set to 'n', then the 'rte_smp_rmb' > would be used. >=20 > We can look at handling the #ifdef clutter based on Ferruh's feedback. >=20 > > > > > > > > > > > > > > > > > > > > > > > > > > Other than that, I prefer to avoid ifdef clutter by > > > > > > introducing two separate file just like ring C11 implementation= . > > > > > > > > > > > > I don't have strong opinion on this this part, I let KNI > > > > > > MAINTAINER to decide on how to accommodate this change. > > > > > > > > > > I prefer to change this as well, I am open for suggestions. > > > > > Introducing two separate files would be too much for this library= . > > > > > A better > > > > way would be to have something similar to 'smp_store_release' > > > > provided by the kernel. i.e. create #defines for loads/stores. > > > > Hide the clutter behind the #defines. > > > > > > > > No Strong opinion on this, leaving to KNI Maintainer. > > > Will wait on this before re-spinning the patch > > > > > > > > > > > This patch needs to split by two, > > > > a) Fixes for non C11 implementation(i.e new addition to > > > > rte_smp_wmb()) > > > > b) add support for C11 implementation. > > > Agree > > > > > > > > > > > > > > > > > > > > > > > > > + return (fifo->len + fifo_write - fifo_read) & > > > > > > > +(fifo->len - 1); #else > > > > > > > return (fifo->len + fifo->write - fifo->read) & > > > > > > > (fifo->len > > > > > > > - 1); > Requires rte_smp_rmb() for x86 to prevent compiler reordering. >=20 > > > > > > > +#endif > > > > > > > } > > > > > > > -- > > > > > > > 2.7.4 > > > > > > >