-/* $OpenBSD: subr_prof.c,v 1.32 2023/04/25 00:58:47 cheloha Exp $ */
+/* $OpenBSD: subr_prof.c,v 1.33 2023/04/25 01:32:36 cheloha Exp $ */
/* $NetBSD: subr_prof.c,v 1.12 1996/04/22 01:38:50 christos Exp $ */
/*-
* until we're sure they are in a sane state.
*/
int gmoninit = 0;
+u_int gmon_cpu_count; /* [K] number of CPUs with profiling enabled */
extern char etext[];
{
int error = 0;
+ KERNEL_ASSERT_LOCKED();
+
if (gp->state == oldstate)
return (0);
*/
error = db_prof_enable();
#endif
- if (error == 0)
- startprofclock(&process0);
+ if (error == 0) {
+ if (++gmon_cpu_count == 1)
+ startprofclock(&process0);
+ }
break;
default:
error = EINVAL;
gp->state = GMON_PROF_OFF;
/* FALLTHROUGH */
case GMON_PROF_OFF:
- stopprofclock(&process0);
+ if (--gmon_cpu_count == 0)
+ stopprofclock(&process0);
#if !defined(GPROF)
db_prof_disable();
#endif