Re: Reduce timing overhead of EXPLAIN ANALYZE using rdtsc?
vignesh C <vignesh21@gmail.com>
From: vignesh C <vignesh21@gmail.com>
To: David Geier <geidav.pg@gmail.com>
Cc: Lukas Fittl <lukas@fittl.com>, Michael Paquier <michael@paquier.xyz>, Ibrar Ahmed <ibrar.ahmad@gmail.com>, Maciek Sakrejda <m.sakrejda@gmail.com>, Andres Freund <andres@anarazel.de>,
pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2023-01-04T10:15:05Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
pg_test_timing: Also test RDTSC[P] timing, report time source, TSC frequency
- 16fca4825483 19 (unreleased) landed
-
Allow retrieving x86 TSC frequency/flags from CPUID
- bcb2cf41f964 19 (unreleased) landed
-
instrumentation: Standardize ticks to nanosecond conversion method
- 0022622c93d9 19 (unreleased) landed
-
instrumentation: Use Time-Stamp Counter on x86-64 to lower overhead
- 294520c44487 19 (unreleased) landed
-
Zero initialize uses of instr_time about to trigger compiler warnings
- 25b2aba0c3a5 16.0 landed
-
instr_time: Represent time as an int64 on all platforms
- 03023a2664f8 16.0 landed
-
Add 250c8ee07ed to git-blame-ignore-revs
- ff23b592ad66 16.0 cited
On Tue, 3 Jan 2023 at 14:08, David Geier <geidav.pg@gmail.com> wrote: > > Hi Lukas, > > On 1/2/23 20:50, Lukas Fittl wrote: > > Thanks for continuing to work on this patch, and my apologies for > > silence on the patch. > > It would be great if you could review it. > Please also share your thoughts around exposing the used clock source as > GUC and renaming INSTR_TIME_GET_DOUBLE() to _SECS(). > > I rebased again on master because of [1]. Patches attached. > > > > > Its been hard to make time, and especially so because I typically > > develop on an ARM-based macOS system where I can't test this directly > > - hence my tests with virtualized EC2 instances, where I ran into the > > timing oddities. > That's good and bad. Bad to do the development and good to test the > implementation on more virtualized setups; given that I also encountered > "interesting" behavior on VMWare (see my previous mails). > > > > On Mon, Jan 2, 2023 at 5:28 AM David Geier <geidav.pg@gmail.com> wrote: > > > > The INSTR_TIME_GET_MICROSEC() returns a uint64 while the other > > variants > > return double. This seems error prone. What about renaming the > > function > > or also have the function return a double and cast where necessary at > > the call site? > > > > > > Minor note, but in my understanding using a uint64 (where we can) is > > faster for any simple arithmetic we do with the values. > > That's true. So the argument could be that for seconds and milliseconds > we want the extra precision while microseconds are precise enough. > Still, we could also make the seconds and milliseconds conversion code > integer only and e.g. return two integers with the value before and > after the comma. FWICS, the functions are nowhere used in performance > critical code, so it doesn't really make a difference performance-wise. > > > > > +1, and feel free to carry this patch forward - I'll try to make an > > effort to review my earlier testing issues again, as well as your > > later improvements to the patch. > Moved to the current commit fest. Will you become reviewer? > > > > Also, FYI, I just posted an alternate idea for speeding up EXPLAIN > > ANALYZE with timing over in [0], using a sampling-based approach to > > reduce the timing overhead. > > Interesting idea. I'll reply with some thoughts on the corresponding thread. > > [1] > https://www.postgresql.org/message-id/flat/CALDaNm3kRBGPhndujr9JcjjbDCG3anhj0vW8b9YtbXrBDMSvvw%40mail.gmail.com CFBot shows some compilation errors as in [1], please post an updated version for the same: 09:08:12.525] /usr/bin/ld: src/bin/pg_test_timing/pg_test_timing.p/pg_test_timing.c.o: warning: relocation against `cycles_to_sec' in read-only section `.text' [09:08:12.525] /usr/bin/ld: src/bin/pg_test_timing/pg_test_timing.p/pg_test_timing.c.o: in function `pg_clock_gettime_ref_cycles': [09:08:12.525] /tmp/cirrus-ci-build/build/../src/include/portability/instr_time.h:119: undefined reference to `use_rdtsc' [09:08:12.525] /usr/bin/ld: src/bin/pg_test_timing/pg_test_timing.p/pg_test_timing.c.o: in function `test_timing': [09:08:12.525] /tmp/cirrus-ci-build/build/../src/bin/pg_test_timing/pg_test_timing.c:135: undefined reference to `pg_clock_gettime_initialize_rdtsc' [09:08:12.525] /usr/bin/ld: /tmp/cirrus-ci-build/build/../src/bin/pg_test_timing/pg_test_timing.c:137: undefined reference to `cycles_to_us' [09:08:12.525] /usr/bin/ld: /tmp/cirrus-ci-build/build/../src/bin/pg_test_timing/pg_test_timing.c:146: undefined reference to `cycles_to_us' [09:08:12.525] /usr/bin/ld: /tmp/cirrus-ci-build/build/../src/bin/pg_test_timing/pg_test_timing.c:169: undefined reference to `cycles_to_us' [09:08:12.525] /usr/bin/ld: /tmp/cirrus-ci-build/build/../src/bin/pg_test_timing/pg_test_timing.c:176: undefined reference to `cycles_to_sec' [09:08:12.525] /usr/bin/ld: warning: creating DT_TEXTREL in a PIE [09:08:12.525] collect2: error: ld returned 1 exit status [1] - https://cirrus-ci.com/task/5375312565895168 Regards, Vignesh