Skip to content

Commit

Permalink
tools/power/turbostat: Abstract TSC tweak support
Browse files Browse the repository at this point in the history
On some models, the CPU base frequency is different from the TSC
frequency, and the aperf/mperf counters are running at CPU base
frequency instead of TSC frequency.

Abstract support for TSC tweak.

Given that tsc_tweak depends on base_hz, move the code to probe_bclk()
after base_hz is available.

Signed-off-by: Zhang Rui <[email protected]>
Reviewed-by: Len Brown <[email protected]>
  • Loading branch information
zhang-rui committed Sep 27, 2023
1 parent bf1ad57 commit 485a017
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions tools/power/x86/turbostat/turbostat.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ struct platform_features {
bool has_fixed_rapl_unit; /* Fixed Energy Unit used for DRAM RAPL Domain */
int rapl_quirk_tdp; /* Hardcoded TDP value when cannot be retrieved from hardware */
int tcc_offset_bits; /* TCC Offset bits in MSR_IA32_TEMPERATURE_TARGET */
bool enable_tsc_tweak; /* Use CPU Base freq instead of TSC freq for aperf/mperf counter */
};

struct platform_data {
Expand Down Expand Up @@ -546,6 +547,7 @@ static const struct platform_features skl_features = {
.trl_msrs = TRL_BASE,
.tcc_offset_bits = 6,
.rapl_msrs = RAPL_PKG_ALL | RAPL_CORE_ALL | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_GFX,
.enable_tsc_tweak = 1,
};

static const struct platform_features cnl_features = {
Expand All @@ -558,6 +560,7 @@ static const struct platform_features cnl_features = {
.trl_msrs = TRL_BASE,
.tcc_offset_bits = 6,
.rapl_msrs = RAPL_PKG_ALL | RAPL_CORE_ALL | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_GFX,
.enable_tsc_tweak = 1,
};

static const struct platform_features skx_features = {
Expand Down Expand Up @@ -660,6 +663,7 @@ static const struct platform_features tmt_features = {
.cst_limit = CST_LIMIT_GMT,
.trl_msrs = TRL_BASE,
.rapl_msrs = RAPL_PKG_ALL | RAPL_CORE_ALL | RAPL_DRAM | RAPL_DRAM_PERF_STATUS | RAPL_GFX,
.enable_tsc_tweak = 1,
};

static const struct platform_features tmtd_features = {
Expand Down Expand Up @@ -2934,11 +2938,6 @@ void probe_cst_limit(void)
pkg_cstate_limit = pkg_cstate_limits[msr & 0xF];
}

static void calculate_tsc_tweak()
{
tsc_tweak = base_hz / tsc_hz;
}

void prewake_cstate_probe(unsigned int family, unsigned int model);

static void dump_platform_info(void)
Expand Down Expand Up @@ -4198,6 +4197,9 @@ void probe_bclk(void)

base_hz = base_ratio * bclk * 1000000;
has_base_hz = 1;

if (platform->enable_tsc_tweak)
tsc_tweak = base_hz / tsc_hz;
}

/*
Expand Down Expand Up @@ -5836,9 +5838,6 @@ void process_cpuid()
if (!quiet)
dump_sysfs_pstate_config();

if (has_skl_msrs(family, model) || is_ehl(family, model))
calculate_tsc_tweak();

if (!access("/sys/class/drm/card0/power/rc6_residency_ms", R_OK))
BIC_PRESENT(BIC_GFX_rc6);

Expand Down

0 comments on commit 485a017

Please sign in to comment.