.\" Copyright (c) 2007 The DragonFly Project.  All rights reserved.
.\"
.\" This code is derived from software contributed to The DragonFly Project
.\" by Matthew Dillon <dillon@backplane.com>
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\"
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in
.\"    the documentation and/or other materials provided with the
.\"    distribution.
.\" 3. Neither the name of The DragonFly Project nor the names of its
.\"    contributors may be used to endorse or promote products derived
.\"    from this software without specific, prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd January 9, 2017
.Dt USCHED_SET 2
.Os
.Sh NAME
.Nm usched_set
.Nd setting up a proc's usched
.Sh LIBRARY
.Lb libc
.Sh SYNOPSIS
.In sys/types.h
.In sys/usched.h
.Ft int
.Fn usched_set "pid_t pid" "int cmd" "void *data" "int bytes"
.Sh DESCRIPTION
The
.Fn usched_set
function is used to perform several user scheduler tasks.
These tasks include: setting the user scheduler, assigning an LWP to a
specific CPU, adding a CPU to the available CPUs for an LWP,
and removing a CPU from the list of available CPUs for an LWP.
The
.Fn usched_set
function requires superuser privileges for all commands except
.Dv USCHED_GET_CPU
and
.Dv USCHED_GET_CPUMASK .
.Pp
The
.Fa cmd
argument specifies the action for
.Fn usched_set
to take:
.Bl -tag -width ".Dv USCHED_SET_SCHEDULER"
.It Dv USCHED_SET_SCHEDULER
set the user scheduler where
.Fa data
is a
.Vt char *
that contains the name of the user scheduler.
.It Dv USCHED_SET_CPU
assign the LWP to the cpuid pointed to by
.Fa data .
.It Dv USCHED_GET_CPU
copy the LWP's CPU ID to the cpuid pointed to by
.Fa data .
.It Dv USCHED_GET_CPUMASK
copy the LWP's CPU mask to the cpumask_t type pointed to by
.Fa data .
.It Dv USCHED_SET_CPUMASK
set the LWP's CPU mask to the cpumask_t type pointed to by
.Fa data .
.It Dv USCHED_ADD_CPU
add the cpuid specified by
.Fa data
to the list of available CPUs for the LWP.
.It Dv USCHED_DEL_CPU
remove the cpuid specified by
.Fa data
from the list of available CPUs for the LWP.
.El
.Sh RETURN VALUES
.Rv -std
.Sh ERRORS
The function will fail if:
.Bl -tag -width Er
.It Bq Er EINVAL
The user scheduler to set is not in the list of available user schedulers.
The
.Fa bytes
argument is not the correct size
.Vt ( int )
for a cpuid.
The specified cpuid is not set in
.Va smp_active_mask .
.Fa Cmd
contains an unknown value.
.It Bq Er EFBIG
The specified cpuid is not a valid cpuid for the system.
.It Bq Er EPERM
Deleting the specified cpuid leaves the LWP without a CPU to run on.
.El
.Sh SEE ALSO
.Xr usched 8
.Sh HISTORY
The
.Fn usched_set
function call was added in
.Dx 1.9 .
.Sh AUTHORS
.An -nosplit
The
.Fn usched_set
system call was written by
.An Matt Dillon .
This manual page was written by
.An Joe Talbott .
.Sh BUGS
Only
.Fa pid
equals current LWP PID or 0 is implemented.
The current LWP PID is used for
.Fa pid
when
.Fa pid
is 0.
One would normally only use 0 for
.Fa pid .
