PERFORCE change 195044 for review
Takuya ASADA
syuu at FreeBSD.org
Mon Jun 20 18:16:57 UTC 2011
http://p4web.freebsd.org/@@195044?ac=10
Change 195044 by syuu at kikurage on 2011/06/20 18:16:04
rmlock on BPFIF_LOCK looks working now
Affected files ...
.. //depot/projects/soc2011/mq_bpf/src/sys/net/bpf.c#9 edit
.. //depot/projects/soc2011/mq_bpf/src/sys/net/bpf.h#5 edit
.. //depot/projects/soc2011/mq_bpf/src/sys/net/bpfdesc.h#4 edit
Differences ...
==== //depot/projects/soc2011/mq_bpf/src/sys/net/bpf.c#9 (text+ko) ====
@@ -603,12 +603,12 @@
* Finally, point the driver's bpf cookie at the interface so
* it will divert packets to bpf.
*/
- BPFIF_LOCK(bp);
+ BPFIF_WLOCK(bp);
d->bd_bif = bp;
LIST_INSERT_HEAD(&bp->bif_dlist, d, bd_next);
bpf_bpfd_cnt++;
- BPFIF_UNLOCK(bp);
+ BPFIF_WUNLOCK(bp);
EVENTHANDLER_INVOKE(bpf_track, bp->bif_ifp, bp->bif_dlt, 1);
}
@@ -624,7 +624,7 @@
struct ifnet *ifp;
bp = d->bd_bif;
- BPFIF_LOCK(bp);
+ BPFIF_WLOCK(bp);
BPFD_LOCK(d);
ifp = d->bd_bif->bif_ifp;
@@ -636,7 +636,7 @@
bpf_bpfd_cnt--;
d->bd_bif = NULL;
BPFD_UNLOCK(d);
- BPFIF_UNLOCK(bp);
+ BPFIF_WUNLOCK(bp);
EVENTHANDLER_INVOKE(bpf_track, ifp, bp->bif_dlt, 0);
@@ -2249,9 +2249,10 @@
#endif
u_int slen;
int gottime;
+ struct rm_priotracker tracker;
gottime = BPF_TSTAMP_NONE;
- BPFIF_LOCK(bp);
+ BPFIF_RLOCK(bp, &tracker);
LIST_FOREACH(d, &bp->bif_dlist, bd_next) {
if (d->bd_qmask.qm_enabled) {
SDT_PROBE2(bpf, functions, bpf_tap, entry, d, d->bd_qmask.qm_other_mask);
@@ -2286,7 +2287,7 @@
}
BPFD_UNLOCK(d);
}
- BPFIF_UNLOCK(bp);
+ BPFIF_RUNLOCK(bp, &tracker);
}
#define BPF_CHECK_DIRECTION(d, r, i) \
@@ -2303,6 +2304,7 @@
#endif
u_int pktlen, slen;
int gottime;
+ struct rm_priotracker tracker;
/* Skip outgoing duplicate packets. */
if ((m->m_flags & M_PROMISC) != 0 && m->m_pkthdr.rcvif == NULL) {
@@ -2313,7 +2315,7 @@
pktlen = m_length(m, NULL);
gottime = BPF_TSTAMP_NONE;
- BPFIF_LOCK(bp);
+ BPFIF_RLOCK(bp, &tracker);
LIST_FOREACH(d, &bp->bif_dlist, bd_next) {
if (d->bd_qmask.qm_enabled) {
if (!(m->m_flags & M_FLOWID)) {
@@ -2365,7 +2367,7 @@
}
BPFD_UNLOCK(d);
}
- BPFIF_UNLOCK(bp);
+ BPFIF_RUNLOCK(bp, &tracker);
}
/*
@@ -2380,6 +2382,7 @@
struct bpf_d *d;
u_int pktlen, slen;
int gottime;
+ struct rm_priotracker tracker;
/* Skip outgoing duplicate packets. */
if ((m->m_flags & M_PROMISC) != 0 && m->m_pkthdr.rcvif == NULL) {
@@ -2399,7 +2402,7 @@
pktlen += dlen;
gottime = BPF_TSTAMP_NONE;
- BPFIF_LOCK(bp);
+ BPFIF_RLOCK(bp, &tracker);
LIST_FOREACH(d, &bp->bif_dlist, bd_next) {
if (d->bd_qmask.qm_enabled) {
SDT_PROBE3(bpf, functions, bpf_mtap2_rx, entry, d, m->m_pkthdr.rxqid, bp->bif_ifp->if_rxq_num);
@@ -2429,7 +2432,7 @@
}
BPFD_UNLOCK(d);
}
- BPFIF_UNLOCK(bp);
+ BPFIF_RUNLOCK(bp, &tracker);
}
#undef BPF_CHECK_DIRECTION
@@ -2706,7 +2709,7 @@
LIST_INIT(&bp->bif_dlist);
bp->bif_ifp = ifp;
bp->bif_dlt = dlt;
- mtx_init(&bp->bif_mtx, "bpf interface lock", NULL, MTX_DEF);
+ BPFIF_LOCK_INIT(bp, "bpf interface lock");
KASSERT(*driverp == NULL, ("bpfattach2: driverp already initialized"));
*driverp = bp;
@@ -2756,7 +2759,7 @@
BPFD_UNLOCK(d);
}
- mtx_destroy(&bp->bif_mtx);
+ BPFIF_LOCK_DESTROY(bp);
free(bp, M_BPF);
}
@@ -2854,10 +2857,11 @@
{
struct bpf_if *bp;
struct bpf_d *bd;
+ struct rm_priotracker tracker;
mtx_lock(&bpf_mtx);
LIST_FOREACH(bp, &bpf_iflist, bif_next) {
- BPFIF_LOCK(bp);
+ BPFIF_RLOCK(bp, &tracker);
LIST_FOREACH(bd, &bp->bif_dlist, bd_next) {
BPFD_LOCK(bd);
bd->bd_rcount = 0;
@@ -2868,7 +2872,7 @@
bd->bd_zcopy = 0;
BPFD_UNLOCK(bd);
}
- BPFIF_UNLOCK(bp);
+ BPFIF_RUNLOCK(bp, &tracker);
}
mtx_unlock(&bpf_mtx);
}
@@ -2911,6 +2915,7 @@
int index, error;
struct bpf_if *bp;
struct bpf_d *bd;
+ struct rm_priotracker tracker;
/*
* XXX This is not technically correct. It is possible for non
@@ -2949,14 +2954,14 @@
}
index = 0;
LIST_FOREACH(bp, &bpf_iflist, bif_next) {
- BPFIF_LOCK(bp);
+ BPFIF_RLOCK(bp, &tracker);
LIST_FOREACH(bd, &bp->bif_dlist, bd_next) {
xbd = &xbdbuf[index++];
BPFD_LOCK(bd);
bpfstats_fill_xbpf(xbd, bd);
BPFD_UNLOCK(bd);
}
- BPFIF_UNLOCK(bp);
+ BPFIF_RUNLOCK(bp, &tracker);
}
mtx_unlock(&bpf_mtx);
error = SYSCTL_OUT(req, xbdbuf, index * sizeof(*xbd));
==== //depot/projects/soc2011/mq_bpf/src/sys/net/bpf.h#5 (text+ko) ====
@@ -40,6 +40,9 @@
#ifndef _NET_BPF_H_
#define _NET_BPF_H_
+#include <sys/lock.h>
+#include <sys/rmlock.h>
+
/* BSD style release date */
#define BPF_RELEASE 199606
@@ -1114,7 +1117,7 @@
u_int bif_dlt; /* link layer type */
u_int bif_hdrlen; /* length of link header */
struct ifnet *bif_ifp; /* corresponding interface */
- struct mtx bif_mtx; /* mutex for interface */
+ struct rmlock bif_lock; /* rmlock for interface */
};
void bpf_bufheld(struct bpf_d *d);
==== //depot/projects/soc2011/mq_bpf/src/sys/net/bpfdesc.h#4 (text+ko) ====
@@ -152,7 +152,12 @@
u_int64_t bd_spare[4];
};
-#define BPFIF_LOCK(bif) mtx_lock(&(bif)->bif_mtx)
-#define BPFIF_UNLOCK(bif) mtx_unlock(&(bif)->bif_mtx)
+#define BPFIF_LOCK_INIT(bif, d) \
+ rm_init_flags(&(bif)->bif_lock, (d), RM_NOWITNESS | RM_RECURSE);
+#define BPFIF_LOCK_DESTROY(bif) rm_destroy(&(bif)->bif_lock)
+#define BPFIF_RLOCK(bif, tracker) rm_rlock(&(bif)->bif_lock, tracker)
+#define BPFIF_RUNLOCK(bif, tracker) rm_runlock(&(bif)->bif_lock, tracker)
+#define BPFIF_WLOCK(bif) rm_wlock(&(bif)->bif_lock)
+#define BPFIF_WUNLOCK(bif) rm_wunlock(&(bif)->bif_lock)
#endif
More information about the p4-projects
mailing list