mirror of
https://github.com/openbsd/src.git
synced 2025-01-03 06:45:37 -08:00
moncontrol(3): remove hertz() fallback function
In the moncontrol(3) code in libc there is a fallback function, hertz(). The idea is, if getting kern.clockrate from sysctl(2) fails, we fall back to deriving the value of hz(9) using setitimer(2)'s rounding behavior. This is extremely clever, but it actually sucks. Calling setitimer(2) quietly cancels any extant ITIMER_REAL timer, so moncontrol(3) cannot be safely used alongside setitimer(2). This fact is not documented. kern.clockrate is not blocked by pledge(2), so outside of stack corruption (which we can't do anything about anyway) I don't see a way for the sysctl(2) call to ever fail on OpenBSD. So hertz() is also pointless. Hence this patch: get rid of hertz(). Thread: https://marc.info/?l=openbsd-tech&m=163881542813633&w=2 ok guenther@
This commit is contained in:
parent
8de049a7e2
commit
39152b4f44
@ -1,4 +1,4 @@
|
|||||||
/* $OpenBSD: gmon.c,v 1.32 2020/10/12 22:08:33 deraadt Exp $ */
|
/* $OpenBSD: gmon.c,v 1.33 2022/07/26 04:07:13 cheloha Exp $ */
|
||||||
/*-
|
/*-
|
||||||
* Copyright (c) 1983, 1992, 1993
|
* Copyright (c) 1983, 1992, 1993
|
||||||
* The Regents of the University of California. All rights reserved.
|
* The Regents of the University of California. All rights reserved.
|
||||||
@ -50,7 +50,6 @@ static int s_scale;
|
|||||||
|
|
||||||
PROTO_NORMAL(moncontrol);
|
PROTO_NORMAL(moncontrol);
|
||||||
PROTO_DEPRECATED(monstartup);
|
PROTO_DEPRECATED(monstartup);
|
||||||
static int hertz(void);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
monstartup(u_long lowpc, u_long highpc)
|
monstartup(u_long lowpc, u_long highpc)
|
||||||
@ -159,17 +158,15 @@ _mcleanup(void)
|
|||||||
if (p->state == GMON_PROF_ERROR)
|
if (p->state == GMON_PROF_ERROR)
|
||||||
ERR("_mcleanup: tos overflow\n");
|
ERR("_mcleanup: tos overflow\n");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* There is nothing we can do if sysctl(2) fails or if
|
||||||
|
* clockinfo.hz is unset.
|
||||||
|
*/
|
||||||
size = sizeof(clockinfo);
|
size = sizeof(clockinfo);
|
||||||
if (sysctl(mib, 2, &clockinfo, &size, NULL, 0) == -1) {
|
if (sysctl(mib, 2, &clockinfo, &size, NULL, 0) == -1) {
|
||||||
/*
|
clockinfo.profhz = 0;
|
||||||
* Best guess
|
|
||||||
*/
|
|
||||||
clockinfo.profhz = hertz();
|
|
||||||
} else if (clockinfo.profhz == 0) {
|
} else if (clockinfo.profhz == 0) {
|
||||||
if (clockinfo.hz != 0)
|
clockinfo.profhz = clockinfo.hz; /* best guess */
|
||||||
clockinfo.profhz = clockinfo.hz;
|
|
||||||
else
|
|
||||||
clockinfo.profhz = hertz();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
moncontrol(0);
|
moncontrol(0);
|
||||||
@ -304,23 +301,3 @@ moncontrol(int mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
DEF_WEAK(moncontrol);
|
DEF_WEAK(moncontrol);
|
||||||
|
|
||||||
/*
|
|
||||||
* discover the tick frequency of the machine
|
|
||||||
* if something goes wrong, we return 0, an impossible hertz.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
hertz(void)
|
|
||||||
{
|
|
||||||
struct itimerval tim;
|
|
||||||
|
|
||||||
tim.it_interval.tv_sec = 0;
|
|
||||||
tim.it_interval.tv_usec = 1;
|
|
||||||
tim.it_value.tv_sec = 0;
|
|
||||||
tim.it_value.tv_usec = 0;
|
|
||||||
setitimer(ITIMER_REAL, &tim, 0);
|
|
||||||
setitimer(ITIMER_REAL, 0, &tim);
|
|
||||||
if (tim.it_interval.tv_usec < 2)
|
|
||||||
return(0);
|
|
||||||
return (1000000 / tim.it_interval.tv_usec);
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user