From owner-p4-projects@FreeBSD.ORG Sat Sep 6 21:47:43 2003 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id C675516A4C1; Sat, 6 Sep 2003 21:47:42 -0700 (PDT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8799E16A4BF for ; Sat, 6 Sep 2003 21:47:42 -0700 (PDT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5C57843FF3 for ; Sat, 6 Sep 2003 21:47:41 -0700 (PDT) (envelope-from sam@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.6/8.12.6) with ESMTP id h874lf0U011111 for ; Sat, 6 Sep 2003 21:47:41 -0700 (PDT) (envelope-from sam@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.6/8.12.6/Submit) id h874le8V011108 for perforce@freebsd.org; Sat, 6 Sep 2003 21:47:40 -0700 (PDT) Date: Sat, 6 Sep 2003 21:47:40 -0700 (PDT) Message-Id: <200309070447.h874le8V011108@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to sam@freebsd.org using -f From: Sam Leffler To: Perforce Change Reviews Subject: PERFORCE change 37704 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Sep 2003 04:47:43 -0000 http://perforce.freebsd.org/chv.cgi?CH=37704 Change 37704 by sam@sam_ebb on 2003/09/06 21:46:49 minor cleanups to make locks less mutex-specific Affected files ... .. //depot/projects/netperf/sys/net/bridge.c#6 edit .. //depot/projects/netperf/sys/net/if.c#3 edit .. //depot/projects/netperf/sys/net/if_disc.c#3 edit .. //depot/projects/netperf/sys/net/if_faith.c#3 edit .. //depot/projects/netperf/sys/net/if_loop.c#4 edit .. //depot/projects/netperf/sys/net/if_stf.c#3 edit .. //depot/projects/netperf/sys/net/route.c#9 edit .. //depot/projects/netperf/sys/net/route.h#4 edit .. //depot/projects/netperf/sys/netinet/if_ether.c#6 edit .. //depot/projects/netperf/sys/netinet/in_rmx.c#5 edit .. //depot/projects/netperf/sys/netinet/ip_dummynet.c#7 edit .. //depot/projects/netperf/sys/netinet/ip_fw2.c#6 edit .. //depot/projects/netperf/sys/netinet6/in6_rmx.c#5 edit .. //depot/projects/netperf/sys/netinet6/nd6.c#4 edit Differences ... ==== //depot/projects/netperf/sys/net/bridge.c#6 (text+ko) ==== @@ -166,9 +166,11 @@ static struct cluster_softc *clusters; static struct mtx bdg_mtx; -#define BDG_LOCK() mtx_lock(&bdg_mtx); -#define BDG_UNLOCK() mtx_unlock(&bdg_mtx); -#define BDG_LOCK_ASSERT(_what) mtx_assert(&bdg_mtx, _what); +#define BDG_LOCK_INIT() mtx_init(&bdg_mtx, "bridge", NULL, MTX_DEF) +#define BDG_LOCK_DESTROY() mtx_destroy(&bdg_mtx) +#define BDG_LOCK() mtx_lock(&bdg_mtx) +#define BDG_UNLOCK() mtx_unlock(&bdg_mtx) +#define BDG_LOCK_ASSERT() mtx_assert(&bdg_mtx, MA_OWNED) #define BDG_MUTED(ifp) (ifp2sc[ifp->if_index].flags & IFF_MUTE) #define BDG_MUTE(ifp) ifp2sc[ifp->if_index].flags |= IFF_MUTE @@ -298,7 +300,7 @@ struct cluster_softc *c = NULL; int i; - BDG_LOCK_ASSERT(MA_OWNED); + BDG_LOCK_ASSERT(); for (i = 0; i < n_clusters ; i++) if (clusters[i].cluster_id == cluster_id) @@ -369,7 +371,7 @@ struct ifnet *ifp ; int i; - BDG_LOCK_ASSERT(MA_OWNED); + BDG_LOCK_ASSERT(); DPRINTF(("%s: n_clusters %d\n", __func__, n_clusters)); @@ -413,7 +415,7 @@ { struct ifnet *ifp ; - BDG_LOCK_ASSERT(MA_OWNED); + BDG_LOCK_ASSERT(); IFNET_RLOCK(); TAILQ_FOREACH(ifp, &ifnet, if_link) { @@ -452,7 +454,7 @@ static void reconfigure_bridge_locked(void) { - BDG_LOCK_ASSERT(MA_OWNED); + BDG_LOCK_ASSERT(); bridge_off(); if (do_bridge) { @@ -490,7 +492,7 @@ int l, cluster; static const char *sep = ", \t"; - BDG_LOCK_ASSERT(MA_OWNED); + BDG_LOCK_ASSERT(); for (p = bridge_cfg; *p ; p++) { struct ifnet *ifp; @@ -705,7 +707,7 @@ { bdg_hash_table *bt; /* pointer to entry in hash table */ - BDG_LOCK_ASSERT(MA_OWNED); + BDG_LOCK_ASSERT(); if (ETHER_IS_MULTICAST(eh->ether_dhost)) return IS_ETHER_BROADCAST(eh->ether_dhost) ? BDG_BCAST : BDG_MCAST; @@ -1192,7 +1194,7 @@ if (ifp2sc == NULL) return ENOMEM; - mtx_init(&bdg_mtx, "bridge", NULL, MTX_DEF); + BDG_LOCK_INIT(); n_clusters = 0; clusters = NULL; @@ -1228,7 +1230,7 @@ free(ifp2sc, M_IFADDR); ifp2sc = NULL; } - mtx_destroy(&bdg_mtx); + BDG_LOCK_DESTROY(); } #endif /* KLD_MODULE */ ==== //depot/projects/netperf/sys/net/if.c#3 (text+ko) ==== @@ -1052,7 +1052,7 @@ struct sockaddr *dst; struct ifnet *ifp; - RT_LOCK_ASSERT(rt, MA_OWNED); + RT_LOCK_ASSERT(rt); if (cmd != RTM_ADD || ((ifa = rt->rt_ifa) == 0) || ((ifp = ifa->ifa_ifp) == 0) || ((dst = rt_key(rt)) == 0)) ==== //depot/projects/netperf/sys/net/if_disc.c#3 (text+ko) ==== @@ -194,7 +194,7 @@ static void discrtrequest(int cmd, struct rtentry *rt, struct rt_addrinfo *info) { - RT_LOCK_ASSERT(rt, MA_OWNED); + RT_LOCK_ASSERT(rt); if (rt) rt->rt_rmx.rmx_mtu = DSMTU; ==== //depot/projects/netperf/sys/net/if_faith.c#3 (text+ko) ==== @@ -270,7 +270,7 @@ struct rtentry *rt; struct rt_addrinfo *info; { - RT_LOCK_ASSERT(rt, MA_OWNED); + RT_LOCK_ASSERT(rt); if (rt) { rt->rt_rmx.rmx_mtu = rt->rt_ifp->if_mtu; /* for ISO */ ==== //depot/projects/netperf/sys/net/if_loop.c#4 (text+ko) ==== @@ -355,7 +355,7 @@ struct rtentry *rt; struct rt_addrinfo *info; { - RT_LOCK_ASSERT(rt, MA_OWNED); + RT_LOCK_ASSERT(rt); if (rt) { rt->rt_rmx.rmx_mtu = rt->rt_ifp->if_mtu; /* for ISO */ ==== //depot/projects/netperf/sys/net/if_stf.c#3 (text+ko) ==== @@ -718,7 +718,7 @@ struct rtentry *rt; struct rt_addrinfo *info; { - RT_LOCK_ASSERT(rt, MA_OWNED); + RT_LOCK_ASSERT(rt); if (rt) rt->rt_rmx.rmx_mtu = IPV6_MMTU; ==== //depot/projects/netperf/sys/net/route.c#9 (text+ko) ==== @@ -204,7 +204,7 @@ } } if (newrt) - RT_LOCK_ASSERT(newrt, MA_OWNED); + RT_LOCK_ASSERT(newrt); return (newrt); } @@ -223,7 +223,7 @@ if (rt == 0 || rnh == 0) panic("rtfree"); - RT_LOCK_ASSERT(rt, MA_OWNED); + RT_LOCK_ASSERT(rt); /* * decrement the reference count by one and if it reaches 0, @@ -920,7 +920,7 @@ caddr_t new, old; int dlen = ROUNDUP(dst->sa_len), glen = ROUNDUP(gate->sa_len); - RT_LOCK_ASSERT(rt, MA_OWNED); + RT_LOCK_ASSERT(rt); /* * A host route with the destination equal to the gateway ==== //depot/projects/netperf/sys/net/route.h#4 (text+ko) ==== @@ -271,7 +271,7 @@ #define RT_LOCK(_rt) mtx_lock(&(_rt)->rt_mtx) #define RT_UNLOCK(_rt) mtx_unlock(&(_rt)->rt_mtx) #define RT_LOCK_DESTROY(_rt) mtx_destroy(&(_rt)->rt_mtx) -#define RT_LOCK_ASSERT(_rt, _what) mtx_assert(&(_rt)->rt_mtx, _what) +#define RT_LOCK_ASSERT(_rt) mtx_assert(&(_rt)->rt_mtx, MA_OWNED) #define RTFREE_LOCKED(_rt) do { \ if ((_rt)->rt_refcnt <= 1) \ ==== //depot/projects/netperf/sys/netinet/if_ether.c#6 (text+ko) ==== @@ -170,7 +170,7 @@ register struct llinfo_arp *la; static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK}; - RT_LOCK_ASSERT(rt, MA_OWNED); + RT_LOCK_ASSERT(rt); if (!arpinit_done) { arpinit_done = 1; ==== //depot/projects/netperf/sys/netinet/in_rmx.c#5 (text+ko) ==== @@ -195,7 +195,7 @@ { struct rtentry *rt = (struct rtentry *)rn; - RT_LOCK_ASSERT(rt, MA_OWNED); + RT_LOCK_ASSERT(rt); if (!(rt->rt_flags & RTF_UP)) return; /* prophylactic measures */ ==== //depot/projects/netperf/sys/netinet/ip_dummynet.c#7 (text+ko) ==== @@ -165,9 +165,12 @@ #endif static struct mtx dummynet_mtx; -#define DUMMYNET_LOCK() mtx_lock(&dummynet_mtx); -#define DUMMYNET_UNLOCK() mtx_unlock(&dummynet_mtx); -#define DUMMYNET_LOCK_ASSERT(_what) mtx_assert(&dummynet_mtx, _what); +#define DUMMYNET_LOCK_INIT() \ + mtx_init(&dummynet_mtx, "dummynet", NULL, MTX_DEF) +#define DUMMYNET_LOCK_DESTROY() mtx_destroy(&dummynet_mtx) +#define DUMMYNET_LOCK() mtx_lock(&dummynet_mtx) +#define DUMMYNET_UNLOCK() mtx_unlock(&dummynet_mtx) +#define DUMMYNET_LOCK_ASSERT() mtx_assert(&dummynet_mtx, MA_OWNED) static int config_pipe(struct dn_pipe *p); static int ip_dn_ctl(struct sockopt *sopt); @@ -542,7 +545,7 @@ struct dn_pipe *p = q->fs->pipe ; int p_was_empty ; - DUMMYNET_LOCK_ASSERT(MA_OWNED); + DUMMYNET_LOCK_ASSERT(); if (p == NULL) { printf("dummynet: ready_event- pipe is gone\n"); @@ -608,7 +611,7 @@ struct dn_heap *sch = &(p->scheduler_heap); struct dn_heap *neh = &(p->not_eligible_heap) ; - DUMMYNET_LOCK_ASSERT(MA_OWNED); + DUMMYNET_LOCK_ASSERT(); if (p->if_name[0] == 0) /* tx clock is simulated */ p->numbytes += ( curr_time - p->sched_time ) * p->bandwidth; @@ -1310,7 +1313,7 @@ struct dn_flow_queue *q, *qn ; int i ; - DUMMYNET_LOCK_ASSERT(MA_OWNED); + DUMMYNET_LOCK_ASSERT(); for (i = 0 ; i <= fs->rq_size ; i++ ) { for (q = fs->rq[i] ; q ; q = qn ) { @@ -1710,7 +1713,7 @@ struct dn_pipe *p; struct dn_pkt *pkt; - DUMMYNET_LOCK_ASSERT(MA_OWNED); + DUMMYNET_LOCK_ASSERT(); heap_free(&ready_heap); heap_free(&wfq_ready_heap); @@ -1817,7 +1820,7 @@ int i, copied = 0 ; struct dn_flow_queue *q, *qp = (struct dn_flow_queue *)bp; - DUMMYNET_LOCK_ASSERT(MA_OWNED); + DUMMYNET_LOCK_ASSERT(); for (i = 0 ; i <= set->rq_size ; i++) for (q = set->rq[i] ; q ; q = q->next, qp++ ) { @@ -1968,7 +1971,7 @@ if (bootverbose) printf("DUMMYNET initialized (011031)\n"); - mtx_init(&dummynet_mtx, "dummynet", NULL, MTX_DEF); + DUMMYNET_LOCK_INIT(); all_pipes = NULL ; all_flow_sets = NULL ; @@ -2000,7 +2003,7 @@ callout_stop(&dn_timeout); dummynet_flush(); - mtx_destroy(&dummynet_mtx); + DUMMYNET_LOCK_DESTROY(); } #endif /* KLD_MODULE */ ==== //depot/projects/netperf/sys/netinet/ip_fw2.c#6 (text+ko) ==== @@ -109,9 +109,12 @@ struct ip_fw *rules; /* list of rules */ struct mtx mtx; /* lock guarding rule list */ }; +#define IPFW_LOCK_INIT(_chain) \ + mtx_init(&(_chain)->mtx, "IPFW static rules", NULL, MTX_DEF) +#define IPFW_LOCK_DESTROY(_chain) mtx_destroy(&(_chain)->mtx) #define IPFW_LOCK(_chain) mtx_lock(&(_chain)->mtx) #define IPFW_UNLOCK(_chain) mtx_unlock(&(_chain)->mtx) -#define IPFW_LOCK_ASSERT(_chain, _what) mtx_assert(&(_chain)->mtx, _what) +#define IPFW_LOCK_ASSERT(_chain) mtx_assert(&(_chain)->mtx, MA_OWNED) /* * list of rules for layer 3 @@ -183,9 +186,12 @@ static u_int32_t curr_dyn_buckets = 256; /* must be power of 2 */ static struct mtx ipfw_dyn_mtx; /* mutex guarding dynamic rules */ +#define IPFW_DYN_LOCK_INIT() \ + mtx_init(&ipfw_dyn_mtx, "IPFW dynamic rules", NULL, MTX_DEF) +#define IPFW_DYN_LOCK_DESTROY() mtx_destroy(&ipfw_dyn_mtx) #define IPFW_DYN_LOCK() mtx_lock(&ipfw_dyn_mtx) #define IPFW_DYN_UNLOCK() mtx_unlock(&ipfw_dyn_mtx) -#define IPFW_DYN_LOCK_ASSERT(_what) mtx_assert(&ipfw_dyn_mtx, _what) +#define IPFW_DYN_LOCK_ASSERT() mtx_assert(&ipfw_dyn_mtx, MA_OWNED) /* * Timeouts for various events in handing dynamic rules. @@ -718,7 +724,7 @@ ipfw_dyn_rule *prev, *q; int i, pass = 0, max_pass = 0; - IPFW_DYN_LOCK_ASSERT(MA_OWNED); + IPFW_DYN_LOCK_ASSERT(); if (ipfw_dyn_v == NULL || dyn_count == 0) return; @@ -790,7 +796,7 @@ int i, dir = MATCH_NONE; ipfw_dyn_rule *prev, *q=NULL; - IPFW_DYN_LOCK_ASSERT(MA_OWNED); + IPFW_DYN_LOCK_ASSERT(); if (ipfw_dyn_v == NULL) goto done; /* not found */ @@ -913,7 +919,7 @@ static void realloc_dynamic_table(void) { - IPFW_DYN_LOCK_ASSERT(MA_OWNED); + IPFW_DYN_LOCK_ASSERT(); /* * Try reallocation, make sure we have a power of 2 and do @@ -955,7 +961,7 @@ ipfw_dyn_rule *r; int i; - IPFW_DYN_LOCK_ASSERT(MA_OWNED); + IPFW_DYN_LOCK_ASSERT(); if (ipfw_dyn_v == NULL || (dyn_count == 0 && dyn_buckets != curr_dyn_buckets)) { @@ -1010,7 +1016,7 @@ ipfw_dyn_rule *q; int i; - IPFW_DYN_LOCK_ASSERT(MA_OWNED); + IPFW_DYN_LOCK_ASSERT(); if (ipfw_dyn_v) { i = hash_packet( pkt ); @@ -2087,7 +2093,7 @@ { struct ip_fw *rule; - IPFW_LOCK_ASSERT(chain, MA_OWNED); + IPFW_LOCK_ASSERT(chain); for (rule = chain->rules; rule; rule = rule->next) rule->next_rule = NULL; @@ -2216,7 +2222,7 @@ struct ip_fw *n; int l = RULESIZE(rule); - IPFW_LOCK_ASSERT(chain, MA_OWNED); + IPFW_LOCK_ASSERT(chain); n = rule->next; IPFW_DYN_LOCK(); @@ -2244,7 +2250,7 @@ { struct ip_fw *prev, *rule; - IPFW_LOCK_ASSERT(chain, MA_OWNED); + IPFW_LOCK_ASSERT(chain); flush_rule_ptrs(chain); /* more efficient to do outside the loop */ for (prev = NULL, rule = chain->rules; rule ; ) @@ -2860,8 +2866,8 @@ int error; layer3_chain.rules = NULL; - mtx_init(&layer3_chain.mtx, "IPFW static rules", NULL, MTX_DEF); - mtx_init(&ipfw_dyn_mtx, "IPFW dynamic rules", NULL, MTX_DEF); + IPFW_LOCK_INIT(&layer3_chain); + IPFW_DYN_LOCK_INIT(); callout_init(&ipfw_timeout, CALLOUT_MPSAFE); bzero(&default_rule, sizeof default_rule); @@ -2882,8 +2888,8 @@ if (error != 0) { printf("ipfw2: error %u initializing default rule " "(support disabled)\n", error); - mtx_destroy(&ipfw_dyn_mtx); - mtx_destroy(&layer3_chain.mtx); + IPFW_DYN_LOCK_DESTROY(); + IPFW_LOCK_DESTROY(&layer3_chain); return (error); } @@ -2944,10 +2950,8 @@ ip_fw_chk_ptr = NULL; ip_fw_ctl_ptr = NULL; free_chain(&layer3_chain, 1 /* kill default rule */); - IPFW_DYN_UNLOCK(); - IPFW_UNLOCK(&layer3_chain); - mtx_destroy(&ipfw_dyn_mtx); - mtx_destroy(&layer3_chain.mtx); + IPFW_DYN_LOCK_DESTROY(); + IPFW_LOCK_DESTROY(&layer3_chain); printf("IP firewall unloaded\n"); err = 0; #endif ==== //depot/projects/netperf/sys/netinet6/in6_rmx.c#5 (text+ko) ==== @@ -255,7 +255,7 @@ { struct rtentry *rt = (struct rtentry *)rn; - RT_LOCK_ASSERT(rt, MA_OWNED); + RT_LOCK_ASSERT(rt); if (!(rt->rt_flags & RTF_UP)) return; /* prophylactic measures */ ==== //depot/projects/netperf/sys/netinet6/nd6.c#4 (text+ko) ==== @@ -1100,7 +1100,7 @@ struct ifnet *ifp = rt->rt_ifp; struct ifaddr *ifa; - RT_LOCK_ASSERT(rt, MA_OWNED); + RT_LOCK_ASSERT(rt); if ((rt->rt_flags & RTF_GATEWAY)) return;