Set the fanspeed in coarse rounded up values and then ever finer grained values in case the card does not support fine values.
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
diff --git a/adl.c b/adl.c
index f937e9c..1348534 100644
--- a/adl.c
+++ b/adl.c
@@ -744,6 +744,39 @@ static void get_fanrange(int gpu, int *imin, int *imax)
*imax = ga->lpFanSpeedInfo.iMaxPercent;
}
+/* This is overkill, but the safest way to set the fan is to round it up to
+ * very coarse multiples of 100, 50, 20, 10, 5 in case the card does not
+ * support finer values */
+static int __set_fanspeed(int gpu, int iFanSpeed)
+{
+ struct gpu_adl *ga = &gpus[gpu].adl;
+ int speed;
+
+ applog(LOG_INFO, "Setting fanspeed to %d", iFanSpeed);
+ speed = iFanSpeed + 99;
+ speed -= speed % 100;
+ ga->lpFanSpeedValue.iFanSpeed = speed;
+ ADL_Overdrive5_FanSpeed_Set(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue);
+ speed = iFanSpeed + 49;
+ speed -= speed % 50;
+ ga->lpFanSpeedValue.iFanSpeed = speed;
+ ADL_Overdrive5_FanSpeed_Set(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue);
+ speed = iFanSpeed + 19;
+ speed -= speed % 20;
+ ga->lpFanSpeedValue.iFanSpeed = speed;
+ ADL_Overdrive5_FanSpeed_Set(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue);
+ speed = iFanSpeed + 9;
+ speed -= speed % 10;
+ ga->lpFanSpeedValue.iFanSpeed = speed;
+ ADL_Overdrive5_FanSpeed_Set(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue);
+ speed = iFanSpeed + 4;
+ speed -= speed % 5;
+ ga->lpFanSpeedValue.iFanSpeed = speed;
+ ADL_Overdrive5_FanSpeed_Set(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue);
+ ga->lpFanSpeedValue.iFanSpeed = iFanSpeed;
+ return ADL_Overdrive5_FanSpeed_Set(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue);
+}
+
static int set_fanspeed(int gpu, int iFanSpeed)
{
struct gpu_adl *ga;
@@ -755,12 +788,19 @@ static int set_fanspeed(int gpu, int iFanSpeed)
}
ga = &gpus[gpu].adl;
- if (!(ga->lpFanSpeedInfo.iFlags & (ADL_DL_FANCTRL_SUPPORTS_RPM_WRITE | ADL_DL_FANCTRL_SUPPORTS_PERCENT_WRITE )))
+ if (!(ga->lpFanSpeedInfo.iFlags & (ADL_DL_FANCTRL_SUPPORTS_RPM_WRITE | ADL_DL_FANCTRL_SUPPORTS_PERCENT_WRITE ))) {
+ if (opt_debug)
+ applog(LOG_DEBUG, "GPU %d doesn't support rpm or percent write", gpu);
return ret;
+ }
lock_adl();
- if (ADL_Overdrive5_FanSpeed_Get(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue) != ADL_OK)
+ if (ADL_Overdrive5_FanSpeed_Get(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue) != ADL_OK) {
+ if (opt_debug)
+ applog(LOG_DEBUG, "GPU %d doesn't support fanspeed get", gpu);
goto out;
+ }
+
/* Store what fanspeed we're actually aiming for for re-entrant changes
* in case this device does not support fine setting changes */
ga->targetfan = iFanSpeed;
@@ -775,9 +815,7 @@ static int set_fanspeed(int gpu, int iFanSpeed)
ga->lpFanSpeedValue.iFlags = ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED;
ADL_Overdrive5_FanSpeed_Set(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue);
}
- ga->lpFanSpeedValue.iFanSpeed = iFanSpeed;
- if (ADL_Overdrive5_FanSpeed_Set(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue) == ADL_OK)
- ret = 0;
+ ret = __set_fanspeed(gpu, iFanSpeed);
ga->managed = true;
out:
unlock_adl();