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.Dv CPU_SET 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 97functions will fail if: 98.Bl -tag -width Er 99.It Bq Er EINVAL 100The 101.Fa pattr 102or the attribute specified by it is 103.Dv NULL . 104.It Bq Er ERANGE 105The 106.Fa cpusetsize 107is too small. 108.El 109.Pp 110The 111.Fn pthread_attr_setaffinity_np 112function will fail if: 113.Bl -tag -width Er 114.It Bq Er EINVAL 115The 116.Fa pattr 117or the attribute specified by it is 118.Dv NULL . 119.It Bq Er EINVAL 120The 121.Fa cpusetp 122specified a CPU that was outside the set supported by the kernel. 123.It Bq Er ERANGE 124The 125.Fa cpusetsize 126is too small. 127.It Bq Er ENOMEM 128Insufficient memory exists to store the cpuset mask. 129.El 130.Sh SEE ALSO 131.Xr cpuset 1 , 132.Xr cpuset 2 , 133.Xr cpuset_getid 2 , 134.Xr cpuset_setid 2 , 135.Xr pthread_get_affinity_np 3 , 136.Xr pthread_set_affinity_np 3 137.Sh STANDARDS 138The 139.Nm pthread_attr_getaffinity_np 140and 141.Nm pthread_attr_setaffinity_np 142functions are non-standard 143.Fx 144extensions and may be not available on other operating systems. 145.Sh HISTORY 146The 147.Nm pthread_attr_getaffinity_np 148and 149.Nm pthread_attr_setaffinity_np 150functions first appeared in 151.Fx 7.2 . 152.Sh AUTHORS 153.An -nosplit 154The 155.Nm pthread_attr_getaffinity_np 156and 157.Nm pthread_attr_setaffinity_np 158functions were written by 159.An David Xu Aq Mt davidxu@FreeBSD.org , 160and this manpage was written by 161.An Xin LI Aq Mt delphij@FreeBSD.org . 162