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