vmm_stat.h revision 250427
1221828Sgrehan/*- 2221828Sgrehan * Copyright (c) 2011 NetApp, Inc. 3221828Sgrehan * All rights reserved. 4221828Sgrehan * 5221828Sgrehan * Redistribution and use in source and binary forms, with or without 6221828Sgrehan * modification, are permitted provided that the following conditions 7221828Sgrehan * are met: 8221828Sgrehan * 1. Redistributions of source code must retain the above copyright 9221828Sgrehan * notice, this list of conditions and the following disclaimer. 10221828Sgrehan * 2. Redistributions in binary form must reproduce the above copyright 11221828Sgrehan * notice, this list of conditions and the following disclaimer in the 12221828Sgrehan * documentation and/or other materials provided with the distribution. 13221828Sgrehan * 4. Neither the name of the University nor the names of its contributors 14221828Sgrehan * may be used to endorse or promote products derived from this software 15221828Sgrehan * without specific prior written permission. 16221828Sgrehan * 17221828Sgrehan * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18221828Sgrehan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19221828Sgrehan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20221828Sgrehan * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21221828Sgrehan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22221828Sgrehan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23221828Sgrehan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24221828Sgrehan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25221828Sgrehan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26221828Sgrehan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27221828Sgrehan * SUCH DAMAGE. 28221828Sgrehan * 29221828Sgrehan * $FreeBSD: head/sys/amd64/vmm/vmm_stat.h 250427 2013-05-10 02:59:49Z neel $ 30221828Sgrehan */ 31221828Sgrehan 32221828Sgrehan#ifndef _VMM_STAT_H_ 33221828Sgrehan#define _VMM_STAT_H_ 34221828Sgrehan 35221828Sgrehanstruct vm; 36221828Sgrehan 37250427Sneel#define MAX_VMM_STAT_ELEMS 64 /* arbitrary */ 38221828Sgrehan 39248389Sneelenum vmm_stat_scope { 40248389Sneel VMM_STAT_SCOPE_ANY, 41248389Sneel VMM_STAT_SCOPE_INTEL, /* Intel VMX specific statistic */ 42248389Sneel VMM_STAT_SCOPE_AMD, /* AMD SVM specific statistic */ 43248389Sneel}; 44248389Sneel 45221828Sgrehanstruct vmm_stat_type { 46221828Sgrehan int index; /* position in the stats buffer */ 47250427Sneel int nelems; /* standalone or array */ 48248389Sneel const char *desc; /* description of statistic */ 49248389Sneel enum vmm_stat_scope scope; 50221828Sgrehan}; 51221828Sgrehan 52221828Sgrehanvoid vmm_stat_init(void *arg); 53221828Sgrehan 54250427Sneel#define VMM_STAT_DEFINE(type, nelems, desc, scope) \ 55221828Sgrehan struct vmm_stat_type type[1] = { \ 56250427Sneel { -1, nelems, desc, scope } \ 57221828Sgrehan }; \ 58221828Sgrehan SYSINIT(type##_stat, SI_SUB_KLD, SI_ORDER_ANY, vmm_stat_init, type) 59221828Sgrehan 60248389Sneel#define VMM_STAT_DECLARE(type) \ 61248389Sneel extern struct vmm_stat_type type[1] 62248389Sneel 63248389Sneel#define VMM_STAT(type, desc) \ 64250427Sneel VMM_STAT_DEFINE(type, 1, desc, VMM_STAT_SCOPE_ANY) 65248389Sneel#define VMM_STAT_INTEL(type, desc) \ 66250427Sneel VMM_STAT_DEFINE(type, 1, desc, VMM_STAT_SCOPE_INTEL) 67248389Sneel#define VMM_STAT_AMD(type, desc) \ 68250427Sneel VMM_STAT_DEFINE(type, 1, desc, VMM_STAT_SCOPE_AMD) 69248389Sneel 70250427Sneel#define VMM_STAT_ARRAY(type, nelems, desc) \ 71250427Sneel VMM_STAT_DEFINE(type, nelems, desc, VMM_STAT_SCOPE_ANY) 72250427Sneel 73221828Sgrehanvoid *vmm_stat_alloc(void); 74221828Sgrehanvoid vmm_stat_free(void *vp); 75221828Sgrehan 76221828Sgrehan/* 77221828Sgrehan * 'buf' should be at least fit 'MAX_VMM_STAT_TYPES' entries 78221828Sgrehan */ 79221828Sgrehanint vmm_stat_copy(struct vm *vm, int vcpu, int *num_stats, uint64_t *buf); 80250427Sneelint vmm_stat_desc_copy(int index, char *buf, int buflen); 81221828Sgrehan 82221828Sgrehanstatic void __inline 83250427Sneelvmm_stat_array_incr(struct vm *vm, int vcpu, struct vmm_stat_type *vst, 84250427Sneel int statidx, uint64_t x) 85250427Sneel{ 86250427Sneel#ifdef VMM_KEEP_STATS 87250427Sneel uint64_t *stats; 88250427Sneel 89250427Sneel stats = vcpu_stats(vm, vcpu); 90250427Sneel 91250427Sneel if (vst->index >= 0 && statidx < vst->nelems) 92250427Sneel stats[vst->index + statidx] += x; 93250427Sneel#endif 94250427Sneel} 95250427Sneel 96250427Sneel 97250427Sneelstatic void __inline 98221828Sgrehanvmm_stat_incr(struct vm *vm, int vcpu, struct vmm_stat_type *vst, uint64_t x) 99221828Sgrehan{ 100250427Sneel 101250427Sneel#ifdef VMM_KEEP_STATS 102250427Sneel vmm_stat_array_incr(vm, vcpu, vst, 0, x); 103221828Sgrehan#endif 104221828Sgrehan} 105221828Sgrehan 106248389SneelVMM_STAT_DECLARE(VCPU_MIGRATIONS); 107248389SneelVMM_STAT_DECLARE(VMEXIT_COUNT); 108248389SneelVMM_STAT_DECLARE(VMEXIT_EXTINT); 109248389SneelVMM_STAT_DECLARE(VMEXIT_HLT); 110248935SneelVMM_STAT_DECLARE(VMEXIT_CR_ACCESS); 111248935SneelVMM_STAT_DECLARE(VMEXIT_RDMSR); 112248935SneelVMM_STAT_DECLARE(VMEXIT_WRMSR); 113248935SneelVMM_STAT_DECLARE(VMEXIT_MTRAP); 114248935SneelVMM_STAT_DECLARE(VMEXIT_PAUSE); 115248935SneelVMM_STAT_DECLARE(VMEXIT_INTR_WINDOW); 116248935SneelVMM_STAT_DECLARE(VMEXIT_NMI_WINDOW); 117248935SneelVMM_STAT_DECLARE(VMEXIT_INOUT); 118248935SneelVMM_STAT_DECLARE(VMEXIT_CPUID); 119248935SneelVMM_STAT_DECLARE(VMEXIT_EPT_FAULT); 120248935SneelVMM_STAT_DECLARE(VMEXIT_UNKNOWN); 121248935SneelVMM_STAT_DECLARE(VMEXIT_ASTPENDING); 122248935SneelVMM_STAT_DECLARE(VMEXIT_USERSPACE); 123221828Sgrehan#endif 124