xref: /dflybsd-src/lib/libc/sys/lwp_setaffinity.2 (revision 480ed3de1b262fe0d036ad078a8dec4a4164a74c)
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.\"
338f95cc34SSepherosa Ziehau.Dd January 11, 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,
628f95cc34SSepherosa Ziehauthen the pid of the calling LWP's process is used.
638f95cc34SSepherosa ZiehauIf the
648f95cc34SSepherosa Ziehau.Fa tid
658f95cc34SSepherosa Ziehauis less than zero,
66*480ed3deSMatthew Dillonthen all threads of the calling LWP are affected.
678f95cc34SSepherosa ZiehauIf the LWP specified by the
688f95cc34SSepherosa Ziehau.Fa pid
698f95cc34SSepherosa Ziehauand the
708f95cc34SSepherosa Ziehau.Fa tid
71*480ed3deSMatthew Dillonis the current thread it will be migrated immediately,
72*480ed3deSMatthew Dillonif necessary, otherwise it will be migrated by the scheduler
73*480ed3deSMatthew Dillonlater.
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,
978f95cc34SSepherosa Ziehauthen the pid of the calling LWP's process is used.
988f95cc34SSepherosa ZiehauIf the
998f95cc34SSepherosa Ziehau.Fa tid
1008f95cc34SSepherosa Ziehauis less than zero,
101*480ed3deSMatthew Dillonthen the first thread 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
1328f95cc34SSepherosa Ziehau.Xr fork 2
1338f95cc34SSepherosa Ziehau.Xr lwp_create 2
1348f95cc34SSepherosa Ziehau.Xr pthread_create 3
1358f95cc34SSepherosa Ziehau.Xr rfork 2
1368f95cc34SSepherosa Ziehau.Xr vfork 2
1378f95cc34SSepherosa Ziehau.Sh HISTORY
1388f95cc34SSepherosa ZiehauThe
1398f95cc34SSepherosa Ziehau.Fn lwp_setaffinity
1408f95cc34SSepherosa Ziehauand
1418f95cc34SSepherosa Ziehau.Fn lwp_getaffinity
1428f95cc34SSepherosa Ziehaufunctions first appeared in
1438f95cc34SSepherosa Ziehau.Dx 4.7 .
144