From: Michael Wolf <mjw@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: kvm@vger.kernel.org, peterz@infradead.org, mtosatti@redhat.com,
glommer@parallels.com, mingo@redhat.com, avi@redhat.com
Subject: [PATCH RFC 2/3] Add a hypercall to retrieve the cpu entitlement value from the host.
Date: Thu, 23 Aug 2012 18:14:34 -0500 [thread overview]
Message-ID: <20120823231433.11681.7644.stgit@lambeau> (raw)
In-Reply-To: <20120823231346.11681.1502.stgit@lambeau>
If the hypercall is not implemented on the host a default value of
100 will be used. This value will be stored in /proc/sys/kernel/cpu_entitlements.
Signed-off-by: Michael Wolf <mjw@linux.vnet.ibm.com>
---
arch/x86/kvm/x86.c | 8 ++++++++
fs/proc/stat.c | 9 +++++++++
include/linux/kvm.h | 3 +++
include/linux/kvm_host.h | 3 +++
include/linux/kvm_para.h | 1 +
virt/kvm/kvm_main.c | 7 +++++++
6 files changed, 31 insertions(+)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 42bce48..734bc3d 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5052,6 +5052,9 @@ int kvm_emulate_hypercall(struct kvm_vcpu *vcpu)
case KVM_HC_VAPIC_POLL_IRQ:
ret = 0;
break;
+ case KVM_HC_CPU_ENTITLEMENT:
+ ret = vcpu->kvm->vcpu_entitlement;
+ break;
default:
ret = -KVM_ENOSYS;
break;
@@ -5897,6 +5900,11 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
return 0;
}
+int kvm_arch_vcpu_ioctl_set_entitlement(struct kvm *kvm, long entitlement)
+{
+ kvm->vcpu_entitlement = (int) entitlement;
+ return 0;
+}
int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
{
struct i387_fxsave_struct *fxsave =
diff --git a/fs/proc/stat.c b/fs/proc/stat.c
index 14e26c8..cf66665 100644
--- a/fs/proc/stat.c
+++ b/fs/proc/stat.c
@@ -11,6 +11,7 @@
#include <linux/irqnr.h>
#include <asm/cputime.h>
#include <linux/tick.h>
+#include <linux/kvm_para.h>
int cpu_entitlement = 100;
#ifndef arch_irq_stat_cpu
@@ -213,6 +214,14 @@ static const struct file_operations proc_stat_operations = {
static int __init proc_stat_init(void)
{
+ long ret;
+
+ if (kvm_para_available()) {
+ ret = kvm_hypercall0(KVM_HC_CPU_ENTITLEMENT);
+ if (ret > 0)
+ cpu_entitlement = (int) ret;
+ }
+
proc_create("stat", 0, NULL, &proc_stat_operations);
return 0;
}
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index 2ce09aa..fccd08e 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -904,6 +904,9 @@ struct kvm_s390_ucas_mapping {
#define KVM_SET_ONE_REG _IOW(KVMIO, 0xac, struct kvm_one_reg)
/* VM is being stopped by host */
#define KVM_KVMCLOCK_CTRL _IO(KVMIO, 0xad)
+/* Set the cpu entitlement this will be used to adjust stealtime reporting */
+#define KVM_SET_ENTITLEMENT _IOW(KVMIO, 0xae, unsigned long)
+
#define KVM_DEV_ASSIGN_ENABLE_IOMMU (1 << 0)
#define KVM_DEV_ASSIGN_PCI_2_3 (1 << 1)
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index b70b48b..71e3d73 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -276,6 +276,7 @@ struct kvm {
struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];
atomic_t online_vcpus;
int last_boosted_vcpu;
+ int vcpu_entitlement;
struct list_head vm_list;
struct mutex lock;
struct kvm_io_bus *buses[KVM_NR_BUSES];
@@ -538,6 +539,8 @@ void kvm_arch_hardware_unsetup(void);
void kvm_arch_check_processor_compat(void *rtn);
int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu);
int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu);
+int kvm_arch_vcpu_ioctl_set_entitlement(struct kvm *kvm,
+ long entitlement);
void kvm_free_physmem(struct kvm *kvm);
diff --git a/include/linux/kvm_para.h b/include/linux/kvm_para.h
index ff476dd..95f3387 100644
--- a/include/linux/kvm_para.h
+++ b/include/linux/kvm_para.h
@@ -19,6 +19,7 @@
#define KVM_HC_MMU_OP 2
#define KVM_HC_FEATURES 3
#define KVM_HC_PPC_MAP_MAGIC_PAGE 4
+#define KVM_HC_CPU_ENTITLEMENT 5
/*
* hypercalls use architecture specific
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 2468523..a0a4939 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2093,6 +2093,13 @@ static long kvm_vm_ioctl(struct file *filp,
break;
}
#endif
+ case KVM_SET_ENTITLEMENT: {
+ r = kvm_arch_vcpu_ioctl_set_entitlement(kvm, arg);
+ if (r)
+ goto out;
+ r = 0;
+ break;
+ }
default:
r = kvm_arch_vm_ioctl(filp, ioctl, arg);
if (r == -ENOTTY)
next prev parent reply other threads:[~2012-08-23 23:15 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-23 23:14 [PATCH RFC 0/3] Add guest cpu_entitlement reporting Michael Wolf
2012-08-23 23:14 ` [PATCH RFC 1/3] Add a sysctl interface to control and report the cpu entitlement setting Michael Wolf
2012-08-23 23:14 ` Michael Wolf [this message]
2012-08-23 23:14 ` [PATCH RFC 3/3] Modify the amount of stealtime that the kernel reports via the /proc interface Michael Wolf
2012-08-24 4:53 ` [PATCH RFC 0/3] Add guest cpu_entitlement reporting Glauber Costa
2012-08-24 15:11 ` Michael Wolf
2012-08-25 23:36 ` Glauber Costa
2012-08-27 15:50 ` Michael Wolf
2012-08-27 18:50 ` Glauber Costa
2012-08-27 20:19 ` Michael Wolf
2012-08-27 20:51 ` Glauber Costa
2012-08-27 18:55 ` Avi Kivity
2012-08-27 20:23 ` Michael Wolf
2012-08-27 20:31 ` Avi Kivity
2012-08-27 21:27 ` Michael Wolf
2012-08-27 21:41 ` Glauber Costa
2012-08-27 21:53 ` Michael Wolf
2012-08-27 21:52 ` Avi Kivity
2012-08-28 16:01 ` Anthony Liguori
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=20120823231433.11681.7644.stgit@lambeau \
--to=mjw@linux.vnet.ibm.com \
--cc=avi@redhat.com \
--cc=glommer@parallels.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mtosatti@redhat.com \
--cc=peterz@infradead.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).