diff options
author | Marc Espie <espie@cvs.openbsd.org> | 1999-09-05 16:23:13 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 1999-09-05 16:23:13 +0000 |
commit | 7ee2a80d3905da8d78a4759da0f2d7e82244fb23 (patch) | |
tree | 56cdcb0c0c2002f9bac52ea275dcf1ad81a943ef | |
parent | 0ac07ac634bd44d2e4a549872e1b4f83c155b5e8 (diff) |
New man pages, adapted from NetBSD.
Add corresponding cross-references.
Missed some uses of .Dv.
-rw-r--r-- | share/man/man9/Makefile | 14 | ||||
-rw-r--r-- | share/man/man9/extent.9 | 334 | ||||
-rw-r--r-- | share/man/man9/fork1.9 | 12 | ||||
-rw-r--r-- | share/man/man9/kthread.9 | 6 | ||||
-rw-r--r-- | share/man/man9/log.9 | 83 | ||||
-rw-r--r-- | share/man/man9/mi_switch.9 | 148 | ||||
-rw-r--r-- | share/man/man9/panic.9 | 8 | ||||
-rw-r--r-- | share/man/man9/printf.9 | 234 | ||||
-rw-r--r-- | share/man/man9/shutdownhook_establish.9 | 5 | ||||
-rw-r--r-- | share/man/man9/sleep.9 | 3 | ||||
-rw-r--r-- | share/man/man9/style.9 | 12 |
11 files changed, 842 insertions, 17 deletions
diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile index 8cb2e739e73..e0253a95b06 100644 --- a/share/man/man9/Makefile +++ b/share/man/man9/Makefile @@ -1,11 +1,12 @@ -# $OpenBSD: Makefile,v 1.11 1999/09/02 17:24:35 espie Exp $ +# $OpenBSD: Makefile,v 1.12 1999/09/05 16:23:11 espie Exp $ # $NetBSD: Makefile,v 1.4 1996/01/09 03:23:01 thorpej Exp $ # Makefile for section 9 (kernel function and variable) manual pages. MAN= boot.9 copy.9 disk.9 doshutdownhooks.9 fetch.9 fork1.9 \ - hz.9 hzto.9 intro.9 inittodr.9 kthread.9 \ - malloc.9 md5.9 microtime.9 panic.9 pfind.9 psignal.9 resettodr.9 \ + extent.9 hz.9 hzto.9 intro.9 inittodr.9 log.9 kthread.9 \ + malloc.9 md5.9 microtime.9 panic.9 pfind.9 printf.9 \ + psignal.9 resettodr.9 \ random.9 shutdownhook_establish.9 sleep.9 spl.9 store.9 style.9 \ time.9 timeout.9 vm_allocate.9 vm_map_copy.9 vm_deallocate.9 \ vm_map_inherit.9 vm_map_protect.9 @@ -15,12 +16,19 @@ MLINKS+=copy.9 copyin.9 copy.9 copyout.9 copy.9 copystr.9 \ MLINKS+=disk.9 disk_init.9 disk.9 disk_attach.9 disk.9 disk_detatch.9 \ disk.9 disk_busy.9 disk.9 disk_unbusy.9 disk.9 disk_find.9 \ disk.9 disk_resetstat.9 +MLINKS+=extent.9 extent_create.9 extent.9 extent_destroy.9 \ + extent.9 extent_alloc.9 extent.9 extent_alloc_subregion.9 \ + extent.9 extent_alloc_region.9 extent.9 extent_free.9 \ + extent.9 extent_free.9 MLINKS+=fetch.9 fubyte.9 fetch.9 fuibyte.9 fetch.9 fusword.9 \ fetch.9 fuswintr.9 fetch.9 fuword.9 fetch.9 fuiword.9 MLINKS+=kthread.9 kthread_create.9 kthread.9 kthread_exit.9 \ kthread.9 kthread_create_deferred.9 +MLINKS+=log.9 addlog.9 MLINKS+=md5.9 MD5Init.9 md5.9 MD5Transform.9 MLINKS+=pfind.9 pgfind.9 +MLINKS+=printf.9 sprintf.9 printf.9 vprintf.9 printf.9 uprintf.9 \ + printf.9 ttyprintf.9 printf.9 db_printf.9 MLINKS+=psignal.9 pgsignal.9 psignal.9 gsignal.9 MLINKS+=shutdownhook_establish.9 shutdownhook_disestablish.9 MLINKS+=sleep.9 tsleep.9 sleep.9 wakeup.9 diff --git a/share/man/man9/extent.9 b/share/man/man9/extent.9 new file mode 100644 index 00000000000..eb6ccd14529 --- /dev/null +++ b/share/man/man9/extent.9 @@ -0,0 +1,334 @@ +.\" $OpenBSD: extent.9,v 1.1 1999/09/05 16:23:11 espie Exp $ +.\" $NetBSD: extent.9,v 1.15 1999/03/16 00:40:47 garbled Exp $ +.\" +.\" Copyright (c) 1996, 1998 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Jason R. Thorpe and Greg Hudson. +.\" +.\" 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. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the NetBSD +.\" Foundation, Inc. and its contributors. +.\" 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 September 23, 1996 +.Dt EXTENT 9 +.Os +.Sh NAME +.Nm extent_create , +.Nm extent_destroy , +.Nm extent_alloc , +.Nm extent_alloc_subregion , +.Nm extent_alloc_region , +.Nm extent_free , +.Nm extent_print +.Nd general purpose extent manager +.Sh SYNOPSIS +.Fd #include <sys/malloc.h> +.Fd #include <sys/extent.h> +.Ft struct extent * +.Fn extent_create "char *name" "u_long start" "u_long end" "int mtype" "caddr_t storage" "size_t storagesize" "int flags" +.Ft void +.Fn extent_destroy "struct extent *ex" +.Ft int +.Fn extent_alloc "struct extent *ex" "u_long size" "u_long alignment" "u_long boundary" "int flags" "u_long *result" +.Ft int +.Fn extent_alloc_subregion "struct extent *ex" "u_long substart" "u_long subend" "u_long size" "u_long alignment" "u_long boundary" "u_long flags" "u_long *result" +.Ft int +.Fn extent_alloc_region "struct extent *ex" "u_long start" "u_long size" "int flags" +.Ft int +.Fn extent_free "struct extent *ex" "u_long start" "u_long size" "int flags" +.Ft void +.Fn extent_print "struct extent *ex" +.Sh DESCRIPTION +The extent manager provides management of areas of memory or +other enumerable spaces (such as I/O ports). An opaque structure +called an +.Nm extent map +keeps track of allocated regions within the enumerable space. +.Pp +.Fn extent_create +creates an extent map managing the space from +.Fa start +to +.Fa end +inclusive. All memory allocation will use the memory type +.Fa mtype +.Po +see +.Xr malloc 9 +.Pc . +The extent map will have the name +.Fa name , +used for identification in case of errors or in +.Xr ddb 4 +.Ic show extents . +If the flag +.Dv EX_NOCOALESCE +is set, internal coalescing of regions is disabled, +and only entire regions may be freed within the extent map, so that +.Fn extent_free +will never have to allocate a region descriptor. +.Pp +Some applications may want to use an extent map but +can't use +.Fn malloc +and +.Fn free . +These applications may provide pre-allocated storage for +all descriptor overhead with the arguments +.Fa storage +and +.Fa storagesize . +An extent of this type is called a +.Nm fixed extent . +If the application can safely use +.Fn malloc +and +.Fn free , +.Fa storage +should be +.Dv NULL . +A fixed extent has a fixed number of region descriptors, so care +should be taken to provide enough storage for them; alternatively, the +flag +.Dv EX_MALLOCOK +may be passed to extent requests to indicate that a fixed extent +map may be extended using a call to +.Fn malloc . +.Pp +The caller should pass the flag +.Dv EX_WAITOK +or +.Dv EX_NOWAIT +to extent functions that have a memory overhead, to specify whether +it is okay to wait. These functions are +.Fn extent_create +(non fixed extents), +.Fn extent_free +(unless +.Dv EX_NOCOALESCE +is set), +.Fn extent_alloc , +.Fn extent_alloc_subregion +and +.Fn extent_alloc_region . +.Pp +.Fn extent_destroy +destroys the extent map +.Fa ex , +freeing all allocated regions. If the extent is not a fixed extent, +the region and internal extent descriptors themselves are freed. +This function always succeeds. +.Pp +.Fn extent_alloc +allocates a region in the extent map +.Fa ex +of size +.Fa size +that fits the provided parameters. There are two distinct allocation +policies, which are selected by the +.Fa flags +argument: +.Bl -tag -offset indent -width "XXXXXXXXX" +.It Dv EX_FAST +Allocate the first region that fits the provided parameters, regardless +of resulting extent fragmentation. +.It default +Allocate the smallest region that is capable of holding the request, +thus minimizing fragmentation of the extent. +.El +.Pp +The caller may specify that it is okay to wait for space to become free in the +extent by setting the flag +.Dv EX_WAITSPACE . +If +.Dv EX_WAITSPACE +is not set, the allocation will fail if the request can not be +satisfied without sleeping. +.Pp +The request will be aligned to a multiple of +.Fa alignment . +That value must be a power of 2. If no alignment +is necessary, the value +.Dv EX_NOALIGN +should be specified. If +.Fa boundary +is not +.Dv EX_NOBOUNDARY , +the allocated region will not cross any boundary lines, spaced +.Fa boundary +apart. If the caller specifies the +.Dv EX_BOUNDZERO +flag, boundary lines begin at zero. Otherwise, boundary lines +begin at the beginning of the extent. The allocated region may begin on a +boundary line, but the end of the region will not touch nor cross a +boundary line. A +.Fa boundary +argument smaller than the size of the request is +invalid. Upon successful completion, +.Fa *result +will contain the start of the allocated region. +.Pp +.Fn extent_alloc_subregion +is a generalized version of +.Fn extent_alloc +that also allows the caller to specify that the allocated region must +fall within the subregion from +.Fa substart +to +.Fa subend +inclusive. +.Pp +.Fn extent_alloc_region +allocates the specific region in the extent map +.Fa ex +beginning at +.Fa start +with the size +.Fa size . +The caller may specify that it is okay to wait for the indicated +region to be free by setting the flag +.Dv EX_WAITSPACE . +If +.Dv EX_WAITSPACE +is not set, the allocation will fail if the request can not be +satisfied without sleeping. +.Pp +.Fn extent_free +frees a region of +.Fa size +bytes starting at +.Fa start +in the extent map +.Fa ex . +If the extent has the +.Dv EX_NOCOALESCE +property, only entire regions may be freed. If the extent has the +.Dv EX_NOCOALESCE +property and the caller attempts to free a partial region, behavior is +undefined. +.Pp +.Fn extent_print +Prints out information about extent +.Fa ex . +This function always succeeds. +.Sh RETURN VALUES +The behavior of all extent manager functions is undefined if given +invalid arguments. +.Fn extent_create +returns the extent map on success, or +.Dv NULL +if it fails to allocate storage for the extent map. It always +succeeds when creating a fixed extent or when given the flag +.Dv EX_WAITOK . +.Fn extent_alloc , +.Fn extent_alloc_region , +.Fn extent_alloc_subregion , +and +.Fn extent_free +return one of the following values: +.Bl -tag -offset indent -width "XXXXXXXX" +.It Dv 0 +Operation was successful. +.It Dv ENOMEM +If +.Dv EX_NOWAIT +is specified, the extent manager was not able to allocate a region +descriptor for the new region or to split a region when freeing a +partial region. +.It Dv EAGAIN +Requested region is not available and +.Dv EX_WAITSPACE +was not specified. +.It Dv EINTR +Process received a signal while waiting for the requested region to +become available in the extent. +.El +.Sh EXAMPLES +Here is an example of a (useless) function that uses several of the +extent manager routines. +.Bd -literal +void +func() +{ + struct extent *foo_ex; + u_long region_start; + int error; + + /* + * Extent "foo" manages a 256k region starting at 0x0 and + * only allows complete regions to be freed so that + * extent_free() never needs to allocate memory. + */ + foo_ex = extent_create("foo", 0x0, 0x3ffff, M_DEVBUF, + NULL, 0, EX_WAITOK | EX_NOCOALESCE); + + /* + * Allocate an 8k region, aligned to a 4k boundary, which + * does not cross any of the 3 64k boundaries (at 64k, + * 128k, and 192k) within the extent. + */ + error = extent_alloc(foo_ex, 0x2000, 0x1000, 0x10000, + EX_NOWAIT, ®ion_start); + if (error) + panic("you lose"); + + /* + * Give up the extent. + */ + extent_destroy(foo_ex); +} +.Ed +.\" +.\" Yeah, right... document EX_CATCH first... +.\" +.\" .Sh LIMITATIONS +.\" The flag +.\" .Dv EX_CATCH +.\" cannot be used to catch signals in all circumstances since +.\" .Xr malloc 9 +.\" does not provide such a functionality. +.Sh CODE REFERENCES +The extent manager itself is implemented within the file +.Pa sys/kern/subr_extent.c . +.Pp +The i386 bus management code uses the extent manager for managing I/O +ports and I/O memory. See +.Pa sys/arch/i386/i386/machdep.c . +.Sh AUTHOR +The extent manager was designed and implemented by Jason +R. Thorpe <thorpej@NetBSD.ORG>. Matthias Drochner +<drochner@zelux6.zel.kfa-juelich.de> contributed to the initial +testing and optimization of the implementation. Chris Demetriou +<cgd@NetBSD.ORG> contributed many architectural suggestions. +.Sh SEE ALSO +.Xr ddb 4 , +.Xr malloc 9 +.Sh HISTORY +The extent manager appeared in +.Nx 1.3 . diff --git a/share/man/man9/fork1.9 b/share/man/man9/fork1.9 index cc6ae4c52e1..f0a22c2e6bb 100644 --- a/share/man/man9/fork1.9 +++ b/share/man/man9/fork1.9 @@ -1,4 +1,4 @@ -.\" $OpenBSD: fork1.9,v 1.1 1999/09/02 17:24:35 espie Exp $ +.\" $OpenBSD: fork1.9,v 1.2 1999/09/05 16:23:11 espie Exp $ .\" $NetBSD: fork1.9,v 1.3 1999/03/16 00:40:47 garbled Exp $ .\" .\" Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -110,7 +110,9 @@ copy-on-write snapshot of the parent address space. .Pp If .Fa stack -is not NULL, the area starting at +is not +.Dv NULL , +the area starting at .Fa stack of extent .Fa stacksize @@ -119,7 +121,9 @@ stack. .Pp If .Fa retval -is not NULL, it will hold the following values after successful completion +is not +.Dv NULL , +it will hold the following values after successful completion of the fork operation: .Bl -tag -width retval[0] .It Fa retval[0] @@ -148,7 +152,7 @@ function semantics are specific to Other BSD systems have different semantics. .Pp The system never uses -.Nm +.Fn fork1 with a non-null .Fa stack , so that feature is not even tested. diff --git a/share/man/man9/kthread.9 b/share/man/man9/kthread.9 index cbc20560f14..f1417140fa5 100644 --- a/share/man/man9/kthread.9 +++ b/share/man/man9/kthread.9 @@ -1,4 +1,4 @@ -.\" $OpenBSD: kthread.9,v 1.1 1999/09/02 17:24:35 espie Exp $ +.\" $OpenBSD: kthread.9,v 1.2 1999/09/05 16:23:11 espie Exp $ .\" .\" Copyright (c) 1999 Marc Espie .\" All rights reserved. @@ -59,7 +59,9 @@ with argument .Fa arg . If .Fa newpp -is not NULL, it is filled with the address of the new process. +is not +.Dv NULL , +it is filled with the address of the new process. .Fa fmt and the remaining arguments are used to name the process. .Pp diff --git a/share/man/man9/log.9 b/share/man/man9/log.9 new file mode 100644 index 00000000000..0ffa285336b --- /dev/null +++ b/share/man/man9/log.9 @@ -0,0 +1,83 @@ +.\" $NetBSD: log.9,v 1.6 1999/08/17 05:24:06 enami Exp $ +.\" +.\" Copyright (c) 1997 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Michael Graff. +.\" +.\" 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. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the NetBSD +.\" Foundation, Inc. and its contributors. +.\" 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 May 12, 1997 +.Dt LOG 9 +.Os +.Sh NAME +.Nm log , +.Nm addlog +.Nd log a message from the kernel through the +.Pa /dev/klog +device +.Sh SYNOPSIS +.Fd #include <sys/syslog.h> +.Ft void +.Fo "log" +.Fa "int level" +.Fa "const char *format" +.Fa "..." +.Fc +.Ft void +.Fn addlog "const char *format" ... +.Sh DESCRIPTION +The +.Fn log +function allows the kernel to send formatted messages to user processes +listening on +.Pa /dev/klog . +Usually +.Xr syslogd 8 +monitors +.Pa /dev/klog +for these messages and writes them to a log file. +.Pp +All messages are formatted using +.Xr printf 9 , +logged using facility +.Dv LOG_KERN , +and priority level +.Fa level . +.Pp +The +.Fn addlog +function is used to build a log message in steps, by adding information +to an initial call to +.Fn log . +.Sh SEE ALSO +.Xr syslog 3 , +.Xr syslogd 8 , +.Xr printf 9 . diff --git a/share/man/man9/mi_switch.9 b/share/man/man9/mi_switch.9 new file mode 100644 index 00000000000..217d15551c9 --- /dev/null +++ b/share/man/man9/mi_switch.9 @@ -0,0 +1,148 @@ +.\" $OpenBSD: mi_switch.9,v 1.1 1999/09/05 16:23:11 espie Exp $ +.\" $NetBSD: ctxsw.9,v 1.10 1999/03/16 00:40:47 garbled Exp $ +.\" +.\" Copyright (c) 1996 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Paul Kranenburg. +.\" +.\" 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. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the NetBSD +.\" Foundation, Inc. and its contributors. +.\" 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 November 24, 1996 +.Dt CONTEXT SWITCH 9 +.Os +.Sh NAME +.Nm mi_switch , +.Nm cpu_switch +.Nd switch to another process context +.Sh SYNOPSIS +.Ft void +.Fn mi_switch "void" +.Ft void +.Fn cpu_switch "void" +.Sh DESCRIPTION +The +.Fn mi_switch +function implements the machine-independent prelude to a process context +switch. +It is called from only a few distinguished places in the kernel code as a +result of the principle of non-preemptable kernel mode execution. +The three major uses of +.Fn mi_switch +can be enumerated as follows: +.Bl -enum -offset indent +.It +From within +.Xr sleep 9 +and +.Xr tsleep 9 +when the current process +voluntarily relinquishes the CPU to wait for some resource to become +available. +.It +After handling a trap +.Pq e.g. a system call or device interrupt +when the kernel prepares a return to user-mode execution. +This case is typically handled by machine-dependent trap-handling code after +detection of a change in the signal disposition of the current process, or +when a higher priority process might be available to run. +The latter event is communicated by the machine-independent scheduling +routines by calling the machine-dependent +.Fn need_resched . +.It +In the signal handling code +.Pq see Xr issignal 9 +if a signal is delivered that causes a process to stop. +.El +.Pp +.Fn mi_switch +records the amount of time the current process has been running in the +process structure and checks this value against the CPU time limits +allocated to the process +.Pq see Xr getrlimit 2 . +Exceeding the soft limit results in a +.Dv SIGXCPU +signal to be posted to the process, while exceeding the hard limit will +cause a +.Dv SIGKILL . +After these administrative tasks are done, +.Fn mi_switch +hands over control to the machine dependent routine +.Fn cpu_switch , +which will perform the actual process context switch. +.Pp +.Fn cpu_switch +will make a choice amongst the processes which are ready to run from a +priority queue data-structure. +The priority queue consists of an array +.Va qs[NQS] +of queue header structures, each of which identifies a list of runnable +processes of equal priority +.Pq see Aq Pa sys/proc.h . +A single word +.Va whichqs +containing a bit mask identifying non-empty queues assists in selecting +a process quickly. +.Fn cpu_switch +must remove the first process from the list on the queue +with the highest priority +(lower indices in +.Va qs +indicate higher priority), +and assign the address of its process structure to the global variable +.Va curproc . +If no processes are available on the run queues, +.Fn cpu_switch +shall go into an +.Dq idle +loop. +The idle loop must allow interrupts to be taken that will eventually cause +processes to appear again on the run queues. +The variable +.Va curproc +should be +.Dv NULL +while +.Fn cpu_switch +waits for this to happen. +.Pp +Note that +.Fn mi_switch +and thus +.Fn cpu_switch +should be called at +.Xr splhigh 9 . +.Sh CODE_REFERENCES +The +.Fn mi_switch +function is implemented in the file +.Pa sys/kern/kern_synch.c . +.Sh SEE ALSO +.Xr sleep 9 . diff --git a/share/man/man9/panic.9 b/share/man/man9/panic.9 index 9001cdb9b0a..b996a38792e 100644 --- a/share/man/man9/panic.9 +++ b/share/man/man9/panic.9 @@ -1,4 +1,4 @@ -.\" $OpenBSD: panic.9,v 1.3 1999/07/18 16:36:39 espie Exp $ +.\" $OpenBSD: panic.9,v 1.4 1999/09/05 16:23:11 espie Exp $ .\" $NetBSD: panic.9,v 1.2 1996/10/09 17:20:04 explorer Exp $ .\" .\" Copyright (c) 1996 Michael Graff. @@ -47,7 +47,7 @@ The function makes the OpenBSD system terminate. The message .Fa fmt is a -.Xr printf 3 +.Xr printf 9 style format string. The message is printed to the console and the location pointed to by the global char pointer .Fa panicstr @@ -66,3 +66,7 @@ rebooted without syncing the disks. The .Fn panic function does not return. +.Sh SEE ALSO +.Xr printf 3 , +.Xr boot 9 , +.Xr printf 9 diff --git a/share/man/man9/printf.9 b/share/man/man9/printf.9 new file mode 100644 index 00000000000..5dd57396666 --- /dev/null +++ b/share/man/man9/printf.9 @@ -0,0 +1,234 @@ +.\" $NetBSD: kprintf.9,v 1.6 1999/03/16 00:40:47 garbled Exp $ +.\" +.\" Copyright (c) 1998 The NetBSD Foundation, Inc. +.\" All rights reserved. +.\" +.\" This code is derived from software contributed to The NetBSD Foundation +.\" by Jeremy Cooper. +.\" +.\" 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. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the NetBSD +.\" Foundation, Inc. and its contributors. +.\" 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 Sep 1, 1998 +.Dt PRINTF 9 +.Os +.Sh NAME +.Nm printf , +.Nm sprintf , +.Nm vprintf, +.Nm uprintf, +.Nm ttyprintf, +.Nm db_printf +.Nd kernel formatted output conversion +.Sh SYNOPSIS +.Fd #include <sys/types.h> +.Fd #include <sys/systm.h> +.Ft void +.Fo "printf" +.Fa "const char *format" +.Fa "..." +.Fc +.Ft int +.Fo "sprintf" +.Fa "char *buf" +.Fa "const char *format" +.Fa "..." +.Fc +.Ft void +.Fo "vprintf" +.Fa "const char *format" +.Fa "va_list ap" +.Fc +.Ft void +.Fo "uprintf" +.Fa "const char *format" +.Fa "..." +.Fc +.Ft void +.Fo "ttyprintf" +.Fa "struct tty *tty" +.Fa "const char *format" +.Fa "..." +.Fc +.Ft void +.Fn db_printf "const char *format" ... +.Sh DESCRIPTION +The +.Fn printf , +.Fn sprintf , +.Fn vprintf , +.Fn uprintf , +.Fn ttyprintf , +and +.Fn db_printf +functions allow the kernel to send formatted messages to various output +devices. +The functions +.Fn printf +and +.Fn vprintf +send formatted strings to the system console and to the system log. +The functions +.Fn uprintf +and +.Fn ttyprintf +send formatted strings to the current process's controlling tty and a specific +tty, +respectively. +The function +.Fn db_printf +sends formatted strings to the ddb console, and is only used to implement +.Xr ddb 4 . +.Pp +Since each of these kernel functions is a variant of its user space +counterpart, +this page describes only the differences between the user space and kernel +versions. Refer to +.Xr printf 3 +for functional details. +.Ss FORMAT OPTIONS +The kernel functions don't support any floating point formatting +specifiers. In addition to other formatting specifiers common with the user +space functions, the kernel functions accept the following format specifiers +in the format string +.Fa format : +.Pp +.Bl -tag -width "\e177" +.It Li %b +Bit field expansion. +This format specifier is useful for decoding bit fields in device registers. +It displays an integer using a specified radix +.Pq base +and an interpretation of +the bits within that integer as though they were flags. +It requires two arguments from the argument vector, the first argument being +the bit field to be decoded +.Pq "as an integer" +and the second being a decoding directive string. +.Pp +The decoding directive string describes how the bitfield is to be interpreted +and displayed. +The first character of the string is a binary character representation of the +output numeral base in which the bitfield will be printed before it is decoded. +Recognized radix values +.Pq "in C escape-character format" +are +.Li \e10 +.Pq octal , +.Li \e12 +.Pq decimal , +and +.Li \e20 +.Pq hexadecimal . +.Pp +The remaining characters in the decoding directive string are interpreted as a +list of bit-position\(endescription pairs. +A bit-position\(endescription pair begins with a binary character value +that represents the position of the bit being described. +A bit position value of one describes the least significant bit. +Whereas a position value of 32 +.Pq "octal 40, hexadecimal 20, the ASCII space character" +describes the most significant bit. +.Pp +The remaining characters in a bit-position\(endescription pair are the +characters to print should the bit being described be set. +Description strings are delimited by the next bit position value character +encountered +.Pq "distinguishable by its value being \(<= 32" , +or the end of the decoding directive string itself. +.It Li %: +Inline format continuation. +This format specifier allows for recursive formatted output. +Its argument is the new formatting string to obey and the argument which +follows it is a +.Va va_list +argument vector from which to obtain the data to be formatted. +.It Li %r +Displays an integer using the current +.Tn DDB +radix. +This non-standard interpretation of +.Li %r +is only available to +.Fn db_printf . +.It Li %z +Displays a signed integer using the C-style hexadecimal constant format. +This format specifier is only available to +.Fn db_printf . +.El +.Sh RETURN VALUES +The +.Fn sprintf +function returns the number of characters it placed in the buffer +.Fa buf . +.Sh EXAMPLES +Use of the +.Li %b +format specifier for decoding device registers. +.Bd -literal -offset indent +printf("reg=%b\en", 3, "\e10\e2BITTWO\e1BITONE") +\(rA "reg=3<BITTWO,BITONE>" + +printf("enablereg=%b\en", 0xe860, + "\e20\ex10NOTBOOT\ex0fFPP\ex0eSDVMA\ex0cVIDEO" + "\ex0bLORES\ex0aFPA\ex09DIAG\ex07CACHE" + "\ex06IOCACHE\ex05LOOPBACK\ex04DBGCACHE") +\(rA "enablereg=e860<NOTBOOT,FPP,SDVMA,VIDEO,CACHE,IOCACHE>" +.Ed +.Pp +Use of the +.Li %: +format specifier for recursive formatting. +.Bd -literal -offset indent +void +bail(char *fmt, ...) +{ + va_list ap; + va_start (ap, fmt); + printf("bailing out: %:\en", fmt, ap); + va_end(ap); +} + +bail("descriptor %d is invalid.", 5) +\(rA "bailing out: descriptor 5 is invalid" +.Ed +.Sh SEE ALSO +.\" The following page has not been written, but I am including a cross- +.\" reference to it in the hopes that it will inspire someone to write it. +.Xr revoke 2 , +.Xr printf 3 , +.Xr ddb 4 , +.Xr log 9 , +.Xr tprintf 9 +.Sh CODE REFERENCES +.Pa sys/kern/subr_prf.c +.Sh LIMITATIONS +The +.Li %b +format specifier cannot be used to decode integers greater than 32 bits in +size. diff --git a/share/man/man9/shutdownhook_establish.9 b/share/man/man9/shutdownhook_establish.9 index 7e66a32110a..855677bba6c 100644 --- a/share/man/man9/shutdownhook_establish.9 +++ b/share/man/man9/shutdownhook_establish.9 @@ -1,4 +1,4 @@ -.\" $OpenBSD: shutdownhook_establish.9,v 1.6 1999/09/02 17:28:07 espie Exp $ +.\" $OpenBSD: shutdownhook_establish.9,v 1.7 1999/09/05 16:23:11 espie Exp $ .\" $NetBSD: shutdownhook_establish.9,v 1.1 1995/11/25 21:24:52 perry Exp $ .\" .\" Copyright (c) 1994 Christopher G. Demetriou @@ -75,7 +75,8 @@ integrity (because the system could be rebooting after a crash). If successful, .Fn shutdownhook_establish returns an opaque pointer describing the newly established -shutdown hook. Otherwise, it returns NULL. +shutdown hook. Otherwise, it returns +.Dv NULL . .Sh EXAMPLES It may be appropriate to use a shutdown hook to disable a device that does direct memory access, so that diff --git a/share/man/man9/sleep.9 b/share/man/man9/sleep.9 index 762288fedf8..c4b054ecae5 100644 --- a/share/man/man9/sleep.9 +++ b/share/man/man9/sleep.9 @@ -1,4 +1,4 @@ -.\" $OpenBSD: sleep.9,v 1.2 1999/09/02 17:28:07 espie Exp $ +.\" $OpenBSD: sleep.9,v 1.3 1999/09/05 16:23:11 espie Exp $ .\" $NetBSD: sleep.9,v 1.11 1999/03/24 06:15:12 mycroft Exp $ .\" .\" Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -181,4 +181,5 @@ These functions are implemented in the file .Pa sys/kern/kern_synch.c . .Sh SEE ALSO .Xr hz 9 , +.Xr mi_switch 9 , .Xr timeout 9 diff --git a/share/man/man9/style.9 b/share/man/man9/style.9 index 2f2ac145568..cbb5b53cb54 100644 --- a/share/man/man9/style.9 +++ b/share/man/man9/style.9 @@ -22,7 +22,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: style.9,v 1.2 1999/08/31 17:08:04 espie Exp $ +.\" $OpenBSD: style.9,v 1.3 1999/09/05 16:23:12 espie Exp $ .\" .Dd August 19, 1999 .Dt STYLE 9 @@ -390,14 +390,20 @@ Casts and sizeof's are not followed by a space. Note that .Xr indent 1 does not understand this rule. .Pp -NULL is the preferred null pointer constant. Use NULL instead of +.Dv +NULL +is the preferred null pointer constant. Use +.Dv NULL +instead of (type *)0 or (type *)NULL in contexts where the compiler knows the type, e.g., in assignments. Use (type *)NULL in other contexts, in particular for all function args. (Casting is essential for variadic args and is necessary for other args if the function prototype might not be in scope.) Test pointers -against NULL, e.g., use: +against +.Dv NULL , +e.g., use: .Bd -literal -offset 0i (p = f()) == NULL .Ed |