From nobody Mon Oct 11 08:58:24 2021 X-Original-To: freebsd-hackers@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 5ED5F17F7A1F for ; Mon, 11 Oct 2021 08:58:35 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (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 mx1.freebsd.org (Postfix) with ESMTPS id 4HSXlH0PrXz3LX7 for ; Mon, 11 Oct 2021 08:58:34 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.16.1/8.16.1) with ESMTPS id 19B8wOxa083459 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 11 Oct 2021 11:58:28 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 19B8wOxa083459 Received: (from kostik@localhost) by tom.home (8.16.1/8.16.1/Submit) id 19B8wO7r083458; Mon, 11 Oct 2021 11:58:24 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 11 Oct 2021 11:58:24 +0300 From: Konstantin Belousov To: Sebastian Huber Cc: FreeBSD Hackers Subject: Re: Large timecounter delta handling Message-ID: References: <5318327d-d247-bb73-81d9-967c4ae18d32@embedded-brains.de> List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5318327d-d247-bb73-81d9-967c4ae18d32@embedded-brains.de> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.5 X-Spam-Checker-Version: SpamAssassin 3.4.5 (2021-03-20) on tom.home X-Rspamd-Queue-Id: 4HSXlH0PrXz3LX7 X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-ThisMailContainsUnwantedMimeParts: N On Mon, Oct 11, 2021 at 09:53:31AM +0200, Sebastian Huber wrote: > Hello, > > I synchronize currently the port of the FreeBSD timecounters to RTEMS. I > have to write test cases for all code we use in RTEMS. In 2020 some code was > added to fix integer overflow issues with large time deltas while getting > the time from a timehand. > > https://github.com/freebsd/freebsd-src/commit/6cf2362e2c7e9061611f93a48ec654a5b7451d6b#diff-8b8e2f8e41e6a847f14ab08c7d50454c20a4a135f2c2241d91687c0832c1d99e > > If a time delta obtained by tc_delta(th) is greater than or equal to > th->th_large_delta, then some extra calculation is carried out. > > The th->th_large_delta is computed like this > > scale = (uint64_t)1 << 63; > scale += (th->th_adjustment / 1024) * 2199; > scale /= th->th_counter->tc_frequency; > th->th_scale = scale * 2; > th->th_large_delta = MIN(((uint64_t)1 << 63) / scale, UINT_MAX); > > If we ignore the th->th_adjustment (== 0), then we have ideally > > scale = 2**64 / f > th->th_large_delta = MIN( f / 2, UINT_MAX ) > > Does this mean that we only need the large delta processing if a timehand > was not updated for about 0.5s? I do not understand your question. We need large_delta to handle overflows in bintime_off(). tc_large_delta is computed in advance during windup to avoid this calculation in time reading code. Your question is more like "under which conditions we switch to use tc_large_delta path in bintime_off()?" Then it is mostly right, that long intervals between tc_windup() calls would trigger it, and it seems that indeed it is around 0.5 sec. If you have a controlled environment, just skip some tc_windup() calls to see.