Skip to content

Commit 8cc438b

Browse files
Kenneth Fengalexdeucher
authored andcommitted
drm/amd/pm: correct the workload setting
Correct the workload setting in order not to mix the setting with the end user. Update the workload mask accordingly. v2: changes as below: 1. the end user can not erase the workload from driver except default workload. 2. always shows the real highest priority workoad to the end user. 3. the real workload mask is combined with driver workload mask and end user workload mask. v3: apply this to the other ASICs as well. v4: simplify the code v5: refine the code based on the review comments. Signed-off-by: Kenneth Feng <[email protected]> Acked-by: Alex Deucher <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent e5ad717 commit 8cc438b

File tree

12 files changed

+84
-36
lines changed

12 files changed

+84
-36
lines changed

drivers/gpu/drm/amd/pm/swsmu/amdgpu_smu.c

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,26 +1261,33 @@ static int smu_sw_init(struct amdgpu_ip_block *ip_block)
12611261
smu->watermarks_bitmap = 0;
12621262
smu->power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
12631263
smu->default_power_profile_mode = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
1264+
smu->user_dpm_profile.user_workload_mask = 0;
12641265

12651266
atomic_set(&smu->smu_power.power_gate.vcn_gated, 1);
12661267
atomic_set(&smu->smu_power.power_gate.jpeg_gated, 1);
12671268
atomic_set(&smu->smu_power.power_gate.vpe_gated, 1);
12681269
atomic_set(&smu->smu_power.power_gate.umsch_mm_gated, 1);
12691270

1270-
smu->workload_prority[PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT] = 0;
1271-
smu->workload_prority[PP_SMC_POWER_PROFILE_FULLSCREEN3D] = 1;
1272-
smu->workload_prority[PP_SMC_POWER_PROFILE_POWERSAVING] = 2;
1273-
smu->workload_prority[PP_SMC_POWER_PROFILE_VIDEO] = 3;
1274-
smu->workload_prority[PP_SMC_POWER_PROFILE_VR] = 4;
1275-
smu->workload_prority[PP_SMC_POWER_PROFILE_COMPUTE] = 5;
1276-
smu->workload_prority[PP_SMC_POWER_PROFILE_CUSTOM] = 6;
1271+
smu->workload_priority[PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT] = 0;
1272+
smu->workload_priority[PP_SMC_POWER_PROFILE_FULLSCREEN3D] = 1;
1273+
smu->workload_priority[PP_SMC_POWER_PROFILE_POWERSAVING] = 2;
1274+
smu->workload_priority[PP_SMC_POWER_PROFILE_VIDEO] = 3;
1275+
smu->workload_priority[PP_SMC_POWER_PROFILE_VR] = 4;
1276+
smu->workload_priority[PP_SMC_POWER_PROFILE_COMPUTE] = 5;
1277+
smu->workload_priority[PP_SMC_POWER_PROFILE_CUSTOM] = 6;
12771278

12781279
if (smu->is_apu ||
1279-
!smu_is_workload_profile_available(smu, PP_SMC_POWER_PROFILE_FULLSCREEN3D))
1280-
smu->workload_mask = 1 << smu->workload_prority[PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT];
1281-
else
1282-
smu->workload_mask = 1 << smu->workload_prority[PP_SMC_POWER_PROFILE_FULLSCREEN3D];
1280+
!smu_is_workload_profile_available(smu, PP_SMC_POWER_PROFILE_FULLSCREEN3D)) {
1281+
smu->driver_workload_mask =
1282+
1 << smu->workload_priority[PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT];
1283+
} else {
1284+
smu->driver_workload_mask =
1285+
1 << smu->workload_priority[PP_SMC_POWER_PROFILE_FULLSCREEN3D];
1286+
smu->default_power_profile_mode = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
1287+
}
12831288

1289+
smu->workload_mask = smu->driver_workload_mask |
1290+
smu->user_dpm_profile.user_workload_mask;
12841291
smu->workload_setting[0] = PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
12851292
smu->workload_setting[1] = PP_SMC_POWER_PROFILE_FULLSCREEN3D;
12861293
smu->workload_setting[2] = PP_SMC_POWER_PROFILE_POWERSAVING;
@@ -2355,17 +2362,20 @@ static int smu_switch_power_profile(void *handle,
23552362
return -EINVAL;
23562363

23572364
if (!en) {
2358-
smu->workload_mask &= ~(1 << smu->workload_prority[type]);
2365+
smu->driver_workload_mask &= ~(1 << smu->workload_priority[type]);
23592366
index = fls(smu->workload_mask);
23602367
index = index > 0 && index <= WORKLOAD_POLICY_MAX ? index - 1 : 0;
23612368
workload[0] = smu->workload_setting[index];
23622369
} else {
2363-
smu->workload_mask |= (1 << smu->workload_prority[type]);
2370+
smu->driver_workload_mask |= (1 << smu->workload_priority[type]);
23642371
index = fls(smu->workload_mask);
23652372
index = index <= WORKLOAD_POLICY_MAX ? index - 1 : 0;
23662373
workload[0] = smu->workload_setting[index];
23672374
}
23682375

2376+
smu->workload_mask = smu->driver_workload_mask |
2377+
smu->user_dpm_profile.user_workload_mask;
2378+
23692379
if (smu_dpm_ctx->dpm_level != AMD_DPM_FORCED_LEVEL_MANUAL &&
23702380
smu_dpm_ctx->dpm_level != AMD_DPM_FORCED_LEVEL_PERF_DETERMINISM)
23712381
smu_bump_power_profile_mode(smu, workload, 0);
@@ -3056,12 +3066,23 @@ static int smu_set_power_profile_mode(void *handle,
30563066
uint32_t param_size)
30573067
{
30583068
struct smu_context *smu = handle;
3069+
int ret;
30593070

30603071
if (!smu->pm_enabled || !smu->adev->pm.dpm_enabled ||
30613072
!smu->ppt_funcs->set_power_profile_mode)
30623073
return -EOPNOTSUPP;
30633074

3064-
return smu_bump_power_profile_mode(smu, param, param_size);
3075+
if (smu->user_dpm_profile.user_workload_mask &
3076+
(1 << smu->workload_priority[param[param_size]]))
3077+
return 0;
3078+
3079+
smu->user_dpm_profile.user_workload_mask =
3080+
(1 << smu->workload_priority[param[param_size]]);
3081+
smu->workload_mask = smu->user_dpm_profile.user_workload_mask |
3082+
smu->driver_workload_mask;
3083+
ret = smu_bump_power_profile_mode(smu, param, param_size);
3084+
3085+
return ret;
30653086
}
30663087

30673088
static int smu_get_fan_control_mode(void *handle, u32 *fan_mode)

drivers/gpu/drm/amd/pm/swsmu/inc/amdgpu_smu.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ struct smu_user_dpm_profile {
240240
/* user clock state information */
241241
uint32_t clk_mask[SMU_CLK_COUNT];
242242
uint32_t clk_dependency;
243+
uint32_t user_workload_mask;
243244
};
244245

245246
#define SMU_TABLE_INIT(tables, table_id, s, a, d) \
@@ -557,7 +558,8 @@ struct smu_context {
557558
bool disable_uclk_switch;
558559

559560
uint32_t workload_mask;
560-
uint32_t workload_prority[WORKLOAD_POLICY_MAX];
561+
uint32_t driver_workload_mask;
562+
uint32_t workload_priority[WORKLOAD_POLICY_MAX];
561563
uint32_t workload_setting[WORKLOAD_POLICY_MAX];
562564
uint32_t power_profile_mode;
563565
uint32_t default_power_profile_mode;

drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,6 @@ static int arcturus_set_power_profile_mode(struct smu_context *smu,
14551455
return -EINVAL;
14561456
}
14571457

1458-
14591458
if ((profile_mode == PP_SMC_POWER_PROFILE_CUSTOM) &&
14601459
(smu->smc_fw_version >= 0x360d00)) {
14611460
if (size != 10)
@@ -1523,14 +1522,14 @@ static int arcturus_set_power_profile_mode(struct smu_context *smu,
15231522

15241523
ret = smu_cmn_send_smc_msg_with_param(smu,
15251524
SMU_MSG_SetWorkloadMask,
1526-
1 << workload_type,
1525+
smu->workload_mask,
15271526
NULL);
15281527
if (ret) {
15291528
dev_err(smu->adev->dev, "Fail to set workload type %d\n", workload_type);
15301529
return ret;
15311530
}
15321531

1533-
smu->power_profile_mode = profile_mode;
1532+
smu_cmn_assign_power_profile(smu);
15341533

15351534
return 0;
15361535
}

drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2083,10 +2083,13 @@ static int navi10_set_power_profile_mode(struct smu_context *smu, long *input, u
20832083
smu->power_profile_mode);
20842084
if (workload_type < 0)
20852085
return -EINVAL;
2086+
20862087
ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetWorkloadMask,
2087-
1 << workload_type, NULL);
2088+
smu->workload_mask, NULL);
20882089
if (ret)
20892090
dev_err(smu->adev->dev, "[%s] Failed to set work load mask!", __func__);
2091+
else
2092+
smu_cmn_assign_power_profile(smu);
20902093

20912094
return ret;
20922095
}

drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1788,10 +1788,13 @@ static int sienna_cichlid_set_power_profile_mode(struct smu_context *smu, long *
17881788
smu->power_profile_mode);
17891789
if (workload_type < 0)
17901790
return -EINVAL;
1791+
17911792
ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetWorkloadMask,
1792-
1 << workload_type, NULL);
1793+
smu->workload_mask, NULL);
17931794
if (ret)
17941795
dev_err(smu->adev->dev, "[%s] Failed to set work load mask!", __func__);
1796+
else
1797+
smu_cmn_assign_power_profile(smu);
17951798

17961799
return ret;
17971800
}

drivers/gpu/drm/amd/pm/swsmu/smu11/vangogh_ppt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,15 +1081,15 @@ static int vangogh_set_power_profile_mode(struct smu_context *smu, long *input,
10811081
}
10821082

