From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51778) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VCXUb-0003ke-Tg for qemu-devel@nongnu.org; Thu, 22 Aug 2013 12:12:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VCXUV-0003wN-Uk for qemu-devel@nongnu.org; Thu, 22 Aug 2013 12:12:13 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6219) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VCXUV-0003wE-MS for qemu-devel@nongnu.org; Thu, 22 Aug 2013 12:12:07 -0400 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.5 \(1508\)) From: Eduardo Habkost In-Reply-To: <1377185968-13129-1-git-send-email-drjones@redhat.com> Date: Thu, 22 Aug 2013 13:12:00 -0300 Content-Transfer-Encoding: quoted-printable Message-Id: References: <1377185968-13129-1-git-send-email-drjones@redhat.com> Subject: Re: [Qemu-devel] [PATCH] kvm: warn if num cpus is greater than num recommended List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Andrew Jones Cc: kvm@vger.kernel.org, gleb@redhat.com, libvir-list@redhat.com, mtosatti@redhat.com, qemu-devel developers , pbonzini@redhat.com On 22/08/2013, at 12:39, Andrew Jones wrote: > The comment in kvm_max_vcpus() states that it's using the recommended > procedure from the kernel API documentation to get the max number > of vcpus that kvm supports. It is, but by always returning the > maximum number supported. The maximum number should only be used > for development purposes. qemu should check KVM_CAP_NR_VCPUS for > the recommended number of vcpus. This patch adds a warning if a user > specifies a number of cpus between the recommended and max. >=20 > Signed-off-by: Andrew Jones CCing libvir-list. It is probably interesting for libvirt to expose or = warn about the recommended VCPU limit somehow, and in this case a simple = warning on stderr won't be enough. > --- > kvm-all.c | 45 +++++++++++++++++++++++++++------------------ > 1 file changed, 27 insertions(+), 18 deletions(-) >=20 > diff --git a/kvm-all.c b/kvm-all.c > index 716860f617455..9092e13ae60ea 100644 > --- a/kvm-all.c > +++ b/kvm-all.c > @@ -1313,24 +1313,24 @@ static int kvm_irqchip_create(KVMState *s) > return 0; > } >=20 > -static int kvm_max_vcpus(KVMState *s) > +/* Find number of supported CPUs using the recommended > + * procedure from the kernel API documentation to cope with > + * older kernels that may be missing capabilities. > + */ > +static int kvm_recommended_vcpus(KVMState *s) > { > int ret; >=20 > - /* 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 =3D kvm_check_extension(s, KVM_CAP_MAX_VCPUS); > - if (ret) { > - return ret; > - } > ret =3D kvm_check_extension(s, KVM_CAP_NR_VCPUS); > - if (ret) { > - return ret; > - } > + return (ret) ? ret : 4; > +} >=20 > - return 4; > +static int kvm_max_vcpus(KVMState *s) > +{ > + int ret; > + > + ret =3D kvm_check_extension(s, KVM_CAP_MAX_VCPUS); > + return (ret) ? ret : kvm_recommended_vcpus(s); > } >=20 > int kvm_init(void) > @@ -1383,12 +1383,21 @@ int kvm_init(void) > goto err; > } >=20 > - max_vcpus =3D kvm_max_vcpus(s); > + max_vcpus =3D kvm_recommended_vcpus(s); > if (smp_cpus > max_vcpus) { > - ret =3D -EINVAL; > - fprintf(stderr, "Number of SMP cpus requested (%d) exceeds = max cpus " > - "supported by KVM (%d)\n", smp_cpus, max_vcpus); > - goto err; > + fprintf(stderr, > + "Warning: Number of SMP cpus requested (%d) exceeds " > + "recommended cpus supported by KVM (%d)\n", > + smp_cpus, max_vcpus); > + > + max_vcpus =3D kvm_max_vcpus(s); > + if (smp_cpus > max_vcpus) { > + ret =3D -EINVAL; > + fprintf(stderr, "Number of SMP cpus requested (%d) = exceeds " > + "max cpus supported by KVM (%d)\n", > + smp_cpus, max_vcpus); > + goto err; > + } > } >=20 > s->vmfd =3D kvm_ioctl(s, KVM_CREATE_VM, 0); > --=20 > 1.8.1.4 >=20 --=20 Eduardo=09