From patchwork Tue Jun 15 02:47:11 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Guangrong X-Patchwork-Id: 106110 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o5F2pSXI007922 for ; Tue, 15 Jun 2010 02:52:59 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757388Ab0FOCus (ORCPT ); Mon, 14 Jun 2010 22:50:48 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:64480 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1756578Ab0FOCup (ORCPT ); Mon, 14 Jun 2010 22:50:45 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 65CF0170125; Tue, 15 Jun 2010 10:50:44 +0800 (CST) Received: from fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id o5F2mL1X001623; Tue, 15 Jun 2010 10:48:21 +0800 Received: from [10.167.141.99] (unknown [10.167.141.99]) by fnst.cn.fujitsu.com (Postfix) with ESMTPA id CE3BB10C0DB; Tue, 15 Jun 2010 10:50:30 +0800 (CST) Message-ID: <4C16E9AF.2090501@cn.fujitsu.com> Date: Tue, 15 Jun 2010 10:47:11 +0800 From: Xiao Guangrong User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: Avi Kivity CC: Marcelo Tosatti , LKML , KVM list Subject: [PATCH 6/6] KVM: MMU: trace pte prefetch References: <4C16E6ED.7020009@cn.fujitsu.com> <4C16E75F.6020003@cn.fujitsu.com> <4C16E7AD.1060101@cn.fujitsu.com> <4C16E7F4.5060801@cn.fujitsu.com> <4C16E82E.5010306@cn.fujitsu.com> <4C16E867.8040606@cn.fujitsu.com> In-Reply-To: <4C16E867.8040606@cn.fujitsu.com> 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 (demeter.kernel.org [140.211.167.41]); Tue, 15 Jun 2010 02:53:15 +0000 (UTC) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 941c86b..0aaa18d 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -91,6 +91,11 @@ module_param(oos_shadow, bool, 0644); #define PTE_PREFETCH_NUM 16 +#define PREFETCH_SUCCESS 0 +#define PREFETCH_ERR_GFN2PFN 1 +#define PREFETCH_ERR_ALLOC_MEM 2 +#define PREFETCH_ERR_READ_GPTE 3 + #define PT_FIRST_AVAIL_BITS_SHIFT 9 #define PT64_SECOND_AVAIL_BITS_SHIFT 52 @@ -2066,11 +2071,16 @@ static void direct_pte_prefetch(struct kvm_vcpu *vcpu, u64 *sptep) pfn = gfn_to_pfn_atomic(vcpu->kvm, gfn); if (is_error_pfn(pfn)) { kvm_release_pfn_clean(pfn); + trace_pte_prefetch(true, PREFETCH_ERR_GFN2PFN); break; } - if (pte_prefetch_topup_memory_cache(vcpu)) + + if (pte_prefetch_topup_memory_cache(vcpu)) { + trace_pte_prefetch(true, PREFETCH_ERR_ALLOC_MEM); break; + } + trace_pte_prefetch(true, PREFETCH_SUCCESS); mmu_set_spte(vcpu, spte, ACC_ALL, ACC_ALL, 0, 0, 1, NULL, sp->role.level, gfn, pfn, true, false); } diff --git a/arch/x86/kvm/mmutrace.h b/arch/x86/kvm/mmutrace.h index 3aab0f0..1c3e84e 100644 --- a/arch/x86/kvm/mmutrace.h +++ b/arch/x86/kvm/mmutrace.h @@ -195,6 +195,32 @@ DEFINE_EVENT(kvm_mmu_page_class, kvm_mmu_prepare_zap_page, TP_ARGS(sp) ); + +#define pte_prefetch_err \ + {PREFETCH_SUCCESS, "SUCCESS" }, \ + {PREFETCH_ERR_GFN2PFN, "ERR_GFN2PFN" }, \ + {PREFETCH_ERR_ALLOC_MEM, "ERR_ALLOC_MEM" }, \ + {PREFETCH_ERR_READ_GPTE, "ERR_READ_GPTE" } + +TRACE_EVENT( + pte_prefetch, + TP_PROTO(bool direct, int err_code), + TP_ARGS(direct, err_code), + + TP_STRUCT__entry( + __field(bool, direct) + __field(int, err_code) + ), + + TP_fast_assign( + __entry->direct = direct; + __entry->err_code = err_code; + ), + + TP_printk("%s %s", __entry->direct ? "direct" : "no-direct", + __print_symbolic(__entry->err_code, pte_prefetch_err)) +); + #endif /* _TRACE_KVMMMU_H */ #undef TRACE_INCLUDE_PATH diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h index af4e041..64f2acb 100644 --- a/arch/x86/kvm/paging_tmpl.h +++ b/arch/x86/kvm/paging_tmpl.h @@ -331,6 +331,8 @@ static void FNAME(pte_prefetch)(struct kvm_vcpu *vcpu, u64 *sptep) page = gfn_to_page_atomic(vcpu->kvm, sp->gfn); if (is_error_page(page)) { kvm_release_page_clean(page); + trace_pte_prefetch(false, + PREFETCH_ERR_READ_GPTE); break; } table = kmap_atomic(page, KM_USER0); @@ -353,11 +355,16 @@ gfn_mapping: pfn = gfn_to_pfn_atomic(vcpu->kvm, gfn); if (is_error_pfn(pfn)) { kvm_release_pfn_clean(pfn); + trace_pte_prefetch(false, PREFETCH_ERR_GFN2PFN); break; } - if (pte_prefetch_topup_memory_cache(vcpu)) + if (pte_prefetch_topup_memory_cache(vcpu)) { + trace_pte_prefetch(false, PREFETCH_ERR_ALLOC_MEM); break; + } + + trace_pte_prefetch(false, PREFETCH_SUCCESS); mmu_set_spte(vcpu, spte, sp->role.access, pte_access, 0, 0, dirty, NULL, sp->role.level, gfn, pfn, true, false);