Deleted Added
full compact
vmm_stat.c (248935) vmm_stat.c (250427)
1/*-
2 * Copyright (c) 2011 NetApp, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2011 NetApp, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/sys/amd64/vmm/vmm_stat.c 248935 2013-03-30 17:46:03Z neel $
26 * $FreeBSD: head/sys/amd64/vmm/vmm_stat.c 250427 2013-05-10 02:59:49Z neel $
27 */
28
29#include <sys/cdefs.h>
27 */
28
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sys/amd64/vmm/vmm_stat.c 248935 2013-03-30 17:46:03Z neel $");
30__FBSDID("$FreeBSD: head/sys/amd64/vmm/vmm_stat.c 250427 2013-05-10 02:59:49Z neel $");
31
32#include <sys/param.h>
33#include <sys/kernel.h>
34#include <sys/systm.h>
35#include <sys/malloc.h>
36#include <sys/smp.h>
37
38#include <machine/vmm.h>
39#include "vmm_util.h"
40#include "vmm_stat.h"
41
31
32#include <sys/param.h>
33#include <sys/kernel.h>
34#include <sys/systm.h>
35#include <sys/malloc.h>
36#include <sys/smp.h>
37
38#include <machine/vmm.h>
39#include "vmm_util.h"
40#include "vmm_stat.h"
41
42static int vstnum;
43static struct vmm_stat_type *vsttab[MAX_VMM_STAT_TYPES];
42/*
43 * 'vst_num_elems' is the total number of addressable statistic elements
44 * 'vst_num_types' is the number of unique statistic types
45 *
46 * It is always true that 'vst_num_elems' is greater than or equal to
47 * 'vst_num_types'. This is because a stat type may represent more than
48 * one element (for e.g. VMM_STAT_ARRAY).
49 */
50static int vst_num_elems, vst_num_types;
51static struct vmm_stat_type *vsttab[MAX_VMM_STAT_ELEMS];
44
45static MALLOC_DEFINE(M_VMM_STAT, "vmm stat", "vmm stat");
46
47void
48vmm_stat_init(void *arg)
49{
50 struct vmm_stat_type *vst = arg;
51
52 /* We require all stats to identify themselves with a description */
53 if (vst->desc == NULL)
54 return;
55
56 if (vst->scope == VMM_STAT_SCOPE_INTEL && !vmm_is_intel())
57 return;
58
59 if (vst->scope == VMM_STAT_SCOPE_AMD && !vmm_is_amd())
60 return;
61
52
53static MALLOC_DEFINE(M_VMM_STAT, "vmm stat", "vmm stat");
54
55void
56vmm_stat_init(void *arg)
57{
58 struct vmm_stat_type *vst = arg;
59
60 /* We require all stats to identify themselves with a description */
61 if (vst->desc == NULL)
62 return;
63
64 if (vst->scope == VMM_STAT_SCOPE_INTEL && !vmm_is_intel())
65 return;
66
67 if (vst->scope == VMM_STAT_SCOPE_AMD && !vmm_is_amd())
68 return;
69
62 if (vstnum >= MAX_VMM_STAT_TYPES) {
70 if (vst_num_elems + vst->nelems >= MAX_VMM_STAT_ELEMS) {
63 printf("Cannot accomodate vmm stat type \"%s\"!\n", vst->desc);
64 return;
65 }
66
71 printf("Cannot accomodate vmm stat type \"%s\"!\n", vst->desc);
72 return;
73 }
74
67 vst->index = vstnum;
68 vsttab[vstnum++] = vst;
75 vst->index = vst_num_elems;
76 vst_num_elems += vst->nelems;
77
78 vsttab[vst_num_types++] = vst;
69}
70
71int
72vmm_stat_copy(struct vm *vm, int vcpu, int *num_stats, uint64_t *buf)
73{
74 int i;
75 uint64_t *stats;
76
77 if (vcpu < 0 || vcpu >= VM_MAXCPU)
78 return (EINVAL);
79
80 stats = vcpu_stats(vm, vcpu);
79}
80
81int
82vmm_stat_copy(struct vm *vm, int vcpu, int *num_stats, uint64_t *buf)
83{
84 int i;
85 uint64_t *stats;
86
87 if (vcpu < 0 || vcpu >= VM_MAXCPU)
88 return (EINVAL);
89
90 stats = vcpu_stats(vm, vcpu);
81 for (i = 0; i < vstnum; i++)
91 for (i = 0; i < vst_num_elems; i++)
82 buf[i] = stats[i];
92 buf[i] = stats[i];
83 *num_stats = vstnum;
93 *num_stats = vst_num_elems;
84 return (0);
85}
86
87void *
88vmm_stat_alloc(void)
89{
90 u_long size;
91
94 return (0);
95}
96
97void *
98vmm_stat_alloc(void)
99{
100 u_long size;
101
92 size = vstnum * sizeof(uint64_t);
102 size = vst_num_elems * sizeof(uint64_t);
93
94 return (malloc(size, M_VMM_STAT, M_ZERO | M_WAITOK));
95}
96
97void
98vmm_stat_free(void *vp)
99{
100 free(vp, M_VMM_STAT);
101}
102
103
104 return (malloc(size, M_VMM_STAT, M_ZERO | M_WAITOK));
105}
106
107void
108vmm_stat_free(void *vp)
109{
110 free(vp, M_VMM_STAT);
111}
112
103const char *
104vmm_stat_desc(int index)
113int
114vmm_stat_desc_copy(int index, char *buf, int bufsize)
105{
115{
116 int i;
117 struct vmm_stat_type *vst;
106
118
107 if (index >= 0 && index < vstnum)
108 return (vsttab[index]->desc);
109 else
110 return (NULL);
119 for (i = 0; i < vst_num_types; i++) {
120 vst = vsttab[i];
121 if (index >= vst->index && index < vst->index + vst->nelems) {
122 if (vst->nelems > 1) {
123 snprintf(buf, bufsize, "%s[%d]",
124 vst->desc, index - vst->index);
125 } else {
126 strlcpy(buf, vst->desc, bufsize);
127 }
128 return (0); /* found it */
129 }
130 }
131
132 return (EINVAL);
111}
112
113/* global statistics */
114VMM_STAT(VCPU_MIGRATIONS, "vcpu migration across host cpus");
115VMM_STAT(VMEXIT_COUNT, "total number of vm exits");
116VMM_STAT(VMEXIT_EXTINT, "vm exits due to external interrupt");
117VMM_STAT(VMEXIT_HLT, "number of times hlt was intercepted");
118VMM_STAT(VMEXIT_CR_ACCESS, "number of times %cr access was intercepted");

--- 12 unchanged lines hidden ---
133}
134
135/* global statistics */
136VMM_STAT(VCPU_MIGRATIONS, "vcpu migration across host cpus");
137VMM_STAT(VMEXIT_COUNT, "total number of vm exits");
138VMM_STAT(VMEXIT_EXTINT, "vm exits due to external interrupt");
139VMM_STAT(VMEXIT_HLT, "number of times hlt was intercepted");
140VMM_STAT(VMEXIT_CR_ACCESS, "number of times %cr access was intercepted");

--- 12 unchanged lines hidden ---