From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM04-BN3-obe.outbound.protection.outlook.com (mail-eopbgr680061.outbound.protection.outlook.com [40.107.68.61]) by dpdk.org (Postfix) with ESMTP id 7C2AE44BE; Mon, 8 Oct 2018 12:47:17 +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=l4NdyFi1NqMTAHz1IH2dxS6GAHqcTbJhEMkMqZkFlRk=; b=WLtXS1abt2dTwlE8U6keysOshrZO5TsWrzl0Q9aGiORalXTPmQ8ErcG/nyMSBJ4+vXsaSzwRJFLfGmBRDmT7YsFGkmwwMf9mEi2b/78pFHHOa7RVt3mA76Bo3TGYh63tfjEyPczEab0V5V58I14Pei17dntMxMdsZ4e347T8xos= 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.1207.23; Mon, 8 Oct 2018 10:47:12 +0000 Date: Mon, 8 Oct 2018 16:16:54 +0530 From: Jerin Jacob To: Ola Liljedahl Cc: "dev@dpdk.org" , Honnappa Nagarahalli , "Ananyev, Konstantin" , "Gavin Hu (Arm Technology China)" , Steve Capper , nd , "stable@dpdk.org" Message-ID: <20181008104653.GC11081@jerin> References: <60055965-A7C8-4E9F-8668-0AE1DCE57515@arm.com> <20181006074126.GA16715@jerin> <20181007040243.GA1850@jerin> <7A156041-23EC-4CCB-B129-3607AF34A992@arm.com> <20181008060629.GA5228@jerin> <063A95EC-CFC1-42F7-B864-DFB9C6718AC8@arm.com> <20181008100004.GB11081@jerin> 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: BMXPR01CA0012.INDPRD01.PROD.OUTLOOK.COM (2603:1096:b00:d::22) To BYAPR07MB4997.namprd07.prod.outlook.com (2603:10b6:a03:5b::22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 435b868b-898d-4f67-512a-08d62d0b69ca X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:BYAPR07MB4997; X-Microsoft-Exchange-Diagnostics: 1; BYAPR07MB4997; 3:PDuIKiL9Ndj7wf+qFKNQoFjGXLeBRe4yrsk68CufmRcNSmGDjf64a9kWY4nhejTnMT1CoD0QId3t4dlpVe2z2vAnDsV9ChP2/iHlOoZZ8660JZV2sPhG0NqD42f1Id8fPwVbduh4ftIE7HsavJ3YjvrbK9CYv2dudRLZdCTP0mxRXsiubr9x8N9mblYBSYiSbq2xAOGmmVQAIH6CqF5URbNu2PIh3PAz2YXkzCXaQZ0MW2KTEjkABIWJ4v3EfCAk; 25:wYhIWL61tbX68G9DVgDca474RmGVTxupuSEx2nlbgOsEPjhvDKlLg6uFTuAewrUu+zqZixoTnJuQsWntcoYS4DasEGPNqky37K6JEHfg8CXFh4HhlD+pueVkLp1GuyaFCDTf6Q8UDgWJQVyPTK2/UgYzv57JG4bDNJBhOEApx9jsWeAdw+xT+yhyx6zdtjTpDOFSeW3NnPvDyv3Qxn3lFshckxufvJCBA7HoITtL8B5+dAEFoOzwpR3qWhSX5rBPAeeQM4/JfvssrTFPX66+Jow1ydru7LqIrE3Dw7rzWTbTmaR71dVcrYpPVLqSyBSCz7Zv1KtgDl0I+eZfx+Vknw==; 31:BNif5r57aDbJHoE1u8Mb0JJfinsOoGqtlaG6We87vvk0wCYmbkqrMUVjHI5wpjY/WV2aAoF9ZNxpJQNNvvsJxVkp54k/34uPED+3Diy1H/acKbUy/NCinQUJRo4JUZWLOyl9mjzjY8R2sokkrjds0+oDM2LI1yjgq/hjR6xTXy7HxH00f/lX+4HGWBGhEMwMvqghrwrwxxZ/RsDmCfqMmHLxWwOTV1b+OOFXLLcRwzg= X-MS-TrafficTypeDiagnostic: BYAPR07MB4997: X-Microsoft-Exchange-Diagnostics: 1; BYAPR07MB4997; 20:I4cMgMOufd9F4u0t37kqU05EKVoU1k7BvDwugen31Bm9OPfw1nG83zFkR0AecnDzPpuEux8EWQM6aOp7MRF5BeuWdxfMmSy3KDfPvfr7MDJFgrtFT6JY4g03e1T2DTZ70VpTbF1ArJBPX1cWsKSysMHaxNbHXSoCaIcL4D0X3HFcH4NBYbZGA9xzARN83seMvKoz18c7WOFt+Ffvm7Fu1mWjNg/Tu8Aw2r4tRle+5QRvhYZ1OPpdBmjmDMUDWYl7ANgezJCr2mo60r5F37bpScxWQV5uOPC8+e/tgn6zes0Wm40tWSySyMHJP5nQedjDjabUtT0Bm8o+6iDaEldzmbH+7wq9ONdpPMuen+ws7dEmZx+NDj/mtD4YQU0kqK3G6GcKVEv90EY+9I2us1ywie6AQbk5IROtwscY5snXR3QkFMKCA8uOK3w3i41jmdOiUqxVzALRWMQGznZGn/gzBoyrd3DKUnz8+GbDzvVgTmoLxr3iFyNzNKZVulBs+WCX8NrhuukoVKY36laLiedPZZz3MRZ+kDmq/IQvI0BYY/y+Izsp4nxoLtDwVxRtfCP68N6Q2TY+X1Av9us8UnDtOjzXLK+jcAdZ5a7WBGjssIo= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(180628864354917)(228905959029699)(166708455590820); X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(93006095)(10201501046)(3231355)(944501410)(52105095)(3002001)(149066)(150057)(6041310)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123560045)(20161123562045)(201708071742011)(7699051); SRVR:BYAPR07MB4997; BCL:0; PCL:0; RULEID:; SRVR:BYAPR07MB4997; X-Microsoft-Exchange-Diagnostics: 1; BYAPR07MB4997; 4:JnLkxMY6FuaehtgVgELEKLLhSwMrrsqyNHhPASgjWPjPv021xMIL7SfL8fxoTVaHdrEqCd78M8xbZkJUOBjlQOZDgdpiUVj9M/Fm4MnZtYPXzlYbNoEaZ5TxeQ02X2mifqJMzK8tlTy6pMMpHJ83cSYNjsF6yHssLH6mpHmImOVaWmM7xkZvhUMcCtJB015V0NFy8/is8Qyb0mjxhHWOsjgT/vaHVZ2HAs85PyZq/1nwodQHcoNOtF0qVSSSSEkCFe2FquALNsHAlW75tYPI4KntWkUFN28aksSngVHoiWnVUuJf7BXQNJYR8vG/G492zd9iuR8zonSdqNfYJhjc7b7qOvLukaYLQfJuZGSSxUaHfejaKcKXqZF+roX2dZXo X-Forefront-PRVS: 081904387B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(39860400002)(396003)(366004)(346002)(136003)(13464003)(199004)(189003)(33716001)(23676004)(53936002)(81156014)(81166006)(6496006)(8676002)(76176011)(33896004)(2906002)(316002)(44832011)(50466002)(55016002)(33656002)(19627235002)(305945005)(106356001)(6306002)(105586002)(7736002)(9686003)(66066001)(478600001)(52116002)(1076002)(4744004)(6666003)(45080400002)(47776003)(52146003)(6116002)(3846002)(966005)(6246003)(2486003)(72206003)(14444005)(16526019)(229853002)(186003)(476003)(26005)(4326008)(6916009)(956004)(446003)(42882007)(55236004)(53546011)(11346002)(386003)(97736004)(93886005)(68736007)(2870700001)(8936002)(54906003)(5660300001)(486006)(58126008)(25786009)(18370500001); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR07MB4997; H:jerin; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtCWUFQUjA3TUI0OTk3OzIzOkVacnRsQmlpTjB2dDh6cTJDTHFhb2MzZUJ1?= =?utf-8?B?YTFwams2SHBsSEpYeG9pV1FzMS9FdEQ3enc4UDVDL3VjWTRjamZWSUY3WGlx?= =?utf-8?B?akowalZzQyt2dUtJc0dteGdDNjdDMHBwSG1TWEJWNTZRZGM0T0I1U1BDSjda?= =?utf-8?B?Uk4wSWQzc0toRUVTRm1rZzMrRWtwVFBubUc2K3ZhZmVkN3F1R1NjWUI1QUow?= =?utf-8?B?WUFZdThoMEp6U0Q0VWMzZmhTMDBTeWFLYnpEYVN6cUNCY2sxNUFjREFTQTJP?= =?utf-8?B?OUoyZmNRWE5CcnlrMnl3bVNpQjhwdW1pQVNwRlZOOEh1WTVrY1YzSU1STWFT?= =?utf-8?B?d2pQU0x4ZkVtWmF6eDF4Q0ZCMUFPell4WWF1MCtCbk5tNk94MGNsYW04aVRX?= =?utf-8?B?SjVwVHlxUzQxY296aFNpeFJGa1l4SmV5ZnFsZlkvZ0JSc2RMS0lVSGJKZXpo?= =?utf-8?B?cjVmZEtwMG4zTTNOS2pOUE5KK3FGU1N1LzZTVS9rUFdGeFhqVEI1bHJlV0dZ?= =?utf-8?B?NFByNHdESkh3SWRKQ2VxODV6SDNmMThDOTIyMEh6UWZiOENMK3IyOXc5NCtX?= =?utf-8?B?TitoZmZ1VFFBTkQzN05hN0ZiZ2lMR25xV3NzKzN1WC84L280eHFScE9Qd1dM?= =?utf-8?B?VXRVbjhMOWh5YWRPenArYVNCNUNFd0VQdDdqckNKbXBBdlVqM0VxUFRsTGx1?= =?utf-8?B?cm9nQ204S0E1dURFTkUyeERDZHpUVDlmT05yTVoyUjlDTWpia2k0NENLV3RL?= =?utf-8?B?RlZRTmV3VGp5RHFXMDg5Vjl5RnMvRG5OZTladDlMRkcrRkttbEZRZWpxdTZy?= =?utf-8?B?VmxR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0t0io/KqATLwa3DgAjx4qI33ug0V+p+bhao8GjLQW5mTXVO1GyEU7ZQvXlDivpkFvCVN4D9P4VSZLST25mMsAFL7CPHCl3r8SSX6l8rcJrMgF1ASa4y96lOVUHA97r3yDtMJUjoykbL1GBK6hYoVb04mE8BsVDNrkFrk25JwB/QF8jpxorZqxi+r55lh8wYdBPKPLCi48xmE7T7ZDTAl5rwuqsHmfkle3k08yWbimW8mymW1975wQXdRXuvbbxVyH7dxe2iSdUN3Q1lEmc3D1AdvJwFDfD4pEBDboeGaOgA==; 5:quFHvYL+OFJWqdBX+yOoQT+3UKHF9SaRqs2g53/ChluroPOn4dmGNYL/1uu2KPj8eiJHA6Dvw7volcXvBYSGgFDZnF7HoV82ZiuWnsipXR0NA65ENVEdesLvNoNvVOc69N80Omia/SUkxbeAKkQBhYdxEPmICHYwkCgty5MYIgU=; 7:dcnBtRLp1c8xxRVvrtJji/OMJ+SN26DRDCvwG64QDFSsBHpC/IVnT6NpXiEyQHOi78HYhAKihu9R4x79hdvAbmP6TC/fbPl7IXh5AFhieSH2RW6lFnnQgEjPtsjDU1SBVYdwolu8jBRDYXkyl/tYln93A5Z/Ll8clqHkhZfGkSpIkIuiX+bSL4/Tc8aRl4Q1BZvQxqMzTo/XzFoPaEpg65EuIjLQgQDYX9lREYuA/JBx5Wf3fzhDG3w7M/TRkHl0 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Oct 2018 10:47:12.4604 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 435b868b-898d-4f67-512a-08d62d0b69ca 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-dev] [PATCH v3 1/3] ring: read tail using atomic load 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: Mon, 08 Oct 2018 10:47:18 -0000 -----Original Message----- > Date: Mon, 8 Oct 2018 10:25:45 +0000 > From: Ola Liljedahl > To: Jerin Jacob > CC: "dev@dpdk.org" , Honnappa Nagarahalli > , "Ananyev, Konstantin" > , "Gavin Hu (Arm Technology China)" > , Steve Capper , nd , > "stable@dpdk.org" > Subject: Re: [PATCH v3 1/3] ring: read tail using atomic load > user-agent: Microsoft-MacOutlook/10.11.0.180909 > > > On 08/10/2018, 12:00, "Jerin Jacob" wrote: > > -----Original Message----- > > Date: Mon, 8 Oct 2018 09:22:05 +0000 > > From: Ola Liljedahl > > To: Jerin Jacob > > CC: "dev@dpdk.org" , Honnappa Nagarahalli > > , "Ananyev, Konstantin" > > , "Gavin Hu (Arm Technology China)" > > , Steve Capper , nd , > > "stable@dpdk.org" > > Subject: Re: [PATCH v3 1/3] ring: read tail using atomic load > > user-agent: Microsoft-MacOutlook/10.11.0.180909 > > > > External Email > > > > On 08/10/2018, 08:06, "Jerin Jacob" wrote: > > > > -----Original Message----- > > > Date: Sun, 7 Oct 2018 20:44:54 +0000 > > > From: Ola Liljedahl > > > To: Jerin Jacob > > > CC: "dev@dpdk.org" , Honnappa Nagarahalli > > > , "Ananyev, Konstantin" > > > , "Gavin Hu (Arm Technology China)" > > > , Steve Capper , nd , > > > "stable@dpdk.org" > > > Subject: Re: [PATCH v3 1/3] ring: read tail using atomic load > > > user-agent: Microsoft-MacOutlook/10.11.0.180909 > > > > > > > > > Could you please fix the email client for inline reply. > > Sorry that doesn't seem to be possible with Outlook for Mac 16 or Office365. The official Office365/Outlook > > documentation doesn't match the actual user interface... > > > > > > > > https://www.kernel.org/doc/html/v4.19-rc7/process/email-clients.html > > > > > > > > > > On 07/10/2018, 06:03, "Jerin Jacob" wrote: > > > > > > In arm64 case, it will have ATOMIC_RELAXED followed by asm volatile ("":::"memory") of rte_pause(). > > > I would n't have any issue, if the generated code code is same or better than the exiting case. but it not the case, Right? > > > The existing case is actually not interesting (IMO) as it exposes undefined behaviour which allows the compiler to do anything. But you seem to be satisfied with "works for me, right here right now". I think the cost of avoiding undefined behaviour is acceptable (actually I don't think it even will be noticeable). > > > > I am not convinced because of use of volatile in head and tail indexes. > > For me that brings the defined behavior. > > As long as you don't mix in C11 atomic accesses (just use "plain" accesses to volatile objects), > > it is AFAIK defined behaviour (but not necessarily using atomic loads and stores). But I quoted > > the C11 spec where it explicitly mentions that mixing atomic and non-atomic accesses to the same > > object is undefined behaviour. Don't argue with me, argue with the C11 spec. > > If you want to disobey the spec, this should at least be called out for in the code with a comment. > > That's boils down only one question, should we follow C11 spec? Why not only take load > acquire and store release semantics only just like Linux kernel and FreeBSD. > And introduce even more undefined behaviour? Yes. The all world(Linux and Freebsd) is running with undefined behavior and still it runs. > > Does not look like C11 memory model is super efficient in term of gcc > implementation. > You are making a chicken out of a feather. > > I think this "problem" with one additional ADD instruction will only concern __atomic_load_n(__ATOMIC_RELAXED) and __atomic_store_n(__ATOMIC_RELAXED) because the compiler separates the address generation (add offset of struct member) from the load or store itself. For other atomic operations and memory orderings (e.g. __atomic_load_n(__ATOMIC_ACQUIRE), the extra ADD instruction will be included anyway (as long as we access a non-first struct member) because e.g. LDAR only accepts a base register with no offset. > > I suggest minimising the imposed memory orderings can have a much larger (positive) effect on performance compared to avoiding one ADD instruction (memory accesses are much slower than CPU ALU instructions). > Using C11 memory model and identifying exactly which objects are used for synchronisation and whether (any) updates to shared memory are acquired or released (no updates to shared memory means relaxed order can be used) will provide maximum freedom to the compiler and hardware to get the best result. No more comments on this. It is not data driven. > > The FreeBSD and DPDK ring buffers show some fundamental misunderstandings here. Instead excessive orderings and explicit barriers have been used as band-aids, with unknown effects on performance. > > > > > > > > That the reason why I shared > > the generated assembly code. If you think other way, Pick any compiler > > and see generated output. > > This is what one compiler for one architecture generates today. These things change. Other things > > that used to work or worked for some specific architecture has stopped working in newer versions of > > the compiler. > > > > > > And > > > > Freebsd implementation of ring buffer(Which DPDK derived from), Don't have > > such logic, See https://github.com/freebsd/freebsd/blob/master/sys/sys/buf_ring.h#L108 > > It looks like FreeBSD uses some kind of C11 atomic memory model-inspired API although I don't see > > exactly how e.g. atomic_store_rel_int() is implemented. The code also mixes in explicit barriers > > so definitively not pure C11 memory model usage. And finally, it doesn't establish the proper > > load-acquire/store-release relationships (e.g. store-release cons_tail requires a load-acquire cons_tail, > > same for prod_tail). > > > > "* multi-producer safe lock-free ring buffer enqueue" > > The comment is also wrong. This design is not lock-free, how could it be when there is spinning > > (waiting) for other threads in the code? If a thread must wait for other threads, then by definition > > the design is blocking. > > > > So you are saying that because FreeBSD is doing it wrong, DPDK can also do it wrong? > > > > > > See below too. > > > > > > > > Skipping the compiler memory barrier in rte_pause() potentially allows for optimisations that provide much more benefit, e.g. hiding some cache miss latency for later loads. The DPDK ring buffer implementation is defined so to enable inlining of enqueue/dequeue functions into the caller, any code could immediately follow these calls. > > > > > > From INTERNATIONAL STANDARD ©ISO/IEC ISO/IEC 9899:201x > > > Programming languages — C > > > > > > 5.1.2.4 > > > 4 Two expression evaluations conflict if one of them modifies a memory location and the other one reads or modifies the same memory location. > > > > > > 25 The execution of a program contains a data race if it contains two conflicting actions in different threads, at least one of which is not atomic, and neither happens before the other. Any such data race results in undefined behavior. > > > > IMO, Both condition will satisfy if the variable is volatile and 32bit read will atomic > > for 32b and 64b machines. If not, the problem persist for generic case > > as well(lib/librte_ring/rte_ring_generic.h) > > The read from a volatile object is not an atomic access per the C11 spec. It just happens to > > be translated to an instruction (on x86-64 and AArch64/A64) that implements an atomic load. > > I don't think any compiler would change this code generation and suddenly generate some > > non-atomic load instruction for a program that *only* uses volatile to do "atomic" accesses. > > But a future compiler could detect the mix of atomic and non-atomic accesses and mark this > > expression as causing undefined behaviour and that would have consequences for code generation. > > > > > > I agree with you on C11 memory model semantics usage. The reason why I > > propose name for the file as rte_ring_c11_mem.h as DPDK it self did not > > had definitions for load acquire and store release semantics. > > I was looking for taking load acquire and store release semantics > > from C11 instead of creating new API like Linux kernel for FreeBSD(APIs > > like atomic_load_acq_32(), atomic_store_rel_32()). If the file name is your > > concern then we could create new abstractions as well. That would help > > exiting KNI problem as well. > > I appreciate your embrace of the C11 memory model. I think it is better for describing > > (both to the compiler and to humans) which and how objects are used for synchronisation. > > > > However, I don't think an API as you suggest (and others have suggested before, e.g. as > > done in ODP) is a good idea. There is an infinite amount of possible base types, an > > increasing number of operations and a bunch of different memory orderings, a "complete" > > API would be very large and difficult to test, and most members of the API would never be used. > > GCC and Clang both support the __atomic intrinsics. This API avoids the problems I > > described above. Or we could use the official C11 syntax (stdatomic.h). But then we > > have the problem with using pre-C11 compilers... > > I have no objection, if everyone agrees to move C11 memory model > with __atomic intrinsics. But if we need to keep both have then > atomic_load_acq_32() kind of API make sense. > > > > > > > > > > > > I think, currently it mixed usage because, the same variable declaration > > used for C11 vs non C11 usage.Ideally we wont need "volatile" for C11 > > case. Either we need to change only to C11 mode OR have APIs for > > atomic_load_acq_() and atomic_store_rel_() to allow both models like > > Linux kernel and FreeBSD. > > > > > > > > -- Ola > > > > > > > > > > > > > > >