| 1 | /*	$NetBSD: evcnt.h,v 1.11 2024/01/15 18:14:23 thorpej 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 | 	union { |
| 87 | 		uint64_t ev_count;	/* how many have occurred */ |
| 88 | 		uint32_t ev__count32[2]; |
| 89 | 	}; |
| 90 | 	TAILQ_ENTRY(evcnt) ev_list;	/* entry on list of all counters */ |
| 91 | 	unsigned char	ev_type;	/* counter type; see below */ |
| 92 | 	unsigned char	ev_grouplen;	/* 'group' len, excluding NUL */ |
| 93 | 	unsigned char	ev_namelen;	/* 'name' len, excluding NUL */ |
| 94 | 	char		ev_pad1;	/* reserved (for now); 0 */ |
| 95 | 	const struct evcnt *ev_parent;	/* parent, for hierarchical ctrs */ |
| 96 | 	const char	*ev_group;	/* name of group */ |
| 97 | 	const char	*ev_name;	/* name of specific event */ |
| 98 | }; |
| 99 | TAILQ_HEAD(evcntlist, evcnt); |
| 100 | |
| 101 | /* |
| 102 | * For 32-bit counters, ev_count32 is the correct half of the 64-bit |
| 103 | * counter field. |
| 104 | */ |
| 105 | #if _BYTE_ORDER == _BIG_ENDIAN |
| 106 | #define	ev_count32	ev__count32[1] |
| 107 | #elif _BYTE_ORDER == _LITTLE_ENDIAN |
| 108 | #define	ev_count32	ev__count32[0] |
| 109 | #endif |
| 110 | |
| 111 | /* maximum group/name lengths, including trailing NUL */ |
| 112 | #define	EVCNT_STRING_MAX	255 |
| 113 | |
| 114 | /* ev_type values */ |
| 115 | #define	EVCNT_TYPE_ANY		-1	/* for sysctl */ |
| 116 | #define	EVCNT_TYPE_MISC		0	/* miscellaneous; catch all */ |
| 117 | #define	EVCNT_TYPE_INTR		1	/* interrupt; count with vmstat -i */ |
| 118 | #define	EVCNT_TYPE_TRAP		2	/* processor trap/exception */ |
| 119 | |
| 120 | #ifdef __HAVE_LEGACY_INTRCNT |
| 121 | void evcnt_attach_legacy_intrcnt(void); |
| 122 | #endif |
| 123 | |
| 124 | /* |
| 125 | * initializer for an event count structure. the lengths are initted and |
| 126 | * it is added to the evcnt list at attach time. |
| 127 | */ |
| 128 | #define	EVCNT_INITIALIZER(type, parent, group, name)	\ |
| 129 | {							\ |
| 130 | 	.ev_type = type,				\ |
| 131 | 	.ev_parent = parent,				\ |
| 132 | 	.ev_group = group,				\ |
| 133 | 	.ev_name = name,				\ |
| 134 | } |
| 135 | |
| 136 | /* |
| 137 | * Attach a static event counter. This uses a link set to do the work. |
| 138 | * NOTE: "ev" should not be a pointer to the object, but rather a direct |
| 139 | * reference to the object itself. |
| 140 | */ |
| 141 | #define	EVCNT_ATTACH_STATIC(ev)		__link_set_add_data(evcnts, ev) |
| 142 | #define	EVCNT_ATTACH_STATIC2(ev, n)	__link_set_add_data2(evcnts, ev, n) |
| 143 | |
| 144 | #ifdef _KERNEL |
| 145 | |
| 146 | extern struct evcntlist allevents;	/* list of all event counters */ |
| 147 | |
| 148 | void	evcnt_init(void); |
| 149 | void	evcnt_attach_static(struct evcnt *); |
| 150 | void	evcnt_attach_dynamic_nozero(struct evcnt *, int, const struct evcnt *, |
| 151 | 	 const char *, const char *); |
| 152 | void	evcnt_attach_dynamic(struct evcnt *, int, const struct evcnt *, |
| 153 | 	 const char *, const char *); |
| 154 | void	evcnt_detach(struct evcnt *); |
| 155 | #endif /* _KERNEL */ |
| 156 | |
| 157 | #endif /* !_SYS_EVCNT_H_ */ |