vmm_stat.h revision 221828
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$
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
39221828Sgrehanstruct vmm_stat_type {
40221828Sgrehan	const char	*desc;		/* description of statistic */
41221828Sgrehan	int	index;			/* position in the stats buffer */
42221828Sgrehan};
43221828Sgrehan
44221828Sgrehanvoid	vmm_stat_init(void *arg);
45221828Sgrehan
46221828Sgrehan#define	VMM_STAT_DEFINE(type, desc)					\
47221828Sgrehan	struct vmm_stat_type type[1] = {				\
48221828Sgrehan		{ desc, -1 }						\
49221828Sgrehan	};								\
50221828Sgrehan	SYSINIT(type##_stat, SI_SUB_KLD, SI_ORDER_ANY, vmm_stat_init, type)
51221828Sgrehan
52221828Sgrehanvoid	*vmm_stat_alloc(void);
53221828Sgrehanvoid 	vmm_stat_free(void *vp);
54221828Sgrehan
55221828Sgrehan/*
56221828Sgrehan * 'buf' should be at least fit 'MAX_VMM_STAT_TYPES' entries
57221828Sgrehan */
58221828Sgrehanint	vmm_stat_copy(struct vm *vm, int vcpu, int *num_stats, uint64_t *buf);
59221828Sgrehanconst char *vmm_stat_desc(int index);
60221828Sgrehan
61221828Sgrehanstatic void __inline
62221828Sgrehanvmm_stat_incr(struct vm *vm, int vcpu, struct vmm_stat_type *vst, uint64_t x)
63221828Sgrehan{
64221828Sgrehan#ifdef	VMM_KEEP_STATS
65221828Sgrehan	uint64_t *stats = vcpu_stats(vm, vcpu);
66221828Sgrehan	if (vst->index >= 0)
67221828Sgrehan		stats[vst->index] += x;
68221828Sgrehan#endif
69221828Sgrehan}
70221828Sgrehan
71221828Sgrehan#endif
72