From: Marcelo Tosatti <mtosatti@redhat.com>
To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Radim Krcmar <rkrcmar@redhat.com>,
"Rafael J. Wysocki" <rjw@rjwysocki.net>,
Viresh Kumar <viresh.kumar@linaro.org>,
Marcelo Tosatti <mtosatti@redhat.com>
Subject: [patch 3/3] KVM: x86: frequency change hypercalls
Date: Thu, 02 Feb 2017 15:47:58 -0200 [thread overview]
Message-ID: <20170202174921.983532379@redhat.com> (raw)
In-Reply-To: 20170202174755.946578704@redhat.com
[-- Attachment #1: kvm-cpufreq-api --]
[-- Type: text/plain, Size: 4840 bytes --]
Implement min/max/up/down frequency change
KVM hypercalls. To be used by DPDK implementation.
Also allow such hypercalls from guest userspace.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
---
Documentation/virtual/kvm/hypercalls.txt | 45 +++++++++++++++++++
arch/x86/kvm/x86.c | 71 ++++++++++++++++++++++++++++++-
include/uapi/linux/kvm_para.h | 5 ++
3 files changed, 120 insertions(+), 1 deletion(-)
Index: kvm-pvfreq/arch/x86/kvm/x86.c
===================================================================
--- kvm-pvfreq.orig/arch/x86/kvm/x86.c 2017-02-02 11:17:17.063756725 -0200
+++ kvm-pvfreq/arch/x86/kvm/x86.c 2017-02-02 11:17:17.822752510 -0200
@@ -6219,10 +6219,58 @@
kvm_x86_ops->refresh_apicv_exec_ctrl(vcpu);
}
+#ifdef CONFIG_CPU_FREQ_GOV_USERSPACE
+/* call into cpufreq-userspace governor */
+static int kvm_pvfreq_up(struct kvm_vcpu *vcpu)
+{
+ int ret;
+ int cpu = get_cpu();
+
+ ret = cpufreq_userspace_freq_up(cpu);
+ put_cpu();
+
+ return ret;
+}
+
+static int kvm_pvfreq_down(struct kvm_vcpu *vcpu)
+{
+ int ret;
+ int cpu = get_cpu();
+
+ ret = cpufreq_userspace_freq_down(cpu);
+ put_cpu();
+
+ return ret;
+}
+
+static int kvm_pvfreq_max(struct kvm_vcpu *vcpu)
+{
+ int ret;
+ int cpu = get_cpu();
+
+ ret = cpufreq_userspace_freq_max(cpu);
+ put_cpu();
+
+ return ret;
+}
+
+static int kvm_pvfreq_min(struct kvm_vcpu *vcpu)
+{
+ int ret;
+ int cpu = get_cpu();
+
+ ret = cpufreq_userspace_freq_min(cpu);
+ put_cpu();
+
+ return ret;
+}
+#endif
+
int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
{
unsigned long nr, a0, a1, a2, a3, ret;
int op_64_bit, r;
+ bool cpl_check;
r = kvm_skip_emulated_instruction(vcpu);
@@ -6246,7 +6294,13 @@
a3 &= 0xFFFFFFFF;
}
- if (kvm_x86_ops->get_cpl(vcpu) != 0) {
+ cpl_check = true;
+ if (nr == KVM_HC_FREQ_UP || nr == KVM_HC_FREQ_DOWN ||
+ nr == KVM_HC_FREQ_MIN || nr == KVM_HC_FREQ_MAX)
+ if (vcpu->arch.allow_freq_hypercall == true)
+ cpl_check = false;
+
+ if (cpl_check == true && kvm_x86_ops->get_cpl(vcpu) != 0) {
ret = -KVM_EPERM;
goto out;
}
@@ -6262,6 +6316,21 @@
case KVM_HC_CLOCK_PAIRING:
ret = kvm_pv_clock_pairing(vcpu, a0, a1);
break;
+#ifdef CONFIG_CPU_FREQ_GOV_USERSPACE
+ case KVM_HC_FREQ_UP:
+ ret = kvm_pvfreq_up(vcpu);
+ break;
+ case KVM_HC_FREQ_DOWN:
+ ret = kvm_pvfreq_down(vcpu);
+ break;
+ case KVM_HC_FREQ_MAX:
+ ret = kvm_pvfreq_max(vcpu);
+ break;
+ case KVM_HC_FREQ_MIN:
+ ret = kvm_pvfreq_min(vcpu);
+ break;
+#endif
+
default:
ret = -KVM_ENOSYS;
break;
Index: kvm-pvfreq/include/uapi/linux/kvm_para.h
===================================================================
--- kvm-pvfreq.orig/include/uapi/linux/kvm_para.h 2017-02-02 10:51:53.741217306 -0200
+++ kvm-pvfreq/include/uapi/linux/kvm_para.h 2017-02-02 11:17:17.824752499 -0200
@@ -25,6 +25,11 @@
#define KVM_HC_MIPS_EXIT_VM 7
#define KVM_HC_MIPS_CONSOLE_OUTPUT 8
#define KVM_HC_CLOCK_PAIRING 9
+#define KVM_HC_FREQ_UP 10
+#define KVM_HC_FREQ_DOWN 11
+#define KVM_HC_FREQ_MAX 12
+#define KVM_HC_FREQ_MIN 13
+
/*
* hypercalls use architecture specific
Index: kvm-pvfreq/Documentation/virtual/kvm/hypercalls.txt
===================================================================
--- kvm-pvfreq.orig/Documentation/virtual/kvm/hypercalls.txt 2017-02-02 10:51:53.741217306 -0200
+++ kvm-pvfreq/Documentation/virtual/kvm/hypercalls.txt 2017-02-02 15:29:24.401692793 -0200
@@ -116,3 +116,48 @@
Returns KVM_EOPNOTSUPP if the host does not use TSC clocksource,
or if clock type is different than KVM_CLOCK_PAIRING_WALLCLOCK.
+
+7. KVM_HC_FREQ_UP
+-----------------
+
+Architecture: x86
+Status: active
+Purpose: Hypercall used to increase frequency to the next
+higher frequency.
+Usage example: DPDK power aware applications, that run on
+isolated CPUs. No input argument, returns 0 if success,
+1 if already at lowest frequency, error otherwise.
+
+8. KVM_HC_FREQ_DOWN
+---------------------
+
+Architecture: x86
+Status: active
+Purpose: Hypercall used to decrease frequency to the next
+lower frequency.
+Usage example: DPDK power aware applications, that run on
+isolated CPUs. No input argument, returns 0 if success,
+1 if already at lowest frequency, negative error otherwise.
+
+9. KVM_HC_FREQ_MIN
+-------------------
+
+Architecture: x86
+Status: active
+Purpose: Hypercall used to decrease frequency to the
+minimum frequency.
+Usage example: DPDK power aware applications, that run
+on isolated CPUs. No input argument, returns 0 if success
+error otherwise.
+
+10. KVM_HC_FREQ_MAX
+-------------------
+
+Architecture: x86
+Status: active
+Purpose: Hypercall used to increase frequency to the
+maximum frequency.
+Usage example: DPDK power aware applications, that run
+on isolated CPUs. No input argument, returns 0 if success
+error otherwise.
+
next prev parent reply other threads:[~2017-02-02 17:59 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-02 17:47 [patch 0/3] KVM CPU frequency change hypercalls Marcelo Tosatti
2017-02-02 17:47 ` [patch 1/3] cpufreq: implement min/max/up/down functions Marcelo Tosatti
2017-02-03 4:09 ` Viresh Kumar
2017-02-02 17:47 ` [patch 2/3] KVM: x86: introduce ioctl to allow frequency hypercalls Marcelo Tosatti
2017-02-03 17:03 ` Radim Krcmar
2017-02-22 21:18 ` Marcelo Tosatti
2017-02-23 16:48 ` Radim Krcmar
2017-02-23 17:31 ` Paolo Bonzini
2017-02-02 17:47 ` Marcelo Tosatti [this message]
2017-02-02 18:01 ` [patch 3/3] KVM: x86: frequency change hypercalls Marcelo Tosatti
2017-02-03 17:40 ` Radim Krcmar
2017-02-03 18:24 ` Marcelo Tosatti
2017-02-03 19:28 ` Radim Krcmar
2017-02-03 12:50 ` [patch 0/3] KVM CPU " Rafael J. Wysocki
2017-02-03 16:43 ` Radim Krcmar
2017-02-03 18:14 ` Marcelo Tosatti
2017-02-03 19:09 ` Radim Krcmar
2017-02-23 17:35 ` Paolo Bonzini
2017-02-23 23:19 ` Marcelo Tosatti
2017-02-24 9:18 ` Paolo Bonzini
2017-02-24 11:50 ` Marcelo Tosatti
2017-02-24 12:17 ` Paolo Bonzini
2017-02-24 13:04 ` Marcelo Tosatti
2017-02-24 15:34 ` Paolo Bonzini
2017-02-24 16:54 ` Rafael J. Wysocki
2017-02-28 2:45 ` Marcelo Tosatti
2017-03-01 14:21 ` Paolo Bonzini
2017-03-01 15:11 ` Marcelo Tosatti
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=20170202174921.983532379@redhat.com \
--to=mtosatti@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=rjw@rjwysocki.net \
--cc=rkrcmar@redhat.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 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).