xref: /dflybsd-src/lib/libc/sys/lwp_setaffinity.2 (revision a0c14455e541f70c119a228586e2fcb579ce4f19)
18f95cc34SSepherosa Ziehau.\" Copyright (c) 2017 The DragonFly Project.  All rights reserved.
28f95cc34SSepherosa Ziehau.\"
38f95cc34SSepherosa Ziehau.\" This code is derived from software contributed to The DragonFly Project
48f95cc34SSepherosa Ziehau.\" by Sepherosa Ziehau <sepherosa@gmail.com>.
58f95cc34SSepherosa Ziehau.\"
68f95cc34SSepherosa Ziehau.\" Redistribution and use in source and binary forms, with or without
78f95cc34SSepherosa Ziehau.\" modification, are permitted provided that the following conditions
88f95cc34SSepherosa Ziehau.\" are met:
98f95cc34SSepherosa Ziehau.\"
108f95cc34SSepherosa Ziehau.\" 1. Redistributions of source code must retain the above copyright
118f95cc34SSepherosa Ziehau.\"    notice, this list of conditions and the following disclaimer.
128f95cc34SSepherosa Ziehau.\" 2. Redistributions in binary form must reproduce the above copyright
138f95cc34SSepherosa Ziehau.\"    notice, this list of conditions and the following disclaimer in
148f95cc34SSepherosa Ziehau.\"    the documentation and/or other materials provided with the
158f95cc34SSepherosa Ziehau.\"    distribution.
168f95cc34SSepherosa Ziehau.\" 3. Neither the name of The DragonFly Project nor the names of its
178f95cc34SSepherosa Ziehau.\"    contributors may be used to endorse or promote products derived
188f95cc34SSepherosa Ziehau.\"    from this software without specific, prior written permission.
198f95cc34SSepherosa Ziehau.\"
208f95cc34SSepherosa Ziehau.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
218f95cc34SSepherosa Ziehau.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
228f95cc34SSepherosa Ziehau.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
238f95cc34SSepherosa Ziehau.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
248f95cc34SSepherosa Ziehau.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
258f95cc34SSepherosa Ziehau.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
268f95cc34SSepherosa Ziehau.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
278f95cc34SSepherosa Ziehau.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
288f95cc34SSepherosa Ziehau.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
298f95cc34SSepherosa Ziehau.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
308f95cc34SSepherosa Ziehau.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
318f95cc34SSepherosa Ziehau.\" SUCH DAMAGE.
328f95cc34SSepherosa Ziehau.\"
33907281d1SSepherosa Ziehau.Dd January 14, 2017
348f95cc34SSepherosa Ziehau.Dt LWP_SETAFFINITY 2
358f95cc34SSepherosa Ziehau.Os
368f95cc34SSepherosa Ziehau.Sh NAME
378f95cc34SSepherosa Ziehau.Nm lwp_setaffinity,
388f95cc34SSepherosa Ziehau.Nm lwp_getaffinity
398f95cc34SSepherosa Ziehau.Nd set and get a LWP's CPU affinity mask
408f95cc34SSepherosa Ziehau.Sh LIBRARY
418f95cc34SSepherosa Ziehau.Lb libc
428f95cc34SSepherosa Ziehau.Sh SYNOPSIS
438f95cc34SSepherosa Ziehau.In sys/types.h
448f95cc34SSepherosa Ziehau.In sys/usched.h
458f95cc34SSepherosa Ziehau.Ft int
468f95cc34SSepherosa Ziehau.Fn lwp_setaffinity "pid_t pid" "lwpid_t tid" "const cpumask_t *mask"
478f95cc34SSepherosa Ziehau.Ft int
488f95cc34SSepherosa Ziehau.Fn lwp_getaffinity "pid_t pid" "lwpid_t tid" "cpumask_t *mask"
498f95cc34SSepherosa Ziehau.Sh DESCRIPTION
508f95cc34SSepherosa ZiehauThe
518f95cc34SSepherosa Ziehau.Fn lwp_setaffinity
528f95cc34SSepherosa Ziehausystem call sets the CPU affinity mask of the LWP,
538f95cc34SSepherosa Ziehauwhich is identified by the
548f95cc34SSepherosa Ziehau.Fa pid
558f95cc34SSepherosa Ziehauand the
568f95cc34SSepherosa Ziehau.Fa tid ,
578f95cc34SSepherosa Ziehauto the value specified by the
588f95cc34SSepherosa Ziehau.Fa mask .
598f95cc34SSepherosa ZiehauIf the
608f95cc34SSepherosa Ziehau.Fa pid
618f95cc34SSepherosa Ziehauis zero,
62907281d1SSepherosa Ziehauthen the pid of the calling process is used.
638f95cc34SSepherosa ZiehauIf the
648f95cc34SSepherosa Ziehau.Fa tid
658f95cc34SSepherosa Ziehauis less than zero,
66907281d1SSepherosa Ziehauthen all LWPs of the process identified by the
67907281d1SSepherosa Ziehau.Fa pid
68907281d1SSepherosa Ziehauare affected.
698f95cc34SSepherosa ZiehauIf the LWP specified by the
708f95cc34SSepherosa Ziehau.Fa pid
718f95cc34SSepherosa Ziehauand the
728f95cc34SSepherosa Ziehau.Fa tid
73907281d1SSepherosa Ziehauis the current LWP it will be migrated immediately,
74*a0c14455SSepherosa Ziehauif necessary, otherwise it will be migrated by the scheduler later.
758f95cc34SSepherosa Ziehau.Pp
768f95cc34SSepherosa ZiehauA process created by
778f95cc34SSepherosa Ziehau.Xr fork 2 ,
788f95cc34SSepherosa Ziehau.Xr vfork 2 ,
798f95cc34SSepherosa Ziehauand
808f95cc34SSepherosa Ziehau.Xr rfork 2
818f95cc34SSepherosa Ziehauinherits the calling LWP's CPU affinity mask.
828f95cc34SSepherosa ZiehauSame applies to the LWPs created by
838f95cc34SSepherosa Ziehau.Xr lwp_create 2 ,
848f95cc34SSepherosa Ziehauand the threads created by
858f95cc34SSepherosa Ziehau.Xr pthread_create 3 .
868f95cc34SSepherosa Ziehau.Pp
878f95cc34SSepherosa Ziehau.Fn lwp_getaffinity
888f95cc34SSepherosa Ziehauwrites the affinity mask of the LWP,
898f95cc34SSepherosa Ziehauwhich is identified by the
908f95cc34SSepherosa Ziehau.Fa pid
918f95cc34SSepherosa Ziehauand the
928f95cc34SSepherosa Ziehau.Fa tid ,
938f95cc34SSepherosa Ziehauto the cpumask_t structure pointed to by
948f95cc34SSepherosa Ziehau.Fa mask .
958f95cc34SSepherosa ZiehauIf the
968f95cc34SSepherosa Ziehau.Fa pid
978f95cc34SSepherosa Ziehauis zero,
98907281d1SSepherosa Ziehauthen the pid of the calling process is used.
998f95cc34SSepherosa ZiehauIf the
1008f95cc34SSepherosa Ziehau.Fa tid
1018f95cc34SSepherosa Ziehauis less than zero,
102907281d1SSepherosa Ziehauthen the first LWP of specified process is used.
1038f95cc34SSepherosa Ziehau.Sh RETURN VALUES
1048f95cc34SSepherosa ZiehauThese system calls return \-1 on error and
1058f95cc34SSepherosa Ziehau0 upon successful completion.
1068f95cc34SSepherosa Ziehau.Sh ERRORS
1078f95cc34SSepherosa ZiehauThe
1088f95cc34SSepherosa Ziehau.Fn lwp_setaffinity
1098f95cc34SSepherosa Ziehauand
1108f95cc34SSepherosa Ziehau.Fn lwp_getaffinity
1118f95cc34SSepherosa Ziehausystem calls will fail if:
1128f95cc34SSepherosa Ziehau.Bl -tag -width Er
1138f95cc34SSepherosa Ziehau.It Bq Er EFAULT
1148f95cc34SSepherosa ZiehauThe
1158f95cc34SSepherosa Ziehau.Fa name
1168f95cc34SSepherosa Ziehauparameter is outside the process's allocated address space.
1178f95cc34SSepherosa Ziehau.It Bq Er EINVAL
1188f95cc34SSepherosa ZiehauThe
1198f95cc34SSepherosa Ziehau.Fa pid
1208f95cc34SSepherosa Ziehauparameter is negative.
1218f95cc34SSepherosa Ziehau.It Bq Er ESRCH
1228f95cc34SSepherosa ZiehauThe LWP identified by the
1238f95cc34SSepherosa Ziehau.Fa pid
1248f95cc34SSepherosa Ziehauand the
1258f95cc34SSepherosa Ziehau.Fa tid
1268f95cc34SSepherosa Ziehaudoes not exist.
1278f95cc34SSepherosa Ziehau.It Bq Er EPERM
1288f95cc34SSepherosa ZiehauThe
1298f95cc34SSepherosa Ziehau.Fa mask
1308f95cc34SSepherosa Ziehaudoes not contain a valid CPU.
1318f95cc34SSepherosa Ziehau.El
1328f95cc34SSepherosa Ziehau.Sh SEE ALSO
1338f95cc34SSepherosa Ziehau.Xr fork 2
1348f95cc34SSepherosa Ziehau.Xr lwp_create 2
1358f95cc34SSepherosa Ziehau.Xr pthread_create 3
136*a0c14455SSepherosa Ziehau.Xr pthread_getaffinity_np 3
137*a0c14455SSepherosa Ziehau.Xr pthread_setaffinity_np 3
1388f95cc34SSepherosa Ziehau.Xr rfork 2
139*a0c14455SSepherosa Ziehau.Xr sched_getaffinity 2
140*a0c14455SSepherosa Ziehau.Xr sched_setaffinity 2
1418f95cc34SSepherosa Ziehau.Xr vfork 2
1428f95cc34SSepherosa Ziehau.Sh HISTORY
1438f95cc34SSepherosa ZiehauThe
1448f95cc34SSepherosa Ziehau.Fn lwp_setaffinity
1458f95cc34SSepherosa Ziehauand
1468f95cc34SSepherosa Ziehau.Fn lwp_getaffinity
1478f95cc34SSepherosa Ziehaufunctions first appeared in
1488f95cc34SSepherosa Ziehau.Dx 4.7 .
149