Skip to content

Commit b4b9156

Browse files
Rafael Antognollilenb
authored andcommitted
tools/power turbostat: Add a new GFXAMHz column that exposes gt_act_freq_mhz.
The column already present called GFXMHz reads from gt_cur_freq_mhz, which represents the GT frequency that was requested, but power management might not be able to do that. So the new column will display what the actual frequency GT is running at. Signed-off-by: Rafael Antognolli <rafael.antognolli@intel.com> Signed-off-by: Len Brown <len.brown@intel.com>
1 parent 0936cdf commit b4b9156

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

tools/power/x86/turbostat/turbostat.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ unsigned long long gfx_cur_rc6_ms;
7979
unsigned long long cpuidle_cur_cpu_lpi_us;
8080
unsigned long long cpuidle_cur_sys_lpi_us;
8181
unsigned int gfx_cur_mhz;
82+
unsigned int gfx_act_mhz;
8283
unsigned int tcc_activation_temp;
8384
unsigned int tcc_activation_temp_override;
8485
double rapl_power_units, rapl_time_units;
@@ -210,6 +211,7 @@ struct pkg_data {
210211
unsigned long long pkg_both_core_gfxe_c0;
211212
long long gfx_rc6_ms;
212213
unsigned int gfx_mhz;
214+
unsigned int gfx_act_mhz;
213215
unsigned int package_id;
214216
unsigned long long energy_pkg; /* MSR_PKG_ENERGY_STATUS */
215217
unsigned long long energy_dram; /* MSR_DRAM_ENERGY_STATUS */
@@ -558,6 +560,7 @@ struct msr_counter bic[] = {
558560
{ 0x0, "APIC" },
559561
{ 0x0, "X2APIC" },
560562
{ 0x0, "Die" },
563+
{ 0x0, "GFXAMHz" },
561564
};
562565

563566
#define MAX_BIC (sizeof(bic) / sizeof(struct msr_counter))
@@ -612,6 +615,7 @@ struct msr_counter bic[] = {
612615
#define BIC_APIC (1ULL << 48)
613616
#define BIC_X2APIC (1ULL << 49)
614617
#define BIC_Die (1ULL << 50)
618+
#define BIC_GFXACTMHz (1ULL << 51)
615619

616620
#define BIC_DISABLED_BY_DEFAULT (BIC_USEC | BIC_TOD | BIC_APIC | BIC_X2APIC)
617621

@@ -831,6 +835,9 @@ void print_header(char *delim)
831835
if (DO_BIC(BIC_GFXMHz))
832836
outp += sprintf(outp, "%sGFXMHz", (printed++ ? delim : ""));
833837

838+
if (DO_BIC(BIC_GFXACTMHz))
839+
outp += sprintf(outp, "%sGFXAMHz", (printed++ ? delim : ""));
840+
834841
if (DO_BIC(BIC_Totl_c0))
835842
outp += sprintf(outp, "%sTotl%%C0", (printed++ ? delim : ""));
836843
if (DO_BIC(BIC_Any_c0))
@@ -1198,6 +1205,10 @@ int format_counters(struct thread_data *t, struct core_data *c,
11981205
if (DO_BIC(BIC_GFXMHz))
11991206
outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_mhz);
12001207

1208+
/* GFXACTMHz */
1209+
if (DO_BIC(BIC_GFXACTMHz))
1210+
outp += sprintf(outp, "%s%d", (printed++ ? delim : ""), p->gfx_act_mhz);
1211+
12011212
/* Totl%C0, Any%C0 GFX%C0 CPUGFX% */
12021213
if (DO_BIC(BIC_Totl_c0))
12031214
outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), 100.0 * p->pkg_wtd_core_c0/tsc);
@@ -1349,6 +1360,7 @@ delta_package(struct pkg_data *new, struct pkg_data *old)
13491360
old->gfx_rc6_ms = new->gfx_rc6_ms - old->gfx_rc6_ms;
13501361

13511362
old->gfx_mhz = new->gfx_mhz;
1363+
old->gfx_act_mhz = new->gfx_act_mhz;
13521364

13531365
old->energy_pkg = new->energy_pkg - old->energy_pkg;
13541366
old->energy_cores = new->energy_cores - old->energy_cores;
@@ -1565,6 +1577,7 @@ void clear_counters(struct thread_data *t, struct core_data *c, struct pkg_data
15651577

15661578
p->gfx_rc6_ms = 0;
15671579
p->gfx_mhz = 0;
1580+
p->gfx_act_mhz = 0;
15681581
for (i = 0, mp = sys.tp; mp; i++, mp = mp->next)
15691582
t->counter[i] = 0;
15701583

@@ -1660,6 +1673,7 @@ int sum_counters(struct thread_data *t, struct core_data *c,
16601673

16611674
average.packages.gfx_rc6_ms = p->gfx_rc6_ms;
16621675
average.packages.gfx_mhz = p->gfx_mhz;
1676+
average.packages.gfx_act_mhz = p->gfx_act_mhz;
16631677

16641678
average.packages.pkg_temp_c = MAX(average.packages.pkg_temp_c, p->pkg_temp_c);
16651679

@@ -2108,6 +2122,9 @@ int get_counters(struct thread_data *t, struct core_data *c, struct pkg_data *p)
21082122
if (DO_BIC(BIC_GFXMHz))
21092123
p->gfx_mhz = gfx_cur_mhz;
21102124

2125+
if (DO_BIC(BIC_GFXACTMHz))
2126+
p->gfx_act_mhz = gfx_act_mhz;
2127+
21112128
for (i = 0, mp = sys.pp; mp; i++, mp = mp->next) {
21122129
if (get_mp(cpu, mp, &p->counter[i]))
21132130
return -10;
@@ -3018,6 +3035,33 @@ int snapshot_gfx_mhz(void)
30183035
return 0;
30193036
}
30203037

3038+
/*
3039+
* snapshot_gfx_cur_mhz()
3040+
*
3041+
* record snapshot of
3042+
* /sys/class/graphics/fb0/device/drm/card0/gt_act_freq_mhz
3043+
*
3044+
* return 1 if config change requires a restart, else return 0
3045+
*/
3046+
int snapshot_gfx_act_mhz(void)
3047+
{
3048+
static FILE *fp;
3049+
int retval;
3050+
3051+
if (fp == NULL)
3052+
fp = fopen_or_die("/sys/class/graphics/fb0/device/drm/card0/gt_act_freq_mhz", "r");
3053+
else {
3054+
rewind(fp);
3055+
fflush(fp);
3056+
}
3057+
3058+
retval = fscanf(fp, "%d", &gfx_act_mhz);
3059+
if (retval != 1)
3060+
err(1, "GFX ACT MHz");
3061+
3062+
return 0;
3063+
}
3064+
30213065
/*
30223066
* snapshot_cpu_lpi()
30233067
*
@@ -3083,6 +3127,9 @@ int snapshot_proc_sysfs_files(void)
30833127
if (DO_BIC(BIC_GFXMHz))
30843128
snapshot_gfx_mhz();
30853129

3130+
if (DO_BIC(BIC_GFXACTMHz))
3131+
snapshot_gfx_act_mhz();
3132+
30863133
if (DO_BIC(BIC_CPU_LPI))
30873134
snapshot_cpu_lpi_us();
30883135

@@ -5236,6 +5283,9 @@ void process_cpuid()
52365283
if (!access("/sys/class/graphics/fb0/device/drm/card0/gt_cur_freq_mhz", R_OK))
52375284
BIC_PRESENT(BIC_GFXMHz);
52385285

5286+
if (!access("/sys/class/graphics/fb0/device/drm/card0/gt_act_freq_mhz", R_OK))
5287+
BIC_PRESENT(BIC_GFXACTMHz);
5288+
52395289
if (!access("/sys/devices/system/cpu/cpuidle/low_power_idle_cpu_residency_us", R_OK))
52405290
BIC_PRESENT(BIC_CPU_LPI);
52415291
else

0 commit comments

Comments
 (0)