From patchwork Wed Dec 21 15:52:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pratyush Yadav X-Patchwork-Id: 35425 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3600106wrn; Wed, 21 Dec 2022 07:56:32 -0800 (PST) X-Google-Smtp-Source: AMrXdXvZlp+biouZ1/UTBN9xjGIngq3Qvv+AB4rW8pzJTCZFfHrYH4AAytg988EIZqPC8nH2UCVt X-Received: by 2002:a17:907:8b09:b0:7c1:bb5:5704 with SMTP id sz9-20020a1709078b0900b007c10bb55704mr1743015ejc.26.1671638192455; Wed, 21 Dec 2022 07:56:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671638192; cv=none; d=google.com; s=arc-20160816; b=JqSHAnTNfMeFib5Txf6B0hvb6wkxkDrG5hg4qPSdJ1VKyaFx6/IVa/3jwimgLkKzTG ev6DX3vy9luxuRj62lU+4D/sOaQs43b+CyfhtWkAoLyvkFQp6VSonS1AItm/r9c7hGQ2 6exXJN4wj2QukXZxYVNxhjjgByvGwNaYOTuo0WCz8echW0dpxP/9eKzme8B90HXOjdHg Bz7Sg61UBfacZdXLjX84+Zvt09nVjIaztzAkTHTGOlzPvTDdHRTJ8RIMhssnQ86f7bnZ IWmRAaGhDEvcdz0gKsqF+HZaeJRyLUYZ/ryH6HFHChqjJDshzYX0wxljrcj9bMchboFK pk7A== 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 :dkim-signature; bh=fPHbtq9qCbxUujjnY3/7YX+cvjvbTVPwrWqhH/h+PEk=; b=XVtN3gL0eSvXGQ9L7ThB4t6bND4t5eTzWpm527N0OvNerXX4Oj9xZTa7OwXH9RmsYe m21PlpSgW5cv9zENp9DJBLz6mCag43BpJo12qQD4kK+inESntmcr6byawPBPLyHVz3fp kRarszH2HPK+QJBpwy9zPP8SddcJFgUaahGpOXyGXBJN/o4t4rt+sQMgToOnoTL+5+8N XxFeWpZT+DIhSat+5RYgo0+rIIfR7PS9IE9n/GA1ta6nRf4bTgpvu+aDBX8VHvSswWTQ DIwTWNOxVpZppyYMsQk5VDkPJD357iAIKaYdg6JWw5b2S1NMnI+m3xMp17U4N1EGy9w3 Tpsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=JJ1Fsp53; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sa25-20020a1709076d1900b007f46a3735c4si12602202ejc.555.2022.12.21.07.56.09; Wed, 21 Dec 2022 07:56:32 -0800 (PST) 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; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=JJ1Fsp53; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234099AbiLUPwW (ORCPT + 99 others); Wed, 21 Dec 2022 10:52:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232524AbiLUPwS (ORCPT ); Wed, 21 Dec 2022 10:52:18 -0500 Received: from smtp-fw-6002.amazon.com (smtp-fw-6002.amazon.com [52.95.49.90]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF8601A393; Wed, 21 Dec 2022 07:52:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1671637937; x=1703173937; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fPHbtq9qCbxUujjnY3/7YX+cvjvbTVPwrWqhH/h+PEk=; b=JJ1Fsp534wZA9AD1yviaKPtplc1g6I0dGyLxS10aSnMnPQZcuoFlA9H0 MJjOlk4CoauWjggrH5KI4gsZG3f9sQ2eAKTWp9CFi0dJkwpP3gxVINcuJ c1XzecTP9Ne0c9IR2fKLxMmAPNhuuEE8vE2yWy4wcWzshoQfFsjHY2VMN Y=; X-IronPort-AV: E=Sophos;i="5.96,262,1665446400"; d="scan'208";a="279685468" Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1d-m6i4x-25ac6bd5.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-6002.iad6.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Dec 2022 15:52:14 +0000 Received: from EX13D46EUB002.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1d-m6i4x-25ac6bd5.us-east-1.amazon.com (Postfix) with ESMTPS id B0BFB428FE; Wed, 21 Dec 2022 15:52:11 +0000 (UTC) Received: from EX19D028EUB002.ant.amazon.com (10.252.61.43) by EX13D46EUB002.ant.amazon.com (10.43.166.241) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 21 Dec 2022 15:52:10 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX19D028EUB002.ant.amazon.com (10.252.61.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1118.20; Wed, 21 Dec 2022 15:52:10 +0000 Received: from dev-dsk-ptyadav-1c-37607b33.eu-west-1.amazon.com (10.15.11.255) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Wed, 21 Dec 2022 15:52:08 +0000 Received: by dev-dsk-ptyadav-1c-37607b33.eu-west-1.amazon.com (Postfix, from userid 23027615) id 4B3C120D20; Wed, 21 Dec 2022 16:52:08 +0100 (CET) From: Pratyush Yadav To: CC: Pratyush Yadav , "Rafael J. Wysocki" , Len Brown , Srinivas Pandruvada , Viresh Kumar , Robert Moore , , , Subject: [PATCH 1/2] acpi: processor: allow fixing up the frequency for a performance state Date: Wed, 21 Dec 2022 16:52:02 +0100 Message-ID: <20221221155203.11347-2-ptyadav@amazon.de> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221221155203.11347-1-ptyadav@amazon.de> References: <20221221155203.11347-1-ptyadav@amazon.de> MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_SPF_WL 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?1752839689415486658?= X-GMAIL-MSGID: =?utf-8?q?1752839689415486658?= In some cases the ACPI table can have an incorrect frequency populated for a performance state. For example, in Intel platforms, the Turbo frequency is just listed as +1 MHz above the max non-turbo frequency. The frequency can actually go much higher based on various factors like temperature, voltage, etc. Allow drivers like intel_pstate to fix up performance state frequencies with the actual maximum value. While at it, also update the QoS constraints if needed to match the new frequency values. Signed-off-by: Pratyush Yadav --- drivers/acpi/processor_perflib.c | 40 ++++++++++++++++++++++++++++++++ include/acpi/processor.h | 2 ++ 2 files changed, 42 insertions(+) diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c index 970f04a958cd..4958aee4c024 100644 --- a/drivers/acpi/processor_perflib.c +++ b/drivers/acpi/processor_perflib.c @@ -766,3 +766,43 @@ void acpi_processor_unregister_performance(unsigned int cpu) mutex_unlock(&performance_mutex); } EXPORT_SYMBOL(acpi_processor_unregister_performance); + +int acpi_processor_fixup_perf_state(unsigned int cpu, unsigned int state, + unsigned int frequency) +{ + struct acpi_processor *pr; + int ret; + + mutex_lock(&performance_mutex); + + pr = per_cpu(processors, cpu); + if (!pr) { + mutex_unlock(&performance_mutex); + return -ENODEV; + } + + if (!pr->performance) { + mutex_unlock(&performance_mutex); + return -EINVAL; + } + + if (state >= pr->performance->state_count) { + mutex_unlock(&performance_mutex); + return -EINVAL; + } + + pr->performance->states[state].core_frequency = frequency; + + if (ignore_ppc != 1 && state == pr->performance_platform_limit && + freq_qos_request_active(&pr->perflib_req)) { + ret = freq_qos_update_request(&pr->perflib_req, + frequency * 1000); + if (ret < 0) + pr_warn("Failed to update perflib freq constraint: CPU%d (%d)\n", + pr->id, ret); + } + + mutex_unlock(&performance_mutex); + return 0; +} +EXPORT_SYMBOL(acpi_processor_fixup_perf_state); diff --git a/include/acpi/processor.h b/include/acpi/processor.h index 94181fe9780a..daff978cfa7d 100644 --- a/include/acpi/processor.h +++ b/include/acpi/processor.h @@ -258,6 +258,8 @@ extern int acpi_processor_preregister_performance(struct extern int acpi_processor_register_performance(struct acpi_processor_performance *performance, unsigned int cpu); extern void acpi_processor_unregister_performance(unsigned int cpu); +extern int acpi_processor_fixup_perf_state(unsigned int cpu, unsigned int state, + unsigned int frequency); int acpi_processor_pstate_control(void); /* note: this locks both the calling module and the processor module From patchwork Wed Dec 21 15:52:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pratyush Yadav X-Patchwork-Id: 35426 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp3600453wrn; Wed, 21 Dec 2022 07:57:11 -0800 (PST) X-Google-Smtp-Source: AMrXdXtdqNpbptq1+N1QiFWuM54IkWWwEOIrOaurey/T/mhjrIa4JAz0dipsy+5hfPuZDCJhmMuY X-Received: by 2002:a17:907:86a6:b0:7c0:fd1a:79f0 with SMTP id qa38-20020a17090786a600b007c0fd1a79f0mr6669869ejc.21.1671638231070; Wed, 21 Dec 2022 07:57:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671638231; cv=none; d=google.com; s=arc-20160816; b=fCRb/EH6++vvx5uLFkVM2nAjHYFCaN+p0MPHb+hC/MU4NiHahydqZRC1dQ20XvpJ1K +6silSH+JXDY2mal6KXZXZYWr/ixc5smALfZ2keQyV3VcS1+4aH/OyNmVib2nTer8x4L rXNQ2qT2HUIkhZiKKkhhH8j5tOFfQseclMaBnpkLfLutkMM+8O0kHU51nC3hYJs64u29 jsYur1PEQfKyFT+xyEHC4SyUg7+thZFzWqtlXGPe6Kj7MkxkZfK0yEsRx55K4V0fu4Yt 3TgUKU6/U+ojIeCFLawhw+moQti4S3kyUgHZjRVEap4ZIpBP/0MqfMnUTvlV5K67RAfe KCYQ== 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 :dkim-signature; bh=J37cAmUSy89NFuYuAIQwv935ukDljKuizMPHPLJPbKM=; b=qlgh/JmP3l/aki4Xb++VDaJoLGSjkvwSt/hP8sAYpzbP4Mq73POd3KyzJfFLdVBesx kvsFciwoFPZKofYXqDvS6VTCrBZGQYKuaWnaiSvqUMSObjbz1Arv3n6dOQRWb7cieCDA O10cwe9Hc4ZdxAZT0tZyHK30ITHAnidkWUx8z9fwY8z0Tpwk5232BtHfNdfiomB0sHxm uV0DoclAj0aBmmgAR03FmO+sTLUjRtXJNY5w8oVBNMuBafZEiejLBeyPezpHqHutfSqF 970Mrhx0AWuukOR0GOlkf0zx+fFCnu6if+E3AER2agckRVxWCAuIRdrKYpxCRgxgulyO OVzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=nMl2HKAY; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g11-20020a1709065d0b00b007aee2977f40si2756701ejt.484.2022.12.21.07.56.47; Wed, 21 Dec 2022 07:57:11 -0800 (PST) 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; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=nMl2HKAY; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234073AbiLUPwl (ORCPT + 99 others); Wed, 21 Dec 2022 10:52:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229620AbiLUPw0 (ORCPT ); Wed, 21 Dec 2022 10:52:26 -0500 Received: from smtp-fw-9102.amazon.com (smtp-fw-9102.amazon.com [207.171.184.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F210B1AF11; Wed, 21 Dec 2022 07:52:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1671637944; x=1703173944; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=J37cAmUSy89NFuYuAIQwv935ukDljKuizMPHPLJPbKM=; b=nMl2HKAYop3b/z5l54nQ+AhmJQkqYOczWdr3s4fX9f+pRGMEGl6dUC8u sNd9weT/8qTJpfM56u6RHXCMwb+8BODhQw1PdnYG0IXvWkJzndDkskPcn v8mSGKWyUAYbulbspBJSSPVmBiFly2+5DVULNbBm/dyFjUhqvcoslvvMT 4=; X-IronPort-AV: E=Sophos;i="5.96,262,1665446400"; d="scan'208";a="293101506" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1e-m6i4x-3554bfcf.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-9102.sea19.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Dec 2022 15:52:16 +0000 Received: from EX13D32EUC001.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1e-m6i4x-3554bfcf.us-east-1.amazon.com (Postfix) with ESMTPS id 7C927862F6; Wed, 21 Dec 2022 15:52:13 +0000 (UTC) Received: from EX19D028EUC002.ant.amazon.com (10.252.61.186) by EX13D32EUC001.ant.amazon.com (10.43.164.159) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 21 Dec 2022 15:52:12 +0000 Received: from EX13MTAUWA001.ant.amazon.com (10.43.160.58) by EX19D028EUC002.ant.amazon.com (10.252.61.186) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1118.20; Wed, 21 Dec 2022 15:52:11 +0000 Received: from dev-dsk-ptyadav-1c-37607b33.eu-west-1.amazon.com (10.15.11.255) by mail-relay.amazon.com (10.43.160.118) with Microsoft SMTP Server id 15.0.1497.42 via Frontend Transport; Wed, 21 Dec 2022 15:52:10 +0000 Received: by dev-dsk-ptyadav-1c-37607b33.eu-west-1.amazon.com (Postfix, from userid 23027615) id 412FB20D08; Wed, 21 Dec 2022 16:52:10 +0100 (CET) From: Pratyush Yadav To: CC: Pratyush Yadav , "Rafael J. Wysocki" , Len Brown , Srinivas Pandruvada , Viresh Kumar , Robert Moore , , , Subject: [PATCH 2/2] cpufreq: intel_pstate: use acpi perflib to update turbo frequency Date: Wed, 21 Dec 2022 16:52:03 +0100 Message-ID: <20221221155203.11347-3-ptyadav@amazon.de> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221221155203.11347-1-ptyadav@amazon.de> References: <20221221155203.11347-1-ptyadav@amazon.de> MIME-Version: 1.0 X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_SPF_WL 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?1752839729931403916?= X-GMAIL-MSGID: =?utf-8?q?1752839729931403916?= The _PSS table does not contain the whole turbo frequency range, but only +1 MHz above the max non-turbo frequency. The pstate driver then updates the ACPI perf data with the actual max frequency. But doing this here directly would mean that frequency QoS constraints that acpi perflib imposes do not get updated. This is a problem when a CPU is brought offline and online again. When the CPU first comes online, cpufreq is not initialized. So PPC constraints are not applied (because ignore_ppc == -1). This leads to the frequency QoS allowing all values from acpi perflib side. Once everything is initialized and then userspace brings a CPU down and up again, intel_pstate_init_acpi_perf_limits() calls acpi_processor_register_performance(), which then eventually calls acpi_processor_get_platform_limit(). There PPC is state 0, the turbo state, but the frequency has not been updated yet. So when acpi_processor_get_platform_limit() sets QoS constraints, it sets them with the max_non_turbo + 1 value. Now even though intel_pstate says it can support the full turbo speed, cpufreq only asks for up to max_non_turbo + 1 MHz since that is what satisfies all constraints. Call into acpi perflib's function to update the frequency so it can also update the QoS constraints with the new value. Signed-off-by: Pratyush Yadav --- drivers/cpufreq/intel_pstate.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c index fd73d6d2b808..b312f87ff522 100644 --- a/drivers/cpufreq/intel_pstate.c +++ b/drivers/cpufreq/intel_pstate.c @@ -464,8 +464,9 @@ static void intel_pstate_init_acpi_perf_limits(struct cpufreq_policy *policy) * Also need to convert to MHz as _PSS freq is in MHz. */ if (!global.turbo_disabled) - cpu->acpi_perf_data.states[0].core_frequency = - policy->cpuinfo.max_freq / 1000; + acpi_processor_fixup_perf_state(policy->cpu, 0, + policy->cpuinfo.max_freq / 1000); + cpu->valid_pss_table = true; pr_debug("_PPC limits will be enforced\n");