From nobody Sat Feb 26 23:11:31 2022 X-Original-To: bugs@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 6624619D22B8 for ; Sat, 26 Feb 2022 23:11:31 +0000 (UTC) (envelope-from bugzilla-noreply@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 4K5j7l0R4Tz3HPP for ; Sat, 26 Feb 2022 23:11:31 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (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 E32591CA01 for ; Sat, 26 Feb 2022 23:11:30 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 21QNBUAe065584 for ; Sat, 26 Feb 2022 23:11:30 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 21QNBUHn065583 for bugs@FreeBSD.org; Sat, 26 Feb 2022 23:11:30 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 262215] Two imprecisions in cputime counters Date: Sat, 26 Feb 2022 23:11:31 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: 13.0-RELEASE X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: firk@cantconnect.ru X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@freebsd.org MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645917091; 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=ZedgTmBo/2ShSkmgEfnrlLPES5oCFYBwIGcRe2U/08g=; b=SBI8wSgr3Au8worBbGn7rfxEb1KlIQ84SYdav7nF4en+KdZ/nLtONUQdH/JQudDtjUcE+1 SZfucOhhw/KEZNN/0wg2IrdhTKTOG6gGteyqQIiEywuRXRKsLpwbrLZ4Eg+gOEl/K21QPi BDZbycGuwrUDYjsPVlh8QrzTSUmRiqwIa7OFJg4a8aSbaxUAOtX3GKW/ui3UULnySsmrwO umtuv5Bgs9AfZH2Rx7J2vtR3x3yns5lTTRP/Ig+J174wk0P00WqR24mxJVuuCNJCjNT50g IyQRRyznNFS9hAXCbK1q2551iGFprNLa8Ubb0Gc9sAUCtmFX8IDrc6YinIB7Tw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645917091; a=rsa-sha256; cv=none; b=YkblIKvfseoCxayMAKhPeU3pCGCz5npoEUrCeXejvD798ienm5i31Wz9cLNMBFstdDc06D tXv2t2P5JOQrzjTsH4mbrURtzatuGAhbUeTBxaGnvajzdXqrcGc4tcX/l2d+QA98WwkHdJ 7DmfSLkoLN6ebEHGLgY4hBkzfljbtJyMLgZIFpoUtk30KblLHq6uTm3amSySeunPWBRT9F L/hWebvVdwJAxEExJccnAAUqUaVc4Y3nRLv2Ordb7/328Ud+aCL5JpmVzf8fqOANjdAQpQ IbcaHkRJfhHepPR/RU1EEo1kN9H2iAnziCjxRz8B/ivfI1OmvLmvFW3Z3wRWxA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D262215 Bug ID: 262215 Summary: Two imprecisions in cputime counters Product: Base System Version: 13.0-RELEASE Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: firk@cantconnect.ru Created attachment 232127 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D232127&action= =3Dedit patch for 10.4 - 14-CURRENT =3D=3D=3D=3D=3D=3D kern_tc.c/cputick2usec() =3D=3D=3D=3D=3D=3D > uint64_t cputick2usec(uint64_t tick) { > if (tick > 18446744073709551LL) /* floor(2^64 / 1000) */ > return (tick / (cpu_tickrate() / 1000000LL)); > else if (tick > 18446744073709LL) /* floor(2^64 / 1000000) */ > return ((tick * 1000LL) / (cpu_tickrate() / 1000LL)); > else > return ((tick * 1000000LL) / cpu_tickrate()); > } There is huge precision loss from dividing cpu_tickrate() by 1000 or 1000000 (up to 0.025% in the second case for 4GHz CPU). Worse, it will result in useconds step after reaching these two thresholds. Let's see: CPU 3999999999 Hz tick =3D 18446744073709 (real time 1:16:51.686019) usec =3D 18446744073709*1000000/3999999999 =3D 4611686019 =3D 1:16:51.686019 next usec =3D 18446744073710*1000/3999999 =3D 4611687171 =3D 1:16:51.687171 diff =3D 1152 usec (not so big, and such a step may be caused by a lot of s= ources anytime, but it is a fake step anyway) tick =3D 18446744073709551 (real time 53D 9:01:26.019580) usec =3D 18446744073709551*1000/3999999 =3D 4611687171349 =3D 53D 9:01:27.1= 71349 (note already 1 sec imprecise) next usec =3D 18446744073709552/3999 =3D 4612839228234 =3D 53D 9:20:39.2282= 34 diff =3D 19 minutes! =3D=3D=3D=3D=3D=3D kern_time.c/cputick2timespec() =3D=3D=3D=3D=3D=3D (it is used for clock_gettime() for querying process or thread consumed cpu time) Uses cputick2usec() and then needlessly converting usec to nsec, obviously losing precision even with fixed cputick2usec(). =3D=3D=3D=3D=3D=3D kern_time.c/kern_clock_getres() =3D=3D=3D=3D=3D=3D Uses some weird (anyway wrong) formula for getting cputick resolution. ------- patch attached the patch was done for 12.3, but may be applied succesfully to any version = from 10.4 to CURRENT --=20 You are receiving this mail because: You are the assignee for the bug.=