xref: /dflybsd-src/lib/libc/sys/lwp_setaffinity.2 (revision 476c884a573292e93796bc5fccec91d43c1a37a1)
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
430d9899e7SSepherosa Ziehau.In sys/lwp.h
448f95cc34SSepherosa Ziehau.Ft int
458f95cc34SSepherosa Ziehau.Fn lwp_setaffinity "pid_t pid" "lwpid_t tid" "const cpumask_t *mask"
468f95cc34SSepherosa Ziehau.Ft int
478f95cc34SSepherosa Ziehau.Fn lwp_getaffinity "pid_t pid" "lwpid_t tid" "cpumask_t *mask"
488f95cc34SSepherosa Ziehau.Sh DESCRIPTION
498f95cc34SSepherosa ZiehauThe
508f95cc34SSepherosa Ziehau.Fn lwp_setaffinity
518f95cc34SSepherosa Ziehausystem call sets the CPU affinity mask of the LWP,
528f95cc34SSepherosa Ziehauwhich is identified by the
538f95cc34SSepherosa Ziehau.Fa pid
548f95cc34SSepherosa Ziehauand the
558f95cc34SSepherosa Ziehau.Fa tid ,
568f95cc34SSepherosa Ziehauto the value specified by the
578f95cc34SSepherosa Ziehau.Fa mask .
588f95cc34SSepherosa ZiehauIf the
598f95cc34SSepherosa Ziehau.Fa pid
608f95cc34SSepherosa Ziehauis zero,
61907281d1SSepherosa Ziehauthen the pid of the calling process is used.
628f95cc34SSepherosa ZiehauIf the
638f95cc34SSepherosa Ziehau.Fa tid
648f95cc34SSepherosa Ziehauis less than zero,
65907281d1SSepherosa Ziehauthen all LWPs of the process identified by the
66907281d1SSepherosa Ziehau.Fa pid
67907281d1SSepherosa Ziehauare affected.
688f95cc34SSepherosa ZiehauIf the LWP specified by the
698f95cc34SSepherosa Ziehau.Fa pid
708f95cc34SSepherosa Ziehauand the
718f95cc34SSepherosa Ziehau.Fa tid
72907281d1SSepherosa Ziehauis the current LWP it will be migrated immediately,
73a0c14455SSepherosa Ziehauif necessary, otherwise it will be migrated by the scheduler later.
748f95cc34SSepherosa Ziehau.Pp
758f95cc34SSepherosa ZiehauA process created by
768f95cc34SSepherosa Ziehau.Xr fork 2 ,
778f95cc34SSepherosa Ziehau.Xr vfork 2 ,
788f95cc34SSepherosa Ziehauand
798f95cc34SSepherosa Ziehau.Xr rfork 2
808f95cc34SSepherosa Ziehauinherits the calling LWP's CPU affinity mask.
818f95cc34SSepherosa ZiehauSame applies to the LWPs created by
828f95cc34SSepherosa Ziehau.Xr lwp_create 2 ,
838f95cc34SSepherosa Ziehauand the threads created by
848f95cc34SSepherosa Ziehau.Xr pthread_create 3 .
858f95cc34SSepherosa Ziehau.Pp
868f95cc34SSepherosa Ziehau.Fn lwp_getaffinity
878f95cc34SSepherosa Ziehauwrites the affinity mask of the LWP,
888f95cc34SSepherosa Ziehauwhich is identified by the
898f95cc34SSepherosa Ziehau.Fa pid
908f95cc34SSepherosa Ziehauand the
918f95cc34SSepherosa Ziehau.Fa tid ,
928f95cc34SSepherosa Ziehauto the cpumask_t structure pointed to by
938f95cc34SSepherosa Ziehau.Fa mask .
948f95cc34SSepherosa ZiehauIf the
958f95cc34SSepherosa Ziehau.Fa pid
968f95cc34SSepherosa Ziehauis zero,
97907281d1SSepherosa Ziehauthen the pid of the calling process is used.
988f95cc34SSepherosa ZiehauIf the
998f95cc34SSepherosa Ziehau.Fa tid
1008f95cc34SSepherosa Ziehauis less than zero,
101907281d1SSepherosa Ziehauthen the first LWP of specified process is used.
1028f95cc34SSepherosa Ziehau.Sh RETURN VALUES
1038f95cc34SSepherosa ZiehauThese system calls return \-1 on error and
1048f95cc34SSepherosa Ziehau0 upon successful completion.
1058f95cc34SSepherosa Ziehau.Sh ERRORS
1068f95cc34SSepherosa ZiehauThe
1078f95cc34SSepherosa Ziehau.Fn lwp_setaffinity
1088f95cc34SSepherosa Ziehauand
1098f95cc34SSepherosa Ziehau.Fn lwp_getaffinity
1108f95cc34SSepherosa Ziehausystem calls will fail if:
1118f95cc34SSepherosa Ziehau.Bl -tag -width Er
1128f95cc34SSepherosa Ziehau.It Bq Er EFAULT
1138f95cc34SSepherosa ZiehauThe
1148f95cc34SSepherosa Ziehau.Fa name
1158f95cc34SSepherosa Ziehauparameter is outside the process's allocated address space.
1168f95cc34SSepherosa Ziehau.It Bq Er EINVAL
1178f95cc34SSepherosa ZiehauThe
1188f95cc34SSepherosa Ziehau.Fa pid
1198f95cc34SSepherosa Ziehauparameter is negative.
1208f95cc34SSepherosa Ziehau.It Bq Er ESRCH
1218f95cc34SSepherosa ZiehauThe LWP identified by the
1228f95cc34SSepherosa Ziehau.Fa pid
1238f95cc34SSepherosa Ziehauand the
1248f95cc34SSepherosa Ziehau.Fa tid
1258f95cc34SSepherosa Ziehaudoes not exist.
1268f95cc34SSepherosa Ziehau.It Bq Er EPERM
1278f95cc34SSepherosa ZiehauThe
1288f95cc34SSepherosa Ziehau.Fa mask
1298f95cc34SSepherosa Ziehaudoes not contain a valid CPU.
1308f95cc34SSepherosa Ziehau.El
1318f95cc34SSepherosa Ziehau.Sh SEE ALSO
132*476c884aSSascha Wildner.Xr fork 2 ,
133*476c884aSSascha Wildner.Xr lwp_create 2 ,
134*476c884aSSascha Wildner.Xr rfork 2 ,
135*476c884aSSascha Wildner.Xr sched_getaffinity 2 ,
136*476c884aSSascha Wildner.Xr sched_setaffinity 2 ,
137*476c884aSSascha Wildner.Xr vfork 2 ,
138*476c884aSSascha Wildner.Xr pthread_create 3 ,
139*476c884aSSascha Wildner.Xr pthread_getaffinity_np 3 ,
140a0c14455SSepherosa Ziehau.Xr pthread_setaffinity_np 3
1418f95cc34SSepherosa Ziehau.Sh HISTORY
1428f95cc34SSepherosa ZiehauThe
1438f95cc34SSepherosa Ziehau.Fn lwp_setaffinity
1448f95cc34SSepherosa Ziehauand
1458f95cc34SSepherosa Ziehau.Fn lwp_getaffinity
1468f95cc34SSepherosa Ziehaufunctions first appeared in
1478f95cc34SSepherosa Ziehau.Dx 4.7 .
148