xref: /freebsd/share/man/man3/pthread_affinity_np.3 (revision 2c2a04984c95d78d9bb9498963fb71dc43cd5764)
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.\"
2762801712SDmitry Chagin.Dd January 29, 2023
28777f8cebSXin LI.Dt PTHREAD_AFFINITY_NP 3
29777f8cebSXin LI.Os
30777f8cebSXin LI.Sh NAME
31777f8cebSXin LI.Nm pthread_getaffinity_np ,
32777f8cebSXin LI.Nm pthread_setaffinity_np
33777f8cebSXin LI.Nd manage CPU affinity
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_getaffinity_np "pthread_t td" "size_t cpusetsize" "cpuset_t *cpusetp"
40777f8cebSXin LI.Ft int
41777f8cebSXin LI.Fn pthread_setaffinity_np "pthread_t td" "size_t cpusetsize" "const cpuset_t *cpusetp"
42777f8cebSXin LI.Sh DESCRIPTION
43777f8cebSXin LI.Fn pthread_getaffinity_np
44777f8cebSXin LIand
45777f8cebSXin LI.Fn pthread_setaffinity_np
46d49bbd73SChristian Bruefferallow the manipulation of sets of CPUs available to the specified thread.
47777f8cebSXin LI.Pp
48777f8cebSXin LIMasks of type
49777f8cebSXin LI.Ft cpuset_t
50777f8cebSXin LIare composed using the
51cd088fc4SJoel Dahl.Dv CPU_SET
52777f8cebSXin LImacros.
5362801712SDmitry ChaginIf the user-supplied mask is not large enough to fit all of the matching CPUs,
54777f8cebSXin LI.Fn pthread_getaffinity_np
5562801712SDmitry Chaginfails with
5662801712SDmitry Chagin.Er ERANGE .
57777f8cebSXin LICalls to
58777f8cebSXin LI.Fn pthread_setaffinity_np
5962801712SDmitry Chagintolerate masks of any size with no restrictions.
6062801712SDmitry ChaginThe kernel uses the meaningful part of the mask, where the upper bound is
6162801712SDmitry Chaginthe maximum CPU id present in the system.
6262801712SDmitry ChaginIf bits for non-existing CPUs are set, calls to
6362801712SDmitry Chagin.Fn pthread_setaffinity_np
64*2c2a0498SJens Schweikhardtfail with
6562801712SDmitry Chagin.Er EINVAL .
66777f8cebSXin LI.Pp
67777f8cebSXin LIThe supplied mask should have a size of
68777f8cebSXin LI.Fa cpusetsize
69777f8cebSXin LIbytes.
70777f8cebSXin LIThis size is usually provided by calling
71777f8cebSXin LI.Li sizeof(cpuset_t)
72777f8cebSXin LIwhich is ultimately determined by the value of
73777f8cebSXin LI.Dv CPU_SETSIZE
74777f8cebSXin LIas defined in
75777f8cebSXin LI.In sys/cpuset.h .
76777f8cebSXin LI.Pp
77777f8cebSXin LI.Fn pthread_getaffinity_np
78777f8cebSXin LIretrieves the
79777f8cebSXin LImask from the thread specified by
80777f8cebSXin LI.Fa td ,
81777f8cebSXin LIand stores it in the space provided by
82d49bbd73SChristian Brueffer.Fa cpusetp .
83777f8cebSXin LI.Pp
84777f8cebSXin LI.Fn pthread_setaffinity_np
85777f8cebSXin LIattempts to set the mask for the thread specified by
86777f8cebSXin LI.Fa td
87777f8cebSXin LIto the value in
88d49bbd73SChristian Brueffer.Fa cpusetp .
89777f8cebSXin LI.Sh RETURN VALUES
90777f8cebSXin LIIf successful, the
91777f8cebSXin LI.Fn pthread_getaffinity_np
92777f8cebSXin LIand
93777f8cebSXin LI.Fn pthread_setaffinity_np
94777f8cebSXin LIfunctions will return zero.
95777f8cebSXin LIOtherwise an error number will be returned
96777f8cebSXin LIto indicate the error.
97777f8cebSXin LI.Sh ERRORS
98777f8cebSXin LIThe
99777f8cebSXin LI.Fn pthread_getaffinity_np
100777f8cebSXin LIand
101777f8cebSXin LI.Fn pthread_setaffinity_np
102777f8cebSXin LIfunctions may fail if:
103777f8cebSXin LI.Bl -tag -width Er
10462801712SDmitry Chagin.It Bq Er EINVAL
10562801712SDmitry ChaginThe
10662801712SDmitry Chagin.Fa cpusetp
10762801712SDmitry Chaginargument specified when calling
10862801712SDmitry Chagin.Fn pthread_setaffinity_np
10962801712SDmitry Chaginwas not a valid value.
110777f8cebSXin LI.It Bq Er EDEADLK
111777f8cebSXin LIThe
112777f8cebSXin LI.Fn pthread_setaffinity_np
113777f8cebSXin LIcall would leave a thread without a valid CPU to run on because the set
114777f8cebSXin LIdoes not overlap with the thread's anonymous mask.
115777f8cebSXin LI.It Bq Er EFAULT
116777f8cebSXin LIThe
117d49bbd73SChristian Brueffer.Fa cpusetp
118777f8cebSXin LIpointer passed was invalid.
119777f8cebSXin LI.It Bq Er ESRCH
120777f8cebSXin LIThe thread specified by the
121777f8cebSXin LI.Fa td
122777f8cebSXin LIargument could not be found.
123777f8cebSXin LI.It Bq Er ERANGE
124777f8cebSXin LIThe
125777f8cebSXin LI.Fa cpusetsize
12662801712SDmitry Chaginwas smaller than needed to fit all of the matching CPUs.
127777f8cebSXin LI.It Bq Er EPERM
128777f8cebSXin LIThe calling thread did not have the credentials required to complete the
129777f8cebSXin LIoperation.
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 ,
136777f8cebSXin LI.Xr pthread 3 ,
13767b9e255SXin LI.Xr pthread_attr_getaffinity_np 3 ,
138df7d7638SFelix Johnson.Xr pthread_attr_setaffinity_np 3 ,
139df7d7638SFelix Johnson.Xr pthread_np 3
140777f8cebSXin LI.Sh STANDARDS
141777f8cebSXin LIThe
142777f8cebSXin LI.Nm pthread_getaffinity_np
143777f8cebSXin LIand
144777f8cebSXin LI.Nm pthread_setaffinity_np
145777f8cebSXin LIfunctions are non-standard
146777f8cebSXin LI.Fx
147777f8cebSXin LIextensions and may be not available on other operating systems.
148777f8cebSXin LI.Sh HISTORY
149777f8cebSXin LIThe
150777f8cebSXin LI.Nm pthread_getaffinity_np
151777f8cebSXin LIand
152777f8cebSXin LI.Nm pthread_setaffinity_np
153777f8cebSXin LIfunction first appeared in
154777f8cebSXin LI.Fx 7.2 .
155777f8cebSXin LI.Sh AUTHORS
156777f8cebSXin LI.An -nosplit
157777f8cebSXin LIThe
158777f8cebSXin LI.Nm pthread_getaffinity_np
159777f8cebSXin LIand
160777f8cebSXin LI.Nm pthread_setaffinity_np
161777f8cebSXin LIfunctions were written by
162a63d6c94SBaptiste Daroussin.An David Xu Aq Mt davidxu@FreeBSD.org ,
163777f8cebSXin LIand this manpage was written by
164a63d6c94SBaptiste Daroussin.An Xin LI Aq Mt delphij@FreeBSD.org .
165