Move the ADL setup and clearing to separate functions and provide a reinit_adl function to be used when adl fails while running.
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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
diff --git a/adl.c b/adl.c
index 70dcdfe..13dd06b 100644
--- a/adl.c
+++ b/adl.c
@@ -124,11 +124,9 @@ static bool fanspeed_twin(struct gpu_adl *ga, struct gpu_adl *other_ga)
return true;
}
-void init_adl(int nDevs)
+static bool prepare_adl(void)
{
- int result, i, j, devices = 0, last_adapter = -1, gpu = 0, dummy = 0;
- struct gpu_adapters adapters[MAX_GPUDEVICES], vadapters[MAX_GPUDEVICES];
- bool devs_match = true;
+ int result;
#if defined (LINUX)
hDLL = dlopen( "libatiadlxx.so", RTLD_LAZY|RTLD_GLOBAL);
@@ -141,14 +139,8 @@ void init_adl(int nDevs)
#endif
if (hDLL == NULL) {
applog(LOG_INFO, "Unable to load ati adl library");
- return;
- }
-
- if (unlikely(pthread_mutex_init(&adl_lock, NULL))) {
- applog(LOG_ERR, "Failed to init adl_lock in init_adl");
- return;
+ return false;
}
-
ADL_Main_Control_Create = (ADL_MAIN_CONTROL_CREATE) GetProcAddress(hDLL,"ADL_Main_Control_Create");
ADL_Main_Control_Destroy = (ADL_MAIN_CONTROL_DESTROY) GetProcAddress(hDLL,"ADL_Main_Control_Destroy");
ADL_Adapter_NumberOfAdapters_Get = (ADL_ADAPTER_NUMBEROFADAPTERS_GET) GetProcAddress(hDLL,"ADL_Adapter_NumberOfAdapters_Get");
@@ -177,7 +169,7 @@ void init_adl(int nDevs)
!ADL_Main_Control_Refresh || !ADL_Overdrive5_PowerControl_Get ||
!ADL_Overdrive5_PowerControl_Set || !ADL_Overdrive5_FanSpeedToDefault_Set) {
applog(LOG_WARNING, "ATI ADL's API is missing");
- return;
+ return false;
}
// Initialise ADL. The second parameter is 1, which means:
@@ -185,15 +177,32 @@ void init_adl(int nDevs)
result = ADL_Main_Control_Create (ADL_Main_Memory_Alloc, 1);
if (result != ADL_OK) {
applog(LOG_INFO, "ADL Initialisation Error! Error %d!", result);
- return ;
+ return false;
}
result = ADL_Main_Control_Refresh();
if (result != ADL_OK) {
applog(LOG_INFO, "ADL Refresh Error! Error %d!", result);
- return ;
+ return false;
}
+ return true;
+}
+
+void init_adl(int nDevs)
+{
+ int result, i, j, devices = 0, last_adapter = -1, gpu = 0, dummy = 0;
+ struct gpu_adapters adapters[MAX_GPUDEVICES], vadapters[MAX_GPUDEVICES];
+ bool devs_match = true;
+
+ if (unlikely(pthread_mutex_init(&adl_lock, NULL))) {
+ applog(LOG_ERR, "Failed to init adl_lock in init_adl");
+ return;
+ }
+
+ if (!prepare_adl())
+ return;
+
// Obtain the number of adapters for the system
result = ADL_Adapter_NumberOfAdapters_Get (&iNumberAdapters);
if (result != ADL_OK) {
@@ -1314,6 +1323,17 @@ updated:
}
#endif
+static void free_adl(void)
+{
+ ADL_Main_Memory_Free ((void **)&lpInfo);
+ ADL_Main_Control_Destroy ();
+#if defined (LINUX)
+ dlclose(hDLL);
+#else
+ FreeLibrary(hDLL);
+#endif
+}
+
void clear_adl(int nDevs)
{
struct gpu_adl *ga;
@@ -1334,15 +1354,21 @@ void clear_adl(int nDevs)
ADL_Overdrive5_FanSpeed_Set(ga->iAdapterIndex, 0, &ga->DefFanSpeedValue);
ADL_Overdrive5_FanSpeedToDefault_Set(ga->iAdapterIndex, 0);
}
-
- ADL_Main_Memory_Free ( (void **)&lpInfo );
- ADL_Main_Control_Destroy ();
+ adl_active = false;
unlock_adl();
+ free_adl();
+}
-#if defined (LINUX)
- dlclose(hDLL);
-#else
- FreeLibrary(hDLL);
-#endif
+void reinit_adl(void)
+{
+ bool ret;
+ lock_adl();
+ free_adl();
+ ret = prepare_adl();
+ if (!ret) {
+ adl_active = false;
+ applog(LOG_WARNING, "Attempt to re-initialise ADL has failed, disabling");
+ }
+ unlock_adl();
}
#endif /* HAVE_ADL */
diff --git a/adl.h b/adl.h
index f48c420..363741c 100644
--- a/adl.h
+++ b/adl.h
@@ -19,10 +19,12 @@ bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vdd
void change_gpusettings(int gpu);
void gpu_autotune(int gpu, enum dev_enable *denable);
void clear_adl(int nDevs);
+void reinit_adl(void);
#else /* HAVE_ADL */
#define adl_active (0)
static inline void init_adl(int nDevs) {}
static inline void change_gpusettings(int gpu) { }
static inline void clear_adl(int nDevs) {}
+static inline void reinit_adl(void) {}
#endif
#endif