xref: /netbsd/sys/sys/evcnt.h (revision 2e429d79)
1 /*	$NetBSD: evcnt.h,v 1.10 2021/08/03 23:12:14 andvar Exp $	*/
2 
3 /*
4  * Copyright (c) 1996, 2000 Christopher G. Demetriou
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *          This product includes software developed for the
18  *          NetBSD Project.  See http://www.NetBSD.org/ for
19  *          information about NetBSD.
20  * 4. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  * --(license Id: LICENSE.proto,v 1.1 2000/06/13 21:40:26 cgd Exp )--
35  */
36 
37 /*
38  * Copyright (c) 1992, 1993
39  *	The Regents of the University of California.  All rights reserved.
40  *
41  * This software was developed by the Computer Systems Engineering group
42  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
43  * contributed to Berkeley.
44  *
45  * All advertising materials mentioning features or use of this software
46  * must display the following acknowledgement:
47  *	This product includes software developed by the University of
48  *	California, Lawrence Berkeley Laboratories.
49  *
50  * Redistribution and use in source and binary forms, with or without
51  * modification, are permitted provided that the following conditions
52  * are met:
53  * 1. Redistributions of source code must retain the above copyright
54  *    notice, this list of conditions and the following disclaimer.
55  * 2. Redistributions in binary form must reproduce the above copyright
56  *    notice, this list of conditions and the following disclaimer in the
57  *    documentation and/or other materials provided with the distribution.
58  * 3. Neither the name of the University nor the names of its contributors
59  *    may be used to endorse or promote products derived from this software
60  *    without specific prior written permission.
61  *
62  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72  * SUCH DAMAGE.
73  */
74 
75 #ifndef _SYS_EVCNT_H_
76 #define	_SYS_EVCNT_H_
77 
78 #include <sys/queue.h>
79 #include <sys/stdint.h>
80 
81 /*
82  * event counters
83  */
84 
85 struct evcnt {
86 	uint64_t	ev_count;	/* how many have occurred */
87 	TAILQ_ENTRY(evcnt) ev_list;	/* entry on list of all counters */
88 	unsigned char	ev_type;	/* counter type; see below */
89 	unsigned char	ev_grouplen;	/* 'group' len, excluding NUL */
90 	unsigned char	ev_namelen;	/* 'name' len, excluding NUL */
91 	char		ev_pad1;	/* reserved (for now); 0 */
92 	const struct evcnt *ev_parent;	/* parent, for hierarchical ctrs */
93 	const char	*ev_group;	/* name of group */
94 	const char	*ev_name;	/* name of specific event */
95 };
96 TAILQ_HEAD(evcntlist, evcnt);
97 
98 /* maximum group/name lengths, including trailing NUL */
99 #define	EVCNT_STRING_MAX	255
100 
101 /* ev_type values */
102 #define	EVCNT_TYPE_ANY		-1	/* for sysctl */
103 #define	EVCNT_TYPE_MISC		0	/* miscellaneous; catch all */
104 #define	EVCNT_TYPE_INTR		1	/* interrupt; count with vmstat -i */
105 #define	EVCNT_TYPE_TRAP		2	/* processor trap/exception */
106 
107 #ifdef __HAVE_LEGACY_INTRCNT
108 void evcnt_attach_legacy_intrcnt(void);
109 #endif
110 
111 /*
112  * initializer for an event count structure.  the lengths are initted and
113  * it is added to the evcnt list at attach time.
114  */
115 #define	EVCNT_INITIALIZER(type, parent, group, name)	\
116     {							\
117 	.ev_type = type,				\
118 	.ev_parent = parent,				\
119 	.ev_group = group,				\
120 	.ev_name = name,				\
121     }
122 
123 /*
124  * Attach a static event counter.  This uses a link set to do the work.
125  * NOTE: "ev" should not be a pointer to the object, but rather a direct
126  * reference to the object itself.
127  */
128 #define	EVCNT_ATTACH_STATIC(ev)		__link_set_add_data(evcnts, ev)
129 #define	EVCNT_ATTACH_STATIC2(ev, n)	__link_set_add_data2(evcnts, ev, n)
130 
131 #ifdef _KERNEL
132 
133 extern struct evcntlist allevents;	/* list of all event counters */
134 
135 void	evcnt_init(void);
136 void	evcnt_attach_static(struct evcnt *);
137 void	evcnt_attach_dynamic_nozero(struct evcnt *, int, const struct evcnt *,
138 	    const char *, const char *);
139 void	evcnt_attach_dynamic(struct evcnt *, int, const struct evcnt *,
140 	    const char *, const char *);
141 void	evcnt_detach(struct evcnt *);
142 #endif /* _KERNEL */
143 
144 #endif /* !_SYS_EVCNT_H_ */
145