From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56976) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLFo3-0004iv-VX for qemu-devel@nongnu.org; Fri, 31 Jul 2015 15:17:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZLFnz-0005Z1-Cj for qemu-devel@nongnu.org; Fri, 31 Jul 2015 15:17:23 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57063) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLFnz-0005Yx-56 for qemu-devel@nongnu.org; Fri, 31 Jul 2015 15:17:19 -0400 Date: Fri, 31 Jul 2015 21:17:12 +0200 From: Andrew Jones Message-ID: <20150731191712.GI3680@hawk.localdomain> References: <1438358041-18021-1-git-send-email-alex.bennee@linaro.org> <1438358041-18021-10-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1438358041-18021-10-git-send-email-alex.bennee@linaro.org> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [kvm-unit-tests PATCH v5 09/11] arm: query /dev/kvm for maximum vcpus List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alex =?iso-8859-1?Q?Benn=E9e?= Cc: mttcg@greensocs.com, peter.maydell@linaro.org, Alex =?iso-8859-1?Q?Benn=E9e?= , claudio.fontana@huawei.com, kvm@vger.kernel.org, a.spyridakis@virtualopensystems.com, mark.burton@greensocs.com, a.rigo@virtualopensystems.com, qemu-devel@nongnu.org, fred.konrad@greensocs.com On Fri, Jul 31, 2015 at 04:53:59PM +0100, Alex Benn=E9e wrote: > From: Alex Benn=E9e >=20 > The previous $(getconf _NPROCESSORS_CONF) isn't correct as the default > maximum VCPU configuration is 4 on arm64 machines which typically have > more actual cores. The kernel should probably bump that up to 8, but that's an aside, as it wouldn't resolve the general issue. For this patch, I don't think we need a C utility as we can probe with QEMU, and thus just need a script. $QEMU -machine virt,accel=3Dkvm -smp 9 Number of SMP cpus requested (9), exceeds max cpus supported by machine= `virt' (8) The script can live in $root/scripts/, which is a directory recently created for standalone test support. Thanks, drew >=20 > This introduces a simple utility program to query the KVM capabilities > and use the correct maximum number of vcpus. >=20 > [FOR DISCUSSION: this fails on TCG which could use _NPROCESSORS_CONF] >=20 > Signed-off-by: Alex Benn=E9e > --- > arm/unittests.cfg | 10 +++++----- > arm/utils/kvm-query.c | 41 ++++++++++++++++++++++++++++++++++++= +++++ > config/config-arm-common.mak | 8 +++++++- > 3 files changed, 53 insertions(+), 6 deletions(-) > create mode 100644 arm/utils/kvm-query.c >=20 > diff --git a/arm/unittests.cfg b/arm/unittests.cfg > index 19d72ad..7a3a32b 100644 > --- a/arm/unittests.cfg > +++ b/arm/unittests.cfg > @@ -32,30 +32,30 @@ groups =3D selftest > # Test SMP support > [selftest::smp] > file =3D selftest.flat > -smp =3D $(getconf _NPROCESSORS_CONF) > +smp =3D $(./arm/utils/kvm-query max_vcpu) > extra_params =3D -append 'smp' > groups =3D selftest > =20 > # TLB Torture Tests > [tlbflush::all_other] > file =3D tlbflush-test.flat > -smp =3D $(getconf _NPROCESSORS_CONF) > +smp =3D $(./arm/utils/kvm-query max_vcpu) > groups =3D tlbflush > =20 > [tlbflush::page_other] > file =3D tlbflush-test.flat > -smp =3D $(getconf _NPROCESSORS_CONF) > +smp =3D $(./arm/utils/kvm-query max_vcpu) > extra_params =3D -append 'page' > groups =3D tlbflush > =20 > [tlbflush::all_self] > file =3D tlbflush-test.flat > -smp =3D $(getconf _NPROCESSORS_CONF) > +smp =3D $(./arm/utils/kvm-query max_vcpu) > extra_params =3D -append 'self' > groups =3D tlbflush > =20 > [tlbflush::page_self] > file =3D tlbflush-test.flat > -smp =3D $(getconf _NPROCESSORS_CONF) > +smp =3D $(./arm/utils/kvm-query max_vcpu) > extra_params =3D -append 'page self' > groups =3D tlbflush > diff --git a/arm/utils/kvm-query.c b/arm/utils/kvm-query.c > new file mode 100644 > index 0000000..4f979b1 > --- /dev/null > +++ b/arm/utils/kvm-query.c > @@ -0,0 +1,41 @@ > +/* > + * kvm-query.c > + * > + * A simple utility to query KVM capabilities. > + */ > + > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > + > +#include > + > +int get_max_vcpu(void) > +{ > + int fd =3D open("/dev/kvm", O_RDWR); > + if (fd>0) { > + int ret =3D ioctl(fd, KVM_CHECK_EXTENSION, KVM_CAP_MAX_VCPUS); > + printf("%d\n", ret > 0 ? ret : 0); > + close(fd); > + return 0; > + } else { > + return -1; > + } > +} > + > +int main(int argc, char **argv) > +{ > + for (int i=3D0; i + char *arg =3D argv[i]; > + if (strcmp(arg, "max_vcpu") =3D=3D 0) { > + return get_max_vcpu(); > + } > + } > + > + return -1; > +} > diff --git a/config/config-arm-common.mak b/config/config-arm-common.ma= k > index 164199b..9c7607b 100644 > --- a/config/config-arm-common.mak > +++ b/config/config-arm-common.mak > @@ -13,7 +13,9 @@ tests-common =3D $(TEST_DIR)/selftest.flat > tests-common +=3D $(TEST_DIR)/spinlock-test.flat > tests-common +=3D $(TEST_DIR)/tlbflush-test.flat > =20 > -all: test_cases > +utils-common =3D $(TEST_DIR)/utils/kvm-query > + > +all: test_cases utils > =20 > ################################################################## > phys_base =3D $(LOADADDR) > @@ -58,6 +60,9 @@ FLATLIBS =3D $(libcflat) $(LIBFDT_archive) $(libgcc) = $(libeabi) > $(libeabi): $(eabiobjs) > $(AR) rcs $@ $^ > =20 > +$(TEST_DIR)/utils/%: $(TEST_DIR)/utils/%.c > + $(CC) -std=3Dgnu99 -o $@ $^ > + > arm_clean: libfdt_clean asm_offsets_clean > $(RM) $(TEST_DIR)/*.{o,flat,elf} $(libeabi) $(eabiobjs) \ > $(TEST_DIR)/.*.d lib/arm/.*.d > @@ -69,6 +74,7 @@ tests_and_config =3D $(TEST_DIR)/*.flat $(TEST_DIR)/u= nittests.cfg > generated_files =3D $(asm-offsets) > =20 > test_cases: $(generated_files) $(tests-common) $(tests) > +utils: $(utils-common) > =20 > $(TEST_DIR)/selftest.elf: $(cstart.o) $(TEST_DIR)/selftest.o > $(TEST_DIR)/spinlock-test.elf: $(cstart.o) $(TEST_DIR)/spinlock-test.o > --=20 > 2.5.0 >=20 >=20