Date: Mon, 29 Mar 2004 10:57:16 -0800 (PST) From: Robert Watson <rwatson@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 49903 for review Message-ID: <200403291857.i2TIvGTt032129@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=49903 Change 49903 by rwatson@rwatson_tislabs on 2004/03/29 10:57:14 Integrate netperf_socket: - Adopt conditional CALLOUT_MPSAFE initialization in UNIX domain sockets looped back from rwatson_netperf. - Conditionally assert Giant in UNIX domain socket callouts (looped back from rwatson_netperf). - Loop back structural/style changes in socket kqueue functions. - Loop back if_tun global mutex locking from rwatson_netperf. Affected files ... .. //depot/projects/netperf_socket/sys/kern/uipc_domain.c#4 integrate .. //depot/projects/netperf_socket/sys/kern/uipc_socket.c#7 integrate .. //depot/projects/netperf_socket/sys/net/if_tun.c#6 integrate Differences ... ==== //depot/projects/netperf_socket/sys/kern/uipc_domain.c#4 (text+ko) ==== @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: src/sys/kern/uipc_domain.c,v 1.34 2003/09/02 20:59:23 sam Exp $"); +__FBSDID("$FreeBSD: src/sys/kern/uipc_domain.c,v 1.35 2004/03/29 17:00:05 rwatson Exp $"); #include <sys/param.h> #include <sys/socket.h> @@ -134,8 +134,13 @@ if (max_linkhdr < 16) /* XXX */ max_linkhdr = 16; - callout_init(&pffast_callout, CALLOUT_MPSAFE); - callout_init(&pfslow_callout, CALLOUT_MPSAFE); + if (debug_mpsafenet) { + callout_init(&pffast_callout, CALLOUT_MPSAFE); + callout_init(&pfslow_callout, CALLOUT_MPSAFE); + } else { + callout_init(&pffast_callout, 0); + callout_init(&pfslow_callout, 0); + } callout_reset(&pffast_callout, 1, pffasttimo, NULL); callout_reset(&pfslow_callout, 1, pfslowtimo, NULL); @@ -236,6 +241,8 @@ register struct domain *dp; register struct protosw *pr; + NET_ASSERT_GIANT(); + for (dp = domains; dp; dp = dp->dom_next) for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) if (pr->pr_slowtimo) @@ -250,6 +257,8 @@ register struct domain *dp; register struct protosw *pr; + NET_ASSERT_GIANT(); + for (dp = domains; dp; dp = dp->dom_next) for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) if (pr->pr_fasttimo) ==== //depot/projects/netperf_socket/sys/kern/uipc_socket.c#7 (text+ko) ==== @@ -34,7 +34,7 @@ */ #include <sys/cdefs.h> -__FBSDID("$FreeBSD: src/sys/kern/uipc_socket.c,v 1.165 2004/03/01 03:14:21 rwatson Exp $"); +__FBSDID("$FreeBSD: src/sys/kern/uipc_socket.c,v 1.167 2004/03/29 18:06:15 rwatson Exp $"); #include "opt_inet.h" #include "opt_mac.h" @@ -1880,13 +1880,12 @@ kn->kn_flags |= EV_EOF; kn->kn_fflags = so->so_error; result = 1; - } else if (so->so_error) { /* temporary udp error */ + } else if (so->so_error) /* temporary udp error */ result = 1; - } else if (kn->kn_sfflags & NOTE_LOWAT) { + else if (kn->kn_sfflags & NOTE_LOWAT) result = (kn->kn_data >= kn->kn_sdata); - } else { + else result = (so->so_rcv.sb_cc >= so->so_rcv.sb_lowat); - } SOCKBUF_UNLOCK(&so->so_rcv); return (result); } @@ -1916,16 +1915,15 @@ kn->kn_flags |= EV_EOF; kn->kn_fflags = so->so_error; result = 1; - } else if (so->so_error) { /* temporary udp error */ + } else if (so->so_error) /* temporary udp error */ result = 1; - } else if (((so->so_state & SS_ISCONNECTED) == 0) && - (so->so_proto->pr_flags & PR_CONNREQUIRED)) { + else if (((so->so_state & SS_ISCONNECTED) == 0) && + (so->so_proto->pr_flags & PR_CONNREQUIRED)) result = 0; - } else if (kn->kn_sfflags & NOTE_LOWAT) { + else if (kn->kn_sfflags & NOTE_LOWAT) result = (kn->kn_data >= kn->kn_sdata); - } else { + else result = (kn->kn_data >= so->so_snd.sb_lowat); - } SOCKBUF_UNLOCK(&so->so_snd); return (result); } ==== //depot/projects/netperf_socket/sys/net/if_tun.c#6 (text+ko) ==== @@ -13,7 +13,7 @@ * UCL. This driver is based much more on read/write/poll mode of * operation though. * - * $FreeBSD: src/sys/net/if_tun.c,v 1.137 2004/03/17 01:12:09 rwatson Exp $ + * $FreeBSD: src/sys/net/if_tun.c,v 1.138 2004/03/29 18:42:51 rwatson Exp $ */ #include "opt_atalk.h" @@ -87,6 +87,12 @@ #define TUNDEBUG if (tundebug) if_printf #define TUNNAME "tun" +/* + * All mutable global variables in if_tun are locked using tunmtx, with + * the exception of tundebug, which is used unlocked, and tunclones, + * which is static after setup. + */ +static struct mtx tunmtx; static MALLOC_DEFINE(M_TUN, TUNNAME, "Tunnel Interface"); static int tundebug = 0; static struct clonedevs *tunclones; @@ -147,15 +153,30 @@ } } +static void +tun_destroy(struct tun_softc *tp) +{ + dev_t dev; + + KASSERT((tp->tun_flags & TUN_OPEN) == 0, + ("tununits is out of sync - unit %d", tp->tun_if.if_dunit)); + + dev = tp->tun_dev; + bpfdetach(&tp->tun_if); + if_detach(&tp->tun_if); + destroy_dev(dev); + free(tp, M_TUN); +} + static int tunmodevent(module_t mod, int type, void *data) { static eventhandler_tag tag; struct tun_softc *tp; - dev_t dev; switch (type) { case MOD_LOAD: + mtx_init(&tunmtx, "tunmtx", NULL, MTX_DEF); clone_setup(&tunclones); tag = EVENTHANDLER_REGISTER(dev_clone, tunclone, 0, 1000); if (tag == NULL) @@ -164,19 +185,16 @@ case MOD_UNLOAD: EVENTHANDLER_DEREGISTER(dev_clone, tag); - while (!TAILQ_EMPTY(&tunhead)) { - tp = TAILQ_FIRST(&tunhead); - KASSERT((tp->tun_flags & TUN_OPEN) == 0, - ("tununits is out of sync - unit %d", - tp->tun_if.if_dunit)); + mtx_lock(&tunmtx); + while ((tp = TAILQ_FIRST(&tunhead)) != NULL) { TAILQ_REMOVE(&tunhead, tp, tun_list); - dev = tp->tun_dev; - bpfdetach(&tp->tun_if); - if_detach(&tp->tun_if); - destroy_dev(dev); - free(tp, M_TUN); + mtx_unlock(&tunmtx); + tun_destroy(tp); + mtx_lock(&tunmtx); } + mtx_unlock(&tunmtx); clone_cleanup(&tunclones); + mtx_destroy(&tunmtx); break; } return 0; @@ -215,7 +233,9 @@ MALLOC(sc, struct tun_softc *, sizeof(*sc), M_TUN, M_WAITOK | M_ZERO); sc->tun_flags = TUN_INITED; sc->tun_dev = dev; + mtx_lock(&tunmtx); TAILQ_INSERT_TAIL(&tunhead, sc, tun_list); + mtx_unlock(&tunmtx); ifp = &sc->tun_if; if_initname(ifp, TUNNAME, dev2unit(dev));
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200403291857.i2TIvGTt032129>