xref: /onnv-gate/usr/src/cmd/busstat/busstat.h (revision 0:68f95e015346)
1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate  * Copyright (c) 1999 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate  * All rights reserved.
25*0Sstevel@tonic-gate  */
26*0Sstevel@tonic-gate 
27*0Sstevel@tonic-gate #ifndef	_BUSSTAT_H
28*0Sstevel@tonic-gate #define	_BUSSTAT_H
29*0Sstevel@tonic-gate 
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*0Sstevel@tonic-gate 
33*0Sstevel@tonic-gate /*
34*0Sstevel@tonic-gate  * busstat works by reading and writing from/to kstat's which are
35*0Sstevel@tonic-gate  * exported by drivers on the system.
36*0Sstevel@tonic-gate  *
37*0Sstevel@tonic-gate  * busstat parses the command line it is given and builds up a
38*0Sstevel@tonic-gate  * pair of linked list's to represent the various options specified.
39*0Sstevel@tonic-gate  * An example command line is given below..
40*0Sstevel@tonic-gate  *
41*0Sstevel@tonic-gate  * -w ac2,pic0=wio_pkts,pic1=rbio_pkts -w ac2,pic0=rto_pkts,pic1=rto_pkts -r ac5
42*0Sstevel@tonic-gate  * =============================================================================
43*0Sstevel@tonic-gate  *
44*0Sstevel@tonic-gate  * ______
45*0Sstevel@tonic-gate  * |    |
46*0Sstevel@tonic-gate  * | ac2|->wio_pkts->rto_pkts
47*0Sstevel@tonic-gate  * |pic0|    |            |
48*0Sstevel@tonic-gate  * |    |    -------<------
49*0Sstevel@tonic-gate  * ------
50*0Sstevel@tonic-gate  *    |
51*0Sstevel@tonic-gate  *    |
52*0Sstevel@tonic-gate  * ______
53*0Sstevel@tonic-gate  * |    |
54*0Sstevel@tonic-gate  * | ac2|->rbio_pkts->rto_pkts
55*0Sstevel@tonic-gate  * |pic1|     |            |
56*0Sstevel@tonic-gate  * |    |     --------<-----
57*0Sstevel@tonic-gate  * ------
58*0Sstevel@tonic-gate  *    |
59*0Sstevel@tonic-gate  *    |
60*0Sstevel@tonic-gate  * ______
61*0Sstevel@tonic-gate  * |    |
62*0Sstevel@tonic-gate  * | ac5|->evt
63*0Sstevel@tonic-gate  * |pic0|
64*0Sstevel@tonic-gate  * |    |
65*0Sstevel@tonic-gate  * ------
66*0Sstevel@tonic-gate  *   |
67*0Sstevel@tonic-gate  *   |
68*0Sstevel@tonic-gate  * ______
69*0Sstevel@tonic-gate  * |    |
70*0Sstevel@tonic-gate  * | ac5|->evt
71*0Sstevel@tonic-gate  * |pic1|
72*0Sstevel@tonic-gate  * |    |
73*0Sstevel@tonic-gate  * ------
74*0Sstevel@tonic-gate  *
75*0Sstevel@tonic-gate  * The above diagram shows the lists created after the initial parsing.
76*0Sstevel@tonic-gate  *
77*0Sstevel@tonic-gate  * Each device instance/pic is represented by a device node. Hanging off
78*0Sstevel@tonic-gate  * that is at least one event node.
79*0Sstevel@tonic-gate  *
80*0Sstevel@tonic-gate  * Event nodes come in two different types. Nodes that are the result of a -r
81*0Sstevel@tonic-gate  * operation will have the r_w field in their parent dev_node set to EVT_READ,
82*0Sstevel@tonic-gate  * and most of their other fields set to zero or NULL. An event node that was
83*0Sstevel@tonic-gate  * created because of a -w operation (r_w = EVT_WRITE) will have all it's fields
84*0Sstevel@tonic-gate  * filled in. When a device node is created, an  event node is automatically
85*0Sstevel@tonic-gate  * created and marked as EVT_READ. If the device node was created as the result
86*0Sstevel@tonic-gate  * of a -r operation, nothing more happens. But if it was a -w operation, then
87*0Sstevel@tonic-gate  * the event node is modified (r_w changed to EVT_WRITE, event pcr mask and
88*0Sstevel@tonic-gate  * event name written if known).
89*0Sstevel@tonic-gate  *
90*0Sstevel@tonic-gate  * Setting events : work along the list of dev_nodes, for each device node check
91*0Sstevel@tonic-gate  * the event node pointed to by evt_node, if it is marked as EVT_WRITE in the
92*0Sstevel@tonic-gate  * corresponding r_w array, if so set the event stored in the node.
93*0Sstevel@tonic-gate  *
94*0Sstevel@tonic-gate  * Reading events : work along the list of dev_nodes, for each device node check
95*0Sstevel@tonic-gate  * the event node pointed to by evt_node, if it is marked EVT_WRITE, just read
96*0Sstevel@tonic-gate  * the event count from the appropiate PIC and store it in the node. If the node
97*0Sstevel@tonic-gate  * is EVT_READ however, read the PCR, determine the event name, store it in the
98*0Sstevel@tonic-gate  * node along with the event count.
99*0Sstevel@tonic-gate  *
100*0Sstevel@tonic-gate  * Multiplexing is handled by cycling through the event nodes. The event nodes
101*0Sstevel@tonic-gate  * are on a circular list, which allows each pic to be multiplexing between
102*0Sstevel@tonic-gate  * different numbers of events.
103*0Sstevel@tonic-gate  */
104*0Sstevel@tonic-gate 
105*0Sstevel@tonic-gate #define	TRUE	1
106*0Sstevel@tonic-gate #define	FALSE	0
107*0Sstevel@tonic-gate #define	FAIL	-1
108*0Sstevel@tonic-gate 
109*0Sstevel@tonic-gate #define	READ_EVT	1
110*0Sstevel@tonic-gate #define	WRITE_EVT	0
111*0Sstevel@tonic-gate 
112*0Sstevel@tonic-gate #define	EVT_READ	0x1
113*0Sstevel@tonic-gate #define	EVT_WRITE	0x2
114*0Sstevel@tonic-gate #define	ONE_INST_CALL	0x4
115*0Sstevel@tonic-gate #define	ALL_INST_CALL	0x8
116*0Sstevel@tonic-gate 
117*0Sstevel@tonic-gate #define	STATE_INIT	0x10	/* Initial state of node when created */
118*0Sstevel@tonic-gate #define	STATE_INST	0x20	/* Node was created by specific instance call */
119*0Sstevel@tonic-gate #define	STATE_ALL	0x40	/* Node was created by call for all instances */
120*0Sstevel@tonic-gate 
121*0Sstevel@tonic-gate #define	NANO		1000000000	/* To convert from nanosecs to secs */
122*0Sstevel@tonic-gate 
123*0Sstevel@tonic-gate #define	PIC_STR_LEN	3
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate #define	EVT_STR		-1
126*0Sstevel@tonic-gate 
127*0Sstevel@tonic-gate typedef struct evt_node {
128*0Sstevel@tonic-gate 	char		evt_name[KSTAT_STRLEN];	/* The event name */
129*0Sstevel@tonic-gate 	uint64_t	prev_count;	/* The previous count for this evt */
130*0Sstevel@tonic-gate 	uint64_t	total;		/* Total count for this event */
131*0Sstevel@tonic-gate 	uint64_t	evt_pcr_mask;	/* PCR mask for this event */
132*0Sstevel@tonic-gate 	struct evt_node *next;
133*0Sstevel@tonic-gate } evt_node_t;
134*0Sstevel@tonic-gate 
135*0Sstevel@tonic-gate typedef struct dev_node {
136*0Sstevel@tonic-gate 	char		name[KSTAT_STRLEN];	/* Device name e.g. ac */
137*0Sstevel@tonic-gate 	int		dev_inst;	/* Device instance number */
138*0Sstevel@tonic-gate 	int		pic_num;	/* PIC number. */
139*0Sstevel@tonic-gate 	kstat_t		*cnt_ksp;	/* "counters" kstat pointer */
140*0Sstevel@tonic-gate 	kstat_t		*pic_ksp;	/* pointer to picN kstat */
141*0Sstevel@tonic-gate 	int		r_w;		/* r_w flag */
142*0Sstevel@tonic-gate 	int		state;		/* state flag */
143*0Sstevel@tonic-gate 	struct evt_node	*evt_node;	/* ptr to current evt_node */
144*0Sstevel@tonic-gate 	struct dev_node	*next;
145*0Sstevel@tonic-gate } dev_node_t;
146*0Sstevel@tonic-gate 
147*0Sstevel@tonic-gate #endif	/* _BUSSTAT_H */
148