xref: /freebsd/share/man/man3/pthread_attr_affinity_np.3 (revision 5fee12e18967d8896a68bf9c5f6d92e7d5ae6bf9)
1777f8cebSXin LI.\"-
2777f8cebSXin LI.\" Copyright (c) 2010 Xin LI <delphij@FreeBSD.org>
3777f8cebSXin LI.\"
4777f8cebSXin LI.\" Redistribution and use in source and binary forms, with or without
5777f8cebSXin LI.\" modification, are permitted provided that the following conditions
6777f8cebSXin LI.\" are met:
7777f8cebSXin LI.\" 1. Redistributions of source code must retain the above copyright
8777f8cebSXin LI.\"    notice, this list of conditions and the following disclaimer.
9777f8cebSXin LI.\" 2. Redistributions in binary form must reproduce the above copyright
10777f8cebSXin LI.\"    notice, this list of conditions and the following disclaimer in the
11777f8cebSXin LI.\"    documentation and/or other materials provided with the distribution.
12777f8cebSXin LI.\"
13777f8cebSXin LI.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14777f8cebSXin LI.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15777f8cebSXin LI.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16777f8cebSXin LI.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17777f8cebSXin LI.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18777f8cebSXin LI.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19777f8cebSXin LI.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20777f8cebSXin LI.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21777f8cebSXin LI.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22777f8cebSXin LI.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23777f8cebSXin LI.\" SUCH DAMAGE.
24777f8cebSXin LI.\"
25777f8cebSXin LI.\" $FreeBSD$
26777f8cebSXin LI.\"
272b87addfSDmitry Chagin.Dd January 29, 2023
28777f8cebSXin LI.Dt PTHREAD_ATTR_AFFINITY_NP 3
29777f8cebSXin LI.Os
30777f8cebSXin LI.Sh NAME
31777f8cebSXin LI.Nm pthread_attr_getaffinity_np ,
32777f8cebSXin LI.Nm pthread_attr_setaffinity_np
33d49bbd73SChristian Brueffer.Nd manage CPU affinity in thread attribute objects
34777f8cebSXin LI.Sh LIBRARY
35777f8cebSXin LI.Lb libpthread
36777f8cebSXin LI.Sh SYNOPSIS
37777f8cebSXin LI.In pthread_np.h
38777f8cebSXin LI.Ft int
39777f8cebSXin LI.Fn pthread_attr_getaffinity_np "const pthread_attr_t *pattr" "size_t cpusetsize" "cpuset_t *cpusetp"
40777f8cebSXin LI.Ft int
41777f8cebSXin LI.Fn pthread_attr_setaffinity_np "pthread_attr_t *pattr" "size_t cpusetsize" "const cpuset_t *cpusetp"
42777f8cebSXin LI.Sh DESCRIPTION
43d49bbd73SChristian BruefferThe
44777f8cebSXin LI.Fn pthread_attr_getaffinity_np
45777f8cebSXin LIand
46777f8cebSXin LI.Fn pthread_attr_setaffinity_np
47d49bbd73SChristian Bruefferfunctions allow the manipulation of sets of CPUs available to the specified thread attribute object.
48777f8cebSXin LI.Pp
49777f8cebSXin LIMasks of type
50777f8cebSXin LI.Ft cpuset_t
51777f8cebSXin LIare composed using the
52cd088fc4SJoel Dahl.Dv CPU_SET
53777f8cebSXin LImacros.
54f35093f8SDmitry ChaginIf the user-supplied mask is not large enough to fit all of the matching CPUs,
552b87addfSDmitry Chagin.Fn pthread_attr_getaffinity_np
56f35093f8SDmitry Chaginfails with
57f35093f8SDmitry Chagin.Er ERANGE .
58777f8cebSXin LICalls to
592b87addfSDmitry Chagin.Fn pthread_attr_setaffinity_np
60f35093f8SDmitry Chagintolerate masks of any size with no restrictions.
612b87addfSDmitry Chagin.Fn pthread_attr_setaffinity_np
622b87addfSDmitry Chaginuses the meaningful part of the mask, where the upper bound is
63f35093f8SDmitry Chaginthe maximum CPU id present in the system.
64f35093f8SDmitry ChaginIf bits for non-existing CPUs are set, calls to
652b87addfSDmitry Chagin.Fn pthread_attr_setaffinity_np
66*5fee12e1SJens Schweikhardtfail with
67f35093f8SDmitry Chagin.Er EINVAL .
68777f8cebSXin LI.Pp
69777f8cebSXin LIThe supplied mask should have a size of
70777f8cebSXin LI.Fa cpusetsize
71777f8cebSXin LIbytes.
72777f8cebSXin LIThis size is usually provided by calling
73777f8cebSXin LI.Li sizeof(cpuset_t)
74777f8cebSXin LIwhich is ultimately determined by the value of
75777f8cebSXin LI.Dv CPU_SETSIZE
76777f8cebSXin LIas defined in
77777f8cebSXin LI.In sys/cpuset.h .
78777f8cebSXin LI.Pp
79777f8cebSXin LI.Fn pthread_attr_getaffinity_np
80777f8cebSXin LIretrieves the
81777f8cebSXin LImask from the thread attribute object specified by
82777f8cebSXin LI.Fa pattr ,
83777f8cebSXin LIand stores it in the space provided by
84d49bbd73SChristian Brueffer.Fa cpusetp .
85777f8cebSXin LI.Pp
86777f8cebSXin LI.Fn pthread_attr_setaffinity_np
87d49bbd73SChristian Brueffersets the mask for the thread attribute object specified by
88777f8cebSXin LI.Fa pattr
89777f8cebSXin LIto the value in
90d49bbd73SChristian Brueffer.Fa cpusetp .
91777f8cebSXin LI.Sh RETURN VALUES
92777f8cebSXin LIIf successful, the
93777f8cebSXin LI.Fn pthread_attr_getaffinity_np
94777f8cebSXin LIand
95777f8cebSXin LI.Fn pthread_attr_setaffinity_np
96777f8cebSXin LIfunctions will return zero.
97777f8cebSXin LIOtherwise an error number will be returned
98777f8cebSXin LIto indicate the error.
99777f8cebSXin LI.Sh ERRORS
100777f8cebSXin LIThe
101777f8cebSXin LI.Fn pthread_attr_getaffinity_np
102777f8cebSXin LIfunctions will fail if:
103777f8cebSXin LI.Bl -tag -width Er
104777f8cebSXin LI.It Bq Er EINVAL
105777f8cebSXin LIThe
106777f8cebSXin LI.Fa pattr
107d49bbd73SChristian Bruefferor the attribute specified by it is
108d49bbd73SChristian Brueffer.Dv NULL .
1091200ef56SDavid Xu.It Bq Er ERANGE
1101200ef56SDavid XuThe
1111200ef56SDavid Xu.Fa cpusetsize
1121200ef56SDavid Xuis too small.
113777f8cebSXin LI.El
114777f8cebSXin LI.Pp
115777f8cebSXin LIThe
116777f8cebSXin LI.Fn pthread_attr_setaffinity_np
117777f8cebSXin LIfunction will fail if:
118777f8cebSXin LI.Bl -tag -width Er
119777f8cebSXin LI.It Bq Er EINVAL
120777f8cebSXin LIThe
121777f8cebSXin LI.Fa pattr
122d49bbd73SChristian Bruefferor the attribute specified by it is
123d49bbd73SChristian Brueffer.Dv NULL .
1241200ef56SDavid Xu.It Bq Er EINVAL
1251200ef56SDavid XuThe
1261200ef56SDavid Xu.Fa cpusetp
1271200ef56SDavid Xuspecified a CPU that was outside the set supported by the kernel.
128777f8cebSXin LI.It Bq Er ENOMEM
129777f8cebSXin LIInsufficient memory exists to store the cpuset mask.
130777f8cebSXin LI.El
131777f8cebSXin LI.Sh SEE ALSO
132777f8cebSXin LI.Xr cpuset 1 ,
133777f8cebSXin LI.Xr cpuset 2 ,
134777f8cebSXin LI.Xr cpuset_getid 2 ,
135777f8cebSXin LI.Xr cpuset_setid 2 ,
13628e33578SEric van Gyzen.Xr pthread_getaffinity_np 3 ,
137df7d7638SFelix Johnson.Xr pthread_np 3 ,
13828e33578SEric van Gyzen.Xr pthread_setaffinity_np 3
139777f8cebSXin LI.Sh STANDARDS
140777f8cebSXin LIThe
141777f8cebSXin LI.Nm pthread_attr_getaffinity_np
142777f8cebSXin LIand
143777f8cebSXin LI.Nm pthread_attr_setaffinity_np
144777f8cebSXin LIfunctions are non-standard
145777f8cebSXin LI.Fx
146777f8cebSXin LIextensions and may be not available on other operating systems.
147777f8cebSXin LI.Sh HISTORY
148777f8cebSXin LIThe
149777f8cebSXin LI.Nm pthread_attr_getaffinity_np
150777f8cebSXin LIand
151777f8cebSXin LI.Nm pthread_attr_setaffinity_np
152777f8cebSXin LIfunctions first appeared in
153777f8cebSXin LI.Fx 7.2 .
154777f8cebSXin LI.Sh AUTHORS
155777f8cebSXin LI.An -nosplit
156777f8cebSXin LIThe
157777f8cebSXin LI.Nm pthread_attr_getaffinity_np
158777f8cebSXin LIand
159777f8cebSXin LI.Nm pthread_attr_setaffinity_np
160777f8cebSXin LIfunctions were written by
161a63d6c94SBaptiste Daroussin.An David Xu Aq Mt davidxu@FreeBSD.org ,
162777f8cebSXin LIand this manpage was written by
163a63d6c94SBaptiste Daroussin.An Xin LI Aq Mt delphij@FreeBSD.org .
164