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) 1997 by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All rights reserved. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate /* 30*7c478bd9Sstevel@tonic-gate * Kernel Basic Block Profiling - profiling initialization hooks 31*7c478bd9Sstevel@tonic-gate */ 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #include <sys/param.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 35*7c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 36*7c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 37*7c478bd9Sstevel@tonic-gate #include <sys/systm.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/spl.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/unix_bb_info.h> 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate #ifdef KCOV 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate /* 44*7c478bd9Sstevel@tonic-gate * routines to do kernel basic block coverage. 45*7c478bd9Sstevel@tonic-gate */ 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate struct bb_info *unix_bb_list; 48*7c478bd9Sstevel@tonic-gate lock_t unix_bb_lock; 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate /* 51*7c478bd9Sstevel@tonic-gate * There is the potential that we will be called by any C routine. 52*7c478bd9Sstevel@tonic-gate * So we avoid calling any C routines from here, as we'll get 53*7c478bd9Sstevel@tonic-gate * a recursive call. 54*7c478bd9Sstevel@tonic-gate * Also, we wish to avoid a deadlock due to being called by 55*7c478bd9Sstevel@tonic-gate * an interrupt handler, so we lock at the NMI level. 56*7c478bd9Sstevel@tonic-gate * Of course, that leaves the possibility that we'll 57*7c478bd9Sstevel@tonic-gate * be called from an NMI handler. If the lock is available, 58*7c478bd9Sstevel@tonic-gate * fine, otherwise, if we're on the interrupt stack at the 59*7c478bd9Sstevel@tonic-gate * NMI level, we just return. 60*7c478bd9Sstevel@tonic-gate * 61*7c478bd9Sstevel@tonic-gate * We will probably get another chance to add the bb_info structure 62*7c478bd9Sstevel@tonic-gate * to the list, since the bb_info structure is for the entire object file. 63*7c478bd9Sstevel@tonic-gate */ 64*7c478bd9Sstevel@tonic-gate #ifdef KCOV_TEST 65*7c478bd9Sstevel@tonic-gate int unix_bb_a, unix_bb_b, unix_bb_c; 66*7c478bd9Sstevel@tonic-gate int unix_bb_d, unix_bb_e, unix_bb_f, unix_bb_g; 67*7c478bd9Sstevel@tonic-gate processorid_t bb_last_who; 68*7c478bd9Sstevel@tonic-gate char *bb_last_where; 69*7c478bd9Sstevel@tonic-gate #endif 70*7c478bd9Sstevel@tonic-gate 71*7c478bd9Sstevel@tonic-gate void 72*7c478bd9Sstevel@tonic-gate __bb_init_func(struct bb_info *bb) 73*7c478bd9Sstevel@tonic-gate { 74*7c478bd9Sstevel@tonic-gate u_short s; 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate /* 77*7c478bd9Sstevel@tonic-gate * a = c + g 78*7c478bd9Sstevel@tonic-gate * b = c + d 79*7c478bd9Sstevel@tonic-gate * a = c + e 80*7c478bd9Sstevel@tonic-gate * e = g 81*7c478bd9Sstevel@tonic-gate * 82*7c478bd9Sstevel@tonic-gate * a->b->c 83*7c478bd9Sstevel@tonic-gate * a->b->d->e->g 84*7c478bd9Sstevel@tonic-gate * a->b->d->e->f->g 85*7c478bd9Sstevel@tonic-gate * a->e->g 86*7c478bd9Sstevel@tonic-gate * a->e->f->g 87*7c478bd9Sstevel@tonic-gate */ 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate /* 90*7c478bd9Sstevel@tonic-gate * Raise the pil and try to get the lock. 91*7c478bd9Sstevel@tonic-gate */ 92*7c478bd9Sstevel@tonic-gate s = spl8(); 93*7c478bd9Sstevel@tonic-gate #ifdef KCOV_TEST 94*7c478bd9Sstevel@tonic-gate unix_bb_a++; 95*7c478bd9Sstevel@tonic-gate #endif 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate if (!lock_try(&unix_bb_lock)) { 98*7c478bd9Sstevel@tonic-gate /* 99*7c478bd9Sstevel@tonic-gate * If we're on the interrrupt stack, we just return 100*7c478bd9Sstevel@tonic-gate * in case it's an NMI and we're looking at a deadlock 101*7c478bd9Sstevel@tonic-gate * situation. Otherwise, we use lock_set_spl() 102*7c478bd9Sstevel@tonic-gate */ 103*7c478bd9Sstevel@tonic-gate #ifdef KCOV_TEST 104*7c478bd9Sstevel@tonic-gate unix_bb_b++; 105*7c478bd9Sstevel@tonic-gate #endif 106*7c478bd9Sstevel@tonic-gate if (CPU_ON_INTR(CPU)) { 107*7c478bd9Sstevel@tonic-gate #ifdef KCOV_TEST 108*7c478bd9Sstevel@tonic-gate unix_bb_c++; 109*7c478bd9Sstevel@tonic-gate #endif 110*7c478bd9Sstevel@tonic-gate splx(s); 111*7c478bd9Sstevel@tonic-gate return; 112*7c478bd9Sstevel@tonic-gate } 113*7c478bd9Sstevel@tonic-gate #ifdef KCOV_TEST 114*7c478bd9Sstevel@tonic-gate unix_bb_d++; 115*7c478bd9Sstevel@tonic-gate #endif 116*7c478bd9Sstevel@tonic-gate splx(s); 117*7c478bd9Sstevel@tonic-gate lock_set_spl(&unix_bb_lock, ipltospl(NMI_LEVEL), &s); 118*7c478bd9Sstevel@tonic-gate } 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate #ifdef KCOV_TEST 121*7c478bd9Sstevel@tonic-gate bb_last_who = CPU->cpu_id; 122*7c478bd9Sstevel@tonic-gate bb_last_where = bb->bb_filename; 123*7c478bd9Sstevel@tonic-gate unix_bb_e++; 124*7c478bd9Sstevel@tonic-gate #endif 125*7c478bd9Sstevel@tonic-gate /* 126*7c478bd9Sstevel@tonic-gate * We've got the lock. If we have not been initialized, add us 127*7c478bd9Sstevel@tonic-gate * to the list and set the initialized flag. 128*7c478bd9Sstevel@tonic-gate */ 129*7c478bd9Sstevel@tonic-gate #ifdef KCOV_TEST 130*7c478bd9Sstevel@tonic-gate if (bb->bb_next == 0) { 131*7c478bd9Sstevel@tonic-gate unix_bb_f++; 132*7c478bd9Sstevel@tonic-gate #else 133*7c478bd9Sstevel@tonic-gate if (bb->bb_initflag == 0) { 134*7c478bd9Sstevel@tonic-gate bb->bb_initflag = 1; 135*7c478bd9Sstevel@tonic-gate #endif 136*7c478bd9Sstevel@tonic-gate bb->bb_next = unix_bb_list; 137*7c478bd9Sstevel@tonic-gate unix_bb_list = bb; 138*7c478bd9Sstevel@tonic-gate } 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate #ifdef KCOV_TEST 141*7c478bd9Sstevel@tonic-gate unix_bb_g++; 142*7c478bd9Sstevel@tonic-gate #endif 143*7c478bd9Sstevel@tonic-gate lock_clear_splx(&unix_bb_lock, s); 144*7c478bd9Sstevel@tonic-gate } 145*7c478bd9Sstevel@tonic-gate #endif /* KCOV */ 146