1 .\" $NetBSD: affinity.3,v 1.3 2008/10/18 03:37:41 rmind Exp $
3 .\" Copyright (c) 2008 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Mindaugas Rasiukevicius <rmind at NetBSD org>.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
34 .Nm pthread_setaffinity_np ,
35 .Nm pthread_getaffinity_np
36 .Nd affinity of threads
43 .Fn pthread_setaffinity_np "pthread_t thread" "size_t size" "cpuset_t *set"
45 .Fn pthread_getaffinity_np "pthread_t thread" "size_t size" "cpuset_t *set"
47 Thread affinity allows to run the thread on specified CPU or CPUs only.
49 .Fn pthread_setaffinity_np
50 function sets the affinity mask
54 At least one valid CPU must be set in the mask.
57 .Fn pthread_getaffinity_np
58 function gets the affinity mask of
65 must be created and initialized using the
70 .Fn pthread_setaffinity_np
72 .Fn pthread_getaffinity_np
73 functions return 0 on success.
74 Otherwise, an error number is returned to indicate the error.
76 An example of code fragment, which sets the affinity for the current
77 thread to the CPU whose ID is 0:
83 cset = cpuset_create();
85 err(EXIT_FAILURE, "cpuset_create");
91 error = pthread_setaffinity_np(pth, cpuset_size(cset), cset);
99 .Fn pthread_setaffinity_np
101 .Fn pthread_getaffinity_np
109 The calling process lacks the appropriate privileges to perform
112 No thread could be found corresponding to the one specified by
116 There is an alternative processor sets interface, see
118 However, thread affinity and processor sets are mutually exclusive,
119 hence mixing of these interfaces is prohibited.
123 .Xr pthread_getschedparam 3 ,
124 .Xr pthread_setschedparam 3 ,