Print this page
13275 bhyve needs richer INIT/SIPI support
Reviewed by: Robert Mustacchi <rm@fingolfin.org>
Approved by: Gordon Ross <gordon.w.ross@gmail.com>
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/i86pc/io/vmm/vmm_stat.c
+++ new/usr/src/uts/i86pc/io/vmm/vmm_stat.c
1 1 /*-
2 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 3 *
4 4 * Copyright (c) 2011 NetApp, Inc.
5 5 * All rights reserved.
6 6 *
7 7 * Redistribution and use in source and binary forms, with or without
8 8 * modification, are permitted provided that the following conditions
9 9 * are met:
10 10 * 1. Redistributions of source code must retain the above copyright
11 11 * notice, this list of conditions and the following disclaimer.
12 12 * 2. Redistributions in binary form must reproduce the above copyright
13 13 * notice, this list of conditions and the following disclaimer in the
14 14 * documentation and/or other materials provided with the distribution.
15 15 *
16 16 * THIS SOFTWARE IS PROVIDED BY NETAPP, INC ``AS IS'' AND
17 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 19 * ARE DISCLAIMED. IN NO EVENT SHALL NETAPP, INC OR CONTRIBUTORS BE LIABLE
20 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 26 * SUCH DAMAGE.
27 27 *
28 28 * $FreeBSD$
29 29 */
30 30
31 31 #include <sys/cdefs.h>
32 32 __FBSDID("$FreeBSD$");
33 33
34 34 #include <sys/param.h>
35 35 #include <sys/kernel.h>
36 36 #include <sys/systm.h>
37 37 #include <sys/malloc.h>
38 38
39 39 #include <machine/vmm.h>
40 40 #include "vmm_util.h"
41 41 #include "vmm_stat.h"
42 42
43 43 /*
44 44 * 'vst_num_elems' is the total number of addressable statistic elements
45 45 * 'vst_num_types' is the number of unique statistic types
46 46 *
47 47 * It is always true that 'vst_num_elems' is greater than or equal to
48 48 * 'vst_num_types'. This is because a stat type may represent more than
49 49 * one element (for e.g. VMM_STAT_ARRAY).
50 50 */
51 51 static int vst_num_elems, vst_num_types;
52 52 static struct vmm_stat_type *vsttab[MAX_VMM_STAT_ELEMS];
53 53
54 54 static MALLOC_DEFINE(M_VMM_STAT, "vmm stat", "vmm stat");
55 55
56 56 #define vst_size ((size_t)vst_num_elems * sizeof (uint64_t))
57 57
58 58 void
59 59 vmm_stat_register(void *arg)
60 60 {
61 61 struct vmm_stat_type *vst = arg;
62 62
63 63 /* We require all stats to identify themselves with a description */
64 64 if (vst->desc == NULL)
65 65 return;
66 66
67 67 if (vst->scope == VMM_STAT_SCOPE_INTEL && !vmm_is_intel())
68 68 return;
69 69
70 70 if (vst->scope == VMM_STAT_SCOPE_AMD && !vmm_is_svm())
71 71 return;
72 72
73 73 if (vst_num_elems + vst->nelems >= MAX_VMM_STAT_ELEMS) {
74 74 printf("Cannot accommodate vmm stat type \"%s\"!\n", vst->desc);
75 75 return;
76 76 }
77 77
78 78 vst->index = vst_num_elems;
79 79 vst_num_elems += vst->nelems;
80 80
81 81 vsttab[vst_num_types++] = vst;
82 82 }
83 83
84 84 int
85 85 vmm_stat_copy(struct vm *vm, int vcpu, int *num_stats, uint64_t *buf)
86 86 {
87 87 struct vmm_stat_type *vst;
88 88 uint64_t *stats;
89 89 int i;
90 90
91 91 if (vcpu < 0 || vcpu >= vm_get_maxcpus(vm))
92 92 return (EINVAL);
93 93
94 94 /* Let stats functions update their counters */
95 95 for (i = 0; i < vst_num_types; i++) {
96 96 vst = vsttab[i];
97 97 if (vst->func != NULL)
98 98 (*vst->func)(vm, vcpu, vst);
99 99 }
100 100
101 101 /* Copy over the stats */
102 102 stats = vcpu_stats(vm, vcpu);
103 103 for (i = 0; i < vst_num_elems; i++)
104 104 buf[i] = stats[i];
105 105 *num_stats = vst_num_elems;
106 106 return (0);
107 107 }
108 108
109 109 void *
110 110 vmm_stat_alloc(void)
111 111 {
112 112
113 113 return (malloc(vst_size, M_VMM_STAT, M_WAITOK));
114 114 }
115 115
116 116 void
117 117 vmm_stat_init(void *vp)
118 118 {
119 119
120 120 bzero(vp, vst_size);
121 121 }
122 122
123 123 void
124 124 vmm_stat_free(void *vp)
125 125 {
126 126 free(vp, M_VMM_STAT);
127 127 }
128 128
129 129 int
130 130 vmm_stat_desc_copy(int index, char *buf, int bufsize)
131 131 {
132 132 int i;
133 133 struct vmm_stat_type *vst;
134 134
135 135 for (i = 0; i < vst_num_types; i++) {
136 136 vst = vsttab[i];
137 137 if (index >= vst->index && index < vst->index + vst->nelems) {
138 138 if (vst->nelems > 1) {
139 139 snprintf(buf, bufsize, "%s[%d]",
140 140 vst->desc, index - vst->index);
141 141 } else {
142 142 strlcpy(buf, vst->desc, bufsize);
143 143 }
144 144 return (0); /* found it */
145 145 }
146 146 }
147 147
148 148 return (EINVAL);
149 149 }
150 150
151 151 /* global statistics */
152 152 VMM_STAT(VCPU_MIGRATIONS, "vcpu migration across host cpus");
153 153 VMM_STAT(VMEXIT_COUNT, "total number of vm exits");
154 154 VMM_STAT(VMEXIT_EXTINT, "vm exits due to external interrupt");
155 155 VMM_STAT(VMEXIT_HLT, "number of times hlt was intercepted");
156 156 VMM_STAT(VMEXIT_CR_ACCESS, "number of times %cr access was intercepted");
157 157 VMM_STAT(VMEXIT_RDMSR, "number of times rdmsr was intercepted");
158 158 VMM_STAT(VMEXIT_WRMSR, "number of times wrmsr was intercepted");
159 159 VMM_STAT(VMEXIT_MTRAP, "number of monitor trap exits");
|
↓ open down ↓ |
159 lines elided |
↑ open up ↑ |
160 160 VMM_STAT(VMEXIT_PAUSE, "number of times pause was intercepted");
161 161 VMM_STAT(VMEXIT_INTR_WINDOW, "vm exits due to interrupt window opening");
162 162 VMM_STAT(VMEXIT_NMI_WINDOW, "vm exits due to nmi window opening");
163 163 VMM_STAT(VMEXIT_INOUT, "number of times in/out was intercepted");
164 164 VMM_STAT(VMEXIT_CPUID, "number of times cpuid was intercepted");
165 165 VMM_STAT(VMEXIT_NESTED_FAULT, "vm exits due to nested page fault");
166 166 VMM_STAT(VMEXIT_MMIO_EMUL, "vm exits for mmio emulation");
167 167 VMM_STAT(VMEXIT_UNKNOWN, "number of vm exits for unknown reason");
168 168 VMM_STAT(VMEXIT_ASTPENDING, "number of times astpending at exit");
169 169 VMM_STAT(VMEXIT_REQIDLE, "number of times idle requested at exit");
170 -VMM_STAT(VMEXIT_USERSPACE, "number of vm exits handled in userspace");
171 -VMM_STAT(VMEXIT_RUNBLOCK, "number of times runblock at exit");
172 170 VMM_STAT(VMEXIT_EXCEPTION, "number of vm exits due to exceptions");
171 +VMM_STAT(VMEXIT_RUN_STATE, "number of vm exits due to run_state change");
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX