From patchwork Thu Jul 13 10:37:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13311780 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 5354FC001DC for ; Thu, 13 Jul 2023 10:35:06 +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=lMt11yNedm0PjZipKTCea8W/bb6pUBekFrvvqcvORbI=; b=SMGD7mylAqzqE9 bBs8lVevZvlKt3cSnhuVrD3gAQrm+hhKeWlfucrVYVD7TBMyDyDuOS/P7uge3SsZzn6T4nfZJVJTy 8SbpMpFU0LzLYS2OQjiPCQnIBltWgR+h5cGePEQvLDKL0gQRMDKw3rjgskeTJpo6aGDzKqGybTX87 qhLyjyx7eOMty5fJqul1KUO7mF7eevylqJJhHC3dR+1EeBYCeY7Qaal6EZmGDQRWKwQSRjYPXMGvB i5LNV6yXHsiDqCnWr42ETygXoEtZVso9eP1i7nSEfFHk6tLU3HSfiyuATZBJr83aZnTDxUMbYDeqr jQjhP+T4akcgzVqSLKvw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qJteY-002rzT-0l; Thu, 13 Jul 2023 10:34:30 +0000 Received: from mail-db3eur04on0612.outbound.protection.outlook.com ([2a01:111:f400:fe0c::612] helo=EUR04-DB3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qJteV-002rvb-13 for linux-arm-kernel@lists.infradead.org; Thu, 13 Jul 2023 10:34:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S2WG9RS4JGwZXXv4XnWp+szbTuj5VqeyAcKqY/1cjR3Q6qNvicUdsdosdUKBTetjNMfpIEKIHc8Uvs2jTxRAh8uSnQwDqqre+3rWJEDR5lnZYrwSILpZkRHmcPdmb6j4/dps9rYDqHDLYsbEFSKwCF/VqXxNbaakmF/BKfa30W39eB2dX9yU4ayC0Plrj0r7Tb05Kh8aG05H6n5GLm3nHITv7r9Fb1Vubhu0aB6RVqLXv2Yg43v3J6vUQbKCUDIr4BfGeViYPpZjEZrNy7hqlke/NHgrS0Nf9xQKOpnr1v9pDyKEiX/GK397+GP+LPzZVi0awh8v19FXID+KCHICNw== 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=4938jlDxil8WRWnpxNgepeIYa7Q2q/rq7i047J6JdGA=; b=mBUWuhwQkizI7aSubhFydCSnEt9Ow03iPe17VsBXrwbW0RoQqjjFkPaIXDFhrxcBahfK8o1C/NXcvcyJaXQsijC4KKAOMVo5AOXRrF+chBlXyupIyfv7PEiOs+HKylFN5nwl/xfke0A+Mek7FpaOIt78jXmou/MvrFS7dfo3zU10r8yzsa8wnY4Fb6zZXMo6qnnP2aHbE+Nkmmt/YvZMBK7YR7xbtbe02IUcRqtiEqNXhyQKu0DTqAG1kLj3EadzENSPNnvgx7NryrwKCUlZlwkxaZvEvD7H9FXjs3ZYb6UBeUQuREwGESMPrtluH2XIA7fLlO6076W2+wpJtU+mtw== 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=4938jlDxil8WRWnpxNgepeIYa7Q2q/rq7i047J6JdGA=; b=mZ9t6A8pbO0/K3pUkHTAE2iksxIyld59M/x0kAitauvdK4X1YNdKrYrgBwCnYYCp4xBTJ2uBJSJdcEOzCSHFAvdR4XyiXW9aqflunkaLed0dOH7254vzGdlL8omYYmnedLVE/g/RdpDyH6WfgXwtSoFcncZZJYbJvXc6jjzlKt8= 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 PA4PR04MB7968.eurprd04.prod.outlook.com (2603:10a6:102:c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.22; Thu, 13 Jul 2023 10:34:19 +0000 Received: from DB7PR04MB4505.eurprd04.prod.outlook.com ([fe80::f9b0:8c34:e57:92a4]) by DB7PR04MB4505.eurprd04.prod.outlook.com ([fe80::f9b0:8c34:e57:92a4%7]) with mapi id 15.20.6588.017; Thu, 13 Jul 2023 10:34:19 +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 v2 1/3] perf/imx_ddr: speed up overflow frequency of cycle counter Date: Thu, 13 Jul 2023 18:37:56 +0800 Message-Id: <20230713103758.2627269-1-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SI2PR02CA0015.apcprd02.prod.outlook.com (2603:1096:4:194::16) To DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4505:EE_|PA4PR04MB7968:EE_ X-MS-Office365-Filtering-Correlation-Id: c99a5291-19ad-4780-08fa-08db838cb70e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IgoCZommsmYF9e+mGcUZw/8ZGp4Re5N1FK9TEN0s7UBqJVOfjRjm3SZhoMXYydOVVbp5QG+kuT5JU5aKiiyC5/rz3iNVns+2cWuWYZx0Y4qskayok6qtMsNW3waco5VfrkG0BehsJJ3mm1VYCSDN3afbUKDjUcWsX61bHeaB2Q/c9WEKp/diqfarTw1otcMJcsZDnxfbyqya2lnkATmXQ3naokrA+yh4oDTxhLfAm65/9/IOP1461kCZFJFEXLgHyNlpWpmH3J/2Zj2WUqGg8AJjAgeTBvyGO3GbJtxyO0olgidLts0yJmf9bnCFBgMzh2kz3ptzu5rD2CVpMkJetE+PGKk6RpOrQqHxMd5T7b1zH4jXnqsYONOedBD5ci8UD6Nz/g2t+EYFL+5YA1a0SSfNBVp8oS7HYNpr5E1p8oSzAmn5jRpHuocrKUrfI2zx45MBNwh0AJsnodg2dM81m1rcZiRPt/vraFM1+7vsglPAlVAYA0NVdWbA27fWkUF/GAYur/lfpYIrV+TV9jaOC4eCWd+e8qYToq4KHKgrcKvX8RY+q+0MDSqvXJDzWOcBIY0AnWVPw1JKpfbIYRVG9Aaz6q/Msujlr7nVuUHEAelvJ+9bXtfc1bRB1gSCs9uf 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)(4636009)(396003)(366004)(346002)(136003)(39860400002)(376002)(451199021)(6512007)(4326008)(1076003)(26005)(6506007)(36756003)(37006003)(38350700002)(38100700002)(8676002)(5660300002)(8936002)(86362001)(41300700001)(316002)(66476007)(2906002)(34206002)(66556008)(6636002)(66946007)(6486002)(52116002)(6666004)(478600001)(83380400001)(2616005)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HgIldveYSvpWPktEXl+SLe9uCT7cjNyOjknA4umzt+gvWyZ94wf4/Rso/GVpVv/17u4ifqX9JjgAjop9/UO+BHjPAFK3YppjM83UFLtSrQ9Tsu2eiHoEH8fiCVeMTw/YtymgH1l7gG6U8BBUpWbqBenaNdRxWxs4qiZgdLtlvkIr2kRGcomrJIjVxFGRfotDpNfZVUua3M2pvXUYPjkLDEXQCrpUt/S9yEiAjNapOL4hkuuLvIa0LArDD2UC6yLvwAyLq8NOjBoMuXEE2OeK0KjT5empffWWyAhciSy7CnO/DXjcEXvBD6sBYe+8tFDwp17+AIqphpXKWmlvHJ4CjPm+j/nG43Nn/JhmZT4CBlg8ysG8ETDy6QdZLZ7PNV+r5exLtIyIABjR1A8ZO42KdJL4qAd+BB+9JBjt2KyaJ/4qulpbPeOf693frflnU1miPBSm9Ue/Idif3cR2QeyBEZuGqSmxdYfI1QhA6ShseQxIOuWBmFRH6nOgR3e0cUPalMiNagG+99f0chJK1r+3RQP24irnTdtkPtoUouA4WbFb54pHwkOQtNS2jo7QZsm/miVHC1SQJ6OKZJaL0Y5+tDDIneleLaZELVcG+nEEpfgszJ/U6IM6UxkizPONJxfE5vYPNZcJyRI7ia0DUAkHy/d6wrg2YqjXObj+XZu742+GdH8RI+G9ZdG0ZIJGcXHBYm5CF+GxSR+EOY4P34O/S9DT7ExYR95z6xvdJRD8IZUCN6Z6/1NfX9WWS7rUsR7fkHUqJcN6qUblbAZWmaKtMSc2nhy3t8YxSuvUxAn0pxjoc2fYlTbud9TYMnQBbU+eZJb37KvxhjkGzk0HKmYURy//tCHtBKPnOnhrgh2Kkath/kH/wRgR6fWivnnngnMHnoomhakJI2METBcA6FF15jZKQcbyXYL5h66PpFH0iMKczX6qNRzvkQwDoXU8g4oAwyx0cGbHgqUAnodEavKkjZXT5ZBsvuzVigL3BnCzTAIi+zfwbcUiuoT8uEkFSmEU428XghkMZMapfUvzlUCPp1lDsnbdrLHVd7GhJylrnYhgiUW/xtorjvTvOn3EImKOuah6DZ3cAkLIq3mkpbYlwO14eQWz4E5YzDDa6xoYB28sBuIP1cvs8pK0Lo8AkJfHm/ZRT9kIyfcqvKJTum14+5LcRlOuc/ZY0yBzVX6nuve164UNPhoipjxwaYS6GHRpLrtgGdgzWs9jJ6zyggP4dWta5xVawTcQ/2w9EdWZozTfHmhyJ3IVEEdUTr0DW3BeKhwvt0GLWVaxH/Sk84rgvzEdN9gLX7P0y5XRTmWfhta3SxMY7mcLEjnLeHPqZSpV3YJml1gaGkzhXV0j0hKvDDCneH9ddZ7rCVLlU6NHpT0tDPe+IFR/r7IdaTnIu96zO4lrzX7FJQDmOWQwKPIfQkbw4NWPch8saxFFK9GP2w0YSM2Y+3myyMOcnXPPPsX2Ud06iJ5Yzi4X9Xx0FIasVH3lMMBxRzfP2B3i3j2SUVuukNICGDLJe3Dchlyt29h2jqUDhggg+AJNgNcG5I1GpfA8VFUMlAiJCJvkknZOaUztTylw3Oaco9C/L9JNG0UQ X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c99a5291-19ad-4780-08fa-08db838cb70e X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4505.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2023 10:34:19.4435 (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: aIgP+pGenprThIErvHkw+rahZsLjQ+CJ65aUcRBQgVaOqZYC6OX3le4lBRsUoAUyo5rykzhV4B5O1/5sr5o6IQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7968 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230713_033427_390651_3BC27B93 X-CRM114-Status: GOOD ( 11.61 ) 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. Signed-off-by: Xu Yang --- Changes in v2: - improve if condition --- drivers/perf/fsl_imx8_ddr_perf.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/perf/fsl_imx8_ddr_perf.c b/drivers/perf/fsl_imx8_ddr_perf.c index 5222ba1e79d0..039069756bbc 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) @@ -427,6 +429,19 @@ 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); + + /* + * Workaround for i.MX8MP: + * Common counters and byte counters share the same COUNTER_CNTL, + * and byte counters could overflow before cycle counter. Need set + * counter parameter(CP) of cycle counter to give it initial value + * which can speed up cycle counter overflow frequency. + */ + 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 */ From patchwork Thu Jul 13 10:37:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13311781 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 402A8C001DC for ; Thu, 13 Jul 2023 10:35:11 +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=KtRUofrVb2pwrM7KipU7p85ki+oTZJxK9Im5tw3LYHo=; b=0M/wv/0UL0JRzn XQYc472hHVS0APRgV9C7Cdo436tcHX9lS4yCVNV2GSkGpNice07BfZbPmHsMKiCl1DTPhdWZPvgz1 RhSd8GZeSauMP7mOe8ztOWTIloRqrlFA5XELT51SPHVLPJI83rPWPgM71k680qbzarwy3/B1jW+fS p4H93wUmvPp7Mwyt6c0Qib06iwaua+IkKySanMc0pzqggMN2tEHRU+NhQlPXTuxsDwrVgC6XRPmj9 0+esEnYWnHEto6oZQ4aSvfEv8Z3YOaD0X/U7/6HUR/qe0g7UeEWO1K1/o12zTsIL4xvzdxRJ/4fS1 XJhhUi1mptUD3eadkmkg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qJtec-002s2p-1w; Thu, 13 Jul 2023 10:34:34 +0000 Received: from mail-db3eur04on0612.outbound.protection.outlook.com ([2a01:111:f400:fe0c::612] helo=EUR04-DB3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qJteW-002rvb-3A for linux-arm-kernel@lists.infradead.org; Thu, 13 Jul 2023 10:34:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VL8/Lv3xi9UpBxZuym0474RMZ2RHxsXi0haJf+J7+Oc3U2vHYVMG02BLKJSq6fpBwa12Js5Bc047dZ2jj0nYkn7XWfJHVW0enWszz0O1dPt0oUQ8P7lQtMjm3ZRvg/vEwGKVKDUo1dN7Z3jCT+5NJoscRacimqJWLH2sinVW94aCumAfT4QpexkDTttfpdUQKWB2pOEQfw3TG7fEBoNhFgul9Nn+DNvDyQAQbCrMnoqffYR5fBBycCG7mYqhx4IFbglCQ5ycB/DOpT42cEdUjdIaTJMTl4+/70dmCeeD+X5KQdFRCwvD/zVowNNGwZele/FCdCS6wCZCKGQlNDaxfg== 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=wHsFY6w9asKt3CyY9wYxL1KFv9ZonF0gt1dASt+Bqic=; b=HshMndk4+zsXnDCnwird6sWIAt8uE/Fmc+zGV/J72VwhPXuuHniwrLFnZr0DL/ExCjJ1ObAKA7BOTu/BdTG+9M9yrcmUAO3geredul9gyQTa8VqyUOfk/f0fhSIPTAi/AVEsuBC8AdEyVj2FBIxUJdbO+qLcKjeMiCtwSSnO9/dkojtyiEzZqq3M7wEKLYnSDXSE7BXBmG3vjrj6B1CysN5e3zDJSTXhRY3c+nQGBbJRvPOuBSjjDD4mYB3CLS9tm4jUeQZXxLJ4yzV6/LsIfBLnQS5dwj/cmiSlboqiN17SFWNOcUO15CUvmhMUy5KU94r30cCUCK7vNkqaJIaFkA== 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=wHsFY6w9asKt3CyY9wYxL1KFv9ZonF0gt1dASt+Bqic=; b=lI6xxOAbvrBwTD42TFOCm8vAcH7YOeuCddOjcPGda4xQlIHRSlaF+aQj193CeQ93SZHielnpKrWedGYTN6+KR/IgPMUPzbFH8cTYV8ViIS5Z7pspAcAtdSouViVKJt0X5/54YA27BaNjE+wg2fLXjbph7iOW13dTOxmowqF5mXk= 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 PA4PR04MB7968.eurprd04.prod.outlook.com (2603:10a6:102:c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.22; Thu, 13 Jul 2023 10:34:22 +0000 Received: from DB7PR04MB4505.eurprd04.prod.outlook.com ([fe80::f9b0:8c34:e57:92a4]) by DB7PR04MB4505.eurprd04.prod.outlook.com ([fe80::f9b0:8c34:e57:92a4%7]) with mapi id 15.20.6588.017; Thu, 13 Jul 2023 10:34:22 +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 v2 2/3] perf/imx_ddr: adjust counter result after read cycle counter Date: Thu, 13 Jul 2023 18:37:57 +0800 Message-Id: <20230713103758.2627269-2-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230713103758.2627269-1-xu.yang_2@nxp.com> References: <20230713103758.2627269-1-xu.yang_2@nxp.com> X-ClientProxiedBy: SI2PR02CA0015.apcprd02.prod.outlook.com (2603:1096:4:194::16) To DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4505:EE_|PA4PR04MB7968:EE_ X-MS-Office365-Filtering-Correlation-Id: 03aea57b-3c1a-4eb7-9d23-08db838cb8d0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JMy6soijdd9pvQL+QOy1piuS9syEFsuSjjDMr9MVA7x3DfAkh1YuVq0hgaOhST1PNND/zVXk0UnKblU/z4RfFQgeZ+EmQYk1JdfYHegEhijJGLeUU8Lc6decwyvoNkXRrzjGNGZIUHnkKMrAcHTnDphqHGd/6OpcqRk2se7jrQHTZPqafy0D/JAtkKIlIdsRUFnDHtiN+AfOUunmComXJp/xrVG40de2Gp3alDojRE4mA7Ovl8oKPJZtkrJF69ATeBgnA7tlb6dFktAVaUdFtbc2FnhBk3FWQ0lC3Uapr5pJ/1rnG04DoAqaLNnRkfujQG7aHnAWRrUcg9w7gCizuPlmMEH/STm1rUBHS3mpVMKRWlfzwVy2bNZI6MvPHXX3qBB4JVXWvJvaAPXJLMTvCGdt9ACMvfVqFZz4JdpLop+io+95W2i6pDwjLIfXnlUGile4dubpeziQd0PX/ymXQsiOeqX3az8On23NUUR8nm1L1VKlmyWZMLOBQrJ569y1/ik+s9Fvj3QyDZvBswWVKJ0guIKetTLNCXB9Kcc8RyH2IpAhig3gGSeiWCnNBm6TrULT6ttskD4ujQ1cPsmBx+1MiWcbJPCwTJfd192lrkRgcBO5iXmydnxi8ey5Tn0J 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)(4636009)(396003)(366004)(346002)(136003)(39860400002)(376002)(451199021)(6512007)(4326008)(1076003)(26005)(6506007)(36756003)(37006003)(38350700002)(38100700002)(8676002)(5660300002)(8936002)(86362001)(4744005)(41300700001)(316002)(66476007)(2906002)(34206002)(66556008)(6636002)(66946007)(6486002)(52116002)(6666004)(478600001)(83380400001)(2616005)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AFTNEIemPCBAytBrahTbjcq/UQ38Y9ZETozYCtNPXtUgc6fD7eiyCaDSBhQqkIhIH+9uVYGJFha12nwc3tf+ieB/RrfQaqubSmZF8KTRF4nDFpiAgbj7Asy3RRqs078xik3YPZ0yd31DbrAtRSeAQMy4JDlQlG8BZYO+aKUZBe9CLtZPam8Mvx4BzLKLnfWMLgKRf4507N+EBCIcXi6jJwiyIWYnaer7yrvBRShmgNuwnLtCC5PYBUxtd/08c3zsTh2wGqaE6ozl0f+E3osHsOBcEJ/Jc/qGKPk/r+anP6j17YjQpjiAw616XvzYySVf5kXn/sXUtPULeFNk1WLj/Vr8+r5m3J8bZU/h9m5Di7ccrOzZ1CA3in4jTp7UjSLOUf6spzSbbEZZfpy++eaIO1+A/Ul9c2205BW+aOxBZ9RWTcQsIIqi21hM9eQn3zDFAqD9k+D/Jsex7UsUlIYmyQDXXPfDt4ox+J5UeOVDaz769HVf3/QsBaxW7CyfW8Vy0frdk3niH2q3rc7VnpRQpAZxl28+iff37EtxgkTyB0Ut6nT38DQYcFTwHc0cWtS2+5B+E6fqKL1uglUIjcXCUt3eZfalxmGw89Tf340CdOEjCiaIDP3ZJjUZGdMWq0e9iy+OtZuZxtZKxpsSzHWbFjIgUEaSem/JTc4C+66/asfGQiH+2BTnmggeise6OedNU+DLhni9AcM/kfidClb7Qd/khap5qxiLSEtbRaYhvlP+damUfvVKtliC6PHFDDgFtEW0ZkwG0ulrQkH98yR3LkURV5DkWh8SRYK1kqK/9N6Q+Tku8SNosdZCzLggMpJOjul3jV/Tb9MrlM/pLKQ4YcDFeWYViXDHhkhbN34Z8k25jJu5st90BeFaaIr1yPHcICcd8rm7wIRnmi1Ayw0gkBo5GhXUxgmZXFVhafMp4oqMyD3t18EDCKj6WjPfrCcM+CkEO2jSdBVreJW9OV+vMvSTLqXgG4I7FGQ/E/hR80n2WoDJ2cEwbEe5w+7Mc5MT/4ryxnbAF+e85j1ge0Zr3cQL9lvGf1m1fQebwwepDgb4jtnLlFtZhPU9zeKGbxlAnm6lO2iuPK0utwQZaSMO+kL92spDtY0QmYsjnYtevU1pEU57lRY/FqZKBlofi6mamduLMhCDd4VhDKYlLeWQzs+AkgWiHN/x+sX4J1bzji9FK1kFGdgTTLLL3VuxDjCX58ERO6HjaHBeiUaOLNUUqgCWI1yCxa4XhxTvDnqeG9N7pqyNo6b5zokqT6hnNbHk010gu/qrKOwGOQvTS/0Na3M7t7hFAsOQCOx9kvMZzM4GX8AnE37f4GRzGUZ/d7cwXyG9JEe/ctPWJTi/RE31OGog3oJWfP+iN9LqnNrWZsgzoLmnwI3QIZ5I+gWXkiEijNu8bOjkgRYcGgiQInF9L015eK1zP5lGFWSn9Csk0hlaS4XkmvuLPrTeqeRibPIEmv6tGsOBo6+nHbWAGY8ncUWKYwFo6bNZCvL9d5mFtLS6O8JMaWlU47ZiGtTRy7PmmU5Z1QNkrug2P2LjuPF7d9yYJnQomKr9nrYQRsaciKN19KRli8GXgZjYh3oRNRdK X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 03aea57b-3c1a-4eb7-9d23-08db838cb8d0 X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4505.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2023 10:34:22.5794 (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: Fo1VCSi5PfGHWjZZnJP5FrOXpC1Wwg/wD/gQhbUowfjfzPUuQJC20SIyds3P3WApeMublRpgV9t0KeedhzKODA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7968 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230713_033429_021574_D9358210 X-CRM114-Status: GOOD ( 10.83 ) 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 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 --- Changes in v2: - improve if condition --- drivers/perf/fsl_imx8_ddr_perf.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/perf/fsl_imx8_ddr_perf.c b/drivers/perf/fsl_imx8_ddr_perf.c index 039069756bbc..d65200d4e96e 100644 --- a/drivers/perf/fsl_imx8_ddr_perf.c +++ b/drivers/perf/fsl_imx8_ddr_perf.c @@ -481,6 +481,12 @@ static void ddr_perf_event_update(struct perf_event *event) int ret; new_raw_count = ddr_perf_read_counter(pmu, counter); + /* Workaround for i.MX8MP */ + if (pmu->devtype_data->quirks & DDR_CAP_AXI_ID_FILTER_ENHANCED) { + if (counter == EVENT_CYCLES_COUNTER) + new_raw_count -= 0xF0000000; + } + local64_add(new_raw_count, &event->count); /* From patchwork Thu Jul 13 10:37:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13311779 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 2ED3CEB64DD for ; Thu, 13 Jul 2023 10:35:04 +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=mCflUJJkDOpOaB+p+ve7PuUikkvWMj+s0+VkWTjpsdo=; b=1x+G1LMbvUYyyp KNqlnnEf53UKCQiMTy6nR6daRLXnZw2XXrgpuDXaDO60EgR+FKWcAJdWKAAdPNyAtPW3QxMX6eEvq wiKFknTPIjNx/d+36KSfJdGDHsSvdYCnN1jlRoMZMtQ1gj5hWEuOLxqklbn2Flfz6ZeuQoIerBoQu Ep/u3z+WCF2Tpqk8Scjwbjn8O5YVSNhr9Hkx3ch6RFDkbOS/uTNtendlDIBqZ/RXiknF29IU2SBGl tO0GISiGUn5CczGEL7POJlg3jYXWVdN7Y0LJJHYdUjGS31/pap5Ek4XNUYCDDLRCUT4kG4YPovRq0 WN97y6ydLUG/O9PxYNKA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qJted-002s3T-0a; Thu, 13 Jul 2023 10:34:35 +0000 Received: from mail-db3eur04on0612.outbound.protection.outlook.com ([2a01:111:f400:fe0c::612] helo=EUR04-DB3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qJteY-002rvb-1P for linux-arm-kernel@lists.infradead.org; Thu, 13 Jul 2023 10:34:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=THEcj++XSRGvDKXUnVJGHCqQzLfLtWQzycdKWfXMyouylpxX+/I2epSVESVNjkDYpdbMlh80VcoF0jT5f/TxgFOGYFpmNNGOibH4clsQv2dQAaydyRXveA9bKYs29h3a6n+w8YHPgI1okqgp93uUoAsXzgYGZhVKWe081/kE7vM2MFDMpVPWIr2JytxqtuGX/uPwiqIWVt5eOLhogzdaQuSfEwXHFYNBya8hpnl4a275iaajnxPASzU4zc7bqz0RXUeFynNlq0vksi8h27YwqGgSUHdaxI4RiUv6SbzfCAQJ3BOzdV8Mg5qo4n6iOHuK2WarrrRuVjyQW4tx0/lZFw== 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=1hGTgUGFWB8NO2D7sR2TVDwA+9lioA1rKgZdvAaZHpg=; b=C2oYWTltif+eQBnIcFbnkWWc70jwGj9ua7ZKEMkpetiVqYbRUJ4OAjfTd/mu3euRwOw3xt1gATcjBzFrLlILbMWp+CRNYUIa1VC1xnTbP3H1/M1d9110tzKfTG/0pvbz6AhpX8HzmOiuQkGNPXiD1ijd5cfiDB0JQHLPzohGv/5R8aHlCZMjMJqFq72pOsuGSLOVm7tYlxfaqIknUl3OHHtHRhinSLSJdauUCAC6nv0fUSzF0aYqCM9PnyJmkRNvaRPFf4aAkqMq3CWpHYaMml7oSolFUZ1addbiNYzBUXaC2rMEadNuo7ltgz7tN0lVEmDN/ddNcYCE2WozR7SQHA== 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=1hGTgUGFWB8NO2D7sR2TVDwA+9lioA1rKgZdvAaZHpg=; b=Mlc4Pr2QDp/RNp18q3AkiKmwwlWvH55qzHBwXKSCMHL0pChYlAL0m7ntEgeE/4OnxK+z8tA9l5FkRazB76P2avSWVYS4RilX27MCsFPf07GyFPG3GBfalxGTWnprchogc5BEFtH7rMW08kXhkcS6O3vYFEM9ookr6YqPRNf9L3g= 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 PA4PR04MB7968.eurprd04.prod.outlook.com (2603:10a6:102:c0::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.22; Thu, 13 Jul 2023 10:34:25 +0000 Received: from DB7PR04MB4505.eurprd04.prod.outlook.com ([fe80::f9b0:8c34:e57:92a4]) by DB7PR04MB4505.eurprd04.prod.outlook.com ([fe80::f9b0:8c34:e57:92a4%7]) with mapi id 15.20.6588.017; Thu, 13 Jul 2023 10:34:25 +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 v2 3/3] perf/imx_ddr: don't enable counter0 if none of 4 counters are used Date: Thu, 13 Jul 2023 18:37:58 +0800 Message-Id: <20230713103758.2627269-3-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230713103758.2627269-1-xu.yang_2@nxp.com> References: <20230713103758.2627269-1-xu.yang_2@nxp.com> X-ClientProxiedBy: SI2PR02CA0015.apcprd02.prod.outlook.com (2603:1096:4:194::16) To DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4505:EE_|PA4PR04MB7968:EE_ X-MS-Office365-Filtering-Correlation-Id: 58c0b9a0-8ed7-4c88-541c-08db838cbad8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gyD/1uUfCN8CyIngQwXBgiokgZiNxG1yXjZ9mcRFT4Wda5RQzAXTR0+iccHBFV+JrS1lRqmJp6m0IRRyFk31ZUg2u1Ue20kfxhBSzBu3aWjK4oVZN0kM+T+eZ9+485WYP+OBgEi9dIUftggrbgmd31F9lvh+ko8hzVKeGQ2UW1Ww0wgg9Rd1Lfi1VvrzMAQd6NR2uDMJDnQS6gffl37/5kNOCUfeQItsGGaclAIguVCItoomGtYhyfsmQ4TbCoFh4GFiwcJmHrN//Hlu8dMK3CYEWlzDF9y2v0Sw5+gnmVG4yq0KwT4PG/RHYvHctWSKs5ChZ47f2XILEO3l4/DlKBXkXV1uV5+1B4gf66SfSSeBN90Jcy2otrZ7+JuoWrMWzjuRewfBF/NjcFqja+V241biRPAntHQI2YTgiT0ODWcPc//0p1Y8TqC8y7mSB3EKfKt5BBqOORuwp8mhg6qXg/KnfQINDAr94qhouqhYnYF0C5sIOoFf0OPzmdxhm6uKuEGlIhz2mEjQ5Mi0wuXqCRmcP3RjZkm/Pn2B9MxG/vr7ydsuROKl4HxTPGmpV2/gKuJQcjL1EtJt05szZtMaFTg+pm7AX/6npmDw0Gbsf/Tyqvd5oTKedag8X39O36pr 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)(4636009)(396003)(366004)(346002)(136003)(39860400002)(376002)(451199021)(6512007)(4326008)(1076003)(26005)(6506007)(36756003)(37006003)(38350700002)(38100700002)(8676002)(5660300002)(8936002)(86362001)(41300700001)(316002)(66476007)(2906002)(34206002)(66556008)(6636002)(66946007)(6486002)(52116002)(6666004)(478600001)(83380400001)(2616005)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0YwfmcWVBkxy2WsnAaZohST5j1spWBb3XPqtnAHmTZpOhZsm3SwmEf7YjrSyPXeULkJ6eHBZssDOsPFm+43qp+Klx1aTuWA1/yL3i5rwBKYqtSvSkBJrsbZylz4vqFHnjzWs80pIqd4TtpNGrBr3ZwWHKNoXSsE+7CUdIG6it/VOa+NK7E84UxBExslHRew8j6veHaKlVkdkt/WQHsS+lbUtVs6tdVksI6/Pu6O8h1ULUuvjMduUtLWW+2K/ZQXBOTzT2eb/2aNcN6jjCoB7YN55QCC64NgcMhs3+oAQkf7kt0PJYacUZEdl9kATP2kUMroqK2fPmCRt/tWiL5sJNWT79hzTkjc59I8YoMAqhpWlsMKUrJp757I/469IW2BuPJqBWxudIQYuF3rfiUdckzwXY4ysyiVaHvkdGOirMzx6XyN9/uF45umG/MYL384i6vXlK/15HLWv4NfDfOHfERiHPblNN4aau4ml2JRely0MYD83qb3h3zxIMtjv4KlTKD4VBM8pS7TGrqHtHu4pHWK5O27mudV4DuX0zW4KXtjHG4VTyCV8p7R/I5qOp7RvHSYGitT0rPBn9BM0ro4rKLKL+WDo6O6uVR7mWl1ZuKCzTiq7tdegh5xDWAG0H9KgcN6fEvzfCQK1K84uiiaJyx9Q1K+exdvpDBspB1qt3PkEeMMU9fztsjRIL1LeUYL681aRS0qJYwNMuoim9dfOsQ2gSZgo5v6ry/adXKQSN9fYZCIrtEyWEegZ3z5BGf71G3ipOy5RWbAl1kQuh9wuYTptdraiVhK2tvOioqP7y7vQiU7ld9PjBaiic/NKcxQQW+SLLGAOMYmwRhxnsnxQ7S0I0MAlU9uZr/N0W2xwmbCI+VMHH8Qgh32c8XhWQZak/Z4rlrl0qAXZvV+5UKoC0WcNUssTp28g8CQ88LUDIoKBdtVSGhjUqQEKtB9+X6rpFn6oL0FRDy5qAWqyxZxDtsh2HeXGHsS1qN7yXeGggRClYOSBIFhUlfq7ZN2aWJHMQF1nu3XeQT8jzxjfLmU17hJTKPR8s0HTR+B1g9aawBOTLofX3r6abvQpurxzkPFHoNDZGJhE1/f255C4MKX509RUMQpG8yL3Iw73Dudpgxy3yFUawd+W3gOxJIrLnsQsmuB4zxKHY1lLfiSbD5LO2G7jtZccX7oDrq4r+kFRLcaFcVU2OXQTNogWwNkA/hY+GNNKC3k22RD0mHWS/wy4+r87QAdnBdUtQtCFPTHig5oqsqXuw2L7LAi7MOYOq6G4CqKX1e6xyxh+uZgVg4GkfecEv4dU/fubwg2HMBv3rmxBnqyLnq18SLpreImLvc3bW4ZlE7BRbaNSH5zwaN5+yZ0TyiZhWkZaQhjsAd199+38K6b+0ZWJFMTEwIGX2IbmSZeTNr2N88sVY7khL/4xViALyZrDvlVGVLI2P6Tkq9Z9tmU9j5ZR+Dh0OgXsGRbCspc69F5ihYZt8Ehw1ClIou5HU5gTaQdENoJXwWScx9y/4Z/OzIZUTYDPk3PtD+k334IsYmaC+exStMJWg8SIOMrjvsSMw4C3yDz6D6rBm5IQDI9Pq+gmQjL8wEw/zDgS X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 58c0b9a0-8ed7-4c88-541c-08db838cbad8 X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4505.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2023 10:34:25.8360 (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: rJaYVObtM7sunuBjUp874JeNCQqzudnIE2gO9JmQESPrXIAVyPRqpiWA36/8it0LsXsypdHeHJfavhLtO9Mo1A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7968 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230713_033430_497884_64E6360B X-CRM114-Status: GOOD ( 15.52 ) 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 Acked-by: Mark Rutland --- Changes in v2: - add active events count as suggested from Frank --- drivers/perf/fsl_imx8_ddr_perf.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/perf/fsl_imx8_ddr_perf.c b/drivers/perf/fsl_imx8_ddr_perf.c index d65200d4e96e..761e45f21092 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,9 @@ static void ddr_perf_event_start(struct perf_event *event, int flags) ddr_perf_counter_enable(pmu, event->attr.config, counter, true); + if (counter != EVENT_CYCLES_COUNTER) + pmu->active_count++; + hwc->state = 0; } @@ -569,6 +573,9 @@ 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); + if (counter != EVENT_CYCLES_COUNTER) + pmu->active_count--; + hwc->state |= PERF_HES_STOPPED; } @@ -589,7 +596,8 @@ 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) + if ((ddr_pmu->events[EVENT_CYCLES_COUNTER] == NULL) + && ddr_pmu->active_count > 0) ddr_perf_counter_enable(ddr_pmu, EVENT_CYCLES_ID, EVENT_CYCLES_COUNTER, @@ -600,7 +608,8 @@ 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) + if ((ddr_pmu->events[EVENT_CYCLES_COUNTER] == NULL) + && ddr_pmu->active_count > 0) ddr_perf_counter_enable(ddr_pmu, EVENT_CYCLES_ID, EVENT_CYCLES_COUNTER,