Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752484AbdLEHgo (ORCPT ); Tue, 5 Dec 2017 02:36:44 -0500 Received: from mga14.intel.com ([192.55.52.115]:28624 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752431AbdLEHgm (ORCPT ); Tue, 5 Dec 2017 02:36:42 -0500 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,363,1508828400"; d="scan'208";a="10639959" From: "Reshetova, Elena" To: Randy Dunlap , "peterz@infradead.org" CC: "linux-kernel@vger.kernel.org" , "keescook@chromium.org" , "david@fromorbit.com" Subject: RE: [PATCH] refcount_t: documentation for memory ordering differences Thread-Topic: [PATCH] refcount_t: documentation for memory ordering differences Thread-Index: AQHTaQ8EfESScr39uUyqIumZ/UYH7KMu9W2AgAVvTrA= Date: Tue, 5 Dec 2017 07:36:39 +0000 Message-ID: <2236FBA76BA1254E88B949DDB74E612B802C8117@IRSMSX102.ger.corp.intel.com> References: <1511958996-19501-1-git-send-email-elena.reshetova@intel.com> <1511958996-19501-2-git-send-email-elena.reshetova@intel.com> <2dbef3c8-a70f-9584-2de5-3440520f224a@infradead.org> In-Reply-To: <2dbef3c8-a70f-9584-2de5-3440520f224a@infradead.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-ctpclassification: CTP_IC x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiMjNiMTI0OWQtN2Y1NC00MDE0LWFkZWEtN2FiMGYyNDRkZmM5IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX0lDIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjIuNS4xOCIsIlRydXN0ZWRMYWJlbEhhc2giOiJsSzAwQXJibjFRWmJpZkl6NEUycUl0THpBYzlrd3JYc25YVUJwMU9MQWNJM1dyM3ZSK2ZpWWVpMUxnbit1M1Z4In0= x-originating-ip: [163.33.239.182] Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by nfs id vB57amp2020904 Content-Length: 3979 Lines: 91 On 11/29/2017 04:36 AM, Elena Reshetova wrote: > > Some functions from refcount_t API provide different > > memory ordering guarantees that their atomic counterparts. > > This adds a document outlining these differences. > > > > Signed-off-by: Elena Reshetova > > --- > > Documentation/core-api/index.rst | 1 + > > Documentation/core-api/refcount-vs-atomic.rst | 129 > ++++++++++++++++++++++++++ > > 2 files changed, 130 insertions(+) > > create mode 100644 Documentation/core-api/refcount-vs-atomic.rst > > > diff --git a/Documentation/core-api/refcount-vs-atomic.rst > b/Documentation/core-api/refcount-vs-atomic.rst > > new file mode 100644 > > index 0000000..5619d48 > > --- /dev/null > > +++ b/Documentation/core-api/refcount-vs-atomic.rst > > @@ -0,0 +1,129 @@ > > +=================================== > > +refcount_t API compared to atomic_t > > +=================================== > > + > > +The goal of refcount_t API is to provide a minimal API for implementing > > +an object's reference counters. While a generic architecture-independent > > +implementation from lib/refcount.c uses atomic operations underneath, > > +there are a number of differences between some of the refcount_*() and > > +atomic_*() functions with regards to the memory ordering guarantees. > > +This document outlines the differences and provides respective examples > > +in order to help maintainers validate their code against the change in > > +these memory ordering guarantees. > > + > > +memory-barriers.txt and atomic_t.txt provide more background to the > > +memory ordering in general and for atomic operations specifically. > > + > > +Relevant types of memory ordering > > +================================= > > + > > +**Note**: the following section only covers some of the memory > > +ordering types that are relevant for the atomics and reference > > +counters and used through this document. For a much broader picture > > +please consult memory-barriers.txt document. > > + > > +In the absence of any memory ordering guarantees (i.e. fully unordered) > > +atomics & refcounters only provide atomicity and > > +program order (po) relation (on the same CPU). It guarantees that > > +each atomic_*() and refcount_*() operation is atomic and instructions > > +are executed in program order on a single CPU. > > +This is implemented using READ_ONCE()/WRITE_ONCE() and > > +compare-and-swap primitives. > > + > > +A strong (full) memory ordering guarantees that all prior loads and > > +stores (all po-earlier instructions) on the same CPU are completed > > +before any po-later instruction is executed on the same CPU. > > +It also guarantees that all po-earlier stores on the same CPU > > +and all propagated stores from other CPUs must propagate to all > > +other CPUs before any po-later instruction is executed on the original > > +CPU (A-cumulative property). This is implemented using smp_mb(). > > I don't know what "A-cumulative property" means, and google search didn't > either. > > Is it non-cumulative, similar to typical vs. atypical, where atypical > roughly means non-typical. Or is it accumlative (something being > accumulated, summed up, gathered up)? > > Or is it something else.. TBD? Sorry, I should have mentioned also explicitly in this document where the terms are coming from. I have mentioned in cover letter, but failed to say here. I will fix it. Thank you for catching! I see that reply was already given to this by Andrea. Best Regards, Elena > > > +A RELEASE memory ordering guarantees that all prior loads and > > +stores (all po-earlier instructions) on the same CPU are completed > > +before the operation. It also guarantees that all po-earlier > > +stores on the same CPU and all propagated stores from other CPUs > > +must propagate to all other CPUs before the release operation > > +(A-cumulative property). This is implemented using smp_store_release(). > > thanks. > -- > ~Randy