pgsql: Allow retrieving x86 TSC frequency/flags from CPUID

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Allow retrieving x86 TSC frequency/flags from CPUID
Date: 2026-04-07 17:59:42
Message-ID: E1wAAiD-003Qwj-0r@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)fittl(dot)com>
Author: David Geier <geidav(dot)pg(at)gmail(dot)com>
Author: Andres Freund <andres(at)anarazel(dot)de>
Reviewed-by: Andres Freund <andres(at)anarazel(dot)de>
Reviewed-by: David Geier <geidav(dot)pg(at)gmail(dot)com>
Reviewed-by: John Naylor <john(dot)naylor(at)postgresql(dot)org>
Reviewed-by: Jakub Wartak <jakub(dot)wartak(at)enterprisedb(dot)com> (in an earlier version)
Discussion: https://www.postgresql.org/message-id/flat/20200612232810.f46nbqkdhbutzqdg%40alap3.anarazel.de

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/bcb2cf41f964e9ed4d27abe4dee8daa249f659bb

Modified Files
--------------
src/include/port/pg_cpu.h | 12 +++-
src/port/pg_cpu_x86.c | 138 ++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 145 insertions(+), 5 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2026-04-07 18:45:55 pgsql: Fix WITHOUT OVERLAPS' interaction with domains.
Previous Message Aleksander Alekseev 2026-04-07 15:24:28 Re: pgsql: Add CONCURRENTLY option to REPACK