From: Wei Wang <wei.w.wang@intel.com>
To: jbeulich@suse.com, andrew.cooper3@citrix.com, xen-devel@lists.xen.org
Cc: Wei Wang <wei.w.wang@intel.com>
Subject: [PATCH v5 9/9] tools: enable xenpm to control the intel_pstate driver
Date: Mon, 14 Sep 2015 10:32:10 +0800 [thread overview]
Message-ID: <1442197930-3738-10-git-send-email-wei.w.wang@intel.com> (raw)
In-Reply-To: <1442197930-3738-1-git-send-email-wei.w.wang@intel.com>
The intel_pstate driver receives percentage values to set the
performance limits. This patch adds interfaces to support the
input of percentage values to control the intel_pstate driver.
The "get-cpufreq-para" is modified to show percentage
based feedback info.
Also, some changes in identation are made to make the printed
info looks tidy.
Signed-off-by: Wei Wang <wei.w.wang@intel.com>
---
tools/libxc/include/xenctrl.h | 21 ++++----
tools/libxc/xc_pm.c | 5 +-
tools/misc/xenpm.c | 116 ++++++++++++++++++++++++++++++++++--------
3 files changed, 108 insertions(+), 34 deletions(-)
changes in v5:
1) re-organize "struct xc_get_cpufreq_para" to make it less than 128Byte;
2) change to use switch() and enum based perf_alias, instead of string
comparisons.
diff --git a/tools/libxc/include/xenctrl.h b/tools/libxc/include/xenctrl.h
index 2000f12..27f9f18 100644
--- a/tools/libxc/include/xenctrl.h
+++ b/tools/libxc/include/xenctrl.h
@@ -2249,6 +2249,17 @@ struct xc_get_cpufreq_para {
uint32_t cpu_num;
uint32_t freq_num;
uint32_t gov_num;
+ int32_t turbo_enabled;
+
+ uint32_t cpuinfo_cur_freq;
+ uint32_t cpuinfo_max_freq;
+ uint32_t cpuinfo_min_freq;
+ uint32_t scaling_cur_freq;
+
+ uint32_t scaling_turbo_pct;
+ uint32_t scaling_max_perf;
+ uint32_t scaling_min_perf;
+ enum perf_alias perf_alias;
/* for all governors */
/* OUT variable */
@@ -2256,23 +2267,13 @@ struct xc_get_cpufreq_para {
uint32_t *scaling_available_frequencies;
char *scaling_available_governors;
char scaling_driver[CPUFREQ_NAME_LEN];
-
- uint32_t cpuinfo_cur_freq;
- uint32_t cpuinfo_max_freq;
- uint32_t cpuinfo_min_freq;
- uint32_t scaling_cur_freq;
-
char scaling_governor[CPUFREQ_NAME_LEN];
- uint32_t scaling_max_freq;
- uint32_t scaling_min_freq;
/* for specific governor */
union {
xc_userspace_t userspace;
xc_ondemand_t ondemand;
} u;
-
- int32_t turbo_enabled;
};
int xc_get_cpufreq_para(xc_interface *xch, int cpuid,
diff --git a/tools/libxc/xc_pm.c b/tools/libxc/xc_pm.c
index 5ad777a..2e22ae4 100644
--- a/tools/libxc/xc_pm.c
+++ b/tools/libxc/xc_pm.c
@@ -264,8 +264,9 @@ int xc_get_cpufreq_para(xc_interface *xch, int cpuid,
user_para->cpuinfo_max_freq = sys_para->cpuinfo_max_freq;
user_para->cpuinfo_min_freq = sys_para->cpuinfo_min_freq;
user_para->scaling_cur_freq = sys_para->scaling_cur_freq;
- user_para->scaling_max.pct = sys_para->scaling_max_perf;
- user_para->scaling_min.pct = sys_para->scaling_min_perf;
+ user_para->scaling_max_perf = sys_para->scaling_max_perf;
+ user_para->scaling_min_perf = sys_para->scaling_min_perf;
+ user_para->perf_alias = sys_para->perf_alias;
user_para->scaling_turbo_pct = sys_para->scaling_turbo_pct;
user_para->turbo_enabled = sys_para->turbo_enabled;
diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c
index 08f2242..49ceb89 100644
--- a/tools/misc/xenpm.c
+++ b/tools/misc/xenpm.c
@@ -32,6 +32,11 @@
#define MAX_CORE_RESIDENCIES 8
#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
+#define min_t(type,x,y) \
+ ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; })
+#define max_t(type,x,y) \
+ ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; })
+#define clamp_t(type, val, lo, hi) min_t(type, max_t(type, val, lo), hi)
static xc_interface *xc_handle;
static unsigned int max_cpu_nr;
@@ -46,6 +51,9 @@ void show_help(void)
" get-cpuidle-states [cpuid] list cpu idle info of CPU <cpuid> or all\n"
" get-cpufreq-states [cpuid] list cpu freq info of CPU <cpuid> or all\n"
" get-cpufreq-para [cpuid] list cpu freq parameter of CPU <cpuid> or all\n"
+ " set-scaling-max-pct [cpuid] <num> set max performance limit in percentage\n"
+ " or as scaling speed in percentage in userspace governor\n"
+ " set-scaling-min-pct [cpuid] <num> set min performance limit in percentage\n"
" set-scaling-maxfreq [cpuid] <HZ> set max cpu frequency <HZ> on CPU <cpuid>\n"
" or all CPUs\n"
" set-scaling-minfreq [cpuid] <HZ> set min cpu frequency <HZ> on CPU <cpuid>\n"
@@ -59,10 +67,10 @@ void show_help(void)
" set-up-threshold [cpuid] <num> set up threshold on CPU <cpuid> or all\n"
" it is used in ondemand governor.\n"
" get-cpu-topology get thread/core/socket topology info\n"
- " set-sched-smt enable|disable enable/disable scheduler smt power saving\n"
+ " set-sched-smt enable|disable enable/disable scheduler smt power saving\n"
" set-vcpu-migration-delay <num> set scheduler vcpu migration delay in us\n"
" get-vcpu-migration-delay get scheduler vcpu migration delay\n"
- " set-max-cstate <num> set the C-State limitation (<num> >= 0)\n"
+ " set-max-cstate <num> set the C-State limitation (<num> >= 0)\n"
" start [seconds] start collect Cx/Px statistics,\n"
" output after CTRL-C or SIGINT or several seconds.\n"
" enable-turbo-mode [cpuid] enable Turbo Mode for processors that support it.\n"
@@ -677,37 +685,51 @@ static void print_cpufreq_para(int cpuid, struct xc_get_cpufreq_para *p_cpufreq)
printf("current_governor : %s\n", p_cpufreq->scaling_governor);
if ( !strncmp(p_cpufreq->scaling_governor,
- "userspace", CPUFREQ_NAME_LEN) )
+ "userspace", CPUFREQ_NAME_LEN) &&
+ strncmp(p_cpufreq->scaling_driver,
+ "intel_pstate", CPUFREQ_NAME_LEN) )
{
- printf(" userspace specific :\n");
- printf(" scaling_setspeed : %u\n",
+ printf("userspace specific :\n");
+ printf("scaling_setspeed : %u\n",
p_cpufreq->u.userspace.scaling_setspeed);
}
else if ( !strncmp(p_cpufreq->scaling_governor,
- "ondemand", CPUFREQ_NAME_LEN) )
+ "ondemand", CPUFREQ_NAME_LEN) &&
+ strncmp(p_cpufreq->scaling_driver,
+ "intel_pstate", CPUFREQ_NAME_LEN) )
{
- printf(" ondemand specific :\n");
- printf(" sampling_rate : max [%u] min [%u] cur [%u]\n",
+ printf("ondemand specific :\n");
+ printf("sampling_rate : max [%u] min [%u] cur [%u]\n",
p_cpufreq->u.ondemand.sampling_rate_max,
p_cpufreq->u.ondemand.sampling_rate_min,
p_cpufreq->u.ondemand.sampling_rate);
- printf(" up_threshold : %u\n",
+ printf("up_threshold : %u\n",
p_cpufreq->u.ondemand.up_threshold);
}
- printf("scaling_avail_freq :");
- for ( i = 0; i < p_cpufreq->freq_num; i++ )
- if ( p_cpufreq->scaling_available_frequencies[i] ==
- p_cpufreq->scaling_cur_freq )
- printf(" *%d", p_cpufreq->scaling_available_frequencies[i]);
- else
- printf(" %d", p_cpufreq->scaling_available_frequencies[i]);
- printf("\n");
-
- printf("scaling frequency : max [%u] min [%u] cur [%u]\n",
- p_cpufreq->scaling_max_freq,
- p_cpufreq->scaling_min_freq,
- p_cpufreq->scaling_cur_freq);
+ switch ( p_cpufreq->perf_alias )
+ {
+ case PERCENTAGE:
+ printf("max_perf_pct : %d\n", p_cpufreq->scaling_max_perf);
+ printf("min_perf_pct : %d\n", p_cpufreq->scaling_min_perf);
+ printf("turbo_pct : %d\n", p_cpufreq->scaling_turbo_pct);
+ break;
+ case FREQUENCY:
+ default:
+ printf("scaling_avail_freq :");
+ for ( i = 0; i < p_cpufreq->freq_num; i++ )
+ if ( p_cpufreq->scaling_available_frequencies[i] ==
+ p_cpufreq->scaling_cur_freq )
+ printf(" *%d", p_cpufreq->scaling_available_frequencies[i]);
+ else
+ printf(" %d", p_cpufreq->scaling_available_frequencies[i]);
+ printf("\n");
+ printf("scaling frequency : max [%u] min [%u] cur [%u]\n",
+ p_cpufreq->scaling_max_perf,
+ p_cpufreq->scaling_min_perf,
+ p_cpufreq->scaling_cur_freq);
+ break;
+ }
printf("turbo mode : %s\n",
p_cpufreq->turbo_enabled ? "enabled" : "disabled or n/a");
@@ -854,6 +876,54 @@ void scaling_min_freq_func(int argc, char *argv[])
}
}
+void scaling_max_pct_func(int argc, char *argv[])
+{
+ int cpuid = -1, pct = -1;
+
+ parse_cpuid_and_int(argc, argv, &cpuid, &pct, "percentage");
+ pct = clamp_t(int, pct, 0, 100);
+
+ if ( cpuid < 0 )
+ {
+ int i;
+ for ( i = 0; i < max_cpu_nr; i++ )
+ if ( xc_set_cpufreq_para(xc_handle, i, SCALING_MAX_PCT, pct) )
+ fprintf(stderr,
+ "[CPU%d] failed to set scaling max freq (%d - %s)\n",
+ i, errno, strerror(errno));
+ }
+ else
+ {
+ if ( xc_set_cpufreq_para(xc_handle, cpuid, SCALING_MAX_PCT, pct) )
+ fprintf(stderr, "failed to set scaling max freq (%d - %s)\n",
+ errno, strerror(errno));
+ }
+}
+
+void scaling_min_pct_func(int argc, char *argv[])
+{
+ int cpuid = -1, pct = -1;
+
+ parse_cpuid_and_int(argc, argv, &cpuid, &pct, "percentage");
+ pct = clamp_t(int, pct, 0, 100);
+
+ if ( cpuid < 0 )
+ {
+ int i;
+ for ( i = 0; i < max_cpu_nr; i++ )
+ if ( xc_set_cpufreq_para(xc_handle, i, SCALING_MIN_PCT, pct) )
+ fprintf(stderr,
+ "[CPU%d] failed to set scaling max pct (%d - %s)\n",
+ i, errno, strerror(errno));
+ }
+ else
+ {
+ if ( xc_set_cpufreq_para(xc_handle, cpuid, SCALING_MIN_PCT, pct) )
+ fprintf(stderr, "failed to set scaling min pct (%d - %s)\n",
+ errno, strerror(errno));
+ }
+}
+
void scaling_speed_func(int argc, char *argv[])
{
int cpuid = -1, speed = -1;
@@ -1133,6 +1203,8 @@ struct {
{ "get-cpufreq-para", cpufreq_para_func },
{ "set-scaling-maxfreq", scaling_max_freq_func },
{ "set-scaling-minfreq", scaling_min_freq_func },
+ { "set-scaling-max-pct", scaling_max_pct_func},
+ { "set-scaling-min-pct", scaling_min_pct_func},
{ "set-scaling-governor", scaling_governor_func },
{ "set-scaling-speed", scaling_speed_func },
{ "set-sampling-rate", scaling_sampling_rate_func },
--
1.9.1
prev parent reply other threads:[~2015-09-14 2:32 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-09-14 2:32 [PATCH v5 0/9] Porting the intel_pstate driver to Xen Wei Wang
2015-09-14 2:32 ` [PATCH v5 1/9] x86/intel_pstate: add some calculation related support Wei Wang
2015-09-17 15:19 ` Andrew Cooper
2015-10-05 16:00 ` Jan Beulich
2015-09-14 2:32 ` [PATCH v5 2/9] x86/intel_pstate: APERF/MPERF feature detect Wei Wang
2015-09-17 15:26 ` Andrew Cooper
2015-10-05 16:14 ` Jan Beulich
2015-09-14 2:32 ` [PATCH v5 3/9] x86/intel_pstate: add a new driver interface, setpolicy() Wei Wang
2015-09-17 15:34 ` Andrew Cooper
2015-10-06 15:37 ` Jan Beulich
2015-09-14 2:32 ` [PATCH v5 4/9] x86/intel_pstate: relocate the driver register function Wei Wang
2015-09-17 15:38 ` Andrew Cooper
2015-09-21 13:13 ` Jan Beulich
2015-10-07 15:08 ` Jan Beulich
2015-09-14 2:32 ` [PATCH v5 5/9] x86/intel_pstate: changes in cpufreq_del_cpu for CPU offline Wei Wang
2015-09-17 15:43 ` Andrew Cooper
2015-10-07 15:28 ` Jan Beulich
2015-10-11 2:19 ` Wang, Wei W
2015-09-14 2:32 ` [PATCH v5 6/9] x86/intel_pstate: the main boby of the intel_pstate driver Wei Wang
2015-09-17 15:51 ` Andrew Cooper
2015-10-07 15:39 ` Jan Beulich
2015-09-14 2:32 ` [PATCH v5 7/9] x86/intel_pstate: add a booting param to select the driver to load Wei Wang
2015-09-17 16:08 ` Andrew Cooper
2015-09-21 13:15 ` Jan Beulich
2015-10-07 15:46 ` Jan Beulich
2015-10-23 8:09 ` Wang, Wei W
2015-10-23 8:16 ` Wang, Wei W
2015-10-23 8:18 ` Wang, Wei W
2015-10-23 8:35 ` Jan Beulich
2015-10-23 8:48 ` Wang, Wei W
2015-09-14 2:32 ` [PATCH v5 8/9] x86/intel_pstate: support the use of intel_pstate in pmstat.c Wei Wang
2015-10-07 16:10 ` Jan Beulich
2015-10-26 6:26 ` Wang, Wei W
2015-10-26 7:02 ` Jan Beulich
2015-10-26 7:59 ` Wang, Wei W
2015-10-26 9:40 ` Jan Beulich
2015-10-26 9:48 ` Wang, Wei W
2015-10-26 9:53 ` Jan Beulich
2015-10-26 10:19 ` Wang, Wei W
2015-10-26 10:35 ` Jan Beulich
2015-10-26 10:45 ` Wang, Wei W
2015-10-26 10:51 ` Jan Beulich
2015-10-26 11:03 ` Wang, Wei W
2015-09-14 2:32 ` Wei Wang [this message]
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=1442197930-3738-10-git-send-email-wei.w.wang@intel.com \
--to=wei.w.wang@intel.com \
--cc=andrew.cooper3@citrix.com \
--cc=jbeulich@suse.com \
--cc=xen-devel@lists.xen.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).