From owner-svn-soc-all@freebsd.org Fri Jul 8 15:43:37 2016 Return-Path: Delivered-To: svn-soc-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 7284EB824ED for ; Fri, 8 Jul 2016 15:43:37 +0000 (UTC) (envelope-from vincenzo@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 578CD1184 for ; Fri, 8 Jul 2016 15:43:37 +0000 (UTC) (envelope-from vincenzo@FreeBSD.org) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.15.2/8.15.2) with ESMTP id u68FhbRt007281 for ; Fri, 8 Jul 2016 15:43:37 GMT (envelope-from vincenzo@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.15.2/8.15.2/Submit) id u68FhaWE007278 for svn-soc-all@FreeBSD.org; Fri, 8 Jul 2016 15:43:36 GMT (envelope-from vincenzo@FreeBSD.org) Date: Fri, 8 Jul 2016 15:43:36 GMT Message-Id: <201607081543.u68FhaWE007278@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to vincenzo@FreeBSD.org using -f From: vincenzo@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r305824 - soc2016/vincenzo/head/sys/dev/netmap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jul 2016 15:43:37 -0000 Author: vincenzo Date: Fri Jul 8 15:43:36 2016 New Revision: 305824 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=305824 Log: freebsd: ptnet_rx_eof: introduce ptnet_rx_slot() to improve readability Modified: soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Modified: soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c ============================================================================== --- soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:43:27 2016 (r305823) +++ soc2016/vincenzo/head/sys/dev/netmap/if_ptnet.c Fri Jul 8 15:43:36 2016 (r305824) @@ -1532,6 +1532,43 @@ return ptnet_drain_transmit_queue(pq); } +static inline int +ptnet_rx_slot(uint8_t *nmbuf, unsigned int nmbuf_len, struct mbuf **mtail, + uint8_t **mdata) +{ + do { + unsigned int copy; + + if ((*mtail)->m_len == MCLBYTES) { + struct mbuf *mf; + + mf = m_getcl(M_NOWAIT, MT_DATA, 0); + if (unlikely(!mf)) { + return ENOMEM; + } + + (*mtail)->m_next = mf; + (*mtail) = mf; + *mdata = mtod(*mtail, uint8_t *); + (*mtail)->m_len = 0; + } + + copy = MCLBYTES - (*mtail)->m_len; + if (nmbuf_len < copy) { + copy = nmbuf_len; + } + + memcpy(*mdata, nmbuf, copy); + + nmbuf += copy; + nmbuf_len -= copy; + *mdata += copy; + (*mtail)->m_len += copy; + } while (nmbuf_len); + + return 0; +} + static int ptnet_rx_eof(struct ptnet_queue *pq) { @@ -1604,6 +1641,8 @@ mtail->m_len = 0; for (;;) { + int err; + slot = ring->slot + head; nmbuf_len = slot->len; nmbuf = NMB(na, slot); @@ -1615,48 +1654,22 @@ head, ring->tail, nmbuf_len, slot->flags)); - do { - unsigned int copy; - - if (mtail->m_len == MCLBYTES) { - struct mbuf *mf; - - mf = m_getcl(M_NOWAIT, MT_DATA, 0); - if (unlikely(!mf)) { - /* Ouch. We ran out of memory - * while processing a packet. - * We have to restore the - * previous head position, - * free the mbuf chain, and - * schedule the taskqueue to - * give the packet another - * chance. */ - head = prev_head; - m_freem(mhead); - taskqueue_enqueue(pq->taskq, - &pq->task); - goto escape; - } - - mtail->m_next = mf; - mtail = mf; - mdata = mtod(mtail, uint8_t *); - mtail->m_len = 0; - } - - copy = MCLBYTES - mtail->m_len; - if (nmbuf_len < copy) { - copy = nmbuf_len; - } - - memcpy(mdata, nmbuf, copy); - - nmbuf += copy; - nmbuf_len -= copy; - mdata += copy; - mtail->m_len += copy; - } while (nmbuf_len); - + err = ptnet_rx_slot(nmbuf, nmbuf_len, &mtail, &mdata); + if (unlikely(err)) { + /* Ouch. We ran out of memory + * while processing a packet. + * We have to restore the + * previous head position, + * free the mbuf chain, and + * schedule the taskqueue to + * give the packet another + * chance. */ + head = prev_head; + m_freem(mhead); + taskqueue_enqueue(pq->taskq, + &pq->task); + goto escape; + } head = nm_next(head, lim); if (!(slot->flags & NS_MOREFRAG)) {