Page MenuHomeFreeBSD

linuxkpi: Add `rwsem_is_contended()`
Needs ReviewPublic

Authored by dumbbell on Thu, Apr 16, 9:01 PM.
Tags
None
Referenced Files
F154037729: D56443.diff
Sat, Apr 25, 3:49 PM
F153998235: D56443.diff
Sat, Apr 25, 8:35 AM
Unknown Object (File)
Fri, Apr 24, 9:00 PM
Unknown Object (File)
Wed, Apr 22, 4:26 PM
Unknown Object (File)
Wed, Apr 22, 4:10 PM
Unknown Object (File)
Wed, Apr 22, 1:31 AM
Unknown Object (File)
Tue, Apr 21, 12:44 AM
Unknown Object (File)
Mon, Apr 20, 5:49 PM
Subscribers

Details

Reviewers
bz
Group Reviewers
linuxkpi
Summary

This function indicates to the caller if other threads are waiting for this semaphore. It is assumed that the caller holds the semaphore, though it is not asserted.

To be able to implement this function, a new waiters_count field was added to struct rw_semaphone.

This counter is incremented and decremented by modified versions of down_{read,write}(). Here is what they now do in pseudo code:

if (!try lock) {
    waiters_count++;
    blocking lock;
    waiters_count--;
}

On Linux, they would manage this using a wait list and an internal lock to protect this list.

down_{read_write}() functions are moved to a C file because they are a bit more involved than the simple alias to sx_*lock(). up_{read_write}() were moved as well to keep them together.

The amdgpu DRM driver started to use rwsem_is_contended() in Linux 6.12.

This is part of the update of DRM drivers to Linux 6.12.

Sponsored by: The FreeBSD Foundation

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

Uploaded the wrong patch before.

bz requested changes to this revision.Mon, Apr 20, 10:29 PM
bz added a subscriber: bz.
bz added inline comments.
sys/compat/linuxkpi/common/include/linux/rwsem.h
56–67

The should use linuxkpi_ not linux_ given we are changing things anyway already.

sys/compat/linuxkpi/common/src/linux_rwsem.c
11

This is copyright someone else in theory; 684bcfec8994ed608775ecd3f848406253be60b1 and before that in ofed aa0a1e58f0189.

@emaste?

23

So this is done w/o any lock; can we rely on ++ / -- for this here and in down_read?

This revision now requires changes to proceed.Mon, Apr 20, 10:29 PM
sys/compat/linuxkpi/common/src/linux_rwsem.c
23

I’m not 100% confident myself. Should I use atomic operations here?