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 1wFjPN-005U18-1h for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Apr 2026 02:03:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wFjPM-00Fzgg-2N for pgsql-hackers@arkaria.postgresql.org; Thu, 23 Apr 2026 02:03:12 +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 1wFjPM-00FzgX-0c for pgsql-hackers@lists.postgresql.org; Thu, 23 Apr 2026 02:03:12 +0000 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wFjPJ-00000002LCb-2x2L for pgsql-hackers@lists.postgresql.org; Thu, 23 Apr 2026 02:03:11 +0000 Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-35d965648a2so5322161a91.0 for ; Wed, 22 Apr 2026 19:03:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776909789; x=1777514589; darn=lists.postgresql.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=OYLORHJ3qOJmf3gxppWZVgOqI2Hj3buEwkpnh0YEnFY=; b=lvCgguTFoySbWeeAZCRyuS4TC/I3ABV+pEHGbUoF4WwUKj47Z44SYPZ/w8axJyJtdc eliZTDnTvBonenUku2Tw2Fdwep1Z1ClVvQfReAtLpyW6vFnTkCks8f/XQ9BLmPhY9mhf m1jktB/U0ZRY3aO82d/VLD5bsP9b+U0+P9ndVuzWnXkXNO+WL42jaJ8o6eXw8sJxjUAM JPMgNNEd45GezPHNBb8FFRZNV/1Asrb2a5KZQx/H+VzSHfWf8PXrjAEWXQGXsHlp000S hlw3LFkFfWF+HDE5CXDSi7NpFsFSm4O7VBX8jPKGB1TDelskOFhkBNjIltWedkHP8fEh sDqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776909789; x=1777514589; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=OYLORHJ3qOJmf3gxppWZVgOqI2Hj3buEwkpnh0YEnFY=; b=bAvddBRILAyBScyJYFLi9vCFLAHJvupS3QH+26zTAxsDEnCBSlhCHcxLiwqut+QDW3 uxHJmbQVnF6hVcghVAGcng5PrBmtuO5ldqthQicqLxFGn8tmYWXi8br8nWLRgiBn8XpH VXl2vXitGD9Y1vDrLUdjn+s7mmPc7noHGNn0lWOP4slaVJKzAXdte3BQgyZfpBj/ECRm SuCJjRzInOnYCIEg1xoGNKuqUOIISF2kuROnM80dsRxxRc9bMaWVmghQ4EQJTEFCV/QT eCIXF4m7XP4yeT0KTLEEq8z31s9PGxLFVd4kTfxIN+eApVOB2qWmdUT6umLZJoO8IYaU T1Wg== X-Forwarded-Encrypted: i=1; AFNElJ/oqH1J2gPJkeGRAxL8LHOP1+TX9WsIDlvObZ0PGVLPOG8sSeCKa7SJnS1r+vdAZz7BMx6Ob3Lhp/Rx+Rj/@lists.postgresql.org X-Gm-Message-State: AOJu0Yx36qWITDZVPd3HcuRL3HLyadsUoOBK26XMQ37HJod3VZkieYmP 4x6TFa0mnFlnPwe2g6e8LNTKy4swdHRutF9bizMDHSETpmaN4nNVfX5I X-Gm-Gg: AeBDietB7XQxE6H/pMgraQ9D/01vzo6pPIC01YtKQfp63oVn64YyrKHLPps6rWtlD8X AEyYuR0fgdIhr3ei3apATBupH2s5CTjGzpoG5qDUk/6yc/XshUskC8tEt130Gh49JfwJYHuvsvC F/stEFhIbVzW1FcmSUf+P/PAPbBm6dR0ZNS3Y/z3ULe58kDnaJU2QVZYnDZwDQPTn6XzhFsx6lT Ko4ln1+92u0W1RLOrLH3tZiIofJC2X3W8yRIr9cOGvVg+39reTn7xsjhWNnzKU1IxdQ9muCiWlA FSmtuRnHyM+BA5EcUpghncKLCE6eAF7HAi40AqrFNX1DxYw0pEBV/QWXZTUVF9RuH1FB7eA10hG 3Qk8WJw/QU0oEjcgnWutQQK2JYAoeTGv5krpO6sFdYhhHbUe3TNwCOL1OsaQxV2z4bVsjDNzHL0 BDOORXDIBx058imWTb7RLLLaT7VxuxqYvdBRPGoBz0mg== X-Received: by 2002:a17:90b:1d44:b0:35f:c493:cac7 with SMTP id 98e67ed59e1d1-3614049e4d1mr27719001a91.25.1776909789131; Wed, 22 Apr 2026 19:03:09 -0700 (PDT) Received: from smtpclient.apple ([45.32.121.103]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-36141868906sm18381989a91.3.2026.04.22.19.03.05 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 22 Apr 2026 19:03:08 -0700 (PDT) From: Chao Li Message-Id: <21E668C0-CEAE-44F8-B585-319F31883AFE@gmail.com> Content-Type: multipart/mixed; boundary="Apple-Mail=_78E6C52E-0496-47D5-88A6-0C4E8D5F9BF9" Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: pg_test_timing: fix unit typo and widen diff type Date: Thu, 23 Apr 2026 10:02:31 +0800 In-Reply-To: Cc: "wang.xiao.peng" , lukas@fittl.com, PostgreSQL Hackers , Tom Lane , Hannu Krosing To: Fujii Masao References: <7d4afbdb.5322.19d70df0de4.Coremail.wxp_728@163.com> <56B09FF0-13AB-4AF3-A4C4-29428A695FB0@gmail.com> 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=_78E6C52E-0496-47D5-88A6-0C4E8D5F9BF9 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Apr 23, 2026, at 00:11, Fujii Masao wrote: >=20 > On Wed, Apr 22, 2026 at 5:58=E2=80=AFPM Chao Li = wrote: >> PFA v4: >>=20 >> * 0001 unchanged from v3. >> * 0002 changed size of histogram[] 64. >=20 > Thanks for updating the patch! >=20 > Since patch 0001 is a bug fix, it should be backpatched to the = supported stable > branches. However, in v19 the unit should be changed like s/ms/ns, = while in v18 > and earlier s/ms/us, since those older branches report the diff in = microseconds. > Right? I just checked old branches. Looks like 0001 can be back-patched down to = v10. Yes, pre-19, all branches use microsecond, so the back-patch should = change =E2=80=9Cms=E2=80=9D to =E2=80=9Cus=E2=80=9D. I have helped create back-patch diff files as attached: * nocfbot.v10-v13.pg_test_timing-backpatch.diff for v10-v13 * nocfbot.v14-v15.pg_test_timing-backpatch.diff for v14-v15 * nocfbot.v16-v18.pg_test_timing-backpatch.diff for v16-v18 For v16 to v18, we can make a tiny improvement by replacing =E2=80=9C1e9=E2= =80=9D with a constant macro NS_PER_S. This change has been included in = the diff. I have built and tested on all branches. >=20 > Patch 0002 looks more like an improvement than a bug fix, so we should = probably > wait for the next CommitFest before committing it. Thoughts? >=20 I see 0002 a bit differently. In v19, the unit changed from microseconds = to nanoseconds, which introduced a potential overflow: nanoseconds = require int64, but the local variable remained int32. So I think this is = actually a v19-only bug. PFA v5: 0001 replaced =E2=80=9C1e9=E2=80=9D with NS_PER_S; 0002 = unchanged. Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/ --Apple-Mail=_78E6C52E-0496-47D5-88A6-0C4E8D5F9BF9 Content-Disposition: attachment; filename=nocfbot.v10-v13.pg_test_timing-backpatch.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="nocfbot.v10-v13.pg_test_timing-backpatch.diff" Content-Transfer-Encoding: 7bit diff --git a/src/bin/pg_test_timing/pg_test_timing.c b/src/bin/pg_test_timing/pg_test_timing.c index e14802372bd..79ef32353dc 100644 --- a/src/bin/pg_test_timing/pg_test_timing.c +++ b/src/bin/pg_test_timing/pg_test_timing.c @@ -138,7 +138,7 @@ test_timing(int32 duration) if (diff < 0) { fprintf(stderr, _("Detected clock going backwards in time.\n")); - fprintf(stderr, _("Time warp: %d ms\n"), diff); + fprintf(stderr, _("Time warp: %d us\n"), diff); exit(1); } --Apple-Mail=_78E6C52E-0496-47D5-88A6-0C4E8D5F9BF9 Content-Disposition: attachment; filename=nocfbot.v14-v15.pg_test_timing-backpatch.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="nocfbot.v14-v15.pg_test_timing-backpatch.diff" Content-Transfer-Encoding: 7bit diff --git a/src/bin/pg_test_timing/pg_test_timing.c b/src/bin/pg_test_timing/pg_test_timing.c index c29d6f87629..0ccf55761ce 100644 --- a/src/bin/pg_test_timing/pg_test_timing.c +++ b/src/bin/pg_test_timing/pg_test_timing.c @@ -149,7 +149,7 @@ test_timing(unsigned int duration) if (diff < 0) { fprintf(stderr, _("Detected clock going backwards in time.\n")); - fprintf(stderr, _("Time warp: %d ms\n"), diff); + fprintf(stderr, _("Time warp: %d us\n"), diff); exit(1); } --Apple-Mail=_78E6C52E-0496-47D5-88A6-0C4E8D5F9BF9 Content-Disposition: attachment; filename=nocfbot.v16-v18.pg_test_timing-backpatch.diff Content-Type: application/octet-stream; x-unix-mode=0644; name="nocfbot.v16-v18.pg_test_timing-backpatch.diff" Content-Transfer-Encoding: 7bit diff --git a/src/bin/pg_test_timing/pg_test_timing.c b/src/bin/pg_test_timing/pg_test_timing.c index ce7aad4b25a..3c7672f592d 100644 --- a/src/bin/pg_test_timing/pg_test_timing.c +++ b/src/bin/pg_test_timing/pg_test_timing.c @@ -149,7 +149,7 @@ test_timing(unsigned int duration) if (diff < 0) { fprintf(stderr, _("Detected clock going backwards in time.\n")); - fprintf(stderr, _("Time warp: %d ms\n"), diff); + fprintf(stderr, _("Time warp: %d us\n"), diff); exit(1); } @@ -173,7 +173,7 @@ test_timing(unsigned int duration) INSTR_TIME_SUBTRACT(end_time, start_time); printf(_("Per loop time including overhead: %0.2f ns\n"), - INSTR_TIME_GET_DOUBLE(end_time) * 1e9 / loop_count); + INSTR_TIME_GET_DOUBLE(end_time) * NS_PER_S / loop_count); return loop_count; } --Apple-Mail=_78E6C52E-0496-47D5-88A6-0C4E8D5F9BF9 Content-Disposition: attachment; filename=v5-0001-pg_test_timing-fix-unit-in-backward-clock-warning.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v5-0001-pg_test_timing-fix-unit-in-backward-clock-warning.patch" Content-Transfer-Encoding: quoted-printable =46rom=20ee388e247cc7d2473b12ca370b06cc9bbf0037fd=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= v5=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:=20Lukas=20Fittl=20=0AReviewed-by:=20Fujii=20= Masao=20=0ADiscussion:=20= https://postgr.es/m/F780CEEB-A237-4302-9F55-60E9D8B6533D@gmail.com=0A---=0A= =20src/bin/pg_test_timing/pg_test_timing.c=20|=204=20++--=0A=201=20file=20= changed,=202=20insertions(+),=202=20deletions(-)=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= 2afb0e6a410..5eb20e091b1=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-281,7=20+281,7=20@@=20= test_timing(unsigned=20int=20duration,=20TimingClockSourceType=20source,=20= bool=20fast_timin=0A=20=09=09if=20(unlikely(diff=20<=200))=0A=20=09=09{=0A= =20=09=09=09fprintf(stderr,=20_("Detected=20clock=20going=20backwards=20= in=20time.\n"));=0A-=09=09=09fprintf(stderr,=20_("Time=20warp:=20%d=20= ms\n"),=20diff);=0A+=09=09=09fprintf(stderr,=20_("Time=20warp:=20%d=20= ns\n"),=20diff);=0A=20=09=09=09exit(1);=0A=20=09=09}=0A=20=0A@@=20-316,7=20= +316,7=20@@=20test_timing(unsigned=20int=20duration,=20= TimingClockSourceType=20source,=20bool=20fast_timin=0A=20=09= INSTR_TIME_SUBTRACT(end_time,=20start_time);=0A=20=0A=20=09= printf(_("Average=20loop=20time=20including=20overhead:=20%0.2f=20= ns\n"),=0A-=09=09=20=20=20INSTR_TIME_GET_DOUBLE(end_time)=20*=201e9=20/=20= loop_count);=0A+=09=09=20=20=20INSTR_TIME_GET_DOUBLE(end_time)=20*=20= NS_PER_S=20/=20loop_count);=0A=20=0A=20=09return=20loop_count;=0A=20}=0A= --=20=0A2.50.1=20(Apple=20Git-155)=0A=0A= --Apple-Mail=_78E6C52E-0496-47D5-88A6-0C4E8D5F9BF9 Content-Disposition: attachment; filename=v5-0002-pg_test_timing-use-int64-for-largest-observed-tim.patch Content-Type: application/octet-stream; x-unix-mode=0644; name="v5-0002-pg_test_timing-use-int64-for-largest-observed-tim.patch" Content-Transfer-Encoding: quoted-printable =46rom=203eea80de37049bd453cf5724951c18505d557a99=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= v5=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:=20Lukas=20Fittl=20=0AReviewed-by:=20Fujii=20= Masao=20=0ADiscussion:=20= https://postgr.es/m/F780CEEB-A237-4302-9F55-60E9D8B6533D@gmail.com=0A---=0A= =20src/bin/pg_test_timing/pg_test_timing.c=20|=2028=20= ++++++++++++++-----------=0A=201=20file=20changed,=2016=20insertions(+),=20= 12=20deletions(-)=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= 5eb20e091b1..340b529e972=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-18,14=20+18,14=20@@=20= static=20unsigned=20int=20test_duration=20=3D=203;=0A=20static=20double=20= max_rprct=20=3D=2099.99;=0A=20=0A=20/*=20record=20duration=20in=20powers=20= of=202=20nanoseconds=20*/=0A-static=20long=20long=20int=20histogram[32];=0A= +static=20long=20long=20int=20histogram[64];=0A=20=0A=20/*=20record=20= counts=20of=20first=2010K=20durations=20directly=20*/=0A=20#define=20= NUM_DIRECT=2010000=0A=20static=20long=20long=20int=20= direct_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-262,8=20+262,8=20@@=20= test_timing(unsigned=20int=20duration,=20TimingClockSourceType=20source,=20= bool=20fast_timin=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-281,13=20+281,17=20@@=20= test_timing(unsigned=20int=20duration,=20TimingClockSourceType=20source,=20= bool=20fast_timin=0A=20=09=09if=20(unlikely(diff=20<=200))=0A=20=09=09{=0A= =20=09=09=09fprintf(stderr,=20_("Detected=20clock=20going=20backwards=20= in=20time.\n"));=0A-=09=09=09fprintf(stderr,=20_("Time=20warp:=20%d=20= ns\n"),=20diff);=0A+=09=09=09fprintf(stderr,=20_("Time=20warp:=20"=20= INT64_FORMAT=20"=20ns\n"),=20diff);=0A=20=09=09=09exit(1);=0A=20=09=09}=0A= =20=0A=20=09=09/*=20What=20is=20the=20highest=20bit=20in=20the=20time=20= diff?=20*/=0A=20=09=09if=20(diff=20>=200)=0A-=09=09=09bits=20=3D=20= pg_leftmost_one_pos32(diff)=20+=201;=0A+=09=09{=0A+=09=09=09bits=20=3D=20= pg_leftmost_one_pos64(diff)=20+=201;=0A+=09=09=09/*=20histogram=20should=20= be=20define=20large=20enough=20*/=0A+=09=09=09Assert(bits=20<=20= lengthof(histogram));=0A+=09=09}=0A=20=09=09else=0A=20=09=09=09bits=20=3D=20= 0;=0A=20=0A@@=20-324,7=20+328,7=20@@=20test_timing(unsigned=20int=20= duration,=20TimingClockSourceType=20source,=20bool=20fast_timin=0A=20= static=20void=0A=20output(uint64=20loop_count)=0A=20{=0A-=09int=09=09=09= max_bit=20=3D=2031;=0A+=09int=09=09=09max_bit=20=3D=20= lengthof(histogram)=20-=201;=0A=20=09const=20char=20*header1=20=3D=20= _("<=3D=20ns");=0A=20=09const=20char=20*header1b=20=3D=20_("ns");=0A=20=09= const=20char=20*header2=20=3D=20/*=20xgettext:no-c-format=20*/=20_("%=20= of=20total");=0A@@=20-342,7=20+346,7=20@@=20output(uint64=20loop_count)=0A= =20=09=09max_bit--;=0A=20=0A=20=09/*=20set=20minimum=20column=20widths=20= */=0A-=09len1=20=3D=20Max(8,=20len1);=0A+=09len1=20=3D=20Max(19,=20= len1);=0A=20=09len2=20=3D=20Max(10,=20len2);=0A=20=09len3=20=3D=20= Max(10,=20len3);=0A=20=09len4=20=3D=20Max(10,=20len4);=0A@@=20-360,8=20= +364,8=20@@=20output(uint64=20loop_count)=0A=20=09=09double=09=09prct=20= =3D=20(double)=20histogram[i]=20*=20100=20/=20loop_count;=0A=20=0A=20=09=09= rprct=20+=3D=20prct;=0A-=09=09printf("%*ld=20=20=20%*.4f=20%*.4f=20= %*lld\n",=0A-=09=09=09=20=20=20len1,=20(1L=20<<=20i)=20-=201,=0A+=09=09= printf("%*llu=20=20=20%*.4f=20%*.4f=20%*lld\n",=0A+=09=09=09=20=20=20= len1,=20(1ULL=20<<=20i)=20-=201,=0A=20=09=09=09=20=20=20len2,=20prct,=0A=20= =09=09=09=20=20=20len3,=20rprct,=0A=20=09=09=09=20=20=20len4,=20= histogram[i]);=0A@@=20-409,8=20+413,8=20@@=20output(uint64=20loop_count)=0A= =20=09=09double=09=09prct=20=3D=20(double)=20largest_diff_count=20*=20= 100=20/=20loop_count;=0A=20=0A=20=09=09printf("...\n");=0A-=09=09= printf("%*d=20=20=20%*.4f=20%*.4f=20%*lld\n",=0A-=09=09=09=20=20=20len1,=20= largest_diff,=0A+=09=09printf("%*lld=20=20=20%*.4f=20%*.4f=20%*lld\n",=0A= +=09=09=09=20=20=20len1,=20(long=20long)=20largest_diff,=0A=20=09=09=09=20= =20=20len2,=20prct,=0A=20=09=09=09=20=20=20len3,=20100.0,=0A=20=09=09=09=20= =20=20len4,=20largest_diff_count);=0A--=20=0A2.50.1=20(Apple=20Git-155)=0A= =0A= --Apple-Mail=_78E6C52E-0496-47D5-88A6-0C4E8D5F9BF9--