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); /*