]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/pthread_attr_setaffinity_np.3
7f3e02a0dd7164b7fff97c74e52071bfb0f08e7e
[thirdparty/man-pages.git] / man3 / pthread_attr_setaffinity_np.3
1 .\" Copyright (c) 2008 Linux Foundation, written by Michael Kerrisk
2 .\" <mtk.manpages@gmail.com>
3 .\"
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
5 .\"
6 .TH PTHREAD_ATTR_SETAFFINITY_NP 3 2021-03-22 "Linux" "Linux Programmer's Manual"
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 .PP
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 .PP
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 .IR attr
42 in the buffer pointed to by
43 .IR cpuset .
44 .PP
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 .PP
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 .BR 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 .BR 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 .IR 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 VERSIONS
88 These functions are provided by glibc since version 2.3.4.
89 .SH ATTRIBUTES
90 For an explanation of the terms used in this section, see
91 .BR attributes (7).
92 .ad l
93 .nh
94 .TS
95 allbox;
96 lbx lb lb
97 l l l.
98 Interface Attribute Value
99 T{
100 .BR pthread_attr_setaffinity_np (),
101 .BR pthread_attr_getaffinity_np ()
102 T} Thread safety MT-Safe
103 .TE
104 .hy
105 .ad
106 .sp 1
107 .SH CONFORMING TO
108 These functions are nonstandard GNU extensions;
109 hence the suffix "_np" (nonportable) in the names.
110 .SH NOTES
111 In glibc 2.3.3 only,
112 versions of these functions were provided that did not have a
113 .I cpusetsize
114 argument.
115 Instead the CPU set size given to the underlying system calls was always
116 .IR sizeof(cpu_set_t) .
117 .SH SEE ALSO
118 .BR sched_setaffinity (2),
119 .BR pthread_attr_init (3),
120 .BR pthread_setaffinity_np (3),
121 .BR cpuset (7),
122 .BR pthreads (7)