From patchwork Thu Oct 27 06:15:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Qiu X-Patchwork-Id: 687464 X-Patchwork-Delegate: diproiettod@vmware.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3t4Gz80zMcz9t0w for ; Thu, 27 Oct 2016 17:23:00 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=G+5Ta5uo; dkim-atps=neutral Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id D92BC1022E; Wed, 26 Oct 2016 23:22:58 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e4.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id 4E6B61022E for ; Wed, 26 Oct 2016 23:22:57 -0700 (PDT) Received: from bar5.cudamail.com (unknown [192.168.21.12]) by mx1e4.cudamail.com (Postfix) with ESMTPS id D84AD1E041A for ; Thu, 27 Oct 2016 00:22:56 -0600 (MDT) X-ASG-Debug-ID: 1477549376-09eadd4cc6241e30001-byXFYA Received: from mx3-pf2.cudamail.com ([192.168.14.1]) by bar5.cudamail.com with ESMTP id bFwOkTw7WIEKkzSc (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Thu, 27 Oct 2016 00:22:56 -0600 (MDT) X-Barracuda-Envelope-From: qdy220091330@gmail.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.1 Received: from unknown (HELO mail-pf0-f196.google.com) (209.85.192.196) by mx3-pf2.cudamail.com with ESMTPS (AES128-SHA encrypted); 27 Oct 2016 06:22:55 -0000 Received-SPF: pass (mx3-pf2.cudamail.com: SPF record at _netblocks.google.com designates 209.85.192.196 as permitted sender) X-Barracuda-Apparent-Source-IP: 209.85.192.196 X-Barracuda-RBL-IP: 209.85.192.196 Received: by mail-pf0-f196.google.com with SMTP id s8so1650001pfj.2 for ; Wed, 26 Oct 2016 23:22:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qzr1U/JxpnrPd2tBtsYYrRplu+ywKuGRfwnUFt0Vesk=; b=G+5Ta5uoIT8vSO/XYqx3vN1YC6wJHS5qT1A6ymJ8yBGY7zU8k0LL9TUlet0aQxYvz8 MKrVh99KDVC9y6d7x7d2acPjSAolX68Py3u9f37GmHR7u0h41cgVpzsZIrkuOVYLOsLy XRl3Jy/iesUXgbjhth3EaJRGWaL+yYWoi6OckZwzHIr4rrc9Kwx+r6fngbmjcS5tNPMu dqJqtdNPvlmo2tTW2hqamkwDQ7j2ZDpWrarBH+mDHp32cobwUlRJig25FPsSSr9iHQn+ dZkwC+S6m5YUvcxWz+5lR6oIPIWk7yfaGe+vtKXyDMRmeAHJHWQUWcvTGlPClk6Y2tL9 vv+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qzr1U/JxpnrPd2tBtsYYrRplu+ywKuGRfwnUFt0Vesk=; b=b4UWA9NbAnZW1qm2YKcl+xJup8mFzGHfqnqF1T114ZRko6dfkrHN3GlMQkWy3G/6KE 1m/wOHk2HbiDuhRu2LK+NWvoJlj645nYKEwnD/eiimaIFDAoDvs+6Ox9VyomMQvDWxAc kkk1BPRC4bJWa4NjSw5ELbUSfpwD2KX3LmaEhg65EYHYxQTIsnbpgpy0S2Sl2lzBq7bo viUbmiB/j9YVpWvI+9IAp0Y0wJxeS3sCdOAq1PNaCkmfxpC+/+Z5dNFPRq3RzdgRLVN+ JRLjO34u+jbJTNO5d0GL5e66GazL2+o89XR/mwA7GfTvLIWVxUBsuFRLz1ksxJKMT5Rb Q17Q== X-Gm-Message-State: ABUngvfvwfvOhoA/RyT0k0bzuZrQrkz6LGJKMAQZzBm7UCweURqwHD+h9ompBRiA//sEHA== X-Received: by 10.98.53.199 with SMTP id c190mr2331920pfa.63.1477549373889; Wed, 26 Oct 2016 23:22:53 -0700 (PDT) Received: from localhost.localdomain ([67.229.141.125]) by smtp.gmail.com with ESMTPSA id 141sm8410079pfw.63.2016.10.26.23.22.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Oct 2016 23:22:53 -0700 (PDT) X-CudaMail-Envelope-Sender: qdy220091330@gmail.com From: Michael Qiu X-Google-Original-From: Michael Qiu To: dev@openvswitch.org X-CudaMail-MID: CM-V2-1026000214 X-CudaMail-DTE: 102716 X-CudaMail-Originating-IP: 209.85.192.196 Date: Thu, 27 Oct 2016 14:15:24 +0800 X-ASG-Orig-Subj: [##CM-V2-1026000214##][PATCH 5/5] lib/netdev-dpdk: copy large packet to multi-segment mbufs Message-Id: <1477548924-26376-6-git-send-email-qiudayu@chinac.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1477548924-26376-1-git-send-email-qiudayu@chinac.com> References: <1477548924-26376-1-git-send-email-qiudayu@chinac.com> X-GBUdb-Analysis: 0, 209.85.192.196, Ugly c=0.392278 p=-0.2 Source Normal X-MessageSniffer-Rules: 0-0-0-10679-c X-Barracuda-Connect: UNKNOWN[192.168.14.1] X-Barracuda-Start-Time: 1477549376 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.60 X-Barracuda-Spam-Status: No, SCORE=0.60 using global scores of TAG_LEVEL=3.5 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=4.0 tests=BSF_SC5_MJ1963, DKIM_SIGNED, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.34084 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 DKIM_SIGNED Domain Keys Identified Mail: message has a signature 0.10 RDNS_NONE Delivered to trusted network by a host with no rDNS 0.50 BSF_SC5_MJ1963 Custom Rule MJ1963 Cc: Jijiang Liu , kevin.traynor@intel.com, Michael Qiu Subject: [ovs-dev] [PATCH 5/5] lib/netdev-dpdk: copy large packet to multi-segment mbufs X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" Currently, one packet is only copied to one segment in function dpdk_do_tx_copy(), this could be an issue when a jumboframe comes, especially for multipile segments. This patch calculate the segment number needed by the packet and copy the data to different segments. Signed-off-by: Michael Qiu Signed-off-by: Jijiang Liu --- lib/netdev-dpdk.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index ad92504..abb3b53 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -1554,9 +1554,10 @@ dpdk_do_tx_copy(struct netdev *netdev, int qid, struct dp_packet_batch *batch) #endif struct netdev_dpdk *dev = netdev_dpdk_cast(netdev); struct rte_mbuf *mbufs[PKT_ARRAY_SIZE]; + struct rte_mbuf *temp, *head = NULL; int dropped = 0; int newcnt = 0; - int i; + int i, j, nb_segs; /* If we are on a non pmd thread we have to use the mempool mutex, because * every non pmd thread shares the same mempool cache */ @@ -1569,6 +1570,7 @@ dpdk_do_tx_copy(struct netdev *netdev, int qid, struct dp_packet_batch *batch) for (i = 0; i < batch->count; i++) { int size = dp_packet_size(batch->packets[i]); + int max_data_len, tmp_len; if (OVS_UNLIKELY(size > dev->max_packet_len)) { VLOG_WARN_RL(&rl, "Too big size %d max_packet_len %d", @@ -1578,7 +1580,24 @@ dpdk_do_tx_copy(struct netdev *netdev, int qid, struct dp_packet_batch *batch) continue; } - mbufs[newcnt] = rte_pktmbuf_alloc(dev->dpdk_mp->mp); + temp = mbufs[newcnt] = rte_pktmbuf_alloc(dev->dpdk_mp->mp); + + /* all new allocated mbuf's max data len is the same */ + max_data_len = temp->buf_len - temp->data_off; + + nb_segs = size/max_data_len; + if (size % max_data_len) + nb_segs = nb_segs + 1; + + for (j = 1; j < nb_segs; j++) { + temp->next = rte_pktmbuf_alloc(dev->dpdk_mp->mp); + if (!temp->next) { + rte_pktmbuf_free(mbufs[newcnt]); + mbufs[newcnt] = NULL; + break; + } + temp = temp->next; + } if (!mbufs[newcnt]) { dropped += batch->count - i; @@ -1586,15 +1605,37 @@ dpdk_do_tx_copy(struct netdev *netdev, int qid, struct dp_packet_batch *batch) } /* We have to do a copy for now */ - memcpy(rte_pktmbuf_mtod(mbufs[newcnt], void *), - dp_packet_data(batch->packets[i]), size); + rte_pktmbuf_pkt_len(mbufs[newcnt]) = size; + temp = mbufs[newcnt]; + tmp_len = size < max_data_len ? size: max_data_len; + if (batch->packets[i]->source == DPBUF_DPDK) { + head = &(batch->packets[i]->mbuf); + while (temp && head && size > 0) { + rte_memcpy(rte_pktmbuf_mtod(temp, void*), dp_packet_data((struct dp_packet *)head),tmp_len); + rte_pktmbuf_data_len(temp) = tmp_len; + head = head->next; + size = size - tmp_len; + tmp_len = size < max_data_len ? size: max_data_len; + temp = temp->next; + } + } else { + int offset = 0; + while (temp && size > 0) { + memcpy(rte_pktmbuf_mtod(temp, void *), + dp_packet_at(batch->packets[i], offset,tmp_len), tmp_len); + rte_pktmbuf_data_len(temp) = tmp_len; + temp = temp->next; + size = size - tmp_len; + offset +=tmp_len; + tmp_len = size < max_data_len ? size: max_data_len; + } + } + - mbufs[newcnt]->nb_segs = batch->packets[i]->mbuf.nb_segs; + mbufs[newcnt]->nb_segs = nb_segs; mbufs[newcnt]->ol_flags = batch->packets[i]->mbuf.ol_flags; mbufs[newcnt]->packet_type = batch->packets[i]->mbuf.packet_type; mbufs[newcnt]->tx_offload = batch->packets[i]->mbuf.tx_offload; - rte_pktmbuf_data_len(mbufs[newcnt]) = size; - rte_pktmbuf_pkt_len(mbufs[newcnt]) = size; newcnt++; }