Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w89VX-000G4r-14 for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Apr 2026 04:18:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w89VW-003rcA-0l for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Apr 2026 04:18:14 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w89VV-003rc1-33 for pgsql-hackers@lists.postgresql.org; Thu, 02 Apr 2026 04:18:14 +0000 Received: from mail-qk1-x72c.google.com ([2607:f8b0:4864:20::72c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w89VU-000000007js-1eez for pgsql-hackers@lists.postgresql.org; Thu, 02 Apr 2026 04:18:13 +0000 Received: by mail-qk1-x72c.google.com with SMTP id af79cd13be357-8cfc2d1fdbfso41290285a.3 for ; Wed, 01 Apr 2026 21:18:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775103492; cv=none; d=google.com; s=arc-20240605; b=HsDO/qRhEFtqjPFDaoYHGGedfRpDY5OxC6Edc808Lp0N+zW0aGLw2JA/txUYI7oqZL nj0erOqfQseGv1Kd0DvXPodd1b2ul0mnQbahl/0Yw7ARGqOPuDPIZfB2Z6r7vacvBhAa uoKbD65XfvB5ZGgE9baNxn//Gxckuym8RdNbADhz7i9IxJ0q9vj73xISRPupHsumJENO MLYt26y32wesmXyhN3/SImNAMC4dm8uhd/MURcPIzZnxH43g2PBnc4kDZNGJZBoaA8jT cIZ/2HMT2QyFQxqFRopRgPjhRQ6IYFHOK1eJW8Uo/TiAAtsd2OgGER/+bKLzxNoPKRsv 8PVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=1uBlPCRMGknymRF3Mkr9fUiSo7vwQnLUruwwX62OFLg=; fh=Q08Ee6xj138z8XBbqBHS2haokZHyBF4L8Yk5F3v8n0c=; b=gP6L8INq83v0Z1z2NJ8N5jodS7P//iISI9W/nykzwHPdROAYmdRP+xcW9bFtrrab8q i2OrEoFY+Yasf5jC48MmRzeu7s5WbEqDXlb2mLbAcHci+dF0aRQqZbBkFBiEkhYjTJDY 1LO8d8Pp2tm4Y4UZOt4pUmFqNOc5O5Fd9+8IEwM8biD8+bYV3IP8q9i8vJ2kApH7S5xi aHtSchG/V9p0vF7D5sVoDoai307NkIVc6wSWJqpRZYemQd0dKEglX9RFXuOfZgYoG5C1 SRt04X8z9o2u/r5mmQxqmQV/WgVxYaO0goVnBkAtzzM7U/CETT0FkEw3yCKQJuJTlqne yNNQ==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fittl.com; s=google; t=1775103492; x=1775708292; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=1uBlPCRMGknymRF3Mkr9fUiSo7vwQnLUruwwX62OFLg=; b=JW+cXNoqs0YpkgTyG0vibLcJwG0Mi/cyT2PAfmK546cmJ0ujIwKKJ6Sx0+vFzz+ESO f/kb6+YO/+4vEKgnCL/YBTY3BmfApldVy2bFjNNW8X2aCZoZDu9JAGe0AUj9npZBkb3X NnNqygNBIzF/dNjxq4mz6TKyyRHkXM+iiVcLs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775103492; x=1775708292; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=1uBlPCRMGknymRF3Mkr9fUiSo7vwQnLUruwwX62OFLg=; b=XzIoUunjFdsdqXPBeEOcQ+f+Jr+eyhT3aFvUv6iQqSnVhQ0e5UuSGy+kDsNLcxW4Bg TvhtpRiKv+eYeD65JXAc8wdJlRUxLYmXb6BASQCNWeNvJjSEfkJ1pOOyZ26eTH+p77sY Z3I43VAZpV5IITcqmC+M2jMhDOOx9e2KKwRlZC3FPa0nOCez8RYAB9A3QPfHxx5xMYak 2Sfah8v201S5QQdnZVcZY1hHeUTpYwd/6H29PA8dZXkE/gWoxSdNJZV9QuhD4kS3NbH+ oxzpzYRITIwuIiDlmrn7cN6A0yCEaZD2c+g/vcM7gfX8jCV2PEsWTLCVKhYVgfdTe7mU Gt0A== X-Gm-Message-State: AOJu0YycWi3h1Gn4hAPE2fV2fbytnaC2O8RVxj7r3bsj7dGfIqHyG+d9 fOeGQW4v0jR4PKZfR1mh1RSQyAbVtd7yrB/pNlNJqMD47bdRXQLDNPu1cakPHzLmqnDyIBDbe4G g7meIYBj1QS7aGi2hQ4VwTKcYgWdegLkSlP9kmczD X-Gm-Gg: ATEYQzycRg16vBRrUUZbCiV0+aXYua/C038JmU+4fPEoG31+Ww3GphyF4qULunRW0jK BiQ5HE/LdhMj5bnpYPGTt/dgbu/2BcNCxSbOso8GJOQroJh09IX8RtaGGaRUaznst1t57xLyxdz +cXSkMFpfic4t6V5wPRvpfHMy74DwYDVhPkf6uTaSP0rBEBTK4C3MqMcUJIKxjF3uTc/xuXm8qU LB9l6N+VP2sDSQo5h0fPHgeCaPc+s/Q9E98Y9U0u7TDJwp3S4rl9JS7PXeyO+juAzVxNImU5rRC /r6RLUPc4Y8CgRrh00RqGI6ssy+lFrQ7JYqnfpWG X-Received: by 2002:a05:620a:d84:b0:8cd:8f04:50df with SMTP id af79cd13be357-8d1b5a9fd73mr950984885a.12.1775103491608; Wed, 01 Apr 2026 21:18:11 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Lukas Fittl Date: Wed, 1 Apr 2026 21:17:35 -0700 X-Gm-Features: AQROBzC-iEDFIvWNMzrZNz5vpusy9czUh3Deap4bcjh-4_irx23XUdFi11GsMrI Message-ID: Subject: Re: pg_test_timing: fix unit typo and widen diff type To: Chao Li Cc: PostgreSQL Hackers , Tom Lane , Hannu Krosing Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi Chao, On Wed, Apr 1, 2026 at 8:10=E2=80=AFPM Chao Li wro= te: > > Hi, > > This morning, as part of my usual routine, I synced the master branch and= read through the recent commits. While reading 82c0cb4e672, I noticed a mi= stake in an error message. The relevant code is like: > ``` > diff =3D INSTR_TIME_GET_NANOSEC(diff_time); > > fprintf(stderr, _("Time warp: %d ms\n"), diff); > ``` > > Here, =E2=80=9Cdiff" is in nanoseconds, but the error message prints ms a= s the unit, which is incorrect. Good catch! It looks like the use of nanoseconds for "diff" got introduced last year in 0b096e379e6f9bd49 (as you note later in the email, today's commit didn't actually change that part), CCing Tom and Hannu as authors of that earlier change. That said, its a bit odd that we were using INSTR_TIME_GET_MICROSEC there before that earlier commit, but called it "ms" (i.e. milliseconds) in the error message. > > To fix that, I think there are two possible options: > > 1. Use INSTR_TIME_GET_MILLISEC to get =E2=80=9Cdiff" > 2. Change =E2=80=9Cms" to =E2=80=9Cns" in the error message > > After reading through the whole file, I think option 2 is the right fix. = While doing that, I also noticed another issue. > > =E2=80=9Cdiff" is currently defined as int32. Although one might think th= at is enough for a time delta, I believe it should be int64 for two reasons= : > > * INSTR_TIME_GET_NANOSEC() explicitly returns int64: > ``` > #define INSTR_TIME_GET_NANOSEC(t) \ > ((int64) (t).ticks) > ``` > > * The current code has a sanity check for backward clock drift: > ``` > /* Did time go backwards? */ > if (unlikely(diff < 0)) > { > fprintf(stderr, _("Detected clock going backwards in time.\n"= )); > fprintf(stderr, _("Time warp: %d ms\n"), diff); > exit(1); > } > ``` > Clock jumping forward is also possible, and a forward jump of about 2.14 = seconds would overflow int32 when expressed in nanoseconds, making the valu= e appear negative. In that case, the code could report a =E2=80=9Cbackwards= =E2=80=9D clock jump when the actual jump was forwards, which would be misl= eading. I agree it doesn't seem sound to use an int32 for storing the result of INSTR_TIME_GET_NANOSEC. It looks like we may also need to adjust the call to pg_leftmost_one_pos32 though if we actually accept that large a "diff" value, as in your patch. Maybe we should error out if the diff is larger than an int32, noting a positive time drift? Independently of that, its worth noting we could easily emit the diff in a larger unit (micro or milliseconds) for easier interpretation, by just calling INSTR_TIME_GET_MICROSEC / INSTR_TIME_GET_MILLISEC on the "diff_time" again. Thanks, Lukas -- Lukas Fittl