From nobody Sun Oct 23 08:14:18 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Mw9wB4jvcz4gXDc; Sun, 23 Oct 2022 08:14:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Mw9wB49wqz43xx; Sun, 23 Oct 2022 08:14:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666512858; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=b+rQey/RD8QMZyfnSWuiFPkII1aXMg22lvEppESlI5I=; b=V6ULMJNr/IDv80P2Q7Z+qMYGypmf0MmloM8G+THl17eqfwFRhCrTvdmDIg6Xwu7G2n+S2D 86jmEcZRVduwMeJl2vkZouGSzngI/kPIJG0+Ar4eA7VLjVecQMEcgqPwc+upT6BYMXdyWi 484l6JoeJC59EwZHB7q1TJRzBjR6dgmm6i9KgJX+FkWYIaeM4jS129P0Fy1Tb+UQxs8668 zbTihBDcIbUhMm7Q6/rt8e1sk9ErLvT+AMBWTMdnOVsCnk3rghOt6HCNTuujAc7rkDJhLB FICdMACNlBmkydgYGvlRVw3eM8qgxvv6F+lnuaTYjJSVXJD7SqkeOPiUlIxaHA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Mw9wB38VmzqWG; Sun, 23 Oct 2022 08:14:18 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 29N8EIDL054279; Sun, 23 Oct 2022 08:14:18 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29N8EIjW054278; Sun, 23 Oct 2022 08:14:18 GMT (envelope-from git) Date: Sun, 23 Oct 2022 08:14:18 GMT Message-Id: <202210230814.29N8EIjW054278@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Hans Petter Selasky Subject: git: ee29897fc3d6 - main - time(3): Declare the minimum and maximum hz values supported. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: hselasky X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ee29897fc3d66ba7006c9ee3f524bf2e8cf30a4f Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666512858; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=b+rQey/RD8QMZyfnSWuiFPkII1aXMg22lvEppESlI5I=; b=l/2lHw83tm+277LfHNom6c+84uZ24s2o4OZUMq4iIWNycqzhBvxUA5s39TIc4senpLiuIT AFk9c+gpzJdfyBhpeeipw6aX8siHu7nC+qmpLc8DvZd/1R+h0v/QQATVDg9C0lJPU5rXLr cpg1bIm1W7onK/IQPle/kwAP6Ouwys1CRxJFRt0jc3f22g6/2bSzJiS0sCkCejfulAlSGF avyoBANmlI2p7LsIyK6x8uZf2kY9VFHN20OuwoK6tTSWJpYZTp9VuIU/5emtrfKR+Mn7hm 5IfQmmdGNUy0V+8YN9m349Z+Pj8izebI0BkThcpjH+9NO+3Tb5HWepIQi8HUPQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666512858; a=rsa-sha256; cv=none; b=xR1RHhHhOD68qBX1j7y1wzIMzvBpYnb9sIKtyiAV3/d4Wog4pIswXpTmcb7zGsG32C51gG J/KqtUFGNTWR6CHFaWS6XVet6Ycso9rBoqSdUwlP92u4kH49M7WED88QnoY0iLq11/lcfN 6DomsBBJXP87/oLm4xd675lH/3WmASXmMSPQFZGzNPrC/HZSOk3IAx1Nt5s/kiJALmqU3+ JE/iPO4OYAOtha4PduOqh/0NJV/3g3kVv3PBChccyn1Tw+3zJbsZKGCij+0mq4LlEKkv4g vhrT3UII4tFmvgQO6vddhCt9p8ET8AeTajiEfdf16CKKXX2XvmtJiH9E/mq54w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by hselasky: URL: https://cgit.FreeBSD.org/src/commit/?id=ee29897fc3d66ba7006c9ee3f524bf2e8cf30a4f commit ee29897fc3d66ba7006c9ee3f524bf2e8cf30a4f Author: Hans Petter Selasky AuthorDate: 2022-10-03 09:08:53 +0000 Commit: Hans Petter Selasky CommitDate: 2022-10-23 08:04:50 +0000 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 --- sys/kern/subr_param.c | 11 +++++++++++ sys/sys/time.h | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/sys/kern/subr_param.c b/sys/kern/subr_param.c index ebb21283c5f9..f9c2f8df87b8 100644 --- a/sys/kern/subr_param.c +++ b/sys/kern/subr_param.c @@ -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); diff --git a/sys/sys/time.h b/sys/sys/time.h index 41d84aab5640..5d7f3f07234e 100644 --- a/sys/sys/time.h +++ b/sys/sys/time.h @@ -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) \