From patchwork Thu Sep 5 16:29:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13792680 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DFF3F1A0722; Thu, 5 Sep 2024 16:30:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553819; cv=none; b=b0Sj6OAB3LxJ5gZNafKyH+ns9+0Q7ic0nDhdVMQzJUuwNGW9Ien0sr82WFEa9t6uTszI8/sniYvsij7dqpI1U0B/jw4FuwlRCMSRGUE8rO36Q8Z+gg+TEKCTmta0jN23h5FXs0M9ZjY9XI+ylycVC6EDOqC6SVAt73UQWYiCEXY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553819; c=relaxed/simple; bh=rowiKubLUEKpsIMfOF/UJKXNOL/WqssxE3TBLP8jy5Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uHV3OTGgkERvY9M5gZKmgc1UlCW9hGPuYVWZfryuLuoZzVpWTV2k9+N92NF8Qf9USaLcIhhk+ct9us4/4pjzi/y65tnewXH8ZySWcefPbYHarIyI5oUxOO8K461jI+Ttbfwx6zskl5NtTpN2gv6P9Vsy3pDGqeaZ/cWk8KsWlgk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JZbC8adR; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="JZbC8adR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 88EABC4AF09; Thu, 5 Sep 2024 16:30:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725553818; bh=rowiKubLUEKpsIMfOF/UJKXNOL/WqssxE3TBLP8jy5Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JZbC8adRirAH8S6GArZD+fWf4Nz97gwlRtguq346tRcvRxq+v6tU6Bu4ilc0wpFM5 dDF61ulI08eDK00LaN1WaV+aWLO/yAUSaueb4xxhXMOSOUvPa53PFMxT3KW6jBaOWd r+kc0qY3ZO2rY22sZul66sanhJhwO/ZYHms5Pa60b4YP7tSFBOuMkkLeWgBG5Ns5YS oAAYbqopBA9OdGSThIXI5A90dXpE5HzFJPW6a3XdLx7Ka4HR06I89a/E3Z3FBYRqk6 6WGto8QuI0gr1RBV/pJwON5WdUd4b2D2xEL98vB0JpKkKoxhPluISSLGifGhiYOiKT R95Whdwni3Hvg== From: Mario Limonciello To: "Gautham R . Shenoy" , Perry Yuan Cc: Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "Rafael J . Wysocki" , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)), linux-acpi@vger.kernel.org (open list:ACPI), linux-pm@vger.kernel.org (open list:CPU FREQUENCY SCALING FRAMEWORK), Mario Limonciello Subject: [PATCH v3 01/11] x86/amd: Move amd_get_highest_perf() from amd.c to cppc.c Date: Thu, 5 Sep 2024 11:29:57 -0500 Message-ID: <20240905163007.1350840-2-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240905163007.1350840-1-superm1@kernel.org> References: <20240905163007.1350840-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello To prepare to let amd_get_highest_perf() detect preferred cores it will require CPPC functions. Move amd_get_highest_perf() to cppc.c to prepare for 'preferred core detection' rework. No functional changes intended. Reviewed-by: Perry Yuan Reviewed-by: Gautham R. Shenoy Signed-off-by: Mario Limonciello --- arch/x86/kernel/acpi/cppc.c | 16 ++++++++++++++++ arch/x86/kernel/cpu/amd.c | 16 ---------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/arch/x86/kernel/acpi/cppc.c b/arch/x86/kernel/acpi/cppc.c index ff8f25faca3dd..7ec8f2ce859c8 100644 --- a/arch/x86/kernel/acpi/cppc.c +++ b/arch/x86/kernel/acpi/cppc.c @@ -116,3 +116,19 @@ void init_freq_invariance_cppc(void) init_done = true; mutex_unlock(&freq_invariance_lock); } + +u32 amd_get_highest_perf(void) +{ + struct cpuinfo_x86 *c = &boot_cpu_data; + + if (c->x86 == 0x17 && ((c->x86_model >= 0x30 && c->x86_model < 0x40) || + (c->x86_model >= 0x70 && c->x86_model < 0x80))) + return 166; + + if (c->x86 == 0x19 && ((c->x86_model >= 0x20 && c->x86_model < 0x30) || + (c->x86_model >= 0x40 && c->x86_model < 0x70))) + return 166; + + return 255; +} +EXPORT_SYMBOL_GPL(amd_get_highest_perf); diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c index 1e0fe5f8ab84e..015971adadfc7 100644 --- a/arch/x86/kernel/cpu/amd.c +++ b/arch/x86/kernel/cpu/amd.c @@ -1190,22 +1190,6 @@ unsigned long amd_get_dr_addr_mask(unsigned int dr) } EXPORT_SYMBOL_GPL(amd_get_dr_addr_mask); -u32 amd_get_highest_perf(void) -{ - struct cpuinfo_x86 *c = &boot_cpu_data; - - if (c->x86 == 0x17 && ((c->x86_model >= 0x30 && c->x86_model < 0x40) || - (c->x86_model >= 0x70 && c->x86_model < 0x80))) - return 166; - - if (c->x86 == 0x19 && ((c->x86_model >= 0x20 && c->x86_model < 0x30) || - (c->x86_model >= 0x40 && c->x86_model < 0x70))) - return 166; - - return 255; -} -EXPORT_SYMBOL_GPL(amd_get_highest_perf); - static void zenbleed_check_cpu(void *unused) { struct cpuinfo_x86 *c = &cpu_data(smp_processor_id()); From patchwork Thu Sep 5 16:29:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13792681 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C9CF41A08B8; Thu, 5 Sep 2024 16:30:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553819; cv=none; b=IdndIHY89/cUzm0vKTHFjJ/jJsorS4vdauhwoG1vPu1UfDLvV3qdhrEXEK09Bo5VZMykrxGBQFP9s2n/VWl1M40XHK/XXFdplaXJsqhV3OY730RgbaWend2dDwun8jfPXPHVC1znRMbIJ3wM4SX69eUb4fJxTBfW9yG7PSNu2SU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553819; c=relaxed/simple; bh=ZAeOThCVIA/Hdzu0NXAoIn+TTinxpUo0rpgK3LbmGIE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DOhctowY2sH6CS2MVExpC8zsxA4gn+VMDX1WZ9F1xShDoHNzuXlLOlyjw5cR9Vu7J9HYW+shmNIAjMNxabXHoEeRf8e4pf1HZF3529eP9ei2zt6MAaqv8I0fQJI7dFrnQPHPAYoA64Q/NiD/R2q6u8TXIwkmD0d5FDnAkGE/quw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fiKBvbsH; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="fiKBvbsH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B5CCBC4CECA; Thu, 5 Sep 2024 16:30:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725553819; bh=ZAeOThCVIA/Hdzu0NXAoIn+TTinxpUo0rpgK3LbmGIE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fiKBvbsHvPtuPoqorYewNsdu9tW97uv9mpiJBViIE+5LELearMNhjMRhGHLWF7ZNH vleUPwo2AeGNfiG/RImGl8ECC7w30pINS/dkcD9I/S3gICk6pU7ohrYnMqv4IihviH HiLOGD+XXhcmndeBRtzh7mhmdBKTJ9qL7sa8dOJiW9ZXoIlmQrdlPR/UFa55f8naxJ FmkHfAakiYN3ILZdr+7GFR9R+GHPlcYdhPX0GqX481MnmOXntqa7Db2yDfuyMMVxId M07O2GSEp5Kaw0EVIi4x2MO6YJP+8dngMmJQwSxgxslCQPTz+8YJpItZO0PFeQS7GI Hd1ozyupkLJZQ== From: Mario Limonciello To: "Gautham R . Shenoy" , Perry Yuan Cc: Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "Rafael J . Wysocki" , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)), linux-acpi@vger.kernel.org (open list:ACPI), linux-pm@vger.kernel.org (open list:CPU FREQUENCY SCALING FRAMEWORK), Mario Limonciello Subject: [PATCH v3 02/11] ACPI: CPPC: Adjust return code for inline functions in !CONFIG_ACPI_CPPC_LIB Date: Thu, 5 Sep 2024 11:29:58 -0500 Message-ID: <20240905163007.1350840-3-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240905163007.1350840-1-superm1@kernel.org> References: <20240905163007.1350840-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello Checkpath emits the following warning: ``` WARNING: ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP ``` Adjust the code accordingly. Reviewed-by: Gautham R. Shenoy Signed-off-by: Mario Limonciello --- v2->v3: * Pick up tag --- include/acpi/cppc_acpi.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h index 930b6afba6f4d..409a7190a4a86 100644 --- a/include/acpi/cppc_acpi.h +++ b/include/acpi/cppc_acpi.h @@ -162,31 +162,31 @@ extern int cppc_set_auto_sel(int cpu, bool enable); #else /* !CONFIG_ACPI_CPPC_LIB */ static inline int cppc_get_desired_perf(int cpunum, u64 *desired_perf) { - return -ENOTSUPP; + return -EOPNOTSUPP; } static inline int cppc_get_nominal_perf(int cpunum, u64 *nominal_perf) { - return -ENOTSUPP; + return -EOPNOTSUPP; } static inline int cppc_get_highest_perf(int cpunum, u64 *highest_perf) { - return -ENOTSUPP; + return -EOPNOTSUPP; } static inline int cppc_get_perf_ctrs(int cpu, struct cppc_perf_fb_ctrs *perf_fb_ctrs) { - return -ENOTSUPP; + return -EOPNOTSUPP; } static inline int cppc_set_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls) { - return -ENOTSUPP; + return -EOPNOTSUPP; } static inline int cppc_set_enable(int cpu, bool enable) { - return -ENOTSUPP; + return -EOPNOTSUPP; } static inline int cppc_get_perf_caps(int cpu, struct cppc_perf_caps *caps) { - return -ENOTSUPP; + return -EOPNOTSUPP; } static inline bool cppc_perf_ctrs_in_pcc(void) { @@ -210,27 +210,27 @@ static inline bool cpc_ffh_supported(void) } static inline int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val) { - return -ENOTSUPP; + return -EOPNOTSUPP; } static inline int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val) { - return -ENOTSUPP; + return -EOPNOTSUPP; } static inline int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable) { - return -ENOTSUPP; + return -EOPNOTSUPP; } static inline int cppc_get_epp_perf(int cpunum, u64 *epp_perf) { - return -ENOTSUPP; + return -EOPNOTSUPP; } static inline int cppc_set_auto_sel(int cpu, bool enable) { - return -ENOTSUPP; + return -EOPNOTSUPP; } static inline int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf_caps) { - return -ENOTSUPP; + return -EOPNOTSUPP; } #endif /* !CONFIG_ACPI_CPPC_LIB */ From patchwork Thu Sep 5 16:29:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13792682 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 064BA1A0BE1; Thu, 5 Sep 2024 16:30:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553821; cv=none; b=YcuwSA7XVSfKkvNYoHj1j8JxfXVw+933di+UJqad0Cg591tYJjO3e3ogEe6U9jwNROfHFZgBx1AI6caWBEoTyUik9v68hx2VzqeUj6W11n77aPk8DuOJqT/+UIEnLBGqOjIRHGHlBnR2P6dlswiWenozmFn8Sa99Lqxc4D+uFvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553821; c=relaxed/simple; bh=0BgiaAI++xtqM2cTIwFfJh8E4/FpbNamTJUW/AokoLU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g0zVoVW+T7xSkJtoGqiHiWMbGYp5mrscTK0G8uAbP61f8qrqGSWywRc18LpN06TcNQPAXx810mVWmshC1CajcXuHooH1S6rEAzyVwi+/Msb4yHs0sozCMGQCtex0w4OBXbjp+r7A2bp2tdU/JdJoRTjc7ZtNX8Fx96qZvzI0fxY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eMZuAHTv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eMZuAHTv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9113C4CECD; Thu, 5 Sep 2024 16:30:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725553820; bh=0BgiaAI++xtqM2cTIwFfJh8E4/FpbNamTJUW/AokoLU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eMZuAHTvYuGNsBgCA3jH8P2nK1mGf84b5xn8n1cwQxW3uQn/RoqE4KZW4RF5PdoHX +H419g+Mjidh8pRmCc9p8B2/qmA/iajaVs4AT6J7ehvIvwpgPQtHlWWSJWpTS3RJtk 6RQt9vageAYCWU6LyWm8bv/UwyvKjgxeQbO7+6hX0AxNUiGVydWQmhOxejamCyJ+/x v75gNX/L1TF1+NKXGLslNnRYDWIqF8CvT/mbeDg2ZmZqY1dnw/f+ckMh+EazqwUQxq svjtIR/c6hVgXhQdi/yUtgS1QGSpKUADdV16+GxTAZNyURP00s9ahfq/uD6/XZkQBU gBlIDquzS48eQ== From: Mario Limonciello To: "Gautham R . Shenoy" , Perry Yuan Cc: Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "Rafael J . Wysocki" , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)), linux-acpi@vger.kernel.org (open list:ACPI), linux-pm@vger.kernel.org (open list:CPU FREQUENCY SCALING FRAMEWORK), Mario Limonciello Subject: [PATCH v3 03/11] x86/amd: Rename amd_get_highest_perf() to amd_get_boost_ratio_numerator() Date: Thu, 5 Sep 2024 11:29:59 -0500 Message-ID: <20240905163007.1350840-4-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240905163007.1350840-1-superm1@kernel.org> References: <20240905163007.1350840-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello The function name is ambiguous because it returns an intermediate value for calculating maximum frequency rather than the CPPC 'Highest Perf' register. Rename the function to clarify its use and allow the function to return errors. Adjust the consumer in acpi-cpufreq to catch errors. Reviewed-by: Gautham R. Shenoy Signed-off-by: Mario Limonciello --- v1->v2: * Rename variable from `highest_perf` to `numerator` * Fail when unable to return boost numerator * Move prototype behind CONFIG_ACPI_CPPC_LIB (lkp robot) v2->v3: * Pick up tag --- arch/x86/include/asm/processor.h | 3 --- arch/x86/kernel/acpi/cppc.c | 44 +++++++++++++++++++++++--------- drivers/cpufreq/acpi-cpufreq.c | 12 ++++++--- include/acpi/cppc_acpi.h | 5 ++++ 4 files changed, 46 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h index a75a07f4931fd..775acbdea1a96 100644 --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -691,8 +691,6 @@ static inline u32 per_cpu_l2c_id(unsigned int cpu) } #ifdef CONFIG_CPU_SUP_AMD -extern u32 amd_get_highest_perf(void); - /* * Issue a DIV 0/1 insn to clear any division data from previous DIV * operations. @@ -705,7 +703,6 @@ static __always_inline void amd_clear_divider(void) extern void amd_check_microcode(void); #else -static inline u32 amd_get_highest_perf(void) { return 0; } static inline void amd_clear_divider(void) { } static inline void amd_check_microcode(void) { } #endif diff --git a/arch/x86/kernel/acpi/cppc.c b/arch/x86/kernel/acpi/cppc.c index 7ec8f2ce859c8..660cfeb6384ba 100644 --- a/arch/x86/kernel/acpi/cppc.c +++ b/arch/x86/kernel/acpi/cppc.c @@ -69,7 +69,7 @@ int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val) static void amd_set_max_freq_ratio(void) { struct cppc_perf_caps perf_caps; - u64 highest_perf, nominal_perf; + u64 numerator, nominal_perf; u64 perf_ratio; int rc; @@ -79,15 +79,19 @@ static void amd_set_max_freq_ratio(void) return; } - highest_perf = amd_get_highest_perf(); + rc = amd_get_boost_ratio_numerator(0, &numerator); + if (rc) { + pr_debug("Could not retrieve highest performance (%d)\n", rc); + return; + } nominal_perf = perf_caps.nominal_perf; - if (!highest_perf || !nominal_perf) { - pr_debug("Could not retrieve highest or nominal performance\n"); + if (!nominal_perf) { + pr_debug("Could not retrieve nominal performance\n"); return; } - perf_ratio = div_u64(highest_perf * SCHED_CAPACITY_SCALE, nominal_perf); + perf_ratio = div_u64(numerator * SCHED_CAPACITY_SCALE, nominal_perf); /* midpoint between max_boost and max_P */ perf_ratio = (perf_ratio + SCHED_CAPACITY_SCALE) >> 1; if (!perf_ratio) { @@ -117,18 +121,34 @@ void init_freq_invariance_cppc(void) mutex_unlock(&freq_invariance_lock); } -u32 amd_get_highest_perf(void) +/** + * amd_get_boost_ratio_numerator: Get the numerator to use for boost ratio calculation + * @cpu: CPU to get numerator for. + * @numerator: Output variable for numerator. + * + * Determine the numerator to use for calculating the boost ratio on + * a CPU. On systems that support preferred cores, this will be a hardcoded + * value. On other systems this will the highest performance register value. + * + * Return: 0 for success, negative error code otherwise. + */ +int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator) { struct cpuinfo_x86 *c = &boot_cpu_data; if (c->x86 == 0x17 && ((c->x86_model >= 0x30 && c->x86_model < 0x40) || - (c->x86_model >= 0x70 && c->x86_model < 0x80))) - return 166; + (c->x86_model >= 0x70 && c->x86_model < 0x80))) { + *numerator = 166; + return 0; + } if (c->x86 == 0x19 && ((c->x86_model >= 0x20 && c->x86_model < 0x30) || - (c->x86_model >= 0x40 && c->x86_model < 0x70))) - return 166; + (c->x86_model >= 0x40 && c->x86_model < 0x70))) { + *numerator = 166; + return 0; + } + *numerator = 255; - return 255; + return 0; } -EXPORT_SYMBOL_GPL(amd_get_highest_perf); +EXPORT_SYMBOL_GPL(amd_get_boost_ratio_numerator); diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c index a8ca625a98b89..0f04feb6cafaf 100644 --- a/drivers/cpufreq/acpi-cpufreq.c +++ b/drivers/cpufreq/acpi-cpufreq.c @@ -642,10 +642,16 @@ static u64 get_max_boost_ratio(unsigned int cpu) return 0; } - if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) - highest_perf = amd_get_highest_perf(); - else + if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) { + ret = amd_get_boost_ratio_numerator(cpu, &highest_perf); + if (ret) { + pr_debug("CPU%d: Unable to get boost ratio numerator (%d)\n", + cpu, ret); + return 0; + } + } else { highest_perf = perf_caps.highest_perf; + } nominal_perf = perf_caps.nominal_perf; diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h index 409a7190a4a86..97861abc5f5b8 100644 --- a/include/acpi/cppc_acpi.h +++ b/include/acpi/cppc_acpi.h @@ -159,6 +159,7 @@ extern int cppc_get_epp_perf(int cpunum, u64 *epp_perf); extern int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable); extern int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf_caps); extern int cppc_set_auto_sel(int cpu, bool enable); +extern int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator); #else /* !CONFIG_ACPI_CPPC_LIB */ static inline int cppc_get_desired_perf(int cpunum, u64 *desired_perf) { @@ -232,6 +233,10 @@ static inline int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf { return -EOPNOTSUPP; } +static inline int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator) +{ + return -EOPNOTSUPP; +} #endif /* !CONFIG_ACPI_CPPC_LIB */ #endif /* _CPPC_ACPI_H*/ From patchwork Thu Sep 5 16:30:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13792683 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C7A51A2C14; Thu, 5 Sep 2024 16:30:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553822; cv=none; b=t/n8WvELJhViCkOjdsmTBYKdpwoKBR90hsMQImff0BdUr5rPjFLs+KdTe4dJL955LHfBqk/ZHyCo4U7r0YAlv7rqXPDQXM2ruS00gG5e+JR8QeGaEB6OstdX8Zho1+uf5eJ9i+uhrnpZd45VymkbyKx4YJ3ga6UO+AhYhUAWmAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553822; c=relaxed/simple; bh=Zt3i+cvHegpXXitpCTq/1E918OQsdv+WUjbGkfVqzaY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XP7BtSOjwC3/OXE1lTRWEFTvjd2bqD7JWH4szUpwqeM3BI5HhHCIycJVT9NcChNecvxmQZp61E5bf/+7X3ExDLQyTaZnSLIvv4eK9xSlIii9LTdJNYZZGn6An6oDWDXlEaeBiJleBHUF4kmdBodbOFwu6WXJb8ItQS3UAQGdFqI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MOBw9jGW; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MOBw9jGW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 290D7C4CEC3; Thu, 5 Sep 2024 16:30:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725553822; bh=Zt3i+cvHegpXXitpCTq/1E918OQsdv+WUjbGkfVqzaY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MOBw9jGWBy6zH4mf7er170DBKItNU2UaaG4P/92GcBFXTjwYd70aDDdHQ+CcFgFUF k6SifQsr9Y/BmL+dV2e02RXQnCHzxkt0KHKJ8UmbhtrcIM23KWtANvbc6v4kunvuge RSy7uiJI+sfZ9dntVp5xjpncb1XvfQzJGQH2KaMf/y42Mdi+reQSF4G6wm2V0Mctwj H+VAsAHF+12/bQLQm++BylRbk8zdTiNG+rQeVzO2pxZrNG2eY2i9V/7RI2u1A5NXVe eqilM77OgaCD+XuUJKdT4tHdzuNVMc/JtsQwRG53YuS1q5lqi7CBr473l4kRDwH9al E6b3vcWhar2XQ== From: Mario Limonciello To: "Gautham R . Shenoy" , Perry Yuan Cc: Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "Rafael J . Wysocki" , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)), linux-acpi@vger.kernel.org (open list:ACPI), linux-pm@vger.kernel.org (open list:CPU FREQUENCY SCALING FRAMEWORK), Mario Limonciello , "Gautham R . Shenoy" Subject: [PATCH v3 04/11] ACPI: CPPC: Drop check for non zero perf ratio Date: Thu, 5 Sep 2024 11:30:00 -0500 Message-ID: <20240905163007.1350840-5-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240905163007.1350840-1-superm1@kernel.org> References: <20240905163007.1350840-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello perf_ratio is a u64 and SCHED_CAPACITY_SCALE is a large number. Shifting by one will never have a zero value. Drop the check. Suggested-by: Gautham R. Shenoy Reviewed-by: Gautham R. Shenoy Signed-off-by: Mario Limonciello --- v2->v3: * Correct typo in commit message * Pick up tag --- arch/x86/kernel/acpi/cppc.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/arch/x86/kernel/acpi/cppc.c b/arch/x86/kernel/acpi/cppc.c index 660cfeb6384ba..e65c77afab318 100644 --- a/arch/x86/kernel/acpi/cppc.c +++ b/arch/x86/kernel/acpi/cppc.c @@ -91,13 +91,8 @@ static void amd_set_max_freq_ratio(void) return; } - perf_ratio = div_u64(numerator * SCHED_CAPACITY_SCALE, nominal_perf); /* midpoint between max_boost and max_P */ - perf_ratio = (perf_ratio + SCHED_CAPACITY_SCALE) >> 1; - if (!perf_ratio) { - pr_debug("Non-zero highest/nominal perf values led to a 0 ratio\n"); - return; - } + perf_ratio = (div_u64(numerator * SCHED_CAPACITY_SCALE, nominal_perf) + SCHED_CAPACITY_SCALE) >> 1; freq_invariance_set_perf_ratio(perf_ratio, false); } From patchwork Thu Sep 5 16:30:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13792685 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C94091A3A9D; Thu, 5 Sep 2024 16:30:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553824; cv=none; b=KBDcHfcx9CmNb6fVgh9LPRHM2VkkMw5Lptg+3hmHGS5mCjE93FSOMFXnNCa09BnO4TKIxJd4J7hWPEATNEBkLdZ4+4PijmXcoSXLfaaCepDkrwn8lU+eZfi4TfJMQ3PkSAw/6WEPjBwIeQcpit2+H6Xzm+ExWmDLkCbk9dvbLIw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553824; c=relaxed/simple; bh=SN+VV989YznpmWRMUK1wgF+lwg7k+mPg1elKKPJ0iac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OKCZ8+H58YEVwLzWw/1U8hSf7i6NWo4M6Vzqw+Y0Q3/9bl6XLn5YXlGQKh+2nKimX0oRJIMWf+GvOVnuPYhbrehTGs/wFP3Hw/nXfhnyZgxowenjizWxruMuK20xDmCCQR2aEz4g4eyGmFGYWqH8ej3MsXyqH5PSelFIfuPnqDQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=seQyZai6; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="seQyZai6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6A097C4CEC7; Thu, 5 Sep 2024 16:30:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725553823; bh=SN+VV989YznpmWRMUK1wgF+lwg7k+mPg1elKKPJ0iac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=seQyZai6qK17Jl2DWBqYRgCEG2VfAd8WrVIrexs3RGg4djkF70sVPEPM2UATuUBle PkOuT/q4J3MgRNOHNHjaXw4ilhegmFoR9haxV2BTx6vRJk7rqoZUPbZvnYtAwVR0Nw LVbPU4wKGIT9tq+QJGZ4XLvhwffQzxLFWTilqSp6TW5CIpO/oQQUYFEt++HZDSDqO1 Z8hg/0Fg6RWw5ucM5dO+8jU0qoIzm9hSGie2y8WfQeBxR7iTo7K828XQUTcDkzfdMy wIzsgYLYc+NeTWmSUU9R8NyVTymfZJ7wV0R5dgvKUOAnbLxkRaboasTpcLjmrAMbGs C2wtGdkD9FMCw== From: Mario Limonciello To: "Gautham R . Shenoy" , Perry Yuan Cc: Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "Rafael J . Wysocki" , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)), linux-acpi@vger.kernel.org (open list:ACPI), linux-pm@vger.kernel.org (open list:CPU FREQUENCY SCALING FRAMEWORK), Mario Limonciello , Perry Yuan Subject: [PATCH v3 05/11] ACPI: CPPC: Adjust debug messages in amd_set_max_freq_ratio() to warn Date: Thu, 5 Sep 2024 11:30:01 -0500 Message-ID: <20240905163007.1350840-6-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240905163007.1350840-1-superm1@kernel.org> References: <20240905163007.1350840-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello If the boost ratio isn't calculated properly for the system for any reason this can cause other problems that are non-obvious. Raise all messages to warn instead. Suggested-by: Perry Yuan Reviewed-by: Perry Yuan Reviewed-by: Gautham R. Shenoy Signed-off-by: Mario Limonciello --- arch/x86/kernel/acpi/cppc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/acpi/cppc.c b/arch/x86/kernel/acpi/cppc.c index e65c77afab318..f0328ce98a8fe 100644 --- a/arch/x86/kernel/acpi/cppc.c +++ b/arch/x86/kernel/acpi/cppc.c @@ -75,19 +75,19 @@ static void amd_set_max_freq_ratio(void) rc = cppc_get_perf_caps(0, &perf_caps); if (rc) { - pr_debug("Could not retrieve perf counters (%d)\n", rc); + pr_warn("Could not retrieve perf counters (%d)\n", rc); return; } rc = amd_get_boost_ratio_numerator(0, &numerator); if (rc) { - pr_debug("Could not retrieve highest performance (%d)\n", rc); + pr_warn("Could not retrieve highest performance (%d)\n", rc); return; } nominal_perf = perf_caps.nominal_perf; if (!nominal_perf) { - pr_debug("Could not retrieve nominal performance\n"); + pr_warn("Could not retrieve nominal performance\n"); return; } From patchwork Thu Sep 5 16:30:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13792684 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1FEB1A3A8D; Thu, 5 Sep 2024 16:30:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553824; cv=none; b=njhqqYq7Ps4YjQbG1PLIA7tRKyq/Nfe4ffeqiZuH415+Bhnf1ot33TE6ugJxN8T3y+8TdNnmB8J9AETpavYs6ohCqO1CVUBl06ThABBVyEi6lHdtqEiTG2aR+/1sMGI+HLMYJQbH57twAb06PXJfKcB1fSK3kzLW8KWa1bOOt0E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553824; c=relaxed/simple; bh=72h3WUChhX1/hxEuoU38xiisjOiAcozzY3/6ch+SP44=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Z6RnCQkG4bPvUiXoBK47f1yh6PQQ7GR4vI3D52ZRpY0EF8nh/B+zWKEtgsTWMymQZeOBs03AaXI2yBaPDgnVIVGs750DDblGGaet+4CY00CRlmAuyzh4szpSKM+jAaUctYJcpaQC2kBTfKU3FLQPc+C56r/JMrluukBLUE+UwrY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GrK4Btdr; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GrK4Btdr" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8415C4CEC9; Thu, 5 Sep 2024 16:30:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725553824; bh=72h3WUChhX1/hxEuoU38xiisjOiAcozzY3/6ch+SP44=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GrK4Btdr3Gz5dDZocPPsQDBXG4O6zCJlzte2KuppFv5SsdGsYdl9ZrC3YsNOPlU+5 yYy4KaahwCre6CVPpIwHgPaYzby1AQ0JtL2PSGvVQX7Tm1SOAoq8blzQqOSYGyeSjH yR0RfWcuvj/kEE/CD0wdjg5syBfAao4gSTAnjY974Rs080dHFdk77GxlifhHVoHf2U iv6qS/5lpYVY5Ii4MZHjk8J5Xkqnklo4KNJjee8VbgrUXhyOZhcfSdZzBkFeuQKxmt k0sQLvkFWumvyrnSMi0lUrT7UF3B2BNqGbyMMQluKrzaPzrnjbA3IDsOgFDOMGGbzI Wa4YI+oKFhpVQ== From: Mario Limonciello To: "Gautham R . Shenoy" , Perry Yuan Cc: Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "Rafael J . Wysocki" , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)), linux-acpi@vger.kernel.org (open list:ACPI), linux-pm@vger.kernel.org (open list:CPU FREQUENCY SCALING FRAMEWORK), Mario Limonciello Subject: [PATCH v3 06/11] x86/amd: Move amd_get_highest_perf() out of amd-pstate Date: Thu, 5 Sep 2024 11:30:02 -0500 Message-ID: <20240905163007.1350840-7-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240905163007.1350840-1-superm1@kernel.org> References: <20240905163007.1350840-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello amd_pstate_get_highest_perf() is a helper used to get the highest perf value on AMD systems. It's used in amd-pstate as part of preferred core handling, but applicable for acpi-cpufreq as well. Move it out to cppc handling code as amd_get_highest_perf(). Reviewed-by: Perry Yuan Reviewed-by: Gautham R. Shenoy Signed-off-by: Mario Limonciello --- v1->v2: * Update commit message (Gautham) --- arch/x86/kernel/acpi/cppc.c | 30 ++++++++++++++++++++++++++++++ drivers/cpufreq/amd-pstate.c | 34 ++-------------------------------- include/acpi/cppc_acpi.h | 5 +++++ 3 files changed, 37 insertions(+), 32 deletions(-) diff --git a/arch/x86/kernel/acpi/cppc.c b/arch/x86/kernel/acpi/cppc.c index f0328ce98a8fe..a75dcb382c786 100644 --- a/arch/x86/kernel/acpi/cppc.c +++ b/arch/x86/kernel/acpi/cppc.c @@ -116,6 +116,36 @@ void init_freq_invariance_cppc(void) mutex_unlock(&freq_invariance_lock); } +/* + * Get the highest performance register value. + * @cpu: CPU from which to get highest performance. + * @highest_perf: Return address for highest performance value. + * + * Return: 0 for success, negative error code otherwise. + */ +int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf) +{ + u64 val; + int ret; + + if (cpu_feature_enabled(X86_FEATURE_CPPC)) { + ret = rdmsrl_safe_on_cpu(cpu, MSR_AMD_CPPC_CAP1, &val); + if (ret) + goto out; + + val = AMD_CPPC_HIGHEST_PERF(val); + } else { + ret = cppc_get_highest_perf(cpu, &val); + if (ret) + goto out; + } + + WRITE_ONCE(*highest_perf, (u32)val); +out: + return ret; +} +EXPORT_SYMBOL_GPL(amd_get_highest_perf); + /** * amd_get_boost_ratio_numerator: Get the numerator to use for boost ratio calculation * @cpu: CPU to get numerator for. diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index db4f747f128f1..44df6ef66b5fa 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -803,36 +803,6 @@ static void amd_pstste_sched_prefcore_workfn(struct work_struct *work) } static DECLARE_WORK(sched_prefcore_work, amd_pstste_sched_prefcore_workfn); -/* - * Get the highest performance register value. - * @cpu: CPU from which to get highest performance. - * @highest_perf: Return address. - * - * Return: 0 for success, -EIO otherwise. - */ -static int amd_pstate_get_highest_perf(int cpu, u32 *highest_perf) -{ - int ret; - - if (cpu_feature_enabled(X86_FEATURE_CPPC)) { - u64 cap1; - - ret = rdmsrl_safe_on_cpu(cpu, MSR_AMD_CPPC_CAP1, &cap1); - if (ret) - return ret; - WRITE_ONCE(*highest_perf, AMD_CPPC_HIGHEST_PERF(cap1)); - } else { - u64 cppc_highest_perf; - - ret = cppc_get_highest_perf(cpu, &cppc_highest_perf); - if (ret) - return ret; - WRITE_ONCE(*highest_perf, cppc_highest_perf); - } - - return (ret); -} - #define CPPC_MAX_PERF U8_MAX static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) @@ -840,7 +810,7 @@ static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) int ret, prio; u32 highest_perf; - ret = amd_pstate_get_highest_perf(cpudata->cpu, &highest_perf); + ret = amd_get_highest_perf(cpudata->cpu, &highest_perf); if (ret) return; @@ -879,7 +849,7 @@ static void amd_pstate_update_limits(unsigned int cpu) if ((!amd_pstate_prefcore) || (!cpudata->hw_prefcore)) goto free_cpufreq_put; - ret = amd_pstate_get_highest_perf(cpu, &cur_high); + ret = amd_get_highest_perf(cpu, &cur_high); if (ret) goto free_cpufreq_put; diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h index 97861abc5f5b8..f7c7abf2a95e9 100644 --- a/include/acpi/cppc_acpi.h +++ b/include/acpi/cppc_acpi.h @@ -159,6 +159,7 @@ extern int cppc_get_epp_perf(int cpunum, u64 *epp_perf); extern int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable); extern int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf_caps); extern int cppc_set_auto_sel(int cpu, bool enable); +extern int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf); extern int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator); #else /* !CONFIG_ACPI_CPPC_LIB */ static inline int cppc_get_desired_perf(int cpunum, u64 *desired_perf) @@ -233,6 +234,10 @@ static inline int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf { return -EOPNOTSUPP; } +static inline int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf) +{ + return -ENODEV; +} static inline int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator) { return -EOPNOTSUPP; From patchwork Thu Sep 5 16:30:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13792686 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 500CC1A7263; Thu, 5 Sep 2024 16:30:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553827; cv=none; b=ct9+hUXtjBlGI/7DAGestfc8XWBqqoqgxgDhiIIV4E1Te2DtfUgGc/kWn8AK301WeacdN0I/XDK0x4GdJ2CvINQvlU7Fcfq8m4N5oA+0rm51XzRysUK2lbsPffbFshhALLaQ/5Xh4JyoYcITGiHAcaspOPe4aiuWp+meDGesuDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553827; c=relaxed/simple; bh=V8++tM5kfE+fBeAJooozN2LS1B3Q+HgamDt7vl/R7Fc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e57lx46kII26oqA59RVtwlYvO8r8DoHVgnW1EstP0jR9qsBt3r/TehXhWimrW7ncpzM9RF0zVv+XZlfAwaHLX/e/y8g0mqofJODW4l+JgMbC4+0LuCNdYsSPjPOP+whLz+O5J941jSE/tXFLvc+tCStyIY/t9LUuvDWpI3M1LBg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HfqHPmHV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HfqHPmHV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D591EC4CEC3; Thu, 5 Sep 2024 16:30:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725553825; bh=V8++tM5kfE+fBeAJooozN2LS1B3Q+HgamDt7vl/R7Fc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HfqHPmHV9NQpjPhuiB+NbqqWFdD2tw0fwgJU9oNAkUN1iK6mnuomf4DD8qWblzAl/ DHyK7DnOiwSEDqCO5lto/RFpzcDmgpPAvCtWj/A6llNmeUv8sgV97iUTjaMUwrRwSY FMJ2pVrT/qlrCamkMsam74jKWB7wfD/h0V4wUos4RCkJp23qQjBmMZ8SxHPIrad+zl OSYdmTEST8veAJJpjAtc7ZePmjQcuBsN274nFwifNgsIRMaltQKzI/ejss5Hqx1gLW lx6cXIgm182zqNi20wdV6aiFoY1lInQs7SMjfNItagFUMxIjSkX2KairNw6pzcweMo miTQcUW8qS7/A== From: Mario Limonciello To: "Gautham R . Shenoy" , Perry Yuan Cc: Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "Rafael J . Wysocki" , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)), linux-acpi@vger.kernel.org (open list:ACPI), linux-pm@vger.kernel.org (open list:CPU FREQUENCY SCALING FRAMEWORK), Mario Limonciello Subject: [PATCH v3 07/11] x86/amd: Detect preferred cores in amd_get_boost_ratio_numerator() Date: Thu, 5 Sep 2024 11:30:03 -0500 Message-ID: <20240905163007.1350840-8-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240905163007.1350840-1-superm1@kernel.org> References: <20240905163007.1350840-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello AMD systems that support preferred cores will use "166" as their numerator for max frequency calculations instead of "255". Add a function for detecting preferred cores by looking at the highest perf value on all cores. If preferred cores are enabled return 166 and if disabled the value in the highest perf register. As the function will be called multiple times, cache the values for the boost numerator and if preferred cores will be enabled in global variables. Reviewed-by: Gautham R. Shenoy Signed-off-by: Mario Limonciello --- v1->v2: * Add a comment into amd_get_boost_ratio_numerator() as well v2->v3: * Fix kernel robot error --- arch/x86/kernel/acpi/cppc.c | 93 ++++++++++++++++++++++++++++++++---- drivers/cpufreq/amd-pstate.c | 34 +++++-------- include/acpi/cppc_acpi.h | 5 ++ 3 files changed, 101 insertions(+), 31 deletions(-) diff --git a/arch/x86/kernel/acpi/cppc.c b/arch/x86/kernel/acpi/cppc.c index a75dcb382c786..df367bc359308 100644 --- a/arch/x86/kernel/acpi/cppc.c +++ b/arch/x86/kernel/acpi/cppc.c @@ -9,6 +9,16 @@ #include #include +#define CPPC_HIGHEST_PERF_PREFCORE 166 + +enum amd_pref_core { + AMD_PREF_CORE_UNKNOWN = 0, + AMD_PREF_CORE_SUPPORTED, + AMD_PREF_CORE_UNSUPPORTED, +}; +static enum amd_pref_core amd_pref_core_detected; +static u64 boost_numerator; + /* Refer to drivers/acpi/cppc_acpi.c for the description of functions */ bool cpc_supported_by_cpu(void) @@ -146,6 +156,66 @@ int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf) } EXPORT_SYMBOL_GPL(amd_get_highest_perf); +/** + * amd_detect_prefcore: Detect if CPUs in the system support preferred cores + * @detected: Output variable for the result of the detection. + * + * Determine whether CPUs in the system support preferred cores. On systems + * that support preferred cores, different highest perf values will be found + * on different cores. On other systems, the highest perf value will be the + * same on all cores. + * + * The result of the detection will be stored in the 'detected' parameter. + * + * Return: 0 for success, negative error code otherwise + */ +int amd_detect_prefcore(bool *detected) +{ + int cpu, count = 0; + u64 highest_perf[2] = {0}; + + if (WARN_ON(!detected)) + return -EINVAL; + + switch (amd_pref_core_detected) { + case AMD_PREF_CORE_SUPPORTED: + *detected = true; + return 0; + case AMD_PREF_CORE_UNSUPPORTED: + *detected = false; + return 0; + default: + break; + } + + for_each_present_cpu(cpu) { + u32 tmp; + int ret; + + ret = amd_get_highest_perf(cpu, &tmp); + if (ret) + return ret; + + if (!count || (count == 1 && tmp != highest_perf[0])) + highest_perf[count++] = tmp; + + if (count == 2) + break; + } + + *detected = (count == 2); + boost_numerator = highest_perf[0]; + + amd_pref_core_detected = *detected ? AMD_PREF_CORE_SUPPORTED : + AMD_PREF_CORE_UNSUPPORTED; + + pr_debug("AMD CPPC preferred core is %ssupported (highest perf: 0x%llx)\n", + *detected ? "" : "un", highest_perf[0]); + + return 0; +} +EXPORT_SYMBOL_GPL(amd_detect_prefcore); + /** * amd_get_boost_ratio_numerator: Get the numerator to use for boost ratio calculation * @cpu: CPU to get numerator for. @@ -155,24 +225,27 @@ EXPORT_SYMBOL_GPL(amd_get_highest_perf); * a CPU. On systems that support preferred cores, this will be a hardcoded * value. On other systems this will the highest performance register value. * + * If booting the system with amd-pstate enabled but preferred cores disabled then + * the correct boost numerator will be returned to match hardware capabilities + * even if the preferred cores scheduling hints are not enabled. + * * Return: 0 for success, negative error code otherwise. */ int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator) { - struct cpuinfo_x86 *c = &boot_cpu_data; + bool prefcore; + int ret; - if (c->x86 == 0x17 && ((c->x86_model >= 0x30 && c->x86_model < 0x40) || - (c->x86_model >= 0x70 && c->x86_model < 0x80))) { - *numerator = 166; - return 0; - } + ret = amd_detect_prefcore(&prefcore); + if (ret) + return ret; - if (c->x86 == 0x19 && ((c->x86_model >= 0x20 && c->x86_model < 0x30) || - (c->x86_model >= 0x40 && c->x86_model < 0x70))) { - *numerator = 166; + /* without preferred cores, return the highest perf register value */ + if (!prefcore) { + *numerator = boost_numerator; return 0; } - *numerator = 255; + *numerator = CPPC_HIGHEST_PERF_PREFCORE; return 0; } diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 44df6ef66b5fa..c29cdf2d3882c 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -807,32 +807,18 @@ static DECLARE_WORK(sched_prefcore_work, amd_pstste_sched_prefcore_workfn); static void amd_pstate_init_prefcore(struct amd_cpudata *cpudata) { - int ret, prio; - u32 highest_perf; - - ret = amd_get_highest_perf(cpudata->cpu, &highest_perf); - if (ret) + /* user disabled or not detected */ + if (!amd_pstate_prefcore) return; cpudata->hw_prefcore = true; - /* check if CPPC preferred core feature is enabled*/ - if (highest_perf < CPPC_MAX_PERF) - prio = (int)highest_perf; - else { - pr_debug("AMD CPPC preferred core is unsupported!\n"); - cpudata->hw_prefcore = false; - return; - } - - if (!amd_pstate_prefcore) - return; /* * The priorities can be set regardless of whether or not * sched_set_itmt_support(true) has been called and it is valid to * update them at any time after it has been called. */ - sched_set_itmt_core_prio(prio, cpudata->cpu); + sched_set_itmt_core_prio((int)READ_ONCE(cpudata->highest_perf), cpudata->cpu); schedule_work(&sched_prefcore_work); } @@ -998,12 +984,12 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy) cpudata->cpu = policy->cpu; - amd_pstate_init_prefcore(cpudata); - ret = amd_pstate_init_perf(cpudata); if (ret) goto free_cpudata1; + amd_pstate_init_prefcore(cpudata); + ret = amd_pstate_init_freq(cpudata); if (ret) goto free_cpudata1; @@ -1453,12 +1439,12 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) cpudata->cpu = policy->cpu; cpudata->epp_policy = 0; - amd_pstate_init_prefcore(cpudata); - ret = amd_pstate_init_perf(cpudata); if (ret) goto free_cpudata1; + amd_pstate_init_prefcore(cpudata); + ret = amd_pstate_init_freq(cpudata); if (ret) goto free_cpudata1; @@ -1920,6 +1906,12 @@ static int __init amd_pstate_init(void) static_call_update(amd_pstate_update_perf, cppc_update_perf); } + if (amd_pstate_prefcore) { + ret = amd_detect_prefcore(&amd_pstate_prefcore); + if (ret) + return ret; + } + /* enable amd pstate feature */ ret = amd_pstate_enable(true); if (ret) { diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h index f7c7abf2a95e9..482e0587a0413 100644 --- a/include/acpi/cppc_acpi.h +++ b/include/acpi/cppc_acpi.h @@ -161,6 +161,7 @@ extern int cppc_get_auto_sel_caps(int cpunum, struct cppc_perf_caps *perf_caps); extern int cppc_set_auto_sel(int cpu, bool enable); extern int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf); extern int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator); +extern int amd_detect_prefcore(bool *detected); #else /* !CONFIG_ACPI_CPPC_LIB */ static inline int cppc_get_desired_perf(int cpunum, u64 *desired_perf) { @@ -242,6 +243,10 @@ static inline int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator { return -EOPNOTSUPP; } +static inline int amd_detect_prefcore(bool *detected) +{ + return -ENODEV; +} #endif /* !CONFIG_ACPI_CPPC_LIB */ #endif /* _CPPC_ACPI_H*/ From patchwork Thu Sep 5 16:30:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13792687 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E3A31A7267; Thu, 5 Sep 2024 16:30:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553827; cv=none; b=SBW2PoQTI253MHvkYp23M2I5KLY2aToB7KobS+m4n73e8cMr6uYRHOP5r7bDqBPGIOTSiLzfgjOr6to6ze4jv06Hdl/3Qu6P0tfrZfodsyB/uz2OWcJ54bLe8DBLa9tVBsTVdotprjbVCrj55MKkWjHV7CI/PugN/PetjD+rfp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553827; c=relaxed/simple; bh=Y54jxoqOwq9hafYzm3zMRq3v1cZWWr87gVCbSOuKlsI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l+9s9UO7Vve+RYxPNkG7lTC9p+Mam39ANzJXyjHoXyLZjMhcBBHK0hr/L05k/lMWZz9rwnENnRIh6waomtL1pDhQcA+kqlEZptgJZyz8T73SDWn1T9EFmIGmM//8l5Z/vBroZrngOx0Kx0/8dmU1S5D+EoO1cKiNK5G1wKiuUIU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BDNcmz93; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BDNcmz93" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D7A1C4CEC7; Thu, 5 Sep 2024 16:30:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725553827; bh=Y54jxoqOwq9hafYzm3zMRq3v1cZWWr87gVCbSOuKlsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BDNcmz93dGLHlQYH5aM5GF5k/Tky8bDBKfLN9eO4ruqvluJRiScIQq6IArnImzqYV k4YkSmmms/RzdE2aUe6Or+ZddrmABbQIENRKQLKm9R8f5a/VQHh2ORAPA7F0fUsLgy U5veu6HuLJAnPhHUpp3/S0hifVUv129b3cL1ZxpmiPX4bsDO5TwMornrm+fJdlIZwG 78Lu1T62MztnYOW/4Ohw59jqo39XQKkgZ1WILIr43IHzEPPSh0N0sdofJ6qUtLhZmX 8jQZ23Di/UjMbCnFb2VA/RfTQ9WeyYMeQVp/RYdxuhh0vqWZGisAs1UQBZsnIPrYzX 9vqhCGkqdul6g== From: Mario Limonciello To: "Gautham R . Shenoy" , Perry Yuan Cc: Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "Rafael J . Wysocki" , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)), linux-acpi@vger.kernel.org (open list:ACPI), linux-pm@vger.kernel.org (open list:CPU FREQUENCY SCALING FRAMEWORK), Mario Limonciello Subject: [PATCH v3 08/11] cpufreq: amd-pstate: Merge amd_pstate_highest_perf_set() into amd_get_boost_ratio_numerator() Date: Thu, 5 Sep 2024 11:30:04 -0500 Message-ID: <20240905163007.1350840-9-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240905163007.1350840-1-superm1@kernel.org> References: <20240905163007.1350840-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello The special case in amd_pstate_highest_perf_set() is the value used for calculating the boost numerator. Merge this into amd_get_boost_ratio_numerator() and then use that to calculate boost ratio. This allows dropping more special casing of the highest perf value. Reviewed-by: Gautham R. Shenoy Signed-off-by: Mario Limonciello --- v2->v3: * Add tag v1->v2: * Document that preferred cores will have different values for highest perf. * Fix an uninitialized variable caused by merge --- Documentation/admin-guide/pm/amd-pstate.rst | 3 +- arch/x86/kernel/acpi/cppc.c | 16 +++++++ drivers/cpufreq/amd-pstate.c | 52 ++++----------------- 3 files changed, 28 insertions(+), 43 deletions(-) diff --git a/Documentation/admin-guide/pm/amd-pstate.rst b/Documentation/admin-guide/pm/amd-pstate.rst index d0324d44f5482..e13915c540648 100644 --- a/Documentation/admin-guide/pm/amd-pstate.rst +++ b/Documentation/admin-guide/pm/amd-pstate.rst @@ -251,7 +251,8 @@ performance supported in `AMD CPPC Performance Capability `_). In some ASICs, the highest CPPC performance is not the one in the ``_CPC`` table, so we need to expose it to sysfs. If boost is not active, but still supported, this maximum frequency will be larger than the one in -``cpuinfo``. +``cpuinfo``. On systems that support preferred core, the driver will have +different values for some cores than others. This attribute is read-only. ``amd_pstate_lowest_nonlinear_freq`` diff --git a/arch/x86/kernel/acpi/cppc.c b/arch/x86/kernel/acpi/cppc.c index df367bc359308..956984054bf30 100644 --- a/arch/x86/kernel/acpi/cppc.c +++ b/arch/x86/kernel/acpi/cppc.c @@ -9,6 +9,7 @@ #include #include +#define CPPC_HIGHEST_PERF_PERFORMANCE 196 #define CPPC_HIGHEST_PERF_PREFCORE 166 enum amd_pref_core { @@ -245,6 +246,21 @@ int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator) *numerator = boost_numerator; return 0; } + + /* + * For AMD CPUs with Family ID 19H and Model ID range 0x70 to 0x7f, + * the highest performance level is set to 196. + * https://bugzilla.kernel.org/show_bug.cgi?id=218759 + */ + if (cpu_feature_enabled(X86_FEATURE_ZEN4)) { + switch (boot_cpu_data.x86_model) { + case 0x70 ... 0x7f: + *numerator = CPPC_HIGHEST_PERF_PERFORMANCE; + return 0; + default: + break; + } + } *numerator = CPPC_HIGHEST_PERF_PREFCORE; return 0; diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index c29cdf2d3882c..3ae41af6f041e 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -52,8 +52,6 @@ #define AMD_PSTATE_TRANSITION_LATENCY 20000 #define AMD_PSTATE_TRANSITION_DELAY 1000 #define AMD_PSTATE_FAST_CPPC_TRANSITION_DELAY 600 -#define CPPC_HIGHEST_PERF_PERFORMANCE 196 -#define CPPC_HIGHEST_PERF_DEFAULT 166 #define AMD_CPPC_EPP_PERFORMANCE 0x00 #define AMD_CPPC_EPP_BALANCE_PERFORMANCE 0x80 @@ -372,43 +370,17 @@ static inline int amd_pstate_enable(bool enable) return static_call(amd_pstate_enable)(enable); } -static u32 amd_pstate_highest_perf_set(struct amd_cpudata *cpudata) -{ - struct cpuinfo_x86 *c = &cpu_data(0); - - /* - * For AMD CPUs with Family ID 19H and Model ID range 0x70 to 0x7f, - * the highest performance level is set to 196. - * https://bugzilla.kernel.org/show_bug.cgi?id=218759 - */ - if (c->x86 == 0x19 && (c->x86_model >= 0x70 && c->x86_model <= 0x7f)) - return CPPC_HIGHEST_PERF_PERFORMANCE; - - return CPPC_HIGHEST_PERF_DEFAULT; -} - static int pstate_init_perf(struct amd_cpudata *cpudata) { u64 cap1; - u32 highest_perf; int ret = rdmsrl_safe_on_cpu(cpudata->cpu, MSR_AMD_CPPC_CAP1, &cap1); if (ret) return ret; - /* For platforms that do not support the preferred core feature, the - * highest_pef may be configured with 166 or 255, to avoid max frequency - * calculated wrongly. we take the AMD_CPPC_HIGHEST_PERF(cap1) value as - * the default max perf. - */ - if (cpudata->hw_prefcore) - highest_perf = amd_pstate_highest_perf_set(cpudata); - else - highest_perf = AMD_CPPC_HIGHEST_PERF(cap1); - - WRITE_ONCE(cpudata->highest_perf, highest_perf); - WRITE_ONCE(cpudata->max_limit_perf, highest_perf); + WRITE_ONCE(cpudata->highest_perf, AMD_CPPC_HIGHEST_PERF(cap1)); + WRITE_ONCE(cpudata->max_limit_perf, AMD_CPPC_HIGHEST_PERF(cap1)); WRITE_ONCE(cpudata->nominal_perf, AMD_CPPC_NOMINAL_PERF(cap1)); WRITE_ONCE(cpudata->lowest_nonlinear_perf, AMD_CPPC_LOWNONLIN_PERF(cap1)); WRITE_ONCE(cpudata->lowest_perf, AMD_CPPC_LOWEST_PERF(cap1)); @@ -420,19 +392,13 @@ static int pstate_init_perf(struct amd_cpudata *cpudata) static int cppc_init_perf(struct amd_cpudata *cpudata) { struct cppc_perf_caps cppc_perf; - u32 highest_perf; int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf); if (ret) return ret; - if (cpudata->hw_prefcore) - highest_perf = amd_pstate_highest_perf_set(cpudata); - else - highest_perf = cppc_perf.highest_perf; - - WRITE_ONCE(cpudata->highest_perf, highest_perf); - WRITE_ONCE(cpudata->max_limit_perf, highest_perf); + WRITE_ONCE(cpudata->highest_perf, cppc_perf.highest_perf); + WRITE_ONCE(cpudata->max_limit_perf, cppc_perf.highest_perf); WRITE_ONCE(cpudata->nominal_perf, cppc_perf.nominal_perf); WRITE_ONCE(cpudata->lowest_nonlinear_perf, cppc_perf.lowest_nonlinear_perf); @@ -905,8 +871,8 @@ static u32 amd_pstate_get_transition_latency(unsigned int cpu) static int amd_pstate_init_freq(struct amd_cpudata *cpudata) { int ret; - u32 min_freq; - u32 highest_perf, max_freq; + u32 min_freq, max_freq; + u64 numerator; u32 nominal_perf, nominal_freq; u32 lowest_nonlinear_perf, lowest_nonlinear_freq; u32 boost_ratio, lowest_nonlinear_ratio; @@ -928,8 +894,10 @@ static int amd_pstate_init_freq(struct amd_cpudata *cpudata) nominal_perf = READ_ONCE(cpudata->nominal_perf); - highest_perf = READ_ONCE(cpudata->highest_perf); - boost_ratio = div_u64(highest_perf << SCHED_CAPACITY_SHIFT, nominal_perf); + ret = amd_get_boost_ratio_numerator(cpudata->cpu, &numerator); + if (ret) + return ret; + boost_ratio = div_u64(numerator << SCHED_CAPACITY_SHIFT, nominal_perf); max_freq = (nominal_freq * boost_ratio >> SCHED_CAPACITY_SHIFT) * 1000; lowest_nonlinear_perf = READ_ONCE(cpudata->lowest_nonlinear_perf); From patchwork Thu Sep 5 16:30:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13792688 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8677919DF4F; Thu, 5 Sep 2024 16:30:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553828; cv=none; b=AaNTyW+zSEzD4TvCwnuGaVEu+embesScZcr1PfzsdUgtXUMvPVDzERQTVgoyls2Na89mFDSxDNEExMIfZF/g+6a9S7C7JJX+BapMop/+n/2A9dj28zsvTMfUhQeYWHVTD/hEbTbRMkF01vxbT46mVN0GVjmqfjkjcUZDdF0glyQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553828; c=relaxed/simple; bh=+sHrHnLT2FfYkGdEfPvMGy5X5VchYsR5Qb+fThI971s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ePE7aIES5+m8ug8vuAJZCE6hdrKBHLUX0+5+zuA2V1PhoBkLYk/3V91I79sjdejMgZVufTwibSwt65Hs6aJisQzS25yu8e06/FGpzJ3PgoHUeYDjbCepbzLUn+I+2QOvy7LhiOrFItof4yFc/pfus3OxLcFwMQG6jJ7e3MQTqfY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YDBnH6uM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="YDBnH6uM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40559C4CECC; Thu, 5 Sep 2024 16:30:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725553828; bh=+sHrHnLT2FfYkGdEfPvMGy5X5VchYsR5Qb+fThI971s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YDBnH6uMKXrNppDFxcEi30uU1d9AUGQ8jutZRjvtXvmS78neX2sE7GVQYrZ0fXEaK KsFVUKDApoKvFDRu/01w16dAfCJ9cHzM322GBdl+NQAlAb3kdqC3UU49PRGdyfg0bG Lipd6KhoUvMm5QylDKb67VoYYj2NrHoLqO9cJs4nJ3bTHTMXdDHQZ2WOYRnpXAMm35 zw9Pl2NqWod14s7TFL1Q3lWd2c/cgKb5jxeIJJ4agOCp+lzVGx19bcav1Zfm2oYPqf UaUXdz5rjPiccD4NwIZ9QcVL5Ee40P4yAHx8u+9zb8i9OWlQ5bNuogwTkFO0dtnsqp /O0ZDeGetTl/g== From: Mario Limonciello To: "Gautham R . Shenoy" , Perry Yuan Cc: Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "Rafael J . Wysocki" , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)), linux-acpi@vger.kernel.org (open list:ACPI), linux-pm@vger.kernel.org (open list:CPU FREQUENCY SCALING FRAMEWORK), Mario Limonciello Subject: [PATCH v3 09/11] cpufreq: amd-pstate: Optimize amd_pstate_update_limits() Date: Thu, 5 Sep 2024 11:30:05 -0500 Message-ID: <20240905163007.1350840-10-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240905163007.1350840-1-superm1@kernel.org> References: <20240905163007.1350840-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello Don't take and release the mutex when prefcore isn't present and avoid initialization of variables that will be initially set in the function. Reviewed-by: Gautham R. Shenoy Reviewed-by: Perry Yuan Signed-off-by: Mario Limonciello --- drivers/cpufreq/amd-pstate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/cpufreq/amd-pstate.c b/drivers/cpufreq/amd-pstate.c index 3ae41af6f041e..9312d4e40994f 100644 --- a/drivers/cpufreq/amd-pstate.c +++ b/drivers/cpufreq/amd-pstate.c @@ -797,17 +797,17 @@ static void amd_pstate_update_limits(unsigned int cpu) int ret; bool highest_perf_changed = false; - mutex_lock(&amd_pstate_driver_lock); - if ((!amd_pstate_prefcore) || (!cpudata->hw_prefcore)) - goto free_cpufreq_put; + if (!amd_pstate_prefcore) + return; + mutex_lock(&amd_pstate_driver_lock); ret = amd_get_highest_perf(cpu, &cur_high); if (ret) goto free_cpufreq_put; prev_high = READ_ONCE(cpudata->prefcore_ranking); - if (prev_high != cur_high) { - highest_perf_changed = true; + highest_perf_changed = (prev_high != cur_high); + if (highest_perf_changed) { WRITE_ONCE(cpudata->prefcore_ranking, cur_high); if (cur_high < CPPC_MAX_PERF) From patchwork Thu Sep 5 16:30:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13792689 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C16811AE056; Thu, 5 Sep 2024 16:30:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553829; cv=none; b=PEYwYYJJl+jqj+abF3fpHZw92w8KGikkXP4H9TYt4yrdTo46L/Q2MGLk3EwZ9eDInfomWy/UNM/OSfZXOgsCXmPbySBiIIHG2hec8bc5Q+978vNSDUwdiWWxbpXtuIjIbFK+vCZ5NYl0FvACwNlCwRwZFkYMWU/kJhiNajnRiC8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553829; c=relaxed/simple; bh=Hvu/JDym95sl9P2OaGdfnlcHvW9GhdS42LXTs42qNMk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ulutI5FSVs+uIQ7PtUIB6y7A6KsmASrO88aA6RKZyKfchWrRTJ6skB2nKs7323taALWwjpe7jzLv1Rk2XHnjaScfuOB44LMYHPiSvNUWIds9in7M40FHaTIElIb/4ovuDKwa8CZZRJt42ue+ud74REW+wmrQ2oiEzC73ivk75ps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UEeRcFP4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UEeRcFP4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E2AFC4CEC3; Thu, 5 Sep 2024 16:30:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725553829; bh=Hvu/JDym95sl9P2OaGdfnlcHvW9GhdS42LXTs42qNMk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UEeRcFP4hQ/4B4S3/fx4scu5EFBZCQs5mdXWnQl6OZt/ZUKSlNEHTj5Dnw1uIHQlx QZKUtYn86Rj/bbcGnCJEYF6Qu9yPrsUUgOmVOXhhxrRU0RygabQhrtCIAwDuIyJOTH 5Dz1WiLw/LbS2PT/3Zl8IJzG8yw5BxJj+0hsWG0mXjQDdNtD7RX08cCV94WkhJ5gvu NcVNYL2VFj4dqhiUgZpOUdYzNPLvcjcP43vxNWNQ3IsAZfcVV4HoRzgTSpi5mIVRVH IuxKEEfIq3Gv4ll5F57H7fkjhpxX6zGjNEzhagZOZe26fTZZd5bjZXRZh9vux4ir81 6CM1FsaZAR42A== From: Mario Limonciello To: "Gautham R . Shenoy" , Perry Yuan Cc: Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "Rafael J . Wysocki" , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)), linux-acpi@vger.kernel.org (open list:ACPI), linux-pm@vger.kernel.org (open list:CPU FREQUENCY SCALING FRAMEWORK), Mario Limonciello Subject: [PATCH v3 10/11] cpufreq: amd-pstate: Add documentation for `amd_pstate_hw_prefcore` Date: Thu, 5 Sep 2024 11:30:06 -0500 Message-ID: <20240905163007.1350840-11-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240905163007.1350840-1-superm1@kernel.org> References: <20240905163007.1350840-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello Explain that the sysfs file represents both preferred core being enabled by the user and supported by the hardware. Reviewed-by: Gautham R. Shenoy Signed-off-by: Mario Limonciello --- v2->v3: * Add tag --- Documentation/admin-guide/pm/amd-pstate.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/admin-guide/pm/amd-pstate.rst b/Documentation/admin-guide/pm/amd-pstate.rst index e13915c540648..d5c050ea390dc 100644 --- a/Documentation/admin-guide/pm/amd-pstate.rst +++ b/Documentation/admin-guide/pm/amd-pstate.rst @@ -263,6 +263,11 @@ lowest non-linear performance in `AMD CPPC Performance Capability `_.) This attribute is read-only. +``amd_pstate_hw_prefcore`` + +Whether the platform supports the preferred core feature and it has been +enabled. This attribute is read-only. + ``energy_performance_available_preferences`` A list of all the supported EPP preferences that could be used for From patchwork Thu Sep 5 16:30:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mario Limonciello X-Patchwork-Id: 13792690 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7DBE1B12DF; Thu, 5 Sep 2024 16:30:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553830; cv=none; b=Ilh+mEaInwhy8PaQGBdPlLCTOys4pXNUi5xn6dRPIQtGYReQpa8tEQweQBjZMeQ1b0h/Vb3pMo0xHidWcViyhVXcYauzJSR8FLjAfkNzl6dSSbRsJJIYa/3Fe6NHda2xz4L5Nv4L5OSyetuepqSIu0VJms2GMufVzVbauCa62K0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725553830; c=relaxed/simple; bh=XZ7K6Q+GJiNQh7jOC8M+XdWVBVAC/1BxSYrJDHfXPXQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=r2DIZqGSEjM8dD08I15I/01A7rTTrqHsX54HOcRV+R9hvkVN/wtTxymgIKzUEMI2X6UiSp9G56/ysh3aF/zHZPFxcd+XgP/++byk8q/xb0gWHvncm9b1ZMB8c0VRZI4sUh89Tw2pkL41RJ3Ms66mNfzUYTVGqxHuEWeg+Kexzm0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ry35W/6q; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ry35W/6q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9ECC1C4CEC5; Thu, 5 Sep 2024 16:30:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1725553830; bh=XZ7K6Q+GJiNQh7jOC8M+XdWVBVAC/1BxSYrJDHfXPXQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ry35W/6quC7b4BBuc2q3MVv+P1Gy74ff9eX3m9FFLrQ/8sk+SXVUDYFE5ks4QTB4u 1XlBMu7+WEW6j9soNmWYITemPs/0kaJPxTo8Vogs9M2+NXCg61XjWkg+E0PqeNY+jH 7lFCS20Zo8RbNZmb/RqoJl6yKcU28y3aXipkOylKj91xI24//FjrRVRF7xBhKOxSJi xPp+JOOBKhR/w5DH0DYNjHA020DVhSqZOX2XJrAT8eyHxdyF811IG+wwCv+4s9UtkM SzHmYb/sArMNUzmFHGnRHRJZb2ThazTOkN4qKf5DxReJURdpQEHAVjtVAX25pSCiCI i918ESuJBSWXg== From: Mario Limonciello To: "Gautham R . Shenoy" , Perry Yuan Cc: Borislav Petkov , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), "Rafael J . Wysocki" , linux-kernel@vger.kernel.org (open list:X86 ARCHITECTURE (32-BIT AND 64-BIT)), linux-acpi@vger.kernel.org (open list:ACPI), linux-pm@vger.kernel.org (open list:CPU FREQUENCY SCALING FRAMEWORK), Mario Limonciello Subject: [PATCH v3 11/11] amd-pstate: Add missing documentation for `amd_pstate_prefcore_ranking` Date: Thu, 5 Sep 2024 11:30:07 -0500 Message-ID: <20240905163007.1350840-12-superm1@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240905163007.1350840-1-superm1@kernel.org> References: <20240905163007.1350840-1-superm1@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Mario Limonciello `amd_pstate_prefcore_ranking` reflects the dynamic rankings of a CPU core based on platform conditions. Explicitly include it in the documentation. Reviewed-by: Gautham R. Shenoy Signed-off-by: Mario Limonciello --- v2->v3: * Add tag --- Documentation/admin-guide/pm/amd-pstate.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/pm/amd-pstate.rst b/Documentation/admin-guide/pm/amd-pstate.rst index d5c050ea390dc..210a808b74ec2 100644 --- a/Documentation/admin-guide/pm/amd-pstate.rst +++ b/Documentation/admin-guide/pm/amd-pstate.rst @@ -252,7 +252,8 @@ In some ASICs, the highest CPPC performance is not the one in the ``_CPC`` table, so we need to expose it to sysfs. If boost is not active, but still supported, this maximum frequency will be larger than the one in ``cpuinfo``. On systems that support preferred core, the driver will have -different values for some cores than others. +different values for some cores than others and this will reflect the values +advertised by the platform at bootup. This attribute is read-only. ``amd_pstate_lowest_nonlinear_freq`` @@ -268,6 +269,12 @@ This attribute is read-only. Whether the platform supports the preferred core feature and it has been enabled. This attribute is read-only. +``amd_pstate_prefcore_ranking`` + +The performance ranking of the core. This number doesn't have any unit, but +larger numbers are preferred at the time of reading. This can change at +runtime based on platform conditions. This attribute is read-only. + ``energy_performance_available_preferences`` A list of all the supported EPP preferences that could be used for