Skip to content

Commit fe26546

Browse files
Kenneth Fengalexdeucher
authored andcommitted
drm/amdgpu/pm: support gpu_metrics sysfs interface for smu v14.0.2/3
support gpu_metrics sysfs interface for smu v14.0.2/3 Signed-off-by: Kenneth Feng <[email protected]> Reviewed-by: Yang Wang <[email protected]> Signed-off-by: Alex Deucher <[email protected]> (cherry picked from commit 60c30ba)
1 parent d4ef5d2 commit fe26546

File tree

1 file changed

+84
-2
lines changed

1 file changed

+84
-2
lines changed

drivers/gpu/drm/amd/pm/swsmu/smu14/smu_v14_0_2_ppt.c

Lines changed: 84 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767
#define MP0_MP1_DATA_REGION_SIZE_COMBOPPTABLE 0x4000
6868
#define DEBUGSMC_MSG_Mode1Reset 2
69+
#define LINK_SPEED_MAX 3
6970

7071
static struct cmn2asic_msg_mapping smu_v14_0_2_message_map[SMU_MSG_MAX_COUNT] = {
7172
MSG_MAP(TestMessage, PPSMC_MSG_TestMessage, 1),
@@ -221,7 +222,6 @@ static struct cmn2asic_mapping smu_v14_0_2_workload_map[PP_SMC_POWER_PROFILE_COU
221222
WORKLOAD_MAP(PP_SMC_POWER_PROFILE_WINDOW3D, WORKLOAD_PPLIB_WINDOW_3D_BIT),
222223
};
223224

224-
#if 0
225225
static const uint8_t smu_v14_0_2_throttler_map[] = {
226226
[THROTTLER_PPT0_BIT] = (SMU_THROTTLER_PPT0_BIT),
227227
[THROTTLER_PPT1_BIT] = (SMU_THROTTLER_PPT1_BIT),
@@ -241,7 +241,6 @@ static const uint8_t smu_v14_0_2_throttler_map[] = {
241241
[THROTTLER_GFX_APCC_PLUS_BIT] = (SMU_THROTTLER_APCC_BIT),
242242
[THROTTLER_FIT_BIT] = (SMU_THROTTLER_FIT_BIT),
243243
};
244-
#endif
245244

246245
static int
247246
smu_v14_0_2_get_allowed_feature_mask(struct smu_context *smu,
@@ -1869,6 +1868,88 @@ static ssize_t smu_v14_0_2_get_ecc_info(struct smu_context *smu,
18691868
return ret;
18701869
}
18711870

1871+
static ssize_t smu_v14_0_2_get_gpu_metrics(struct smu_context *smu,
1872+
void **table)
1873+
{
1874+
struct smu_table_context *smu_table = &smu->smu_table;
1875+
struct gpu_metrics_v1_3 *gpu_metrics =
1876+
(struct gpu_metrics_v1_3 *)smu_table->gpu_metrics_table;
1877+
SmuMetricsExternal_t metrics_ext;
1878+
SmuMetrics_t *metrics = &metrics_ext.SmuMetrics;
1879+
int ret = 0;
1880+
1881+
ret = smu_cmn_get_metrics_table(smu,
1882+
&metrics_ext,
1883+
true);
1884+
if (ret)
1885+
return ret;
1886+
1887+
smu_cmn_init_soft_gpu_metrics(gpu_metrics, 1, 3);
1888+
1889+
gpu_metrics->temperature_edge = metrics->AvgTemperature[TEMP_EDGE];
1890+
gpu_metrics->temperature_hotspot = metrics->AvgTemperature[TEMP_HOTSPOT];
1891+
gpu_metrics->temperature_mem = metrics->AvgTemperature[TEMP_MEM];
1892+
gpu_metrics->temperature_vrgfx = metrics->AvgTemperature[TEMP_VR_GFX];
1893+
gpu_metrics->temperature_vrsoc = metrics->AvgTemperature[TEMP_VR_SOC];
1894+
gpu_metrics->temperature_vrmem = max(metrics->AvgTemperature[TEMP_VR_MEM0],
1895+
metrics->AvgTemperature[TEMP_VR_MEM1]);
1896+
1897+
gpu_metrics->average_gfx_activity = metrics->AverageGfxActivity;
1898+
gpu_metrics->average_umc_activity = metrics->AverageUclkActivity;
1899+
gpu_metrics->average_mm_activity = max(metrics->Vcn0ActivityPercentage,
1900+
metrics->Vcn1ActivityPercentage);
1901+
1902+
gpu_metrics->average_socket_power = metrics->AverageSocketPower;
1903+
gpu_metrics->energy_accumulator = metrics->EnergyAccumulator;
1904+
1905+
if (metrics->AverageGfxActivity <= SMU_14_0_2_BUSY_THRESHOLD)
1906+
gpu_metrics->average_gfxclk_frequency = metrics->AverageGfxclkFrequencyPostDs;
1907+
else
1908+
gpu_metrics->average_gfxclk_frequency = metrics->AverageGfxclkFrequencyPreDs;
1909+
1910+
if (metrics->AverageUclkActivity <= SMU_14_0_2_BUSY_THRESHOLD)
1911+
gpu_metrics->average_uclk_frequency = metrics->AverageMemclkFrequencyPostDs;
1912+
else
1913+
gpu_metrics->average_uclk_frequency = metrics->AverageMemclkFrequencyPreDs;
1914+
1915+
gpu_metrics->average_vclk0_frequency = metrics->AverageVclk0Frequency;
1916+
gpu_metrics->average_dclk0_frequency = metrics->AverageDclk0Frequency;
1917+
gpu_metrics->average_vclk1_frequency = metrics->AverageVclk1Frequency;
1918+
gpu_metrics->average_dclk1_frequency = metrics->AverageDclk1Frequency;
1919+
1920+
gpu_metrics->current_gfxclk = gpu_metrics->average_gfxclk_frequency;
1921+
gpu_metrics->current_socclk = metrics->CurrClock[PPCLK_SOCCLK];
1922+
gpu_metrics->current_uclk = metrics->CurrClock[PPCLK_UCLK];
1923+
gpu_metrics->current_vclk0 = metrics->CurrClock[PPCLK_VCLK_0];
1924+
gpu_metrics->current_dclk0 = metrics->CurrClock[PPCLK_DCLK_0];
1925+
gpu_metrics->current_vclk1 = metrics->CurrClock[PPCLK_VCLK_0];
1926+
gpu_metrics->current_dclk1 = metrics->CurrClock[PPCLK_DCLK_0];
1927+
1928+
gpu_metrics->throttle_status =
1929+
smu_v14_0_2_get_throttler_status(metrics);
1930+
gpu_metrics->indep_throttle_status =
1931+
smu_cmn_get_indep_throttler_status(gpu_metrics->throttle_status,
1932+
smu_v14_0_2_throttler_map);
1933+
1934+
gpu_metrics->current_fan_speed = metrics->AvgFanRpm;
1935+
1936+
gpu_metrics->pcie_link_width = metrics->PcieWidth;
1937+
if ((metrics->PcieRate - 1) > LINK_SPEED_MAX)
1938+
gpu_metrics->pcie_link_speed = pcie_gen_to_speed(1);
1939+
else
1940+
gpu_metrics->pcie_link_speed = pcie_gen_to_speed(metrics->PcieRate);
1941+
1942+
gpu_metrics->system_clock_counter = ktime_get_boottime_ns();
1943+
1944+
gpu_metrics->voltage_gfx = metrics->AvgVoltage[SVI_PLANE_VDD_GFX];
1945+
gpu_metrics->voltage_soc = metrics->AvgVoltage[SVI_PLANE_VDD_SOC];
1946+
gpu_metrics->voltage_mem = metrics->AvgVoltage[SVI_PLANE_VDDIO_MEM];
1947+
1948+
*table = (void *)gpu_metrics;
1949+
1950+
return sizeof(struct gpu_metrics_v1_3);
1951+
}
1952+
18721953
static const struct pptable_funcs smu_v14_0_2_ppt_funcs = {
18731954
.get_allowed_feature_mask = smu_v14_0_2_get_allowed_feature_mask,
18741955
.set_default_dpm_table = smu_v14_0_2_set_default_dpm_table,
@@ -1905,6 +1986,7 @@ static const struct pptable_funcs smu_v14_0_2_ppt_funcs = {
19051986
.enable_thermal_alert = smu_v14_0_enable_thermal_alert,
19061987
.disable_thermal_alert = smu_v14_0_disable_thermal_alert,
19071988
.notify_memory_pool_location = smu_v14_0_notify_memory_pool_location,
1989+
.get_gpu_metrics = smu_v14_0_2_get_gpu_metrics,
19081990
.set_soft_freq_limited_range = smu_v14_0_set_soft_freq_limited_range,
19091991
.init_pptable_microcode = smu_v14_0_init_pptable_microcode,
19101992
.populate_umd_state_clk = smu_v14_0_2_populate_umd_state_clk,

0 commit comments

Comments
 (0)