Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F156442713
D51196.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D51196.id.diff
View Options
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -298,6 +298,7 @@
setjmp.3 \
setmode.3 \
setproctitle.3 \
+ sched_getaffinity.3 \
siginterrupt.3 \
signal.3 \
sigsetops.3 \
@@ -519,6 +520,7 @@
setjmp.3 sigsetjmp.3
MLINKS+=setmode.3 getmode.3
MLINKS+=setproctitle.3 setproctitle_fast.3
+MLINKS+=sched_getaffinity.3
MLINKS+=sigsetops.3 sigaddset.3 \
sigsetops.3 sigandset.3 \
sigsetops.3 sigdelset.3 \
diff --git a/lib/libc/gen/sched_getaffinity.3 b/lib/libc/gen/sched_getaffinity.3
new file mode 100644
--- /dev/null
+++ b/lib/libc/gen/sched_getaffinity.3
@@ -0,0 +1,92 @@
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.\" Copyright (c) 2025 Felix Johnson
+.Dd June 30, 2025
+.Dt SCHED_GETAFFINITY 3
+.Os
+.Sh NAME
+.Nm sched_getaffinity ,
+.Nm sched_setaffinity
+.Nd get or set thread to CPU affinity
+.Sh SYNOPSIS
+.Lb libc
+.In sched.h
+.Ft int
+.Fo sched_getaffinity
+.Fa "pid_t pid"
+.Fa "size_t cpusetsz"
+.Fa "cpuset_t *cpuset"
+.Fc
+.Ft int
+.Fo sched_setaffinity
+.Fa "pid_t pid"
+.Fa "size_t cpusetsz"
+.Fa "const cpuset_t *cpuset"
+.Fc
+.Sh DESCRIPTION
+The
+.Fn sched_getaffinity
+function retrieves the current CPU affinity mask for
+a thread or process.
+.Pp
+The
+.Fn sched_setaffinity
+function sets the CPU affinity mask for a given thread
+or process, specifying which CPUs it is eligible to run on.
+.Pp
+The value of the
+.Fa pid
+parameter determines whether a thread or process is the target.
+If the value is 0,
+.Fa pid
+refers to the calling thread.
+If the value is greater than zero and less than or equal to
+.Dv PID_MAX ,
+.Fa pid
+refers to a process id.
+If the value is greater than
+.Dv PID_MAX ,
+then
+.Fa pid
+refers to a specific thread id.
+.Pp
+Getting the affinity mask for a process returns the union
+of CPUs available to the individual threads within the
+process.
+Setting the affinity mask for a process sets the affinity
+mask for all threads within the process.
+.Pp
+Affinity masks are represented using the
+.Vt cpuset_t
+type, which encodes a set of CPUs as a bitmask.
+.Pp
+These functions are convenience wrappers around
+.Xr cpuset_getaffinity 3
+and
+.Xr cpuset_setaffinity 3 .
+.Sh RETURN VALUES
+.Rv -std sched_getaffinity sched_setaffinity
+.Sh ERRORS
+See
+.Xr cpuset_getaffinity 2
+and
+.Xr cpuset_setaffinity 2
+for a list of possible error codes.
+.Sh SEE ALSO
+.Xr cpuset 2 ,
+.Xr cpuset_getaffinity 2 ,
+.Xr cpuset_setaffinity 2
+.Sh STANDARDS
+The
+.Fn sched_getaffinity
+and
+.Fn sched_setaffinity
+functions originated in Linux.
+This implementation aims to be source-compatible with the Linux implementation.
+.Sh HISTORY
+The
+.Fn sched_getaffinity
+and
+.Fn sched_setaffinity
+functions were introduced in
+.Fx 13.1 .
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, May 14, 5:42 PM (16 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33050993
Default Alt Text
D51196.id.diff (2 KB)
Attached To
Mode
D51196: Document sched_getaffinity and sched_setaffinity
Attached
Detach File
Event Timeline
Log In to Comment