include: gcc 7's cpp has problems with the line continuations in .x files
[unleashed.git] / kernel / os / unix_bb.c
blobb5ce13f347bfea55d71c6f32e0c590024519a596
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1997 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * Kernel Basic Block Profiling - profiling initialization hooks
33 #include <sys/param.h>
34 #include <sys/types.h>
35 #include <sys/t_lock.h>
36 #include <sys/cpuvar.h>
37 #include <sys/systm.h>
38 #include <sys/spl.h>
39 #include <sys/unix_bb_info.h>
41 #ifdef KCOV
44 * routines to do kernel basic block coverage.
47 struct bb_info *unix_bb_list;
48 lock_t unix_bb_lock;
51 * There is the potential that we will be called by any C routine.
52 * So we avoid calling any C routines from here, as we'll get
53 * a recursive call.
54 * Also, we wish to avoid a deadlock due to being called by
55 * an interrupt handler, so we lock at the NMI level.
56 * Of course, that leaves the possibility that we'll
57 * be called from an NMI handler. If the lock is available,
58 * fine, otherwise, if we're on the interrupt stack at the
59 * NMI level, we just return.
61 * We will probably get another chance to add the bb_info structure
62 * to the list, since the bb_info structure is for the entire object file.
64 #ifdef KCOV_TEST
65 int unix_bb_a, unix_bb_b, unix_bb_c;
66 int unix_bb_d, unix_bb_e, unix_bb_f, unix_bb_g;
67 processorid_t bb_last_who;
68 char *bb_last_where;
69 #endif
71 void
72 __bb_init_func(struct bb_info *bb)
74 u_short s;
77 * a = c + g
78 * b = c + d
79 * a = c + e
80 * e = g
82 * a->b->c
83 * a->b->d->e->g
84 * a->b->d->e->f->g
85 * a->e->g
86 * a->e->f->g
90 * Raise the pil and try to get the lock.
92 s = spl8();
93 #ifdef KCOV_TEST
94 unix_bb_a++;
95 #endif
97 if (!lock_try(&unix_bb_lock)) {
99 * If we're on the interrrupt stack, we just return
100 * in case it's an NMI and we're looking at a deadlock
101 * situation. Otherwise, we use lock_set_spl()
103 #ifdef KCOV_TEST
104 unix_bb_b++;
105 #endif
106 if (CPU_ON_INTR(CPU)) {
107 #ifdef KCOV_TEST
108 unix_bb_c++;
109 #endif
110 splx(s);
111 return;
113 #ifdef KCOV_TEST
114 unix_bb_d++;
115 #endif
116 splx(s);
117 lock_set_spl(&unix_bb_lock, ipltospl(NMI_LEVEL), &s);
120 #ifdef KCOV_TEST
121 bb_last_who = CPU->cpu_id;
122 bb_last_where = bb->bb_filename;
123 unix_bb_e++;
124 #endif
126 * We've got the lock. If we have not been initialized, add us
127 * to the list and set the initialized flag.
129 #ifdef KCOV_TEST
130 if (bb->bb_next == 0) {
131 unix_bb_f++;
132 #else
133 if (bb->bb_initflag == 0) {
134 bb->bb_initflag = 1;
135 #endif
136 bb->bb_next = unix_bb_list;
137 unix_bb_list = bb;
140 #ifdef KCOV_TEST
141 unix_bb_g++;
142 #endif
143 lock_clear_splx(&unix_bb_lock, s);
145 #endif /* KCOV */