vmm_stat.h revision 248935
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 248935 2013-03-30 17:46:03Z neel $
30221828Sgrehan */
31221828Sgrehan
32221828Sgrehan#ifndef _VMM_STAT_H_
33221828Sgrehan#define	_VMM_STAT_H_
34221828Sgrehan
35221828Sgrehanstruct vm;
36221828Sgrehan
37221828Sgrehan#define	MAX_VMM_STAT_TYPES	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 */
47248389Sneel	const char *desc;		/* description of statistic */
48248389Sneel	enum vmm_stat_scope scope;
49221828Sgrehan};
50221828Sgrehan
51221828Sgrehanvoid	vmm_stat_init(void *arg);
52221828Sgrehan
53248389Sneel#define	VMM_STAT_DEFINE(type, desc, scope)				\
54221828Sgrehan	struct vmm_stat_type type[1] = {				\
55248389Sneel		{ -1, desc, scope }					\
56221828Sgrehan	};								\
57221828Sgrehan	SYSINIT(type##_stat, SI_SUB_KLD, SI_ORDER_ANY, vmm_stat_init, type)
58221828Sgrehan
59248389Sneel#define	VMM_STAT_DECLARE(type)						\
60248389Sneel	extern struct vmm_stat_type type[1]
61248389Sneel
62248389Sneel#define	VMM_STAT(type, desc)		\
63248389Sneel	VMM_STAT_DEFINE(type, desc, VMM_STAT_SCOPE_ANY)
64248389Sneel#define	VMM_STAT_INTEL(type, desc)	\
65248389Sneel	VMM_STAT_DEFINE(type, desc, VMM_STAT_SCOPE_INTEL)
66248389Sneel#define	VMM_STAT_AMD(type, desc)	\
67248389Sneel	VMM_STAT_DEFINE(type, desc, VMM_STAT_SCOPE_AMD)
68248389Sneel
69221828Sgrehanvoid	*vmm_stat_alloc(void);
70221828Sgrehanvoid 	vmm_stat_free(void *vp);
71221828Sgrehan
72221828Sgrehan/*
73221828Sgrehan * 'buf' should be at least fit 'MAX_VMM_STAT_TYPES' entries
74221828Sgrehan */
75221828Sgrehanint	vmm_stat_copy(struct vm *vm, int vcpu, int *num_stats, uint64_t *buf);
76221828Sgrehanconst char *vmm_stat_desc(int index);
77221828Sgrehan
78221828Sgrehanstatic void __inline
79221828Sgrehanvmm_stat_incr(struct vm *vm, int vcpu, struct vmm_stat_type *vst, uint64_t x)
80221828Sgrehan{
81221828Sgrehan#ifdef	VMM_KEEP_STATS
82221828Sgrehan	uint64_t *stats = vcpu_stats(vm, vcpu);
83221828Sgrehan	if (vst->index >= 0)
84221828Sgrehan		stats[vst->index] += x;
85221828Sgrehan#endif
86221828Sgrehan}
87221828Sgrehan
88248389SneelVMM_STAT_DECLARE(VCPU_MIGRATIONS);
89248389SneelVMM_STAT_DECLARE(VMEXIT_COUNT);
90248389SneelVMM_STAT_DECLARE(VMEXIT_EXTINT);
91248389SneelVMM_STAT_DECLARE(VMEXIT_HLT);
92248935SneelVMM_STAT_DECLARE(VMEXIT_CR_ACCESS);
93248935SneelVMM_STAT_DECLARE(VMEXIT_RDMSR);
94248935SneelVMM_STAT_DECLARE(VMEXIT_WRMSR);
95248935SneelVMM_STAT_DECLARE(VMEXIT_MTRAP);
96248935SneelVMM_STAT_DECLARE(VMEXIT_PAUSE);
97248935SneelVMM_STAT_DECLARE(VMEXIT_INTR_WINDOW);
98248935SneelVMM_STAT_DECLARE(VMEXIT_NMI_WINDOW);
99248935SneelVMM_STAT_DECLARE(VMEXIT_INOUT);
100248935SneelVMM_STAT_DECLARE(VMEXIT_CPUID);
101248935SneelVMM_STAT_DECLARE(VMEXIT_EPT_FAULT);
102248935SneelVMM_STAT_DECLARE(VMEXIT_UNKNOWN);
103248935SneelVMM_STAT_DECLARE(VMEXIT_ASTPENDING);
104248935SneelVMM_STAT_DECLARE(VMEXIT_USERSPACE);
105221828Sgrehan#endif
106