From patchwork Tue May 16 13:32:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zeng Heng X-Patchwork-Id: 94721 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp447803vqo; Tue, 16 May 2023 07:00:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7y+XADNf6LCGPMZwq6t6owK52zBp7QYy/EUI2pD2JO11xZUUnaXuTUP2F4sWQAkX0NMQDP X-Received: by 2002:a17:902:cec9:b0:19a:a9d8:e47f with SMTP id d9-20020a170902cec900b0019aa9d8e47fmr53206053plg.36.1684245628314; Tue, 16 May 2023 07:00:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684245628; cv=none; d=google.com; s=arc-20160816; b=hanOkiksBDm5L0P1hIPcAO1XEXOf18aTXf+/FTtGioEhGR7ISp8oWr4d01W3f5BHd2 SLiHObHARaVelNWLq4Nbq12K0+fjELu9PLtGiW0N/iIkQRH3XJDnKADaLF1ylH565zJz aPqqhzQyMq0bNz/l1QHGULokFTfQX6n8JAds0RH1O5SVu8EqHXKU8etGcBVNSgI38mpI wtID36rs6CdQflhVu0/Wsa399wUFy6oq6QGYaeatqMSbCIOGKyHqDmjzBi8lDryM28R7 bYD96psrbop5rjjlr8R8w8n7ABwFE//Q7ZzeutT1/4BDRwLPOEJcxWjFwFEn7Au0tb9J Ck1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=PzmuAghbzhLXpxPFHB7IH3hgsBrsQGuYP5Hk5hw9Exk=; b=qXFUszigvXoW28x+5XrulkbhefVDh+6z7iL7Q808Wu+SdfXJDSQj/R2oSemr8cLIGG Q/OIhWMk+LxDAN3zGc7M48Iht35vbk++Qjekqsbjmfc+jk8BqE7UWab1qBPdtGk3ugCR Z72Sa+UNpG8zMgqh/ybDQrJPP/7mhxDRs0eVoh0IaForCBXZrdPnjMYPdStnPiYWil4d q2T7Ye8Ko8dwTiayPJSKVd9dE23vV9HEWDlRiHboZtU9Tw5HI1XH1ldEy/LS5pq7YD+2 odAzAz3vUNmQCp7uOXmqvb/TOBk6s3UcWyvMHKlvFLYXzOOL01+OMvb+N+eux9SZD7uJ OvSA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q12-20020a17090311cc00b001ae16575087si5903625plh.595.2023.05.16.07.00.14; Tue, 16 May 2023 07:00:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233538AbjEPNdL (ORCPT + 99 others); Tue, 16 May 2023 09:33:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232641AbjEPNdH (ORCPT ); Tue, 16 May 2023 09:33:07 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CB3D10DA; Tue, 16 May 2023 06:33:06 -0700 (PDT) Received: from kwepemi500024.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QLH9r5MzwzTkg4; Tue, 16 May 2023 21:28:16 +0800 (CST) Received: from huawei.com (10.175.103.91) by kwepemi500024.china.huawei.com (7.221.188.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 16 May 2023 21:33:03 +0800 From: Zeng Heng To: , , CC: , , , , , , Subject: [PATCH v2 1/2] cpufreq: CPPC: keep target core awake when reading its cpufreq rate Date: Tue, 16 May 2023 21:32:46 +0800 Message-ID: <20230516133248.712242-1-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500024.china.huawei.com (7.221.188.100) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766059543535857504?= X-GMAIL-MSGID: =?utf-8?q?1766059543535857504?= As ARM AMU's document says, all counters are subject to any changes in clock frequency, including clock stopping caused by the WFI and WFE instructions. Therefore, using smp_call_on_cpu() to trigger target CPU to read self's AMU counters, which ensures the counters are working properly during calculation. Signed-off-by: Zeng Heng --- drivers/cpufreq/cppc_cpufreq.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c index 022e3555407c..910167f58bb3 100644 --- a/drivers/cpufreq/cppc_cpufreq.c +++ b/drivers/cpufreq/cppc_cpufreq.c @@ -837,9 +837,24 @@ static int cppc_perf_from_fbctrs(struct cppc_cpudata *cpu_data, return (reference_perf * delta_delivered) / delta_reference; } +static int cppc_get_perf_ctrs_smp(void *val) +{ + int cpu = smp_processor_id(); + struct cppc_perf_fb_ctrs *fb_ctrs = val; + int ret; + + ret = cppc_get_perf_ctrs(cpu, fb_ctrs); + if (ret) + return ret; + + udelay(2); /* 2usec delay between sampling */ + + return cppc_get_perf_ctrs(cpu, fb_ctrs + 1); +} + static unsigned int cppc_cpufreq_get_rate(unsigned int cpu) { - struct cppc_perf_fb_ctrs fb_ctrs_t0 = {0}, fb_ctrs_t1 = {0}; + struct cppc_perf_fb_ctrs fb_ctrs[2] = {0}; struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); struct cppc_cpudata *cpu_data = policy->driver_data; u64 delivered_perf; @@ -847,19 +862,12 @@ static unsigned int cppc_cpufreq_get_rate(unsigned int cpu) cpufreq_cpu_put(policy); - ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t0); - if (ret) - return ret; - - udelay(2); /* 2usec delay between sampling */ - - ret = cppc_get_perf_ctrs(cpu, &fb_ctrs_t1); + ret = smp_call_on_cpu(cpu, cppc_get_perf_ctrs_smp, fb_ctrs, 1); if (ret) return ret; - delivered_perf = cppc_perf_from_fbctrs(cpu_data, &fb_ctrs_t0, - &fb_ctrs_t1); - + delivered_perf = cppc_perf_from_fbctrs(cpu_data, fb_ctrs, + fb_ctrs + 1); return cppc_cpufreq_perf_to_khz(cpu_data, delivered_perf); } From patchwork Tue May 16 13:32:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zeng Heng X-Patchwork-Id: 94709 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp437689vqo; Tue, 16 May 2023 06:43:57 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ydeVUom+eGakN756mdTqZutfW1HAthPq0lFw9JGjmoUgIerwfE5d+3Rp+1LhmleAy2O3V X-Received: by 2002:a05:6a20:9143:b0:104:c2c:52ed with SMTP id x3-20020a056a20914300b001040c2c52edmr13973731pzc.34.1684244636916; Tue, 16 May 2023 06:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684244636; cv=none; d=google.com; s=arc-20160816; b=mEfqorGL4Nyf4Q0gKoMfQ6FJPSWWQuONPbrnG/Oapi4NfmMLgQDQ1CotQaCf6Fro+O oeBGjqp35BedElwyTPPBBATBPPC0fT+I6HrEbTndTbO7yrKZBstmOBj84QD6jzgKFbhd U9O/7h4qqF61UM6N41e1mLObqpAnAJPplAZiClqR36BvAB9GnOsUIJiuk9uDxxOIucFJ z4W6dbMXE3jtZLbi7u67JH3xJ9RhpLT1U1hCBpfz7LA0+lgDpCDBqPtFvg1VtAW+XIal TRXs/niLe41RFXFqRvXH6CbV8zcLOmVCG0oV1rJIvBhM4WkUnhlAEDPU+N+O8d63HWqC c93A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=rRwlOiPq5WpoCDfD0xv3hyvOoxXJyGMPUWJS7DNoWDE=; b=J0MZnyYXm+mf8xWkzKpekvzEHSL64vcvZZ6s1Oll1Nl/SWAskIZzok3NEww4esDE2E uHTsYZzxglFG7sldD1WHrpEEMbr7XDhqfbaWXBZYGNpdBaOxnQ1o0osnd2ac7d5pY0u7 F+c3nbRcy6Dx9GPICgrRWb0zIw0nIm0jUvm1neyplBnKfMt21VN7JRFksTaldkw0ykEw JWnHqLLQ2v/pi5TTHijoe92k2pDL0qXj2HfP5juqIlUCvuUr5p+FUM+jwRu7fXC0OTEC FpFKQB7FaWEd5Yhu9jkE/B2FDbPzESuzbW+q8uarWEewhmNLRRWBTzIGhBc0iDit7dMA PI6w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b23-20020aa79517000000b0063b716685fasi19794129pfp.235.2023.05.16.06.43.41; Tue, 16 May 2023 06:43:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233400AbjEPNdI (ORCPT + 99 others); Tue, 16 May 2023 09:33:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232480AbjEPNdH (ORCPT ); Tue, 16 May 2023 09:33:07 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7519C3C1D; Tue, 16 May 2023 06:33:06 -0700 (PDT) Received: from kwepemi500024.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4QLHD35NJszLprZ; Tue, 16 May 2023 21:30:11 +0800 (CST) Received: from huawei.com (10.175.103.91) by kwepemi500024.china.huawei.com (7.221.188.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Tue, 16 May 2023 21:33:03 +0800 From: Zeng Heng To: , , CC: , , , , , , Subject: [PATCH v2 2/2] acpi: CPPC: read delivered_reg and reference_reg in critical section Date: Tue, 16 May 2023 21:32:47 +0800 Message-ID: <20230516133248.712242-2-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230516133248.712242-1-zengheng4@huawei.com> References: <20230516133248.712242-1-zengheng4@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemi500024.china.huawei.com (7.221.188.100) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766058504559867858?= X-GMAIL-MSGID: =?utf-8?q?1766058504559867858?= Reading the content of delivered_reg and reference_reg should be in the same critical section, in case any interrupt comes, which could lead to inaccurate frequency calculation. Signed-off-by: Zeng Heng --- drivers/acpi/cppc_acpi.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 7ff269a78c20..92af57ff61ce 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -1315,6 +1315,7 @@ int cppc_get_perf_ctrs(int cpunum, struct cppc_perf_fb_ctrs *perf_fb_ctrs) struct cppc_pcc_data *pcc_ss_data = NULL; u64 delivered, reference, ref_perf, ctr_wrap_time; int ret = 0, regs_in_pcc = 0; + unsigned long flags; if (!cpc_desc) { pr_debug("No CPC descriptor for CPU:%d\n", cpunum); @@ -1350,8 +1351,11 @@ int cppc_get_perf_ctrs(int cpunum, struct cppc_perf_fb_ctrs *perf_fb_ctrs) } } + local_irq_save(flags); cpc_read(cpunum, delivered_reg, &delivered); cpc_read(cpunum, reference_reg, &reference); + local_irq_restore(flags); + cpc_read(cpunum, ref_perf_reg, &ref_perf); /*