From patchwork Sun Apr 30 16:15:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Qiu X-Patchwork-Id: 756895 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 3wGCRR6J5kz9s7p for ; Mon, 1 May 2017 02:18:59 +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="rZ1efZ5G"; dkim-atps=neutral Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 4381AB30; Sun, 30 Apr 2017 16:16:37 +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 7DC5BA88 for ; Sun, 30 Apr 2017 16:16:35 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pf0-f194.google.com (mail-pf0-f194.google.com [209.85.192.194]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 2C1F015B for ; Sun, 30 Apr 2017 16:16:35 +0000 (UTC) Received: by mail-pf0-f194.google.com with SMTP id o68so5794236pfj.2 for ; Sun, 30 Apr 2017 09:16:35 -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=+1rk/0KgyvtmoFWCglE/fZQQTioSzLm6daRh2tzWtTo=; b=rZ1efZ5GhMfeDCqNAbI9+XgMbuj1tRtTMNbHGINvSwVC1DCmtRSAzQhTr5mXgm9tLu xTHUU3zndNRXmsnos9ePALYYOTc74T9Sr/WwJj3Sf51cjUMhAH7BeihRUIofXCocKSPP 85yXxhOfjyEjXV7S36zWJyUMqtBr607Y1CvzDMyQ+aFiFnWctZlYhl5LqGK+BiQ6d31o aZqLqGV/mDLolbmtAWX9kfPEfu2jzkkCG19pbaUuoImxhFkFUctZKesxfFSCQ7iqFgFa 7XmYEa2Z9MHLvZvvcPLJ7gg5DTh5wbihezrY51MSCuOFyhIYhfrftXWR9YWIBZnQ88Rq Njjw== 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=+1rk/0KgyvtmoFWCglE/fZQQTioSzLm6daRh2tzWtTo=; b=jI+rvW3lFt60bSzOcCt1z7bMlew6tAtM2SlEjgaYRX16eVVNm+sc9u6y/3GKvjjO7E DBpOZ4h1ksGpKzsQzVWQhWM2sPfiOT2/hRBugYDycCMrIx+05AsA9lp+X3tNO4LUR6DH IiarJaOeK7bkY/6L7Wu9eEOUK9l+51b3FFOHpqHVQCkZULLqroQAMY6h92mkneSm7EVD 6rjO7+TlH8aET1Mm5q4LR9xN3/oLLkksjsk3aQkU6hN7g5QlWFuR7aK7B4EZ7XCGtoIf gfr2j5LLsoz0l6laqT8MEyVWiPgbUGSg/jhs5gVx6ULaUXfo4SwCdQbQpZzxsEclQXYL HBXg== X-Gm-Message-State: AN3rC/785/bVUJMB+ugJSMZfpSUejp8wmJ2Bp+n0fnASE3RmEgEeYdge 1mKo7ecCTnDeTw== X-Received: by 10.84.211.136 with SMTP id c8mr615867pli.115.1493568994801; Sun, 30 Apr 2017 09:16:34 -0700 (PDT) Received: from localhost.localdomain (softbank060067191191.bbtec.net. [60.67.191.191]) by smtp.gmail.com with ESMTPSA id b74sm20900540pfl.58.2017.04.30.09.16.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 30 Apr 2017 09:16:34 -0700 (PDT) From: Michael Qiu To: dev@openvswitch.org Date: Mon, 1 May 2017 00:15:34 +0800 Message-Id: <1493568934-3099-6-git-send-email-qdy220091330@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1493568934-3099-1-git-send-email-qdy220091330@gmail.com> References: <1493568934-3099-1-git-send-email-qdy220091330@gmail.com> X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM 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 | 55 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index ad92504..47e64ad 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++; }