| 1 |
'\" t |
| 2 |
.\" Copyright, the authors of the Linux man-pages project |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 5 |
.\" |
| 6 |
.TH pthread_attr_setaffinity_np 3 2025-05-17 "Linux man-pages 6.18" |
| 7 |
.SH NAME |
| 8 |
pthread_attr_setaffinity_np, pthread_attr_getaffinity_np \- set/get |
| 9 |
CPU affinity attribute in thread attributes object |
| 10 |
.SH LIBRARY |
| 11 |
POSIX threads library |
| 12 |
.RI ( libpthread ,\~ \-lpthread ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */" |
| 16 |
.B #include <pthread.h> |
| 17 |
.P |
| 18 |
.BI "int pthread_attr_setaffinity_np(pthread_attr_t *" attr , |
| 19 |
.BI " size_t " cpusetsize ", const cpu_set_t *" cpuset ); |
| 20 |
.BI "int pthread_attr_getaffinity_np(const pthread_attr_t *" attr , |
| 21 |
.BI " size_t " cpusetsize ", cpu_set_t *" cpuset ); |
| 22 |
.fi |
| 23 |
.SH DESCRIPTION |
| 24 |
The |
| 25 |
.BR pthread_attr_setaffinity_np () |
| 26 |
function |
| 27 |
sets the CPU affinity mask attribute of the |
| 28 |
thread attributes object referred to by |
| 29 |
.I attr |
| 30 |
to the value specified in |
| 31 |
.IR cpuset . |
| 32 |
This attribute determines the CPU affinity mask |
| 33 |
of a thread created using the thread attributes object |
| 34 |
.IR attr . |
| 35 |
.P |
| 36 |
The |
| 37 |
.BR pthread_attr_getaffinity_np () |
| 38 |
function |
| 39 |
returns the CPU affinity mask attribute of the thread attributes object |
| 40 |
referred to by |
| 41 |
.I attr |
| 42 |
in the buffer pointed to by |
| 43 |
.IR cpuset . |
| 44 |
.P |
| 45 |
The argument |
| 46 |
.I cpusetsize |
| 47 |
is the length (in bytes) of the buffer pointed to by |
| 48 |
.IR cpuset . |
| 49 |
Typically, this argument would be specified as |
| 50 |
.IR sizeof(cpu_set_t) . |
| 51 |
.P |
| 52 |
For more details on CPU affinity masks, see |
| 53 |
.BR sched_setaffinity (2). |
| 54 |
For a description of a set of macros |
| 55 |
that can be used to manipulate and inspect CPU sets, see |
| 56 |
.BR CPU_SET (3). |
| 57 |
.SH RETURN VALUE |
| 58 |
On success, these functions return 0; |
| 59 |
on error, they return a nonzero error number. |
| 60 |
.SH ERRORS |
| 61 |
.TP |
| 62 |
.B EINVAL |
| 63 |
.RB ( pthread_attr_setaffinity_np ()) |
| 64 |
.I cpuset |
| 65 |
specified a CPU that was outside the set supported by the kernel. |
| 66 |
(The kernel configuration option |
| 67 |
.B CONFIG_NR_CPUS |
| 68 |
defines the range of the set supported by the kernel data type |
| 69 |
.\" cpumask_t |
| 70 |
used to represent CPU sets.) |
| 71 |
.\" The raw sched_getaffinity() system call returns the size (in bytes) |
| 72 |
.\" of the cpumask_t type. |
| 73 |
.TP |
| 74 |
.B EINVAL |
| 75 |
.RB ( pthread_attr_getaffinity_np ()) |
| 76 |
A CPU in the affinity mask of the thread attributes object referred to by |
| 77 |
.I attr |
| 78 |
lies outside the range specified by |
| 79 |
.I cpusetsize |
| 80 |
(i.e., |
| 81 |
.IR cpuset / cpusetsize |
| 82 |
is too small). |
| 83 |
.TP |
| 84 |
.B ENOMEM |
| 85 |
.RB ( pthread_attr_setaffinity_np ()) |
| 86 |
Could not allocate memory. |
| 87 |
.SH ATTRIBUTES |
| 88 |
For an explanation of the terms used in this section, see |
| 89 |
.BR attributes (7). |
| 90 |
.TS |
| 91 |
allbox; |
| 92 |
lbx lb lb |
| 93 |
l l l. |
| 94 |
Interface Attribute Value |
| 95 |
T{ |
| 96 |
.na |
| 97 |
.nh |
| 98 |
.BR pthread_attr_setaffinity_np (), |
| 99 |
.BR pthread_attr_getaffinity_np () |
| 100 |
T} Thread safety MT-Safe |
| 101 |
.TE |
| 102 |
.SH STANDARDS |
| 103 |
GNU; |
| 104 |
hence the suffix "_np" (nonportable) in the names. |
| 105 |
.SH HISTORY |
| 106 |
glibc 2.3.4. |
| 107 |
.SH NOTES |
| 108 |
In glibc 2.3.3 only, |
| 109 |
versions of these functions were provided that did not have a |
| 110 |
.I cpusetsize |
| 111 |
argument. |
| 112 |
Instead the CPU set size given to the underlying system calls was always |
| 113 |
.IR sizeof(cpu_set_t) . |
| 114 |
.SH SEE ALSO |
| 115 |
.BR sched_setaffinity (2), |
| 116 |
.BR pthread_attr_init (3), |
| 117 |
.BR pthread_setaffinity_np (3), |
| 118 |
.BR cpuset (7), |
| 119 |
.BR pthreads (7) |