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