From patchwork Fri Aug 11 15:52:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fischetti, Antonio" X-Patchwork-Id: 800627 X-Patchwork-Delegate: dlu998@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) 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 3xTV2h2cj2z9t2v for ; Sat, 12 Aug 2017 01:55:24 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id C17D6B5A; Fri, 11 Aug 2017 15:52:56 +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 1585EB14 for ; Fri, 11 Aug 2017 15:52:52 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id D0ED315C for ; Fri, 11 Aug 2017 15:52:51 +0000 (UTC) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Aug 2017 08:52:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.41,358,1498546800"; d="scan'208"; a="1002648558" Received: from sivswdev01.ir.intel.com (HELO localhost.localdomain) ([10.237.217.45]) by orsmga003.jf.intel.com with ESMTP; 11 Aug 2017 08:52:50 -0700 From: antonio.fischetti@intel.com To: dev@openvswitch.org Date: Fri, 11 Aug 2017 16:52:46 +0100 Message-Id: <1502466766-17370-5-git-send-email-antonio.fischetti@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1502466766-17370-1-git-send-email-antonio.fischetti@intel.com> References: <1502466766-17370-1-git-send-email-antonio.fischetti@intel.com> Subject: [ovs-dev] [PATCH v3 4/4] dp-packet: Use memcpy on dp_packet elements. 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 memcpy replaces the several single copies inside dp_packet_clone_with_headroom(). Signed-off-by: Antonio Fischetti --- I tested this change by comparing the CPU Time over a 60 sec analysis with VTune. In original ovs: dp_packet_clone_with_headroom 4.530s + this changes: dp_packet_clone_with_headroom 3.920s Further details were reported in this reply for v1 https://mail.openvswitch.org/pipermail/ovs-dev/2017-June/334536.html --- lib/dp-packet.c | 18 +++++++++--------- lib/dp-packet.h | 6 +++++- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/dp-packet.c b/lib/dp-packet.c index 67aa406..f4dbcb7 100644 --- a/lib/dp-packet.c +++ b/lib/dp-packet.c @@ -157,8 +157,9 @@ dp_packet_clone(const struct dp_packet *buffer) return dp_packet_clone_with_headroom(buffer, 0); } -/* Creates and returns a new dp_packet whose data are copied from 'buffer'. The - * returned dp_packet will additionally have 'headroom' bytes of headroom. */ +/* Creates and returns a new dp_packet whose data are copied from 'buffer'. + * The returned dp_packet will additionally have 'headroom' bytes of + * headroom. */ struct dp_packet * dp_packet_clone_with_headroom(const struct dp_packet *buffer, size_t headroom) { @@ -167,13 +168,12 @@ dp_packet_clone_with_headroom(const struct dp_packet *buffer, size_t headroom) new_buffer = dp_packet_clone_data_with_headroom(dp_packet_data(buffer), dp_packet_size(buffer), headroom); - new_buffer->l2_pad_size = buffer->l2_pad_size; - new_buffer->l2_5_ofs = buffer->l2_5_ofs; - new_buffer->l3_ofs = buffer->l3_ofs; - new_buffer->l4_ofs = buffer->l4_ofs; - new_buffer->md = buffer->md; - new_buffer->cutlen = buffer->cutlen; - new_buffer->packet_type = buffer->packet_type; + /* Copy the following fields into the returned buffer: l2_pad_size, + * l2_5_ofs, l3_ofs, l4_ofs, cutlen, packet_type and md. */ + memcpy(&new_buffer->l2_pad_size, &buffer->l2_pad_size, + sizeof(struct dp_packet) - + offsetof(struct dp_packet, l2_pad_size)); + #ifdef DPDK_NETDEV new_buffer->mbuf.ol_flags = buffer->mbuf.ol_flags; #else diff --git a/lib/dp-packet.h b/lib/dp-packet.h index 9dbb611..9cab7c7 100644 --- a/lib/dp-packet.h +++ b/lib/dp-packet.h @@ -40,7 +40,8 @@ enum OVS_PACKED_ENUM dp_packet_source { DPBUF_STACK, /* Un-movable stack space or static buffer. */ DPBUF_STUB, /* Starts on stack, may expand into heap. */ DPBUF_DPDK, /* buffer data is from DPDK allocated memory. - * ref to dp_packet_init_dpdk() in dp-packet.c. */ + * ref to dp_packet_init_dpdk() in dp-packet.c. + */ }; #define DP_PACKET_CONTEXT_SIZE 64 @@ -61,6 +62,9 @@ struct dp_packet { bool rss_hash_valid; /* Is the 'rss_hash' valid? */ #endif enum dp_packet_source source; /* Source of memory allocated as 'base'. */ + + /* All the following elements of this struct are copied by a single call + * to memcpy in dp_packet_clone_with_headroom. */ uint8_t l2_pad_size; /* Detected l2 padding size. * Padding is non-pullable. */ uint16_t l2_5_ofs; /* MPLS label stack offset, or UINT16_MAX */