From patchwork Mon Mar 2 18:46:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciprian Barbu X-Patchwork-Id: 45309 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 E7166214B5 for ; Mon, 2 Mar 2015 18:48:11 +0000 (UTC) Received: by lbdu10 with SMTP id u10sf25606542lbd.3 for ; Mon, 02 Mar 2015 10:48:10 -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:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=kkVvUcN1JWqDzNEUVfEebGmAvSCPSrGZxswLqOOeJoo=; b=bpk+nYfwe7eOdni6yxfZbTGoVCd9qCMgXTWjtd/3JjMojK3TFWnc4oBFOIvOO4Sz8T Ejj0jbjT49ccdjRml4Yq9R80nHdP/o8f8Got5ELZN2YjWYJRcJ4mADf0qTj+6JIWURJr 8whYkIeY2sWFU5gM7gkMGNqXrbdtKPH6lMa2Tb3mAwMnwTmPVxfF/d3CDBo7wHAn8qMe KB/+1K42/Qc3/ApdMrdDmY8/pARuA4w1svNHFv0ET9cIFmf912jM38SkG3QFh9BOHawu 0upV+iBhUAqjemklga2NjGad6C10MZVugnqXcRxjuDCF7Ozht7HuBCTSfEEp5pEebzG/ 8UEA== X-Gm-Message-State: ALoCoQn3oGo40Pe09fR9GCzuN6Su7mLaVq/fJiUP2R2yYkJUDQ6ovPBpf+xxkC8OjaURSTJYYVPO X-Received: by 10.112.167.98 with SMTP id zn2mr3948058lbb.6.1425322090864; Mon, 02 Mar 2015 10:48:10 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.103 with SMTP id s7ls188210lag.105.gmail; Mon, 02 Mar 2015 10:48:10 -0800 (PST) X-Received: by 10.152.9.200 with SMTP id c8mr22739037lab.67.1425322090650; Mon, 02 Mar 2015 10:48:10 -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 d1si5326076laa.39.2015.03.02.10.48.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 02 Mar 2015 10:48:10 -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 labge10 with SMTP id ge10so32327019lab.12 for ; Mon, 02 Mar 2015 10:48:10 -0800 (PST) X-Received: by 10.152.178.197 with SMTP id da5mr8501972lac.56.1425322090505; Mon, 02 Mar 2015 10:48:10 -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.35.133 with SMTP id h5csp90259lbj; Mon, 2 Mar 2015 10:48:09 -0800 (PST) X-Received: by 10.140.48.67 with SMTP id n61mr50552039qga.82.1425322089266; Mon, 02 Mar 2015 10:48:09 -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 13si12417544qhv.28.2015.03.02.10.48.08 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 02 Mar 2015 10:48:09 -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 1YSVNu-0008I8-8V; Mon, 02 Mar 2015 18:48:06 +0000 Received: from mail-la0-f43.google.com ([209.85.215.43]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1YSVND-0008AJ-1h for lng-odp@lists.linaro.org; Mon, 02 Mar 2015 18:47:23 +0000 Received: by labhs14 with SMTP id hs14so32335587lab.1 for ; Mon, 02 Mar 2015 10:47:17 -0800 (PST) X-Received: by 10.152.1.170 with SMTP id 10mr25452134lan.89.1425322037504; Mon, 02 Mar 2015 10:47:17 -0800 (PST) Received: from cipriantemp.enea.se (sestofw01.enea.se. [192.36.1.252]) by mx.google.com with ESMTPSA id i13sm2696725lab.38.2015.03.02.10.47.16 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 02 Mar 2015 10:47:16 -0800 (PST) From: Ciprian Barbu To: lng-odp@lists.linaro.org Date: Mon, 2 Mar 2015 20:46:55 +0200 Message-Id: <1425322017-14636-11-git-send-email-ciprian.barbu@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1425322017-14636-1-git-send-email-ciprian.barbu@linaro.org> References: <1425322017-14636-1-git-send-email-ciprian.barbu@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCH NETMAP 10/12] linux-netmap: pktio: refactor packet 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 | 4 - platform/linux-netmap/odp_packet_netmap.c | 218 +++++++--------------- 2 files changed, 71 insertions(+), 151 deletions(-) diff --git a/platform/linux-netmap/include/odp_packet_netmap.h b/platform/linux-netmap/include/odp_packet_netmap.h index 89d1a27..fe376d1 100644 --- a/platform/linux-netmap/include/odp_packet_netmap.h +++ b/platform/linux-netmap/include/odp_packet_netmap.h @@ -38,10 +38,6 @@ typedef struct { size_t frame_offset; /* 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; - uint32_t end; - struct netmap_ring *rxring; - struct netmap_ring *txring; odp_queue_t tx_access; /* exclusive access to send packets */ uint32_t if_flags; netmap_dev_t *nm_dev; diff --git a/platform/linux-netmap/odp_packet_netmap.c b/platform/linux-netmap/odp_packet_netmap.c index 9558440..9b52bd6 100644 --- a/platform/linux-netmap/odp_packet_netmap.c +++ b/platform/linux-netmap/odp_packet_netmap.c @@ -64,6 +64,12 @@ static odp_spinlock_t nm_global_lock; static netmap_dev_t netmap_devs[MAX_DEVS]; static int nm_dev_cnt; +struct dispatch_args { + odp_packet_t *pkt_table; + unsigned nb_rx; + pkt_netmap_t *pkt_nm; +}; + int odp_netmap_init_global(void) { odp_spinlock_init(&nm_global_lock); @@ -198,11 +204,6 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, 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; @@ -256,173 +257,96 @@ int close_pkt_netmap(pkt_netmap_t * const pkt_nm) return 0; } -int recv_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], - unsigned len) +static void nm_recv_cb(uint8_t *arg, const struct nm_pkthdr *hdr, + const uint8_t *buf) { - 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; - struct pollfd fds[1]; - int ret; - - fd = pkt_nm->desc->fd; - fds[0].fd = fd; - fds[0].events = POLLIN; - - while (nb_rx < len) { - ret = poll(fds, 1, POLL_TMO); - if (ret <= 0 || (fds[0].revents & POLLERR)) - break; - - /* Find first ring not empty */ - while (nm_ring_empty(rxring)) { - ringid++; + struct dispatch_args *args = (struct dispatch_args *)arg; + odp_packet_t pkt; + uint8_t *pkt_buf, *l2_hdr; + size_t frame_len; - /* 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; - } + frame_len = (size_t)hdr->len; - rxring = NETMAP_RXRING(pkt_nm->desc->nifp, ringid); - } + if (frame_len > args->pkt_nm->max_frame_len) { + ODP_ERR("[%04d] RX: frame too big %u %lu!\n", + odp_thread_id(), + (unsigned)frame_len, args->pkt_nm->max_frame_len); + return; + } - if (ringid == pkt_nm->end) - break; + if (odp_unlikely(frame_len < ODPH_ETH_LEN_MIN)) { + ODP_ERR("[%04d] RX: Frame truncated: %u\n", + odp_thread_id(), + (unsigned)frame_len); + return; + } - limit = len - nb_rx; - if (nm_ring_space(rxring) < limit) - limit = nm_ring_space(rxring); - - 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++; - } + pkt = odph_packet_alloc(args->pkt_nm->pool); - if (odp_unlikely(pkt == ODP_PACKET_INVALID)) - break; + 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 + args->pkt_nm->frame_offset; + /* For now copy the data in the mbuf, + worry about zero-copy later */ + memcpy(l2_hdr, buf, frame_len); - if (odp_unlikely(pkt != ODP_PACKET_INVALID)) - odp_buffer_free((odp_buffer_t) pkt); + /* Initialize, parse and set packet header data */ + odp_packet_init(pkt); + odp_packet_parse(pkt, frame_len, args->pkt_nm->frame_offset); - return nb_rx; + args->pkt_table[args->nb_rx++] = pkt; } -int send_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], +int recv_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; struct pollfd fds[1]; int ret; + struct dispatch_args args; - fd = pkt_nm->desc->fd; fds[0].fd = fd; - fds[0].events = POLLOUT; + fds[0].events = POLLIN; - while (nb_tx < len) { - ret = poll(fds, 1, POLL_TMO); - if (ret <= 0 || (fds[0].revents & POLLERR)) - break; + ret = poll(fds, 1, POLL_TMO); + if (ret <= 0 || (fds[0].revents & POLLERR)) + return 0; - /* Find first ring not empty */ - while (nm_ring_empty(txring)) { - ringid++; + args.pkt_table = pkt_table; + args.nb_rx = 0; + args.pkt_nm = pkt_nm; + nm_dispatch(pkt_nm->desc, len, nm_recv_cb, (uint8_t *)&args); - /* 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; - } + return args.nb_rx; +} - txring = NETMAP_TXRING(pkt_nm->desc->nifp, ringid); - } +int send_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[], + unsigned len) +{ + int fd = pkt_nm->desc->fd; + unsigned tx, nb_tx; + struct pollfd fds[2]; + int ret; - if (ringid == pkt_nm->end) - break; + fds[0].fd = fd; + fds[0].events = POLLOUT; - limit = len - nb_tx; - if (nm_ring_space(txring) < limit) - limit = nm_ring_space(txring); - - 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++; - } + ret = poll(fds, 1, POLL_TMO); + if (ret <= 0 || (fds[0].revents & POLLERR)) + goto out; + + 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) == 0) + break; } +out: for (tx = 0; tx < len; tx++) odph_packet_free(pkt_table[tx]);