From: Shuah Khan <skhan@linuxfoundation.org>
To: Matthew Wilcox <willy@infradead.org>
Cc: corbet@lwn.net, keescook@chromium.org,
gregkh@linuxfoundation.org, peterz@infradead.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
Shuah Khan <skhan@linuxfoundation.org>
Subject: Re: [PATCH v2 01/13] seqnum_ops: Introduce Sequence Number Ops
Date: Tue, 17 Nov 2020 09:34:24 -0700 [thread overview]
Message-ID: <13467f88-7e22-ce3e-60b6-44e7c3dfa7dc@linuxfoundation.org> (raw)
In-Reply-To: <20201113210327.GJ17076@casper.infradead.org>
On 11/13/20 2:03 PM, Matthew Wilcox wrote:
>> +==========================
>> +Sequence Number Operations
>> +==========================
>> +
>> +:Author: Shuah Khan
>> +:Copyright: |copy| 2020, The Linux Foundation
>> +:Copyright: |copy| 2020, Shuah Khan <skhan@linuxfoundation.org>
>> +
>> +Sequence Number api provides interfaces for unsigned up counters
>> +leveraging atomic_t and atomic64_t ops underneath.
>
> As I said last time you posted this, the documentation is all
> back-to-front. You're describing what it isn't, not what it is.
>
I will rephrase it to read better.
>> +There are a number of atomic_t usages in the kernel where atomic_t api
>> +is used for counting sequence numbers and other statistical counters.
>> +Several of these usages, convert atomic_read() and atomic_inc_return()
>> +return values to unsigned. Introducing sequence number ops supports
>> +these use-cases with a standard core-api.
>> +
>> +The atomic_t api provides a wide range of atomic operations as a base
>> +api to implement atomic counters, bitops, spinlock interfaces. The usages
>> +also evolved into being used for resource lifetimes and state management.
>> +The refcount_t api was introduced to address resource lifetime problems
>> +related to atomic_t wrapping. There is a large overlap between the
>> +atomic_t api used for resource lifetimes and just counters, stats, and
>> +sequence numbers. It has become difficult to differentiate between the
>> +atomic_t usages that should be converted to refcount_t and the ones that
>> +can be left alone. Introducing seqnum_ops to wrap the usages that are
>> +stats, counters, sequence numbers makes it easier for tools that scan
>> +for underflow and overflow on atomic_t usages to detect overflow and
>> +underflows to scan just the cases that are prone to errors.
>> +
>> +In addition, to supporting sequence number use-cases, Sequence Number Ops
>> +helps differentiate atomic_t counter usages from atomic_t usages that guard
>> +object lifetimes, hence prone to overflow and underflow errors from up
>> +counting use-cases.
>
> I think almost all of this information should go into atomic_ops.rst
> pushing people towards using the other APIs instead of atomic_t.
> Someone who already landed here doesn't want to read about refcount_t.
> They want to know what a seqnum_t is and how to use it.
>
Looks like this is resolved with atomic_ops.rst is now gone.
>> +Sequence Number Ops
>> +===================
>> +
>> +seqnum32 and seqnum64 types use atomic_t and atomic64_t underneath to
>
> Don't talk about the implementation.
>
>> +leverage atomic_t api, to provide increment by 1 and return new value
>> +and fetch current value interfaces necessary to support unsigned up
>> +counters. ::
>> +
>> + struct seqnum32 { atomic_t seqnum; };
>> + struct seqnum64 { atomic64_t seqnum; };
>> +
>> +Please see :ref:`Documentation/core-api/atomic_ops.rst <atomic_ops>` for
>> +information on the Semantics and Behavior of Atomic operations.
>> +
>> +Initializers
>> +------------
>> +
>> +Interfaces for initializing sequence numbers are write operations which
>> +in turn invoke their ``ATOMIC_INIT() and atomic_set()`` counterparts ::
>> +
>> + #define SEQNUM_INIT(i) { .seqnum = ATOMIC_INIT(i) }
>> + seqnum32_init() --> atomic_set() to 0
>> + seqnum64_init() --> atomic64_set() to 0
>> +
>> +Increment interface
>> +-------------------
>> +
>> +Increments sequence number and returns the new value. ::
>> +
>> + seqnum32_inc_return() --> (u32) atomic_inc_return(seqnum)
>> + seqnum64_inc_return() --> (u64) atomic64_inc_return(seqnum)
>
> seqnum_inc() should just return the new value -- seqnum_inc_return is
> too verbose. And do we not need a seqnum_add()?
>
I had the patch series with seqnum_inc() all ready to go and then
revisited the choice. My thinking is that matching the current atomic
api that has _inc() and inc_return() might be less confusing. That
being said, I have no problems with making just _inc(). The reason
for 32 and 64 appended is based on comments that it including size
in the api makes it very clear.
No need for atomic_add() - inc_return() is sufficient for this use-case.
> Also, this would be a good point to talk about behaviour on overflow.
>
I can add some overflow information.
thanks,
-- Shuah
next prev parent reply other threads:[~2020-11-17 16:34 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-13 17:46 [PATCH v2 00/13] Introduce seqnum_ops Shuah Khan
2020-11-13 17:46 ` [PATCH v2 01/13] seqnum_ops: Introduce Sequence Number Ops Shuah Khan
2020-11-13 21:03 ` Matthew Wilcox
2020-11-16 14:49 ` Peter Zijlstra
2020-11-16 14:58 ` Peter Zijlstra
2020-11-17 14:50 ` Shuah Khan
2020-11-17 15:21 ` Peter Zijlstra
2020-11-17 16:34 ` Shuah Khan [this message]
2020-11-17 17:38 ` Matthew Wilcox
2020-11-17 18:23 ` Shuah Khan
2020-11-17 18:24 ` Shuah Khan
2020-11-16 14:53 ` Peter Zijlstra
2020-11-17 16:15 ` Shuah Khan
2020-11-13 17:46 ` [PATCH v2 02/13] selftests: lib:test_seqnum_ops: add new test for seqnum_ops Shuah Khan
2020-11-13 17:46 ` [PATCH v2 03/13] drivers/acpi: convert seqno seqnum_ops Shuah Khan
2020-11-13 17:46 ` [PATCH v2 04/13] drivers/acpi/apei: convert seqno to seqnum_ops Shuah Khan
2020-11-13 17:46 ` [PATCH v2 05/13] drivers/base/test/test_async_driver_probe: convert to use seqnum_ops Shuah Khan
2020-11-13 17:46 ` [PATCH v2 06/13] drivers/char/ipmi: convert stats " Shuah Khan
2020-11-13 17:46 ` [PATCH v2 07/13] drivers/edac: convert pci counters to seqnum_ops Shuah Khan
2020-11-13 17:46 ` [PATCH v2 08/13] drivers/oprofile: convert stats to use seqnum_ops Shuah Khan
2020-11-13 17:46 ` [PATCH v2 09/13] drivers/staging/rtl8723bs: " Shuah Khan
2020-11-13 17:46 ` [PATCH v2 10/13] usb: usbip/vhci: convert seqno to seqnum_ops Shuah Khan
2020-11-13 17:46 ` [PATCH v2 11/13] drivers/staging/rtl8188eu: convert stats to use seqnum_ops Shuah Khan
2020-11-13 17:46 ` [PATCH v2 12/13] drivers/staging/unisys/visorhba: " Shuah Khan
2020-11-13 17:46 ` [PATCH v2 13/13] security/integrity/ima: converts stats to seqnum_ops Shuah Khan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=13467f88-7e22-ce3e-60b6-44e7c3dfa7dc@linuxfoundation.org \
--to=skhan@linuxfoundation.org \
--cc=corbet@lwn.net \
--cc=gregkh@linuxfoundation.org \
--cc=keescook@chromium.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome