|
Added
Link Here
|
| 1 |
.\" |
| 2 |
.\" Copyright (C) 2002 Garrett Rooney <rooneg@electricjellyfish.net>. All |
| 3 |
.\" 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 |
.\" 1. Redistributions of source code must retain the above copyright |
| 9 |
.\" notice(s), this list of conditions and the following disclaimer as |
| 10 |
.\" the first lines of this file unmodified other than the possible |
| 11 |
.\" addition of one or more copyright notices. |
| 12 |
.\" 2. Redistributions in binary form must reproduce the above copyright |
| 13 |
.\" notice(s), this list of conditions and the following disclaimer in the |
| 14 |
.\" documentation and/or other materials provided with the distribution. |
| 15 |
.\" |
| 16 |
.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY |
| 17 |
.\" EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 |
.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 |
.\" DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY |
| 20 |
.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 21 |
.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 22 |
.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 23 |
.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 24 |
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 25 |
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH |
| 26 |
.\" DAMAGE. |
| 27 |
.\" |
| 28 |
.\" $FreeBSD$ |
| 29 |
.\" |
| 30 |
.Dd March 25, 2002 |
| 31 |
.Dt MTX_POOL 9 |
| 32 |
.Os |
| 33 |
.Sh NAME |
| 34 |
.Nm mtx_pool , |
| 35 |
.Nm mtx_pool_alloc , |
| 36 |
.Nm mtx_pool_find , |
| 37 |
.Nm mtx_lock_lock , |
| 38 |
.Nm mtx_lock_unlock |
| 39 |
.Nd mutex pool routines |
| 40 |
.Sh SYNOPSIS |
| 41 |
.In sys/mutex.h |
| 42 |
.Ft struct mtx * |
| 43 |
.Fn mtx_pool_alloc "void" |
| 44 |
.Ft struct mtx * |
| 45 |
.Fn mtx_pool_find "void *ptr" |
| 46 |
.Ft void |
| 47 |
.Fn mtx_pool_lock "void *ptr" |
| 48 |
.Ft void |
| 49 |
.Fn mtx_pool_unlock "void *ptr" |
| 50 |
.Sh DESCRIPTION |
| 51 |
Mutex pools are designed to be used as short term leaf mutexes, e.g. the |
| 52 |
last mutex you might acquire other than calling |
| 53 |
.Fn msleep . |
| 54 |
They operate using a shared pool of mutexes. |
| 55 |
A mutex is chosen from the pool based on the supplied pointer (which may or |
| 56 |
may not be valid). |
| 57 |
.Pp |
| 58 |
The shared mutex managed by the pool module are standard, non-recursive, |
| 59 |
blockable mutexes, and should only be used in appropriate situations. |
| 60 |
.Pp |
| 61 |
The caller can lock and unlock mutexes returned by the pool routines, but |
| 62 |
since the mutexes are shared, the caller should not attempt to destroy them |
| 63 |
or modify their characteristics. |
| 64 |
While pool mutexes are normally 'leaf' mutexes, meaning that you cannot |
| 65 |
depend on any ordering guarantees after obtaining one, you can still obtain |
| 66 |
other mutexes under carefully controlled circumstances. |
| 67 |
Specifically, if you have a private mutex (that you allocate and |
| 68 |
.Fn mtx_init |
| 69 |
yourself), and you carefully manage the ordering issues, you can obtain your |
| 70 |
private mutex after obtaining the pool mutex. |
| 71 |
In these cases the private mute winds up being the true 'leaf' mutex. |
| 72 |
.Pp |
| 73 |
Mutex pools have the following advantages: |
| 74 |
.Bl -enum |
| 75 |
.It |
| 76 |
No structural overhead. |
| 77 |
Mutexes can be associated with structures without adding bloat to the structures. |
| 78 |
.It |
| 79 |
Mutexes can be obtained for invalid pointers, which is useful when one uses |
| 80 |
mutexes to interlock destructor operations. |
| 81 |
.It |
| 82 |
No initialization/destruction overhead. |
| 83 |
.It |
| 84 |
Can be used with msleep. |
| 85 |
.El |
| 86 |
.Pp |
| 87 |
And the following disadvantages: |
| 88 |
.Bl -enum |
| 89 |
.It |
| 90 |
Should generally only be used as leaf mutexes. |
| 91 |
.It |
| 92 |
Pool/pool dependency ordering cannot be depended on. |
| 93 |
.It |
| 94 |
Possible L1 cache mastership contention between CPUs. |
| 95 |
.El |
| 96 |
.Pp |
| 97 |
.Fn mtx_pool_alloc |
| 98 |
obtains a shared mutex from the pool. |
| 99 |
This routine uses a simple rover to choose one of the shared mutexes managed |
| 100 |
by the module. |
| 101 |
.Pp |
| 102 |
.Fn mtx_pool_find |
| 103 |
returns the shared mutex associated with the specified address. |
| 104 |
This routine will create a hash out of the arbitrary pointer passed into it |
| 105 |
and will choose a shared mutex based on the hash. |
| 106 |
The pointer need not point to anything real. |
| 107 |
.Pp |
| 108 |
.Fn mtx_pool_lock |
| 109 |
locks the shared mutex associated with the specified address. |
| 110 |
This routine provides an easy-to-use combination of |
| 111 |
.Fn mtx_pool_find |
| 112 |
and |
| 113 |
.Fn mtx_pool_lock . |
| 114 |
Note that because it must hash the pointer passed to it, this will not be |
| 115 |
as fast as storing the pointer returned by a previous |
| 116 |
.Fn mtx_pool_find . |
| 117 |
.Pp |
| 118 |
.Fn mtx_pool_unlock |
| 119 |
unlocks the shared mutex associated with the specified address. |
| 120 |
This routine provides an easy-to-use combination of |
| 121 |
.Fn mtx_pool_find |
| 122 |
and |
| 123 |
.Fn mtx_pool_unlock . |
| 124 |
Note that because it must hash the pointer passed to it, this will not be |
| 125 |
as fast as storing the pointer returned by a previous |
| 126 |
.Fn mtx_pool_find . |
| 127 |
.Pp |
| 128 |
.Sh SEE ALSO |
| 129 |
.Xr mutex 9 , |
| 130 |
.Xr msleep 9 |
| 131 |
.Sh HISTORY |
| 132 |
These |
| 133 |
functions appeared in |
| 134 |
.Fx 5.0 . |