From patchwork Thu Aug 10 11:00:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13349283 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DDFB4C001B0 for ; Thu, 10 Aug 2023 10:56:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=o9W9fwqAvw7E9sDBTut8vi30ZzhrhlACJCXodvKC2Q4=; b=ntdv4Ez47XTpHF 0OUE8+oTBu+GDGokBl5jF8zzZKz9X41kYmgVP+q2ZS+O2YvFIBfJ47Cu47T+aNxkHmPuoGyW/F7eO 36/AD8fqAhcr96ozQ/1Wr6sNrLcQNyCrw4kSgbXCctdDLTriqGWxiGb1l//giCwm4pwuu5vJqtFzm TQ3fGHmNhnZM/zd4fekAxsmQnmlPQP0N3YadUsH8CNz73gb08D4hEadPZbvINFKPhDIp8opYMVmA+ /iayg9MxbxvEzyaNKaefWeqyUc0tq9LSHwSzASf5m1V7Fiquqzhmr9c4jNyd9DftaHSLZJ/A6uMls gMtkl4IXAHTZhdfxPiyA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qU3LD-007JiF-0j; Thu, 10 Aug 2023 10:56:31 +0000 Received: from mail-he1eur04on061f.outbound.protection.outlook.com ([2a01:111:f400:fe0d::61f] helo=EUR04-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qU3LA-007Jgv-0z for linux-arm-kernel@lists.infradead.org; Thu, 10 Aug 2023 10:56:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jey2SwWc7YWrJ6Z0IQEqygG0zmfOEO3uPq4A1LdxaeFKtsb5IKDXMWo/1OfqtFAOPqSon7DCgGPE36yfP88ZTBO/RmX6JXb0TdM1m0cOfscRZAKrdbj13paLqDxEg/KMajWUh2ZsUDOuTTCDJ4gsstSmy1yzZ6/JpVzOEg1s3dXhhtulVcQTb7iZyeiqs9YLP28khy99Pue5Ce3DGcWHg7bjs4iEFbDiyit6dZCikZkNygHF+16Z6rgcYcqTSymL5r8ocyuJAudwrwr1pSDG/i4RMI5p/exKl6si5nQr4cSO7yE3NCftKJYExT5JMUeCDsqcFnQ8Vjkt7OaZSOe4NA== 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=fo68bo5hDZVoZqz0mgGM/afuG0+D8tfRxAqKGqBLJxo=; b=bHPcjTKmkM0hTx/vijV+5nWeqH/PBijjZ1pYjFyghVqomHJVZXWKjLgQHYgAmsaXew2cxiAevGdvMSz1mfuUu3oldxnH9MdR098hA4tONVhWvTCB8s1hNzAoTqEVuFrRE19JGlopfj5vZkuMifCV8fzdy9IfD1Y/OZs91vWmy5u+91RW1xcas8r7BzLLXzUsbwmFZuzIMcHo+wkG9otwmxbo4SqXV4vesyjNObpa4XnBhxkkyz4CgYFTMaezAlKhvK5Lr1PYNbVgBpJrAmHw1ULHLQvFJODyDkLA1lpKQZ0PZbkxPaZ864CDKA264KuQAp2PNwbS4bM5sfHFBx2MwA== 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=fo68bo5hDZVoZqz0mgGM/afuG0+D8tfRxAqKGqBLJxo=; b=TVighPMALtRGocPBiwxjz79ZjOHVK9mbb/wx3nmezU/YhbvojmlhQGabiURr2VZGG2NJcDmxEpIr7ODCBD+TnecX3epkLw8jNyHp6+eGzwLrLzYyI+nxLUbPJoHoAM9vz25i8ycsCgFQOM/Spm2bc+pWb4u4Rp5PiqiGhDMkllI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) by PAXPR04MB9108.eurprd04.prod.outlook.com (2603:10a6:102:22b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30; Thu, 10 Aug 2023 10:56:20 +0000 Received: from DB7PR04MB4505.eurprd04.prod.outlook.com ([fe80::85e5:acf6:574d:a2a1]) by DB7PR04MB4505.eurprd04.prod.outlook.com ([fe80::85e5:acf6:574d:a2a1%4]) with mapi id 15.20.6652.028; Thu, 10 Aug 2023 10:56:20 +0000 From: Xu Yang To: frank.li@nxp.com Cc: will@kernel.org, mark.rutland@arm.com, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, linux-imx@nxp.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 1/2] perf/imx_ddr: speed up overflow frequency of cycle Date: Thu, 10 Aug 2023 19:00:27 +0800 Message-Id: <20230810110028.1975176-1-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SI1PR02CA0042.apcprd02.prod.outlook.com (2603:1096:4:1f6::17) To DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4505:EE_|PAXPR04MB9108:EE_ X-MS-Office365-Filtering-Correlation-Id: d2154d86-cda9-4379-935e-08db99906e0c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Yx800FBDo+L2KLyPKXXWmgdgyNijzvhXb6rNk3/b9JiJ4+iLY0KFUAMzUOd9Cb3ftFRYSY79wdynevYMIuKEFGol+z/7DgDjeSwPQVsqRAtjkRTNwhsvPvy6qjkP/fMjWSmq52y5PQA5hmao2tC1DKZEZb3NsJk58odL/7KuHtUECyUzNvAt4J5hTCobL+oxczKc08NzDOrydjmaouONM2LpouONvKe71WFq+cSG73KntAozrHJWhdmkfWcIPy8rW+AbFFUosXepyGCvOKkDlYxcqQIg8B1XyNKDzG6Cl0prajNDhthu8BkD0SlOwbcTuix6N+5DnpgEh3ADDOv95eM8neOQCWPA4RFE9NR9wSzxwxKjMVoWrvvkFjfmSVu9OxxmA7SaBMkSvJ2hRwrpeT3VvO0avzj0hcBRQOiPusg+5MFKJsQrl5HSr8QaBDpJGL3TcpOhjzQNq0t12GNr2zHeNVjrFarduTQ12icujaP5rRuuPGiMcEpESZpE0a9sRO/nH8gdAg5zsA0TGI/z4GEeKgm0BHexrvNzftUE6A+dnJKatUXRGTLz7xhzkJ8CT+vAbfyHsN6vYVcmaFFaTdWfZbJlX7Hid7z563oocM7qgIlQ0wU3cjEgmPc40rwd X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB7PR04MB4505.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(136003)(39860400002)(366004)(396003)(346002)(376002)(186006)(451199021)(1800799006)(478600001)(36756003)(37006003)(38100700002)(38350700002)(2616005)(66946007)(6636002)(4326008)(316002)(41300700001)(8676002)(34206002)(8936002)(66476007)(5660300002)(66556008)(6486002)(26005)(52116002)(83380400001)(2906002)(6506007)(1076003)(6512007)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /Epm5LWUZzZayjvGN4gbW0YdjChHfwLsQ96tf9KQHLX+DOnjwfNbuWz44q+4cqy9tXQCUSaoE1idduAfgwSC2BQSEyQthIMkc1yuHZioNCfpZi2ZakhuLSdoP9yhg4z7YA/1n7eeYvxEzQyg2i3sD+Jk/hhnMZZHMvq+GgY9EFykFltWb5PriJZP+eJL8+dLYhT62xTIO36EBGwEsxkqU2eNIlK3e1Yj43SgosjsvBzWK27Ws7W/o0D1Ch7U1WBsm9LNgZukweVe4O9/ntKg1gPt6poT//lrCUAuXuytTuJodkmF8wXleBav2EcHfnstKJdDcrqmQOH1cejsfOeBA80ep86cwrS0nz4xbQNK2+YRJJDt0aduNrJmCuou8fWnyLIr4zR8c1S/Jx8h6WpUrOS1Fh+5nfTZOgcTRNoQ6GX6dEuSI8y+fgHHw0urjIQtMc0cSR5Oqpgml9Nd7vrEAkYnlUpgIR75PqkVVgAuQHqPkNqXw2Bh+0gkEjq4GxrW2al54Y6GuAD5bwDdWbG7GmRn9ye/QYaOol/UHmJIt6n3DE2f8AJM+mZ5wZgAnm+MBDAhoGNY5SD1vRI6XPtnytpxut4m3DnHoL2DY36/KTh9MCm2FAaLnNk57bhKZg1hY0XzjBY1XnVBfukJJJ5UDidRO1jNZB9vngCdegAyYKc6rQokyCIf3e/oPwoRBxHLYNk3qsFuRgl1XAOZhMuo59d/+XjbHsBt9H9qSoGoheddsrcooEADmpG+F7qo8KkXicbcehhO8gQiJ6sHAnWImBcFF3unK70rAg5sBzUInm/Ct6IXh9eK4hBB9t8bEJy1iNCcn3IBgI4J9dlgkto8+XAFRSlMViVPGx7nOmUl2YkeqfPI1r6Z9h/k/kuhXd+tVCv4fEJsCe3yWu/F7IOH+LCWpnT2wSWI1OxLIgCzppsMxLwYAXaRkmkaJh02MJw9+eovP/760lAXRYhxxmd3Mrhy+4R0ToaR4UGCfzsTTLvv0SnJLuXpX1m/3JOcjpzefYn0huv4j/T4HlymCzGfahnTFgmet71ubFrO27LATRykREQW0dni/5DUOf4RHove469Uh288oLTpP5uLFlewgG8A6TxGer/8s0yOfpWXEYk4K+ynqL/mJQegA+aVJo3owJzGqtmqcqafdDY8AsovYsyx0gJNnZ1i5vYe9Pzj2BM2sHPTp9XbB9SQ/a1biEKejS99ZlNo4jjyVCx8jArBq54FVNvl6TLSiMJb9X6RdaMemFfj9sCtxC6jr4LJtW+CxyiQ/er6ATZlhaMUwmzGX2tFqHwSpcd22StyDcdwzcndhTISCm4gbp2Pd0qUihLp3uZ5iA1QNCGwgloQDXkstbw0r7egp1eULtr6MaaOCFq7gDwPrQf6wXchcPAp7fCzlyMOMIYERP7Iw8xu1OEhFMvS5t1Qp+m/3Ysrp+JxTI2ZJezG39+LGDJv08U39Wdto/Li4WB8XUZyGmVc5h8xKFhX8aBGMxsuyM0m2Z72UJMuSjr/VUwFizIRFKexVlVISY3hGCHl/rQyh6o9/wsIp+1w7MBO+FFOpNduygSaa+Kb0BmOsx2nGwsJ7r8LDDFu X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d2154d86-cda9-4379-935e-08db99906e0c X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4505.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2023 10:56:20.6727 (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: SuyMwax3jc2YW6YBAkt2Zu+ph5ZwdHU33P1Vt+8bBYssNcLHMc404h32h3O6D6WZqj+0n0CcB099tVd9N5PQDA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB9108 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230810_035628_381244_01A58C99 X-CRM114-Status: GOOD ( 15.78 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org For i.MX8MP, we cannot ensure that cycle counter overflow occurs at least 4 times as often as other events. Due to byte counters will count for any event configured, it will overflow more often. And if byte counters overflow that related counters would stop since they share the COUNTER_CNTL. We can speed up cycle counter overflow frequency by setting counter parameter (CP) field of cycle counter. In this way, we can avoid stop counting byte counters when interrupt didn't come and the byte counters can be fetched or updated from each cycle counter overflow interrupt. Because we initialize CP filed to shorten counter0 overflow time, the cycle counter will start couting from a fixed/base value each time. We need to remove the base from the result too. Therefore, we could get precise result from cycle counter. Signed-off-by: Xu Yang Reviewed-by: Frank Li --- Changes in v4: - change comments bit error - add CYCLES_COUNTER_MASK Changes in v3: - modify the comments as suggested from Mark - use mask to remove bias value - merge two patches to one Changes in v2: - improve if condition --- drivers/perf/fsl_imx8_ddr_perf.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/perf/fsl_imx8_ddr_perf.c b/drivers/perf/fsl_imx8_ddr_perf.c index 5222ba1e79d0..e59e4fc6378d 100644 --- a/drivers/perf/fsl_imx8_ddr_perf.c +++ b/drivers/perf/fsl_imx8_ddr_perf.c @@ -28,6 +28,8 @@ #define CNTL_CLEAR_MASK 0xFFFFFFFD #define CNTL_OVER_MASK 0xFFFFFFFE +#define CNTL_CP_SHIFT 16 +#define CNTL_CP_MASK (0xFF << CNTL_CP_SHIFT) #define CNTL_CSV_SHIFT 24 #define CNTL_CSV_MASK (0xFFU << CNTL_CSV_SHIFT) @@ -35,6 +37,8 @@ #define EVENT_CYCLES_COUNTER 0 #define NUM_COUNTERS 4 +/* For removing bias if cycle counter CNTL.CP is set to 0xf0 */ +#define CYCLES_COUNTER_MASK 0x0FFFFFFF #define AXI_MASKING_REVERT 0xffff0000 /* AXI_MASKING(MSB 16bits) + AXI_ID(LSB 16bits) */ #define to_ddr_pmu(p) container_of(p, struct ddr_pmu, pmu) @@ -427,6 +431,17 @@ static void ddr_perf_counter_enable(struct ddr_pmu *pmu, int config, writel(0, pmu->base + reg); val = CNTL_EN | CNTL_CLEAR; val |= FIELD_PREP(CNTL_CSV_MASK, config); + + /* + * On i.MX8MP we need to bias the cycle counter to overflow more often. + * We do this by initializing bits [23:16] of the counter value via the + * COUNTER_CTRL Counter Parameter (CP) field. + */ + if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_FILTER_ENHANCED) { + if (counter == EVENT_CYCLES_COUNTER) + val |= FIELD_PREP(CNTL_CP_MASK, 0xf0); + } + writel(val, pmu->base + reg); } else { /* Disable counter */ @@ -466,6 +481,14 @@ static void ddr_perf_event_update(struct perf_event *event) int ret; new_raw_count = ddr_perf_read_counter(pmu, counter); + /* + * Remove the bias applied in ddr_perf_counter_enable(). + */ + if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_FILTER_ENHANCED) { + if (counter == EVENT_CYCLES_COUNTER) + new_raw_count &= CYCLES_COUNTER_MASK; + } + local64_add(new_raw_count, &event->count); /*