Message ID | 20221111153505.434398-1-shenwei.wang@nxp.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp814641wru; Fri, 11 Nov 2022 07:40:20 -0800 (PST) X-Google-Smtp-Source: AA0mqf6bsLhTNeGNyUlMoFjI3WlmRUrYt3KbJqoLx2OhaVEQl6gWREf3HY+5ViMVhboOkiH8J37U X-Received: by 2002:a17:906:4acb:b0:781:d0c1:4434 with SMTP id u11-20020a1709064acb00b00781d0c14434mr2220482ejt.756.1668181220037; Fri, 11 Nov 2022 07:40:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1668181220; cv=pass; d=google.com; s=arc-20160816; b=ERBd90UTFO5LLxODzx4FNRVm7qfg1VeTpM79xpkzNUKqY4hZDX7fgONx6G0s1sHa0S LuGNpe3Mu1lgmCGXw+sLbncsJPfu+2lgIqYjLYij2R/Phrkc8Jd99/H8bZeiIWplXs5P 31UmZSrOjowQWG46KOF9HedeZxSAgWVg2QzB2+N1GUhP29SISY7ODwKhsxu5B6XvueYs AmDbA+DuCiBQRw5iSyGNDdhy6B/SkuMiFwR321OOZCUJUQS1MYYBvexDH+om6DWWqJgV sMFd+zGVDLjWIc3GUY+uBb/BPtruxWrr3feH0NgbmR8kKC7wFcqRLb/QLM6D72j+eeTE qIQg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :message-id:date:subject:cc:to:from:dkim-signature; bh=Zaverlrmz9D2s+LY2jz8pXhIGP+SQxVmyToq8RrYgnM=; b=P6MVrdbxymP9Zxy0+F2E7NkYA7qK/nns7I+Z4ZkLbrW3JuN1ZlXtnXjfQytHqX4XPK xQh+9UjjjFJKXFuJHJXik7N5mH3+lI+nLyEZ666pv8kfmCoy4kIOR3zE+ZzFB/IsmVE1 8kq2/FPRGzPeQJM/FZyip6rZFPfhtuXtbyM3ClbIuuOKVN0O7csBSX79IXRW6KIK1lag LY6mbRBqEjLWMy9+KRiGfozmnOcxAClqMGW8pL0wJtJoG+zaZut3GFUFN7W5ddLgegNq Srgr5Dd1NUyCWWyLg0VmLtzJikGg0h2xSxrVcikJtKNq2O0fQK4Re0jlirAm+WsOKs0j zvBQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=MVzeszlt; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nd27-20020a170907629b00b0078e27f2ef4bsi2480813ejc.956.2022.11.11.07.39.51; Fri, 11 Nov 2022 07:40:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=MVzeszlt; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233633AbiKKPfa (ORCPT <rfc822;winker.wchi@gmail.com> + 99 others); Fri, 11 Nov 2022 10:35:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232921AbiKKPf1 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 11 Nov 2022 10:35:27 -0500 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-eopbgr70084.outbound.protection.outlook.com [40.107.7.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3301DDF60; Fri, 11 Nov 2022 07:35:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G1Pf1Cf5ZOuEg/tUA7VaMxeXdgiN1iq8JgsjoRObHXSqIdEuXfFCsXcO056yOLU2doFTv5lw2al9SQXOj5WqbvDXygDaI8JNpIjwLdu9FLX2v0GYED42mQzwkA6JPf/LF/zPDrdPDxAgV3wq+1PE9MwTPePcRdFw2IG3M2T8vSLD8UMKlW8i3DvYx/fiUZR52R3NfR5+1P6zAhMHCc89QX9DFxbrsPl0tTJhcCKf2Ji7vBQBwVLY2agwNVhlJ7K9h0YJZLmem/E0dHPyfGKB7zOxDdawCkqBs4mQpNx4eXmgexymioOvMhIekym44/GbKA6JhVIAe4yX9AvDQ3K7OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Zaverlrmz9D2s+LY2jz8pXhIGP+SQxVmyToq8RrYgnM=; b=gAUDgwWNQZh1aPJGmI2LYBWxOkWJ/ainyXDDK92T/yXZroHbngF0qaYk0NHp1/v/d8oHxIRaBguqDSaqgbtSJV36hwFXDcVUUezYXl2PVR5bJA7Zj9aKW9d1JLPoGYlBZpfZTMBTBOj7I1a6W0gjIfGQOCgvwvRC3/X9uu94hF6Z5vxTf/RLOEd6fPTQrUbmdufW0DO1FImz6hxaUWBifHrbinPeUWmG1rAzhX5eaywlsR7YqGIpvi3fsZ3H5pVYp22Tlmz74c6cxlUdfS58CSSmdyURPDunqiTzT1XD+4GoNWFtKnMOq4yPFs+M5xdRxlMbSWDGlBKD5NZ2bQCCDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Zaverlrmz9D2s+LY2jz8pXhIGP+SQxVmyToq8RrYgnM=; b=MVzeszlttS4nGDJX7URRWPY2bpcUoUP3Fbahi4YC7ouvwb2GsEbGClqbfBTihC0JC0//NzppsFktI1mj6U9gvbP3Plwod0qvaM5AFc2kDmAdIyYgkI3MsvE+IU+ZE+GQlgb9293v/8TtV7BQ5wB65b2EoX2K+nW1kvSfEYUfRss= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB9185.eurprd04.prod.outlook.com (2603:10a6:102:231::11) by AM8PR04MB7890.eurprd04.prod.outlook.com (2603:10a6:20b:24e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5791.22; Fri, 11 Nov 2022 15:35:22 +0000 Received: from PAXPR04MB9185.eurprd04.prod.outlook.com ([fe80::6b44:4677:ad1d:b33a]) by PAXPR04MB9185.eurprd04.prod.outlook.com ([fe80::6b44:4677:ad1d:b33a%6]) with mapi id 15.20.5813.013; Fri, 11 Nov 2022 15:35:22 +0000 From: Shenwei Wang <shenwei.wang@nxp.com> To: "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com> Cc: Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Jesper Dangaard Brouer <hawk@kernel.org>, John Fastabend <john.fastabend@gmail.com>, Shenwei Wang <shenwei.wang@nxp.com>, Wei Fang <wei.fang@nxp.com>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, kernel test robot <lkp@intel.com> Subject: [PATCH v3 1/1] net: fec: add xdp and page pool statistics Date: Fri, 11 Nov 2022 09:35:05 -0600 Message-Id: <20221111153505.434398-1-shenwei.wang@nxp.com> X-Mailer: git-send-email 2.34.1 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SJ0PR03CA0051.namprd03.prod.outlook.com (2603:10b6:a03:33e::26) To PAXPR04MB9185.eurprd04.prod.outlook.com (2603:10a6:102:231::11) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB9185:EE_|AM8PR04MB7890:EE_ X-MS-Office365-Filtering-Correlation-Id: dc793eb7-434d-42eb-1e72-08dac3fa58b2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: seVO5TjBRXLTPh6QXgLHqf/zOGnoCrRGGmOqTSkh9TDweXm0Bsx6zwbjkqhmzS6JyoxQjUnnvx1gdMTBijkRCiVnwUe5V7qwyYGakjwRu5G6lSOSj0FvlyKS7LBR+Z/RmEeU60ci8WiGwmuuiBBBRSfAJXFLHDZcBne/s61pa0jVCqE11reTsBEfHiBrvliFjxYCCHfZIQM5/TJx/DBQTXtg/PKvzmjdyF32ZThzyZmkeESEpBqWfVdzghcTE9aKWYPb75AfMYlJORsdDGKir0vIBvvv0GPocdbUqHqvXWvxvxUEGLcE30cZneJyZBGLjXgAAzVrji7w0Up5m9ICbQrBLXLIRXWIEaEkiH95rdr/vclDuiaRSMBxj12veRlg3C4RFyRks1079t9Ble72sGmP3FQTLNyAec3s+Xxa5mQQroltcJkhufwktTiN/SrkJ2bYRRa8tvVyoq08Cv4T0ERgsqmJwSBAzi26oY6HzQWBmQhK46qflkNwIKDDVtPrxEULl7mH6IvoqqNtbj12GeEloS6VGfk+rLKZ2xDuSt8CwfQPxPj26oogWMY0cUvhISN/3H/qN78h0gZHrpYfERz+nc/k+fWbFdsGw3N8cS9Qg9ioy3u81kqQY6zWT2c/xFVLW+7zRC8UJ6bdaAsp7smhlCbw3df0rzvZDMtlFGTtOwqBuyhMNh0OIBthH+4IoKQc1oFACxbuPJ0+qLPELbn9Z+fPLVkiYie7tFRSJSVtS5OCrQPGUAbK1lFwqDPd X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB9185.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(366004)(376002)(39860400002)(346002)(136003)(396003)(451199015)(36756003)(38100700002)(44832011)(2906002)(8936002)(4326008)(5660300002)(7416002)(38350700002)(66946007)(86362001)(83380400001)(316002)(110136005)(54906003)(2616005)(6486002)(478600001)(186003)(66476007)(8676002)(41300700001)(1076003)(55236004)(66556008)(6512007)(6666004)(52116002)(26005)(6506007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: S+F8CGIdXyLiOkbUR65S1I7vUoNDK1zHoIFZOjprPqZp23poz2OISeT5OYAiVmPNMgvFgErxZf1OHLhJDU1M3CqpsR7dLtKh4SDjNEWvBMQo4nhBYXE0DGOZRThha2xFJfDNqtMVWZGQIkZY7tyNaOYOb1q8CQ3WIaZd56oPZ9wDoDg3kaR86c+3bUffh753jTcc9BRCToLcW66KqaiS6xFnIvuA8KcZwpbIhhLLSiKhHbJfYb1GBWoLFJtLt7PEE07VFE4LBSdAyRU89eQBXo9VPrErw2A1F88usJddUU5yD9dARIONpA/gPcEevwKG4T0eBQlhV/TNoCOqNS3KAfLJ9MG05/EvTuocLDbEjMdnewBHW1nNUmjtZpbis+cFjww4AhfVR+fkQIvDeu5BCFF4GLRk92XIVYpPw47q4YzwLmRtV0sPiMkyeDX0e9pirX8KfG9am5e5JSA8ZP8FC+IhCxpLeiN2JEyOfmKxwNejPaJb1NiLnJh2iB1+P94NJtD359E/nE8EQ8rIjYClXzYcdDeyQJeh9676FaYB0Xce2AAvMWNDE2c7OSqdwCHc18HzP7V0RjtKn1mu1L9t6Sk7JF/So+ImqQe1Jnd4Zbu8MD0+8hbFRD0z9tT51YQYHyCmkKZfKo2Nx0ipEK+ocjEKZQLfmNJHbgp8JQb5+TRkvdgKbGSQQI/Xdt8G8w+bhlMxubPMlIWJCIXSpRZRVnFrqP1wsa1pxEeiMsdoXUoXCL4b7QlVfGeVEsrs9fa6G/WnTaEPd+JsYm/w/nYzt+bSEwjW9G2J2rpIf3/cQWv/6lLWi3BuOhpMB9830ja34rkswk1FaHN91nEwPZaGkJJttKBY1+8mSUjQxWqOxcL+2jhPFxjqUmmL2jMYpv/1tIE2Q4rFiTaYQ7bQrrtV5q6AQiNuxWqqQRAHXJtapm7lYBSkVoogwM0d24gU+Ganhh857QQBx7zQL0cxEtjW4Huo7abc+BLKJfWMjajwClCSLg8IvqeyJ70sXfI5wM8kKf22swf0SAdCJ45Ly0Nlu+gnOIk9s/W5KQDPkc22F21YY0q5eiHj6Fkklh+D16C6rs/xxjJzn7KqHBEwV6/XksXzY3SrwrW0cfF+HXKaycDVzNo/smAk7MIu9kziO3xLKuRPI8FAInODYteDCC1F4fllzW+AyYWfGneIKwNQ0BO/IiUeK4uA0CYn5TSj6HaOTdIwzSEu8DDgbyXGIKMI3ssZu+jsLJ/d233Tb9NOr7jniwUpOOBtPcvIjGImiQ0eOdcY4//NrpneHkaBV1UPcxyw3VZuXjHsN8opnqLo/bWuiROMhY+U5qwxPIPGqqsXpg3xKH8FxnPr6gljDK5LDWzwmbThssj1G9E/6mmPX2vkdB2xDm2Ny0snxuVcCvuaGwzOoAM3M3cWW9Vb5Vp/M5cSZcFclRTGkBV9Bk8tMqF7d3bWFAItZZYHtoxAXmgtDuqW2tMi6Jffter7bXpEcPEKmTYJpLxmeOUpX0TntEoQtHZrZRSvHK2AT90G1oSmDeO8yjwaDIDk8kaiyw1ULthwyk2LEUua1WjqMVtPXR67YfqVEWZm984Z3hzpaggR X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: dc793eb7-434d-42eb-1e72-08dac3fa58b2 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB9185.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Nov 2022 15:35:22.6467 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: T0Vd++9ob96WFMIwXSRXYxUNevYTbX+XPlcv1fWT45NLbeXfblOiYljpwRsACR9VCQkZZGzH2gOFlGfE4hTUlg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7890 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749214790938928734?= X-GMAIL-MSGID: =?utf-8?q?1749214790938928734?= |
Series |
[v3,1/1] net: fec: add xdp and page pool statistics
|
|
Commit Message
Shenwei Wang
Nov. 11, 2022, 3:35 p.m. UTC
Added xdp and page pool statistics.
In order to make the implementation simple and compatible, the patch
uses the 32bit integer to record the XDP statistics.
Signed-off-by: Shenwei Wang <shenwei.wang@nxp.com>
Reported-by: kernel test robot <lkp@intel.com>
---
Changes in v3:
- change memcpy to strncpy to fix the warning reported by Paolo Abeni
- fix the compile errors on powerpc
Changes in v2:
- clean up and restructure the codes per Andrew Lunn's review comments
- clear the statistics when the adaptor is down
drivers/net/ethernet/freescale/Kconfig | 1 +
drivers/net/ethernet/freescale/fec.h | 14 ++++
drivers/net/ethernet/freescale/fec_main.c | 85 +++++++++++++++++++++--
3 files changed, 95 insertions(+), 5 deletions(-)
--
2.34.1
Comments
From: Shenwei Wang <shenwei.wang@nxp.com> Date: Fri, 11 Nov 2022 09:35:05 -0600 > Added xdp and page pool statistics. > In order to make the implementation simple and compatible, the patch > uses the 32bit integer to record the XDP statistics. > > Signed-off-by: Shenwei Wang <shenwei.wang@nxp.com> > Reported-by: kernel test robot <lkp@intel.com> I was this went upstream[0], I think it was quite premature. First of all, there was a non-acked reply to me in the v2 thread, but okay, I can live with that. More serious issues in the inline comments below. > --- > Changes in v3: > - change memcpy to strncpy to fix the warning reported by Paolo Abeni > - fix the compile errors on powerpc > > Changes in v2: > - clean up and restructure the codes per Andrew Lunn's review comments > - clear the statistics when the adaptor is down > > drivers/net/ethernet/freescale/Kconfig | 1 + > drivers/net/ethernet/freescale/fec.h | 14 ++++ > drivers/net/ethernet/freescale/fec_main.c | 85 +++++++++++++++++++++-- > 3 files changed, 95 insertions(+), 5 deletions(-) > > diff --git a/drivers/net/ethernet/freescale/Kconfig b/drivers/net/ethernet/freescale/Kconfig > index ce866ae3df03..f1e80d6996ef 100644 > --- a/drivers/net/ethernet/freescale/Kconfig > +++ b/drivers/net/ethernet/freescale/Kconfig > @@ -29,6 +29,7 @@ config FEC > select CRC32 > select PHYLIB > select PAGE_POOL > + select PAGE_POOL_STATS Drivers should never select PAGE_POOL_STATS. This Kconfig option was made to allow user to choose whether he wants stats or better performance on slower systems. It's pure user choice, if something doesn't build or link, it must be guarded with IS_ENABLED(CONFIG_PAGE_POOL_STATS). > imply NET_SELFTESTS > help > Say Y here if you want to use the built-in 10/100 Fast ethernet > diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h > index 61e847b18343..5ba1e0d71c68 100644 > --- a/drivers/net/ethernet/freescale/fec.h > +++ b/drivers/net/ethernet/freescale/fec.h > @@ -526,6 +526,19 @@ struct fec_enet_priv_txrx_info { > struct sk_buff *skb; > }; > > +enum { > + RX_XDP_REDIRECT = 0, > + RX_XDP_PASS, > + RX_XDP_DROP, > + RX_XDP_TX, > + RX_XDP_TX_ERRORS, > + TX_XDP_XMIT, > + TX_XDP_XMIT_ERRORS, > + > + /* The following must be the last one */ > + XDP_STATS_TOTAL, > +}; > + > struct fec_enet_priv_tx_q { > struct bufdesc_prop bd; > unsigned char *tx_bounce[TX_RING_SIZE]; > @@ -546,6 +559,7 @@ struct fec_enet_priv_rx_q { > /* page_pool */ > struct page_pool *page_pool; > struct xdp_rxq_info xdp_rxq; > + u32 stats[XDP_STATS_TOTAL]; Still not convinced it is okay to deliberately provoke overflows here, maybe we need some more reviewers to help us agree on what is better? > > /* rx queue number, in the range 0-7 */ > u8 id; [...] > case ETH_SS_STATS: > - for (i = 0; i < ARRAY_SIZE(fec_stats); i++) > - memcpy(data + i * ETH_GSTRING_LEN, > - fec_stats[i].name, ETH_GSTRING_LEN); > + for (i = 0; i < ARRAY_SIZE(fec_stats); i++) { > + memcpy(data, fec_stats[i].name, ETH_GSTRING_LEN); > + data += ETH_GSTRING_LEN; > + } > + for (i = 0; i < ARRAY_SIZE(fec_xdp_stat_strs); i++) { > + strncpy(data, fec_xdp_stat_strs[i], ETH_GSTRING_LEN); strncpy() is deprecated in favor of strscpy(), there were tons of commits which replace the former with the latter across the whole tree. > + data += ETH_GSTRING_LEN; > + } > + page_pool_ethtool_stats_get_strings(data); > + > break; > case ETH_SS_TEST: > net_selftest_get_strings(data); [...] > + for (i = fep->num_rx_queues - 1; i >= 0; i--) { > + rxq = fep->rx_queue[i]; > + for (j = 0; j < XDP_STATS_TOTAL; j++) > + rxq->stats[j] = 0; (not critical) Just memset(&rxq->stats)? > + } > + > /* Don't disable MIB statistics counters */ > writel(0, fep->hwp + FEC_MIB_CTRLSTAT); > } > @@ -3084,6 +3156,9 @@ static void fec_enet_free_buffers(struct net_device *ndev) > for (i = 0; i < rxq->bd.ring_size; i++) > page_pool_release_page(rxq->page_pool, rxq->rx_skb_info[i].page); > > + for (i = 0; i < XDP_STATS_TOTAL; i++) > + rxq->stats[i] = 0; > + > if (xdp_rxq_info_is_reg(&rxq->xdp_rxq)) > xdp_rxq_info_unreg(&rxq->xdp_rxq); > page_pool_destroy(rxq->page_pool); > -- > 2.34.1 Could you please send a follow-up maybe, fixing at least that PAGE_POOL_STATS select and strncpy()? [0] https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/commit/?h=main&id=6970ef27ff7fd1ce3455b2c696081503d0c0f8ac Thanks, Olek
> Drivers should never select PAGE_POOL_STATS. This Kconfig option was > made to allow user to choose whether he wants stats or better > performance on slower systems. It's pure user choice, if something > doesn't build or link, it must be guarded with > IS_ENABLED(CONFIG_PAGE_POOL_STATS). Given how simple the API is, and the stubs for when CONFIG_PAGE_POOL_STATS is disabled, i doubt there is any need for the driver to do anything. > > struct page_pool *page_pool; > > struct xdp_rxq_info xdp_rxq; > > + u32 stats[XDP_STATS_TOTAL]; > > Still not convinced it is okay to deliberately provoke overflows > here, maybe we need some more reviewers to help us agree on what is > better? You will find that many embedded drivers only have 32 bit hardware stats and do wrap around. And the hardware does not have atomic read and clear so you can accumulate into a u64. The FEC is from the times of MIB 2 ifTable, which only requires 32 bit counters. ifXtable is modern compared to the FEC. Software counters like this are a different matter. The overhead of a u64 on a 32 bit system is probably in the noise, so i think there is strong argument for using u64. Andrew
> -----Original Message----- > From: Alexander Lobakin <alexandr.lobakin@intel.com> > Sent: Monday, November 14, 2022 7:46 AM > To: Shenwei Wang <shenwei.wang@nxp.com> > Cc: Alexander Lobakin <alexandr.lobakin@intel.com>; David S. Miller > <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub > Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Alexei > Starovoitov <ast@kernel.org>; Daniel Borkmann <daniel@iogearbox.net>; > > @@ -29,6 +29,7 @@ config FEC > > select CRC32 > > select PHYLIB > > select PAGE_POOL > > + select PAGE_POOL_STATS > > Drivers should never select PAGE_POOL_STATS. This Kconfig option was made to > allow user to choose whether he wants stats or better performance on slower > systems. It's pure user choice, if something doesn't build or link, it must be > guarded with IS_ENABLED(CONFIG_PAGE_POOL_STATS). As the PAGE_POOL_STATS is becoming the infrastructure codes for many drivers, it is redundant for every driver to implement the stub function in case it is not selected. These stub functions should be provided by PAGE_POOL_STATS itself if the option is not selected. > > > imply NET_SELFTESTS > > help > > Say Y here if you want to use the built-in 10/100 Fast > > ethernet diff --git a/drivers/net/ethernet/freescale/fec.h > > b/drivers/net/ethernet/freescale/fec.h > > index 61e847b18343..5ba1e0d71c68 100644 > > --- a/drivers/net/ethernet/freescale/fec.h > > +++ b/drivers/net/ethernet/freescale/fec.h > > @@ -526,6 +526,19 @@ struct fec_enet_priv_txrx_info { > > struct sk_buff *skb; > > }; > > > > +enum { > > + RX_XDP_REDIRECT = 0, > > + RX_XDP_PASS, > > + RX_XDP_DROP, > > + RX_XDP_TX, > > + RX_XDP_TX_ERRORS, > > + TX_XDP_XMIT, > > + TX_XDP_XMIT_ERRORS, > > + > > + /* The following must be the last one */ > > + XDP_STATS_TOTAL, > > +}; > > + > > struct fec_enet_priv_tx_q { > > struct bufdesc_prop bd; > > unsigned char *tx_bounce[TX_RING_SIZE]; @@ -546,6 +559,7 @@ > > struct fec_enet_priv_rx_q { > > /* page_pool */ > > struct page_pool *page_pool; > > struct xdp_rxq_info xdp_rxq; > > + u32 stats[XDP_STATS_TOTAL]; > > Still not convinced it is okay to deliberately provoke overflows here, maybe we > need some more reviewers to help us agree on what is better? > > > > > /* rx queue number, in the range 0-7 */ > > u8 id; > > [...] > > > case ETH_SS_STATS: > > - for (i = 0; i < ARRAY_SIZE(fec_stats); i++) > > - memcpy(data + i * ETH_GSTRING_LEN, > > - fec_stats[i].name, ETH_GSTRING_LEN); > > + for (i = 0; i < ARRAY_SIZE(fec_stats); i++) { > > + memcpy(data, fec_stats[i].name, ETH_GSTRING_LEN); > > + data += ETH_GSTRING_LEN; > > + } > > + for (i = 0; i < ARRAY_SIZE(fec_xdp_stat_strs); i++) { > > + strncpy(data, fec_xdp_stat_strs[i], > > + ETH_GSTRING_LEN); > > strncpy() is deprecated in favor of strscpy(), there were tons of commits which > replace the former with the latter across the whole tree. > Got it. Thanks. Shenwei > > + data += ETH_GSTRING_LEN; > > + } > > + page_pool_ethtool_stats_get_strings(data); > > + > > break; > > case ETH_SS_TEST: > > net_selftest_get_strings(data); > > [...] > > > + for (i = fep->num_rx_queues - 1; i >= 0; i--) { > > + rxq = fep->rx_queue[i]; > > + for (j = 0; j < XDP_STATS_TOTAL; j++) > > + rxq->stats[j] = 0; > > (not critical) Just memset(&rxq->stats)? > > > + } > > + > > /* Don't disable MIB statistics counters */ > > writel(0, fep->hwp + FEC_MIB_CTRLSTAT); } @@ -3084,6 +3156,9 @@ > > static void fec_enet_free_buffers(struct net_device *ndev) > > for (i = 0; i < rxq->bd.ring_size; i++) > > page_pool_release_page(rxq->page_pool, > > rxq->rx_skb_info[i].page); > > > > + for (i = 0; i < XDP_STATS_TOTAL; i++) > > + rxq->stats[i] = 0; > > + > > if (xdp_rxq_info_is_reg(&rxq->xdp_rxq)) > > xdp_rxq_info_unreg(&rxq->xdp_rxq); > > page_pool_destroy(rxq->page_pool); > > -- > > 2.34.1 > > Could you please send a follow-up maybe, fixing at least that > PAGE_POOL_STATS select and strncpy()? > > [0] > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel > .org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Fnetdev%2Fnet- > next.git%2Fcommit%2F%3Fh%3Dmain%26id%3D6970ef27ff7fd1ce3455b2c6960 > 81503d0c0f8ac&data=05%7C01%7Cshenwei.wang%40nxp.com%7C0f6bfc > 73c869426e59fc08dac64692d2%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0 > %7C0%7C638040303661645473%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4 > wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C > %7C%7C&sdata=8NbrJmoDnsbyb8WXU85OIq6BOYCOrXLBm1mjbTi%2Fam > Q%3D&reserved=0 > > Thanks, > Olek
> -----Original Message----- > From: Andrew Lunn <andrew@lunn.ch> > Sent: Monday, November 14, 2022 8:08 AM > To: Alexander Lobakin <alexandr.lobakin@intel.com> > Cc: Shenwei Wang <shenwei.wang@nxp.com>; David S. Miller > <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub > Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Alexei > Starovoitov <ast@kernel.org>; Daniel Borkmann <daniel@iogearbox.net>; > Jesper Dangaard Brouer <hawk@kernel.org>; John Fastabend > <john.fastabend@gmail.com>; Wei Fang <wei.fang@nxp.com>; > netdev@vger.kernel.org; linux-kernel@vger.kernel.org; imx@lists.linux.dev; > kernel test robot <lkp@intel.com> > Subject: [EXT] Re: [PATCH v3 1/1] net: fec: add xdp and page pool statistics > > Caution: EXT Email > > > Drivers should never select PAGE_POOL_STATS. This Kconfig option was > > made to allow user to choose whether he wants stats or better > > performance on slower systems. It's pure user choice, if something > > doesn't build or link, it must be guarded with > > IS_ENABLED(CONFIG_PAGE_POOL_STATS). > > Given how simple the API is, and the stubs for when CONFIG_PAGE_POOL_STATS > is disabled, i doubt there is any need for the driver to do anything. > > > > struct page_pool *page_pool; > > > struct xdp_rxq_info xdp_rxq; > > > + u32 stats[XDP_STATS_TOTAL]; > > > > Still not convinced it is okay to deliberately provoke overflows here, > > maybe we need some more reviewers to help us agree on what is better? > > You will find that many embedded drivers only have 32 bit hardware stats and do > wrap around. And the hardware does not have atomic read and clear so you can > accumulate into a u64. The FEC is from the times of MIB 2 ifTable, which only > requires 32 bit counters. ifXtable is modern compared to the FEC. > > Software counters like this are a different matter. The overhead of a > u64 on a 32 bit system is probably in the noise, so i think there is strong > argument for using u64. If it is required to support u64 counters, the code logic need to change to record the counter locally per packet, and then update the counters for the fec instance when the napi receive loop is complete. In this way we can reduce the performance overhead. Thanks, Shenwei > > Andrew
From: Shenwei Wang <shenwei.wang@nxp.com> Date: Mon, 14 Nov 2022 15:06:04 +0000 > > -----Original Message----- > > From: Andrew Lunn <andrew@lunn.ch> > > Sent: Monday, November 14, 2022 8:08 AM > > To: Alexander Lobakin <alexandr.lobakin@intel.com> > > Cc: Shenwei Wang <shenwei.wang@nxp.com>; David S. Miller > > <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub > > Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Alexei > > Starovoitov <ast@kernel.org>; Daniel Borkmann <daniel@iogearbox.net>; > > Jesper Dangaard Brouer <hawk@kernel.org>; John Fastabend > > <john.fastabend@gmail.com>; Wei Fang <wei.fang@nxp.com>; > > netdev@vger.kernel.org; linux-kernel@vger.kernel.org; imx@lists.linux.dev; > > kernel test robot <lkp@intel.com> > > Subject: [EXT] Re: [PATCH v3 1/1] net: fec: add xdp and page pool statistics > > > > Caution: EXT Email > > > >> Drivers should never select PAGE_POOL_STATS. This Kconfig option was > >> made to allow user to choose whether he wants stats or better > >> performance on slower systems. It's pure user choice, if something > >> doesn't build or link, it must be guarded with > >> IS_ENABLED(CONFIG_PAGE_POOL_STATS). > > > > Given how simple the API is, and the stubs for when CONFIG_PAGE_POOL_STATS > > is disabled, i doubt there is any need for the driver to do anything. > > > >>> struct page_pool *page_pool; > >>> struct xdp_rxq_info xdp_rxq; > >>> + u32 stats[XDP_STATS_TOTAL]; > >> > >> Still not convinced it is okay to deliberately provoke overflows here, > >> maybe we need some more reviewers to help us agree on what is better? > > > > You will find that many embedded drivers only have 32 bit hardware stats and do > > wrap around. And the hardware does not have atomic read and clear so you can > > accumulate into a u64. The FEC is from the times of MIB 2 ifTable, which only > > requires 32 bit counters. ifXtable is modern compared to the FEC. > > > > Software counters like this are a different matter. The overhead of a > > u64 on a 32 bit system is probably in the noise, so i think there is strong > > argument for using u64. > > If it is required to support u64 counters, the code logic need to change to record > the counter locally per packet, and then update the counters for the fec instance > when the napi receive loop is complete. In this way we can reduce the performance > overhead. That's how it is usually done in the drivers. You put u32 counters on the stack, it's impossible to overflow them in just one NAPI poll cycle. Then, after you're done with processing descriptors, you just increment the 64-bit on-ring counters at once. > > Thanks, > Shenwei > > > > > Andrew Thanks, Olek
From: Shenwei Wang <shenwei.wang@nxp.com> Date: Mon, 14 Nov 2022 14:53:00 +0000 > > -----Original Message----- > > From: Alexander Lobakin <alexandr.lobakin@intel.com> > > Sent: Monday, November 14, 2022 7:46 AM > > To: Shenwei Wang <shenwei.wang@nxp.com> > > Cc: Alexander Lobakin <alexandr.lobakin@intel.com>; David S. Miller > > <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub > > Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Alexei > > Starovoitov <ast@kernel.org>; Daniel Borkmann <daniel@iogearbox.net>; > >> @@ -29,6 +29,7 @@ config FEC > >> select CRC32 > >> select PHYLIB > >> select PAGE_POOL > >> + select PAGE_POOL_STATS > > > > Drivers should never select PAGE_POOL_STATS. This Kconfig option was made to > > allow user to choose whether he wants stats or better performance on slower > > systems. It's pure user choice, if something doesn't build or link, it must be > > guarded with IS_ENABLED(CONFIG_PAGE_POOL_STATS). > > As the PAGE_POOL_STATS is becoming the infrastructure codes for many drivers, it is > redundant for every driver to implement the stub function in case it is not selected. These > stub functions should be provided by PAGE_POOL_STATS itself if the option is not selected. Correct, but I think you added 'select PAGE_POOL_STATS' due to some build issues on PPC64, or not? So if there are any when !PAGE_POOL_STATS, it's always better to handle this at the Page Pool API level in a separate patch. > > > > >> imply NET_SELFTESTS > >> help > >> Say Y here if you want to use the built-in 10/100 Fast Thanks, Olek
> -----Original Message----- > From: Alexander Lobakin <alexandr.lobakin@intel.com> > Sent: Monday, November 14, 2022 9:28 AM > To: Shenwei Wang <shenwei.wang@nxp.com> > Cc: Alexander Lobakin <alexandr.lobakin@intel.com>; David S. Miller > <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub > Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Alexei > Starovoitov <ast@kernel.org>; Daniel Borkmann <daniel@iogearbox.net>; > Jesper Dangaard Brouer <hawk@kernel.org>; John Fastabend > <john.fastabend@gmail.com>; Wei Fang <wei.fang@nxp.com>; > netdev@vger.kernel.org; linux-kernel@vger.kernel.org; imx@lists.linux.dev; > kernel test robot <lkp@intel.com> > > > <daniel@iogearbox.net>; > > >> @@ -29,6 +29,7 @@ config FEC > > >> select CRC32 > > >> select PHYLIB > > >> select PAGE_POOL > > >> + select PAGE_POOL_STATS > > > > > > Drivers should never select PAGE_POOL_STATS. This Kconfig option was > > > made to allow user to choose whether he wants stats or better > > > performance on slower systems. It's pure user choice, if something > > > doesn't build or link, it must be guarded with > IS_ENABLED(CONFIG_PAGE_POOL_STATS). > > > > As the PAGE_POOL_STATS is becoming the infrastructure codes for many > > drivers, it is redundant for every driver to implement the stub > > function in case it is not selected. These stub functions should be provided by > PAGE_POOL_STATS itself if the option is not selected. > > Correct, but I think you added 'select PAGE_POOL_STATS' due to some build > issues on PPC64, or not? So if there are any when !PAGE_POOL_STATS, it's > always better to handle this at the Page Pool API level in a separate patch. Yes, the 'select PAGE_POOL_STATS' was added because of the building failure found on PPC64 platform. Thanks, Shenwei > > > > > > > > >> imply NET_SELFTESTS > > >> help > > >> Say Y here if you want to use the built-in 10/100 Fast > > Thanks, > Olek
> -----Original Message----- > From: Alexander Lobakin <alexandr.lobakin@intel.com> > Sent: Monday, November 14, 2022 9:23 AM > To: Shenwei Wang <shenwei.wang@nxp.com> > Cc: Alexander Lobakin <alexandr.lobakin@intel.com>; Andrew Lunn > <andrew@lunn.ch>; David S. Miller <davem@davemloft.net>; Eric Dumazet > <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni > <pabeni@redhat.com>; Alexei Starovoitov <ast@kernel.org>; Daniel Borkmann > <daniel@iogearbox.net>; Jesper Dangaard Brouer <hawk@kernel.org>; John > Fastabend <john.fastabend@gmail.com>; Wei Fang <wei.fang@nxp.com>; > netdev@vger.kernel.org; linux-kernel@vger.kernel.org; imx@lists.linux.dev; > kernel test robot <lkp@intel.com> > Subject: [EXT] Re: [PATCH v3 1/1] net: fec: add xdp and page pool statistics > > Caution: EXT Email > > From: Shenwei Wang <shenwei.wang@nxp.com> > Date: Mon, 14 Nov 2022 15:06:04 +0000 > > > > -----Original Message----- > > > From: Andrew Lunn <andrew@lunn.ch> > > > Sent: Monday, November 14, 2022 8:08 AM > > > To: Alexander Lobakin <alexandr.lobakin@intel.com> > > > Cc: Shenwei Wang <shenwei.wang@nxp.com>; David S. Miller > > > <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub > > > Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Alexei > > > Starovoitov <ast@kernel.org>; Daniel Borkmann > > > <daniel@iogearbox.net>; Jesper Dangaard Brouer <hawk@kernel.org>; > > > John Fastabend <john.fastabend@gmail.com>; Wei Fang > > > <wei.fang@nxp.com>; netdev@vger.kernel.org; > > > linux-kernel@vger.kernel.org; imx@lists.linux.dev; kernel test robot > > > <lkp@intel.com> > > > Subject: [EXT] Re: [PATCH v3 1/1] net: fec: add xdp and page pool > > > statistics > > > > > > Caution: EXT Email > > > > > >> Drivers should never select PAGE_POOL_STATS. This Kconfig option > > >> was made to allow user to choose whether he wants stats or better > > >> performance on slower systems. It's pure user choice, if something > > >> doesn't build or link, it must be guarded with > > >> IS_ENABLED(CONFIG_PAGE_POOL_STATS). > > > > > > Given how simple the API is, and the stubs for when > > > CONFIG_PAGE_POOL_STATS is disabled, i doubt there is any need for the > driver to do anything. > > > > > >>> struct page_pool *page_pool; > > >>> struct xdp_rxq_info xdp_rxq; > > >>> + u32 stats[XDP_STATS_TOTAL]; > > >> > > >> Still not convinced it is okay to deliberately provoke overflows > > >> here, maybe we need some more reviewers to help us agree on what is > better? > > > > > > You will find that many embedded drivers only have 32 bit hardware > > > stats and do wrap around. And the hardware does not have atomic read > > > and clear so you can accumulate into a u64. The FEC is from the > > > times of MIB 2 ifTable, which only requires 32 bit counters. ifXtable is > modern compared to the FEC. > > > > > > Software counters like this are a different matter. The overhead of > > > a > > > u64 on a 32 bit system is probably in the noise, so i think there is > > > strong argument for using u64. > > > > If it is required to support u64 counters, the code logic need to > > change to record the counter locally per packet, and then update the > > counters for the fec instance when the napi receive loop is complete. > > In this way we can reduce the performance overhead. > > That's how it is usually done in the drivers. You put u32 counters on the stack, > it's impossible to overflow them in just one NAPI poll cycle. Then, after you're > done with processing descriptors, you just increment the 64-bit on-ring counters > at once. > Did some testing with the atomic64_t counter, with the following codes to update the u64 counter in the end of every NAPI poll cycle. @@ -1764,7 +1768,13 @@ fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id) if (xdp_result & FEC_ENET_XDP_REDIR) xdp_do_flush_map(); +#if 1 + if (xdp_prog) { + int i; + for(i = 0; i < XDP_STATS_TOTAL; i++) + atomic64_add(xdp_stats[i], &rxq->stats[i]); + } +#endif return pkt_received; } With the codes above, the testing result is below: root@imx8qxpc0mek:~/bpf# ./xdpsock -i eth0 sock0@eth0:0 rxdrop xdp-drv pps pkts 1.00 rx 349399 1035008 tx 0 0 sock0@eth0:0 rxdrop xdp-drv pps pkts 1.00 rx 349407 1384640 tx 0 0 Without the atomic_add codes above, the testing result is below: root@imx8qxpc0mek:~/bpf# ./xdpsock -i eth0 sock0@eth0:0 rxdrop xdp-drv pps pkts 1.00 rx 350109 1989130 tx 0 0 sock0@eth0:0 rxdrop xdp-drv pps pkts 1.00 rx 350425 2339786 tx 0 0 And regarding the u32 counter solution, the testing result is below: root@imx8qxpc0mek:~/bpf# ./xdpsock -i eth0 sock0@eth0:0 rxdrop xdp-drv pps pkts 1.00 rx 361347 2637796 tx 0 0 There are about 10K pkts/s difference here. Do we really want the u64 counters? Regards, Shenwei > > > > Thanks, > > Shenwei > > > > > > > > Andrew > > Thanks, > Olek
> @@ -1764,7 +1768,13 @@ fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id) > > if (xdp_result & FEC_ENET_XDP_REDIR) > xdp_do_flush_map(); > +#if 1 > + if (xdp_prog) { > + int i; > + for(i = 0; i < XDP_STATS_TOTAL; i++) > + atomic64_add(xdp_stats[i], &rxq->stats[i]); > + } > +#endif Atomic operations are expensive. You should not use them unless you really do need them. What driver are you copying here? There is nothing particularly new here, so you should just be copying code from another driver, and hope you picked a good example. Andrew
From: Shenwei Wang <shenwei.wang@nxp.com> Date: Mon, 14 Nov 2022 21:17:48 +0000 > > -----Original Message----- > > From: Alexander Lobakin <alexandr.lobakin@intel.com> > > Sent: Monday, November 14, 2022 9:23 AM > > To: Shenwei Wang <shenwei.wang@nxp.com> > > Cc: Alexander Lobakin <alexandr.lobakin@intel.com>; Andrew Lunn > > <andrew@lunn.ch>; David S. Miller <davem@davemloft.net>; Eric Dumazet > > <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni > > <pabeni@redhat.com>; Alexei Starovoitov <ast@kernel.org>; Daniel Borkmann > > <daniel@iogearbox.net>; Jesper Dangaard Brouer <hawk@kernel.org>; John > > Fastabend <john.fastabend@gmail.com>; Wei Fang <wei.fang@nxp.com>; > > netdev@vger.kernel.org; linux-kernel@vger.kernel.org; imx@lists.linux.dev; > > kernel test robot <lkp@intel.com> > > Subject: [EXT] Re: [PATCH v3 1/1] net: fec: add xdp and page pool statistics [...] > Did some testing with the atomic64_t counter, with the following codes to update > the u64 counter in the end of every NAPI poll cycle. > > @@ -1764,7 +1768,13 @@ fec_enet_rx_queue(struct net_device *ndev, int budget, u16 queue_id) > > if (xdp_result & FEC_ENET_XDP_REDIR) > xdp_do_flush_map(); > +#if 1 > + if (xdp_prog) { > + int i; > + for(i = 0; i < XDP_STATS_TOTAL; i++) > + atomic64_add(xdp_stats[i], &rxq->stats[i]); > + } > +#endif > return pkt_received; > } > > With the codes above, the testing result is below: > root@imx8qxpc0mek:~/bpf# ./xdpsock -i eth0 > sock0@eth0:0 rxdrop xdp-drv > pps pkts 1.00 > rx 349399 1035008 > tx 0 0 > > sock0@eth0:0 rxdrop xdp-drv > pps pkts 1.00 > rx 349407 1384640 > tx 0 0 > > Without the atomic_add codes above, the testing result is below: > root@imx8qxpc0mek:~/bpf# ./xdpsock -i eth0 > sock0@eth0:0 rxdrop xdp-drv > pps pkts 1.00 > rx 350109 1989130 > tx 0 0 > > sock0@eth0:0 rxdrop xdp-drv > pps pkts 1.00 > rx 350425 2339786 > tx 0 0 > > And regarding the u32 counter solution, the testing result is below: > root@imx8qxpc0mek:~/bpf# ./xdpsock -i eth0 > sock0@eth0:0 rxdrop xdp-drv > pps pkts 1.00 > rx 361347 2637796 > tx 0 0 > > There are about 10K pkts/s difference here. Do we really want the u64 counters? Where did those atomic64_t come from? u64_stats_t use either plain u64 for 32-bit platforms or local64_t for 64-bit ones. Take a look at [0] for the example of how x86_64 does this, it is far from atomic64_t. > > Regards, > Shenwei > > >> > >> Thanks, > >> Shenwei > >> > >>> > >>> Andrew > > > > Thanks, > > Olek [0] https://elixir.bootlin.com/linux/v6.1-rc5/source/arch/x86/include/asm/local.h#L31 Thanks, Olek
> -----Original Message----- > From: Alexander Lobakin <alexandr.lobakin@intel.com> > Sent: Wednesday, November 16, 2022 8:34 AM > To: Shenwei Wang <shenwei.wang@nxp.com> > Cc: Alexander Lobakin <alexandr.lobakin@intel.com>; Andrew Lunn > <andrew@lunn.ch>; David S. Miller <davem@davemloft.net>; Eric Dumazet > <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; Paolo Abeni > <pabeni@redhat.com>; Alexei Starovoitov <ast@kernel.org>; Daniel Borkmann > <daniel@iogearbox.net>; Jesper Dangaard Brouer <hawk@kernel.org>; John > Fastabend <john.fastabend@gmail.com>; Wei Fang <wei.fang@nxp.com>; > netdev@vger.kernel.org; linux-kernel@vger.kernel.org; imx@lists.linux.dev; > kernel test robot <lkp@intel.com> > Subject: [EXT] Re: [PATCH v3 1/1] net: fec: add xdp and page pool statistics > > Caution: EXT Email > > From: Shenwei Wang <shenwei.wang@nxp.com> > Date: Mon, 14 Nov 2022 21:17:48 +0000 > > > > -----Original Message----- > > > From: Alexander Lobakin <alexandr.lobakin@intel.com> > > > Sent: Monday, November 14, 2022 9:23 AM > > > To: Shenwei Wang <shenwei.wang@nxp.com> > > > Cc: Alexander Lobakin <alexandr.lobakin@intel.com>; Andrew Lunn > > > <andrew@lunn.ch>; David S. Miller <davem@davemloft.net>; Eric > > > Dumazet <edumazet@google.com>; Jakub Kicinski <kuba@kernel.org>; > > > Paolo Abeni <pabeni@redhat.com>; Alexei Starovoitov > > > <ast@kernel.org>; Daniel Borkmann <daniel@iogearbox.net>; Jesper > > > Dangaard Brouer <hawk@kernel.org>; John Fastabend > > > <john.fastabend@gmail.com>; Wei Fang <wei.fang@nxp.com>; > > > netdev@vger.kernel.org; linux-kernel@vger.kernel.org; > > > imx@lists.linux.dev; kernel test robot <lkp@intel.com> > > > Subject: [EXT] Re: [PATCH v3 1/1] net: fec: add xdp and page pool > > > statistics > > [...] > > > Did some testing with the atomic64_t counter, with the following codes > > to update the u64 counter in the end of every NAPI poll cycle. > > > > @@ -1764,7 +1768,13 @@ fec_enet_rx_queue(struct net_device *ndev, int > > budget, u16 queue_id) > > > > if (xdp_result & FEC_ENET_XDP_REDIR) > > xdp_do_flush_map(); > > +#if 1 > > + if (xdp_prog) { > > + int i; > > + for(i = 0; i < XDP_STATS_TOTAL; i++) > > + atomic64_add(xdp_stats[i], &rxq->stats[i]); > > + } > > +#endif > > return pkt_received; > > } > > > > With the codes above, the testing result is below: > > root@imx8qxpc0mek:~/bpf# ./xdpsock -i eth0 > > sock0@eth0:0 rxdrop xdp-drv > > pps pkts 1.00 > > rx 349399 1035008 > > tx 0 0 > > > > sock0@eth0:0 rxdrop xdp-drv > > pps pkts 1.00 > > rx 349407 1384640 > > tx 0 0 > > > > Without the atomic_add codes above, the testing result is below: > > root@imx8qxpc0mek:~/bpf# ./xdpsock -i eth0 > > sock0@eth0:0 rxdrop xdp-drv > > pps pkts 1.00 > > rx 350109 1989130 > > tx 0 0 > > > > sock0@eth0:0 rxdrop xdp-drv > > pps pkts 1.00 > > rx 350425 2339786 > > tx 0 0 > > > > And regarding the u32 counter solution, the testing result is below: > > root@imx8qxpc0mek:~/bpf# ./xdpsock -i eth0 > > sock0@eth0:0 rxdrop xdp-drv > > pps pkts 1.00 > > rx 361347 2637796 > > tx 0 0 > > > > There are about 10K pkts/s difference here. Do we really want the u64 > counters? > > Where did those atomic64_t come from? u64_stats_t use either plain > u64 for 32-bit platforms or local64_t for 64-bit ones. Take a look at [0] for the > example of how x86_64 does this, it is far from atomic64_t. The v5 patch has changed it to u64. Thanks, Shenwei > > > > > Regards, > > Shenwei > > > > >> > > >> Thanks, > > >> Shenwei > > >> > > >>> > > >>> Andrew > > > > > > Thanks, > > > Olek > > [0] > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Felixir.boo > tlin.com%2Flinux%2Fv6.1- > rc5%2Fsource%2Farch%2Fx86%2Finclude%2Fasm%2Flocal.h%23L31&data > =05%7C01%7Cshenwei.wang%40nxp.com%7Caf8d6634fcfc4d77e07308dac7dfa > 4a8%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C638042060598040 > 501%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiL > CJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=sWQ4Ts > ayZvfs4pkCpC4tWvT51Cv89c4N6D5w2J%2FDC84%3D&reserved=0 > > Thanks, > Olek
diff --git a/drivers/net/ethernet/freescale/Kconfig b/drivers/net/ethernet/freescale/Kconfig index ce866ae3df03..f1e80d6996ef 100644 --- a/drivers/net/ethernet/freescale/Kconfig +++ b/drivers/net/ethernet/freescale/Kconfig @@ -29,6 +29,7 @@ config FEC select CRC32 select PHYLIB select PAGE_POOL + select PAGE_POOL_STATS imply NET_SELFTESTS help Say Y here if you want to use the built-in 10/100 Fast ethernet diff --git a/drivers/net/ethernet/freescale/fec.h b/drivers/net/ethernet/freescale/fec.h index 61e847b18343..5ba1e0d71c68 100644 --- a/drivers/net/ethernet/freescale/fec.h +++ b/drivers/net/ethernet/freescale/fec.h @@ -526,6 +526,19 @@ struct fec_enet_priv_txrx_info { struct sk_buff *skb; }; +enum { + RX_XDP_REDIRECT = 0, + RX_XDP_PASS, + RX_XDP_DROP, + RX_XDP_TX, + RX_XDP_TX_ERRORS, + TX_XDP_XMIT, + TX_XDP_XMIT_ERRORS, + + /* The following must be the last one */ + XDP_STATS_TOTAL, +}; + struct fec_enet_priv_tx_q { struct bufdesc_prop bd; unsigned char *tx_bounce[TX_RING_SIZE]; @@ -546,6 +559,7 @@ struct fec_enet_priv_rx_q { /* page_pool */ struct page_pool *page_pool; struct xdp_rxq_info xdp_rxq; + u32 stats[XDP_STATS_TOTAL]; /* rx queue number, in the range 0-7 */ u8 id; diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index 3fb870340c22..d3bf3ffe8349 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c @@ -1523,10 +1523,12 @@ fec_enet_run_xdp(struct fec_enet_private *fep, struct bpf_prog *prog, switch (act) { case XDP_PASS: + rxq->stats[RX_XDP_PASS]++; ret = FEC_ENET_XDP_PASS; break; case XDP_REDIRECT: + rxq->stats[RX_XDP_REDIRECT]++; err = xdp_do_redirect(fep->netdev, xdp, prog); if (!err) { ret = FEC_ENET_XDP_REDIR; @@ -1549,6 +1551,7 @@ fec_enet_run_xdp(struct fec_enet_private *fep, struct bpf_prog *prog, fallthrough; /* handle aborts by dropping packet */ case XDP_DROP: + rxq->stats[RX_XDP_DROP]++; ret = FEC_ENET_XDP_CONSUMED; page = virt_to_head_page(xdp->data); page_pool_put_page(rxq->page_pool, page, sync, true); @@ -2659,6 +2662,16 @@ static const struct fec_stat { #define FEC_STATS_SIZE (ARRAY_SIZE(fec_stats) * sizeof(u64)) +static const char *fec_xdp_stat_strs[XDP_STATS_TOTAL] = { + "rx_xdp_redirect", /* RX_XDP_REDIRECT = 0, */ + "rx_xdp_pass", /* RX_XDP_PASS, */ + "rx_xdp_drop", /* RX_XDP_DROP, */ + "rx_xdp_tx", /* RX_XDP_TX, */ + "rx_xdp_tx_errors", /* RX_XDP_TX_ERRORS, */ + "tx_xdp_xmit", /* TX_XDP_XMIT, */ + "tx_xdp_xmit_errors", /* TX_XDP_XMIT_ERRORS, */ +}; + static void fec_enet_update_ethtool_stats(struct net_device *dev) { struct fec_enet_private *fep = netdev_priv(dev); @@ -2668,6 +2681,40 @@ static void fec_enet_update_ethtool_stats(struct net_device *dev) fep->ethtool_stats[i] = readl(fep->hwp + fec_stats[i].offset); } +static void fec_enet_get_xdp_stats(struct fec_enet_private *fep, u64 *data) +{ + u64 xdp_stats[XDP_STATS_TOTAL] = { 0 }; + struct fec_enet_priv_rx_q *rxq; + int i, j; + + for (i = fep->num_rx_queues - 1; i >= 0; i--) { + rxq = fep->rx_queue[i]; + + for (j = 0; j < XDP_STATS_TOTAL; j++) + xdp_stats[j] += rxq->stats[j]; + } + + memcpy(data, xdp_stats, sizeof(xdp_stats)); +} + +static void fec_enet_page_pool_stats(struct fec_enet_private *fep, u64 *data) +{ + struct page_pool_stats stats = {}; + struct fec_enet_priv_rx_q *rxq; + int i; + + for (i = fep->num_rx_queues - 1; i >= 0; i--) { + rxq = fep->rx_queue[i]; + + if (!rxq->page_pool) + continue; + + page_pool_get_stats(rxq->page_pool, &stats); + } + + page_pool_ethtool_stats_get(data, &stats); +} + static void fec_enet_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *stats, u64 *data) { @@ -2677,6 +2724,12 @@ static void fec_enet_get_ethtool_stats(struct net_device *dev, fec_enet_update_ethtool_stats(dev); memcpy(data, fep->ethtool_stats, FEC_STATS_SIZE); + data += FEC_STATS_SIZE / sizeof(u64); + + fec_enet_get_xdp_stats(fep, data); + data += XDP_STATS_TOTAL; + + fec_enet_page_pool_stats(fep, data); } static void fec_enet_get_strings(struct net_device *netdev, @@ -2685,9 +2738,16 @@ static void fec_enet_get_strings(struct net_device *netdev, int i; switch (stringset) { case ETH_SS_STATS: - for (i = 0; i < ARRAY_SIZE(fec_stats); i++) - memcpy(data + i * ETH_GSTRING_LEN, - fec_stats[i].name, ETH_GSTRING_LEN); + for (i = 0; i < ARRAY_SIZE(fec_stats); i++) { + memcpy(data, fec_stats[i].name, ETH_GSTRING_LEN); + data += ETH_GSTRING_LEN; + } + for (i = 0; i < ARRAY_SIZE(fec_xdp_stat_strs); i++) { + strncpy(data, fec_xdp_stat_strs[i], ETH_GSTRING_LEN); + data += ETH_GSTRING_LEN; + } + page_pool_ethtool_stats_get_strings(data); + break; case ETH_SS_TEST: net_selftest_get_strings(data); @@ -2697,9 +2757,14 @@ static void fec_enet_get_strings(struct net_device *netdev, static int fec_enet_get_sset_count(struct net_device *dev, int sset) { + int count; + switch (sset) { case ETH_SS_STATS: - return ARRAY_SIZE(fec_stats); + count = ARRAY_SIZE(fec_stats) + XDP_STATS_TOTAL; + count += page_pool_ethtool_stats_get_count(); + return count; + case ETH_SS_TEST: return net_selftest_get_count(); default: @@ -2710,7 +2775,8 @@ static int fec_enet_get_sset_count(struct net_device *dev, int sset) static void fec_enet_clear_ethtool_stats(struct net_device *dev) { struct fec_enet_private *fep = netdev_priv(dev); - int i; + struct fec_enet_priv_rx_q *rxq; + int i, j; /* Disable MIB statistics counters */ writel(FEC_MIB_CTRLSTAT_DISABLE, fep->hwp + FEC_MIB_CTRLSTAT); @@ -2718,6 +2784,12 @@ static void fec_enet_clear_ethtool_stats(struct net_device *dev) for (i = 0; i < ARRAY_SIZE(fec_stats); i++) writel(0, fep->hwp + fec_stats[i].offset); + for (i = fep->num_rx_queues - 1; i >= 0; i--) { + rxq = fep->rx_queue[i]; + for (j = 0; j < XDP_STATS_TOTAL; j++) + rxq->stats[j] = 0; + } + /* Don't disable MIB statistics counters */ writel(0, fep->hwp + FEC_MIB_CTRLSTAT); } @@ -3084,6 +3156,9 @@ static void fec_enet_free_buffers(struct net_device *ndev) for (i = 0; i < rxq->bd.ring_size; i++) page_pool_release_page(rxq->page_pool, rxq->rx_skb_info[i].page); + for (i = 0; i < XDP_STATS_TOTAL; i++) + rxq->stats[i] = 0; + if (xdp_rxq_info_is_reg(&rxq->xdp_rxq)) xdp_rxq_info_unreg(&rxq->xdp_rxq); page_pool_destroy(rxq->page_pool);