From patchwork Sun Sep 13 16:09:55 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 47169 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n8DGA1BG010084 for ; Sun, 13 Sep 2009 16:10:01 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754810AbZIMQJ4 (ORCPT ); Sun, 13 Sep 2009 12:09:56 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754809AbZIMQJz (ORCPT ); Sun, 13 Sep 2009 12:09:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:8188 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754794AbZIMQJz (ORCPT ); Sun, 13 Sep 2009 12:09:55 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8DG9wQh017847 for ; Sun, 13 Sep 2009 12:09:58 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8DG9v7U018368; Sun, 13 Sep 2009 12:09:58 -0400 Received: from localhost.localdomain (cleopatra.tlv.redhat.com [10.35.255.11]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id C39BD25004D; Sun, 13 Sep 2009 19:09:56 +0300 (IDT) From: Avi Kivity To: Marcelo Tosatti Cc: kvm@vger.kernel.org Subject: [PATCH QEMU-KVM 1/2] test: Allow adding mode vmexit latency tests Date: Sun, 13 Sep 2009 19:09:55 +0300 Message-Id: <1252858196-4870-2-git-send-email-avi@redhat.com> In-Reply-To: <1252858196-4870-1-git-send-email-avi@redhat.com> References: <1252858196-4870-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Make the latency test run on an array of function pointers, which can be expanded with more tests. Signed-off-by: Avi Kivity --- kvm/user/test/x86/vmexit.c | 32 ++++++++++++++++++++++++++++---- 1 files changed, 28 insertions(+), 4 deletions(-) diff --git a/kvm/user/test/x86/vmexit.c b/kvm/user/test/x86/vmexit.c index 981d6c1..364837f 100644 --- a/kvm/user/test/x86/vmexit.c +++ b/kvm/user/test/x86/vmexit.c @@ -24,16 +24,40 @@ static inline unsigned long long rdtsc() # define R "e" #endif -int main() +static void cpuid(void) +{ + asm volatile ("push %%"R "bx; cpuid; pop %%"R "bx" + : : : "eax", "ecx", "edx"); +} + +static struct test { + void (*func)(void); + const char *name; +} tests[] = { + { cpuid, "cpuid", }, +}; + +static void do_test(struct test *test) { int i; unsigned long long t1, t2; + void (*func)(void) = test->func; t1 = rdtsc(); for (i = 0; i < N; ++i) - asm volatile ("push %%"R "bx; cpuid; pop %%"R "bx" - : : : "eax", "ecx", "edx"); + func(); t2 = rdtsc(); - printf("vmexit latency: %d\n", (int)((t2 - t1) / N)); + printf("%s %d\n", test->name, (int)((t2 - t1) / N)); +} + +#define ARRAY_SIZE(_x) (sizeof(_x) / sizeof((_x)[0])) + +int main(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(tests); ++i) + do_test(&tests[i]); + return 0; }