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)
May 1 2024, 11:42 PM
Unknown Object (File)
Apr 27 2024, 7:38 AM
Unknown Object (File)
Feb 11 2024, 7:47 PM
Unknown Object (File)
Jan 13 2024, 12:19 AM
Unknown Object (File)
Jan 9 2024, 4:07 AM
Unknown Object (File)
Dec 25 2023, 5:49 AM
Unknown Object (File)
Dec 23 2023, 3:04 AM
Unknown Object (File)
Sep 24 2023, 11:30 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 Not Applicable
Unit
Tests Not Applicable

Event Timeline

sys/kern/kern_cpuset.c
2169

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?

2170

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