From patchwork Tue Nov 11 17:35:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 40604 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D9858206A5 for ; Tue, 11 Nov 2014 17:36:43 +0000 (UTC) Received: by mail-lb0-f199.google.com with SMTP id n15sf5651144lbi.2 for ; Tue, 11 Nov 2014 09:36:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=hf7vypIwjjPSyplQG5aDE/8cyIyuvTTBLTyWB3VuhuQ=; b=G2s2l9q7K95/Ohw77FCa7S7sAwsMWXHYDTa0YR+4jjEkS3sbWmL/iHviSCqYctdNoA dRxTH5fCGt8Pjk5ctYKrCu2Nl8p0VsEtj0BA93teCBmRn+yqGcoSlHwu/nLX4DrigQfU VzZFotRi8S5ejK+I9gPDNh/M1yQpwzwdjfgbxKnQ69a+ezf9tUL3lWWt54T2P+JLHZy+ cu6b02vufw2DHQjH56nrt6AYZVu/dY7ovpcnBIqXw2HzWX172vzewk6kRXCYIJcZv7aM BNSLppM/YtHUkB5fPvfUDB5lu1vKA3fe7GivoTN93mFRnqtQfj7aaiV4bGj0k9cvBpIv hYiw== X-Gm-Message-State: ALoCoQmR2L6yn9NvafgFRTVJJgOc+7i25SUWRoZcQf7LHJO1zS9ssbJo4ZmsA/WWlCtdP10chKju X-Received: by 10.112.48.98 with SMTP id k2mr580496lbn.15.1415727402886; Tue, 11 Nov 2014 09:36:42 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.129 with SMTP id w1ls583886lal.34.gmail; Tue, 11 Nov 2014 09:36:42 -0800 (PST) X-Received: by 10.112.137.202 with SMTP id qk10mr37418140lbb.0.1415727402627; Tue, 11 Nov 2014 09:36:42 -0800 (PST) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id at1si5313949lbc.18.2014.11.11.09.36.42 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Nov 2014 09:36:42 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by mail-la0-f45.google.com with SMTP id pn19so10011288lab.18 for ; Tue, 11 Nov 2014 09:36:42 -0800 (PST) X-Received: by 10.152.6.228 with SMTP id e4mr37395028laa.71.1415727402510; Tue, 11 Nov 2014 09:36:42 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp295872lbc; Tue, 11 Nov 2014 09:36:41 -0800 (PST) X-Received: by 10.140.18.195 with SMTP id 61mr31779147qgf.56.1415727397520; Tue, 11 Nov 2014 09:36:37 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id i103si11562131qgd.0.2014.11.11.09.36.36 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 11 Nov 2014 09:36:37 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XoFMp-0004Bz-Ud; Tue, 11 Nov 2014 17:36:35 +0000 Received: from mail-lb0-f176.google.com ([209.85.217.176]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XoFMV-0004Aj-N0 for lng-odp@lists.linaro.org; Tue, 11 Nov 2014 17:36:15 +0000 Received: by mail-lb0-f176.google.com with SMTP id 10so7831528lbg.7 for ; Tue, 11 Nov 2014 09:36:10 -0800 (PST) X-Received: by 10.112.168.39 with SMTP id zt7mr16582285lbb.72.1415727370178; Tue, 11 Nov 2014 09:36:10 -0800 (PST) Received: from cipriantemp.enea.se (sestofw01.enea.se. [192.36.1.252]) by mx.google.com with ESMTPSA id ql6sm6122819lbb.31.2014.11.11.09.36.09 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Nov 2014 09:36:09 -0800 (PST) From: Ciprian Barbu To: lng-odp@lists.linaro.org Date: Tue, 11 Nov 2014 19:35:58 +0200 Message-Id: <1415727359-22406-4-git-send-email-ciprian.barbu@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1415727359-22406-1-git-send-email-ciprian.barbu@linaro.org> References: <1415727359-22406-1-git-send-email-ciprian.barbu@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH NETMAP 3/4] Refactor netmap I/O using existing APIs X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: ciprian.barbu@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Signed-off-by: Ciprian Barbu --- platform/linux-netmap/include/odp_packet_netmap.h | 6 +- platform/linux-netmap/odp_packet_netmap.c | 258 ++++++++-------------- 2 files changed, 89 insertions(+), 175 deletions(-) diff --git a/platform/linux-netmap/include/odp_packet_netmap.h b/platform/linux-netmap/include/odp_packet_netmap.h index 78b2379..fae434f 100644 --- a/platform/linux-netmap/include/odp_packet_netmap.h +++ b/platform/linux-netmap/include/odp_packet_netmap.h @@ -30,12 +30,10 @@ typedef struct { size_t frame_offset; /**< Frame start offset from start of pkt buf */ size_t buf_size; /**< Size of buffer payload in 'pool' */ struct nm_desc *desc; /**< Netmap meta-data for the device */ - uint32_t begin; /**< First ring to poll */ - uint32_t end; /**< Last ring to poll */ - struct netmap_ring *rxring; /**< First rx ring */ - struct netmap_ring *txring; /**< First tx ring */ odp_queue_t tx_access; /** Used for exclusive access to send packets */ uint32_t if_flags; + odp_packet_t *pkt_table;/** Used by recv_pkt_netmap */ + int nb_rx; /** Used by recv_pkt_netmap */ char ifname[IFNAMSIZ]; } pkt_netmap_t; diff --git a/platform/linux-netmap/odp_packet_netmap.c b/platform/linux-netmap/odp_packet_netmap.c index 29e7862..37e574b 100644 --- a/platform/linux-netmap/odp_packet_netmap.c +++ b/platform/linux-netmap/odp_packet_netmap.c @@ -103,7 +103,9 @@ static int nm_do_ioctl(pkt_netmap_t * const pkt_nm, unsigned long cmd, case SIOCGIFFLAGS: pkt_nm->if_flags = (ifr.ifr_flags << 16) | (0xffff & ifr.ifr_flags); - ODP_DBG("flags are 0x%x\n", pkt_nm->if_flags); + ODP_DBG("[%04d] flags are 0x%x\n", + odp_thread_id(), + pkt_nm->if_flags); break; default: break; @@ -170,20 +172,17 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, } odp_spinlock_unlock(&mmap_desc_lock); - ODP_DBG("thread %d mmap addr %p\n", + ODP_DBG("[%04d] mmap addr %p\n", odp_thread_id(), pkt_nm->desc->mem); - pkt_nm->begin = 0; - pkt_nm->end = pkt_nm->desc->req.nr_rx_rings; - pkt_nm->rxring = NETMAP_RXRING(pkt_nm->desc->nifp, 0); - pkt_nm->txring = NETMAP_TXRING(pkt_nm->desc->nifp, 0); - ret = nm_do_ioctl(pkt_nm, SIOCGIFFLAGS, 0); if (ret) return ret; if ((pkt_nm->if_flags & IFF_UP) == 0) { - ODP_DBG("%s is down, bringing up...\n", pkt_nm->ifname); + ODP_DBG("[%04d] %s is down, bringing up...\n", + odp_thread_id(), + pkt_nm->ifname); pkt_nm->if_flags |= IFF_UP; } if (ETH_PROMISC) { @@ -192,11 +191,13 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, } ret = nm_do_ioctl(pkt_nm, SIOCETHTOOL, ETHTOOL_SGSO); if (ret) - ODP_DBG("ETHTOOL_SGSO not supported\n"); + ODP_DBG("[%04d] ETHTOOL_SGSO not supported\n", + odp_thread_id()); ret = nm_do_ioctl(pkt_nm, SIOCETHTOOL, ETHTOOL_STSO); if (ret) - ODP_DBG("ETHTOOL_STSO not supported\n"); + ODP_DBG("[%04d] ETHTOOL_STSO not supported\n", + odp_thread_id()); /* TODO: This seems to cause the app to not receive frames * first time it is launched after netmap driver is inserted. * Should be investigated further. @@ -206,11 +207,14 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, */ ret = nm_do_ioctl(pkt_nm, SIOCETHTOOL, ETHTOOL_STXCSUM); if (ret) - ODP_DBG("ETHTOOL_STXCSUM not supported\n"); + ODP_DBG("[%04d] ETHTOOL_STXCSUM not supported\n", + odp_thread_id()); - ODP_DBG("Wait for link to come up\n"); + ODP_DBG("[%04d] Wait for link to come up\n", + odp_thread_id()); sleep(WAITLINK_TMO); - ODP_DBG("Done\n"); + ODP_DBG("[%04d] Done\n", + odp_thread_id()); return 0; } @@ -225,198 +229,110 @@ int close_pkt_netmap(pkt_netmap_t * const pkt_nm) return 0; } +static void nm_recv_cb(uint8_t *arg, const struct nm_pkthdr *hdr, + const uint8_t *buf) +{ + pkt_netmap_t *pkt_nm = (pkt_netmap_t *)arg; + odp_packet_t pkt; + uint8_t *pkt_buf, *l2_hdr; + size_t frame_len; + + frame_len = (size_t)hdr->len; + + if (frame_len > pkt_nm->max_frame_len) { + ODP_ERR("[%04d] RX: frame too big %u %lu!\n", + odp_thread_id(), + (unsigned)frame_len, pkt_nm->max_frame_len); + return; + } + + if (odp_unlikely(frame_len < ODPH_ETH_LEN_MIN)) { + ODP_ERR("[%04d] RX: Frame truncated: %u\n", + odp_thread_id(), + (unsigned)frame_len); + return; + } + + pkt = odph_packet_alloc(pkt_nm->pool); + + if (odp_unlikely(pkt == ODP_PACKET_INVALID)) { + ODP_DBG("[%04d] Could not allocate packet\n", odp_thread_id()); + return; + } + pkt_buf = odp_packet_addr(pkt); + l2_hdr = pkt_buf + pkt_nm->frame_offset; + /* For now copy the data in the mbuf, + worry about zero-copy later */ + memcpy(l2_hdr, buf, frame_len); + + /* Initialize, parse and set packet header data */ + odp_packet_init(pkt); + odp_packet_parse(pkt, frame_len, pkt_nm->frame_offset); + + pkt_nm->pkt_table[pkt_nm->nb_rx++] = pkt; +} + int recv_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], unsigned len) { - struct netmap_ring *rxring = pkt_nm->rxring; - int fd; - unsigned nb_rx = 0; - uint32_t limit, rx; - uint32_t ringid = pkt_nm->begin; - odp_packet_t pkt = ODP_PACKET_INVALID; + int fd = pkt_nm->desc->fd; + #ifdef NETMAP_BLOCKING_IO struct pollfd fds[1]; int ret; -#endif - fd = pkt_nm->desc->fd; -#ifdef NETMAP_BLOCKING_IO fds[0].fd = fd; fds[0].events = POLLIN; -#endif - while (nb_rx < len) { -#ifdef NETMAP_BLOCKING_IO - ret = poll(&fds[0], 1, POLL_TMO); - if (ret <= 0 || (fds[0].revents & POLLERR)) - break; + ret = poll(&fds[0], 1, POLL_TMO); + if (ret <= 0 || (fds[0].revents & POLLERR)) + return 0; #else - ioctl(fd, NIOCRXSYNC, NULL); + ioctl(fd, NIOCRXSYNC, NULL); #endif - /* Find first ring not empty */ - while (nm_ring_empty(rxring)) { - ringid++; - - /* Return to scheduler if no more data to meet the - requested amount (len) */ - if (ringid == pkt_nm->end) { - ODP_DBG("No more data on the wire\n"); - break; - } - - rxring = NETMAP_RXRING(pkt_nm->desc->nifp, ringid); - } - - limit = len - nb_rx; - if (nm_ring_space(rxring) < limit) - limit = nm_ring_space(rxring); - - ODP_DBG("receiving %d frames out of %u\n", limit, len); - - for (rx = 0; rx < limit; rx++) { - struct netmap_slot *rslot; - char *p; - uint16_t frame_len; - uint8_t *pkt_buf; - uint8_t *l2_hdr; - uint32_t cur; - - if (odp_likely(pkt == ODP_PACKET_INVALID)) { - pkt = odph_packet_alloc(pkt_nm->pool); - if (odp_unlikely(pkt == ODP_PACKET_INVALID)) - break; - } - - cur = rxring->cur; - rslot = &rxring->slot[cur]; - p = NETMAP_BUF(rxring, rslot->buf_idx); - frame_len = rslot->len; - - rxring->head = nm_ring_next(rxring, cur); - rxring->cur = rxring->head; - - pkt_buf = odp_packet_addr(pkt); - l2_hdr = pkt_buf + pkt_nm->frame_offset; - - if (frame_len > pkt_nm->max_frame_len) { - ODP_ERR("RX: frame too big %u %lu!\n", - frame_len, pkt_nm->max_frame_len); - /* drop the frame, reuse pkt next interation */ - continue; - } - if (odp_unlikely(frame_len < ODPH_ETH_LEN_MIN)) { - ODP_ERR("RX: Frame truncated: %u\n", - (unsigned)frame_len); - continue; - } - - /* For now copy the data in the mbuf, - worry about zero-copy later */ - memcpy(l2_hdr, p, frame_len); - - /* Initialize, parse and set packet header data */ - odp_packet_init(pkt); - odp_packet_parse(pkt, frame_len, pkt_nm->frame_offset); - - pkt_table[nb_rx] = pkt; - pkt = ODP_PACKET_INVALID; - nb_rx++; - } - - if (odp_unlikely(pkt == ODP_PACKET_INVALID)) - break; - } + pkt_nm->pkt_table = pkt_table; + pkt_nm->nb_rx = 0; + nm_dispatch(pkt_nm->desc, len, nm_recv_cb, (uint8_t *)pkt_nm); - if (odp_unlikely(pkt != ODP_PACKET_INVALID)) - odp_buffer_free((odp_buffer_t) pkt); + if (pkt_nm->nb_rx) + ODP_DBG("[%04d] <=== rcvd %03u frames from netmap adapter\n", + odp_thread_id(), pkt_nm->nb_rx); - if (nb_rx) - ODP_DBG("<=== rcvd %03u frames from netmap adapter\n", nb_rx); - - return nb_rx; + return pkt_nm->nb_rx; } int send_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], unsigned len) { - struct netmap_ring *txring = pkt_nm->txring; - int fd; - unsigned nb_tx = 0; - uint32_t limit, tx; - uint32_t ringid = pkt_nm->begin; - odp_packet_t pkt; + int fd = pkt_nm->desc->fd; + unsigned tx, nb_tx; #ifdef NETMAP_BLOCKING_IO struct pollfd fds[2]; int ret; -#endif - fd = pkt_nm->desc->fd; -#ifdef NETMAP_BLOCKING_IO fds[0].fd = fd; fds[0].events = POLLOUT; -#endif - while (nb_tx < len) { -#ifdef NETMAP_BLOCKING_IO - ret = poll(&fds[0], 1, POLL_TMO); - if (ret <= 0 || (fds[0].revents & POLLERR)) - break; + ret = poll(&fds[0], 1, POLL_TMO); + if (ret <= 0 || (fds[0].revents & POLLERR)) + return 0; #else - ioctl(fd, NIOCTXSYNC, NULL); + ioctl(fd, NIOCTXSYNC, NULL); #endif - /* Find first ring not empty */ - while (nm_ring_empty(txring)) { - ringid++; - - /* Return to scheduler if no more space to meet the - requested amount (len) */ - if (ringid == pkt_nm->end) { - ODP_DBG("No more space in TX rings\n"); - break; - } - - txring = NETMAP_TXRING(pkt_nm->desc->nifp, ringid); - } - - limit = len - nb_tx; - if (nm_ring_space(txring) < limit) - limit = nm_ring_space(txring); - - ODP_DBG("Sending %d packets out of %d to netmap %p %u\n", - limit, len, txring, txring->cur); - - for (tx = 0; tx < limit; tx++) { - struct netmap_slot *tslot; - size_t frame_len; - uint32_t cur; - uint8_t *frame; - void *txbuf; - - cur = txring->cur; - tslot = &txring->slot[cur]; - txbuf = NETMAP_BUF(txring, tslot->buf_idx); - - pkt = pkt_table[nb_tx]; - frame = odp_packet_l2(pkt); - frame_len = odp_packet_get_len(pkt); - - memcpy(txbuf, frame, frame_len); - tslot->len = frame_len; - txring->head = nm_ring_next(txring, cur); - txring->cur = txring->head; - nb_tx++; - } + for (nb_tx = 0; nb_tx < len; nb_tx++) { + odp_packet_t pkt = pkt_table[nb_tx]; + uint8_t *frame = odp_packet_l2(pkt); + size_t frame_len = odp_packet_get_len(pkt); + if (nm_inject(pkt_nm->desc, frame, frame_len)) + break; } -#ifndef NETMAP_BLOCKING_IO - ioctl(fd, NIOCTXSYNC, NULL); -#endif - if (nb_tx) - ODP_DBG("===> sent %03u frames to netmap adapter\n", nb_tx); + ODP_DBG("[%04d] ===> sent %03u frames to netmap adapter\n", + odp_thread_id(), nb_tx); for (tx = 0; tx < len; tx++) odph_packet_free(pkt_table[tx]);