Page MenuHomeFreeBSD

buf_ring: Use atomic operations with br_cons_tail
ClosedPublic

Authored by andrew on Jul 26 2024, 8:56 AM.
Tags
None
Referenced Files
F137892975: D46152.id142149.diff
Wed, Nov 26, 11:13 PM
Unknown Object (File)
Tue, Nov 25, 2:29 AM
Unknown Object (File)
Thu, Nov 6, 10:49 PM
Unknown Object (File)
Wed, Nov 5, 6:52 AM
Unknown Object (File)
Sat, Nov 1, 12:58 PM
Unknown Object (File)
Sat, Nov 1, 10:51 AM
Unknown Object (File)
Thu, Oct 30, 11:34 AM
Unknown Object (File)
Tue, Oct 28, 5:49 AM
Subscribers

Details

Summary

Use an atomic operation with a memory barrier loading br_cons_tail
from the producer thread and storing to it in the consumer thread.

On dequeue we need to read the pointer value from the buf_ring before
moving the consumer tail as that indicates the entry is available to be
used. The store release atomic operation guarantees this.

In the enqueueing thread we then need to use a load acquire atomic
operation to ensure writing to this entry can only happen after the
tail has been read and checked.

Reported by: Ali Saidi <alisaidi@amazon.com>
Co-developed by: Ali Saidi <alisaidi@amazon.com>
Sponsored by: Arm Ltd

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 58847
Build 55734: arc lint + arc unit

Event Timeline

sys/sys/buf_ring.h
100

Does this cmpset still need to have acquire semantics?

sys/sys/buf_ring.h
83

Why do we need critical sections?

sys/sys/buf_ring.h
83

I think it's because the calls have to complete in order because of the cmpset of br_prod_tail. If the thread was to sleep for too long then it would block other threads from enqueuing.

100

Probably not, but I would need to think about it more.

This revision is now accepted and ready to land.Jul 29 2024, 1:47 PM