* [Qemu-devel] [PATCH] kvm: Check if smp_cpus exceeds max cpus supported by kvm
@ 2012-07-30 18:22 riegamaths
2012-07-31 9:51 ` Stefan Hajnoczi
2012-07-31 10:14 ` Peter Maydell
0 siblings, 2 replies; 3+ messages in thread
From: riegamaths @ 2012-07-30 18:22 UTC (permalink / raw)
To: qemu-devel
Cc: Marcelo Tosatti, Dunrong Huang, Stefan Hajnoczi, kvm, Avi Kivity
From: Dunrong Huang <riegamaths@gmail.com>
Add a helper function for fetching max cpus supported by kvm.
Make QEMU exit with an error message if smp_cpus exceeds limit
of VCPU count retrieved by invoking this helper function.
Signed-off-by: Dunrong Huang <riegamaths@gmail.com>
---
kvm-all.c | 25 +++++++++++++++++++++++++
1 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/kvm-all.c b/kvm-all.c
index 2148b20..8cb4b92 100644
--- a/kvm-all.c
+++ b/kvm-all.c
@@ -1207,6 +1207,23 @@ static int kvm_irqchip_create(KVMState *s)
return 0;
}
+static int kvm_max_vcpus(KVMState *s)
+{
+ int max_vcpus = 4;
+ int ret;
+ ret = kvm_check_extension(s, KVM_CAP_MAX_VCPUS);
+ if (ret) {
+ max_vcpus = ret;
+ } else {
+ ret = kvm_check_extension(s, KVM_CAP_NR_VCPUS);
+ if (ret) {
+ max_vcpus = ret;
+ }
+ }
+
+ return max_vcpus;
+}
+
int kvm_init(void)
{
static const char upgrade_note[] =
@@ -1216,6 +1233,7 @@ int kvm_init(void)
const KVMCapabilityInfo *missing_cap;
int ret;
int i;
+ int max_vcpus;
s = g_malloc0(sizeof(KVMState));
@@ -1256,6 +1274,13 @@ int kvm_init(void)
goto err;
}
+ max_vcpus = kvm_max_vcpus(s);
+ if (smp_cpus > max_vcpus) {
+ fprintf(stderr, "Number of SMP cpus requested (%d) exceeds max cpus "
+ "supported by KVM (%d)\n", smp_cpus, max_vcpus);
+ exit(1);
+ }
+
s->vmfd = kvm_ioctl(s, KVM_CREATE_VM, 0);
if (s->vmfd < 0) {
#ifdef TARGET_S390X
--
1.7.8.6
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] kvm: Check if smp_cpus exceeds max cpus supported by kvm
2012-07-30 18:22 [Qemu-devel] [PATCH] kvm: Check if smp_cpus exceeds max cpus supported by kvm riegamaths
@ 2012-07-31 9:51 ` Stefan Hajnoczi
2012-07-31 10:14 ` Peter Maydell
1 sibling, 0 replies; 3+ messages in thread
From: Stefan Hajnoczi @ 2012-07-31 9:51 UTC (permalink / raw)
To: riegamaths; +Cc: Avi Kivity, Marcelo Tosatti, qemu-devel, kvm, Stefan Hajnoczi
On Mon, Jul 30, 2012 at 7:22 PM, <riegamaths@gmail.com> wrote:
> From: Dunrong Huang <riegamaths@gmail.com>
>
> Add a helper function for fetching max cpus supported by kvm.
>
> Make QEMU exit with an error message if smp_cpus exceeds limit
> of VCPU count retrieved by invoking this helper function.
>
> Signed-off-by: Dunrong Huang <riegamaths@gmail.com>
> ---
> kvm-all.c | 25 +++++++++++++++++++++++++
> 1 files changed, 25 insertions(+), 0 deletions(-)
>
> diff --git a/kvm-all.c b/kvm-all.c
> index 2148b20..8cb4b92 100644
> --- a/kvm-all.c
> +++ b/kvm-all.c
> @@ -1207,6 +1207,23 @@ static int kvm_irqchip_create(KVMState *s)
> return 0;
> }
>
> +static int kvm_max_vcpus(KVMState *s)
> +{
> + int max_vcpus = 4;
> + int ret;
> + ret = kvm_check_extension(s, KVM_CAP_MAX_VCPUS);
> + if (ret) {
> + max_vcpus = ret;
> + } else {
> + ret = kvm_check_extension(s, KVM_CAP_NR_VCPUS);
> + if (ret) {
> + max_vcpus = ret;
> + }
> + }
The indentation is off here. It should be 4 spaces.
Otherwise looks fine.
Stefan
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Qemu-devel] [PATCH] kvm: Check if smp_cpus exceeds max cpus supported by kvm
2012-07-30 18:22 [Qemu-devel] [PATCH] kvm: Check if smp_cpus exceeds max cpus supported by kvm riegamaths
2012-07-31 9:51 ` Stefan Hajnoczi
@ 2012-07-31 10:14 ` Peter Maydell
1 sibling, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2012-07-31 10:14 UTC (permalink / raw)
To: riegamaths; +Cc: Avi Kivity, Marcelo Tosatti, qemu-devel, kvm, Stefan Hajnoczi
On 30 July 2012 19:22, <riegamaths@gmail.com> wrote:
> +static int kvm_max_vcpus(KVMState *s)
> +{
> + int max_vcpus = 4;
> + int ret;
> + ret = kvm_check_extension(s, KVM_CAP_MAX_VCPUS);
> + if (ret) {
> + max_vcpus = ret;
> + } else {
> + ret = kvm_check_extension(s, KVM_CAP_NR_VCPUS);
> + if (ret) {
> + max_vcpus = ret;
> + }
> + }
> +
> + return max_vcpus;
> +}
A small thing, but I think having code flow like:
/* Find number of supported CPUs using the recommended
* procedure from the kernel API documentation to cope with
* older kernels that may be missing capabilities.
*/
ret = kvm_check_extension(s, KVM_CAP_MAX_VCPUS);
if (ret) {
return ret;
}
ret = kvm_check_extension(s, KVM_CAP_NR_VCPUS);
if (ret) {
return ret;
}
return 4;
would be clearer.
(also I think a comment helps suggest that 4 isn't a magic
number we made up ourselves :-))
-- PMM
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-07-31 10:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-30 18:22 [Qemu-devel] [PATCH] kvm: Check if smp_cpus exceeds max cpus supported by kvm riegamaths
2012-07-31 9:51 ` Stefan Hajnoczi
2012-07-31 10:14 ` Peter Maydell
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).