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.\" 252b87addfSDmitry Chagin.Dd January 29, 2023 26777f8cebSXin LI.Dt PTHREAD_ATTR_AFFINITY_NP 3 27777f8cebSXin LI.Os 28777f8cebSXin LI.Sh NAME 29777f8cebSXin LI.Nm pthread_attr_getaffinity_np , 30777f8cebSXin LI.Nm pthread_attr_setaffinity_np 31d49bbd73SChristian Brueffer.Nd manage CPU affinity in thread attribute objects 32777f8cebSXin LI.Sh LIBRARY 33777f8cebSXin LI.Lb libpthread 34777f8cebSXin LI.Sh SYNOPSIS 35777f8cebSXin LI.In pthread_np.h 36777f8cebSXin LI.Ft int 37777f8cebSXin LI.Fn pthread_attr_getaffinity_np "const pthread_attr_t *pattr" "size_t cpusetsize" "cpuset_t *cpusetp" 38777f8cebSXin LI.Ft int 39777f8cebSXin LI.Fn pthread_attr_setaffinity_np "pthread_attr_t *pattr" "size_t cpusetsize" "const cpuset_t *cpusetp" 40777f8cebSXin LI.Sh DESCRIPTION 41d49bbd73SChristian BruefferThe 42777f8cebSXin LI.Fn pthread_attr_getaffinity_np 43777f8cebSXin LIand 44777f8cebSXin LI.Fn pthread_attr_setaffinity_np 45d49bbd73SChristian Bruefferfunctions allow the manipulation of sets of CPUs available to the specified thread attribute object. 46777f8cebSXin LI.Pp 47777f8cebSXin LIMasks of type 48777f8cebSXin LI.Ft cpuset_t 49777f8cebSXin LIare composed using the 50cd088fc4SJoel Dahl.Dv CPU_SET 51777f8cebSXin LImacros. 52f35093f8SDmitry ChaginIf the user-supplied mask is not large enough to fit all of the matching CPUs, 532b87addfSDmitry Chagin.Fn pthread_attr_getaffinity_np 54f35093f8SDmitry Chaginfails with 55f35093f8SDmitry Chagin.Er ERANGE . 56777f8cebSXin LICalls to 572b87addfSDmitry Chagin.Fn pthread_attr_setaffinity_np 58f35093f8SDmitry Chagintolerate masks of any size with no restrictions. 592b87addfSDmitry Chagin.Fn pthread_attr_setaffinity_np 602b87addfSDmitry Chaginuses the meaningful part of the mask, where the upper bound is 61f35093f8SDmitry Chaginthe maximum CPU id present in the system. 62f35093f8SDmitry ChaginIf bits for non-existing CPUs are set, calls to 632b87addfSDmitry Chagin.Fn pthread_attr_setaffinity_np 64*5fee12e1SJens Schweikhardtfail with 65f35093f8SDmitry 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_attr_getaffinity_np 78777f8cebSXin LIretrieves the 79777f8cebSXin LImask from the thread attribute object specified by 80777f8cebSXin LI.Fa pattr , 81777f8cebSXin LIand stores it in the space provided by 82d49bbd73SChristian Brueffer.Fa cpusetp . 83777f8cebSXin LI.Pp 84777f8cebSXin LI.Fn pthread_attr_setaffinity_np 85d49bbd73SChristian Brueffersets the mask for the thread attribute object specified by 86777f8cebSXin LI.Fa pattr 87777f8cebSXin LIto the value in 88d49bbd73SChristian Brueffer.Fa cpusetp . 89777f8cebSXin LI.Sh RETURN VALUES 90777f8cebSXin LIIf successful, the 91777f8cebSXin LI.Fn pthread_attr_getaffinity_np 92777f8cebSXin LIand 93777f8cebSXin LI.Fn pthread_attr_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_attr_getaffinity_np 100777f8cebSXin LIfunctions will fail if: 101777f8cebSXin LI.Bl -tag -width Er 102777f8cebSXin LI.It Bq Er EINVAL 103777f8cebSXin LIThe 104777f8cebSXin LI.Fa pattr 105d49bbd73SChristian Bruefferor the attribute specified by it is 106d49bbd73SChristian Brueffer.Dv NULL . 1071200ef56SDavid Xu.It Bq Er ERANGE 1081200ef56SDavid XuThe 1091200ef56SDavid Xu.Fa cpusetsize 1101200ef56SDavid Xuis too small. 111777f8cebSXin LI.El 112777f8cebSXin LI.Pp 113777f8cebSXin LIThe 114777f8cebSXin LI.Fn pthread_attr_setaffinity_np 115777f8cebSXin LIfunction will fail if: 116777f8cebSXin LI.Bl -tag -width Er 117777f8cebSXin LI.It Bq Er EINVAL 118777f8cebSXin LIThe 119777f8cebSXin LI.Fa pattr 120d49bbd73SChristian Bruefferor the attribute specified by it is 121d49bbd73SChristian Brueffer.Dv NULL . 1221200ef56SDavid Xu.It Bq Er EINVAL 1231200ef56SDavid XuThe 1241200ef56SDavid Xu.Fa cpusetp 1251200ef56SDavid Xuspecified a CPU that was outside the set supported by the kernel. 126777f8cebSXin LI.It Bq Er ENOMEM 127777f8cebSXin LIInsufficient memory exists to store the cpuset mask. 128777f8cebSXin LI.El 129777f8cebSXin LI.Sh SEE ALSO 130777f8cebSXin LI.Xr cpuset 1 , 131777f8cebSXin LI.Xr cpuset 2 , 132777f8cebSXin LI.Xr cpuset_getid 2 , 133777f8cebSXin LI.Xr cpuset_setid 2 , 13428e33578SEric van Gyzen.Xr pthread_getaffinity_np 3 , 135df7d7638SFelix Johnson.Xr pthread_np 3 , 13628e33578SEric van Gyzen.Xr pthread_setaffinity_np 3 137777f8cebSXin LI.Sh STANDARDS 138777f8cebSXin LIThe 139777f8cebSXin LI.Nm pthread_attr_getaffinity_np 140777f8cebSXin LIand 141777f8cebSXin LI.Nm pthread_attr_setaffinity_np 142777f8cebSXin LIfunctions are non-standard 143777f8cebSXin LI.Fx 144777f8cebSXin LIextensions and may be not available on other operating systems. 145777f8cebSXin LI.Sh HISTORY 146777f8cebSXin LIThe 147777f8cebSXin LI.Nm pthread_attr_getaffinity_np 148777f8cebSXin LIand 149777f8cebSXin LI.Nm pthread_attr_setaffinity_np 150777f8cebSXin LIfunctions first appeared in 151777f8cebSXin LI.Fx 7.2 . 152777f8cebSXin LI.Sh AUTHORS 153777f8cebSXin LI.An -nosplit 154777f8cebSXin LIThe 155777f8cebSXin LI.Nm pthread_attr_getaffinity_np 156777f8cebSXin LIand 157777f8cebSXin LI.Nm pthread_attr_setaffinity_np 158777f8cebSXin LIfunctions were written by 159a63d6c94SBaptiste Daroussin.An David Xu Aq Mt davidxu@FreeBSD.org , 160777f8cebSXin LIand this manpage was written by 161a63d6c94SBaptiste Daroussin.An Xin LI Aq Mt delphij@FreeBSD.org . 162