Date: Mon, 13 Aug 2007 04:32:30 GMT From: Kip Macy <kmacy@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 125097 for review Message-ID: <200708130432.l7D4WUJw081233@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=125097 Change 125097 by kmacy@kmacy_home:ethng on 2007/08/13 04:31:46 move to using lock embedded in mbuf_ring for protecting producer side Affected files ... .. //depot/projects/ethng/src/sys/dev/cxgb/cxgb_multiq.c#6 edit .. //depot/projects/ethng/src/sys/dev/cxgb/cxgb_osdep.h#3 edit .. //depot/projects/ethng/src/sys/dev/cxgb/cxgb_sge.c#9 edit Differences ... ==== //depot/projects/ethng/src/sys/dev/cxgb/cxgb_multiq.c#6 (text+ko) ==== @@ -113,43 +113,36 @@ struct sge_txq *txq; struct mbuf_ring *mr; struct mbuf_head *mbq; + int prod, cons, mask; int err = 0; if (qs->qs_flags & QS_EXITING) { m_freem_vec(m); return (ENXIO); } - txq = &qs->txq[TXQ_ETH]; DPRINTF("enqueueing packet to cpuid=%d\n", qs->qs_cpuid); mbq = &txq->sendq; - if (curcpu == qs->qs_cpuid) { - critical_enter(); - mbufq_tail(mbq, m); - critical_exit(); + + mr = &txq->txq_mr; + mtx_lock(&mr->mr_lock); + cons = mr->mr_cons; + prod = mr->mr_prod; + mask = mr->mr_size - 1; + if (((prod + 1) & mask) != cons) { + mr->mr_ring[prod] = m; + mr->mr_prod = (prod + 1) & mask; } else { - int prod, cons, mask; - - mr = &txq->txq_mr; - mtx_lock(&txq->lock); - cons = mr->mr_cons; - prod = mr->mr_prod; - mask = mr->mr_size - 1; - if (((prod + 1) & mask) != cons) { - mr->mr_ring[prod] = m; - mr->mr_prod = (prod + 1) & mask; - } else { - txq->txq_drops++; - err = ENOBUFS; - } - mtx_unlock(&txq->lock); - if ((qs->txq[TXQ_ETH].flags & TXQ_TRANSMITTING) == 0) - wakeup(qs); - if (err) - m_freem(m); + txq->txq_drops++; + err = ENOBUFS; } + mtx_unlock(&mr->mr_lock); + if ((qs->txq[TXQ_ETH].flags & TXQ_TRANSMITTING) == 0) + wakeup(qs); + if (err) + m_freem(m); return (err); } @@ -362,7 +355,6 @@ return (ENOBUFS); } - critical_enter(); cons = mr->mr_cons; prod = mr->mr_prod; while (cons != prod) { @@ -375,7 +367,6 @@ mbufq_tail(mbq, imm); *complete = ((mbufq_size(mbq) > TX_WR_SIZE_MAX) || (mbufq_len(mbq) >= TX_WR_COUNT_MAX)); - critical_exit(); return (err); } ==== //depot/projects/ethng/src/sys/dev/cxgb/cxgb_osdep.h#3 (text+ko) ==== @@ -36,6 +36,9 @@ #include <sys/endian.h> #include <sys/bus.h> +#include <sys/lock.h> +#include <sys/mutex.h> + #include <dev/mii/mii.h> #ifdef CONFIG_DEFINED @@ -57,6 +60,7 @@ volatile uint32_t mr_cons; volatile uint32_t mr_prod; int mr_size; + struct mtx mr_lock; }; #define PANIC_IF(exp) do { \ ==== //depot/projects/ethng/src/sys/dev/cxgb/cxgb_sge.c#9 (text+ko) ==== @@ -1540,9 +1540,10 @@ int i; for (i = 0; i < SGE_TXQ_PER_SET; i++) - if (q->txq[i].txq_mr.mr_ring != NULL) + if (q->txq[i].txq_mr.mr_ring != NULL) { free(q->txq[i].txq_mr.mr_ring, M_DEVBUF); - + mtx_destroy(&q->txq[i].txq_mr.mr_lock); + } for (i = 0; i < SGE_RXQ_PER_SET; ++i) { if (q->fl[i].desc) { mtx_lock(&sc->sge.reg_lock); @@ -2070,6 +2071,7 @@ } q->txq[i].txq_mr.mr_prod = q->txq[i].txq_mr.mr_cons = 0; q->txq[i].txq_mr.mr_size = cxgb_txq_mbuf_ring_size; + mtx_init(&q->txq[i].txq_mr.mr_lock, "txq mbuf ring", NULL, MTX_DEF); } init_qset_cntxt(q, id);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200708130432.l7D4WUJw081233>