1.\"-
2.\" Copyright (c) 2010 Xin LI <delphij@FreeBSD.org>
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\"
14.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24.\" SUCH DAMAGE.
25.\"
26.\" $FreeBSD$
27.\"
28.Dd January 8, 2010
29.Dt PTHREAD_ATTR_AFFINITY_NP 3
30.Os
31.Sh NAME
32.Nm pthread_attr_getaffinity_np ,
33.Nm pthread_attr_setaffinity_np
34.Nd manage CPU affinity in thread attribute objects
35.Sh LIBRARY
36.Lb libpthread
37.Sh SYNOPSIS
38.In pthread_np.h
39.Ft int
40.Fn pthread_attr_getaffinity_np "const pthread_attr_t *pattr" "size_t cpusetsize" "cpuset_t *cpusetp"
41.Ft int
42.Fn pthread_attr_setaffinity_np "pthread_attr_t *pattr" "size_t cpusetsize" "const cpuset_t *cpusetp"
43.Sh DESCRIPTION
44The
45.Fn pthread_attr_getaffinity_np
46and
47.Fn pthread_attr_setaffinity_np
48functions allow the manipulation of sets of CPUs available to the specified thread attribute object.
49.Pp
50Masks of type
51.Ft cpuset_t
52are composed using the
53.Xr CPU_SET 3
54macros.
55The kernel tolerates large sets as long as all CPUs specified
56in the set exist.
57Sets smaller than the kernel uses generate an error on calls to
58.Fn pthread_attr_getaffinity_np
59even if the result set would fit within the user supplied set.
60Calls to
61.Fn pthread_attr_setaffinity_np
62tolerate small sets with no restrictions.
63.Pp
64The supplied mask should have a size of
65.Fa cpusetsize
66bytes.
67This size is usually provided by calling
68.Li sizeof(cpuset_t)
69which is ultimately determined by the value of
70.Dv CPU_SETSIZE
71as defined in
72.In sys/cpuset.h .
73.Pp
74.Fn pthread_attr_getaffinity_np
75retrieves the
76mask from the thread attribute object specified by
77.Fa pattr ,
78and stores it in the space provided by
79.Fa cpusetp .
80.Pp
81.Fn pthread_attr_setaffinity_np
82sets the mask for the thread attribute object specified by
83.Fa pattr
84to the value in
85.Fa cpusetp .
86.Sh RETURN VALUES
87If successful, the
88.Fn pthread_attr_getaffinity_np
89and
90.Fn pthread_attr_setaffinity_np
91functions will return zero.
92Otherwise an error number will be returned
93to indicate the error.
94.Sh ERRORS
95The
96.Fn pthread_attr_getaffinity_np
97and
98.Fn pthread_attr_setaffinity_np
99functions will fail if:
100.Bl -tag -width Er
101.It Bq Er EINVAL
102The
103.Fa pattr
104or the attribute specified by it is
105.Dv NULL .
106.El
107.Pp
108The
109.Fn pthread_attr_setaffinity_np
110function will fail if:
111.Bl -tag -width Er
112.It Bq Er EINVAL
113The
114.Fa pattr
115or the attribute specified by it is
116.Dv NULL .
117.It Bq Er ENOMEM
118Insufficient memory exists to store the cpuset mask.
119.El
120.Sh SEE ALSO
121.Xr cpuset 1 ,
122.Xr cpuset 2 ,
123.Xr cpuset_getid 2 ,
124.Xr cpuset_setid 2 ,
125.Xr CPU_SET 3 ,
126.Xr pthread_get_affinity_np 3 ,
127.Xr pthread_set_affinity_np 3
128.Sh STANDARDS
129The
130.Nm pthread_attr_getaffinity_np
131and
132.Nm pthread_attr_setaffinity_np
133functions are non-standard
134.Fx
135extensions and may be not available on other operating systems.
136.Sh HISTORY
137The
138.Nm pthread_attr_getaffinity_np
139and
140.Nm pthread_attr_setaffinity_np
141functions first appeared in
142.Fx 7.2 .
143.Sh AUTHORS
144.An -nosplit
145The
146.Nm pthread_attr_getaffinity_np
147and
148.Nm pthread_attr_setaffinity_np
149functions were written by
150.An David Xu Aq davidxu@FreeBSD.org ,
151and this manpage was written by
152.An Xin LI Aq delphij@FreeBSD.org .
153