time(3): Declare the minimum and maximum hz values supported.

Reviewed by:	kib@ and imp@
MFC after:      1 week
Sponsored by:   NVIDIA Networking
Differential Revision:	https://reviews.freebsd.org/D37072
This commit is contained in:
Hans Petter Selasky 2022-10-03 11:08:53 +02:00
parent e0c3f66b4d
commit ee29897fc3
2 changed files with 18 additions and 0 deletions

View File

@ -111,6 +111,10 @@ u_long sgrowsiz; /* amount to grow stack */
SYSCTL_INT(_kern, OID_AUTO, hz, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &hz, 0,
"Number of clock ticks per second");
SYSCTL_INT(_kern, OID_AUTO, hz_max, CTLFLAG_RD, SYSCTL_NULL_INT_PTR, HZ_MAXIMUM,
"Maximum hz value supported");
SYSCTL_INT(_kern, OID_AUTO, hz_min, CTLFLAG_RD, SYSCTL_NULL_INT_PTR, HZ_MINIMUM,
"Minimum hz value supported");
SYSCTL_INT(_kern, OID_AUTO, nbuf, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &nbuf, 0,
"Number of buffers in the buffer cache");
SYSCTL_INT(_kern, OID_AUTO, nswbuf, CTLFLAG_RDTUN | CTLFLAG_NOFETCH, &nswbuf, 0,
@ -173,6 +177,13 @@ init_param1(void)
TUNABLE_INT_FETCH("kern.hz", &hz);
if (hz == -1)
hz = vm_guest > VM_GUEST_NO ? HZ_VM : HZ;
/* range check the "hz" value */
if (__predict_false(hz < HZ_MINIMUM))
hz = HZ_MINIMUM;
else if (__predict_false(hz > HZ_MAXIMUM))
hz = HZ_MAXIMUM;
tick = 1000000 / hz;
tick_sbt = SBT_1S / hz;
tick_bt = sbttobt(tick_sbt);

View File

@ -583,6 +583,13 @@ void timevaladd(struct timeval *t1, const struct timeval *t2);
void timevalsub(struct timeval *t1, const struct timeval *t2);
int tvtohz(struct timeval *tv);
/*
* The following HZ limits allow the tvtohz() function
* to only use integer computations.
*/
#define HZ_MAXIMUM (INT_MAX / (1000000 >> 6)) /* 137kHz */
#define HZ_MINIMUM 8 /* hz */
#define TC_DEFAULTPERC 5
#define BT2FREQ(bt) \