From patchwork Tue Aug 8 07:27:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13345780 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 74050C001DE for ; Tue, 8 Aug 2023 07:24:30 +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:References:In-Reply-To: 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: List-Owner; bh=QaVzuPhZdFN/nOtEYXD36f0LxeCj/Geueqng2AzAAt4=; b=eeIBx3nQxhzWZ6 K6oRKyn/YerjyPLRLi/0Ti7Ji38GSbZi+BeWVesyomUkp1PAUF4dATZP00ppeW1rWc2XJojqEMX+O 3u2Bp84IcDcDY662qSe7imBL9Q9Udnp4HN72WSuH+aTAo/VfVaYTWIeYVDQvNd3gFTfnrEa8Ge00m ds8AEzJtx++pUhGpVcIRDS+akMg/Sv6xFhjN5q5vxXeFLCTJLhYSYSQFSYAGN41ZQpsWFaQtg2ynp 44PT10CIdHEJVOk8NvBpYaNydWvuNCsNEy8yMXfonFEJ93lZ2NkG0dVaiAGMjfj0F8y5FTjy/FFnZ XojDWttld0Sx9s7BBkpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qTH4Z-001shC-0e; Tue, 08 Aug 2023 07:24:07 +0000 Received: from mail-db3eur04on060a.outbound.protection.outlook.com ([2a01:111:f400:fe0c::60a] helo=EUR04-DB3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qTH4V-001sfV-1I for linux-arm-kernel@lists.infradead.org; Tue, 08 Aug 2023 07:24:04 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y3QIeHPl7oFia5kJd38v4p3RgZT00aGbcn7LELcXOSP3mxsYRLmDdWSULrxKOFggI9DIrmYmScoqWJHcVPfF5QK7ruBjk5XQmTl2IYLfwCz/YfpDKD0zMbGbOtGK2eh0ww3hLpPYlwR2W6CMYHtBZYgacVxSTazTW1eiHHB3zLSuTZxMyhCDBGCTSJbFQrCnc1GWOZxC/TZck7OIoiiXPvqNo7AeEn3qMBine1iq0KShY7C1ymzvzGgmm3D13YHPU6BmawsOP+/YSoKVtFU+qJV94l+qqwZEcItOV5jKPlLY2hY9VFT9X9LmKmYW1r3BRCvnfxQ1X8ehnXGJ6YY1mA== 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=YKWpUepyiS6di/sgCgwvsmtcfDzYIpIfHuaBJ1v9Fz8=; b=MJ4X7f1X3pXLtveC7kpdktYoJ/o1AAR5jfHj1pjP3bGFtRebgTXNkkVrUZ+Q3UiMZxjS+qpm/Ryku5yicf6pgUo/yF6nxECYI2OLSrly37Vk2EYgWIWMweInIJIw2FNX/ZUcAYFR/YXBWbaXN48rdPsCSiEmu/oCOpUsQaYcVZmrMN8WybYMAjeVSgm8NmbzaR+HAVeguH12ozhyBRd+p12k7dWTAF5nq3Psrf9LDvX4WAJPIY2aJybIFU1FzeJtnLDb2j3XezEhFxD/UY98Dbs/SZsEzRAMRBL2Kqmb/Sp9fa1T4unUSCc0Ot3zjEtTWgCL17yEdZwLc9hvayzWNA== 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=YKWpUepyiS6di/sgCgwvsmtcfDzYIpIfHuaBJ1v9Fz8=; b=RwKetQLIRIv55YbCqKATXV7ulSLCFOolV2uyGK78jrRUGXFAPfUS1udiJ6GoWH0XJ918eX9hPsFnSKOhmDP7N7D2OxNXjWYIIPcFQM3Y/MPOfKkQ8VmAZtM/Io4FEseeKbRRx3wTZZgUBSAZNiX+sxrtWErcKw1IerdudRpg9Rw= 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 DUZPR04MB9900.eurprd04.prod.outlook.com (2603:10a6:10:4da::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.26; Tue, 8 Aug 2023 07:23:57 +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.026; Tue, 8 Aug 2023 07:23:57 +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 v3 2/2] perf/imx_ddr: don't enable counter0 if none of 4 counters Date: Tue, 8 Aug 2023 15:27:48 +0800 Message-Id: <20230808072748.374345-2-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230808072748.374345-1-xu.yang_2@nxp.com> References: <20230808072748.374345-1-xu.yang_2@nxp.com> X-ClientProxiedBy: SI1PR02CA0040.apcprd02.prod.outlook.com (2603:1096:4:1f6::7) To DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4505:EE_|DUZPR04MB9900:EE_ X-MS-Office365-Filtering-Correlation-Id: 3105a201-1bc2-4b0d-e362-08db97e06dc6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mDD5pXHeqm4kQuaOt2aD85KKHOHLmOpO0mRYeWNwSPngvnVaP5G+e5K5GucnnnX1quaxBsvt/Yxk/EMwF+OYEUgUIQOsT8tlVxc/J9ZapZg5rdzNqEYWTireyvvyiYfQ8JOZgtPdm8ZSqqha10JwWzhoib8mOMtO75zyqDzJnTEiEHAen/3fRUx5/ZJZYQTWJMx8QH07ZGQGvVGYiHArZ35zxFN7Cft4a5VE/3Qb/uEfUou/S6eE0VldZ0O8PKslnKySbR3+kb8D61Hk/kKF1KYK+i0LrK3AJrQ7JeLCdtG/jobAQL6Z+NL6H217ndyu9kyqyRTh9gWNzgHYYS0dgdQ0Ogsy0CpygTkEy5hsqBo5+mDWr0YNZBrW3VNv7pni+dglglDYVfpKyfGjBj7iIoWRA0OLxaFBmlmbQW2NN7JcGfQpnfXv+fu2Sg8mEfAkoymUxLeYlpK8USVK0b94Keo5OHsPvbtDcKh6J4YWLTDdQCdcTZizXNPLoC7gSAufjjAcFFSFW/wBpVQChP3+j8EMjPd3Pm9u9Xej2QkWxsnX6mZzaNpqEYjCox1Im0E0Ll8gFCaw3JZik9+YoaWTHlgt6sLPfDVRr8Ynr+ha12CUNRp921Ky7R+Ff/Kqy965wOVkjpwtuSUv3r2dLmQ6xelo1Il+rEYtfhgwdGEpQh8evKgXbxyCDRxN/pKqfiqi 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)(39860400002)(376002)(396003)(366004)(346002)(136003)(90021799007)(451199021)(186006)(1800799003)(90011799007)(86362001)(41300700001)(478600001)(34206002)(1076003)(6506007)(8936002)(26005)(8676002)(38100700002)(52116002)(6486002)(38350700002)(6666004)(5660300002)(2616005)(83380400001)(2906002)(36756003)(37006003)(316002)(66476007)(66556008)(66946007)(4326008)(6636002)(6512007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cP6eVjDBiGKo0ryqxNw/cOWvodrcUpZRnChiPH3Y5DkwFGp/Do/9IevQpQ93pp8b1/QD68uSiLDOC2JzVlKD6DsXiXhjqNO94KB3t9k+EY5nGaqE2Czds2LqpLX90B3ncCCMiSELvEmN4BwlRtEZBGEKseKna21X/CNQtl2bgCVskslCjKmpbFui05npAbBOAeG3oAt/FF9S3sqq4MNnxEOOIT+pIqH+8SbDAAkgt7oh3WUibhe47sBJAa8CrLa77SZVciiLAPYkCHshSvS3C35xDkb54FIvfJZMGHOA0kmmVMRvdRA2eC5BEIw0BZ1xQexYcTuTZEv7pqs6iyKK1MxPSB/B1EyEpKPZA5IueTKZXIL6ZF6NT034lA9LYM4W3cm+xjDt4uU51ZM9V9U9AgXauv/hQiatjeKPibcAgpLxrEtyh/MKfAelzqRg60ZaKAFvQaOUAf5Poxv7A7JVrqIe6N0mxze4JPuGRO1CpqNicW3xkzNS7mbpJ3q5cgfsnT0IEhZdQW4xXkIieH1T6Hv1ppCSxHLFpa2xk8Bqz8OW2M64+ufAzr5QxQ30ejV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-1bc2-4b0d-e362-08db97e06dc6 X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4505.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Aug 2023 07:23:57.6844 (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: Hvdk2HmdjnOBwPe47TUS+OHM3GmPGXXCYmsbnYPgzBwqBhqerDP7r7wPB7FziEo4nMk22q038LZz3bop189osQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB9900 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230808_002403_442554_1FE13261 X-CRM114-Status: GOOD ( 16.38 ) 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 In current driver, counter0 will be enabled after ddr_perf_pmu_enable() is called even though none of the 4 counters are used. This will cause counter0 continue to count until ddr_perf_pmu_disabled() is called. If pmu is not disabled all the time, the pmu interrupt will be asserted from time to time due to counter0 will overflow and irq handler will clear it. It's not an expected behavior. This patch will not enable counter0 if none of 4 counters are used. Fixes: 9a66d36cc7ac ("drivers/perf: imx_ddr: Add DDR performance counter support to perf") Signed-off-by: Xu Yang --- Changes in v3: - don't differentiate cycle counter and other counters - modify logic in pmu_enable()/pmu_disable() Changes in v2: - add active events count as suggested from Frank --- drivers/perf/fsl_imx8_ddr_perf.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/perf/fsl_imx8_ddr_perf.c b/drivers/perf/fsl_imx8_ddr_perf.c index f8a94c051f41..32deeace2c93 100644 --- a/drivers/perf/fsl_imx8_ddr_perf.c +++ b/drivers/perf/fsl_imx8_ddr_perf.c @@ -103,6 +103,7 @@ struct ddr_pmu { const struct fsl_ddr_devtype_data *devtype_data; int irq; int id; + int active_count; }; static ssize_t ddr_perf_identifier_show(struct device *dev, @@ -516,6 +517,7 @@ static void ddr_perf_event_start(struct perf_event *event, int flags) ddr_perf_counter_enable(pmu, event->attr.config, counter, true); + pmu->active_count++; hwc->state = 0; } @@ -569,6 +571,7 @@ static void ddr_perf_event_stop(struct perf_event *event, int flags) ddr_perf_counter_enable(pmu, event->attr.config, counter, false); ddr_perf_event_update(event); + pmu->active_count--; hwc->state |= PERF_HES_STOPPED; } @@ -588,8 +591,11 @@ static void ddr_perf_pmu_enable(struct pmu *pmu) { struct ddr_pmu *ddr_pmu = to_ddr_pmu(pmu); - /* enable cycle counter if cycle is not active event list */ - if (ddr_pmu->events[EVENT_CYCLES_COUNTER] == NULL) + /* + * Because counter 1-3 depend on cycle counter, treat cycle + * counter as main switch when any counter of the 4 need to run. + */ + if (ddr_pmu->active_count > 0) ddr_perf_counter_enable(ddr_pmu, EVENT_CYCLES_ID, EVENT_CYCLES_COUNTER, @@ -600,11 +606,13 @@ static void ddr_perf_pmu_disable(struct pmu *pmu) { struct ddr_pmu *ddr_pmu = to_ddr_pmu(pmu); - if (ddr_pmu->events[EVENT_CYCLES_COUNTER] == NULL) - ddr_perf_counter_enable(ddr_pmu, - EVENT_CYCLES_ID, - EVENT_CYCLES_COUNTER, - false); + /* + * Counting should be stopped. Disable cycle counter unconditionally. + */ + ddr_perf_counter_enable(ddr_pmu, + EVENT_CYCLES_ID, + EVENT_CYCLES_COUNTER, + false); } static int ddr_perf_init(struct ddr_pmu *pmu, void __iomem *base,