From patchwork Tue Nov 10 11:01:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 11893847 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40B2BC388F7 for ; Tue, 10 Nov 2020 11:02:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D6822207BB for ; Tue, 10 Nov 2020 11:02:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HDo2tLvT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730164AbgKJLCI (ORCPT ); Tue, 10 Nov 2020 06:02:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729630AbgKJLCI (ORCPT ); Tue, 10 Nov 2020 06:02:08 -0500 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB74CC0613CF; Tue, 10 Nov 2020 03:02:07 -0800 (PST) Received: by mail-pg1-x541.google.com with SMTP id h6so9848109pgk.4; Tue, 10 Nov 2020 03:02:07 -0800 (PST) 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=+SbxyZahfMfXnU/FChOm2quTfC2gyIuFdUfnHAtZnoI=; b=HDo2tLvTPlUvSl/ynyu+g51F9cSukXV+T7MVRGwd/ECz1C+0G0+I2wcLPsSbC18oXd inwKKlEU3sDBIhLVNZk+P/sw4/DfsG0ikuc8rcDBubiB8nStQezh2QFpA9tVWy/mmYXm 0NGQm50exAolDD2y6mImHFcw8p691Yr8NaP+eFDCmJ+Ep0mHz2HmqPLgWqxyRjBm+x/2 wrkiY0LtzeZvMJXty6GT15PD+2pZog2E2BfDbekl3yL+wTk6+IBdbl4rq/X3ialkWXa/ D5nNSkCip85Tn6/xHsVoPBXLanXtl9GKLQslz/3j3gvSFeTCMeS6SxuMRQ5eomkKYJ/f Q2Vg== 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=+SbxyZahfMfXnU/FChOm2quTfC2gyIuFdUfnHAtZnoI=; b=oOOt8918G75V2PJdGrFK71DFQ61YEGILrQgYyK6pgRfTJQcQJrWS779t+lmJ0pe6n7 NbW8kA7dGbnpcxYuiIT/PeQY11AUeiKJOzqzsIr004OHXtbW9WPKctiSywiSgxFbwy2w dEVB6hRFYzlYgRtZw8mDiYlS4qdbHxy9Pu//bD//8Yy997XgyPLpbmSq6mxTXceIN2Ba fQpj+1lgEfRFZYPLa7Juhmp9p2AqO6bRBHP1iA3aIngDQEOFkKP/Ki3IaCKiqeR3Y73l 66d0pzex/RqMKHIa/JN1U8V3X32l/GfnTro4MjPGd8TFfw+elEQtU66t0haGCXN+FoIz Hp3Q== X-Gm-Message-State: AOAM531atR93xP7skoQ3U+S/pLVno8XLoRbFTN1sCRKsPKuaodpuI5Jn gqJOh1pFx2r2hysCkp9M0JA= X-Google-Smtp-Source: ABdhPJzxXLLj8wlpgU6Uci22CTaPUGpi5ulPRN9nH5GXepx6NeUX+461wyJD5OnMiToM2Fxo8oX5zQ== X-Received: by 2002:a63:4912:: with SMTP id w18mr17141230pga.131.1605006127544; Tue, 10 Nov 2020 03:02:07 -0800 (PST) Received: from VM.ger.corp.intel.com ([192.55.55.45]) by smtp.gmail.com with ESMTPSA id 22sm3012024pjb.40.2020.11.10.03.02.02 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Nov 2020 03:02:06 -0800 (PST) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn.topel@intel.com, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, jonathan.lemon@gmail.com, kuba@kernel.org, john.fastabend@gmail.com Cc: bpf@vger.kernel.org, jeffrey.t.kirsher@intel.com, anthony.l.nguyen@intel.com, maciej.fijalkowski@intel.com, maciejromanfijalkowski@gmail.com, intel-wired-lan@lists.osuosl.org Subject: [PATCH bpf-next v2 1/5] samples/bpf: increment Tx stats at sending Date: Tue, 10 Nov 2020 12:01:30 +0100 Message-Id: <1605006094-31097-2-git-send-email-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1605006094-31097-1-git-send-email-magnus.karlsson@gmail.com> References: <1605006094-31097-1-git-send-email-magnus.karlsson@gmail.com> Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Increment the statistics over how many Tx packets have been sent at the time of sending instead of at the time of completion. This as a completion event means that the buffer has been sent AND returned to user space. The packet always gets sent shortly after sendto() is called. The kernel might, for performance reasons, decide to not return every single buffer to user space immediately after sending, for example, only after a batch of packets have been transmitted. Incrementing the number of packets sent at completion, will in that case be confusing as if you send a single packet, the counter might show zero for a while even though the packet has been transmitted. Signed-off-by: Magnus Karlsson Acked-by: John Fastabend --- samples/bpf/xdpsock_user.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c index 1149e94..2567f0d 100644 --- a/samples/bpf/xdpsock_user.c +++ b/samples/bpf/xdpsock_user.c @@ -1146,7 +1146,6 @@ static inline void complete_tx_l2fwd(struct xsk_socket_info *xsk, xsk_ring_prod__submit(&xsk->umem->fq, rcvd); xsk_ring_cons__release(&xsk->umem->cq, rcvd); xsk->outstanding_tx -= rcvd; - xsk->ring_stats.tx_npkts += rcvd; } } @@ -1168,7 +1167,6 @@ static inline void complete_tx_only(struct xsk_socket_info *xsk, if (rcvd > 0) { xsk_ring_cons__release(&xsk->umem->cq, rcvd); xsk->outstanding_tx -= rcvd; - xsk->ring_stats.tx_npkts += rcvd; } } @@ -1260,6 +1258,7 @@ static void tx_only(struct xsk_socket_info *xsk, u32 *frame_nb, int batch_size) } xsk_ring_prod__submit(&xsk->tx, batch_size); + xsk->ring_stats.tx_npkts += batch_size; xsk->outstanding_tx += batch_size; *frame_nb += batch_size; *frame_nb %= NUM_FRAMES; @@ -1348,6 +1347,7 @@ static void l2fwd(struct xsk_socket_info *xsk, struct pollfd *fds) } return; } + xsk->ring_stats.rx_npkts += rcvd; ret = xsk_ring_prod__reserve(&xsk->tx, rcvd, &idx_tx); while (ret != rcvd) { @@ -1379,7 +1379,7 @@ static void l2fwd(struct xsk_socket_info *xsk, struct pollfd *fds) xsk_ring_prod__submit(&xsk->tx, rcvd); xsk_ring_cons__release(&xsk->rx, rcvd); - xsk->ring_stats.rx_npkts += rcvd; + xsk->ring_stats.tx_npkts += rcvd; xsk->outstanding_tx += rcvd; } From patchwork Tue Nov 10 11:01:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 11893849 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E190C388F7 for ; Tue, 10 Nov 2020 11:02:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E57ED2076E for ; Tue, 10 Nov 2020 11:02:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="J4S9UgYK" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726688AbgKJLCQ (ORCPT ); Tue, 10 Nov 2020 06:02:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726344AbgKJLCO (ORCPT ); Tue, 10 Nov 2020 06:02:14 -0500 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5788C0613CF; Tue, 10 Nov 2020 03:02:12 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id 10so11111643pfp.5; Tue, 10 Nov 2020 03:02:12 -0800 (PST) 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=KQXOqU3sgAKcC6WLzuY/tSnBXRqhvqvJ7oAX30tadAw=; b=J4S9UgYKANhxiw2JmO3tlzoy5UuSeHrXUJCm0oVAE7sN+LrVEDHg2UxiD99M5qNGGm blEFWXeW+4xeniL2ggf6nJuaU80JpCYjGgRyZd9NFL3lxuEeWNZxvT5R6hfwLtL0Cpls KORD1J0PVKV1/BVlcTJl+FGLs5/3cierBUEx8vNzJMrh8FAo0sAzgJAPVJddki2BFI5f 7HB4QlCg6HpCmTX5j6CxeUycukZI+wz2j2ktrXwspHooEuNoDFkRw64brjF6z2bdL4WU fT26VWnb8FrHnvlk410js1EX/LxlDFRUet0MOajNOPswMD2GVNFJBv4B9K8lsVDGpcQe 7Xfg== 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=KQXOqU3sgAKcC6WLzuY/tSnBXRqhvqvJ7oAX30tadAw=; b=YUBIPlWLyhfw/Ze60bEkoufizs67kf+dIzeqAeuqlyIEkyS38URMDfvSQIyX5BfeZ/ PS36JJ8ME5olTQEQxT9FyyD5MEHBNmKncAWFolDL1cY5BYG7OugpifobKjho+IrOxOM3 OJjyVYbP6mEQJefHeM5kU3IdH/USgyv43rCMsXjY40xRLP2XBcWHTjvLIDT4bTobqyGv dWcBGr/fSTHY3FwYiNnOL99GT346A5Hr2P0qYY/ETjpJmfCA4ezVRwoSYikjLjFBTTTF 2LaJAGYKTyZmH1XYVaXCGGKze7jh5qT62L1XV1niAVJ2pvqC2VMC4vggHV9j7unOXePt lGNA== X-Gm-Message-State: AOAM532vf28zgDzuncqJqyxot07tkN5kmuolinpwiLrEN1OcbJMLPf3t 88gZAJHRX3LMDhCTc5Xm5fc= X-Google-Smtp-Source: ABdhPJwRGuwTsExWngoV4BxMxccDa3HVjgGDrCrK4lSaC31y1Ni9oHZqVYAKWALykQm97u8XgALuaw== X-Received: by 2002:a62:1901:0:b029:18c:659c:e55f with SMTP id 1-20020a6219010000b029018c659ce55fmr469087pfz.51.1605006132418; Tue, 10 Nov 2020 03:02:12 -0800 (PST) Received: from VM.ger.corp.intel.com ([192.55.55.45]) by smtp.gmail.com with ESMTPSA id 22sm3012024pjb.40.2020.11.10.03.02.07 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Nov 2020 03:02:11 -0800 (PST) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn.topel@intel.com, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, jonathan.lemon@gmail.com, kuba@kernel.org, john.fastabend@gmail.com Cc: bpf@vger.kernel.org, jeffrey.t.kirsher@intel.com, anthony.l.nguyen@intel.com, maciej.fijalkowski@intel.com, maciejromanfijalkowski@gmail.com, intel-wired-lan@lists.osuosl.org Subject: [PATCH bpf-next v2 2/5] i40e: remove unnecessary sw_ring access from xsk Tx Date: Tue, 10 Nov 2020 12:01:31 +0100 Message-Id: <1605006094-31097-3-git-send-email-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1605006094-31097-1-git-send-email-magnus.karlsson@gmail.com> References: <1605006094-31097-1-git-send-email-magnus.karlsson@gmail.com> Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Remove the unnecessary access to the software ring for the AF_XDP zero-copy driver. This was used to record the length of the packet so that the driver Tx completion code could sum this up to produce the total bytes sent. This is now performed during the transmission of the packet, so no need to record this in the software ring. Signed-off-by: Magnus Karlsson Acked-by: John Fastabend --- drivers/net/ethernet/intel/i40e/i40e_xsk.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_xsk.c b/drivers/net/ethernet/intel/i40e/i40e_xsk.c index 6acede0..61aa1fc 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_xsk.c +++ b/drivers/net/ethernet/intel/i40e/i40e_xsk.c @@ -392,7 +392,6 @@ static bool i40e_xmit_zc(struct i40e_ring *xdp_ring, unsigned int budget) { unsigned int sent_frames = 0, total_bytes = 0; struct i40e_tx_desc *tx_desc = NULL; - struct i40e_tx_buffer *tx_bi; struct xdp_desc desc; dma_addr_t dma; @@ -404,9 +403,6 @@ static bool i40e_xmit_zc(struct i40e_ring *xdp_ring, unsigned int budget) xsk_buff_raw_dma_sync_for_device(xdp_ring->xsk_pool, dma, desc.len); - tx_bi = &xdp_ring->tx_bi[xdp_ring->next_to_use]; - tx_bi->bytecount = desc.len; - tx_desc = I40E_TX_DESC(xdp_ring, xdp_ring->next_to_use); tx_desc->buffer_addr = cpu_to_le64(dma); tx_desc->cmd_type_offset_bsz = @@ -415,7 +411,7 @@ static bool i40e_xmit_zc(struct i40e_ring *xdp_ring, unsigned int budget) 0, desc.len, 0); sent_frames++; - total_bytes += tx_bi->bytecount; + total_bytes += desc.len; xdp_ring->next_to_use++; if (xdp_ring->next_to_use == xdp_ring->count) From patchwork Tue Nov 10 11:01:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 11893851 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02E37C55ABD for ; Tue, 10 Nov 2020 11:02:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 900D420795 for ; Tue, 10 Nov 2020 11:02:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ukDfonde" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726344AbgKJLCT (ORCPT ); Tue, 10 Nov 2020 06:02:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730291AbgKJLCR (ORCPT ); Tue, 10 Nov 2020 06:02:17 -0500 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AF0EC0613D1; Tue, 10 Nov 2020 03:02:17 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id w14so8478418pfd.7; Tue, 10 Nov 2020 03:02:17 -0800 (PST) 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=bAeSUpBLbjOCEiLqRz8yHChict8yQeBE89i4qMRCUYE=; b=ukDfondez4f1XSppfnFc+BqF8nQ4L3FdFhCthj7LN4hHv62Bc6btOnZghg75/vUhoC SgBLIjpr3dnU39LDAiTywvdqiYorGMLmYViWeiBMTc2vcSU+oKypGOfj3ctC4gOMAqv1 2BxuTVAg0FPF7IYzCWFasiov0yQN00GObJQWmVDQ4INjoONNHlP8MeV9Tsl3sXBziEHP dzVv+3U7r4iVqELVVMQkBkItHS2+aJ4nLgG4wTWhbrJ0LQNlPl1h+sUQDbUzxHmfXAVr R/zwAK00jdJuFb0ZQokoY75S4oyzlHUfRhlLxLRbi0CMB6AxlRB1g635DAAC3vop7rj8 dHDQ== 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=bAeSUpBLbjOCEiLqRz8yHChict8yQeBE89i4qMRCUYE=; b=GEFr75U2pvKv3PKRrDraw4VuA8PWPPxx/9rHXBZQjt8rV8b3xxE/hwwDojC7oDlUPL Ck+rX4TrWoDPqUuQE6rr0TdpFPJ66JMC6gAP7hS/LfE7f4bQth1MUGh7NwTa9ibmhEy6 nvohEyifYBDomW7O0EB61ebdCqK8aUSwPc3lKhxRQLFCObXoG3qdqSZj2ykzjAZcH8o2 X7togiAx3oReD4eIfU+cVoB6GAStXm0VThzGmD1/+yHbDBGMzrEp/Bu5/FrPsuMP6dj5 N/RJiK0TpfSFjNdu5WZU9pKPJ+qMtxsN9TrTKw4OOvZOrq/K7ZvQYOMelDm7qWFIEZlT En3w== X-Gm-Message-State: AOAM5307AfIDe6BX2vvvfDfh0hugdAYhyGqwTyJNEFiHqYUm3g/gKmAF VFqVesHe3e02+0+ZWUUpRRA= X-Google-Smtp-Source: ABdhPJxAFPJE7ck3w/rJbVJgGyaBFc5nGW5An7BtutpvMMirfepfVJnKzWTpZoLEvdslA1CaiziadA== X-Received: by 2002:a17:90b:395:: with SMTP id ga21mr4396814pjb.219.1605006137204; Tue, 10 Nov 2020 03:02:17 -0800 (PST) Received: from VM.ger.corp.intel.com ([192.55.55.45]) by smtp.gmail.com with ESMTPSA id 22sm3012024pjb.40.2020.11.10.03.02.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Nov 2020 03:02:16 -0800 (PST) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn.topel@intel.com, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, jonathan.lemon@gmail.com, kuba@kernel.org, john.fastabend@gmail.com Cc: bpf@vger.kernel.org, jeffrey.t.kirsher@intel.com, anthony.l.nguyen@intel.com, maciej.fijalkowski@intel.com, maciejromanfijalkowski@gmail.com, intel-wired-lan@lists.osuosl.org Subject: [PATCH bpf-next v2 3/5] xsk: introduce padding between more ring pointers Date: Tue, 10 Nov 2020 12:01:32 +0100 Message-Id: <1605006094-31097-4-git-send-email-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1605006094-31097-1-git-send-email-magnus.karlsson@gmail.com> References: <1605006094-31097-1-git-send-email-magnus.karlsson@gmail.com> Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Introduce one cache line worth of padding between the consumer pointer and the flags field as well as between the flags field and the start of the descriptors in all the lockless rings. This so that the x86 HW adjacency prefetcher will not prefetch the adjacent pointer/field when only one pointer/field is going to be used. This improves throughput performance for the l2fwd sample app with 1% on my machine with HW prefetching turned on in the BIOS. Signed-off-by: Magnus Karlsson Acked-by: John Fastabend --- net/xdp/xsk_queue.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h index cdb9cf3..74fac80 100644 --- a/net/xdp/xsk_queue.h +++ b/net/xdp/xsk_queue.h @@ -18,9 +18,11 @@ struct xdp_ring { /* Hinder the adjacent cache prefetcher to prefetch the consumer * pointer if the producer pointer is touched and vice versa. */ - u32 pad ____cacheline_aligned_in_smp; + u32 pad1 ____cacheline_aligned_in_smp; u32 consumer ____cacheline_aligned_in_smp; + u32 pad2 ____cacheline_aligned_in_smp; u32 flags; + u32 pad3 ____cacheline_aligned_in_smp; }; /* Used for the RX and TX queues for packets */ From patchwork Tue Nov 10 11:01:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 11893853 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1C89C4742C for ; Tue, 10 Nov 2020 11:02:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6AB3E207BB for ; Tue, 10 Nov 2020 11:02:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GunPM72N" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730497AbgKJLCX (ORCPT ); Tue, 10 Nov 2020 06:02:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730291AbgKJLCW (ORCPT ); Tue, 10 Nov 2020 06:02:22 -0500 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F781C0613CF; Tue, 10 Nov 2020 03:02:22 -0800 (PST) Received: by mail-pf1-x443.google.com with SMTP id c20so11100242pfr.8; Tue, 10 Nov 2020 03:02:22 -0800 (PST) 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=djrW28VfAz1HCiwbLKji+0pv2e/bXUYA6HXA2jiTqUM=; b=GunPM72Nn6oN4zIit2fV98MNs3EFcmOi+VRfJFiIMEazgddrEaulBzmMQ3yMUshi5a hBuZnb2ljJljrha6iTllPvggn2LqxnpB7GcC9E4kjs/8rGA1pXczE0GQX4naLiH4WRUL Jl2FQn2pah8L5qcUqB8wEfmk8wpiYGSdWRohEwnJi4j38/I9bVGJayarzRrCtexVmiOB 6mXSpOjv9S1XomByZo+9ZlJZC/S2sfup2b8tgJqLgU/NNmuTX3Y/VHs57iIqbRY0vgGW 11qV4yA+DKpwI1vhHhDM64XLebyCTlt9Dc+LBuxfKF2dbGSU+uO3I4h7+QnM65KkYVJB tBTQ== 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=djrW28VfAz1HCiwbLKji+0pv2e/bXUYA6HXA2jiTqUM=; b=X1jXb6ytyP4xXFVRuhrt+6mqRmYg3k+nX6uo9RykeWfMHXTsod9k7QAaY1/J3X5zfq ORLCnDAeN+3N+bCc0b4PZI6+9BqmGV8cGhH+EstGoUaZflYdYsb8l2kaYOGI/l71R1Op x7gKsrQUIQn2EBKOFfDHpwe6eC/HVOt9iBykzFs6zKhmEPn6GCmJaEobzrh3KG48MP2/ 45zH24uItzT+KNH0UDzXrS0DwZpztnb+0UvGzKBoya8CVle29uuz9srgWfqbVEH6qKED DTAOf2iYUQT10XNZ29wXl8Vxds7+GtLL5TBaTQcDQ6GHVdLfql7Bx3TrVvPAGFaZMqb1 i3Rw== X-Gm-Message-State: AOAM533PCSLaVcTo/LnEIlycDGzyPHbIgCoV0HAOVDquHfaE+fULkEkn QZz0cOxDZokBzS1xF8Ie3GA= X-Google-Smtp-Source: ABdhPJyeU4Y/5WnllPN6a5dgbTVm95BvvTXN4VRuLQgNipyKKSXoPEnn/H1/6cxCU18rRXxmsw8GHA== X-Received: by 2002:a62:1b0e:0:b029:164:228b:f063 with SMTP id b14-20020a621b0e0000b0290164228bf063mr17671308pfb.75.1605006142099; Tue, 10 Nov 2020 03:02:22 -0800 (PST) Received: from VM.ger.corp.intel.com ([192.55.55.45]) by smtp.gmail.com with ESMTPSA id 22sm3012024pjb.40.2020.11.10.03.02.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Nov 2020 03:02:21 -0800 (PST) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn.topel@intel.com, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, jonathan.lemon@gmail.com, kuba@kernel.org, john.fastabend@gmail.com Cc: bpf@vger.kernel.org, jeffrey.t.kirsher@intel.com, anthony.l.nguyen@intel.com, maciej.fijalkowski@intel.com, maciejromanfijalkowski@gmail.com, intel-wired-lan@lists.osuosl.org Subject: [PATCH bpf-next v2 4/5] xsk: introduce batched Tx descriptor interfaces Date: Tue, 10 Nov 2020 12:01:33 +0100 Message-Id: <1605006094-31097-5-git-send-email-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1605006094-31097-1-git-send-email-magnus.karlsson@gmail.com> References: <1605006094-31097-1-git-send-email-magnus.karlsson@gmail.com> Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Introduce batched descriptor interfaces in the xsk core code for the Tx path to be used in the driver to write a code path with higher performance. This interface will be used by the i40e driver in the next patch. Though other drivers would likely benefit from this new interface too. Note that batching is only implemented for the common case when there is only one socket bound to the same device and queue id. When this is not the case, we fall back to the old non-batched version of the function. Signed-off-by: Magnus Karlsson Acked-by: John Fastabend --- include/net/xdp_sock_drv.h | 7 ++++ net/xdp/xsk.c | 57 ++++++++++++++++++++++++++++ net/xdp/xsk_queue.h | 92 +++++++++++++++++++++++++++++++++++++++------- 3 files changed, 143 insertions(+), 13 deletions(-) diff --git a/include/net/xdp_sock_drv.h b/include/net/xdp_sock_drv.h index 5b1ee8a..4e295541 100644 --- a/include/net/xdp_sock_drv.h +++ b/include/net/xdp_sock_drv.h @@ -13,6 +13,7 @@ void xsk_tx_completed(struct xsk_buff_pool *pool, u32 nb_entries); bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc); +u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, struct xdp_desc *desc, u32 max); void xsk_tx_release(struct xsk_buff_pool *pool); struct xsk_buff_pool *xsk_get_pool_from_qid(struct net_device *dev, u16 queue_id); @@ -128,6 +129,12 @@ static inline bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, return false; } +static inline u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, struct xdp_desc *desc, + u32 max) +{ + return 0; +} + static inline void xsk_tx_release(struct xsk_buff_pool *pool) { } diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c index b71a32e..37f70cd 100644 --- a/net/xdp/xsk.c +++ b/net/xdp/xsk.c @@ -332,6 +332,63 @@ bool xsk_tx_peek_desc(struct xsk_buff_pool *pool, struct xdp_desc *desc) } EXPORT_SYMBOL(xsk_tx_peek_desc); +static u32 xsk_tx_peek_release_fallback(struct xsk_buff_pool *pool, struct xdp_desc *descs, + u32 max_entries) +{ + u32 nb_pkts = 0; + + while (nb_pkts < max_entries && xsk_tx_peek_desc(pool, &descs[nb_pkts])) + nb_pkts++; + + xsk_tx_release(pool); + return nb_pkts; +} + +u32 xsk_tx_peek_release_desc_batch(struct xsk_buff_pool *pool, struct xdp_desc *descs, + u32 max_entries) +{ + struct xdp_sock *xs; + u32 nb_pkts; + + rcu_read_lock(); + if (!list_is_singular(&pool->xsk_tx_list)) { + /* Fallback to the non-batched version */ + rcu_read_unlock(); + return xsk_tx_peek_release_fallback(pool, descs, max_entries); + } + + xs = list_first_or_null_rcu(&pool->xsk_tx_list, struct xdp_sock, tx_list); + if (!xs) { + nb_pkts = 0; + goto out; + } + + nb_pkts = xskq_cons_peek_desc_batch(xs->tx, descs, pool, max_entries); + if (!nb_pkts) { + xs->tx->queue_empty_descs++; + goto out; + } + + /* This is the backpressure mechanism for the Tx path. Try to + * reserve space in the completion queue for all packets, but + * if there are fewer slots available, just process that many + * packets. This avoids having to implement any buffering in + * the Tx path. + */ + nb_pkts = xskq_prod_reserve_addr_batch(pool->cq, descs, nb_pkts); + if (!nb_pkts) + goto out; + + xskq_cons_release_n(xs->tx, nb_pkts); + __xskq_cons_release(xs->tx); + xs->sk.sk_write_space(&xs->sk); + +out: + rcu_read_unlock(); + return nb_pkts; +} +EXPORT_SYMBOL(xsk_tx_peek_release_desc_batch); + static int xsk_wakeup(struct xdp_sock *xs, u8 flags) { struct net_device *dev = xs->dev; diff --git a/net/xdp/xsk_queue.h b/net/xdp/xsk_queue.h index 74fac80..7350f87 100644 --- a/net/xdp/xsk_queue.h +++ b/net/xdp/xsk_queue.h @@ -199,6 +199,33 @@ static inline bool xskq_cons_read_desc(struct xsk_queue *q, return false; } +static inline u32 xskq_cons_read_desc_batch(struct xsk_queue *q, + struct xdp_desc *descs, + struct xsk_buff_pool *pool, u32 max) +{ + u32 cached_cons = q->cached_cons, nb_entries = 0; + + while (cached_cons != q->cached_prod && nb_entries < max) { + struct xdp_rxtx_ring *ring = (struct xdp_rxtx_ring *)q->ring; + u32 idx = cached_cons & q->ring_mask; + + descs[nb_entries] = ring->desc[idx]; + if (unlikely(!xskq_cons_is_valid_desc(q, &descs[nb_entries], pool))) { + if (nb_entries) { + /* Invalid entry detected. Return what we have. */ + return nb_entries; + } + /* Use non-batch version to progress beyond invalid entry/entries */ + return xskq_cons_read_desc(q, descs, pool) ? 1 : 0; + } + + nb_entries++; + cached_cons++; + } + + return nb_entries; +} + /* Functions for consumers */ static inline void __xskq_cons_release(struct xsk_queue *q) @@ -220,17 +247,22 @@ static inline void xskq_cons_get_entries(struct xsk_queue *q) __xskq_cons_peek(q); } -static inline bool xskq_cons_has_entries(struct xsk_queue *q, u32 cnt) +static inline u32 xskq_cons_nb_entries(struct xsk_queue *q, u32 max) { u32 entries = q->cached_prod - q->cached_cons; - if (entries >= cnt) - return true; + if (entries >= max) + return max; __xskq_cons_peek(q); entries = q->cached_prod - q->cached_cons; - return entries >= cnt; + return entries >= max ? max : entries; +} + +static inline bool xskq_cons_has_entries(struct xsk_queue *q, u32 cnt) +{ + return xskq_cons_nb_entries(q, cnt) >= cnt ? true : false; } static inline bool xskq_cons_peek_addr_unchecked(struct xsk_queue *q, u64 *addr) @@ -249,16 +281,28 @@ static inline bool xskq_cons_peek_desc(struct xsk_queue *q, return xskq_cons_read_desc(q, desc, pool); } +static inline u32 xskq_cons_peek_desc_batch(struct xsk_queue *q, struct xdp_desc *descs, + struct xsk_buff_pool *pool, u32 max) +{ + u32 entries = xskq_cons_nb_entries(q, max); + + return xskq_cons_read_desc_batch(q, descs, pool, entries); +} + +/* To improve performance in the xskq_cons_release functions, only update local state here. + * Reflect this to global state when we get new entries from the ring in + * xskq_cons_get_entries() and whenever Rx or Tx processing are completed in the NAPI loop. + */ static inline void xskq_cons_release(struct xsk_queue *q) { - /* To improve performance, only update local state here. - * Reflect this to global state when we get new entries - * from the ring in xskq_cons_get_entries() and whenever - * Rx or Tx processing are completed in the NAPI loop. - */ q->cached_cons++; } +static inline void xskq_cons_release_n(struct xsk_queue *q, u32 cnt) +{ + q->cached_cons += cnt; +} + static inline bool xskq_cons_is_full(struct xsk_queue *q) { /* No barriers needed since data is not accessed */ @@ -268,18 +312,23 @@ static inline bool xskq_cons_is_full(struct xsk_queue *q) /* Functions for producers */ -static inline bool xskq_prod_is_full(struct xsk_queue *q) +static inline u32 xskq_prod_nb_free(struct xsk_queue *q, u32 max) { u32 free_entries = q->nentries - (q->cached_prod - q->cached_cons); - if (free_entries) - return false; + if (free_entries >= max) + return max; /* Refresh the local tail pointer */ q->cached_cons = READ_ONCE(q->ring->consumer); free_entries = q->nentries - (q->cached_prod - q->cached_cons); - return !free_entries; + return free_entries >= max ? max : free_entries; +} + +static inline bool xskq_prod_is_full(struct xsk_queue *q) +{ + return xskq_prod_nb_free(q, 1) ? false : true; } static inline int xskq_prod_reserve(struct xsk_queue *q) @@ -304,6 +353,23 @@ static inline int xskq_prod_reserve_addr(struct xsk_queue *q, u64 addr) return 0; } +static inline u32 xskq_prod_reserve_addr_batch(struct xsk_queue *q, struct xdp_desc *descs, + u32 max) +{ + struct xdp_umem_ring *ring = (struct xdp_umem_ring *)q->ring; + u32 nb_entries, i, cached_prod; + + nb_entries = xskq_prod_nb_free(q, max); + + /* A, matches D */ + cached_prod = q->cached_prod; + for (i = 0; i < nb_entries; i++) + ring->desc[cached_prod++ & q->ring_mask] = descs[i].addr; + q->cached_prod = cached_prod; + + return nb_entries; +} + static inline int xskq_prod_reserve_desc(struct xsk_queue *q, u64 addr, u32 len) { From patchwork Tue Nov 10 11:01:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Karlsson X-Patchwork-Id: 11893857 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B79EAC4742C for ; Tue, 10 Nov 2020 11:02:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 60068207D3 for ; Tue, 10 Nov 2020 11:02:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZzbCjSro" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730751AbgKJLC2 (ORCPT ); Tue, 10 Nov 2020 06:02:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730291AbgKJLC1 (ORCPT ); Tue, 10 Nov 2020 06:02:27 -0500 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67CB4C0613CF; Tue, 10 Nov 2020 03:02:27 -0800 (PST) Received: by mail-pg1-x544.google.com with SMTP id r186so9861660pgr.0; Tue, 10 Nov 2020 03:02:27 -0800 (PST) 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=Np8Kwt0HgYs9CiWR284tIJBNdXajPeiuljd5LB33iOo=; b=ZzbCjSroItNvdMfepjeqAArqNYIKkDILb1A2SstxWnNgalJmtyzVsmZ5OrtCgXrGUV zJ83s9Ll2Yrng7BCz/zip8+fweAac7QBN3oYc8NqhGZQoymQDefh4nU5Ow86foqYDP8J EtW+pwdmT5/M3dkmm+JWi/g6/hGeTNnenOIu2xo+BlBEkD3vPOqgiJdI6LaXOaenlg8Z xYTt/PCkuqwTvZfu9LXVUWQb2ewNG5LxTpnURB45StJMMR89lIOl7aQuiw13pxYty+PH nfAOv0LvkI1pw0UrsEDUCakwQxoC/BRxOMDOTgp0Oi0vQz/0/usoZUpeap+G0v7KuUel wLFg== 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=Np8Kwt0HgYs9CiWR284tIJBNdXajPeiuljd5LB33iOo=; b=VRzzbh6nE8qQ9uApPwqgPPxwNwbT+vGKsWDKuTlb+cuikIg7r2jJ4y6eocFCBO2Bf+ 7wWsteLr8VJApl3iVtzfxQG7MrA6SsP1DvMbxA56yH24sWRwPyma2Dka1pZNQs0/4aIT yRFueHla4rWLRDSuRTsfQmWiWTqjlc0/0xKIjkiQrnFcoIAgPZMrDE5SYV/qs1W5jdr1 1d84bYnJbprk2gPJYnKLNbsDtNe4ivwutXHY2bQ5cMhvlmj/s75OUKsAE6qI1JSzRGHx 0lYiEEOrFtZehDGrx1DQjRxrVrupjJQYnCGt/QUQwj452DUVMxHLcrctziZpjxSLbuic O6ZQ== X-Gm-Message-State: AOAM531vwoRE/jQzEx3KrRYcK2OE/LoxU+DSbIBjOnlfhqy/zQSp/JcG g4ELcWS+vxik0tOsHZnbruE= X-Google-Smtp-Source: ABdhPJxgIiZYzHp+Qdpymo3t9JY0huD1GMCTe+j+bFgmutjAPVvpKaJSyxfvX2pRQUWqSF3+lOXsNg== X-Received: by 2002:a62:7e14:0:b029:18a:d515:dc47 with SMTP id z20-20020a627e140000b029018ad515dc47mr18316970pfc.78.1605006146962; Tue, 10 Nov 2020 03:02:26 -0800 (PST) Received: from VM.ger.corp.intel.com ([192.55.55.45]) by smtp.gmail.com with ESMTPSA id 22sm3012024pjb.40.2020.11.10.03.02.22 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Nov 2020 03:02:26 -0800 (PST) From: Magnus Karlsson To: magnus.karlsson@intel.com, bjorn.topel@intel.com, ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org, jonathan.lemon@gmail.com, kuba@kernel.org, john.fastabend@gmail.com Cc: bpf@vger.kernel.org, jeffrey.t.kirsher@intel.com, anthony.l.nguyen@intel.com, maciej.fijalkowski@intel.com, maciejromanfijalkowski@gmail.com, intel-wired-lan@lists.osuosl.org Subject: [PATCH bpf-next v2 5/5] i40e: use batched xsk Tx interfaces to increase performance Date: Tue, 10 Nov 2020 12:01:34 +0100 Message-Id: <1605006094-31097-6-git-send-email-magnus.karlsson@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1605006094-31097-1-git-send-email-magnus.karlsson@gmail.com> References: <1605006094-31097-1-git-send-email-magnus.karlsson@gmail.com> Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Magnus Karlsson Use the new batched xsk interfaces for the Tx path in the i40e driver to improve performance. On my machine, this yields a throughput increase of 4% for the l2fwd sample app in xdpsock. If we instead just look at the Tx part, this patch set increases throughput with above 20% for Tx. Note that I had to explicitly loop unroll the inner loop to get to this performance level, by using a pragma. It is honored by both clang and gcc and should be ignored by versions that do not support it. Using the -funroll-loops compiler command line switch on the source file resulted in a loop unrolling on a higher level that lead to a performance decrease instead of an increase. Signed-off-by: Magnus Karlsson Acked-by: John Fastabend Reported-by: kernel test robot --- drivers/net/ethernet/intel/i40e/i40e_txrx.c | 11 +++ drivers/net/ethernet/intel/i40e/i40e_txrx.h | 1 + drivers/net/ethernet/intel/i40e/i40e_xsk.c | 127 ++++++++++++++++++++-------- 3 files changed, 104 insertions(+), 35 deletions(-) diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.c b/drivers/net/ethernet/intel/i40e/i40e_txrx.c index d43ce13..c21548c 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_txrx.c +++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.c @@ -676,6 +676,8 @@ void i40e_free_tx_resources(struct i40e_ring *tx_ring) i40e_clean_tx_ring(tx_ring); kfree(tx_ring->tx_bi); tx_ring->tx_bi = NULL; + kfree(tx_ring->xsk_descs); + tx_ring->xsk_descs = NULL; if (tx_ring->desc) { dma_free_coherent(tx_ring->dev, tx_ring->size, @@ -1277,6 +1279,13 @@ int i40e_setup_tx_descriptors(struct i40e_ring *tx_ring) if (!tx_ring->tx_bi) goto err; + if (ring_is_xdp(tx_ring)) { + tx_ring->xsk_descs = kcalloc(I40E_MAX_NUM_DESCRIPTORS, sizeof(*tx_ring->xsk_descs), + GFP_KERNEL); + if (!tx_ring->xsk_descs) + goto err; + } + u64_stats_init(&tx_ring->syncp); /* round up to nearest 4K */ @@ -1300,6 +1309,8 @@ int i40e_setup_tx_descriptors(struct i40e_ring *tx_ring) return 0; err: + kfree(tx_ring->xsk_descs); + tx_ring->xsk_descs = NULL; kfree(tx_ring->tx_bi); tx_ring->tx_bi = NULL; return -ENOMEM; diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.h b/drivers/net/ethernet/intel/i40e/i40e_txrx.h index 2feed92..5f531b1 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_txrx.h +++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.h @@ -389,6 +389,7 @@ struct i40e_ring { struct i40e_channel *ch; struct xdp_rxq_info xdp_rxq; struct xsk_buff_pool *xsk_pool; + struct xdp_desc *xsk_descs; /* For storing descriptors in the AF_XDP ZC path */ } ____cacheline_internodealigned_in_smp; static inline bool ring_uses_build_skb(struct i40e_ring *ring) diff --git a/drivers/net/ethernet/intel/i40e/i40e_xsk.c b/drivers/net/ethernet/intel/i40e/i40e_xsk.c index 61aa1fc..a271a02 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_xsk.c +++ b/drivers/net/ethernet/intel/i40e/i40e_xsk.c @@ -381,6 +381,78 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) return failure ? budget : (int)total_rx_packets; } +static void i40e_xmit_pkt(struct i40e_ring *xdp_ring, struct xdp_desc *desc, + unsigned int *total_bytes) +{ + struct i40e_tx_desc *tx_desc; + dma_addr_t dma; + + dma = xsk_buff_raw_get_dma(xdp_ring->xsk_pool, desc->addr); + xsk_buff_raw_dma_sync_for_device(xdp_ring->xsk_pool, dma, desc->len); + + tx_desc = I40E_TX_DESC(xdp_ring, xdp_ring->next_to_use++); + tx_desc->buffer_addr = cpu_to_le64(dma); + tx_desc->cmd_type_offset_bsz = build_ctob(I40E_TX_DESC_CMD_ICRC | I40E_TX_DESC_CMD_EOP, + 0, desc->len, 0); + + *total_bytes += desc->len; +} + +/* This value should match the pragma below. Why 4? It is strictly + * empirical. It seems to be a good compromise between the advantage + * of having simultaneous outstanding reads to the DMA array that can + * hide each others latency and the disadvantage of having a larger + * code path. + */ +#define PKTS_PER_BATCH 4 + +static void i40e_xmit_pkt_batch(struct i40e_ring *xdp_ring, struct xdp_desc *desc, + unsigned int *total_bytes) +{ + u16 ntu = xdp_ring->next_to_use; + struct i40e_tx_desc *tx_desc; + dma_addr_t dma; + u32 i; + +#pragma GCC unroll 4 + for (i = 0; i < PKTS_PER_BATCH; i++) { + dma = xsk_buff_raw_get_dma(xdp_ring->xsk_pool, desc[i].addr); + xsk_buff_raw_dma_sync_for_device(xdp_ring->xsk_pool, dma, desc[i].len); + + tx_desc = I40E_TX_DESC(xdp_ring, ntu++); + tx_desc->buffer_addr = cpu_to_le64(dma); + tx_desc->cmd_type_offset_bsz = build_ctob(I40E_TX_DESC_CMD_ICRC | + I40E_TX_DESC_CMD_EOP, + 0, desc[i].len, 0); + + *total_bytes += desc[i].len; + } + + xdp_ring->next_to_use = ntu; +} + +static void i40e_fill_tx_hw_ring(struct i40e_ring *xdp_ring, struct xdp_desc *descs, u32 nb_pkts, + unsigned int *total_bytes) +{ + u32 batched, leftover, i; + + batched = nb_pkts & ~(PKTS_PER_BATCH - 1); + leftover = nb_pkts & (PKTS_PER_BATCH - 1); + for (i = 0; i < batched; i += PKTS_PER_BATCH) + i40e_xmit_pkt_batch(xdp_ring, &descs[i], total_bytes); + for (i = batched; i < batched + leftover; i++) + i40e_xmit_pkt(xdp_ring, &descs[i], total_bytes); +} + +static void i40e_set_rs_bit(struct i40e_ring *xdp_ring) +{ + u16 ntu = xdp_ring->next_to_use ? xdp_ring->next_to_use - 1 : xdp_ring->count - 1; + struct i40e_tx_desc *tx_desc; + + tx_desc = I40E_TX_DESC(xdp_ring, ntu); + tx_desc->cmd_type_offset_bsz |= (I40E_TX_DESC_CMD_RS << I40E_TXD_QW1_CMD_SHIFT); +} + /** * i40e_xmit_zc - Performs zero-copy Tx AF_XDP * @xdp_ring: XDP Tx ring @@ -390,45 +462,30 @@ int i40e_clean_rx_irq_zc(struct i40e_ring *rx_ring, int budget) **/ static bool i40e_xmit_zc(struct i40e_ring *xdp_ring, unsigned int budget) { - unsigned int sent_frames = 0, total_bytes = 0; - struct i40e_tx_desc *tx_desc = NULL; - struct xdp_desc desc; - dma_addr_t dma; - - while (budget-- > 0) { - if (!xsk_tx_peek_desc(xdp_ring->xsk_pool, &desc)) - break; - - dma = xsk_buff_raw_get_dma(xdp_ring->xsk_pool, desc.addr); - xsk_buff_raw_dma_sync_for_device(xdp_ring->xsk_pool, dma, - desc.len); - - tx_desc = I40E_TX_DESC(xdp_ring, xdp_ring->next_to_use); - tx_desc->buffer_addr = cpu_to_le64(dma); - tx_desc->cmd_type_offset_bsz = - build_ctob(I40E_TX_DESC_CMD_ICRC - | I40E_TX_DESC_CMD_EOP, - 0, desc.len, 0); - - sent_frames++; - total_bytes += desc.len; - - xdp_ring->next_to_use++; - if (xdp_ring->next_to_use == xdp_ring->count) - xdp_ring->next_to_use = 0; + struct xdp_desc *descs = xdp_ring->xsk_descs; + u32 nb_pkts, nb_processed = 0; + unsigned int total_bytes = 0; + + nb_pkts = xsk_tx_peek_release_desc_batch(xdp_ring->xsk_pool, descs, budget); + if (!nb_pkts) + return false; + + if (xdp_ring->next_to_use + nb_pkts >= xdp_ring->count) { + nb_processed = xdp_ring->count - xdp_ring->next_to_use; + i40e_fill_tx_hw_ring(xdp_ring, descs, nb_processed, &total_bytes); + xdp_ring->next_to_use = 0; } - if (tx_desc) { - /* Request an interrupt for the last frame and bump tail ptr. */ - tx_desc->cmd_type_offset_bsz |= (I40E_TX_DESC_CMD_RS << - I40E_TXD_QW1_CMD_SHIFT); - i40e_xdp_ring_update_tail(xdp_ring); + i40e_fill_tx_hw_ring(xdp_ring, &descs[nb_processed], nb_pkts - nb_processed, + &total_bytes); - xsk_tx_release(xdp_ring->xsk_pool); - i40e_update_tx_stats(xdp_ring, sent_frames, total_bytes); - } + /* Request an interrupt for the last frame and bump tail ptr. */ + i40e_set_rs_bit(xdp_ring); + i40e_xdp_ring_update_tail(xdp_ring); + + i40e_update_tx_stats(xdp_ring, nb_pkts, total_bytes); - return !!budget; + return true; } /**