Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net Simplify bridge(4)
details: https://anonhg.NetBSD.org/src/rev/38490e70444e
branches: trunk
changeset: 343569:38490e70444e
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Mon Feb 15 01:11:41 2016 +0000
description:
Simplify bridge(4)
Thanks to introducing softint-based if_input, the entire bridge code now
never run in hardware interrupt context. So we can simplify the code.
- Remove spin mutexes
- They were needed because some code of bridge could run in
hardware interrupt context
- We now need only an adaptive mutex for each shared object
(a member list and a forwarding table)
- Remove pktqueue
- bridge_input is already in softint, using another softint
(for bridge_forward) is useless
- Packet distribution should be down at device drivers
diffstat:
sys/net/bridgestp.c | 42 ++--
sys/net/if_bridge.c | 408 +++++++++++++++---------------------------------
sys/net/if_bridgevar.h | 40 +----
3 files changed, 159 insertions(+), 331 deletions(-)
diffs (truncated from 906 to 300 lines):
diff -r 6bc27342a9f0 -r 38490e70444e sys/net/bridgestp.c
--- a/sys/net/bridgestp.c Sun Feb 14 23:47:57 2016 +0000
+++ b/sys/net/bridgestp.c Mon Feb 15 01:11:41 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bridgestp.c,v 1.18 2014/12/31 17:36:24 ozaki-r Exp $ */
+/* $NetBSD: bridgestp.c,v 1.19 2016/02/15 01:11:41 ozaki-r Exp $ */
/*
* Copyright (c) 2000 Jason L. Wright (jason%thought.net@localhost)
@@ -40,7 +40,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bridgestp.c,v 1.18 2014/12/31 17:36:24 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bridgestp.c,v 1.19 2016/02/15 01:11:41 ozaki-r Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -221,7 +221,7 @@
struct bstp_cbpdu bpdu;
int s;
- KASSERT(BRIDGE_INTR_LOCKED(sc));
+ KASSERT(BRIDGE_LOCKED(sc));
ifp = bif->bif_ifp;
@@ -276,11 +276,11 @@
memcpy(mtod(m, char *) + sizeof(*eh), &bpdu, sizeof(bpdu));
- BRIDGE_INTR_UNLOCK(sc);
+ BRIDGE_UNLOCK(sc);
s = splnet();
bridge_enqueue(sc, ifp, m, 0);
splx(s);
- BRIDGE_INTR_LOCK(sc);
+ BRIDGE_LOCK(sc);
}
static int
@@ -367,7 +367,7 @@
struct mbuf *m;
int s;
- KASSERT(BRIDGE_INTR_LOCKED(sc));
+ KASSERT(BRIDGE_LOCKED(sc));
KASSERT(bif != NULL);
ifp = bif->bif_ifp;
@@ -396,11 +396,11 @@
memcpy(mtod(m, char *) + sizeof(*eh), &bpdu, sizeof(bpdu));
- BRIDGE_INTR_UNLOCK(sc);
+ BRIDGE_UNLOCK(sc);
s = splnet();
bridge_enqueue(sc, ifp, m, 0);
splx(s);
- BRIDGE_INTR_LOCK(sc);
+ BRIDGE_LOCK(sc);
}
static void
@@ -634,9 +634,9 @@
case BSTP_MSGTYPE_TCN:
tu.tu_message_type = tpdu.tbu_bpdutype;
- BRIDGE_INTR_LOCK(sc);
+ BRIDGE_LOCK(sc);
bstp_received_tcn_bpdu(sc, bif, &tu);
- BRIDGE_INTR_UNLOCK(sc);
+ BRIDGE_UNLOCK(sc);
break;
case BSTP_MSGTYPE_CFG:
@@ -675,9 +675,9 @@
cu.cu_topology_change =
(cpdu.cbu_flags & BSTP_FLAG_TC) ? 1 : 0;
- BRIDGE_INTR_LOCK(sc);
+ BRIDGE_LOCK(sc);
bstp_received_config_bpdu(sc, bif, &cu);
- BRIDGE_INTR_UNLOCK(sc);
+ BRIDGE_UNLOCK(sc);
break;
default:
@@ -826,7 +826,7 @@
mif = NULL;
- BRIDGE_INTR_LOCK(sc);
+ BRIDGE_LOCK(sc);
LIST_FOREACH(bif, &sc->sc_iflist, bif_next) {
if ((bif->bif_flags & IFBIF_STP) == 0)
@@ -848,7 +848,7 @@
}
if (mif == NULL) {
- BRIDGE_INTR_UNLOCK(sc);
+ BRIDGE_UNLOCK(sc);
bstp_stop(sc);
return;
}
@@ -862,7 +862,7 @@
(((uint64_t)(uint8_t)CLLADDR(mif->bif_ifp->if_sadl)[4]) << 8) |
(((uint64_t)(uint8_t)CLLADDR(mif->bif_ifp->if_sadl)[5]) << 0);
- BRIDGE_INTR_UNLOCK(sc);
+ BRIDGE_UNLOCK(sc);
sc->sc_designated_root = sc->sc_bridge_id;
sc->sc_root_path_cost = 0;
@@ -880,7 +880,7 @@
callout_reset(&sc->sc_bstpcallout, hz,
bstp_tick, sc);
- BRIDGE_INTR_LOCK(sc);
+ BRIDGE_LOCK(sc);
LIST_FOREACH(bif, &sc->sc_iflist, bif_next) {
if (bif->bif_flags & IFBIF_STP)
@@ -893,7 +893,7 @@
bstp_config_bpdu_generation(sc);
bstp_timer_start(&sc->sc_hello_timer, 0);
- BRIDGE_INTR_UNLOCK(sc);
+ BRIDGE_UNLOCK(sc);
}
void
@@ -901,14 +901,14 @@
{
struct bridge_iflist *bif;
- BRIDGE_INTR_LOCK(sc);
+ BRIDGE_LOCK(sc);
LIST_FOREACH(bif, &sc->sc_iflist, bif_next) {
bstp_set_port_state(bif, BSTP_IFSTATE_DISABLED);
bstp_timer_stop(&bif->bif_hold_timer);
bstp_timer_stop(&bif->bif_message_age_timer);
bstp_timer_stop(&bif->bif_forward_delay_timer);
}
- BRIDGE_INTR_UNLOCK(sc);
+ BRIDGE_UNLOCK(sc);
callout_stop(&sc->sc_bstpcallout);
@@ -1065,7 +1065,7 @@
int s;
s = splnet();
- BRIDGE_INTR_LOCK(sc);
+ BRIDGE_LOCK(sc);
LIST_FOREACH(bif, &sc->sc_iflist, bif_next) {
if ((bif->bif_flags & IFBIF_STP) == 0)
@@ -1113,7 +1113,7 @@
if (sc->sc_if.if_flags & IFF_RUNNING)
callout_reset(&sc->sc_bstpcallout, hz, bstp_tick, sc);
- BRIDGE_INTR_UNLOCK(sc);
+ BRIDGE_UNLOCK(sc);
splx(s);
}
diff -r 6bc27342a9f0 -r 38490e70444e sys/net/if_bridge.c
--- a/sys/net/if_bridge.c Sun Feb 14 23:47:57 2016 +0000
+++ b/sys/net/if_bridge.c Mon Feb 15 01:11:41 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_bridge.c,v 1.107 2016/02/10 06:30:23 ozaki-r Exp $ */
+/* $NetBSD: if_bridge.c,v 1.108 2016/02/15 01:11:41 ozaki-r Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@@ -80,7 +80,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.107 2016/02/10 06:30:23 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.108 2016/02/15 01:11:41 ozaki-r Exp $");
#ifdef _KERNEL_OPT
#include "opt_bridge_ipf.h"
@@ -108,7 +108,6 @@
#include <net/if_dl.h>
#include <net/if_types.h>
#include <net/if_llc.h>
-#include <net/pktqueue.h>
#include <net/if_ether.h>
#include <net/if_bridgevar.h>
@@ -181,10 +180,6 @@
#define BRIDGE_RTABLE_PRUNE_PERIOD (5 * 60)
#endif
-#define BRIDGE_RT_INTR_LOCK(_sc) mutex_enter((_sc)->sc_rtlist_intr_lock)
-#define BRIDGE_RT_INTR_UNLOCK(_sc) mutex_exit((_sc)->sc_rtlist_intr_lock)
-#define BRIDGE_RT_INTR_LOCKED(_sc) mutex_owned((_sc)->sc_rtlist_intr_lock)
-
#define BRIDGE_RT_LOCK(_sc) if ((_sc)->sc_rtlist_lock) \
mutex_enter((_sc)->sc_rtlist_lock)
#define BRIDGE_RT_UNLOCK(_sc) if ((_sc)->sc_rtlist_lock) \
@@ -197,18 +192,8 @@
pserialize_perform((_sc)->sc_rtlist_psz);
#ifdef BRIDGE_MPSAFE
-#define BRIDGE_RT_RENTER(__s) do { \
- if (!cpu_intr_p()) \
- __s = pserialize_read_enter(); \
- else \
- __s = splhigh(); \
- } while (0)
-#define BRIDGE_RT_REXIT(__s) do { \
- if (!cpu_intr_p()) \
- pserialize_read_exit(__s); \
- else \
- splx(__s); \
- } while (0)
+#define BRIDGE_RT_RENTER(__s) do { __s = pserialize_read_enter(); } while (0)
+#define BRIDGE_RT_REXIT(__s) do { pserialize_read_exit(__s); } while (0)
#else /* BRIDGE_MPSAFE */
#define BRIDGE_RT_RENTER(__s) do { __s = 0; } while (0)
#define BRIDGE_RT_REXIT(__s) do { (void)__s; } while (0)
@@ -227,7 +212,7 @@
static void bridge_start(struct ifnet *);
static void bridge_input(struct ifnet *, struct mbuf *);
-static void bridge_forward(void *);
+static void bridge_forward(struct bridge_softc *, struct mbuf *);
static void bridge_timer(void *);
@@ -297,9 +282,6 @@
# endif /* INET6 */
#endif /* BRIDGE_IPF */
-static void bridge_sysctl_fwdq_setup(struct sysctllog **clog,
- struct bridge_softc *sc);
-
struct bridge_control {
int (*bc_func)(struct bridge_softc *, void *);
int bc_argsize;
@@ -424,11 +406,9 @@
LIST_INIT(&sc->sc_iflist);
#ifdef BRIDGE_MPSAFE
- sc->sc_iflist_intr_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_NET);
sc->sc_iflist_psz = pserialize_create();
sc->sc_iflist_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_SOFTNET);
#else
- sc->sc_iflist_intr_lock = NULL;
sc->sc_iflist_psz = NULL;
sc->sc_iflist_lock = NULL;
#endif
@@ -447,11 +427,6 @@
ifp->if_dlt = DLT_EN10MB;
ifp->if_hdrlen = ETHER_HDR_LEN;
- sc->sc_fwd_pktq = pktq_create(IFQ_MAXLEN, bridge_forward, sc);
- KASSERT(sc->sc_fwd_pktq != NULL);
-
- bridge_sysctl_fwdq_setup(&ifp->if_sysctl_log, sc);
-
if_initialize(ifp);
if_register(ifp);
@@ -476,9 +451,6 @@
struct bridge_iflist *bif;
int s;
- /* Must be called during IFF_RUNNING, i.e., before bridge_stop */
- pktq_barrier(sc->sc_fwd_pktq);
-
s = splnet();
bridge_stop(ifp, 1);
@@ -496,16 +468,10 @@
if_detach(ifp);
- /* Should be called after if_detach for safe */
- pktq_flush(sc->sc_fwd_pktq);
- pktq_destroy(sc->sc_fwd_pktq);
-
/* Tear down the routing table. */
bridge_rtable_fini(sc);
cv_destroy(&sc->sc_iflist_cv);
- if (sc->sc_iflist_intr_lock)
- mutex_obj_free(sc->sc_iflist_intr_lock);
if (sc->sc_iflist_psz)
pserialize_destroy(sc->sc_iflist_psz);
@@ -519,92 +485,6 @@
return (0);
}
Home |
Main Index |
Thread Index |
Old Index