1.\" 2.\" Copyright (c) 2007 3.\" The DragonFly Project. All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in 13.\" the documentation and/or other materials provided with the 14.\" distribution. 15.\" 3. Neither the name of The DragonFly Project nor the names of its 16.\" contributors may be used to endorse or promote products derived 17.\" from this software without specific, prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 22.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 23.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 24.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 25.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 27.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 29.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" $DragonFly: src/share/man/man9/serializer.9,v 1.5 2008/05/15 09:21:40 swildner Exp $ 33.\" 34.Dd May 15, 2008 35.Os 36.Dt SERIALIZER 9 37.Sh NAME 38.Nm lwkt_serialize_init , 39.Nm lwkt_serialize_enter , 40.Nm lwkt_serialize_adaptive_enter , 41.Nm lwkt_serialize_try , 42.Nm lwkt_serialize_exit , 43.Nm lwkt_serialize_handler_enable , 44.Nm lwkt_serialize_handler_disable , 45.Nm lwkt_serialize_handler_call , 46.Nm lwkt_serialize_handler_try , 47.Nm ASSERT_SERIALIZED 48.Nm ASSERT_NOT_SERIALIZED 49.Nd generic low level serializer 50.Sh SYNOPSIS 51.In sys/serialize.h 52.Ft void 53.Fn lwkt_serialize_init "lwkt_serialize_t s" 54.Ft void 55.Fn lwkt_serialize_enter "lwkt_serialize_t s" 56.Ft void 57.Fn lwkt_serialize_adaptive_enter "lwkt_serialize_t s" 58.Ft int 59.Fn lwkt_serialize_try "lwkt_serialize_t s" 60.Ft void 61.Fn lwkt_serialize_exit "lwkt_serialize_t s" 62.Ft void 63.Fn lwkt_serialize_handler_enable "lwkt_serialize_t s" 64.Ft void 65.Fn lwkt_serialize_handler_disable "lwkt_serialize_t s" 66.Ft void 67.Fo lwkt_serialize_handler_call 68.Fa "lwkt_serialize_t s" 69.Fa "void (*func)(void *, void *)" 70.Fa "void *arg" 71.Fa "void *frame" 72.Fc 73.Ft int 74.Fo lwkt_serialize_handler_try 75.Fa "lwkt_serialize_t s" 76.Fa "void (*func)(void *, void *)" 77.Fa "void *arg" 78.Fa "void *frame" 79.Fc 80.Fn ASSERT_SERIALIZED "s" 81.Fn ASSERT_NOT_SERIALIZED "s" 82.Sh DESCRIPTION 83The 84.Nm serializer 85API provides a fast locked-bus-cycle-based serialization facility 86that will serialize across blocking conditions. 87It is very similar to a lock but much faster for the common case. 88.Pp 89This API was initially designed to be a replacement for SPL calls, but 90may be used whenever a low level exclusive lock (serialization) and/or 91interrupt/device interaction is required. 92Unlike tokens this serialization is not safe from deadlocks nor is it 93recursive, and care must be taken when using it. 94Note that 95.Xr tsleep 9 96will not release a serializer that is being held. 97.Pp 98There are two primary facilities \(em the serializer facility itself and 99an integrated non-stackable interrupt handler disablement facility 100used by drivers. 101.Pp 102.Fn lwkt_serialize_init , 103.Fn lwkt_serialize_enter 104and 105.Fn lwkt_serialize_exit 106respectively initialize, hold and release the serializer 107.Fa s . 108.Fn lwkt_serialize_try 109is a non-blocking version of 110.Fn lwkt_serialize_enter . 111.Pp 112.Fn lwkt_serialize_adaptive_enter 113is a special version of 114.Fn lwkt_serialize_enter 115which will try to spin a bit before the current thread is put to sleep 116if the serializer 117.Fa s 118is contended. 119By default, 120.Fn lwkt_serialize_adaptive_enter 121favors spinning over sleeping. 122This behavior can be changed by tuning the 123.Va debug.serialize_bolimit 124and 125.Va debug.serialize_boround 126.Xr sysctl 8 127variables. 128Note that 129.Fn lwkt_serialize_adaptive_enter 130is only available in SMP kernels. 131.Pp 132.Fn lwkt_serialize_handler_disable , 133.Fn lwkt_serialize_handler_enable 134and 135.Fn lwkt_serialize_handler_call 136respectively disable, enable and call an interrupt handler 137.Fa func 138for the serializer 139.Fa s . 140The arguments 141.Fa arg 142and 143.Fa frame 144will be passed to the handler. 145.Fn lwkt_serialize_handler_try 146is a non-blocking version of 147.Fn lwkt_serialize_handler_call . 148.Pp 149The 150.Fn ASSERT_SERIALIZED 151and 152.Fn ASSERT_NOT_SERIALIZED 153macros assert that the serializer 154.Fa s 155is being held/not held. 156.Sh RETURN VALUES 157The 158.Fn lwkt_serialize_try 159and 160.Fn lwkt_serialize_handler_try 161functions return 0 on success and 1 on failure. 162.Sh FILES 163.Pa sys/kern/lwkt_serialize.c 164.Sh SEE ALSO 165.Xr crit_enter 9 , 166.Xr serialize_sleep 9 , 167.Xr spinlock 9 168.Sh HISTORY 169The 170.Nm serializer 171API first appeared in 172.Dx 1.3 . 173.Sh AUTHORS 174.An -nosplit 175The 176.Nm serializer 177API was written by 178.An Matt Dillon . 179This manual page was written by 180.An Hasso Tepper . 181