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