Do not bother resetting values to old ones if changes to GPU parameters report failure, instead returning a failure code only if the return value from get() differs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
diff --git a/adl.c b/adl.c
index e3f6187..f51faea 100644
--- a/adl.c
+++ b/adl.c
@@ -605,19 +605,10 @@ static int set_engineclock(int gpu, int iEngineClock)
lpOdPerformanceLevels->aLevels[i].iEngineClock = iEngineClock;
}
lpOdPerformanceLevels->aLevels[lev].iEngineClock = iEngineClock;
- if (ADL_Overdrive5_ODPerformanceLevels_Set(ga->iAdapterIndex, lpOdPerformanceLevels) != ADL_OK)
- goto out;
+ ADL_Overdrive5_ODPerformanceLevels_Set(ga->iAdapterIndex, lpOdPerformanceLevels);
ADL_Overdrive5_ODPerformanceLevels_Get(ga->iAdapterIndex, 0, lpOdPerformanceLevels);
- /* Reset to old value if it fails! */
- if (lpOdPerformanceLevels->aLevels[lev].iEngineClock != iEngineClock) {
- /* Set all the parameters in case they're linked somehow */
- lpOdPerformanceLevels->aLevels[lev].iEngineClock = ga->iEngineClock;
- lpOdPerformanceLevels->aLevels[lev].iMemoryClock = ga->iMemoryClock;
- lpOdPerformanceLevels->aLevels[lev].iVddc = ga->iVddc;
- ADL_Overdrive5_ODPerformanceLevels_Set(ga->iAdapterIndex, lpOdPerformanceLevels);
- ADL_Overdrive5_ODPerformanceLevels_Get(ga->iAdapterIndex, 0, lpOdPerformanceLevels);
- goto out;
- }
+ if (lpOdPerformanceLevels->aLevels[lev].iEngineClock == iEngineClock)
+ ret = 0;
ga->iEngineClock = lpOdPerformanceLevels->aLevels[lev].iEngineClock;
if (ga->iEngineClock > ga->maxspeed)
ga->maxspeed = ga->iEngineClock;
@@ -626,7 +617,6 @@ static int set_engineclock(int gpu, int iEngineClock)
ga->iMemoryClock = lpOdPerformanceLevels->aLevels[lev].iMemoryClock;
ga->iVddc = lpOdPerformanceLevels->aLevels[lev].iVddc;
ga->managed = true;
- ret = 0;
out:
unlock_adl();
return ret;
@@ -671,24 +661,14 @@ static int set_memoryclock(int gpu, int iMemoryClock)
if (lpOdPerformanceLevels->aLevels[i].iMemoryClock > iMemoryClock)
lpOdPerformanceLevels->aLevels[i].iMemoryClock = iMemoryClock;
}
- if (ADL_Overdrive5_ODPerformanceLevels_Set(ga->iAdapterIndex, lpOdPerformanceLevels) != ADL_OK)
- goto out;
+ ADL_Overdrive5_ODPerformanceLevels_Set(ga->iAdapterIndex, lpOdPerformanceLevels);
ADL_Overdrive5_ODPerformanceLevels_Get(ga->iAdapterIndex, 0, lpOdPerformanceLevels);
- /* Reset to old value if it fails! */
- if (lpOdPerformanceLevels->aLevels[lev].iMemoryClock != iMemoryClock) {
- /* Set all the parameters in case they're linked somehow */
- lpOdPerformanceLevels->aLevels[lev].iMemoryClock = ga->iEngineClock;
- lpOdPerformanceLevels->aLevels[lev].iMemoryClock = ga->iMemoryClock;
- lpOdPerformanceLevels->aLevels[lev].iVddc = ga->iVddc;
- ADL_Overdrive5_ODPerformanceLevels_Set(ga->iAdapterIndex, lpOdPerformanceLevels);
- ADL_Overdrive5_ODPerformanceLevels_Get(ga->iAdapterIndex, 0, lpOdPerformanceLevels);
- goto out;
- }
+ if (lpOdPerformanceLevels->aLevels[lev].iMemoryClock == iMemoryClock)
+ ret = 0;
ga->iEngineClock = lpOdPerformanceLevels->aLevels[lev].iEngineClock;
ga->iMemoryClock = lpOdPerformanceLevels->aLevels[lev].iMemoryClock;
ga->iVddc = lpOdPerformanceLevels->aLevels[lev].iVddc;
ga->managed = true;
- ret = 0;
out:
unlock_adl();
return ret;
@@ -744,24 +724,14 @@ static int set_vddc(int gpu, float fVddc)
lpOdPerformanceLevels->aLevels[i].iVddc = iVddc;
}
lpOdPerformanceLevels->aLevels[lev].iVddc = iVddc;
- if (ADL_Overdrive5_ODPerformanceLevels_Set(ga->iAdapterIndex, lpOdPerformanceLevels) != ADL_OK)
- goto out;
+ ADL_Overdrive5_ODPerformanceLevels_Set(ga->iAdapterIndex, lpOdPerformanceLevels);
ADL_Overdrive5_ODPerformanceLevels_Get(ga->iAdapterIndex, 0, lpOdPerformanceLevels);
- /* Reset to old value if it fails! */
- if (lpOdPerformanceLevels->aLevels[lev].iVddc != iVddc) {
- /* Set all the parameters in case they're linked somehow */
- lpOdPerformanceLevels->aLevels[lev].iEngineClock = ga->iEngineClock;
- lpOdPerformanceLevels->aLevels[lev].iMemoryClock = ga->iMemoryClock;
- lpOdPerformanceLevels->aLevels[lev].iVddc = ga->iVddc;
- ADL_Overdrive5_ODPerformanceLevels_Set(ga->iAdapterIndex, lpOdPerformanceLevels);
- ADL_Overdrive5_ODPerformanceLevels_Get(ga->iAdapterIndex, 0, lpOdPerformanceLevels);
- goto out;
- }
+ if (lpOdPerformanceLevels->aLevels[lev].iVddc == iVddc)
+ ret = 0;
ga->iEngineClock = lpOdPerformanceLevels->aLevels[lev].iEngineClock;
ga->iMemoryClock = lpOdPerformanceLevels->aLevels[lev].iMemoryClock;
ga->iVddc = lpOdPerformanceLevels->aLevels[lev].iVddc;
ga->managed = true;
- ret = 0;
out:
unlock_adl();
return ret;
@@ -809,10 +779,9 @@ static int set_fanspeed(int gpu, int iFanSpeed)
} else
ga->lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
ga->lpFanSpeedValue.iFanSpeed = iFanSpeed;
- if (ADL_Overdrive5_FanSpeed_Set(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue) != ADL_OK)
- goto out;
+ if (ADL_Overdrive5_FanSpeed_Set(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue) == ADL_OK)
+ ret = 0;
ga->managed = true;
- ret = 0;
out:
unlock_adl();
return ret;
@@ -833,14 +802,11 @@ static int set_powertune(int gpu, int iPercentage)
oldPercentage = ga->iPercentage;
lock_adl();
- if (ADL_Overdrive5_PowerControl_Set(ga->iAdapterIndex, iPercentage) != ADL_OK) {
- ADL_Overdrive5_PowerControl_Set(ga->iAdapterIndex, ga->iPercentage);
- goto out;
- }
+ ADL_Overdrive5_PowerControl_Set(ga->iAdapterIndex, iPercentage);
ADL_Overdrive5_PowerControl_Get(ga->iAdapterIndex, &ga->iPercentage, &dummy);
+ if (ga->iPercentage == iPercentage)
+ ret = 0;
ga->managed = true;
- ret = 0;
-out:
unlock_adl();
return ret;
}