10831083
ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_ActiveProcessNotify,
1084-
1 << workload_type,
1084+
smu->workload_mask,
10851085
NULL);
10861086
if (ret) {
10871087
dev_err_once(smu->adev->dev, "Fail to set workload type %d\n",
10881088
workload_type);
10891089
return ret;
10901090
}
10911091

1092-
smu->power_profile_mode = profile_mode;
1092+
smu_cmn_assign_power_profile(smu);
10931093

10941094
return 0;
10951095
}

drivers/gpu/drm/amd/pm/swsmu/smu12/renoir_ppt.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,14 +892,14 @@ static int renoir_set_power_profile_mode(struct smu_context *smu, long *input, u
892892
}
893893

894894
ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_ActiveProcessNotify,
895-
1 << workload_type,
895+
smu->workload_mask,
896896
NULL);
897897
if (ret) {
898898
dev_err_once(smu->adev->dev, "Fail to set workload type %d\n", workload_type);
899899
return ret;
900900
}
901901

902-
smu->power_profile_mode = profile_mode;
902+
smu_cmn_assign_power_profile(smu);
903903

904904
return 0;
905905
}

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2473,7 +2473,7 @@ static int smu_v13_0_0_set_power_profile_mode(struct smu_context *smu,
24732473
DpmActivityMonitorCoeffInt_t *activity_monitor =
24742474
&(activity_monitor_external.DpmActivityMonitorCoeffInt);
24752475
int workload_type, ret = 0;
2476-
u32 workload_mask, selected_workload_mask;
2476+
u32 workload_mask;
24772477

24782478
smu->power_profile_mode = input[size];
24792479

@@ -2540,7 +2540,7 @@ static int smu_v13_0_0_set_power_profile_mode(struct smu_context *smu,
25402540
if (workload_type < 0)
25412541
return -EINVAL;
25422542

2543-
selected_workload_mask = workload_mask = 1 << workload_type;
2543+
workload_mask = 1 << workload_type;
25442544

25452545
/* Add optimizations for SMU13.0.0/10. Reuse the power saving profile */
25462546
if ((amdgpu_ip_version(smu->adev, MP1_HWIP, 0) == IP_VERSION(13, 0, 0) &&
@@ -2555,12 +2555,22 @@ static int smu_v13_0_0_set_power_profile_mode(struct smu_context *smu,
25552555
workload_mask |= 1 << workload_type;
25562556
}
25572557

2558+
smu->workload_mask |= workload_mask;
25582559
ret = smu_cmn_send_smc_msg_with_param(smu,
25592560
SMU_MSG_SetWorkloadMask,
2560-
workload_mask,
2561+
smu->workload_mask,
25612562
NULL);
2562-
if (!ret)
2563-
smu->workload_mask = selected_workload_mask;
2563+
if (!ret) {
2564+
smu_cmn_assign_power_profile(smu);
2565+
if (smu->power_profile_mode == PP_SMC_POWER_PROFILE_POWERSAVING) {
2566+
workload_type = smu_cmn_to_asic_specific_index(smu,
2567+
CMN2ASIC_MAPPING_WORKLOAD,
2568+
PP_SMC_POWER_PROFILE_FULLSCREEN3D);
2569+
smu->power_profile_mode = smu->workload_mask & (1 << workload_type)
2570+
? PP_SMC_POWER_PROFILE_FULLSCREEN3D
2571+
: PP_SMC_POWER_PROFILE_BOOTUP_DEFAULT;
2572+
}
2573+
}
25642574

25652575
return ret;
25662576
}

drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,13 +2487,14 @@ static int smu_v13_0_7_set_power_profile_mode(struct smu_context *smu, long *inp
24872487
smu->power_profile_mode);
24882488
if (workload_type < 0)
24892489
return -EINVAL;
2490+
24902491
ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetWorkloadMask,
2491-
1 << workload_type, NULL);
2492+
smu->workload_mask, NULL);
24922493

24932494
if (ret)
24942495
dev_err(smu->adev->dev, "[%s] Failed to set work load mask!", __func__);
24952496
else
2496-
smu->workload_mask = (1 << workload_type);
2497+
smu_cmn_assign_power_profile(smu);
24972498

24982499
return ret;
24992500
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,12 +1795,11 @@ static int smu_v14_0_2_set_power_profile_mode(struct smu_context *smu,
17951795
if (workload_type < 0)
17961796
return -EINVAL;
17971797

1798-
ret = smu_cmn_send_smc_msg_with_param(smu,
1799-
SMU_MSG_SetWorkloadMask,
1800-
1 << workload_type,
1801-
NULL);
1798+
ret = smu_cmn_send_smc_msg_with_param(smu, SMU_MSG_SetWorkloadMask,
1799+
smu->workload_mask, NULL);
1800+
18021801
if (!ret)
1803-
smu->workload_mask = 1 << workload_type;
1802+
smu_cmn_assign_power_profile(smu);
18041803

18051804
return ret;
18061805
}

0 commit comments

Comments
 (0)