xref: /illumos-kvm/kvm_impl.h (revision 2a9ff8dc)
1 /*
2  * This header files contains pieces necessary for the illumos implementation of
3  * the kvm driver. These definitions should not be exported to userland.
4  */
5 /*
6  * GPL HEADER START
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * GPL HEADER END
22  *
23  * Copyright 2011 Joyent, Inc. All Rights Reserved.
24  */
25 
26 #ifndef	__KVM_IMPL_H
27 #define	__KVM_IMPL_H
28 
29 #include <sys/kstat.h>
30 #include <sys/sdt.h>
31 
32 #define	XXX_KVM_PROBE DTRACE_PROBE2(kvm__xxx, \
33 	char *, __FILE__, int, __LINE__)
34 #define	XXX_KVM_SYNC_PROBE DTRACE_PROBE2(kvm__xxx__sync, \
35 	char *, __FILE__, int, __LINE__)
36 
37 #define	KVM_TRACE(name)							\
38 	DTRACE_PROBE(kvm__##name);
39 
40 #define	KVM_TRACE1(name, type1, arg1)					\
41 	DTRACE_PROBE1(kvm__##name, type1, arg1);
42 
43 #define	KVM_TRACE2(name, type1, arg1, type2, arg2)			\
44 	DTRACE_PROBE2(kvm__##name, type1, arg1, type2, arg2);
45 
46 #define	KVM_TRACE3(name, type1, arg1, type2, arg2, type3, arg3)		\
47 	DTRACE_PROBE3(kvm__##name, type1, arg1, type2, arg2, type3, arg3);
48 
49 #define	KVM_TRACE4(name, type1, arg1, type2, arg2, type3, arg3,		\
50 	    type4, arg4)						\
51 	DTRACE_PROBE4(kvm__##name, type1, arg1, type2, arg2, 		\
52 	    type3, arg3, type4, arg4);
53 
54 #define	KVM_TRACE5(name, type1, arg1, type2, arg2, type3, arg3,		\
55 	    type4, arg4, type5, arg5)					\
56 	DTRACE_PROBE5(kvm__##name, type1, arg1, type2, arg2, 		\
57 	    type3, arg3, type4, arg4, type5, arg5);
58 
59 #define	KVM_TRACE6(name, type1, arg1, type2, arg2, type3, arg3,		\
60 	    type4, arg4, type5, arg5, type6, arg6)			\
61 	DTRACE_PROBE6(kvm__##name, type1, arg1, type2, arg2, 		\
62 	    type3, arg3, type4, arg4, type5, arg5, type6, arg6);
63 
64 typedef struct kvm_vcpu_stats {
65 	kstat_named_t kvmvs_id;			/* instance of associated kvm */
66 	kstat_named_t kvmvs_nmi_injections;	/* number of NMI injections */
67 	kstat_named_t kvmvs_irq_injections;	/* number of IRQ injections */
68 	kstat_named_t kvmvs_fpu_reload;		/* number of FPU reloads */
69 	kstat_named_t kvmvs_host_state_reload;	/* host state (re)loads */
70 	kstat_named_t kvmvs_insn_emulation;	/* instruction emulation */
71 	kstat_named_t kvmvs_insn_emulation_fail;	/* emulation failures */
72 	kstat_named_t kvmvs_exits;		/* total VM exits */
73 	kstat_named_t kvmvs_halt_exits;		/* exits due to HLT */
74 	kstat_named_t kvmvs_irq_exits;		/* exits due to IRQ */
75 	kstat_named_t kvmvs_io_exits;		/* exits due to I/O instrn */
76 	kstat_named_t kvmvs_mmio_exits;		/* exits due to mem mppd I/O */
77 	kstat_named_t kvmvs_nmi_window_exits;	/* exits due to NMI window */
78 	kstat_named_t kvmvs_irq_window_exits;	/* exits due to IRQ window */
79 	kstat_named_t kvmvs_request_irq_exits;	/* exits due to requested IRQ */
80 	kstat_named_t kvmvs_signal_exits;	/* exits due to pending sig */
81 	kstat_named_t kvmvs_halt_wakeup;	/* wakeups from HLT */
82 	kstat_named_t kvmvs_invlpg;		/* INVLPG instructions */
83 	kstat_named_t kvmvs_pf_guest;		/* injected guest pagefaults */
84 	kstat_named_t kvmvs_pf_fixed;		/* fixed pagefaults */
85 	kstat_named_t kvmvs_hypercalls;		/* hypercalls (VMCALL instrn) */
86 	kstat_named_t kvmvs_zonename;		/* vcpu zone name */
87 } kvm_vcpu_stats_t;
88 
89 #define	KVM_VCPU_KSTAT_INIT(vcpu, field, name) \
90 	kstat_named_init(&((vcpu)->kvcpu_stats.field), name, KSTAT_DATA_UINT64);
91 
92 #define	KVM_VCPU_KSTAT_INC(vcpu, field) \
93 	(vcpu)->kvcpu_stats.field.value.ui64++;
94 
95 typedef struct kvm_stats {
96 	kstat_named_t kvmks_pid;		/* PID of opening process */
97 	kstat_named_t kvmks_mmu_pte_write;	/* page table entry writes */
98 	kstat_named_t kvmks_mmu_pte_zapped;	/* zapped page table entries */
99 	kstat_named_t kvmks_mmu_pte_updated;	/* page table entry updates */
100 	kstat_named_t kvmks_mmu_flooded;	/* # of pages flooded */
101 	kstat_named_t kvmks_mmu_cache_miss;	/* misses in page cache */
102 	kstat_named_t kvmks_mmu_recycled;	/* recycles from free list */
103 	kstat_named_t kvmks_remote_tlb_flush;	/* remote TLB flushes */
104 	kstat_named_t kvmks_lpages;		/* large pages in use */
105 	kstat_named_t kvmks_mmu_unsync_page;	/* number of unsynced pages */
106 	kstat_named_t kvmks_zonename;		/* zone this is running in */
107 } kvm_stats_t;
108 
109 #define	KVM_KSTAT_INIT(kvmp, field, name) \
110 	kstat_named_init(&((kvmp)->kvm_stats.field), name, KSTAT_DATA_UINT64);
111 
112 #define	KVM_KSTAT_INC(kvmp, field) \
113 	(kvmp)->kvm_stats.field.value.ui64++;
114 
115 #define	KVM_KSTAT_DEC(kvmp, field) \
116 	(kvmp)->kvm_stats.field.value.ui64--;
117 
118 
119 #ifndef ARRAY_SIZE
120 #define	ARRAY_SIZE(x) (sizeof (x)/sizeof (x[0]))
121 #endif /* ARRAY_SIZE */
122 
123 #endif
124