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
F93358502: D46152.id.diff
Mon, Sep 9, 3:28 AM
F93352063: D46152.id141421.diff
Mon, Sep 9, 2:44 AM
Unknown Object (File)
Wed, Aug 21, 1:03 PM
Unknown Object (File)
Mon, Aug 19, 12:46 PM
Unknown Object (File)
Fri, Aug 16, 6:17 PM
Unknown Object (File)
Aug 3 2024, 11:35 AM
Unknown Object (File)
Aug 3 2024, 11:32 AM
Unknown Object (File)
Aug 1 2024, 9:49 PM
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 Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/sys/buf_ring.h
106

Does this cmpset still need to have acquire semantics?

sys/sys/buf_ring.h
90

Why do we need critical sections?

sys/sys/buf_ring.h
90

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.

106

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