Re: Reduce timing overhead of EXPLAIN ANALYZE using rdtsc?
Andres Freund <andres@anarazel.de>
Hi,
Random things I noticed while looking through v19:
- src/common/instr_time.c has the wrong IDENTIFICATION
- instr_time.c should do
#ifndef FRONTEND
#include "postgres.h"
#else
#include "postgres_fe.h"
#endif
instead of always including postgres.h
- It's not PG style to put #includes in the middle of a file as done in
instrument.c
- tsc_use_by_default() may be documenting things that aren't the case anymore
- It may be paranoia, but it seems like tsc_calibrate() should perhaps save
the old clock source and restore it at the end?
- A brief comment in the source (rather than just the thread), why
TSC_CALIBRATION_SKIPS exists would be nice
- pg_initialize_timing() references an allow_tsc_calibration argument that
doesn't exist anymore
- Wonder if it would be clearer if pg_initialize_timing() callled
set_ticks_per_ns_system()?
- Should pg_initialize_timing() allow repeated initialization? Seems like that
would normally be a bug?
- It's nice that pg_test_timing shows the frequency. I was thinking it were
able to show the result of the calibration, even if we were able to
determine the frequency without calibration. That should make it easier to
figure out whether the calibration works well.
- Wonder if some of the code would look a bit cleaner if timing_tsc_enabled,
timing_tsc_frequency_khz were defined regardless of PG_INSTR_TSC_CLOCK.
- is it ok that we are doing pg_cpuid_subleaf() without checking the result?
It's not clear to me if a failed __get_cpuid_count() would clear out the old
reg or leave it in place.
- I don't think the elog() in pg_initialize_timing_tsc() works in any common
scenario, as log_min_messages hasn't been initialized yet, so that message
won't ever be emitted.
If it used a different log level, it'd be emitted without knowing the
log_line_prefix etc, because that hasn't yet been initialized.
- How much do we care about weird results when dynamically changing
timing_clocksource?
postgres[182055][1]=# EXPLAIN ANALYZE SELECT set_config('timing_clock_source', 'tsc', true), pg_sleep(1), set_config('timing_clock_source', 'system', true), pg_sleep(1);
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ QUERY PLAN │
├────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ Result (cost=0.00..0.01 rows=1 width=72) (actual time=-6540570569.396..-6540570569.395 rows=1.00 loops=1) │
│ Planning Time: 0.184 ms │
│ Execution Time: -6540570569.355 ms │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
(3 rows)
Time: 2002.350 ms (00:02.002)
- SGML:
- "modern CPUs" seems a bit pejorative, at least if we don't merge the
aarch64 stuff.
- 'tsc' describes just x86-64, even if there is a patch to support aarch64.
Perhaps it'd be enough to sprinkle a few "E.g. on x86-64, ..." around.
- I wonder if it'd be useful to have a INSTR_TIME_SET_CURRENT_SYSTEM() that'd
always use the "system" method, but convert it to to ticks if appropriate.
E.g. test_tsc_timing() could measure the elapsed time with system and
display the difference in how long the test_timing() takes between tsc based
source and system time.
This might be more of a thing for later.
Think we're getting there...
Greetings,
Andres
Commits
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
pg_test_timing: Show additional TSC clock source debug info
- 5ba34f6dc838 19 (unreleased) landed
-
instrumentation: Avoid CPUID 0x15/0x16 for Hypervisor TSC frequency
- 7fc36c5db550 19 (unreleased) landed
-
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
-
Check for __cpuidex and __get_cpuid_count separately
- effaa464afd3 19 (unreleased) landed
-
pg_test_timing: Reduce per-loop overhead
- 82c0cb4e672d 19 (unreleased) landed
-
Refactor handling of x86 CPUID instructions
- be6a7494d2e3 19 (unreleased) landed
-
instrumentation: Drop INSTR_TIME_SET_CURRENT_LAZY macro
- 9d6294c09ed0 19 (unreleased) landed
-
Rename pg_crc32c_sse42_choose.c for general purpose
- b9278871f991 19 (unreleased) cited
-
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