From patchwork Tue Feb 8 04:46:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Foster X-Patchwork-Id: 12738163 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 831F5C433EF for ; Tue, 8 Feb 2022 05:33:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347104AbiBHFcw (ORCPT ); Tue, 8 Feb 2022 00:32:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347016AbiBHErB (ORCPT ); Mon, 7 Feb 2022 23:47:01 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2097.outbound.protection.outlook.com [40.107.220.97]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08E7FC0401E9; Mon, 7 Feb 2022 20:47:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G4fKnY7hkjy6186++n+Nn/VKlf4aGW+VFfgXFDF4bqvAlfdTCZA2Q+I7373NkuTlMGDXMHsv+ynDKVcv4rksB5soPAjiTNR/f5rRUiSMInK4yX4g1gOGMwjZQRFDdnoMIm7dAbYqKUmP9qg8ShSOA8nMHRPxKdnH9/HFN9E+BoTrBokbzcLjEHQuKBtBfqBUs6VGuzQS60Ptd3ThzlRmvJX/1pqvn/pIXOO67Pn5gnD754Jba3bFV2Sam3bOMFjqgAqabGtnT+EBBgyn9Fv3HI1Aj+f+1ghlmBpx+lznLZDkMyP5N864GlwRgc/OiU6Xk9HiAjs597jQfmNNJWPYNw== 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=Gc3k37fgcH4Cy6R5yFs/SVQZ8AteMJL/IRFkIAGwOj0=; b=mooxyRQ1+PCA1Aul1rQlDYv/SH7OXqqFEtoyRtulvCpfs/DM2x3TuN1jE/VyLJFPVLxN9Ufo2gfPGHJfDHuAhxCooJ/dfjDv4q9lKEknE7kLPBkRSytm2EI7qxGCla0Mm3SJWVC6kRgqunWXG5b2aIQC70jJ1sMTvN8vHT20I5nY+8Eo8DLH+Bn+3MoMPh26Fp+ikmB40y/4/5WSSX61K9rVy7ZQskFk4u8p9set8Tm0PKELO1yYD+b/bXE3IYkrymzuWq3LMHIjtbM7SSYWSgSM/oUI5URNuxgtU5S2NJPBnMVqWhWM4mIYEz2ng8ZpO6oPiwYvfeX9CM0mdDI9FQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inadvantage.onmicrosoft.com; s=selector2-inadvantage-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Gc3k37fgcH4Cy6R5yFs/SVQZ8AteMJL/IRFkIAGwOj0=; b=okSU1O77DiB0T7xeMvx2VCBzYM7FhqZPOsxD7HjV7DOH6rOA/GOgi0p5FD0BGiQi2Z9bBZ3hpPsTCMbgSr6EdPhjiqLpslASHDBnf9e9I+Ap2FKv6DTWnpqk/T0xH+CIYzU7/hVIC3Cz8/Tb5ojl9qPiDA8fUdhHLma8gt9yQ10= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=in-advantage.com; Received: from MWHPR1001MB2351.namprd10.prod.outlook.com (2603:10b6:301:35::37) by MWHPR1001MB2176.namprd10.prod.outlook.com (2603:10b6:301:30::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4951.12; Tue, 8 Feb 2022 04:46:57 +0000 Received: from MWHPR1001MB2351.namprd10.prod.outlook.com ([fe80::2d52:2a96:7e6c:460f]) by MWHPR1001MB2351.namprd10.prod.outlook.com ([fe80::2d52:2a96:7e6c:460f%4]) with mapi id 15.20.4951.018; Tue, 8 Feb 2022 04:46:56 +0000 From: Colin Foster To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Jakub Kicinski , "David S. Miller" , UNGLinuxDriver@microchip.com, Alexandre Belloni , Claudiu Manoil , Vladimir Oltean Subject: [PATCH v5 net-next 3/3] net: mscc: ocelot: use bulk reads for stats Date: Mon, 7 Feb 2022 20:46:44 -0800 Message-Id: <20220208044644.359951-4-colin.foster@in-advantage.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220208044644.359951-1-colin.foster@in-advantage.com> References: <20220208044644.359951-1-colin.foster@in-advantage.com> X-ClientProxiedBy: MWHPR17CA0090.namprd17.prod.outlook.com (2603:10b6:300:c2::28) To MWHPR1001MB2351.namprd10.prod.outlook.com (2603:10b6:301:35::37) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f63ab5a8-2bde-47d9-f6f1-08d9eabe0888 X-MS-TrafficTypeDiagnostic: MWHPR1001MB2176:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1060; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /kglMlFDvd8WapdwImEJouIXaEQIi0SArH7etynnSs6/xHYJ74wTImr3MrmwCzCfeaEYHLXBiQpM7AEBBeECol2YSn+PZBZNXp88Wnqh1gsAwqC5XDjeQRHtbmOU3IDVi8s7s2f3Ddw9wi+zhd7/Oqd78O0r/MVESkz5osNhfkCdAg0z4or3bAl54xdTuKtI37O2v1zkYXpcBE9kIXgVcz09744I55KibJcSHnpuvun8OGjLiSuRuAvi2bIE1eTFDxp+YTiu19ENozNPllxaY4RKJICJvQaeccAcQ6s1cVhCdV62BSOKPsMV5cSZcIF/tYXNqybcfnW0C64fjORJhm7JWj8/MBwoAkkpwsowfKtJloZd5g1o15VZSmRJWwsTGcBC4bZaDY7XxeVw1b3yyeoy7I2bGT2GEEeT123O+aN0da5+7Sb9FSougkgRFn9y7Uq2II/nGRlisSntjHy3l/r9CGttD6klQqG5loHLs3KZ3bABYxNL92MeH0ID25n+JLiqQxo5JoB5B4ZrvPe8ZLuw6vIaEF74o7KD8LdrazWNukNETLm0XNTIv2iuy0LTyigT8pBp0Ty/h8TubNJjG446tAzPKxL6mI6FxGtK9W6oKN2wD0jlXAlMgxxY3TcCGTT0b5j39aTxG9aN2m2prK55jQ1n3BASHAVBW39UCbrUmbhKU+hnlFY1v33eCBBj7ZxV2U0ohskYvGo2rTYS5A== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR1001MB2351.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(366004)(376002)(39830400003)(136003)(346002)(42606007)(396003)(54906003)(86362001)(508600001)(6506007)(44832011)(6512007)(52116002)(36756003)(8676002)(8936002)(66556008)(4326008)(66946007)(6486002)(66476007)(83380400001)(316002)(1076003)(186003)(38100700002)(2616005)(38350700002)(26005)(2906002)(5660300002)(6666004);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9L6MmNNXLO72kpSU3vs3Vs+1/brKx8JyMJYm2ukdDxk2PYpLKcSiVGeQUp6BF4erSsUD9txGdnsXuGTNR0zn/TeRrRQob26d0KRIHmWXjKm9iRdhCjNitAX75JUKfNd8Zktqzov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uBhAPMWXUyWX9hbaUPplYRWhnU8DPByd8IkVZKPeQA6g+YlxqG1bbtPXfvYSLuybQ2XhQa2PeGH3XuFk6zqCXw3G+Nm+5chiMpfBAu1pNqIIER01507hIjji/MJkxXB6WZQgC30pCpo/l4rDbxMl5b0/Xbds439RRwTmSo3io909A0YXfWF5Msf7RvNHPLeO89uyZMvAV7G7PCNBSuE0eyHi41KSmY73bAj7IeLEsBO4+SGN7NHXFrzbl3+6syFK+LdoXAKGGAnL88xCg0gDVq/i+ZUk1DEPByBmKllR/cXdd52rmIjuahbGnORmRi0DLu3RzWe2aI+3eah2cUFcZS5g/slDk/6HeALHYlHD99oy/HlH65Au0cs2EvGikH6c8fL5oKKxRlxnBhT9pdTw2iIflH0ZQtsBFioPEf+eivFxtY/XqXlUK+/GZKvikcbKGbL8hIwoXco1z0ILA== X-OriginatorOrg: in-advantage.com X-MS-Exchange-CrossTenant-Network-Message-Id: f63ab5a8-2bde-47d9-f6f1-08d9eabe0888 X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2351.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Feb 2022 04:46:55.8609 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 48e842ca-fbd8-4633-a79d-0c955a7d3aae X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bDaV868a27ALZXwIUx+lbZpXVlAUWklc0R/w6crbkewB3/aJrcVT3Iokj2tWFBwGTTazI7meUJDkPbf0FjdMUUknRJDvvUa61iTAWYzAD7A= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1001MB2176 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Create and utilize bulk regmap reads instead of single access for gathering stats. The background reading of statistics happens frequently, and over a few contiguous memory regions. High speed PCIe buses and MMIO access will probably see negligible performance increase. Lower speed buses like SPI and I2C could see significant performance increase, since the bus configuration and register access times account for a large percentage of data transfer time. Signed-off-by: Colin Foster Reviewed-by: Vladimir Oltean --- drivers/net/ethernet/mscc/ocelot.c | 78 +++++++++++++++++++++++++----- include/soc/mscc/ocelot.h | 8 +++ 2 files changed, 73 insertions(+), 13 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index 455293aa6343..5efb1f3a1410 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -1737,32 +1737,41 @@ void ocelot_get_strings(struct ocelot *ocelot, int port, u32 sset, u8 *data) } EXPORT_SYMBOL(ocelot_get_strings); -static void ocelot_update_stats(struct ocelot *ocelot) +static int ocelot_update_stats(struct ocelot *ocelot) { - int i, j; + struct ocelot_stats_region *region; + int i, j, err = 0; mutex_lock(&ocelot->stats_lock); for (i = 0; i < ocelot->num_phys_ports; i++) { + unsigned int idx = 0; + /* Configure the port to read the stats from */ ocelot_write(ocelot, SYS_STAT_CFG_STAT_VIEW(i), SYS_STAT_CFG); - for (j = 0; j < ocelot->num_stats; j++) { - u32 val; - unsigned int idx = i * ocelot->num_stats + j; + list_for_each_entry(region, &ocelot->stats_regions, node) { + err = ocelot_bulk_read_rix(ocelot, SYS_COUNT_RX_OCTETS, + region->offset, region->buf, + region->count); + if (err) + goto out; - val = ocelot_read_rix(ocelot, SYS_COUNT_RX_OCTETS, - ocelot->stats_layout[j].offset); + for (j = 0; j < region->count; j++) { + if (region->buf[j] < (ocelot->stats[idx + j] & U32_MAX)) + ocelot->stats[idx + j] += (u64)1 << 32; - if (val < (ocelot->stats[idx] & U32_MAX)) - ocelot->stats[idx] += (u64)1 << 32; + ocelot->stats[idx + j] = (ocelot->stats[idx + j] & + ~(u64)U32_MAX) + region->buf[j]; + } - ocelot->stats[idx] = (ocelot->stats[idx] & - ~(u64)U32_MAX) + val; + idx += region->count; } } +out: mutex_unlock(&ocelot->stats_lock); + return err; } static void ocelot_check_stats_work(struct work_struct *work) @@ -1779,10 +1788,11 @@ static void ocelot_check_stats_work(struct work_struct *work) void ocelot_get_ethtool_stats(struct ocelot *ocelot, int port, u64 *data) { - int i; + int i, err; /* check and update now */ - ocelot_update_stats(ocelot); + err = ocelot_update_stats(ocelot); + WARN_ONCE(err, "Error %d updating ethtool stats\n", err); /* Copy all counters */ for (i = 0; i < ocelot->num_stats; i++) @@ -1799,6 +1809,41 @@ int ocelot_get_sset_count(struct ocelot *ocelot, int port, int sset) } EXPORT_SYMBOL(ocelot_get_sset_count); +static int ocelot_prepare_stats_regions(struct ocelot *ocelot) +{ + struct ocelot_stats_region *region = NULL; + unsigned int last; + int i; + + INIT_LIST_HEAD(&ocelot->stats_regions); + + for (i = 0; i < ocelot->num_stats; i++) { + if (region && ocelot->stats_layout[i].offset == last + 1) { + region->count++; + } else { + region = devm_kzalloc(ocelot->dev, sizeof(*region), + GFP_KERNEL); + if (!region) + return -ENOMEM; + + region->offset = ocelot->stats_layout[i].offset; + region->count = 1; + list_add_tail(®ion->node, &ocelot->stats_regions); + } + + last = ocelot->stats_layout[i].offset; + } + + list_for_each_entry(region, &ocelot->stats_regions, node) { + region->buf = devm_kcalloc(ocelot->dev, region->count, + sizeof(*region->buf), GFP_KERNEL); + if (!region->buf) + return -ENOMEM; + } + + return 0; +} + int ocelot_get_ts_info(struct ocelot *ocelot, int port, struct ethtool_ts_info *info) { @@ -2799,6 +2844,13 @@ int ocelot_init(struct ocelot *ocelot) ANA_CPUQ_8021_CFG_CPUQ_BPDU_VAL(6), ANA_CPUQ_8021_CFG, i); + ret = ocelot_prepare_stats_regions(ocelot); + if (ret) { + destroy_workqueue(ocelot->stats_queue); + destroy_workqueue(ocelot->owq); + return ret; + } + INIT_DELAYED_WORK(&ocelot->stats_work, ocelot_check_stats_work); queue_delayed_work(ocelot->stats_queue, &ocelot->stats_work, OCELOT_STATS_CHECK_DELAY); diff --git a/include/soc/mscc/ocelot.h b/include/soc/mscc/ocelot.h index 312b72558659..d3291a5f7e88 100644 --- a/include/soc/mscc/ocelot.h +++ b/include/soc/mscc/ocelot.h @@ -542,6 +542,13 @@ struct ocelot_stat_layout { char name[ETH_GSTRING_LEN]; }; +struct ocelot_stats_region { + struct list_head node; + u32 offset; + int count; + u32 *buf; +}; + enum ocelot_tag_prefix { OCELOT_TAG_PREFIX_DISABLED = 0, OCELOT_TAG_PREFIX_NONE, @@ -673,6 +680,7 @@ struct ocelot { struct regmap_field *regfields[REGFIELD_MAX]; const u32 *const *map; const struct ocelot_stat_layout *stats_layout; + struct list_head stats_regions; unsigned int num_stats; u32 pool_size[OCELOT_SB_NUM][OCELOT_SB_POOL_NUM];