From patchwork Fri Aug 11 01:54:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13350004 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 24636C001DE for ; Fri, 11 Aug 2023 01:51:07 +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=ySAjx9IaLN7GP7k3vvGapDMHxUgkWKRprQO46vCK6+0=; b=Xrfbcka2v63Xwu RNseQqZLUEkOkZbGar+a8BIvzHQmYBQ7UPW+//cmLWO/Hs/eQqRresbeSLXAtqr2e1uxZeDpDFoF2 3bzXxmHKSja6nl+FtbdBTJ7b8kjM065yQ+fk+G538N82aKpIjeIWbompqSyXj9trRsM2o3OpX8Nt0 VZ+qMFElJIW/zjF87wyvCzvx4iUuZxFBqxbSPebZNUb9N0J/fyZHr5TEKeePhAyzgZ9Re+UtQEUBn 7Bxuxuu5tY4BEN5my+7iql2SE79jhvkBfpNwx+xdDNbSa5Q+tIuFKwN5rmu6+LHh03YQ0wuU39/fq r7wlZWeOXiYY2lYiO8Bg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qUHIW-0096rG-38; Fri, 11 Aug 2023 01:50:41 +0000 Received: from mail-he1eur04on062a.outbound.protection.outlook.com ([2a01:111:f400:fe0d::62a] helo=EUR04-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qUHIS-0096pu-1p for linux-arm-kernel@lists.infradead.org; Fri, 11 Aug 2023 01:50:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZqVgqc6/oR3rgCkBahha4qZJMIaiOcur3cSPwihzNKi5r//fFT/yFOewIbbfPqjf5Q8asRwMDJ0ToIvBy3j89aZDGwcWNqvtKdWNS3U3v4NQkzcB5kzf9BzJqS9X2gM9SSzXsLdANxthUnqeZ7lH8JbYQdA2ceKXY+Yn9VZjFXyM2c/T4gqsgmPswI8tsY1hQYnaLfpqGCHQwMWwKKHs4kOErI8och8PGvGvY3CVtq217+sryxX3Ut3xeCQVw9pp7RLOQ72rGhfhhF1WOxSBzorgTt5xsj5LriPK/3XsrlHTQwTFucJEj/y+wuzuA0+N1C0Mc6IGcp3apKVujMhajw== 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=dsfH9gntuFLQvjw0w6ScpbTRXZ7t/x7eCOGd2qrpPtA=; b=Mle9IQAQr7TyeuiltDx3LrE7Mxs4uDIlAZL2G3KJ535elrnEi5obyM5ty3WgHN539Uzv/Z1oBUS1lw6uxLuKwj8GvOCwyA46Umii42KQ57vW8KKxbrOS7cFz3kJdRkeVu/d21qXu0SmAawvOqfSmvNDn/jx94gQSfaqLwBnpvJgZSS3swtlKirbBEZ5L7CEsznn671VJt22/e0tt2kDVAnpVarwFB6di4fbgFLXMQOpjYC7xlTjkyARuWNTN63k8SKw0kTcxVfG6jpyoOk1ikD3cxc+fyP/yLtc/WvVBdxFyOL7TXpUTJeIUo6M4e9AVth5JWnCzWRecu/KZXYDIbA== 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=dsfH9gntuFLQvjw0w6ScpbTRXZ7t/x7eCOGd2qrpPtA=; b=bNH4pUilYl2sYc+M5D4T2IcNT0UqZmb0f74NH8VGrVzp7XFicxEeMYOJqaKjqjKpS9ZMl9bG3Ki2KVRWutm9R9MhTN04FaMMMV4JDLZtQbzEZfdONselUFVydJAJe1AM7gU4CYnLYmYlncwyJpm12TWPYlFkHi1P3oLMkqty9Lc= 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 AM9PR04MB8746.eurprd04.prod.outlook.com (2603:10a6:20b:43f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.19; Fri, 11 Aug 2023 01:50:33 +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.029; Fri, 11 Aug 2023 01:50:32 +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 v5 1/2] perf/imx_ddr: speed up overflow frequency of cycle Date: Fri, 11 Aug 2023 09:54:37 +0800 Message-Id: <20230811015438.1999307-1-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SG2PR02CA0091.apcprd02.prod.outlook.com (2603:1096:4:90::31) To DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4505:EE_|AM9PR04MB8746:EE_ X-MS-Office365-Filtering-Correlation-Id: f1dc1183-893b-4a0b-bec6-08db9a0d5919 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bumOG4hGRURyHihheGFF7ZodZsj4ptggK/ga00SQyQ0/znsYERDUml+xsEegTN4/+E1vhaSO56MbrEfYGcl3LzgOVnzYPXca3lOAMFqJagTRkE3n9BWJpsbWthLgvrGtvVUTCQGHLbQXoAxcfNciMoNyQYdM/Ufip+obn/h9fMI1boRAPRmoxI7zpFjOtRCN+m7v5wxnsz+qScfTFNcdjsg6m7TZx3PXeUF5k0VjHF2szFjItd07VyKfeqZ1elQzx8dLsSDLD0+6iPYqFqgvzv/BPCdU6JXkhFvKOm7Ec5gwZ69DydZT2S+FfqszTK/jchZIg9O+6PnsHSmcqPlKP2H21L/QoCEmjjDyvzzuUTN8We36U7bSHc/RNIRtPitiejyMrsl4uGlwZ0LWdhVVIR5BDtDYWTv9OYFRJPVSFYaP40d2XpZ/yRhOmcKuNnuzUssioZOFq6lzC6oLQYIx0bqBt9wTTEZHZ6fq5xaRADy7zozn3rA0IDLE/rJSmEkUpJ/IppbP59BEF9UGz9Y06I1Cu7DGCyKIhug1O2auSF0I9anH+4uFnzwPZl0HulLBN5QVlwlaOeu5Md1dqtuXqLxYs3E7RRMpHmhzerPzYJq7YllVUzqWr5l1GUuSMB9T 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)(376002)(396003)(346002)(136003)(39860400002)(366004)(451199021)(1800799006)(186006)(6512007)(6506007)(1076003)(26005)(36756003)(38350700002)(37006003)(38100700002)(5660300002)(86362001)(6636002)(2906002)(4326008)(66946007)(66556008)(66476007)(34206002)(8936002)(8676002)(316002)(41300700001)(52116002)(6486002)(478600001)(2616005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VKbnnGolU6ijM6jWTYlVM5hTuPNLp5iEyFc57PP14/lyzILwaBAfypM+A6803jAgN3BmaxPuVfO3+jFuRTOvEK9qZI2f/QHooND6rgHKdkqIrivPZMdmwdS1iyespAGQrqKt99Xx08BcW67i37x9tTKSn3uVHZPHUwwBdEF2iGAQ8rfqaZ+tvN/MJMHsKjoN5jkeplfBhubbbcpMFww0cYnw1wptfbu8OYx1giaoKnmQTEqsq4t7/gnWW5kvXmxPZPWzcshyT3VCl/fcIhVSQp9MOMkQduRidle793iWcv2neexmkEH3qf/Y6BjTQAhcVPB7pc2PiskJJkqjZ46/QrJFG1R7lE8DdUC8lzAOsm+WH2nzbOrdx5qFujk+Y7qKLnBANqhJ/cejYAn4szlA4a/WnSRGGTWaVYw4O7NW10zrqUtFy7dr6Ks9tlQgVRIi0Ei/mkTOvy9fELvzyV1HVGoX+0BT9YL3FgH4AUgj1ZpuqVBJ9cGFKBDSrCnugSohaBdlX47MLGYoN3kqcvPTb0GHNW5Kr4IOcm1OcS7dX3yAQTdwLDq2/VaDl+sQTHvFxtGeQXCbI5IV4IS4AfGPtvWySM8NuXMs3WmXsEg+dfLNaAVCtO0fqNVoNklx3ozAL8TWQ4WVvcNmc+C59lXs41MH4gNtfqbCECZ3M4wS2FW0OJFPTPxyIoNfbvaWRLleWjjmPKtBVAqGArIbxg1RHEHj92kqa+58f3XcEyddc3GxIyJMAtt7RQpgd8UzwkExFd/Aflmr56Lp4uI4sv/19X6DhQTlvX/vOQOzlC9tI6b0VvUEgkr9nPTXegwK/mINB0DkKq+0cfYD9iqbwzrr+bCKOne70JFZbTvEC5k7ygKEt8wgILBO7DAWCn9hTUs86y+Fjj+gQ1LXQ7emAXL1FWHQh9yv/++OxRxrPj7MJWkhO+h4QppcxMTRx1Ebe0ymMOd3qaDazX168Zk6NK+DVrBDl6ea/B3p/BqGxMz0TKJX9Q7qRmDKyYjJlKmMBtaje8UfqntzxJYEdnZdk/LrKhDowUtx7aexneDNKiUoKYHw8g5GjnP/LlYXLBBIzPSZ0cvQfBi6QLRcQw2OUDWU7mq+hkUrT7G/Hm/IAvEOyz+cXhP4xBhikbVEMPV7qxhicbMThH6iM+6JI7F3uJEZOcEtICwjBTujgsH3kBLQQFgDhOETdaYe2ywhMBOZdZM7QU6QVst7BX+hcNmZVWL3V+pHRMrw4lhIz4QPzAllBQ7WZFRzqU42ckIE2pAS8VaPOl1IDOw9qQYrvfDVMhgOrzV8F5sMqGmQNbNZ4Eof7vVA/KnB/rglBoLyMsbQM7DI6v/P9z1KEHjfskl7OAESwRwEXfS/ELEELyzod3pczU+GJoMLMU+wBaQPLK6YsCNW4lFHGlrb1L44gi9fM1FQkkCjI8gxdwmTZ6Yq7b9dQT+88wpCrUqjIbSbKo9iMd26OIQKdE4T6HgWBpWHfq9QMrGc7LHD6kl8cCHpnkXjfep+nTAU7X1TCz1i6XirVt6ye42lqtNwJNC/ny66CuvT7iWksC/Xie42OqWW4zmu08TlrW0USnjuMk9t3lgcGzJT X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f1dc1183-893b-4a0b-bec6-08db9a0d5919 X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4505.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2023 01:50:32.5006 (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: WSG3DoXdhWJ7kEPFHoEWCZUPN3UJddQJy0anZy0ultZA7l/DOzEB4oYuHWv1tcYCB1q6GfJqRtrRANKyCVqLlA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8746 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230810_185036_635032_C9921C96 X-CRM114-Status: GOOD ( 15.65 ) 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 v5: - change comments 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 | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/perf/fsl_imx8_ddr_perf.c b/drivers/perf/fsl_imx8_ddr_perf.c index 5222ba1e79d0..b022755e6ab9 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,12 @@ 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); /* From patchwork Fri Aug 11 01:54:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13350005 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 A24DDC04E69 for ; Fri, 11 Aug 2023 01:51: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=tDnDV4l3m+np0EZonIjlTJEXtuaVDdLQB2V5aBUhaYs=; b=zCDvaCTTxGLVO8 jV7FEqgyYa43OZgkqzlrBRsufbQZqMj3drx6ZSFrdPlOwTFGUlfQTYXecPzibT2PS5HsTiWpG63vH 9ytITjjQCnokgzSCZ3bxpcOh9NLIa+pRk7UCqziezCSrgg8r3osKpBldlg+M1uC60cL3tQ46z1D+E 2ubwKNumSWA8rTVEiHcV5hhG+NuZpo24//LM+dGWPgPjhfQoTUQvMGF8kQ2jgBHmGK4475BMZWIFM kSblYeYHrGADHAkOA870p+FeEtEMBqlnLtMqxsO9g/KXk4VLAQ9BjmEc4N43J+ToFnQIQ2zla3uql ufUexRIPdz6WjcJ2IzLQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qUHIc-0096sK-2l; Fri, 11 Aug 2023 01:50:46 +0000 Received: from mail-he1eur04on062a.outbound.protection.outlook.com ([2a01:111:f400:fe0d::62a] helo=EUR04-HE1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qUHIU-0096pu-3C for linux-arm-kernel@lists.infradead.org; Fri, 11 Aug 2023 01:50:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fJqrnN+B+0aOy5/Bs3Wo+a0oZOpoU0qSWUcCucJZQNyv2t/GistC8zWkSwfeDRU7rlJERbD6ZeOaY4yGbbrTZXSd60SlLVmoL2GShOTuZ30fdQLnRdrYtMTww65RRgxQEZkwwr38UawCXjx9FxhSemGW6mV6OaDRp8ve+kVGYpS6mnzedeXwbp9T66+VxF091O7jYuOfCcxqYV37V/lCEl2Lz5jPDt4IMCxPj+edUvokdutuw4VH9r+lmE7ZbCGD4hCcBJfN2m5M38g8NdFQQbdXJW9Qwv/aOVgwsMwJ9il/d5jENDiHALUjfORZuE99wlxHSMUMnH59u1EOxF0zgA== 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=ncip1oNg28yWHEIk9a4LZOytBMXwuk7eqQMHFjKmA9o=; b=njW3I+00QWVpgQon7vXFdn9cKborV3kEkX5tQMajNj1InuZeK0W6GO1uRZpyp3GdtBs2MR2mMgv3tt1sTD5E+3+5NwVBg72uqL55poeg5JNQ/UJUmXzHheDvIiSOk300gqBcflvv/P+EcXypByOqVApbWy1LfypOBBpN/h+cJHWPGV7qOiHKD6n7eBFeJ57h7rnrP2Z5f7Dzq43hpH3mEEXk3USX444d2vA9cMepSqC5rQ2Bc/XqgvNAHsx5550OJin1vGQcV9lp7HBXyfxQMDQKY0yk/vMmkySaz5z/In8xk1PJ6lQaN2CvJKLCcO5akO6sRDuixdMaot8ehJcOZw== 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=ncip1oNg28yWHEIk9a4LZOytBMXwuk7eqQMHFjKmA9o=; b=m9g8BxE97q0tzrTiU5wYTkhXl0NUAMIdHhtLlKnDFB3o/yJVwVphXOuGY3KxtA9YslCSL2OMCzEsp+UsOl8AKdfyZ3SxQwSoMhSlMh2Gqj+9AcVdW05KqwKBQNePBDi7WuP/0frP1OY4Kx2KrgzMPcFQRnnovfA/m4KTzcMMmEw= 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 AM9PR04MB8746.eurprd04.prod.outlook.com (2603:10a6:20b:43f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.19; Fri, 11 Aug 2023 01:50:36 +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.029; Fri, 11 Aug 2023 01:50:36 +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 v5 2/2] perf/imx_ddr: don't enable counter0 if none of 4 counters Date: Fri, 11 Aug 2023 09:54:38 +0800 Message-Id: <20230811015438.1999307-2-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811015438.1999307-1-xu.yang_2@nxp.com> References: <20230811015438.1999307-1-xu.yang_2@nxp.com> X-ClientProxiedBy: SG2PR02CA0091.apcprd02.prod.outlook.com (2603:1096:4:90::31) To DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4505:EE_|AM9PR04MB8746:EE_ X-MS-Office365-Filtering-Correlation-Id: ae172cc0-30ea-4abd-6154-08db9a0d5b2d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: msLhr+9fCzCaHxYleQp8m9cTn3fyVahoHeXD0Zd/xlfc/h9RhpVNojkDgRgaJ/1IwoKfSMn6J7XGIKJcu0s/hi4UF08no4/gcWeEz1bftuoISxc3tg9//mY3rQIiFGA/sanweOtJPI6b0QEOwTwAUr4TnG26ghAA7C1PrKL3JZzwSYNRykU6mDZCOX9f6TwO/P3FSz9ibvmZlDgLpi7aDiMo6tLGUcSBUFx1nnPuPWlOJCOzdeY2Oxese8nQP/jO0t5zvzJ9fZsMxJo1vwERCyFB2JPslVPQ41KjHi4waNQZsmfdv5yqtTWtWdQv6UqZ7n9Dt3YqLbLdq9LnhF0jWEs86s42MDwHuHPNI4OBJGaIN5yPnOdGjn0hVXngs+WxmOOq2JTka3Ai9MMf7CB2u3vmr631ewxVKEn/IcWlOA4cY3MLEscH0gRUEkndU8S5z+fZRl/tN927kDFv6I1fEPfQF+rTruP2U1pkzYckyOBb/VP7kEr5vOBcZ/9Dlw5UlPfooOI43CHu1S/uY8nJh6bAdkqzezNXEeOtlTWiAz2/x2NXIfctDMtdt4+a2KTlxchkdJ2HrsclTKzCjT4kyXqIUuw4tG9uc1uX9VQeZ2laeyXyel0cIjigor9BYOYR 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)(376002)(396003)(346002)(136003)(39860400002)(366004)(451199021)(1800799006)(186006)(6512007)(6506007)(1076003)(26005)(36756003)(38350700002)(37006003)(38100700002)(5660300002)(86362001)(6636002)(2906002)(4326008)(66946007)(66556008)(66476007)(34206002)(8936002)(8676002)(316002)(41300700001)(52116002)(6486002)(478600001)(2616005)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lCngYY0nWvldiUpEvbl7153TRGWRBIrUnfmxgWFisPuTyWjRpUyB1DP3lQXWyiHQs9SOlntr5+K7DzkQPenR5IuysGwUuPyh5jQbCfdRreKo7HbLP0Mksf3kjoD4Iy9gAJrC/a7N3c/u0XtPO6gtysnkjkrnQYc1ZRelhCM4+WJIr1+SU1F8psHBVmj7Rbfgd1M+qdz+jk27LbycLgOY2C2+bJjNklcgtHeGpcOQ9836D8xaLm+N/9o/ak8MKt4xKY7g7/ps2lAISccHhfZaJhOT0I6px7y6poBbq3GLKK9tSr7nRX4Jud7f2qliZAERlaTJ6Gy2saaePwIIte08KImAmpUBpC7yHDJOIssHcnJMNKeIB+U8LJz8+Q70zGhO3zcyMZkjZG5DsInD21aV2FnPAuU2SCx1fVrcUCjTSvM/t0xen5ZBzBDDwtkMmBUREcC1gPziRfeOo3q6U21+U1P+VRt4u7H3U1hHufB56b0BV15r9dhlb0ZQaDm6L8J6DURQauX3aDTFrHtCSFZVw0V7ZcpPILtgrNIhfPgiq10u7D3el0ygMgc6Hg052wpdpxUlilhwxHeqQLYqK147RBuu93EAqo3BzQ4666WQZZEF/jrbW99MLWy8l3l9zgakd5+aGTDjb66ER9ultTrO6HLly9OaPmCJ/dZQXdCFaxuFwwRddL7DP/K1avtr9hzn6I9DRmRkJyzp5JPzoL2kz/qq3utPSd1owglZ52PsyabC9us4aipjWSMeWm5zmdLSLDMNd/uaAaoYvGChh8MNfG+Z+FuxU/gpMylZ6jZsm0w8jIhfaLgw4sNRbyOz2jvlsGDV9w8q0IcJunmgBHztBLFJb/1p4vDyqaFamnIyozaCIByr5/n7OAx1WVI35T+KkbgajibkruN/kZtDtePTsUmzEC7gQJovMDByitwoSVBom7z5teLw4Z6roAJUG0s9Jvf5M8Ir25iROTrhX/NB30TO4+czPz+mmpkRZHkvha8hxF2Uuw4TtbeqAvNJBGmFfk9vnjel7yYp0sY7eCIFdS/4SGWWCZjvgfFy226MeAsc1fqyYj3Z9OaleI8tTEpVHGEUnzsmDE75GqiUPEkOnPXshk88RLrOhcSZpK6gI5Ne2CPkDXcAWJ0JSKqjZmF9LTj1riVlvl/pNORo2UT+nHNct09r48JgVVRlA3B1lfo8i/aAKCP3Yf7EdfI4TEEvr7rOY8KISQ5ZR5HW1250dMivbBKQzGyVAirgwMpFYX6H3cnaASD4Z+b5Pe9IyYlAKsF1Vx2ybjoXdZPsnf6WNWzl7LjLvPvYUinIA22R9ONGasywTscBsWaa5C55oU0WRp3vq7/dUzJLHZs90jU0EkjhKK5atkhsBFObfszYMbFV2NC7fhdut0Adh3x/KQfJd8sQD8VeZLIi5y/J9EESD0PnwfaT87YhOusPiONeEzwv1AybHem7i/arKuhA3IzCiOb0P9MfKAVx3Gwtt6U440wesIqq2HIxR8aGVTascDXpE+p1s2y65APmgnLQoxfmOvKAuDgotLht7p7IeVdS71gvGvrNUBcy+R/FHAqvhc/anqYMXeahuUn0Z0xD4RMb X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ae172cc0-30ea-4abd-6154-08db9a0d5b2d X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4505.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Aug 2023 01:50:35.9937 (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: G9dzexNGw9o/RDr2TDE0/22H4xfX/lCR2hBbtYk4As2Hw6LMB/7A4KAwygUK4Od4Nri4KxzVsFJ7VS/al2a/Hg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8746 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230810_185039_078620_E4A16FBF X-CRM114-Status: GOOD ( 14.95 ) 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 v5: - no change 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 b022755e6ab9..e78b30521be2 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, @@ -516,6 +517,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; } @@ -569,6 +574,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; } @@ -586,25 +595,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,