From patchwork Mon Jun 19 05:29:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Qiu X-Patchwork-Id: 777574 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wrfk44hg6z9s76 for ; Mon, 19 Jun 2017 15:32:12 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="SDnu4K3h"; dkim-atps=neutral Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id CD60EB9B; Mon, 19 Jun 2017 05:29:47 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 7DC11B76 for ; Mon, 19 Jun 2017 05:29:46 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pf0-f196.google.com (mail-pf0-f196.google.com [209.85.192.196]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 2454E183 for ; Mon, 19 Jun 2017 05:29:46 +0000 (UTC) Received: by mail-pf0-f196.google.com with SMTP id d5so15015394pfe.1 for ; Sun, 18 Jun 2017 22:29:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=V+pNY5jSePTVvjfQQh7RoFOP2ckgeQC/Ei/WMkvsNJE=; b=SDnu4K3hg6icumzZdF42IWJL0QV/0fMPm55Dn9ALhOhYxrJob29fqTXBK1ewE0HWfy NaOsDKgfv/GoLuOaQ/bfkCYAXiP/3y++ZprYsfgfNsAd6Re8lBmq8IxR+GadqlzNnAT3 HPMjNSLkZd6EFTdV6eQRX9K18c0W/SWnHlyr5JGmm/HdNQvoXKa4XSItSKlbsrzqFy+w uk43OS9K/XpkxkJv4DX+LLUeAy+FN7WbFQIpxI/9A1rp169nYQpZArAyzSdvK2KljMSd u9ZxBxsFiG9XOUG6dfep5UdhrjgbUeBJmpXcYvuZnKeDg+ZuaM6yFv9efjSaFqKzY4BK zCnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=V+pNY5jSePTVvjfQQh7RoFOP2ckgeQC/Ei/WMkvsNJE=; b=tA7JJhb1PkeWBJw5t6RgoNX+0y7mwuXKqAiYZ/s/BXww6rR+oikojbC4KSKUCUIDgc QwdBmpND9Q3v+B9bnjoIIFozaPXtvFh0w0+XZPFSVjA64KJ1xCzwh0p3wxY4ihbf+VA1 dif5nF9WlF94IB3uRP0maJmwEvJ1b7XbTp6FNcwGGKPD3xZTsAHJ3vB4PF5EkrPEO2u9 2Td2mLlpILBkWvueI78GCmNQxqIjhGry8zUGfctV3sIWUYhji1jgbXCkpZ0Mk3bOyA9k 6zlgnjb+exLTZaGMjUKNpZ+H+in1/O0OTB60yODWSCDaktPzHtboYd1VIc7Jr/+Cg3KK COIg== X-Gm-Message-State: AKS2vOwqvSUkd2RDAi8drNYCxK9jq66HE0T7kE0oy2HQH182/86s2FBu JNwba6HkKcSvec/h X-Received: by 10.84.218.134 with SMTP id r6mr27245639pli.288.1497850185633; Sun, 18 Jun 2017 22:29:45 -0700 (PDT) Received: from localhost.localdomain ([101.95.168.242]) by smtp.gmail.com with ESMTPSA id 189sm17869160pgj.67.2017.06.18.22.29.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 18 Jun 2017 22:29:45 -0700 (PDT) From: Michael Qiu To: dev@openvswitch.org Date: Mon, 19 Jun 2017 13:29:03 +0800 Message-Id: <1497850143-3116-6-git-send-email-qdy220091330@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1497850143-3116-1-git-send-email-qdy220091330@gmail.com> References: <1497850143-3116-1-git-send-email-qdy220091330@gmail.com> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Michael Qiu Subject: [ovs-dev] [PATCH 5/5] lib/netdev-dpdk: copy large packet to multi-segment mbufs X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Michael Qiu Currently, one packet is only copied to one segment in function dpdk_do_tx_copy(), this could be an issue when a jumbo frame comes, especially for multiple segments. This patch calculate the segment number needed by the packet and copy the data to different segments. Signed-off-by: Michael Qiu --- lib/netdev-dpdk.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index 0485872..38ec2ed 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -1776,14 +1776,16 @@ 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 *pkts[PKT_ARRAY_SIZE]; + struct rte_mbuf *temp, *head = NULL; int dropped = 0; int newcnt = 0; - int i; + int i, j, nb_segs; dp_packet_batch_apply_cutlen(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", @@ -1793,7 +1795,24 @@ dpdk_do_tx_copy(struct netdev *netdev, int qid, struct dp_packet_batch *batch) continue; } - pkts[newcnt] = rte_pktmbuf_alloc(dev->dpdk_mp->mp); + temp = pkts[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(pkts[newcnt]); + pkts[newcnt] = NULL; + break; + } + temp = temp->next; + } if (!pkts[newcnt]) { dropped += batch->count - i; @@ -1801,10 +1820,34 @@ 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(pkts[newcnt], void *), - dp_packet_data(batch->packets[i]), size); + rte_pktmbuf_pkt_len(pkts[newcnt]) = size; + temp = pkts[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; + } + } + - pkts[newcnt]->nb_segs = batch->packets[i]->mbuf.nb_segs; + pkts[newcnt]->nb_segs = nb_segs; pkts[newcnt]->ol_flags = batch->packets[i]->mbuf.ol_flags; pkts[newcnt]->packet_type = batch->packets[i]->mbuf.packet_type; pkts[newcnt]->tx_offload = batch->packets[i]->mbuf.tx_offload;