subr_evcnt.c revision 1.2.4.2 1 1.2.4.2 skrll /* $NetBSD: subr_evcnt.c,v 1.2.4.2 2004/08/03 10:52:55 skrll Exp $ */
2 1.2.4.2 skrll
3 1.2.4.2 skrll /*
4 1.2.4.2 skrll * Copyright (c) 1996, 2000 Christopher G. Demetriou
5 1.2.4.2 skrll * All rights reserved.
6 1.2.4.2 skrll *
7 1.2.4.2 skrll * Redistribution and use in source and binary forms, with or without
8 1.2.4.2 skrll * modification, are permitted provided that the following conditions
9 1.2.4.2 skrll * are met:
10 1.2.4.2 skrll * 1. Redistributions of source code must retain the above copyright
11 1.2.4.2 skrll * notice, this list of conditions and the following disclaimer.
12 1.2.4.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
13 1.2.4.2 skrll * notice, this list of conditions and the following disclaimer in the
14 1.2.4.2 skrll * documentation and/or other materials provided with the distribution.
15 1.2.4.2 skrll * 3. All advertising materials mentioning features or use of this software
16 1.2.4.2 skrll * must display the following acknowledgement:
17 1.2.4.2 skrll * This product includes software developed for the
18 1.2.4.2 skrll * NetBSD Project. See http://www.NetBSD.org/ for
19 1.2.4.2 skrll * information about NetBSD.
20 1.2.4.2 skrll * 4. The name of the author may not be used to endorse or promote products
21 1.2.4.2 skrll * derived from this software without specific prior written permission.
22 1.2.4.2 skrll *
23 1.2.4.2 skrll * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.2.4.2 skrll * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.2.4.2 skrll * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.2.4.2 skrll * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.2.4.2 skrll * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.2.4.2 skrll * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.2.4.2 skrll * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.2.4.2 skrll * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.2.4.2 skrll * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.2.4.2 skrll * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.2.4.2 skrll *
34 1.2.4.2 skrll * --(license Id: LICENSE.proto,v 1.1 2000/06/13 21:40:26 cgd Exp )--
35 1.2.4.2 skrll */
36 1.2.4.2 skrll
37 1.2.4.2 skrll /*
38 1.2.4.2 skrll * Copyright (c) 1992, 1993
39 1.2.4.2 skrll * The Regents of the University of California. All rights reserved.
40 1.2.4.2 skrll *
41 1.2.4.2 skrll * This software was developed by the Computer Systems Engineering group
42 1.2.4.2 skrll * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
43 1.2.4.2 skrll * contributed to Berkeley.
44 1.2.4.2 skrll *
45 1.2.4.2 skrll * All advertising materials mentioning features or use of this software
46 1.2.4.2 skrll * must display the following acknowledgement:
47 1.2.4.2 skrll * This product includes software developed by the University of
48 1.2.4.2 skrll * California, Lawrence Berkeley Laboratories.
49 1.2.4.2 skrll *
50 1.2.4.2 skrll * Redistribution and use in source and binary forms, with or without
51 1.2.4.2 skrll * modification, are permitted provided that the following conditions
52 1.2.4.2 skrll * are met:
53 1.2.4.2 skrll * 1. Redistributions of source code must retain the above copyright
54 1.2.4.2 skrll * notice, this list of conditions and the following disclaimer.
55 1.2.4.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
56 1.2.4.2 skrll * notice, this list of conditions and the following disclaimer in the
57 1.2.4.2 skrll * documentation and/or other materials provided with the distribution.
58 1.2.4.2 skrll * 3. Neither the name of the University nor the names of its contributors
59 1.2.4.2 skrll * may be used to endorse or promote products derived from this software
60 1.2.4.2 skrll * without specific prior written permission.
61 1.2.4.2 skrll *
62 1.2.4.2 skrll * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 1.2.4.2 skrll * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 1.2.4.2 skrll * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 1.2.4.2 skrll * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 1.2.4.2 skrll * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 1.2.4.2 skrll * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 1.2.4.2 skrll * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 1.2.4.2 skrll * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 1.2.4.2 skrll * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 1.2.4.2 skrll * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 1.2.4.2 skrll * SUCH DAMAGE.
73 1.2.4.2 skrll *
74 1.2.4.2 skrll * from: Header: subr_autoconf.c,v 1.12 93/02/01 19:31:48 torek Exp (LBL)
75 1.2.4.2 skrll *
76 1.2.4.2 skrll * @(#)subr_autoconf.c 8.3 (Berkeley) 5/17/94
77 1.2.4.2 skrll */
78 1.2.4.2 skrll
79 1.2.4.2 skrll #include <sys/cdefs.h>
80 1.2.4.2 skrll __KERNEL_RCSID(0, "$NetBSD: subr_evcnt.c,v 1.2.4.2 2004/08/03 10:52:55 skrll Exp $");
81 1.2.4.2 skrll
82 1.2.4.2 skrll #include "opt_ddb.h"
83 1.2.4.2 skrll
84 1.2.4.2 skrll #include <sys/param.h>
85 1.2.4.2 skrll #include <sys/device.h>
86 1.2.4.2 skrll #include <sys/systm.h>
87 1.2.4.2 skrll
88 1.2.4.2 skrll /* list of all events */
89 1.2.4.2 skrll struct evcntlist allevents = TAILQ_HEAD_INITIALIZER(allevents);
90 1.2.4.2 skrll
91 1.2.4.2 skrll /*
92 1.2.4.2 skrll * We need a dummy object to stuff into the evcnt link set to
93 1.2.4.2 skrll * ensure that there always is at least one object in the set.
94 1.2.4.2 skrll */
95 1.2.4.2 skrll static struct evcnt dummy_static_evcnt;
96 1.2.4.2 skrll __link_set_add_bss(evcnts, dummy_static_evcnt);
97 1.2.4.2 skrll
98 1.2.4.2 skrll /*
99 1.2.4.2 skrll * Initialize event counters. This does the attach procedure for
100 1.2.4.2 skrll * each of the static event counters in the "evcnts" link set.
101 1.2.4.2 skrll */
102 1.2.4.2 skrll void
103 1.2.4.2 skrll evcnt_init(void)
104 1.2.4.2 skrll {
105 1.2.4.2 skrll __link_set_decl(evcnts, struct evcnt);
106 1.2.4.2 skrll struct evcnt * const *evp;
107 1.2.4.2 skrll
108 1.2.4.2 skrll __link_set_foreach(evp, evcnts) {
109 1.2.4.2 skrll if (*evp == &dummy_static_evcnt)
110 1.2.4.2 skrll continue;
111 1.2.4.2 skrll evcnt_attach_static(*evp);
112 1.2.4.2 skrll }
113 1.2.4.2 skrll }
114 1.2.4.2 skrll
115 1.2.4.2 skrll /*
116 1.2.4.2 skrll * Attach a statically-initialized event. The type and string pointers
117 1.2.4.2 skrll * are already set up.
118 1.2.4.2 skrll */
119 1.2.4.2 skrll void
120 1.2.4.2 skrll evcnt_attach_static(struct evcnt *ev)
121 1.2.4.2 skrll {
122 1.2.4.2 skrll int len;
123 1.2.4.2 skrll
124 1.2.4.2 skrll len = strlen(ev->ev_group);
125 1.2.4.2 skrll #ifdef DIAGNOSTIC
126 1.2.4.2 skrll if (len >= EVCNT_STRING_MAX) /* ..._MAX includes NUL */
127 1.2.4.2 skrll panic("evcnt_attach_static: group length (%s)", ev->ev_group);
128 1.2.4.2 skrll #endif
129 1.2.4.2 skrll ev->ev_grouplen = len;
130 1.2.4.2 skrll
131 1.2.4.2 skrll len = strlen(ev->ev_name);
132 1.2.4.2 skrll #ifdef DIAGNOSTIC
133 1.2.4.2 skrll if (len >= EVCNT_STRING_MAX) /* ..._MAX includes NUL */
134 1.2.4.2 skrll panic("evcnt_attach_static: name length (%s)", ev->ev_name);
135 1.2.4.2 skrll #endif
136 1.2.4.2 skrll ev->ev_namelen = len;
137 1.2.4.2 skrll
138 1.2.4.2 skrll TAILQ_INSERT_TAIL(&allevents, ev, ev_list);
139 1.2.4.2 skrll }
140 1.2.4.2 skrll
141 1.2.4.2 skrll /*
142 1.2.4.2 skrll * Attach a dynamically-initialized event. Zero it, set up the type
143 1.2.4.2 skrll * and string pointers and then act like it was statically initialized.
144 1.2.4.2 skrll */
145 1.2.4.2 skrll void
146 1.2.4.2 skrll evcnt_attach_dynamic(struct evcnt *ev, int type, const struct evcnt *parent,
147 1.2.4.2 skrll const char *group, const char *name)
148 1.2.4.2 skrll {
149 1.2.4.2 skrll
150 1.2.4.2 skrll memset(ev, 0, sizeof *ev);
151 1.2.4.2 skrll ev->ev_type = type;
152 1.2.4.2 skrll ev->ev_parent = parent;
153 1.2.4.2 skrll ev->ev_group = group;
154 1.2.4.2 skrll ev->ev_name = name;
155 1.2.4.2 skrll evcnt_attach_static(ev);
156 1.2.4.2 skrll }
157 1.2.4.2 skrll
158 1.2.4.2 skrll /*
159 1.2.4.2 skrll * Detach an event.
160 1.2.4.2 skrll */
161 1.2.4.2 skrll void
162 1.2.4.2 skrll evcnt_detach(struct evcnt *ev)
163 1.2.4.2 skrll {
164 1.2.4.2 skrll
165 1.2.4.2 skrll TAILQ_REMOVE(&allevents, ev, ev_list);
166 1.2.4.2 skrll }
167 1.2.4.2 skrll
168 1.2.4.2 skrll #ifdef DDB
169 1.2.4.2 skrll void
170 1.2.4.2 skrll event_print(int full, void (*pr)(const char *, ...))
171 1.2.4.2 skrll {
172 1.2.4.2 skrll struct evcnt *evp;
173 1.2.4.2 skrll
174 1.2.4.2 skrll TAILQ_FOREACH(evp, &allevents, ev_list) {
175 1.2.4.2 skrll if (evp->ev_count == 0 && !full)
176 1.2.4.2 skrll continue;
177 1.2.4.2 skrll
178 1.2.4.2 skrll (*pr)("evcnt type %d: %s %s = %lld\n", evp->ev_type,
179 1.2.4.2 skrll evp->ev_group, evp->ev_name, evp->ev_count);
180 1.2.4.2 skrll }
181 1.2.4.2 skrll }
182 1.2.4.2 skrll #endif /* DDB */
183