30 #include <sys/cdefs.h>
33 #include <sys/param.h>
37 #include <sys/systm.h>
40 #include <vm/vm_param.h>
60 uintfptr_t frompc, selfpc;
67 struct tostruct *top, *prevtop;
80 if (p->state != GMON_PROF_ON)
86 p->state = GMON_PROF_BUSY;
95 frompc = MCOUNT_FROMPC_USER(frompc);
98 frompci = frompc - p->lowpc;
99 if (frompci >= p->textsize)
103 if (p->state == GMON_PROF_HIRES) {
124 delta = cputime() - cputime_bias - p->mcount_pre_overhead;
125 cputime_bias = p->mcount_post_overhead;
126 KCOUNT(p, frompci) += delta;
127 *p->cputime_count += p->cputime_overhead;
128 *p->mcount_count += p->mcount_overhead;
141 frompc = MCOUNT_FROMPC_INTR(selfpc);
142 if ((frompc - p->lowpc) < p->textsize)
143 frompci = frompc - p->lowpc;
151 if (frompci >= p->textsize)
154 frompcindex = &p->froms[frompci / (p->hashfraction *
sizeof(*p->froms))];
155 toindex = *frompcindex;
160 toindex = ++p->tos[0].link;
161 if (toindex >= p->tolimit)
165 *frompcindex = toindex;
166 top = &p->tos[toindex];
167 top->selfpc = selfpc;
172 top = &p->tos[toindex];
173 if (top->selfpc == selfpc) {
187 if (top->link == 0) {
194 toindex = ++p->tos[0].link;
195 if (toindex >= p->tolimit)
198 top = &p->tos[toindex];
199 top->selfpc = selfpc;
201 top->link = *frompcindex;
202 *frompcindex = toindex;
209 top = &p->tos[top->link];
210 if (top->selfpc == selfpc) {
217 toindex = prevtop->link;
218 prevtop->link = top->link;
219 top->link = *frompcindex;
220 *frompcindex = toindex;
229 p->state = GMON_PROF_ON;
233 p->state = GMON_PROF_ERROR;
252 uintfptr_t selfpcdiff;
255 selfpcdiff = selfpc - (uintfptr_t)p->lowpc;
256 if (selfpcdiff < p->textsize) {
263 delta = cputime() - cputime_bias - p->mexitcount_pre_overhead;
264 cputime_bias = p->mexitcount_post_overhead;
265 KCOUNT(p, selfpcdiff) += delta;
266 *p->cputime_count += p->cputime_overhead;
267 *p->mexitcount_count += p->mexitcount_overhead;
271 #ifndef __GNUCLIKE_ASM
272 #error "This file uses null asms to prevent timing loops being optimized away."
280 for (i = 0; i < CALIB_SCALE; i++)
281 __asm __volatile(
"");
287 __asm __volatile(
"");
295 for (i = 0; i < CALIB_SCALE; i++)
_MCOUNT_DECL(uintfptr_t frompc, uintfptr_t selfpc)