From patchwork Tue Jan 17 16:35:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander H Duyck X-Patchwork-Id: 716292 X-Patchwork-Delegate: jeffrey.t.kirsher@intel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3v2whF1hjzz9ryk for ; Wed, 18 Jan 2017 03:35:41 +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="tF4WFqDD"; dkim-atps=neutral Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 5C94B81447; Tue, 17 Jan 2017 16:35:39 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TGSsT4aVrSUj; Tue, 17 Jan 2017 16:35:38 +0000 (UTC) Received: from ash.osuosl.org (ash.osuosl.org [140.211.166.34]) by whitealder.osuosl.org (Postfix) with ESMTP id 17E0A81658; Tue, 17 Jan 2017 16:35:38 +0000 (UTC) X-Original-To: intel-wired-lan@lists.osuosl.org Delivered-To: intel-wired-lan@lists.osuosl.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by ash.osuosl.org (Postfix) with ESMTP id E6A2D1C0306 for ; Tue, 17 Jan 2017 16:35:36 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id E352A23244 for ; Tue, 17 Jan 2017 16:35:36 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id t86A6w0mqsET for ; Tue, 17 Jan 2017 16:35:36 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) by silver.osuosl.org (Postfix) with ESMTPS id 397641FCFE for ; Tue, 17 Jan 2017 16:35:36 +0000 (UTC) Received: by mail-pg0-f67.google.com with SMTP id 75so8411885pgf.3 for ; Tue, 17 Jan 2017 08:35:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:date:message-id:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=uHzbIaYzWe2U7t+HkW1T6ADvKSkS/zyoDOxukpTefuA=; b=tF4WFqDDN3B8+V48jT+B3y4PzbPMyVLAK/11pIs8pnHIrahofhMTFa6YSqIraQItAg F8h0VLulrpBVxQ/sLnhyFp0IgCCWCCiwXvJ7fSfZForcRhvZdYCkOE/2SOs6ljalslWx GLvMpKpTnfYRpqJd+Dg/4dZvqMuaPFVORoHOLtGkc0FjayJ3q96SfVnYupQ9VRIEOw9n OusSX9iiky+mU6skvy/iDnQcp5qpkDe3Wv8a7EqCD2okrMUf5y+Lnlx5vFvi1W0gUO7J amgzWHt79mH/Igy0iVZr3eErG4aNhPHBBsk77IVvrX9mtKrH0FDjq2HZfbdcscSzknlS R3ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:date:message-id:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=uHzbIaYzWe2U7t+HkW1T6ADvKSkS/zyoDOxukpTefuA=; b=rtwUPAJyXmncghSiePA05KxVkYuUUmqs1WlpC5SFhSW072OIfbQRnS7NohYmUEFPWA /waJ9okTDdpmluNzVIXSUgsypy4Gi65af6d7wavKxYrQXc2IyiJ7jcTgnP36jFt9fIpv 9IkgDLIzNU6RZr9/LCxsWqi2mPNU47/RIguwM4+jWtaxzMH+fWrgoem6geHtGnBdFCMZ nLmd2r7o4O9I4axWeYuhzMcDZACmtv8x0hpCZVgMaiLKCp3E6LAGXTXxuX/vKAm7N9j0 XH/N36cRFG5aoXHMTP2/H/SlbRmpbKRHkiRnKCCbxueteTeoWGKjuNeApCDeAmpx9rXC Grmw== X-Gm-Message-State: AIkVDXJN/DM4VhrK4h19abSKkVinb7du76qjFNV3DFaabeu16QGo/+gERRyRHk5qCL4sww== X-Received: by 10.99.174.4 with SMTP id q4mr46449098pgf.178.1484670935605; Tue, 17 Jan 2017 08:35:35 -0800 (PST) Received: from localhost.localdomain ([2001:470:b:9c3:9e5c:8eff:fe4f:f2d0]) by smtp.gmail.com with ESMTPSA id i82sm8387783pfk.52.2017.01.17.08.35.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jan 2017 08:35:35 -0800 (PST) From: Alexander Duyck To: intel-wired-lan@lists.osuosl.org, jeffrey.t.kirsher@intel.com Date: Tue, 17 Jan 2017 08:35:34 -0800 Message-ID: <20170117163524.5423.68148.stgit@localhost.localdomain> In-Reply-To: <20170117163401.5423.37993.stgit@localhost.localdomain> References: <20170117163401.5423.37993.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Subject: [Intel-wired-lan] [next PATCH v2 01/11] ixgbe: Add function for checking to see if we can reuse page X-BeenThere: intel-wired-lan@lists.osuosl.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Intel Wired Ethernet Linux Kernel Driver Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-wired-lan-bounces@lists.osuosl.org Sender: "Intel-wired-lan" From: Alexander Duyck This patch consolidates the code for the ixgbe driver so that it is more inline with what is already in igb. The general idea is to just consolidate functions that represent logical steps in the Rx process so we can later update them more easily. Signed-off-by: Alexander Duyck Tested-by: Andrew Bowers --- v2: Fix missing rx_ring parameter for PAGE_SIZE > 4K drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 71 +++++++++++++++---------- 1 file changed, 42 insertions(+), 29 deletions(-) diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c index 3beadc8c7a0a..452a407013ef 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c @@ -1947,6 +1947,42 @@ static inline bool ixgbe_page_is_reserved(struct page *page) return (page_to_nid(page) != numa_mem_id()) || page_is_pfmemalloc(page); } +static bool ixgbe_can_reuse_rx_page(struct ixgbe_ring *rx_ring, + struct ixgbe_rx_buffer *rx_buffer, + struct page *page, + const unsigned int truesize) +{ +#if (PAGE_SIZE >= 8192) + unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) - + ixgbe_rx_bufsz(rx_ring); +#endif + /* avoid re-using remote pages */ + if (unlikely(ixgbe_page_is_reserved(page))) + return false; + +#if (PAGE_SIZE < 8192) + /* if we are only owner of page we can reuse it */ + if (unlikely(page_count(page) != 1)) + return false; + + /* flip page offset to other buffer */ + rx_buffer->page_offset ^= truesize; +#else + /* move offset up to the next cache line */ + rx_buffer->page_offset += truesize; + + if (rx_buffer->page_offset > last_offset) + return false; +#endif + + /* Even if we own the page, we are not allowed to use atomic_set() + * This would break get_page_unless_zero() users. + */ + page_ref_inc(page); + + return true; +} + /** * ixgbe_add_rx_frag - Add contents of Rx buffer to sk_buff * @rx_ring: rx descriptor ring to transact packets on @@ -1968,18 +2004,18 @@ static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring, struct sk_buff *skb) { struct page *page = rx_buffer->page; + unsigned char *va = page_address(page) + rx_buffer->page_offset; unsigned int size = le16_to_cpu(rx_desc->wb.upper.length); #if (PAGE_SIZE < 8192) unsigned int truesize = ixgbe_rx_bufsz(rx_ring); #else unsigned int truesize = ALIGN(size, L1_CACHE_BYTES); - unsigned int last_offset = ixgbe_rx_pg_size(rx_ring) - - ixgbe_rx_bufsz(rx_ring); #endif - if ((size <= IXGBE_RX_HDR_SIZE) && !skb_is_nonlinear(skb)) { - unsigned char *va = page_address(page) + rx_buffer->page_offset; + if (unlikely(skb_is_nonlinear(skb))) + goto add_tail_frag; + if (size <= IXGBE_RX_HDR_SIZE) { memcpy(__skb_put(skb, size), va, ALIGN(size, sizeof(long))); /* page is not reserved, we can reuse buffer as-is */ @@ -1991,34 +2027,11 @@ static bool ixgbe_add_rx_frag(struct ixgbe_ring *rx_ring, return false; } +add_tail_frag: skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, rx_buffer->page_offset, size, truesize); - /* avoid re-using remote pages */ - if (unlikely(ixgbe_page_is_reserved(page))) - return false; - -#if (PAGE_SIZE < 8192) - /* if we are only owner of page we can reuse it */ - if (unlikely(page_count(page) != 1)) - return false; - - /* flip page offset to other buffer */ - rx_buffer->page_offset ^= truesize; -#else - /* move offset up to the next cache line */ - rx_buffer->page_offset += truesize; - - if (rx_buffer->page_offset > last_offset) - return false; -#endif - - /* Even if we own the page, we are not allowed to use atomic_set() - * This would break get_page_unless_zero() users. - */ - page_ref_inc(page); - - return true; + return ixgbe_can_reuse_rx_page(rx_ring, rx_buffer, page, truesize); } static struct sk_buff *ixgbe_fetch_rx_buffer(struct ixgbe_ring *rx_ring,