From patchwork Mon Jul 31 20:42:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shuah Khan X-Patchwork-Id: 708656 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B374C001DE for ; Mon, 31 Jul 2023 20:42:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229727AbjGaUmp (ORCPT ); Mon, 31 Jul 2023 16:42:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229535AbjGaUmn (ORCPT ); Mon, 31 Jul 2023 16:42:43 -0400 Received: from mail-io1-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A02390 for ; Mon, 31 Jul 2023 13:42:42 -0700 (PDT) Received: by mail-io1-xd43.google.com with SMTP id ca18e2360f4ac-790b9d7d643so2089239f.1 for ; Mon, 31 Jul 2023 13:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; t=1690836161; x=1691440961; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=XpCC3tOLTpKqE5XEEf3DLfZePXiAc1IjSgoBL2XtPGw=; b=WRRzui429GHkLB7+YIrBM+N33oWBU+/7iXSohevSKaXBZHTYwamKIBPJ4MI+hyLf3+ FicbFwAez8loRGx5BdTVC1aTJNoAR4DBfCB4PibIpKgHhJXxVhE/NygkKL6BiBX3gmD+ 9Hi6te2RbNvj+MfmMGBmr+9cUlvAEPj2ftUsg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690836161; x=1691440961; h=subject:from:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XpCC3tOLTpKqE5XEEf3DLfZePXiAc1IjSgoBL2XtPGw=; b=hJ7QYemDCYcmMj1odLqZ6+jZSTOlQYLLmlah5hzNopEVmVrrIUMfI8JVDrJTURS1ye Uc6jVJl6TJiq+yMxMuzNAk4NYBerQPPfdoN0RqtSFlXjYW33e7tD91lgBA/tRrGTYALw goRhxLa/aHi5Tx9B3czgWj85eX23FjvunIP6KaB38hdN/aO25/u9m1QlMIQ0bUeMU31K jI7p8+MxLsWpCFoDdTYWXOkbeapuesInZLHcd0ST9rxCn4Zc4O9VfrlTglCSzLnVKaOC LRvi+9n9W++SvBbuyy0nrRtXg6ED/wvRw2T/j8n5dSgduy8bNAR9SvTkzW73f4QuMX4I pY7g== X-Gm-Message-State: ABy/qLb6Zp2eSI9EJyMih+4wKeuNgqc4fxWGGfHwAooHjJIwk3uQf2NK ttRT/MV0sQtA9xj2Hgj6eB5CZg== X-Google-Smtp-Source: APBJJlGhIzafQwdOFz7b600+JmwJCPp7w4etPA7NDHpB/VFtLf3UNHRmjNX39xUOTZAh5hXlW+7Y2A== X-Received: by 2002:a05:6602:3d5:b0:780:d65c:d78f with SMTP id g21-20020a05660203d500b00780d65cd78fmr12382748iov.2.1690836161368; Mon, 31 Jul 2023 13:42:41 -0700 (PDT) Received: from [192.168.1.128] ([38.15.45.1]) by smtp.gmail.com with ESMTPSA id g22-20020a056602249600b0077e3acd5ea1sm3468552ioe.53.2023.07.31.13.42.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 31 Jul 2023 13:42:41 -0700 (PDT) Message-ID: Date: Mon, 31 Jul 2023 14:42:40 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.13.0 Content-Language: en-US To: "Rafael J. Wysocki" Cc: trenn@suse.com, trenn@suse.de, linux-pm@vger.kernel.org, Shuah Khan , shuah From: Shuah Khan Subject: [GIT PULL] cpupower update for Linux 6.6-rc1 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Hi Rafael, Please pull the following cpupower update for Linux 6.6-rc1. This cpupower update for Linux 6.6-rc1 consists of 2 fixes and enhancements to add support for amd-pstate active mode driver, amd_pstate mode change, EPP value change, turbo-boost support, and is_valid_path API. diff is attached. thanks, -- Shuah ---------------------------------------------------------------- The following changes since commit 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5: Linux 6.5-rc1 (2023-07-09 13:53:13 -0700) are available in the Git repository at: git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux tags/linux-cpupower-6.6-rc1 for you to fetch changes up to 99481d2195bfd13a663904e6014887abf46b57c7: cpupower: Fix cpuidle_set to accept only numeric values for idle-set operation. (2023-07-18 16:07:08 -0600) ---------------------------------------------------------------- linux-cpupower-6.6-rc1 This cpupower update for Linux 6.6-rc1 consists of 2 fixes and enhancements to add support for amd-pstate active mode driver, amd_pstate mode change, EPP value change, turbo-boost support, and is_valid_path API. ---------------------------------------------------------------- Ben Hutchings (1): cpupower: Bump soname version Likhitha Korrapati (1): cpupower: Fix cpuidle_set to accept only numeric values for idle-set operation. Wyes Karny (5): cpupower: Recognise amd-pstate active mode driver cpupower: Add is_valid_path API cpupower: Add EPP value change support cpupower: Add support for amd_pstate mode change cpupower: Add turbo-boost support in cpupower tools/power/cpupower/Makefile | 2 +- tools/power/cpupower/lib/cpupower.c | 7 +++ tools/power/cpupower/lib/cpupower_intern.h | 1 + tools/power/cpupower/utils/cpuidle-set.c | 16 +++---- tools/power/cpupower/utils/cpupower-set.c | 65 +++++++++++++++++++++++++++- tools/power/cpupower/utils/helpers/helpers.h | 11 +++++ tools/power/cpupower/utils/helpers/misc.c | 57 +++++++++++++++++++++++- 7 files changed, 146 insertions(+), 13 deletions(-) ---------------------------------------------------------------- diff --git a/tools/power/cpupower/Makefile b/tools/power/cpupower/Makefile index 59bfa05dec5d..dc531805a570 100644 --- a/tools/power/cpupower/Makefile +++ b/tools/power/cpupower/Makefile @@ -53,7 +53,7 @@ DESTDIR ?= VERSION:= $(shell ./utils/version-gen.sh) LIB_MAJ= 0.0.1 -LIB_MIN= 0 +LIB_MIN= 1 PACKAGE = cpupower PACKAGE_BUGREPORT = linux-pm@vger.kernel.org diff --git a/tools/power/cpupower/lib/cpupower.c b/tools/power/cpupower/lib/cpupower.c index 3f7d0c0c5067..7a2ef691b20e 100644 --- a/tools/power/cpupower/lib/cpupower.c +++ b/tools/power/cpupower/lib/cpupower.c @@ -14,6 +14,13 @@ #include "cpupower.h" #include "cpupower_intern.h" +int is_valid_path(const char *path) +{ + if (access(path, F_OK) == -1) + return 0; + return 1; +} + unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen) { ssize_t numread; diff --git a/tools/power/cpupower/lib/cpupower_intern.h b/tools/power/cpupower/lib/cpupower_intern.h index ac1112b956ec..5fdb8620d41b 100644 --- a/tools/power/cpupower/lib/cpupower_intern.h +++ b/tools/power/cpupower/lib/cpupower_intern.h @@ -7,5 +7,6 @@ #define SYSFS_PATH_MAX 255 +int is_valid_path(const char *path); unsigned int cpupower_read_sysfs(const char *path, char *buf, size_t buflen); unsigned int cpupower_write_sysfs(const char *path, char *buf, size_t buflen); diff --git a/tools/power/cpupower/utils/cpuidle-set.c b/tools/power/cpupower/utils/cpuidle-set.c index 46158928f9ad..a551d1d4ac51 100644 --- a/tools/power/cpupower/utils/cpuidle-set.c +++ b/tools/power/cpupower/utils/cpuidle-set.c @@ -41,14 +41,6 @@ int cmd_idle_set(int argc, char **argv) cont = 0; break; case 'd': - if (param) { - param = -1; - cont = 0; - break; - } - param = ret; - idlestate = atoi(optarg); - break; case 'e': if (param) { param = -1; @@ -56,7 +48,13 @@ int cmd_idle_set(int argc, char **argv) break; } param = ret; - idlestate = atoi(optarg); + strtol(optarg, &endptr, 10); + if (*endptr != '\0') { + printf(_("Bad value: %s, Integer expected\n"), optarg); + exit(EXIT_FAILURE); + } else { + idlestate = atoi(optarg); + } break; case 'D': if (param) { diff --git a/tools/power/cpupower/utils/cpupower-set.c b/tools/power/cpupower/utils/cpupower-set.c index 180d5ba877e6..0677b58374ab 100644 --- a/tools/power/cpupower/utils/cpupower-set.c +++ b/tools/power/cpupower/utils/cpupower-set.c @@ -18,6 +18,9 @@ static struct option set_opts[] = { {"perf-bias", required_argument, NULL, 'b'}, + {"epp", required_argument, NULL, 'e'}, + {"amd-pstate-mode", required_argument, NULL, 'm'}, + {"turbo-boost", required_argument, NULL, 't'}, { }, }; @@ -37,11 +40,15 @@ int cmd_set(int argc, char **argv) union { struct { int perf_bias:1; + int epp:1; + int mode:1; + int turbo_boost:1; }; int params; } params; - int perf_bias = 0; + int perf_bias = 0, turbo_boost = 1; int ret = 0; + char epp[30], mode[20]; ret = uname(&uts); if (!ret && (!strcmp(uts.machine, "ppc64le") || @@ -55,7 +62,7 @@ int cmd_set(int argc, char **argv) params.params = 0; /* parameter parsing */ - while ((ret = getopt_long(argc, argv, "b:", + while ((ret = getopt_long(argc, argv, "b:e:m:", set_opts, NULL)) != -1) { switch (ret) { case 'b': @@ -69,6 +76,38 @@ int cmd_set(int argc, char **argv) } params.perf_bias = 1; break; + case 'e': + if (params.epp) + print_wrong_arg_exit(); + if (sscanf(optarg, "%29s", epp) != 1) { + print_wrong_arg_exit(); + return -EINVAL; + } + params.epp = 1; + break; + case 'm': + if (cpupower_cpu_info.vendor != X86_VENDOR_AMD) + print_wrong_arg_exit(); + if (params.mode) + print_wrong_arg_exit(); + if (sscanf(optarg, "%19s", mode) != 1) { + print_wrong_arg_exit(); + return -EINVAL; + } + params.mode = 1; + break; + case 't': + if (params.turbo_boost) + print_wrong_arg_exit(); + turbo_boost = atoi(optarg); + if (turbo_boost < 0 || turbo_boost > 1) { + printf("--turbo-boost param out of range [0-1]\n"); + print_wrong_arg_exit(); + } + params.turbo_boost = 1; + break; + + default: print_wrong_arg_exit(); } @@ -77,6 +116,18 @@ int cmd_set(int argc, char **argv) if (!params.params) print_wrong_arg_exit(); + if (params.mode) { + ret = cpupower_set_amd_pstate_mode(mode); + if (ret) + fprintf(stderr, "Error setting mode\n"); + } + + if (params.turbo_boost) { + ret = cpupower_set_turbo_boost(turbo_boost); + if (ret) + fprintf(stderr, "Error setting turbo-boost\n"); + } + /* Default is: set all CPUs */ if (bitmask_isallclear(cpus_chosen)) bitmask_setall(cpus_chosen); @@ -102,6 +153,16 @@ int cmd_set(int argc, char **argv) break; } } + + if (params.epp) { + ret = cpupower_set_epp(cpu, epp); + if (ret) { + fprintf(stderr, + "Error setting epp value on CPU %d\n", cpu); + break; + } + } + } return ret; } diff --git a/tools/power/cpupower/utils/helpers/helpers.h b/tools/power/cpupower/utils/helpers/helpers.h index 96e4bede078b..95749b8ee475 100644 --- a/tools/power/cpupower/utils/helpers/helpers.h +++ b/tools/power/cpupower/utils/helpers/helpers.h @@ -116,6 +116,10 @@ extern int cpupower_intel_set_perf_bias(unsigned int cpu, unsigned int val); extern int cpupower_intel_get_perf_bias(unsigned int cpu); extern unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu); +extern int cpupower_set_epp(unsigned int cpu, char *epp); +extern int cpupower_set_amd_pstate_mode(char *mode); +extern int cpupower_set_turbo_boost(int turbo_boost); + /* Read/Write msr ****************************/ /* PCI stuff ****************************/ @@ -173,6 +177,13 @@ static inline int cpupower_intel_get_perf_bias(unsigned int cpu) static inline unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu) { return 0; }; +static inline int cpupower_set_epp(unsigned int cpu, char *epp) +{ return -1; }; +static inline int cpupower_set_amd_pstate_mode(char *mode) +{ return -1; }; +static inline int cpupower_set_turbo_boost(int turbo_boost) +{ return -1; }; + /* Read/Write msr ****************************/ static inline int cpufreq_has_boost_support(unsigned int cpu, int *support, diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c index 9547b29254a7..76e461ff4f74 100644 --- a/tools/power/cpupower/utils/helpers/misc.c +++ b/tools/power/cpupower/utils/helpers/misc.c @@ -87,6 +87,61 @@ int cpupower_intel_set_perf_bias(unsigned int cpu, unsigned int val) return 0; } +int cpupower_set_epp(unsigned int cpu, char *epp) +{ + char path[SYSFS_PATH_MAX]; + char linebuf[30] = {}; + + snprintf(path, sizeof(path), + PATH_TO_CPU "cpu%u/cpufreq/energy_performance_preference", cpu); + + if (!is_valid_path(path)) + return -1; + + snprintf(linebuf, sizeof(linebuf), "%s", epp); + + if (cpupower_write_sysfs(path, linebuf, 30) <= 0) + return -1; + + return 0; +} + +int cpupower_set_amd_pstate_mode(char *mode) +{ + char path[SYSFS_PATH_MAX]; + char linebuf[20] = {}; + + snprintf(path, sizeof(path), PATH_TO_CPU "amd_pstate/status"); + + if (!is_valid_path(path)) + return -1; + + snprintf(linebuf, sizeof(linebuf), "%s\n", mode); + + if (cpupower_write_sysfs(path, linebuf, 20) <= 0) + return -1; + + return 0; +} + +int cpupower_set_turbo_boost(int turbo_boost) +{ + char path[SYSFS_PATH_MAX]; + char linebuf[2] = {}; + + snprintf(path, sizeof(path), PATH_TO_CPU "cpufreq/boost"); + + if (!is_valid_path(path)) + return -1; + + snprintf(linebuf, sizeof(linebuf), "%d", turbo_boost); + + if (cpupower_write_sysfs(path, linebuf, 2) <= 0) + return -1; + + return 0; +} + bool cpupower_amd_pstate_enabled(void) { char *driver = cpufreq_get_driver(0); @@ -95,7 +150,7 @@ bool cpupower_amd_pstate_enabled(void) if (!driver) return ret; - if (!strcmp(driver, "amd-pstate")) + if (!strncmp(driver, "amd", 3)) ret = true; cpufreq_put_driver(driver);