From patchwork Wed Sep 16 09:25:46 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 47878 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 n8G9QbnO009638 for ; Wed, 16 Sep 2009 09:26:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758513AbZIPJ0a (ORCPT ); Wed, 16 Sep 2009 05:26:30 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1758272AbZIPJ03 (ORCPT ); Wed, 16 Sep 2009 05:26:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44494 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758264AbZIPJ0K (ORCPT ); Wed, 16 Sep 2009 05:26:10 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8G9QE4R025672 for ; Wed, 16 Sep 2009 05:26:14 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8G9QClg003695; Wed, 16 Sep 2009 05:26:13 -0400 Received: from localhost.localdomain (cleopatra.tlv.redhat.com [10.35.255.11]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id 16469250058; Wed, 16 Sep 2009 12:26:11 +0300 (IDT) From: Avi Kivity To: Marcelo Tosatti Cc: kvm@vger.kernel.org Subject: [PATCH QEMU-KVM 11/34] test: Allow adding mode vmexit latency tests Date: Wed, 16 Sep 2009 12:25:46 +0300 Message-Id: <1253093169-1423-12-git-send-email-avi@redhat.com> In-Reply-To: <1253093169-1423-1-git-send-email-avi@redhat.com> References: <1253093169-1423-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 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; }