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 1w88Rd-000FEG-10 for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Apr 2026 03:10:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w88Rc-003V9N-0a for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Apr 2026 03:10:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1w88Rb-003V9E-2n for pgsql-hackers@lists.postgresql.org; Thu, 02 Apr 2026 03:10:08 +0000 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w88RZ-000000007yq-1qf2 for pgsql-hackers@lists.postgresql.org; Thu, 02 Apr 2026 03:10:08 +0000 Received: by mail-pj1-x1029.google.com with SMTP id 98e67ed59e1d1-35da01fc0baso233176a91.2 for ; Wed, 01 Apr 2026 20:10:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775099402; x=1775704202; darn=lists.postgresql.org; h=to:date:message-id:subject:mime-version:from:from:to:cc:subject :date:message-id:reply-to; bh=rNdj0qm+rTUacZHUKGFl0niY9MF+nTG8Ke41LyKcHAU=; b=JXGE01TaQgIOXj4quXS51l2D7C0v7bYQP8hYscrt7NlYO4+cqmqUMpwGBBC/GlBJBM kqTC9qa1PAKJBhJjzqsSsjGK2nMj5ElzRAC1KQCAjeYJWuU0M5p1SAeUgjTV3zHhzCvL Vc3T0/u+osDzdIAAS8lkHT00pWghTSP1cI78X+rN/447IKrOwIb95ilViTf52+m3sBsh eeExSYq6Ojb1bLSHp0lPV2PKyhIfqLSnvdDDoKDvrWORmKK4AkVF638Kr/I6RZuijoOK 60opyAGtzQoCQ8cFCmlGnSAKM+KUG6OAni6rRbmzO4oUpN7BdoLXMOK3ZDjos4Zkn0LS hdrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775099402; x=1775704202; h=to:date:message-id:subject:mime-version:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=rNdj0qm+rTUacZHUKGFl0niY9MF+nTG8Ke41LyKcHAU=; b=gr+ZZyf2QjGSSMzbiv7uPy4z2SMPgrCUuvx4jgc+2gCw5VryDF13Yqvz+JirsdcjA5 sOGonBmWaYssWoe/6RU9mBz6ZVfmLCO8OcAn3Tdou+IgWr2iZcsoaDHyua+blY9EOo4q x+Uo5OplAhGBhQKkmuPtq1YUMySnbbJxNzIy/X6Jf9m8DwSFcyHTIC2iGgExsVpIbA7o tSx2OgzSy6zUcPd7M/tZ4oVU6WE3ZgV273GFBZrh1zKrz71oBwRo9UheVW2GXCzhhbkm zTXYqrbCPRN7B1a7UASkBOLYLWrxon76L+DAbBL5DZOtMVMA94QKAL3GQBu6FpzwpTw4 sLXQ== X-Gm-Message-State: AOJu0YwRtaHZziJ4pb9MiF7663/EUiC8vMA38KuFPQGxBVkz2nlA35hI k63Fvkp5CMuTqjJ2qzXYabIQ8PmvGqkTSeNvKL17lGARUj4zYKG9TdNAYM9tvoJHNyQ= X-Gm-Gg: ATEYQzwU/Kx1jKbjxl1M/yxmARZR3A6AMeS17Bw6EfhgDpJNWcoYGUVYJtmPfZkEsHw gJdSOGgvsa2Q1IqupMtO0d3txb7aljLxdl46sgEO9vsibWLxBhzLXkTQ6uv0KXVnGSGZHUNRXDX 093lTc+fp9htuE2ZZ1ILJZO6aFp5MDw21iHaNmAtGFpB9ZEHGc97GbivgvpAbKC7lSvWrPTPrEw nam1ZcIaBFsunDbpJV+XG4Z3yqUCVexoiEAiu5G5xfM/b1CljMJxPeo4Bqt1k5dnFgzaUSabNcu xJivPO0m+iDN0dc4+1bI7lA47/aDNwLyNKFBbDVPV6PBm5N9kKKNaHXjBRs7eSaAG0s9jkTaIL0 aFMRhfQkO3VRziTfec2AqWQpXTDas2YgvJ1D5PxpPhkooS0EcnU0olwMJxmAJFYEwKhdV+9vrqg l715Aioat2JrzIC/uw8kHwyC9penJuA1U= X-Received: by 2002:a17:90b:380f:b0:35d:9d4f:f58a with SMTP id 98e67ed59e1d1-35dc6eb7da1mr5747736a91.9.1775099402260; Wed, 01 Apr 2026 20:10:02 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-35dd35f7229sm1114712a91.7.2026.04.01.20.10.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Apr 2026 20:10:01 -0700 (PDT) From: Chao Li Content-Type: multipart/mixed; boundary="Apple-Mail=_5D6B312F-5340-4C15-82F5-67111BAF2BE0" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: pg_test_timing: fix unit typo and widen diff type Message-Id: Date: Thu, 2 Apr 2026 11:09:23 +0800 To: PostgreSQL Hackers X-Mailer: Apple Mail (2.3864.400.21) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Apple-Mail=_5D6B312F-5340-4C15-82F5-67111BAF2BE0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 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 mistake 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 = as the unit, which is incorrect. 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 = that 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 = value 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 misleading. To make the patch easier to process, I split it into two parts: 0001 = fixes the unit in the error message, and 0002 changes the type of diff. = If this gets accepted, I would be happy to squash them into one commit. I should also note that although I noticed this while reading = 82c0cb4e672, I do not think this was an oversight of that commit. More = likely, because clock drift backwards is rare, this issue has simply = gone unnoticed for many years. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_5D6B312F-5340-4C15-82F5-67111BAF2BE0 Content-Disposition: attachment; filename=v1-0001-pg_test_timing-fix-unit-in-backward-clock-warning.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v1-0001-pg_test_timing-fix-unit-in-backward-clock-warning.patch" Content-Transfer-Encoding: quoted-printable =46rom=200dc6d45322d60fb54c27a649f2b146242ed64f62=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20"Chao=20Li=20(Evan)"=20=0A= Date:=20Thu,=202=20Apr=202026=2010:21:40=20+0800=0ASubject:=20[PATCH=20= v1=201/2]=20pg_test_timing:=20fix=20unit=20in=20backward-clock=20warning=0A= =0Apg_test_timing=20measures=20timing=20differences=20in=20nanoseconds=20= via=0AINSTR_TIME_GET_NANOSEC(),=20but=20the=20backward-clock=20warning=20= incorrectly=0Areported=20the=20value=20as=20milliseconds.=20Fix=20the=20= message=20to=20use=20"ns"=20so=0Athat=20it=20matches=20the=20actual=20= unit=20of=20diff.=0A=0AAuthor:=20Chao=20Li=20=0A= Reviewed-by:=0ADiscussion:=20https://postgr.es/m/=0A---=0A=20= src/bin/pg_test_timing/pg_test_timing.c=20|=202=20+-=0A=201=20file=20= changed,=201=20insertion(+),=201=20deletion(-)=0A=0Adiff=20--git=20= a/src/bin/pg_test_timing/pg_test_timing.c=20= b/src/bin/pg_test_timing/pg_test_timing.c=0Aindex=20= aee41dbe3f9..cbdc5af09d9=20100644=0A---=20= a/src/bin/pg_test_timing/pg_test_timing.c=0A+++=20= b/src/bin/pg_test_timing/pg_test_timing.c=0A@@=20-191,7=20+191,7=20@@=20= test_timing(unsigned=20int=20duration)=0A=20=09=09if=20(unlikely(diff=20= <=200))=0A=20=09=09{=0A=20=09=09=09fprintf(stderr,=20_("Detected=20clock=20= going=20backwards=20in=20time.\n"));=0A-=09=09=09fprintf(stderr,=20= _("Time=20warp:=20%d=20ms\n"),=20diff);=0A+=09=09=09fprintf(stderr,=20= _("Time=20warp:=20%d=20ns\n"),=20diff);=0A=20=09=09=09exit(1);=0A=20=09=09= }=0A=20=0A--=20=0A2.50.1=20(Apple=20Git-155)=0A=0A= --Apple-Mail=_5D6B312F-5340-4C15-82F5-67111BAF2BE0 Content-Disposition: attachment; filename=v1-0002-pg_test_timing-use-int64-for-largest-observed-tim.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v1-0002-pg_test_timing-use-int64-for-largest-observed-tim.patch" Content-Transfer-Encoding: quoted-printable =46rom=20e29ff7fef693e830b4929f9b7444cc943fd16516=20Mon=20Sep=2017=20= 00:00:00=202001=0AFrom:=20"Chao=20Li=20(Evan)"=20=0A= Date:=20Thu,=202=20Apr=202026=2010:29:06=20+0800=0ASubject:=20[PATCH=20= v1=202/2]=20pg_test_timing:=20use=20int64=20for=20largest=20observed=20= time=0A=20delta=0A=0Apg_test_timing=20obtains=20timing=20deltas=20with=20= INSTR_TIME_GET_NANOSEC(),=0Awhich=20returns=20a=20nanosecond=20value=20= that=20should=20be=20stored=20in=20int64.=20Adjust=0Adiff=20and=20= largest_diff=20to=20use=20int64=20accordingly.=0A=0AAlso=20fix=20the=20= corresponding=20printf=20format=20specifiers=20so=20these=20values=20are=0A= printed=20correctly.=0A=0AAuthor:=20Chao=20Li=20=0A= Reviewed-by:=0ADiscussion:=20https://postgr.es/m/=0A---=0A=20= src/bin/pg_test_timing/pg_test_timing.c=20|=2010=20+++++-----=0A=201=20= file=20changed,=205=20insertions(+),=205=20deletions(-)=0A=0Adiff=20= --git=20a/src/bin/pg_test_timing/pg_test_timing.c=20= b/src/bin/pg_test_timing/pg_test_timing.c=0Aindex=20= cbdc5af09d9..07b98a6388d=20100644=0A---=20= a/src/bin/pg_test_timing/pg_test_timing.c=0A+++=20= b/src/bin/pg_test_timing/pg_test_timing.c=0A@@=20-25,7=20+25,7=20@@=20= static=20long=20long=20int=20histogram[32];=0A=20static=20long=20long=20= int=20direct_histogram[NUM_DIRECT];=0A=20=0A=20/*=20separately=20record=20= highest=20observed=20duration=20*/=0A-static=20int32=20largest_diff;=0A= +static=20int64=20largest_diff;=0A=20static=20long=20long=20int=20= largest_diff_count;=0A=20=0A=20=0A@@=20-176,8=20+176,8=20@@=20= test_timing(unsigned=20int=20duration)=0A=20=0A=20=09while=20= (INSTR_TIME_GT(end_time,=20cur))=0A=20=09{=0A-=09=09int32=09=09diff,=0A-=09= =09=09=09=09bits;=0A+=09=09int64=09=09diff;=0A+=09=09int32=09=09bits;=0A=20= =09=09instr_time=09diff_time;=0A=20=0A=20=09=09prev=20=3D=20cur;=0A@@=20= -191,7=20+191,7=20@@=20test_timing(unsigned=20int=20duration)=0A=20=09=09= if=20(unlikely(diff=20<=200))=0A=20=09=09{=0A=20=09=09=09fprintf(stderr,=20= _("Detected=20clock=20going=20backwards=20in=20time.\n"));=0A-=09=09=09= fprintf(stderr,=20_("Time=20warp:=20%d=20ns\n"),=20diff);=0A+=09=09=09= fprintf(stderr,=20_("Time=20warp:=20%lld=20ns\n"),=20diff);=0A=20=09=09=09= exit(1);=0A=20=09=09}=0A=20=0A@@=20-319,7=20+319,7=20@@=20output(uint64=20= loop_count)=0A=20=09=09double=09=09prct=20=3D=20(double)=20= largest_diff_count=20*=20100=20/=20loop_count;=0A=20=0A=20=09=09= printf("...\n");=0A-=09=09printf("%*d=20=20=20%*.4f=20%*.4f=20%*lld\n",=0A= +=09=09printf("%*lld=20=20=20%*.4f=20%*.4f=20%*lld\n",=0A=20=09=09=09=20=20= =20len1,=20largest_diff,=0A=20=09=09=09=20=20=20len2,=20prct,=0A=20=09=09= =09=20=20=20len3,=20100.0,=0A--=20=0A2.50.1=20(Apple=20Git-155)=0A=0A= --Apple-Mail=_5D6B312F-5340-4C15-82F5-67111BAF2BE0--