Bug 1988151 - Review Request: atomic-queue - C++ lockless queue
Summary: Review Request: atomic-queue - C++ lockless queue
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: Package Review
Version: rawhide
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jerry James
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-07-29 21:07 UTC by Ben Beasley
Modified: 2021-08-25 20:04 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2021-08-25 19:34:21 UTC
Type: ---
Embargoed:
loganjerry: fedora-review+


Attachments (Terms of Use)

Description Ben Beasley 2021-07-29 21:07:58 UTC
Spec URL: https://music.fedorapeople.org/atomic-queue.spec
SRPM URL: https://music.fedorapeople.org/atomic-queue-0-0.1.20210729git8fec762.fc34.src.rpm
Description:

C++14 multiple-producer-multiple-consumer lockless queues based on circular
buffer with std::atomic.

The main design principle these queues follow is minimalism: the bare minimum
of atomic operations, fixed size buffer, value semantics.

These qualities are also limitations:

  • The maximum queue size must be set at compile time or construction time.
    The circular buffer side-steps the memory reclamation problem inherent in
    linked-list based queues for the price of fixed buffer size. See Effective
    memory reclamation for lock-free data structures in C++ for more details.
    Fixed buffer size may not be that much of a limitation, since once the
    queue gets larger than the maximum expected size that indicates a problem
    that elements aren’t processed fast enough, and if the queue keeps growing
    it may eventually consume all available memory which may affect the entire
    system, rather than the problematic process only. The only apparent
    inconvenience is that one has to do an upfront back-of-the-envelope
    calculation on what would be the largest expected/acceptable queue size.
  • There are no OS-blocking push/pop functions. This queue is designed for
    ultra-low-latency scenarios and using an OS blocking primitive would be
    sacrificing push-to-pop latency. For lowest possible latency one cannot
    afford blocking in the OS kernel because the wake-up latency of a blocked
    thread is about 1-3 microseconds, whereas this queue’s round-trip time can
    be as low as 150 nanoseconds.

Ultra-low-latency applications need just that and nothing more. The minimalism
pays off, see the throughput and latency benchmarks.

Available containers are:

  • AtomicQueue - a fixed size ring-buffer for atomic elements.
  • OptimistAtomicQueue - a faster fixed size ring-buffer for atomic elements
    which busy-waits when empty or full.
  • AtomicQueue2 - a fixed size ring-buffer for non-atomic elements.
  • OptimistAtomicQueue2 - a faster fixed size ring-buffer for non-atomic
    elements which busy-waits when empty or full.

These containers have corresponding AtomicQueueB, OptimistAtomicQueueB,
AtomicQueueB2, OptimistAtomicQueueB2 versions where the buffer size is
specified as an argument to the constructor.

Totally ordered mode is supported. In this mode consumers receive messages in
the same FIFO order the messages were posted. This mode is supported for push
and pop functions, but for not the try_ versions. On Intel x86 the totally
ordered mode has 0 cost, as of 2019.

Single-producer-single-consumer mode is supported. In this mode, no
read-modify-write instructions are necessary, only the atomic loads and stores.
That improves queue throughput significantly.

Fedora Account System Username: music

Koji builds:

F35: https://koji.fedoraproject.org/koji/taskinfo?taskID=72932278
F34: https://koji.fedoraproject.org/koji/taskinfo?taskID=72932294
F33: https://koji.fedoraproject.org/koji/taskinfo?taskID=72932296

I am aware of https://docs.fedoraproject.org/en-US/packaging-guidelines/#_architecture_build_failures and will file bugs blocking PPCTracker and F-ExcludeArch-s390x after import.

Comment 1 Ben Beasley 2021-07-31 13:11:57 UTC
My PR to make building the benchmarks optional was merged. Updated submission:

Spec URL: https://music.fedorapeople.org/20210731/atomic-queue.spec
SRPM URL: https://music.fedorapeople.org/20210731/atomic-queue-0-0.1.20210731gitaa08199.fc34.src.rpm

Comment 2 Jerry James 2021-08-14 01:41:51 UTC
I will take this review.

Comment 3 Jerry James 2021-08-14 02:15:37 UTC
Neither issue below warrants blocking the package.  This package is APPROVED.

Package Review
==============

Legend:
[x] = Pass, [!] = Fail, [-] = Not applicable, [?] = Not evaluated


Issues:
=======
- Note the description-line-too-long warning from rpmlint.  There is a macro on
  the indicated line that expands to a fairly long string.

