Transitioning if_addr_lock to an rwlock
Bjoern A. Zeeb
bz at freebsd.org
Fri Jan 6 20:56:56 UTC 2012
On 6. Jan 2012, at 20:39 , John Baldwin wrote:
>
> Now that all of this is in the tree, here is the small patch to cut the locks
> over to rwlocks rather than mutexes:
I have not checked if that's all (esp. for witness) but the macro conversion look right.
> Index: kern/subr_witness.c
> ===================================================================
> --- kern/subr_witness.c (revision 229726)
> +++ kern/subr_witness.c (working copy)
> @@ -520,7 +520,7 @@
> { "udpinp", &lock_class_rw },
> { "in_multi_mtx", &lock_class_mtx_sleep },
> { "igmp_mtx", &lock_class_mtx_sleep },
> - { "if_addr_mtx", &lock_class_mtx_sleep },
> + { "if_addr_lock", &lock_class_rw },
> { NULL, NULL },
> /*
> * IPv6 multicast:
> @@ -529,7 +529,7 @@
> { "udpinp", &lock_class_rw },
> { "in6_multi_mtx", &lock_class_mtx_sleep },
> { "mld_mtx", &lock_class_mtx_sleep },
> - { "if_addr_mtx", &lock_class_mtx_sleep },
> + { "if_addr_lock", &lock_class_rw },
> { NULL, NULL },
> /*
> * UNIX Domain Sockets
> Index: net/if_var.h
> ===================================================================
> --- net/if_var.h (revision 229726)
> +++ net/if_var.h (working copy)
> @@ -189,7 +189,7 @@
> int if_afdata_initialized;
> struct rwlock if_afdata_lock;
> struct task if_linktask; /* task for link change events */
> - struct mtx if_addr_mtx; /* mutex to protect address lists */
> + struct rwlock if_addr_lock; /* lock to protect address lists */
>
> LIST_ENTRY(ifnet) if_clones; /* interfaces of a cloner */
> TAILQ_HEAD(, ifg_list) if_groups; /* linked list of groups per if */
> @@ -246,15 +246,14 @@
> /*
> * Locks for address lists on the network interface.
> */
> -#define IF_ADDR_LOCK_INIT(if) mtx_init(&(if)->if_addr_mtx, \
> - "if_addr_mtx", NULL, MTX_DEF)
> -#define IF_ADDR_LOCK_DESTROY(if) mtx_destroy(&(if)->if_addr_mtx)
> -#define IF_ADDR_WLOCK(if) mtx_lock(&(if)->if_addr_mtx)
> -#define IF_ADDR_WUNLOCK(if) mtx_unlock(&(if)->if_addr_mtx)
> -#define IF_ADDR_RLOCK(if) mtx_lock(&(if)->if_addr_mtx)
> -#define IF_ADDR_RUNLOCK(if) mtx_unlock(&(if)->if_addr_mtx)
> -#define IF_ADDR_LOCK_ASSERT(if) mtx_assert(&(if)->if_addr_mtx, MA_OWNED)
> -#define IF_ADDR_WLOCK_ASSERT(if) mtx_assert(&(if)->if_addr_mtx, MA_OWNED)
> +#define IF_ADDR_LOCK_INIT(if) rw_init(&(if)->if_addr_lock, "if_addr_lock")
> +#define IF_ADDR_LOCK_DESTROY(if) rw_destroy(&(if)->if_addr_lock)
> +#define IF_ADDR_WLOCK(if) rw_wlock(&(if)->if_addr_lock)
> +#define IF_ADDR_WUNLOCK(if) rw_wunlock(&(if)->if_addr_lock)
> +#define IF_ADDR_RLOCK(if) rw_rlock(&(if)->if_addr_lock)
> +#define IF_ADDR_RUNLOCK(if) rw_runlock(&(if)->if_addr_lock)
> +#define IF_ADDR_LOCK_ASSERT(if) rw_assert(&(if)->if_addr_lock, RA_LOCKED)
> +#define IF_ADDR_WLOCK_ASSERT(if) rw_assert(&(if)->if_addr_lock, RA_WLOCKED)
> /* XXX: Compat. */
> #define IF_ADDR_LOCK(if) IF_ADDR_WLOCK(if)
> #define IF_ADDR_UNLOCK(if) IF_ADDR_WUNLOCK(if)
>
> --
> John Baldwin
--
Bjoern A. Zeeb You have to have visions!
It does not matter how good you are. It matters what good you do!
More information about the freebsd-net
mailing list