From patchwork Sun Sep 19 13:56:50 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 193712 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id o8JDuHnM029687 for ; Sun, 19 Sep 2010 13:56:17 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754495Ab0ISN4I (ORCPT ); Sun, 19 Sep 2010 09:56:08 -0400 Received: from tx2ehsobe004.messaging.microsoft.com ([65.55.88.14]:28877 "EHLO TX2EHSOBE008.bigfish.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754275Ab0ISN4F (ORCPT ); Sun, 19 Sep 2010 09:56:05 -0400 Received: from mail153-tx2-R.bigfish.com (10.9.14.235) by TX2EHSOBE008.bigfish.com (10.9.40.28) with Microsoft SMTP Server id 8.1.340.0; Sun, 19 Sep 2010 13:56:04 +0000 Received: from mail153-tx2 (localhost.localdomain [127.0.0.1]) by mail153-tx2-R.bigfish.com (Postfix) with ESMTP id 821CF1268190; Sun, 19 Sep 2010 13:56:04 +0000 (UTC) X-SpamScore: 1 X-BigFish: VS1(zzzz1202hzz8275bhz32i87h2a8h43h61h) X-Spam-TCS-SCL: 0:0 X-FB-DOMAIN-IP-MATCH: fail Received: from mail153-tx2 (localhost.localdomain [127.0.0.1]) by mail153-tx2 (MessageSwitch) id 128490456449653_24102; Sun, 19 Sep 2010 13:56:04 +0000 (UTC) Received: from TX2EHSMHS009.bigfish.com (unknown [10.9.14.251]) by mail153-tx2.bigfish.com (Postfix) with ESMTP id 080DEED004B; Sun, 19 Sep 2010 13:56:04 +0000 (UTC) Received: from ausb3extmailp01.amd.com (163.181.251.8) by TX2EHSMHS009.bigfish.com (10.9.99.109) with Microsoft SMTP Server (TLS) id 14.0.482.44; Sun, 19 Sep 2010 13:56:03 +0000 Received: from ausb3twp01.amd.com ([163.181.250.37]) by ausb3extmailp01.amd.com (Switch-3.2.7/Switch-3.2.7) with SMTP id o8JDx4QE017383; Sun, 19 Sep 2010 08:59:07 -0500 X-WSS-ID: 0L8ZYP7-01-0L5-02 X-M-MSG: Received: from sausexhtp01.amd.com (sausexhtp01.amd.com [163.181.3.165]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by ausb3twp01.amd.com (Tumbleweed MailGate 3.7.2) with ESMTP id 201F4102881D; Sun, 19 Sep 2010 08:55:54 -0500 (CDT) Received: from storexhtp01.amd.com (172.24.4.3) by sausexhtp01.amd.com (163.181.3.165) with Microsoft SMTP Server (TLS) id 8.3.83.0; Sun, 19 Sep 2010 08:55:57 -0500 Received: from gwo.osrc.amd.com (165.204.16.204) by storexhtp01.amd.com (172.24.4.3) with Microsoft SMTP Server id 8.3.83.0; Sun, 19 Sep 2010 09:55:56 -0400 Received: from lemmy.osrc.amd.com (lemmy.osrc.amd.com [165.204.15.93]) by gwo.osrc.amd.com (Postfix) with ESMTP id 3E36E49C1FF; Sun, 19 Sep 2010 14:55:56 +0100 (BST) Received: by lemmy.osrc.amd.com (Postfix, from userid 1000) id 4C004A05CF; Sun, 19 Sep 2010 15:57:06 +0200 (CEST) From: Joerg Roedel To: Avi Kivity , Marcelo Tosatti CC: , Alexander Graf , Joerg Roedel Subject: [PATCH 1/2] svm: Add VMRUN/VMEXIT latency test Date: Sun, 19 Sep 2010 15:56:50 +0200 Message-ID: <1284904611-2458-2-git-send-email-joerg.roedel@amd.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1284904611-2458-1-git-send-email-joerg.roedel@amd.com> References: <1284904611-2458-1-git-send-email-joerg.roedel@amd.com> MIME-Version: 1.0 X-Reverse-DNS: unknown Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Sun, 19 Sep 2010 13:56:17 +0000 (UTC) diff --git a/x86/svm.c b/x86/svm.c index dc3098f..babd77d 100644 --- a/x86/svm.c +++ b/x86/svm.c @@ -13,6 +13,18 @@ u64 *pde[4]; u64 *pte[2048]; u64 *scratch_page; +#define LATENCY_RUNS 1000000 + +u64 tsc_start; +u64 tsc_end; + +u64 vmrun_sum, vmexit_sum; +u64 latvmrun_max; +u64 latvmrun_min; +u64 latvmexit_max; +u64 latvmexit_min; +u64 runs; + static bool npt_supported(void) { return cpuid(0x8000000A).d & 1; @@ -162,6 +174,7 @@ static bool test_run(struct test *test, struct vmcb *vmcb) vmcb->save.rip = (ulong)test_thunk; vmcb->save.rsp = (ulong)(guest_stack + ARRAY_SIZE(guest_stack)); do { + tsc_start = rdtsc(); asm volatile ( "clgi \n\t" "vmload \n\t" @@ -176,9 +189,11 @@ static bool test_run(struct test *test, struct vmcb *vmcb) : "rbx", "rcx", "rdx", "rsi", "r8", "r9", "r10", "r11" , "r12", "r13", "r14", "r15", "memory"); + tsc_end = rdtsc(); ++test->exits; } while (!test->finished(test)); + success = test->succeeded(test); printf("%s: %s\n", test->name, success ? "PASS" : "FAIL"); @@ -582,6 +597,70 @@ static bool npt_pfwalk_check(struct test *test) && (test->vmcb->control.exit_info_2 == read_cr3()); } +static void latency_prepare(struct test *test) +{ + default_prepare(test); + runs = LATENCY_RUNS; + latvmrun_min = latvmexit_min = -1ULL; + latvmrun_max = latvmexit_max = 0; + vmrun_sum = vmexit_sum = 0; +} + +static void latency_test(struct test *test) +{ + u64 cycles; + +start: + tsc_end = rdtsc(); + + cycles = tsc_end - tsc_start; + + if (cycles > latvmrun_max) + latvmrun_max = cycles; + + if (cycles < latvmrun_min) + latvmrun_min = cycles; + + vmrun_sum += cycles; + + tsc_start = rdtsc(); + + asm volatile ("vmmcall" : : : "memory"); + goto start; +} + +static bool latency_finished(struct test *test) +{ + u64 cycles; + + tsc_end = rdtsc(); + + cycles = tsc_end - tsc_start; + + if (cycles > latvmexit_max) + latvmexit_max = cycles; + + if (cycles < latvmexit_min) + latvmexit_min = cycles; + + vmexit_sum += cycles; + + test->vmcb->save.rip += 3; + + runs -= 1; + + return runs == 0; +} + +static bool latency_check(struct test *test) +{ + printf(" Latency VMRUN : max: %d min: %d avg: %d\n", latvmrun_max, + latvmrun_min, vmrun_sum / LATENCY_RUNS); + printf(" Latency VMEXIT: max: %d min: %d avg: %d\n", latvmexit_max, + latvmexit_min, vmexit_sum / LATENCY_RUNS); + return true; +} + static struct test tests[] = { { "null", default_supported, default_prepare, null_test, default_finished, null_check }, @@ -614,6 +693,8 @@ static struct test tests[] = { default_finished, npt_rw_check }, { "npt_pfwalk", npt_supported, npt_pfwalk_prepare, null_test, default_finished, npt_pfwalk_check }, + { "latency_run_exit", default_supported, latency_prepare, latency_test, + latency_finished, latency_check }, }; int main(int ac, char **av)