1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-28 02:33:10 +03:00

Allow retrieving x86 TSC frequency/flags from CPUID

This adds additional x86 specific CPUID checks for flags needed for
determining whether the Time-Stamp Counter (TSC) is usable on a given system,
as well as a helper function to retrieve the TSC frequency from CPUID.

This is intended for a future patch that will utilize the TSC to lower the
overhead of timing instrumentation.

In passing, always make pg_cpuid_subleaf reset the variables used for its
result, to avoid accidentally using stale results if __get_cpuid_count errors
out and the caller doesn't check for it.

Author: Lukas Fittl <lukas@fittl.com>
Author: David Geier <geidav.pg@gmail.com>
Author: Andres Freund <andres@anarazel.de>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: David Geier <geidav.pg@gmail.com>
Reviewed-by: John Naylor <john.naylor@postgresql.org>
Reviewed-by: Jakub Wartak <jakub.wartak@enterprisedb.com> (in an earlier version)
Discussion: https://www.postgresql.org/message-id/flat/20200612232810.f46nbqkdhbutzqdg%40alap3.anarazel.de
This commit is contained in:
Andres Freund
2026-04-07 12:48:07 -04:00
parent 0022622c93
commit bcb2cf41f9
2 changed files with 145 additions and 5 deletions

View File

@@ -32,8 +32,16 @@ typedef enum X86FeatureId
PG_AVX512_VL,
PG_AVX512_VPCLMULQDQ,
PG_AVX512_VPOPCNTDQ,
/* identification */
PG_HYPERVISOR,
/* Time-Stamp Counter (TSC) flags */
PG_RDTSCP,
PG_TSC_INVARIANT,
PG_TSC_ADJUST,
} X86FeatureId;
#define X86FeaturesSize (PG_AVX512_VPOPCNTDQ + 1)
#define X86FeaturesSize (PG_TSC_ADJUST + 1)
extern PGDLLIMPORT bool X86Features[];
@@ -48,6 +56,8 @@ x86_feature_available(X86FeatureId feature)
return X86Features[feature];
}
extern uint32 x86_tsc_frequency_khz(void);
#endif /* defined(USE_SSE2) || defined(__i386__) */
#endif /* PG_CPU_H */