xref: /dflybsd-src/lib/libc/sys/lwp_setaffinity.2 (revision 907281d1a2ecde2d5dfefe84c7a5781df8a217d4)
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.\"
33*907281d1SSepherosa 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,
62*907281d1SSepherosa Ziehauthen the pid of the calling process is used.
638f95cc34SSepherosa ZiehauIf the
648f95cc34SSepherosa Ziehau.Fa tid
658f95cc34SSepherosa Ziehauis less than zero,
66*907281d1SSepherosa Ziehauthen all LWPs of the process identified by the
67*907281d1SSepherosa Ziehau.Fa pid
68*907281d1SSepherosa Ziehauare affected.
698f95cc34SSepherosa ZiehauIf the LWP specified by the
708f95cc34SSepherosa Ziehau.Fa pid
718f95cc34SSepherosa Ziehauand the
728f95cc34SSepherosa Ziehau.Fa tid
73*907281d1SSepherosa Ziehauis the current LWP it will be migrated immediately,
74480ed3deSMatthew Dillonif necessary, otherwise it will be migrated by the scheduler
75480ed3deSMatthew Dillonlater.
768f95cc34SSepherosa Ziehau.Pp
778f95cc34SSepherosa ZiehauA process created by
788f95cc34SSepherosa Ziehau.Xr fork 2 ,
798f95cc34SSepherosa Ziehau.Xr vfork 2 ,
808f95cc34SSepherosa Ziehauand
818f95cc34SSepherosa Ziehau.Xr rfork 2
828f95cc34SSepherosa Ziehauinherits the calling LWP's CPU affinity mask.
838f95cc34SSepherosa ZiehauSame applies to the LWPs created by
848f95cc34SSepherosa Ziehau.Xr lwp_create 2 ,
858f95cc34SSepherosa Ziehauand the threads created by
868f95cc34SSepherosa Ziehau.Xr pthread_create 3 .
878f95cc34SSepherosa Ziehau.Pp
888f95cc34SSepherosa Ziehau.Fn lwp_getaffinity
898f95cc34SSepherosa Ziehauwrites the affinity mask of the LWP,
908f95cc34SSepherosa Ziehauwhich is identified by the
918f95cc34SSepherosa Ziehau.Fa pid
928f95cc34SSepherosa Ziehauand the
938f95cc34SSepherosa Ziehau.Fa tid ,
948f95cc34SSepherosa Ziehauto the cpumask_t structure pointed to by
958f95cc34SSepherosa Ziehau.Fa mask .
968f95cc34SSepherosa ZiehauIf the
978f95cc34SSepherosa Ziehau.Fa pid
988f95cc34SSepherosa Ziehauis zero,
99*907281d1SSepherosa Ziehauthen the pid of the calling process is used.
1008f95cc34SSepherosa ZiehauIf the
1018f95cc34SSepherosa Ziehau.Fa tid
1028f95cc34SSepherosa Ziehauis less than zero,
103*907281d1SSepherosa Ziehauthen the first LWP of specified process is used.
1048f95cc34SSepherosa Ziehau.Sh RETURN VALUES
1058f95cc34SSepherosa ZiehauThese system calls return \-1 on error and
1068f95cc34SSepherosa Ziehau0 upon successful completion.
1078f95cc34SSepherosa Ziehau.Sh ERRORS
1088f95cc34SSepherosa ZiehauThe
1098f95cc34SSepherosa Ziehau.Fn lwp_setaffinity
1108f95cc34SSepherosa Ziehauand
1118f95cc34SSepherosa Ziehau.Fn lwp_getaffinity
1128f95cc34SSepherosa Ziehausystem calls will fail if:
1138f95cc34SSepherosa Ziehau.Bl -tag -width Er
1148f95cc34SSepherosa Ziehau.It Bq Er EFAULT
1158f95cc34SSepherosa ZiehauThe
1168f95cc34SSepherosa Ziehau.Fa name
1178f95cc34SSepherosa Ziehauparameter is outside the process's allocated address space.
1188f95cc34SSepherosa Ziehau.It Bq Er EINVAL
1198f95cc34SSepherosa ZiehauThe
1208f95cc34SSepherosa Ziehau.Fa pid
1218f95cc34SSepherosa Ziehauparameter is negative.
1228f95cc34SSepherosa Ziehau.It Bq Er ESRCH
1238f95cc34SSepherosa ZiehauThe LWP identified by the
1248f95cc34SSepherosa Ziehau.Fa pid
1258f95cc34SSepherosa Ziehauand the
1268f95cc34SSepherosa Ziehau.Fa tid
1278f95cc34SSepherosa Ziehaudoes not exist.
1288f95cc34SSepherosa Ziehau.It Bq Er EPERM
1298f95cc34SSepherosa ZiehauThe
1308f95cc34SSepherosa Ziehau.Fa mask
1318f95cc34SSepherosa Ziehaudoes not contain a valid CPU.
1328f95cc34SSepherosa Ziehau.El
1338f95cc34SSepherosa Ziehau.Sh SEE ALSO
1348f95cc34SSepherosa Ziehau.Xr fork 2
1358f95cc34SSepherosa Ziehau.Xr lwp_create 2
1368f95cc34SSepherosa Ziehau.Xr pthread_create 3
1378f95cc34SSepherosa Ziehau.Xr rfork 2
1388f95cc34SSepherosa Ziehau.Xr vfork 2
1398f95cc34SSepherosa Ziehau.Sh HISTORY
1408f95cc34SSepherosa ZiehauThe
1418f95cc34SSepherosa Ziehau.Fn lwp_setaffinity
1428f95cc34SSepherosa Ziehauand
1438f95cc34SSepherosa Ziehau.Fn lwp_getaffinity
1448f95cc34SSepherosa Ziehaufunctions first appeared in
1458f95cc34SSepherosa Ziehau.Dx 4.7 .
146