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