From patchwork Wed Oct 4 14:05:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Gupta X-Patchwork-Id: 148315 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:254a:b0:403:3b70:6f57 with SMTP id hf10csp158574vqb; Wed, 4 Oct 2023 07:06:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGXoUysiw0FkThPZeF9Vc2ZGN/8UvqPjhQhyY91gnHSWmkcs/NiXhQ3w9JcgAcUY1G5AsuD X-Received: by 2002:a17:90a:4dc7:b0:276:a08e:a871 with SMTP id r7-20020a17090a4dc700b00276a08ea871mr2276032pjl.47.1696428418878; Wed, 04 Oct 2023 07:06:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1696428418; cv=pass; d=google.com; s=arc-20160816; b=v4yfmbVJLZrWr55y0MysW2M6lC6/INKElxVG0GxLCG6rOE6IM7Gr7yKocxMhNpK0vO k4Zy8h3EwIQtJ+8I0QIH5Fd7JcZtVb6TxYiscWjQIQKcDq5GglAtenVp2WsSZmmKJB5z fy4ZMrS7xmiO0rOz3D7buZEqZ64STl7LfafGSJGO8Na9VHyvAhhEtK0T6OKftqosig+k ZPqPq8JD8W5dPi2xps3muobFr7SqM3PHk6Y3gdJDrVY2CbdKc8naCD2ZwhXWY5bNLY7H TnAmcdZhs/oCa1O8i25pJFdXaAZQV9zweQvrIP//9AwZJpjdUqFrIa7XiNItT3me+B+b LmQQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=pky6nMg0VDXVUZ4ilIxjkrdr7ovwOi5yeVaTId+Cx5g=; fh=PTp2mvTrCvo/vo16l0ne4zJtbYthE/in2768K/EMwdE=; b=JHPwxfCSyp2LcnptRq2VVNXEHssMiCGhc5pJp/8ZjCBcn8AKbBLwVq7FwM7pwY+ryd 4PAUiXNTxTTyU62TgHQu7lsBd4GhKThJgYlUuU/jCp7l7kSlwNxxQpxellvz2q+zFLia x/lSDg/RlC3bxrJO8HOcWXfnWWii+3B/J3qKhi4OfMpDCbVkHaCj18ZqN+DVrTTP1gQp QlYv3llFSm3JdDbUfTSUUlYK90aCw10o3qVS68cFqbv+poAccJzbuzJ8Nbbh5XLFwvO5 nQmN4VobNd/oI/FdOiZQUMHDs0R9xWJx/rNgRBOprlNvSPeoSq6ZyeYt2r0HoDBtSaUm qWBw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=It7wWF7V; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id t14-20020a17090a950e00b0027367e0c931si1540844pjo.129.2023.10.04.07.06.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 07:06:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=It7wWF7V; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 00F1C81BFCDA; Wed, 4 Oct 2023 07:06:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242645AbjJDOGV (ORCPT + 18 others); Wed, 4 Oct 2023 10:06:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233306AbjJDOGR (ORCPT ); Wed, 4 Oct 2023 10:06:17 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2056.outbound.protection.outlook.com [40.107.223.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 074BDAB; Wed, 4 Oct 2023 07:06:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Iij+TWygSMOwW76kwAOC0bQGRIQTieFxQdx+Kdc6PsLXBc/UNhK0E6hRvv6n5L3Ta1Mek6VIsL7gq9Mm0uk6q3wav9S17lV4t3EYJD3f5JDdeM0kNHw/wHokA/UcKBuM2fQ5mjDrbI+FCrk1u7xYBfNd39WizwTr+Vfua6OE7TagSCga9VdytkdHwNSJb9Oo+VAv/Vn0EaLe3OMqoZqZAzNOacuT4WZkX0FLcyMW0KHw2OOSa+ZBRrlWaPUmFGzAufRGnrlzA39f9D57HINT/+sYNteBPxireE0NEIhYdJOunQrw6EqVlAe/ojH+RLzU13CgNiBv3KXL35drvRxYgg== 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=pky6nMg0VDXVUZ4ilIxjkrdr7ovwOi5yeVaTId+Cx5g=; b=XxcuyskrBpfKR4qHtFnIZEjria/3GFzF31sWD3lofv3jW8B99CwHE9N2FUkhcRq5dONY9sOi22gOz0tgIRX8Jn0EInb+Vz3720CzFHQNEBHDYJflEuz+At0UHeaHcDPeBIa6HFyKINzS+hqBnn+AxhgqTnFnonhnSHeOZAmyNciDbgjVPTx4YsJoi07El4mT2Ru8J9Dff/oRw6X7YDV7SKni1kl+gSloxqPs+ElQhMJ8qek0a9UhZ3FYK+rFjMrOZOqN1fQtbarIMNsuv7UBiDx/MG2pqb+dgmpplvDOuq+QTOAggNgR9MXZdkdSiVVt94iOlPCmRxWgHjB3i2AK6w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=pky6nMg0VDXVUZ4ilIxjkrdr7ovwOi5yeVaTId+Cx5g=; b=It7wWF7VSLYnwhd+YpD14W+pEMAmUpWOdU2cnzZLUH4Xi4wKh05tNdW2XIpYKS4pZVGtbmV6N21M4epuAOdYDXEPU17RG8J65lEVLOBjmAlfm6rjaGbePBf/wVbiALGHIKzwTg8YdshT9yXV795iRE5CrGOAve2UmZHpnJdCQpOFTt6MZPuD3PILb4GTfB848JrGXsK8FHUYvN9ZX+jqFnEN96wfkSXouc8Xchv4KdZZB1qNxNdzxJ+Duq7RniOFGq0xbpXHdLKlWR/vY9IMqM8RfSkuWS/xRJ0uTiucwmEHjDoH+vmsnxpTPlwpsxZ+RaRd/tHIrGPRNuPgNuu4WA== Received: from CH0PR03CA0354.namprd03.prod.outlook.com (2603:10b6:610:11a::17) by CYYPR12MB8921.namprd12.prod.outlook.com (2603:10b6:930:c7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.34; Wed, 4 Oct 2023 14:06:11 +0000 Received: from DS3PEPF000099E0.namprd04.prod.outlook.com (2603:10b6:610:11a:cafe::e8) by CH0PR03CA0354.outlook.office365.com (2603:10b6:610:11a::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6863.25 via Frontend Transport; Wed, 4 Oct 2023 14:06:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by DS3PEPF000099E0.mail.protection.outlook.com (10.167.17.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.14 via Frontend Transport; Wed, 4 Oct 2023 14:06:09 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Wed, 4 Oct 2023 07:05:52 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Wed, 4 Oct 2023 07:05:52 -0700 Received: from sumitg-l4t.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Wed, 4 Oct 2023 07:05:49 -0700 From: Sumit Gupta To: , , , , CC: , , , , Subject: [Patch v3 1/2] cpufreq: tegra194: save CPU data to avoid repeated SMP calls Date: Wed, 4 Oct 2023 19:35:36 +0530 Message-ID: <20231004140537.1954-2-sumitg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231004140537.1954-1-sumitg@nvidia.com> References: <20231004140537.1954-1-sumitg@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099E0:EE_|CYYPR12MB8921:EE_ X-MS-Office365-Filtering-Correlation-Id: 5286dea1-47fe-4abd-68c9-08dbc4e30f78 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fsb9OkfaA0ig8naCsV+U3YxoW6AxlcjpToBJN/3hZEupJ0qtO9vW3RUfeFgUd3pucOVBFyAvVx662CzjvaKq8C9fjzKx48HvISzSoDCYlZtXsPyCS9oCJAJGfVv83INmNTXg8Lgf9HHzaTtTq4I9PImq3dbRfZ4eKSEAj1hRjHzrjxaSW/xdtkeI3VM3R9cQE5ZIDY5uMdhMYE/olXX1nEBT5m6Tka4jx7Rv+ah1U2FStoJobpl33ss4zs1Nq+roTS+UWl+fxZYZfaoQMCQkp2baZcEwynMEwHa89mD/NR1ysef5JUiXla/l7tC3OQJIKyaGQKV9oIfkmTrfN1IM/tm60q1HSrtNFNU/Ke3Iz7vtlv/Xhnx6INmlt/OTJU+nd02CAM/pHpsR2JHUQ1vDoVrBSvDkAbItyhzd1MC0sWMs/YZlbD6LnZtZEP8ybThy1ocwGhe8lVOd5kvho6R6Qq3wefY7dCm2TqQLDCWSrIwvVcTR45qBPRPDtBEIcpJ555CIJkUrnWl6KHhWLJ48OJuHf6KUi5QVruGZMVQKb6/0gGkd31zcWxCC8uEB+EKlEvfCK7NGun0Dyq3PnCwVmoeKdMV61BFXfaEBOmpk3VEjmfFg/wmPrlpskm6Z6P/Lv8rVtXfrrcYDQSmTBq3940/KMCeJEfZfEATbdQVMZxz6L9FJx7Z+YnQ1XGtE1UCq/Alxq4cMpPs9UFfsCHxgc2Uk0hAEomG56gtoHo4J5zjrfkpeQvBEz4jkuEhpF4Uu X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(136003)(346002)(396003)(376002)(230922051799003)(186009)(1800799009)(451199024)(82310400011)(64100799003)(46966006)(40470700004)(36840700001)(40480700001)(336012)(1076003)(2616005)(426003)(26005)(40460700003)(82740400003)(86362001)(36756003)(356005)(7636003)(70586007)(107886003)(83380400001)(2906002)(478600001)(36860700001)(6666004)(47076005)(7696005)(5660300002)(54906003)(316002)(4326008)(41300700001)(8936002)(8676002)(70206006)(110136005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2023 14:06:09.7508 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5286dea1-47fe-4abd-68c9-08dbc4e30f78 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: DS3PEPF000099E0.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8921 X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 04 Oct 2023 07:06:54 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778834125770512523 X-GMAIL-MSGID: 1778834125770512523 Currently, we make SMP call on every frequency set request to get the physical 'CPU ID' and 'CLUSTER ID' for the target CPU. This change optimizes the repeated calls by storing the physical IDs and the per core frequency register offset for all CPUs during boot. Later this info is used directly when required to set the frequency or read it from ACTMON counters. Signed-off-by: Sumit Gupta --- drivers/cpufreq/tegra194-cpufreq.c | 79 +++++++++++++++++++----------- 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/drivers/cpufreq/tegra194-cpufreq.c b/drivers/cpufreq/tegra194-cpufreq.c index 386aed3637b4..f6a8e6cf6d94 100644 --- a/drivers/cpufreq/tegra194-cpufreq.c +++ b/drivers/cpufreq/tegra194-cpufreq.c @@ -39,6 +39,12 @@ /* cpufreq transisition latency */ #define TEGRA_CPUFREQ_TRANSITION_LATENCY (300 * 1000) /* unit in nanoseconds */ +struct tegra_cpu_data { + u32 cpuid; + u32 clusterid; + void __iomem *freq_core_reg; +}; + struct tegra_cpu_ctr { u32 cpu; u32 coreclk_cnt, last_coreclk_cnt; @@ -69,6 +75,7 @@ struct tegra194_cpufreq_data { struct cpufreq_frequency_table **bpmp_luts; const struct tegra_cpufreq_soc *soc; bool icc_dram_bw_scaling; + struct tegra_cpu_data *cpu_data; }; static struct workqueue_struct *read_counters_wq; @@ -116,14 +123,8 @@ static void tegra234_get_cpu_cluster_id(u32 cpu, u32 *cpuid, u32 *clusterid) static int tegra234_get_cpu_ndiv(u32 cpu, u32 cpuid, u32 clusterid, u64 *ndiv) { struct tegra194_cpufreq_data *data = cpufreq_get_driver_data(); - void __iomem *freq_core_reg; - u64 mpidr_id; - - /* use physical id to get address of per core frequency register */ - mpidr_id = (clusterid * data->soc->maxcpus_per_cluster) + cpuid; - freq_core_reg = SCRATCH_FREQ_CORE_REG(data, mpidr_id); - *ndiv = readl(freq_core_reg) & NDIV_MASK; + *ndiv = readl(data->cpu_data[cpu].freq_core_reg) & NDIV_MASK; return 0; } @@ -131,19 +132,10 @@ static int tegra234_get_cpu_ndiv(u32 cpu, u32 cpuid, u32 clusterid, u64 *ndiv) static void tegra234_set_cpu_ndiv(struct cpufreq_policy *policy, u64 ndiv) { struct tegra194_cpufreq_data *data = cpufreq_get_driver_data(); - void __iomem *freq_core_reg; - u32 cpu, cpuid, clusterid; - u64 mpidr_id; - - for_each_cpu_and(cpu, policy->cpus, cpu_online_mask) { - data->soc->ops->get_cpu_cluster_id(cpu, &cpuid, &clusterid); - - /* use physical id to get address of per core frequency register */ - mpidr_id = (clusterid * data->soc->maxcpus_per_cluster) + cpuid; - freq_core_reg = SCRATCH_FREQ_CORE_REG(data, mpidr_id); + u32 cpu; - writel(ndiv, freq_core_reg); - } + for_each_cpu_and(cpu, policy->cpus, cpu_online_mask) + writel(ndiv, data->cpu_data[cpu].freq_core_reg); } /* @@ -157,11 +149,10 @@ static void tegra234_read_counters(struct tegra_cpu_ctr *c) { struct tegra194_cpufreq_data *data = cpufreq_get_driver_data(); void __iomem *actmon_reg; - u32 cpuid, clusterid; u64 val; - data->soc->ops->get_cpu_cluster_id(c->cpu, &cpuid, &clusterid); - actmon_reg = CORE_ACTMON_CNTR_REG(data, clusterid, cpuid); + actmon_reg = CORE_ACTMON_CNTR_REG(data, data->cpu_data[c->cpu].clusterid, + data->cpu_data[c->cpu].cpuid); val = readq(actmon_reg); c->last_refclk_cnt = upper_32_bits(val); @@ -357,19 +348,17 @@ static void tegra194_set_cpu_ndiv(struct cpufreq_policy *policy, u64 ndiv) static unsigned int tegra194_get_speed(u32 cpu) { struct tegra194_cpufreq_data *data = cpufreq_get_driver_data(); + u32 clusterid = data->cpu_data[cpu].clusterid; struct cpufreq_frequency_table *pos; - u32 cpuid, clusterid; unsigned int rate; u64 ndiv; int ret; - data->soc->ops->get_cpu_cluster_id(cpu, &cpuid, &clusterid); - /* reconstruct actual cpu freq using counters */ rate = tegra194_calculate_speed(cpu); /* get last written ndiv value */ - ret = data->soc->ops->get_cpu_ndiv(cpu, cpuid, clusterid, &ndiv); + ret = data->soc->ops->get_cpu_ndiv(cpu, data->cpu_data[cpu].cpuid, clusterid, &ndiv); if (WARN_ON_ONCE(ret)) return rate; @@ -475,13 +464,12 @@ static int tegra194_cpufreq_init(struct cpufreq_policy *policy) { struct tegra194_cpufreq_data *data = cpufreq_get_driver_data(); int maxcpus_per_cluster = data->soc->maxcpus_per_cluster; + u32 clusterid = data->cpu_data[policy->cpu].clusterid; struct cpufreq_frequency_table *freq_table; struct cpufreq_frequency_table *bpmp_lut; u32 start_cpu, cpu; - u32 clusterid; int ret; - data->soc->ops->get_cpu_cluster_id(policy->cpu, NULL, &clusterid); if (clusterid >= data->soc->num_clusters || !data->bpmp_luts[clusterid]) return -EINVAL; @@ -659,6 +647,28 @@ tegra_cpufreq_bpmp_read_lut(struct platform_device *pdev, struct tegra_bpmp *bpm return freq_table; } +static int tegra194_cpufreq_store_physids(unsigned int cpu, struct tegra194_cpufreq_data *data) +{ + int num_cpus = data->soc->maxcpus_per_cluster * data->soc->num_clusters; + u32 cpuid, clusterid; + u64 mpidr_id; + + if (cpu > (num_cpus - 1)) { + pr_err("cpufreq: wrong num of cpus or clusters in soc data\n"); + return -EINVAL; + } + + data->soc->ops->get_cpu_cluster_id(cpu, &cpuid, &clusterid); + + mpidr_id = (clusterid * data->soc->maxcpus_per_cluster) + cpuid; + + data->cpu_data[cpu].cpuid = cpuid; + data->cpu_data[cpu].clusterid = clusterid; + data->cpu_data[cpu].freq_core_reg = SCRATCH_FREQ_CORE_REG(data, mpidr_id); + + return 0; +} + static int tegra194_cpufreq_probe(struct platform_device *pdev) { const struct tegra_cpufreq_soc *soc; @@ -666,6 +676,7 @@ static int tegra194_cpufreq_probe(struct platform_device *pdev) struct tegra_bpmp *bpmp; struct device *cpu_dev; int err, i; + u32 cpu; data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); if (!data) @@ -692,6 +703,12 @@ static int tegra194_cpufreq_probe(struct platform_device *pdev) return PTR_ERR(data->regs); } + data->cpu_data = devm_kcalloc(&pdev->dev, data->soc->num_clusters * + data->soc->maxcpus_per_cluster, + sizeof(*data->cpu_data), GFP_KERNEL); + if (!data->cpu_data) + return -ENOMEM; + platform_set_drvdata(pdev, data); bpmp = tegra_bpmp_get(&pdev->dev); @@ -713,6 +730,12 @@ static int tegra194_cpufreq_probe(struct platform_device *pdev) } } + for_each_possible_cpu(cpu) { + err = tegra194_cpufreq_store_physids(cpu, data); + if (err) + goto err_free_res; + } + tegra194_cpufreq_driver.driver_data = data; /* Check for optional OPPv2 and interconnect paths on CPU0 to enable ICC scaling */ From patchwork Wed Oct 4 14:05:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sumit Gupta X-Patchwork-Id: 148314 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:254a:b0:403:3b70:6f57 with SMTP id hf10csp158013vqb; Wed, 4 Oct 2023 07:06:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEjxgxy4HwmfVobhIqY2qC1sPVHNWTjoWqMnaIMNurkPJC7mwdOkWQkitG6Ub0YX+qSsoTK X-Received: by 2002:a17:902:e810:b0:1c5:59ea:84de with SMTP id u16-20020a170902e81000b001c559ea84demr2923211plg.29.1696428380097; Wed, 04 Oct 2023 07:06:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1696428380; cv=pass; d=google.com; s=arc-20160816; b=u+oskrgas8nfWTyVZbprqKzqF3KW+lxTVQv1Ki73Pc48b2lSFIvbqr89sqaOTaK1wE QcpXA68G49io87xD+VcahjDPbzMw7He8skSuJvMiFJkZ9fZnXGxFyreM5S/ODSFGnqpa Uh41zSgbKjPwfcoqT+e24loABNBINYu7cE3ALTl9HSEKr6WhO/Xvszg9C0tM7pADwM5t ccxgthntGHZyNq3aawCIXrbYflUZkh7kWFDbkiZNICtbkyKqU6befuUY5AqRhKzyz3W6 7YXJQCOpama1hPwtbdtOcaJydBCKxIzLWo4NROmX2nvoUhsLkNlNsOEo5ljHHa9USt6k rjGg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=mlWA6IqwFgnqYSOaNZVXjc157Wbs69fD+N0aGyKM7Qo=; fh=PTp2mvTrCvo/vo16l0ne4zJtbYthE/in2768K/EMwdE=; b=MhDEelx7bZtgKOzhcqOV1G7cvP5CYdjeb+B6fXF4QwUM3y8Qa3KYRA2n0g5AXr+Muq l1ov27mnr/OJVMTUrtnh7JGd7msc8A/KupgKbDcA3CufNqAUe2ZBNJIwlSyp+yLW6dah bXaficmS6lCKT1TDVA81Ty5pjt/z9uzJPmcvkFv7dYZwij80yjyoGgeKNmNUk/ExF1Tn /ERYjlYdWTOdTJmRNyUzydlQHqrafWF8cOOh4RtspLVEIxt7yNobhI0utMNvMEV5QHM/ O9UEq+PUGPWruydj+xUKxYDXATnFpxVl7CW4dFj8PJ+FRXnDxdpv1DWTq42K8S180uYq mi2Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=A3VWr+DW; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id q1-20020a170902f34100b001b8b4371af8si3377247ple.648.2023.10.04.07.06.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 07:06:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=A3VWr+DW; arc=pass (i=1 spf=pass spfdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 34962821823E; Wed, 4 Oct 2023 07:06:18 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242780AbjJDOGP (ORCPT + 18 others); Wed, 4 Oct 2023 10:06:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233306AbjJDOGN (ORCPT ); Wed, 4 Oct 2023 10:06:13 -0400 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2082.outbound.protection.outlook.com [40.107.95.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03778A1; Wed, 4 Oct 2023 07:06:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H1sDvb5M9b3IxSqG16T4dzoaRm+Os4k0ky5wenzpy6v+0vmGZXBrffXxsLpFNPU6mNS9EyoAJJ8ACC5R/68AL4Dj9UmyO3UNCY68IXatS4OzLtFtxLf65XBR/eMbcY0SfPc3wZIrKblpUBrHftLOkgUj4RHJJemnKryreK9iU8DmgAjnWtgozowY/j17PpjtAlPn2203Iy7DOf8E0torYZKKFK83WCBvaFP+Cqb/kdp2JmwnLzSOoP0uOh9vzG+De3xt5OFeQFsZdb5FRPTynSCk1dUPAnLX3earDQloaKxnKaI0L8AKtRXQOr7KBpiifSutLkTpWjiEFekBlPQbpg== 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=mlWA6IqwFgnqYSOaNZVXjc157Wbs69fD+N0aGyKM7Qo=; b=ZuXdMoOM7nnFQ84uLe4c+hWHsIZDRLSt8ozrLjWmNWTKtE0or/fPYw38exHXRt/LLdCxyXMjn12/gUwqpSXPmb8IGYj9QehvgHzqyCSfG6izHC3/fCM+nRQnhhm8BRVcBQHB3Euswk5Thd5FBYAuYP3svJRE2Bb0sLjr8YQlQuxLCfhxpfHehDaJIVmEuiL79nal6BygzYV/GSNJHXbvAXQvxrWQNGvOwC+KDcpz69+lKkjo+FEpYbMTOLA1BC33csyFkf3gBkuCX+1emOsMsLnlIyYj6l1MXyO2L1aPOx6nes2C+tt11bTVKkgoJdLmEz9WBxRnWfmHydEvsGtxrg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=mlWA6IqwFgnqYSOaNZVXjc157Wbs69fD+N0aGyKM7Qo=; b=A3VWr+DWfwyk8S5PjPl8CX3qWNjfQ8GqMwruYawrifb0BlM1fO0wIzmlnoNfHZUzqhsYqKwUAbSEeStYlQV1vbGMorUtDfnPS5Wm/lOe+Kanyr7KwuK7ESUXnNufLVKPaQVhv7tueILy3+qUHf8IegRg4tFXkax1JPDYVElfZVTC3zsRZuaQYeLborJYm3UzSPWyXGsVbW/sMN8Nd3dFpFUCO4gnX5zaGpZeTnuURxPdhe5TVawqrwv0mlencbmz1bBTljd4rom+TTKGVvyd4MGah/xJfeIju8hfy/eK0j4TbslgGDwIiYYOasifQoU4tWI/bhx/BnuGj/2LQ4djSw== Received: from DS7PR03CA0210.namprd03.prod.outlook.com (2603:10b6:5:3b6::35) by DM4PR12MB6183.namprd12.prod.outlook.com (2603:10b6:8:a7::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.29; Wed, 4 Oct 2023 14:06:08 +0000 Received: from CY4PEPF0000EE37.namprd05.prod.outlook.com (2603:10b6:5:3b6:cafe::9c) by DS7PR03CA0210.outlook.office365.com (2603:10b6:5:3b6::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.37 via Frontend Transport; Wed, 4 Oct 2023 14:06:08 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by CY4PEPF0000EE37.mail.protection.outlook.com (10.167.242.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.20 via Frontend Transport; Wed, 4 Oct 2023 14:06:07 +0000 Received: from rnnvmail204.nvidia.com (10.129.68.6) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Wed, 4 Oct 2023 07:05:57 -0700 Received: from rnnvmail201.nvidia.com (10.129.68.8) by rnnvmail204.nvidia.com (10.129.68.6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.41; Wed, 4 Oct 2023 07:05:57 -0700 Received: from sumitg-l4t.nvidia.com (10.127.8.10) by mail.nvidia.com (10.129.68.8) with Microsoft SMTP Server id 15.2.986.41 via Frontend Transport; Wed, 4 Oct 2023 07:05:54 -0700 From: Sumit Gupta To: , , , , CC: , , , , Subject: [Patch v3 2/2] cpufreq: tegra194: use refclk delta based loop instead of udelay Date: Wed, 4 Oct 2023 19:35:37 +0530 Message-ID: <20231004140537.1954-3-sumitg@nvidia.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231004140537.1954-1-sumitg@nvidia.com> References: <20231004140537.1954-1-sumitg@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 X-NV-OnPremToCloud: ExternallySecured X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CY4PEPF0000EE37:EE_|DM4PR12MB6183:EE_ X-MS-Office365-Filtering-Correlation-Id: c91a4ded-7031-4a20-956b-08dbc4e30e4a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /6k6sv75ZWXVDyNAxEZ6pJjZk97QKHWRnpRg1zDKJSzP45UnV9uo80SHcyVM8WRlSxwP7lmcMgqxyS+ELcsH+Lh3jYitC4kJr2rlKD166I7sjlyDsgIRG5m1GDUWw3lkLMtxSzrY61xp8uXUXTjju68BcuUZQ+fVk5YFzZc62/gpfV+CnKNY/TPhOd4Hu7iopPX9gEmVNUjwMeTBiCm+koPj0MQhFEIDXBznUUGYAaRfYgfYwwAuGgYHptELSUS/bpr2AGhdXeuBK0XAMtQ8vU3NuGCSJoCecTfi7ddaZ0bFtO7oMq8PRpCFe02ILrljvfTjarGqMGEjBhwDGICJEc5nXNw8A4A24B9V5OXgpVx5s6rWa3bdhKE0FYuX0d2M0r9FhgpYqYYIc12BGLJmvBO6Vv2RKUgbx2COyfCgcffsPrK/xSibgrMryWsruPz13XWCBmJ1Gbo4ojC7T2QErSQ3E7ZhZ3lxLZwLwyN/VHoxyqiofwH8xnxB+P7X7CVMDOqg3KGiBjJ0SqwPQ0Y7Fqn/vqUHlESBIbIEuLYbILKDkbQiDvCfL19TfRH7nOtcA/Ux0Ij0ZGAocglo+acxjEJ7LL23EehWxxs2U9ZLCmkj5VQXKno+pTt3vx1L11WfZj34aof4hWr+Tewk5HnzGSqOQcqOgLZzNoSHaIFjKv4bbgpKL0lFolWyg7TYXK4gsVhvS3PtIzHp/kxyc2WhaUyqcE28rpwyYNVQKS259S8RqlNRyuLCRlw1n5uzsqvb X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230031)(4636009)(376002)(136003)(39860400002)(396003)(346002)(230922051799003)(64100799003)(186009)(82310400011)(451199024)(1800799009)(36840700001)(46966006)(40470700004)(426003)(40460700003)(336012)(1076003)(26005)(107886003)(2616005)(82740400003)(7636003)(36860700001)(356005)(86362001)(83380400001)(36756003)(47076005)(316002)(40480700001)(54906003)(478600001)(4326008)(70586007)(5660300002)(8936002)(8676002)(70206006)(7696005)(110136005)(6666004)(41300700001)(2906002);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2023 14:06:07.8352 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c91a4ded-7031-4a20-956b-08dbc4e30e4a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CY4PEPF0000EE37.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB6183 X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 04 Oct 2023 07:06:18 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778834084942865530 X-GMAIL-MSGID: 1778834084942865530 Use reference clock count based loop instead of "udelay()" for sampling of counters to improve the accuracy of re-generated CPU frequency. "udelay()" internally calls "WFE" which stops the counters and results in bigger delta between the last set freq and the re-generated value from counters. The counter sampling window used in loop is the minimum number of reference clock cycles which is known to give a stable value of CPU frequency. The change also helps to reduce the sampling window from "500us" to "<50us". Suggested-by: Antti Miettinen Signed-off-by: Sumit Gupta --- drivers/cpufreq/tegra194-cpufreq.c | 72 +++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 17 deletions(-) diff --git a/drivers/cpufreq/tegra194-cpufreq.c b/drivers/cpufreq/tegra194-cpufreq.c index f6a8e6cf6d94..9dae6195e0e7 100644 --- a/drivers/cpufreq/tegra194-cpufreq.c +++ b/drivers/cpufreq/tegra194-cpufreq.c @@ -5,7 +5,6 @@ #include #include -#include #include #include #include @@ -21,10 +20,11 @@ #define KHZ 1000 #define REF_CLK_MHZ 408 /* 408 MHz */ -#define US_DELAY 500 #define CPUFREQ_TBL_STEP_HZ (50 * KHZ * KHZ) #define MAX_CNT ~0U +#define MAX_DELTA_KHZ 115200 + #define NDIV_MASK 0x1FF #define CORE_OFFSET(cpu) (cpu * 8) @@ -68,6 +68,7 @@ struct tegra_cpufreq_soc { int maxcpus_per_cluster; unsigned int num_clusters; phys_addr_t actmon_cntr_base; + u32 refclk_delta_min; }; struct tegra194_cpufreq_data { @@ -149,6 +150,8 @@ static void tegra234_read_counters(struct tegra_cpu_ctr *c) { struct tegra194_cpufreq_data *data = cpufreq_get_driver_data(); void __iomem *actmon_reg; + u32 delta_refcnt; + int cnt = 0; u64 val; actmon_reg = CORE_ACTMON_CNTR_REG(data, data->cpu_data[c->cpu].clusterid, @@ -157,10 +160,25 @@ static void tegra234_read_counters(struct tegra_cpu_ctr *c) val = readq(actmon_reg); c->last_refclk_cnt = upper_32_bits(val); c->last_coreclk_cnt = lower_32_bits(val); - udelay(US_DELAY); - val = readq(actmon_reg); - c->refclk_cnt = upper_32_bits(val); - c->coreclk_cnt = lower_32_bits(val); + + /* + * The sampling window is based on the minimum number of reference + * clock cycles which is known to give a stable value of CPU frequency. + */ + do { + val = readq(actmon_reg); + c->refclk_cnt = upper_32_bits(val); + c->coreclk_cnt = lower_32_bits(val); + if (c->refclk_cnt < c->last_refclk_cnt) + delta_refcnt = c->refclk_cnt + (MAX_CNT - c->last_refclk_cnt); + else + delta_refcnt = c->refclk_cnt - c->last_refclk_cnt; + if (++cnt >= 0xFFFF) { + pr_warn("cpufreq: problem with refclk on cpu:%d, delta_refcnt:%u, cnt:%d\n", + c->cpu, delta_refcnt, cnt); + break; + } + } while (delta_refcnt < data->soc->refclk_delta_min); } static struct tegra_cpufreq_ops tegra234_cpufreq_ops = { @@ -175,6 +193,7 @@ static const struct tegra_cpufreq_soc tegra234_cpufreq_soc = { .actmon_cntr_base = 0x9000, .maxcpus_per_cluster = 4, .num_clusters = 3, + .refclk_delta_min = 16000, }; static const struct tegra_cpufreq_soc tegra239_cpufreq_soc = { @@ -182,6 +201,7 @@ static const struct tegra_cpufreq_soc tegra239_cpufreq_soc = { .actmon_cntr_base = 0x4000, .maxcpus_per_cluster = 8, .num_clusters = 1, + .refclk_delta_min = 16000, }; static void tegra194_get_cpu_cluster_id(u32 cpu, u32 *cpuid, u32 *clusterid) @@ -222,15 +242,33 @@ static inline u32 map_ndiv_to_freq(struct mrq_cpu_ndiv_limits_response static void tegra194_read_counters(struct tegra_cpu_ctr *c) { + struct tegra194_cpufreq_data *data = cpufreq_get_driver_data(); + u32 delta_refcnt; + int cnt = 0; u64 val; val = read_freq_feedback(); c->last_refclk_cnt = lower_32_bits(val); c->last_coreclk_cnt = upper_32_bits(val); - udelay(US_DELAY); - val = read_freq_feedback(); - c->refclk_cnt = lower_32_bits(val); - c->coreclk_cnt = upper_32_bits(val); + + /* + * The sampling window is based on the minimum number of reference + * clock cycles which is known to give a stable value of CPU frequency. + */ + do { + val = read_freq_feedback(); + c->refclk_cnt = lower_32_bits(val); + c->coreclk_cnt = upper_32_bits(val); + if (c->refclk_cnt < c->last_refclk_cnt) + delta_refcnt = c->refclk_cnt + (MAX_CNT - c->last_refclk_cnt); + else + delta_refcnt = c->refclk_cnt - c->last_refclk_cnt; + if (++cnt >= 0xFFFF) { + pr_warn("cpufreq: problem with refclk on cpu:%d, delta_refcnt:%u, cnt:%d\n", + c->cpu, delta_refcnt, cnt); + break; + } + } while (delta_refcnt < data->soc->refclk_delta_min); } static void tegra_read_counters(struct work_struct *work) @@ -288,9 +326,8 @@ static unsigned int tegra194_calculate_speed(u32 cpu) u32 rate_mhz; /* - * udelay() is required to reconstruct cpu frequency over an - * observation window. Using workqueue to call udelay() with - * interrupts enabled. + * Reconstruct cpu frequency over an observation/sampling window. + * Using workqueue to keep interrupts enabled during the interval. */ read_counters_work.c.cpu = cpu; INIT_WORK_ONSTACK(&read_counters_work.work, tegra_read_counters); @@ -372,9 +409,9 @@ static unsigned int tegra194_get_speed(u32 cpu) if (pos->driver_data != ndiv) continue; - if (abs(pos->frequency - rate) > 115200) { - pr_warn("cpufreq: cpu%d,cur:%u,set:%u,set ndiv:%llu\n", - cpu, rate, pos->frequency, ndiv); + if (abs(pos->frequency - rate) > MAX_DELTA_KHZ) { + pr_warn("cpufreq: cpu%d,cur:%u,set:%u,delta:%d,set ndiv:%llu\n", + cpu, rate, pos->frequency, abs(rate - pos->frequency), ndiv); } else { rate = pos->frequency; } @@ -568,6 +605,7 @@ static const struct tegra_cpufreq_soc tegra194_cpufreq_soc = { .ops = &tegra194_cpufreq_ops, .maxcpus_per_cluster = 2, .num_clusters = 4, + .refclk_delta_min = 16000, }; static void tegra194_cpufreq_free_resources(void) @@ -684,7 +722,7 @@ static int tegra194_cpufreq_probe(struct platform_device *pdev) soc = of_device_get_match_data(&pdev->dev); - if (soc->ops && soc->maxcpus_per_cluster && soc->num_clusters) { + if (soc->ops && soc->maxcpus_per_cluster && soc->num_clusters && soc->refclk_delta_min) { data->soc = soc; } else { dev_err(&pdev->dev, "soc data missing\n");