From patchwork Fri Jul 31 15:53:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 502681 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 59DB71402BB for ; Sat, 1 Aug 2015 01:58:24 +1000 (AEST) Received: from localhost ([::1]:44898 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLChS-0000Ok-KM for incoming@patchwork.ozlabs.org; Fri, 31 Jul 2015 11:58:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLCdq-0000zD-4O for qemu-devel@nongnu.org; Fri, 31 Jul 2015 11:54:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZLCdi-0005uv-Ha for qemu-devel@nongnu.org; Fri, 31 Jul 2015 11:54:38 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:36631) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZLCdi-0005ul-9X for qemu-devel@nongnu.org; Fri, 31 Jul 2015 11:54:30 -0400 Received: by wicgj17 with SMTP id gj17so23709349wic.1 for ; Fri, 31 Jul 2015 08:54:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=A9sxb5CwBcw0kV17bhtUxp9Juwxxu2hHId3lWCM9urY=; b=Cd+A1OKkdOPNSubzTORAowXsvE6RPiilI7sUDJ+TspZRwq1R3VwNSYOV8DHx/0XNbx fde+aSmPdMtfyhG6vkd+D25nqECfz1ejfr3Sk3RIdIp6AsWV+j6lm8CIlwKQBW2vnZIa RVhS5fwOV9ObVSn7K/qt5swgel8ApKGZc4e4lIK8SWOoGEXTXFOYcUcfb4D1iBVs10nv Cma1dSByEeTD3udW6jkgXGwTqlNSVivPybAZ0IgfrxhWiEVHdGLUq/AHOST2LV7nOQ25 sPAyqRW7CGzed+mAjohDMVDcG0WlfytAV6HyrpDjOG+gf35cGCJiJvfUlzUVqqOPCeJB az6A== X-Gm-Message-State: ALoCoQlT828RazBBzWAziPFOPxIJYpIg8Qt7TQkNYQoKpHfntQr3RNC+DhcBX8F4Etl9nrGth344 X-Received: by 10.194.89.98 with SMTP id bn2mr7878195wjb.153.1438358069610; Fri, 31 Jul 2015 08:54:29 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id z9sm5110481wiv.9.2015.07.31.08.54.27 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 31 Jul 2015 08:54:28 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 6C43D3E135D; Fri, 31 Jul 2015 16:54:23 +0100 (BST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: mttcg@listserver.greensocs.com, mark.burton@greensocs.com, fred.konrad@greensocs.com Date: Fri, 31 Jul 2015 16:53:59 +0100 Message-Id: <1438358041-18021-10-git-send-email-alex.bennee@linaro.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1438358041-18021-1-git-send-email-alex.bennee@linaro.org> References: <1438358041-18021-1-git-send-email-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.212.169 Cc: peter.maydell@linaro.org, drjones@redhat.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , kvm@vger.kernel.org, a.spyridakis@virtualopensystems.com, claudio.fontana@huawei.com, a.rigo@virtualopensystems.com, qemu-devel@nongnu.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [Qemu-devel] [kvm-unit-tests PATCH v5 09/11] arm: query /dev/kvm for maximum vcpus X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Alex Bennée 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. This introduces a simple utility program to query the KVM capabilities and use the correct maximum number of vcpus. [FOR DISCUSSION: this fails on TCG which could use _NPROCESSORS_CONF] Signed-off-by: Alex Bennée --- 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 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 = selftest # Test SMP support [selftest::smp] file = selftest.flat -smp = $(getconf _NPROCESSORS_CONF) +smp = $(./arm/utils/kvm-query max_vcpu) extra_params = -append 'smp' groups = selftest # TLB Torture Tests [tlbflush::all_other] file = tlbflush-test.flat -smp = $(getconf _NPROCESSORS_CONF) +smp = $(./arm/utils/kvm-query max_vcpu) groups = tlbflush [tlbflush::page_other] file = tlbflush-test.flat -smp = $(getconf _NPROCESSORS_CONF) +smp = $(./arm/utils/kvm-query max_vcpu) extra_params = -append 'page' groups = tlbflush [tlbflush::all_self] file = tlbflush-test.flat -smp = $(getconf _NPROCESSORS_CONF) +smp = $(./arm/utils/kvm-query max_vcpu) extra_params = -append 'self' groups = tlbflush [tlbflush::page_self] file = tlbflush-test.flat -smp = $(getconf _NPROCESSORS_CONF) +smp = $(./arm/utils/kvm-query max_vcpu) extra_params = -append 'page self' groups = 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 = open("/dev/kvm", O_RDWR); + if (fd>0) { + int ret = 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=0; i