From patchwork Thu Dec 13 12:11:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1871961 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 18BA8DF2EF for ; Thu, 13 Dec 2012 12:12:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753849Ab2LMMME (ORCPT ); Thu, 13 Dec 2012 07:12:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49447 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753411Ab2LMMMD (ORCPT ); Thu, 13 Dec 2012 07:12:03 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qBDCC2di019041 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 13 Dec 2012 07:12:02 -0500 Received: from yakj.usersys.redhat.com (ovpn-112-24.ams2.redhat.com [10.36.112.24]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id qBDCBxTU015242; Thu, 13 Dec 2012 07:12:01 -0500 From: Paolo Bonzini To: kvm@vger.kernel.org Cc: mtosatti@redhat.com Subject: [PATCH kvm-unit-tests] vmexit: time the number of cycles for simple PIO Date: Thu, 13 Dec 2012 13:11:56 +0100 Message-Id: <1355400716-21359-2-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This patch adds two scenarios to the vmexit test. One is a very simple PIO case that is handled in the kernel (reading from ELCR). The other is an unmapped PIO that is handled in userspace. The difference between the two is roughly the cost of a userspace exit; the existing inl_from_pmtimer test is not precise enough, because the device model has a pretty high cost. With the current code in KVM, the difference between inl_from_kernel and vmcall is the cost of emulation. This is arguably a bug, because inl_from_kernel need not go through the whole emulation stuff. Example: vmcall 3898 inl_from_pmtimer 24615 inl_from_qemu 20574 inl_from_kernel 7237 So the cost of exiting to userspace is 13000 cycles on this machine, and the cost of emulation is 3300 cycles. Suggested-by: Avi Kivity Signed-off-by: Paolo Bonzini --- x86/vmexit.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/x86/vmexit.c b/x86/vmexit.c index ad8ab55..545a8bc 100644 --- a/x86/vmexit.c +++ b/x86/vmexit.c @@ -4,6 +4,13 @@ #include "processor.h" #include "atomic.h" +static unsigned int inb(unsigned short port) +{ + unsigned int val; + asm volatile("xorl %0, %0; inb %w1, %b0" : "=a"(val) : "Nd"(port)); + return val; +} + static unsigned int inl(unsigned short port) { unsigned int val; @@ -82,6 +89,16 @@ static void inl_pmtimer(void) inl(0xb008); } +static void inl_nop_qemu(void) +{ + inl(0x1234); +} + +static void inl_nop_kernel(void) +{ + inb(0x4d0); +} + static void ple_round_robin(void) { struct counter { @@ -116,6 +133,8 @@ static struct test { { mov_to_cr8, "mov_to_cr8" , .parallel = 1, }, #endif { inl_pmtimer, "inl_from_pmtimer", .parallel = 1, }, + { inl_nop_qemu, "inl_from_qemu", .parallel = 1 }, + { inl_nop_kernel, "inl_from_kernel", .parallel = 1 }, { ipi, "ipi", is_smp, .parallel = 0, }, { ipi_halt, "ipi+halt", is_smp, .parallel = 0, }, { ple_round_robin, "ple-round-robin", .parallel = 1 },