All of lore.kernel.org
 help / color / mirror / Atom feed
From: Huang Rui <ray.huang@amd.com>
To: "Karny, Wyes" <Wyes.Karny@amd.com>
Cc: "rafael@kernel.org" <rafael@kernel.org>,
	"viresh.kumar@linaro.org" <viresh.kumar@linaro.org>,
	"trenn@suse.com" <trenn@suse.com>,
	"shuah@kernel.org" <shuah@kernel.org>,
	"Shenoy, Gautham Ranjal" <gautham.shenoy@amd.com>,
	"Limonciello, Mario" <Mario.Limonciello@amd.com>,
	"Yuan, Perry" <Perry.Yuan@amd.com>,
	"linux-pm@vger.kernel.org" <linux-pm@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 5/6] cpupower: Add support for amd_pstate mode change
Date: Fri, 16 Jun 2023 15:28:33 +0800	[thread overview]
Message-ID: <ZIwPIeby2TD1drZE@amd.com> (raw)
In-Reply-To: <20230612113615.205353-6-wyes.karny@amd.com>

On Mon, Jun 12, 2023 at 07:36:14PM +0800, Karny, Wyes wrote:
> amd_pstate supports changing of its mode dynamically via `status` sysfs
> file. Add the same capability in cpupower. To change the mode to active
> mode use below command:
> 
> cpupower set --amd-pstate-mode active
> 
> Reviewed-by: Gautham R. Shenoy <gautham.shenoy@amd.com>
> Signed-off-by: Wyes Karny <wyes.karny@amd.com>

Acked-by: Huang Rui <ray.huang@amd.com>

> ---
>  tools/power/cpupower/utils/cpupower-set.c    | 24 ++++++++++++++++++--
>  tools/power/cpupower/utils/helpers/helpers.h |  3 +++
>  tools/power/cpupower/utils/helpers/misc.c    | 18 +++++++++++++++
>  3 files changed, 43 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/power/cpupower/utils/cpupower-set.c b/tools/power/cpupower/utils/cpupower-set.c
> index a789b123dbd4..c2ba69b7ea54 100644
> --- a/tools/power/cpupower/utils/cpupower-set.c
> +++ b/tools/power/cpupower/utils/cpupower-set.c
> @@ -19,6 +19,7 @@
>  static struct option set_opts[] = {
>  	{"perf-bias", required_argument, NULL, 'b'},
>  	{"epp", required_argument, NULL, 'e'},
> +	{"amd-pstate-mode", required_argument, NULL, 'm'},
>  	{ },
>  };
>  
> @@ -39,12 +40,13 @@ int cmd_set(int argc, char **argv)
>  		struct {
>  			int perf_bias:1;
>  			int epp:1;
> +			int mode:1;
>  		};
>  		int params;
>  	} params;
>  	int perf_bias = 0;
>  	int ret = 0;
> -	char epp[30];
> +	char epp[30], mode[20];
>  
>  	ret = uname(&uts);
>  	if (!ret && (!strcmp(uts.machine, "ppc64le") ||
> @@ -58,7 +60,7 @@ int cmd_set(int argc, char **argv)
>  
>  	params.params = 0;
>  	/* parameter parsing */
> -	while ((ret = getopt_long(argc, argv, "b:e:",
> +	while ((ret = getopt_long(argc, argv, "b:e:m:",
>  						set_opts, NULL)) != -1) {
>  		switch (ret) {
>  		case 'b':
> @@ -81,6 +83,17 @@ int cmd_set(int argc, char **argv)
>  			}
>  			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;
>  		default:
>  			print_wrong_arg_exit();
>  		}
> @@ -89,6 +102,12 @@ 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");
> +	}
> +
>  	/* Default is: set all CPUs */
>  	if (bitmask_isallclear(cpus_chosen))
>  		bitmask_setall(cpus_chosen);
> @@ -123,6 +142,7 @@ int cmd_set(int argc, char **argv)
>  				break;
>  			}
>  		}
> +
>  	}
>  	return ret;
>  }
> diff --git a/tools/power/cpupower/utils/helpers/helpers.h b/tools/power/cpupower/utils/helpers/helpers.h
> index 5d998de2d291..d35596631eef 100644
> --- a/tools/power/cpupower/utils/helpers/helpers.h
> +++ b/tools/power/cpupower/utils/helpers/helpers.h
> @@ -117,6 +117,7 @@ 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);
>  
>  /* Read/Write msr ****************************/
>  
> @@ -177,6 +178,8 @@ static inline unsigned long long msr_intel_get_turbo_ratio(unsigned int cpu)
>  
>  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; };
>  
>  /* Read/Write msr ****************************/
>  
> diff --git a/tools/power/cpupower/utils/helpers/misc.c b/tools/power/cpupower/utils/helpers/misc.c
> index 63c3f26ef874..9df9af8a969e 100644
> --- a/tools/power/cpupower/utils/helpers/misc.c
> +++ b/tools/power/cpupower/utils/helpers/misc.c
> @@ -106,6 +106,24 @@ int cpupower_set_epp(unsigned int cpu, char *epp)
>  	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;
> +}
> +
>  bool cpupower_amd_pstate_enabled(void)
>  {
>  	char *driver = cpufreq_get_driver(0);
> -- 
> 2.34.1
> 

  reply	other threads:[~2023-06-16  7:29 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-12 11:36 [PATCH 0/6] cpupower: Add various feature control support for amd_pstate Wyes Karny
2023-06-12 11:36 ` [PATCH 1/6] amd-pstate: Make amd-pstate epp driver name hyphenated Wyes Karny
2023-06-15 17:31   ` Rafael J. Wysocki
2023-06-15 17:55     ` Wyes Karny
2023-06-15 18:30       ` Rafael J. Wysocki
2023-06-15 19:04         ` Wyes Karny
2023-06-16  7:29           ` Yuan, Perry
2023-06-16  7:07   ` Huang Rui
2023-06-16 12:33     ` Rafael J. Wysocki
2023-06-20 12:47       ` Huang Rui
2023-06-12 11:36 ` [PATCH 2/6] cpupower: Recognise amd-pstate active mode driver Wyes Karny
2023-06-12 11:36 ` [PATCH 3/6] cpupower: Add is_sysfs_present API Wyes Karny
2023-06-12 13:17   ` [PATCH v1.1 3/6] cpupower: Add is_valid_path API Wyes Karny
2023-06-12 11:36 ` [PATCH 4/6] cpupower: Add EPP value change support Wyes Karny
2023-06-16  7:22   ` Huang Rui
2023-06-16  9:03     ` Wyes Karny
2023-06-20 12:58       ` Huang Rui
2023-06-20 13:20         ` Wyes Karny
2023-06-20 13:49           ` Huang Rui
2023-06-12 11:36 ` [PATCH 5/6] cpupower: Add support for amd_pstate mode change Wyes Karny
2023-06-16  7:28   ` Huang Rui [this message]
2023-06-12 11:36 ` [PATCH 6/6] cpupower: Add turbo-boost support in cpupower Wyes Karny
2023-06-16  7:29   ` Huang Rui

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZIwPIeby2TD1drZE@amd.com \
    --to=ray.huang@amd.com \
    --cc=Mario.Limonciello@amd.com \
    --cc=Perry.Yuan@amd.com \
    --cc=Wyes.Karny@amd.com \
    --cc=gautham.shenoy@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.org \
    --cc=shuah@kernel.org \
    --cc=trenn@suse.com \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.