- Regarding support for ppc64le and s390x, it looks like the only assembly is
  in defs.h, used to define the spin_loop_pause() function, right?  If that is
  the case, then it would be correct (although unfriendly to the CPU) to define
  an empty spin_loop_pause() function, or to expand to whatever the no-op
  instruction is for each platform.  For PowerPC, something like this (largely
  stolen from the Linux kernel's arch/powerpc/include/asm/vdso/processor.h):

  namespace atomic_queue {
  constexpr int CACHE_LINE_SIZE = 128;
  static inline void spin_loop_pause() noexcept {
      asm volatile("or 1, 1, 1" ::: "memory");
  }
  }

  For s390x, something like this (again stolen from the Linux kernel, but in
  arch/s390/include/asm/processor.h):

  namespace atomic_queue {
  constexpr int CACHE_LINE_SIZE = 256;
  static inline void spin_loop_pause() noexcept {
      asm volatile("bcr 14,0" ::: "memory");
  }
  }

  I know you aren't upstream, just saying that if you want to see the
  ExclusiveArch go away, it may not be too difficult to make that happen.

===== MUST items =====

C/C++:
[x]: Package does not contain kernel modules.
[x]: Package contains no static executables.
[x]: If your application is a C or C++ application you must list a
     BuildRequires against gcc, gcc-c++ or clang.
[x]: Header files in -devel subpackage, if present.
[x]: Package does not contain any libtool archives (.la)
[x]: Rpath absent or only used for internal libs.

Generic:
[x]: Package is licensed with an open-source compatible license and meets
     other legal requirements as defined in the legal section of Packaging
     Guidelines.
[x]: License field in the package spec file matches the actual license.
[x]: %build honors applicable compiler flags or justifies otherwise.
[x]: Package contains no bundled libraries without FPC exception.
[x]: Changelog in prescribed format.
[x]: Sources contain only permissible code or content.
[-]: Package contains desktop file if it is a GUI application.
[x]: Development files must be in a -devel package
[x]: Package uses nothing in %doc for runtime.
[x]: Package consistently uses macros (instead of hard-coded directory
     names).
[x]: Package is named according to the Package Naming Guidelines.
[x]: Package does not generate any conflict.
[x]: Package obeys FHS, except libexecdir and /usr/target.
[-]: If the package is a rename of another package, proper Obsoletes and
     Provides are present.
[x]: Requires correct, justified where necessary.
[x]: Spec file is legible and written in American English.
[-]: Package contains systemd file(s) if in need.
[-]: Useful -debuginfo package or justification otherwise.
[!]: Package is not known to require an ExcludeArch tag.

     It needs an ExclusiveArch tag.  See comment above about that.

[-]: Large documentation must go in a -doc subpackage. Large could be size
     (~1MB) or number of files.
     Note: Documentation size is 20480 bytes in 1 files.
[x]: Package complies to the Packaging Guidelines
[x]: Package successfully compiles and builds into binary rpms on at least
     one supported primary architecture.
[x]: Package installs properly.
[x]: Rpmlint is run on all rpms the build produces.
     Note: There are rpmlint messages (see attachment).
[x]: If (and only if) the source package includes the text of the
     license(s) in its own file, then that file, containing the text of the
     license(s) for the package is included in %license.
[x]: Package requires other packages for directories it uses.
[x]: Package must own all directories that it creates.
[x]: Package does not own files or directories owned by other packages.
[x]: Package uses either %{buildroot} or $RPM_BUILD_ROOT
[x]: Package does not run rm -rf %{buildroot} (or $RPM_BUILD_ROOT) at the
     beginning of %install.
[x]: Macros in Summary, %description expandable at SRPM build time.
[x]: Package does not contain duplicates in %files.
[x]: Permissions on files are set properly.
[x]: Package must not depend on deprecated() packages.
[x]: Package use %makeinstall only when make install DESTDIR=... doesn't
     work.
[x]: Package is named using only allowed ASCII characters.
[x]: Package does not use a name that already exists.
[x]: Package is not relocatable.
[x]: Sources used to build the package match the upstream source, as
     provided in the spec URL.
[x]: Spec file name must match the spec package %{name}, in the format
     %{name}.spec.
[x]: File names are valid UTF-8.
[x]: Packages must not store files under /srv, /opt or /usr/local

===== SHOULD items =====

Generic:
[-]: If the source package does not include license text(s) as a separate
     file from upstream, the packager SHOULD query upstream to include it.
[x]: Final provides and requires are sane (see attachments).
[?]: Package functions as described.
[x]: Latest version is packaged.
[x]: Package does not include license text files separate from upstream.
[-]: Sources are verified with gpgverify first in %prep if upstream
     publishes signatures.
     Note: gpgverify is not used.
[-]: Description and summary sections in the package spec file contains
     translations for supported Non-English languages, if available.
[x]: %check is present and all tests pass.
[x]: Packages should try to preserve timestamps of original installed
     files.
[x]: Reviewer should test that the package builds in mock.
[x]: Buildroot is not present
[x]: Package has no %clean section with rm -rf %{buildroot} (or
     $RPM_BUILD_ROOT)
[x]: No file requires outside of /etc, /bin, /sbin, /usr/bin, /usr/sbin.
[x]: Packager, Vendor, PreReq, Copyright tags should not be in spec file
[x]: Sources can be downloaded from URI in Source: tag
[x]: SourceX is a working URL.
[x]: Package should compile and build into binary rpms on all supported
     architectures.
[x]: Spec use %global instead of %define unless justified.

===== EXTRA items =====

Generic:
[x]: Rpmlint is run on all installed packages.
     Note: There are rpmlint messages (see attachment).
[x]: Large data in /usr/share should live in a noarch subpackage if package
     is arched.
[x]: Spec file according to URL is the same as in SRPM.


Rpmlint
-------
Checking: atomic-queue-devel-0-0.1.20210731gitaa08199.fc36.x86_64.rpm
          atomic-queue-0-0.1.20210731gitaa08199.fc36.src.rpm
atomic-queue-devel.x86_64: W: spelling-error %description -l en_US lockless -> luckless, lock less, lock-less
atomic-queue-devel.x86_64: W: spelling-error %description -l en_US aren -> earn, are, arena
atomic-queue-devel.x86_64: E: description-line-too-long C The atomic-queue-devel package contains libraries and header files for developing
atomic-queue.src: W: spelling-error Summary(en_US) lockless -> luckless, lock less, lock-less
atomic-queue.src: W: spelling-error %description -l en_US lockless -> luckless, lock less, lock-less
atomic-queue.src: W: spelling-error %description -l en_US aren -> earn, are, arena
atomic-queue.src:124: W: macro-in-%changelog %autochangelog
2 packages and 0 specfiles checked; 1 errors, 6 warnings.




Rpmlint (installed packages)
----------------------------
rpmlint: 2.0.0
configuration:
    /usr/lib/python3.10/site-packages/rpmlint/configdefaults.toml
    /etc/xdg/rpmlint/fedora.toml
    /etc/xdg/rpmlint/licenses.toml
    /etc/xdg/rpmlint/scoring.toml
    /etc/xdg/rpmlint/users-groups.toml
    /etc/xdg/rpmlint/warn-on-functions.toml
checks: 31, packages: 1

atomic-queue-devel.x86_64: E: description-line-too-long The atomic-queue-devel package contains libraries and header files for developing
================= 1 packages and 0 specfiles checked; 1 errors, 0 warnings, 1 badness; has taken 0.0 s =================


Source checksums
----------------
https://github.com/max0x7ba/atomic_queue/archive/aa08199a7a516a561be1685afb644cf99e5b98e9/atomic_queue-aa08199a7a516a561be1685afb644cf99e5b98e9.tar.gz :
  CHECKSUM(SHA256) this package     : a5bab145a2185993d6c81437f263d7bf557bfd8f4d31d4ad3c720136b5402f63
  CHECKSUM(SHA256) upstream package : a5bab145a2185993d6c81437f263d7bf557bfd8f4d31d4ad3c720136b5402f63


Requires
--------
atomic-queue-devel (rpmlib, GLIBC filtered):



Provides
--------
atomic-queue-devel:
    atomic-queue-devel
    atomic-queue-devel(x86-64)
    atomic-queue-static



Generated by fedora-review 0.7.6 (b083f91) last change: 2020-11-10
Command line :/usr/bin/fedora-review -b 1988151 -m fedora-rawhide-x86_64
Buildroot used: fedora-rawhide-x86_64
Active plugins: C/C++, Generic, Shell-api
Disabled plugins: Python, Perl, fonts, PHP, Java, Haskell, Ruby, SugarActivity, Ocaml, R
Disabled flags: EPEL6, EPEL7, DISTTAG, BATCH, EXARCH

Comment 4 Ben Beasley 2021-08-16 20:29:14 UTC
Thanks for the review!

> - Note the description-line-too-long warning from rpmlint.  There is a macro on
>   the indicated line that expands to a fairly long string.

Thanks! I’ll fix this.

> - Regarding support for ppc64le and s390x, it looks like the only assembly is
>  in defs.h, used to define the spin_loop_pause() function, right?

Correct, this is the only bit that has to be written to enable additional
architectures. I’d love to be able to fill in the missing architectures.

>                                                                   If that is
>   the case, then it would be correct (although unfriendly to the CPU) to define
>   an empty spin_loop_pause() function, or to expand to whatever the no-op
>   instruction is for each platform.  For PowerPC, something like this (largely
>   stolen from the Linux kernel's arch/powerpc/include/asm/vdso/processor.h):
> 
>   […]
>
>  I know you aren't upstream, just saying that if you want to see the
>  ExclusiveArch go away, it may not be too difficult to make that happen.

Your suggestions are probably correct, but since this package is MIT-licensed, I can’t use anything copied from the GPL-licensed Linux kernel, and I don’t know either missing architecture well enough to craft something I am confident in from first principles.

Comment 5 Gwyn Ciesla 2021-08-16 20:31:00 UTC
(fedscm-admin):  The Pagure repository was created at https://src.fedoraproject.org/rpms/atomic-queue

Comment 6 Jerry James 2021-08-16 22:11:31 UTC
(In reply to Ben Beasley from comment #4)
> Your suggestions are probably correct, but since this package is
> MIT-licensed, I can’t use anything copied from the GPL-licensed Linux
> kernel, and I don’t know either missing architecture well enough to craft
> something I am confident in from first principles.

Fair enough.  If the missing architectures ever become burdensome, though, simply supplying an empty spin_loop_pause() function should be correct, although you may be able to cook dinner on your CPU if you actually run the code. :-)

Comment 7 Ben Beasley 2021-08-17 13:35:29 UTC
I’ll go ahead and create the tracker bugs for the missing architectures. It might still be possible to resolve them with some care, and perhaps consultation with upstream.

I think I now basically understand the requirements for a minimal “empty” spin_loop_pause(). The fallback for ARMs that don’t support the “yield” instruction is a good example. It’s a “nop” instruction plus a memory clobber, to create a “compiler barrier” that keeps the compiler from eliding, hoisting, or otherwise subverting the pause function. This is exactly what the example you gave for PowerPC is doing. “or 1 1 1” is an idiomatic nop for PowerPC, or’ing a register with itself to waste time with no effect.

I’m not so sure about the s390x example from Linux. As far as I can understand from the limited documentation I’ve found, it’s a conditional branch where the condition is zero so the branch is not taken. However, it seems the first argument somehow causes the BCR instruction to have a synchronization function as well (https://github.com/golang/go/issues/42479), although I haven’t found good documentation on the exact effects. I assume this is intentional, and I wonder why it is needed.

Comment 8 Fedora Update System 2021-08-17 13:59:09 UTC
FEDORA-2021-4b83d81872 has been submitted as an update to Fedora 34. https://bodhi.fedoraproject.org/updates/FEDORA-2021-4b83d81872

Comment 9 Fedora Update System 2021-08-17 13:59:50 UTC
FEDORA-2021-69a5c768aa has been submitted as an update to Fedora 33. https://bodhi.fedoraproject.org/updates/FEDORA-2021-69a5c768aa

Comment 10 Fedora Update System 2021-08-17 21:26:42 UTC
FEDORA-EPEL-2021-076a96c8a6 has been submitted as an update to Fedora EPEL 8. https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2021-076a96c8a6

Comment 11 Fedora Update System 2021-08-18 01:21:50 UTC
FEDORA-2021-69a5c768aa has been pushed to the Fedora 33 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf install --enablerepo=updates-testing --advisory=FEDORA-2021-69a5c768aa \*`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2021-69a5c768aa

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 12 Fedora Update System 2021-08-18 01:32:49 UTC
FEDORA-EPEL-2021-076a96c8a6 has been pushed to the Fedora EPEL 8 testing repository.

You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-EPEL-2021-076a96c8a6

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 13 Fedora Update System 2021-08-18 01:54:31 UTC
FEDORA-2021-4b83d81872 has been pushed to the Fedora 34 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf install --enablerepo=updates-testing --advisory=FEDORA-2021-4b83d81872 \*`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2021-4b83d81872

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 14 Fedora Update System 2021-08-25 19:34:21 UTC
FEDORA-EPEL-2021-076a96c8a6 has been pushed to the Fedora EPEL 8 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 15 Fedora Update System 2021-08-25 19:54:30 UTC
FEDORA-2021-4b83d81872 has been pushed to the Fedora 34 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 16 Fedora Update System 2021-08-25 20:04:15 UTC
FEDORA-2021-69a5c768aa has been pushed to the Fedora 33 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.