Page MenuHomeFreeBSD

D38182.id115559.diff
No OneTemporary

D38182.id115559.diff

diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile
--- a/share/man/man9/Makefile
+++ b/share/man/man9/Makefile
@@ -196,6 +196,7 @@
KASSERT.9 \
kern_reboot.9 \
kern_testfrwk.9 \
+ kern_yield.9 \
kernacc.9 \
kernel_mount.9 \
khelp.9 \
@@ -1334,6 +1335,8 @@
intr_event.9 intr_event_handle.9 \
intr_event.9 intr_event_remove_handler.9 \
intr_event.9 intr_priority.9
+MLINKS+=kern_yield.9 maybe_yield.9 \
+ kern_yield.9 should_yield.9
MLINKS+=kernacc.9 useracc.9
MLINKS+=kernel_mount.9 free_mntarg.9 \
kernel_mount.9 mount_arg.9 \
diff --git a/share/man/man9/kern_yield.9 b/share/man/man9/kern_yield.9
new file mode 100644
--- /dev/null
+++ b/share/man/man9/kern_yield.9
@@ -0,0 +1,97 @@
+.\"
+.\" Copyright (c) 2023 The FreeBSD Foundation
+.\"
+.\" Portions of this documentation were written by Mitchell Horne
+.\" under sponsorship from the FreeBSD Foundation.
+.\"
+.\" 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.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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 8, 2023
+.Dt kern_yield 9
+.Os
+.Sh NAME
+.Nm kern_yield ,
+.Nm maybe_yield ,
+.Nm should_yield
+.Nd "functions for yielding execution of the current thread"
+.Sh SYNOPSIS
+.Ft void
+.Fn kern_yield "int prio"
+.Ft void
+.Fn maybe_yield
+.Ft bool
+.Fn should_yield
+.Sh DESCRIPTION
+The
+.Fn kern_yield
+function causes the currently running thread to voluntarily, but
+unconditionally, surrender its execution to the scheduler.
+The
+.Va prio
+argument specifies the scheduling priority to be assigned before the context
+switch, which has an influence on when execution will resume.
+Valid values for
+.Va prio
+are any of the
+.Dv PRI_*
+values defined in
+.In sys/priority.h ,
+as well as the following special values:
+.Bl -tag -width "PRI_UNCHANGED"
+.It Dv PRI_USER
+Schedule the thread with its base user priority; the value corresponding to
+.Xr setpriority 2 /
+.Xr nice 3 .
+.It Dv PRI_UNCHANGED
+Yield the thread without changing its priority.
+.El
+.Pp
+The
+.Fn should_yield
+function returns a boolean value indicating whether or not the current thread
+has been running for sufficient time that yielding would be useful, not
+wasteful.
+.Pp
+The
+.Fn maybe_yield
+function is a helper function for the common task of optionally yielding the processor.
+Internally,
+.Fn kern_yield "PRI_USER"
+will be called if
+.Fn should_yield
+returns
+.Va true.
+.Sh USAGE NOTES
+It is advised that code written using
+.Fn kern_yield
+be measured to confirm that its use has a positive effect on relevant
+performance or responsiveness metrics.
+Switching thread contexts has a non-zero cost, and thus yielding the processor
+too eagerly could have a negative impact on performance.
+.Sh SEE ALSO
+.Xr setpriority 2 ,
+.Xr nice 3 ,
+.Xr mi_switch 9
+.Sh AUTHORS
+.An -nosplit
+This manual page was written by
+.An Mitchell Horne Aq Mt mhorne@FreeBSD.org .

File Metadata

Mime Type
text/plain
Expires
Fri, May 22, 9:42 AM (6 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33418198
Default Alt Text
D38182.id115559.diff (4 KB)

Event Timeline