mbox series

[v3,0/7] Introduce Sequence Number Ops

Message ID cover.1612314468.git.skhan@linuxfoundation.org
Headers show
Series Introduce Sequence Number Ops | expand

Message

Shuah Khan Feb. 3, 2021, 6:11 p.m. UTC
Sequence Number api provides interfaces for unsigned atomic up counters.

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.

Sequence Number ops provide interfaces to initialize, increment and get
the sequence number. These ops also check for overflow and log message to
indicate when overflow occurs. This check is intended to help catch cases
where overflow could lead to problems.

Since v2:
- Uses atomic_inc_return() for incrementing the sequence number.
- No longer uses atomic_read()

Shuah Khan (7):
  seqnum_ops: Introduce Sequence Number Ops
  selftests: lib:test_seqnum_ops: add new test for seqnum_ops
  drivers/acpi: convert seqno to use seqnum_ops
  drivers/acpi/apei: convert seqno to seqnum_ops
  drivers/staging/rtl8723bs: convert event_seq to use seqnum_ops
  drivers/staging/rtl8188eu: convert event_seq to use seqnum_ops
  kobject: convert uevent_seqnum to seqnum_ops

 Documentation/core-api/index.rst              |   1 +
 Documentation/core-api/seqnum_ops.rst         |  62 ++++++++
 MAINTAINERS                                   |   8 ++
 drivers/acpi/acpi_extlog.c                    |   8 +-
 drivers/acpi/apei/ghes.c                      |   8 +-
 drivers/staging/rtl8188eu/core/rtw_mlme_ext.c |  23 ++-
 .../staging/rtl8188eu/include/rtw_mlme_ext.h  |   3 +-
 drivers/staging/rtl8723bs/core/rtw_cmd.c      |   3 +-
 drivers/staging/rtl8723bs/core/rtw_mlme_ext.c |  33 +++--
 drivers/staging/rtl8723bs/include/rtw_cmd.h   |   3 +-
 .../staging/rtl8723bs/include/rtw_mlme_ext.h  |   3 +-
 include/linux/kobject.h                       |   3 +-
 include/linux/seqnum_ops.h                    | 131 +++++++++++++++++
 kernel/ksysfs.c                               |   3 +-
 lib/Kconfig                                   |   9 ++
 lib/Makefile                                  |   1 +
 lib/kobject_uevent.c                          |   9 +-
 lib/test_seqnum_ops.c                         | 133 ++++++++++++++++++
 tools/testing/selftests/lib/Makefile          |   1 +
 tools/testing/selftests/lib/config            |   1 +
 .../testing/selftests/lib/test_seqnum_ops.sh  |  10 ++
 21 files changed, 423 insertions(+), 33 deletions(-)
 create mode 100644 Documentation/core-api/seqnum_ops.rst
 create mode 100644 include/linux/seqnum_ops.h
 create mode 100644 lib/test_seqnum_ops.c
 create mode 100755 tools/testing/selftests/lib/test_seqnum_ops.sh

Comments

Rafael J. Wysocki Feb. 4, 2021, 2:01 p.m. UTC | #1
Hi Shuah,

First off, please indicate the component in the subject, for example:

"ACPI: extlog: convert seqno to use seqnum_ops"

On Wed, Feb 3, 2021 at 7:12 PM Shuah Khan <skhan@linuxfoundation.org> wrote:
>

> Sequence Number api provides interfaces for unsigned atomic up counters

> leveraging atomic_t and atomic64_t ops underneath.

>

> Convert seqno atomic counter to use seqnum_ops.


Apart from the above, it would be good to say why the change is an improvement.

It looks like the rationale is that using struct seqnum32 would allow
tools to easily detect the usage of sequence numbers, but is there
anything else in this particular case?

> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>

> ---

>  drivers/acpi/acpi_extlog.c | 8 ++++----

>  1 file changed, 4 insertions(+), 4 deletions(-)

>

> diff --git a/drivers/acpi/acpi_extlog.c b/drivers/acpi/acpi_extlog.c

> index 72f1fb77abcd..16a4928645a1 100644

> --- a/drivers/acpi/acpi_extlog.c

> +++ b/drivers/acpi/acpi_extlog.c

> @@ -12,6 +12,7 @@

>  #include <linux/ratelimit.h>

>  #include <linux/edac.h>

>  #include <linux/ras.h>

> +#include <linux/seqnum_ops.h>

>  #include <asm/cpu.h>

>  #include <asm/mce.h>

>

> @@ -93,8 +94,7 @@ static struct acpi_hest_generic_status *extlog_elog_entry_check(int cpu, int ban

>  static void __print_extlog_rcd(const char *pfx,

>                                struct acpi_hest_generic_status *estatus, int cpu)

>  {

> -       static atomic_t seqno;

> -       unsigned int curr_seqno;

> +       static struct seqnum32 seqno;

>         char pfx_seq[64];

>

>         if (!pfx) {

> @@ -103,8 +103,8 @@ static void __print_extlog_rcd(const char *pfx,

>                 else

>                         pfx = KERN_ERR;

>         }

> -       curr_seqno = atomic_inc_return(&seqno);

> -       snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}", pfx, curr_seqno);

> +       snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}", pfx,

> +                seqnum32_inc(&seqno));

>         printk("%s""Hardware error detected on CPU%d\n", pfx_seq, cpu);

>         cper_estatus_print(pfx_seq, estatus);

>  }

> --

> 2.27.0

>