From patchwork Thu Aug 10 11:00:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13349284 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 1F797C04A94 for ; Thu, 10 Aug 2023 10:57:02 +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=IZAeTqic/Luw/dOFL0WEDUZDFpVGuV/4J/brusgSEhI=; b=S4qxdOWmMwB3gl wH+riVx7kBRfb1qbNGFMS9FqqCBfC2BqmBI+pY1RWLynmAYf0F3BeZOB+S1pwFzSD7KXre9Py8CFh Iy2dFu65MG1RqSW0otThxxGYSFYkjKI+D3KnJFDr6GbOtIuvDR+KuYZawZi525mAKCjNq1NaKo4bs MYRyyqd6C4Rb21E2JpjNpQQaGrvSFTpvbK3FAKV6gg65ZmsrYky/Dc2LOY42CR3wHbOG9ZTTWvVne jRORYMFNX+Il9rrkpmhFFB9qYhv0f4M+QOOxuBCIJcRsu31h2ZPrt9YBIsn9DouEXQ1yyWDDBkf77 K3+ouatVM7KJ8G+kcBiA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qU3LI-007JjM-33; Thu, 10 Aug 2023 10:56:36 +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 1qU3LC-007Jgv-0G for linux-arm-kernel@lists.infradead.org; Thu, 10 Aug 2023 10:56:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fsrxzqQIUNyaPNJO7UD2b5JCmGSEJdj2wCJFBYKrie10mPLk4/v1fOMP6r+6YJBUImZE3WGsGkucpEGXMWmDYJ+0gjQ/QOvd6CjunnMcpMIblKQCBO+7DVHBkqYeeV//ejhKGDQiLlgtReBPXu3wWDrSFBY6AIzYZWk+upQyDPTr/oyW+JxxRx1e9JIHATREbYc/NPlrhKwZJ+VfdpWyXXgz4G7rLMgCxv8ibKxWNEHRcyCBf3kuMK8KnlAKOKJ7kMnRoJH6DgD8OlF6JbHLj+sp3hdRQl5kfDAhEzANU1pTHix9bb6stjV/Qy0z7OgQFfMx5mt/0kqlcSgMa6VGtg== 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=oEH7SZhLoDXH3f0fmMhcuXaUbsDlymo1w+UogqNoZUg=; b=S9TXLAsmpeU+0C1bstpCo4YsHR/tvwRCo0QCqVtaOKLCV8/zpYJXGtXVFXHKnDPAJdrGSOdZlXyz6riB0v17dE72CqrQsAzrz0EDmOlCpGo1vmiwdSLnyEB+Yqg5Y4oBY7YPvBunK7X8FEJbZZQqcsey6YDN2uXgdAJnaArtQPYY5tZAhhPxNfWMfe9W4fmIwmwYQI7f6fDVsIBtzvnGv5Isgurih5eaSKLQwA+mtgh1pj7TpViklmkf2wbK/B4fiDO4/uxf9NDlrBNtv8x2eLhC81cNDnoyrb7Y2u0Lw4EIU3xYxZFPvdHuFwb62EfNluOjq4IQkbgoHkWmGAcxiA== 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=oEH7SZhLoDXH3f0fmMhcuXaUbsDlymo1w+UogqNoZUg=; b=oP4ufR5rnUtAMARuSQ20ZlwUa7mYe9VsfQQ/S4CxmDzWiHR9bqIB8AIburtPPlNIOn5ABLOekwGN3puBRkFqhbbeLlkMHdRvDBOMv3K4eKV6sijivBPTFyyPG70m09n/IZQWP5n/JeebI31AJdaKParLV0D2jJGiphOzX4GFDT8= 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:23 +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:23 +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 2/2] perf/imx_ddr: don't enable counter0 if none of 4 counters Date: Thu, 10 Aug 2023 19:00:28 +0800 Message-Id: <20230810110028.1975176-2-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230810110028.1975176-1-xu.yang_2@nxp.com> References: <20230810110028.1975176-1-xu.yang_2@nxp.com> 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: 4045e6c8-3d02-4f36-ec66-08db99906fd3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pDUnoWTKIZVS44prGPEhAjUq+7mAbHdtefwzS3A3Eq9BAJHoMBHr3ZUo3SPvJg+tp3krpzZfWwoN6xUWRjKyK32hHdc7qikgWAEYgudskTtNXrrjsDuzDGU40c6SInJ0PwDKklbpHyGDq8YFCp/E8I+zEVBJOLtC6+jlmXLkV2h6iXHTzu4WjrtiIendu759Wrb/HqIULCgteKWY4WpgxXUk6ByVaBy/qd6Kqh+m475AY1/ULgSfxYYTnokCUV/Qyu7uSyuEagV1nEJ6a1zSM4CudP19vbE3mMcTW4EscfnmYGBSxcKC9pe5wojNsVVct8Dymx8jxZ4J5LV/tdWLDO8J/nkDMMRSNUzcrB74ebGSac6FvNBTrFvB+DSCjOPMaSB9E8nTsYWzvWGunvjXWAMEN6HYw6mJ8OyFrS9a/w/fwhGP4w4M/cjL0jmjDZsQGyKre4+kVqMLOE9FWi6FVaKIyPqd5zWhFQmdchBv9L53/2TUf4UYESYWKYo8GlZxNhsE1pBOuo6tQa6q1npkQGwdFKy9r67VdD8eGnBv/esGRn7z6QPZhIX0ioN6G6lekAvaB9f/0yq0wmanWd+8gMMSqqZ4EDcYtRhjJrW69wA3fU/g6QEVFNuDoUAVKmhZ 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: 1VwkxfGdQnDKpbHVEcq5xnnUWUadXp17FXInCBE7vp0WNFNtkwdxPvEwIZ+9xJYt+4tFkvon00Lb64GjaRaZsa3XEalwa+qGeTka8VMrrc7q9+QwO+elt+BilFM363/TlWp2H+1VsdCupWYUA9SruBio2I9H1IfuZUZyo2cB6F/Ot5rd5F5c08qfa5u4oR+AMBA6L1aVP1OibCFt+MliTsqGz5SeSGdORUo0eP+VseCvWs0qsSxzXjkIOI+ZIWB3IEZ+54wpITLe4EAlT6iBwHNr63BuzFDxbDQQBwrVOFe57jJ3PmAzBfLenkVk3vNvgHzh25FzqDEal+dyJ9Vi7ejqBKeCYf3YGkP2nkFP7zRDA02o1iP8dzZDmlMHjwHexsanad9R0kiB8P4lVGmZkqLZQ4JKZ+M20Ea1262lhq3VRu7R3fjnCiDa/LgR78/Hu77hvBdmylwN6i1SI2chi0zceJjCMdp+c2kOblbQ/eiW+uBiURYVyJGwMZE8tOvS+abpSVTu9Qjuehg3mt1Jg4AJS8lP2j58RL9FQRYunmdNifE6RYdYm+GSWvzgBvzttYLayqLGWt0Pr+u5eO+t/IAj+x34fO6qA7cEMECFxunaz3sQ619AIMCKHekb9D1cKOjSOJGSCLkIn+Vi+pPQHwO+WHjOX0MuDbXCl7Mv/tAcpZ5ALYmguplHIAT5Ky75wicnTq+FJ+NKXEq/n62UMBhJkMH9GdW8W9/R1rbxwGfqR29k1juafMCaE9tjBg743Yc/rCrZxmDE6Jinh8k0KSNVe4Uu9IQIPk2pF+mhi1G83tyS88Wyyb8vR6qxg4eD4RejvJoe4hhLvGxIOrQgO08t6kE73OvXJV4BxlRrrAY9odmVdT0jfXzZxp1phRDDrYV3l+IhWPYr0jCwsBX/VOj4aTbFDKvL5w4Cu2/aF84YhJ1mm0THJ/PUUHQRA9BCP6U8Z1O5HeBA2wVGcpcBuPHefpyO9GUZh0zCKmAqqItyePlaoPbvsSsXeTVVqw1cGIaEiwtdWf9B4zp1HIQeGwk4z7AMEZq0PJaT6C7yU05AKZeLlb91PbY7uPNV0rvWF/u+w5tY6uvD++dNa9kdDfpgRLqfJ+UXVADI/F00vRwIM2GDNX7Y2VUqF5l8foEoGJoqMYgQKEvqA9sC7YpF3hH375jyILaUDqHs8T4Sz5dLPs/0u94bQuTU0SPzL5b7lrBK13ir8q9oD35oVqhN1ZqzGWp7QpZPjqQrwTU1CghkBe+V9+Qg+9mwEm70cElcE5i4wOiI7D54IsEZTXNMH35vJxzFuMtmKxOmSY5vuFO2k/y1gc+Ox/r4Pnvo7AdUqEBeu8P/LySKlgfrQE/wemfLpk+pFomGR3u15kCVnOj+VNhvXS4GXF1y6PshczB+ISwussXSr+HIRWSHLNp1K2CLxpODRMP1/6BS+02ZJliffVzhaGbB3JoIIaD+nKC5yPZHzO0c+TXGbwB/zvV4+m9d5Ci4A8vSUhkDCH34kmXpIIAplg/hlstNvWHDdLknLyX/BkVDL3mZ/HgXalPjFOzIRcIC91jZbAfKOaXIu5FzUT2zX2+hagaFuvBZqvcM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4045e6c8-3d02-4f36-ec66-08db99906fd3 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:23.6512 (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: Zn7ZWX/BMBgcMXmT/GHQZe+y7osNsHUMDWB/oUa7v1sVvgHkrfbfT5zX+IE6p3n1HpMD8xrYsRl7NhXMxViMQA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB9108 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230810_035630_118307_AEEA2585 X-CRM114-Status: GOOD ( 15.06 ) 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 Reviewed-by: Frank Li --- Changes in v4: - enable cycle counter when active_counter from 0 -> 1 - disable cycle counter when active_counter from 1 -> 0 - make ddr_perf_pmu_enable/disable() an empty function Changes in v3: - don't differentiate cycle counter and other counters - modify logic in pmu_enable()/pmu_disable() Changes in v2: - add active counter count as suggested from Frank --- drivers/perf/fsl_imx8_ddr_perf.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/drivers/perf/fsl_imx8_ddr_perf.c b/drivers/perf/fsl_imx8_ddr_perf.c index e59e4fc6378d..ed51b1a99f60 100644 --- a/drivers/perf/fsl_imx8_ddr_perf.c +++ b/drivers/perf/fsl_imx8_ddr_perf.c @@ -105,6 +105,7 @@ struct ddr_pmu { const struct fsl_ddr_devtype_data *devtype_data; int irq; int id; + int active_counter; }; static ssize_t ddr_perf_identifier_show(struct device *dev, @@ -518,6 +519,10 @@ static void ddr_perf_event_start(struct perf_event *event, int flags) ddr_perf_counter_enable(pmu, event->attr.config, counter, true); + if (!pmu->active_counter++) + ddr_perf_counter_enable(pmu, EVENT_CYCLES_ID, + EVENT_CYCLES_COUNTER, true); + hwc->state = 0; } @@ -571,6 +576,10 @@ 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 (!--pmu->active_counter) + ddr_perf_counter_enable(pmu, EVENT_CYCLES_ID, + EVENT_CYCLES_COUNTER, false); + hwc->state |= PERF_HES_STOPPED; } @@ -588,25 +597,10 @@ static void ddr_perf_event_del(struct perf_event *event, int flags) 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) - ddr_perf_counter_enable(ddr_pmu, - EVENT_CYCLES_ID, - EVENT_CYCLES_COUNTER, - true); } 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); } static int ddr_perf_init(struct ddr_pmu *pmu, void __iomem *base,