Page MenuHomeFreeBSD

cpuset: Fix sched_[g|s]etaffinity() for better compatibility with Linux.
ClosedPublic

Authored by dchagin on Jan 26 2023, 9:31 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Nov 17, 1:30 AM
Unknown Object (File)
Sat, Nov 16, 6:20 PM
Unknown Object (File)
Thu, Nov 14, 7:27 PM
Unknown Object (File)
Wed, Nov 13, 3:53 PM
Unknown Object (File)
Wed, Nov 13, 8:32 AM
Unknown Object (File)
Tue, Nov 12, 1:13 PM
Unknown Object (File)
Sat, Nov 9, 1:26 PM
Unknown Object (File)
Mon, Oct 21, 4:50 PM
Subscribers

Details

Summary

Under Linux to sched_[g|s]etaffinity() functions the value returned from a call
to gettid(2) (thread id) can be passed in the argument pid. Specifying pid as 0
will set the attribute for the calling thread, and passing the value returned
from a call to getpid(2) (process id) will set the attribute for the main thread
of the thread group.

Native cpuset(2) family of system calls has "which" argument to determine how
the value of id argument is interpreted, i.e., CPU_WHICH_TID is used to pass
a thread id and CPU_WHICH_PID - to pass a process id.

For now native sched_[g|s]etaffinity() implementation is wrong as uses "which"
CPU_WHICH_PID to pass both (process and thread id) to the kernel. To fix this
adding a new "which" CPU_WHICH_TIDORPID intended to handle both id's.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 49286
Build 46176: arc lint + arc unit

Event Timeline

sys/kern/kern_cpuset.c
2156

I do not see a need of this if statement for CPU_WHICH_PID. IMO duplicating cpuset_setproc() line is not too much duplication for simplifying the if() condition. You can remove CPU_WHICH_TID from the check.

Same for the other cases.

sys/sys/cpuset.h
112

thanks, fixed, looks better )

sys/kern/kern_cpuset.c
1762
1997–1999

So this changes semantic for CPU_WHICH_TID, making it to accept pid and return OR of all threads' cpuset masks.

Is it intended? Is it needed?

2157

Again, this makes CPU_WHICH _TID accept pid.

dchagin added inline comments.
sys/kern/kern_cpuset.c
1997–1999

well, I dont think so, the cpuset_which() above do not permit such cases, i.e., specify pid for CPU_WHICH_TID and vice versa. However, to avoid confusing, I will redo this.

This revision is now accepted and ready to land.Jan 28 2023, 6:20 PM

The cpuset(2) should be updated with CPU_WHICH_TIDPID

Well, I wasn't planning adding the new which to the manual as
handling of it is incomplete. Below is an attempt to handle new which.
Compile tested

This revision now requires review to proceed.Jan 28 2023, 10:25 PM
lib/libc/sys/cpuset.2
103
This revision is now accepted and ready to land.Jan 29 2023, 12:37 PM