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
F97763800: D38209.diff
Tue, Oct 1, 4:14 AM
F97600748: D38209.id116002.diff
Mon, Sep 30, 7:12 AM
Unknown Object (File)
Fri, Sep 27, 12:10 PM
Unknown Object (File)
Wed, Sep 25, 12:09 PM
Unknown Object (File)
Tue, Sep 24, 8:37 AM
Unknown Object (File)
Sun, Sep 22, 5:12 PM
Unknown Object (File)
Fri, Sep 20, 9:24 PM
Unknown Object (File)
Fri, Sep 20, 9:14 AM
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 49239
Build 46129: arc lint + arc unit

Event Timeline

sys/kern/kern_cpuset.c
2154

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
118

thanks, fixed, looks better )

sys/kern/kern_cpuset.c
1756
1990–1991

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?

2156

Again, this makes CPU_WHICH _TID accept pid.

dchagin added inline comments.
sys/kern/kern_cpuset.c
1990–1991

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 ↗(On Diff #115987)
This revision is now accepted and ready to land.Jan 29 2023, 12:37 PM