adl.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  1. #include "miner.h"
  2. #include "adl.h"
  3. bool adl_active;
  4. #ifdef HAVE_ADL
  5. #if defined (__linux)
  6. #include "ADL_SDK/adl_sdk.h"
  7. #include <dlfcn.h>
  8. #include <stdlib.h>
  9. #include <unistd.h>
  10. #else
  11. #include <windows.h>
  12. #include <tchar.h>
  13. #include "ADL_SDK/adl_sdk.h"
  14. #endif
  15. #include <stdio.h>
  16. #include <curses.h>
  17. #include "adl_functions.h"
  18. int opt_hysteresis = 3;
  19. int opt_targettemp = 75;
  20. int opt_overheattemp = 85;
  21. // Memory allocation function
  22. static void * __stdcall ADL_Main_Memory_Alloc(int iSize)
  23. {
  24. void *lpBuffer = malloc(iSize);
  25. return lpBuffer;
  26. }
  27. // Optional Memory de-allocation function
  28. static void __stdcall ADL_Main_Memory_Free (void **lpBuffer)
  29. {
  30. if (*lpBuffer) {
  31. free (*lpBuffer);
  32. *lpBuffer = NULL;
  33. }
  34. }
  35. #if defined (LINUX)
  36. // equivalent functions in linux
  37. static void *GetProcAddress(void *pLibrary, const char *name)
  38. {
  39. return dlsym( pLibrary, name);
  40. }
  41. #endif
  42. static ADL_MAIN_CONTROL_CREATE ADL_Main_Control_Create;
  43. static ADL_MAIN_CONTROL_DESTROY ADL_Main_Control_Destroy;
  44. static ADL_ADAPTER_NUMBEROFADAPTERS_GET ADL_Adapter_NumberOfAdapters_Get;
  45. static ADL_ADAPTER_ADAPTERINFO_GET ADL_Adapter_AdapterInfo_Get;
  46. static ADL_ADAPTER_ID_GET ADL_Adapter_ID_Get;
  47. static ADL_OVERDRIVE5_TEMPERATURE_GET ADL_Overdrive5_Temperature_Get;
  48. static ADL_ADAPTER_ACTIVE_GET ADL_Adapter_Active_Get;
  49. static ADL_OVERDRIVE5_CURRENTACTIVITY_GET ADL_Overdrive5_CurrentActivity_Get;
  50. static ADL_OVERDRIVE5_ODPARAMETERS_GET ADL_Overdrive5_ODParameters_Get;
  51. static ADL_OVERDRIVE5_FANSPEEDINFO_GET ADL_Overdrive5_FanSpeedInfo_Get;
  52. static ADL_OVERDRIVE5_FANSPEED_GET ADL_Overdrive5_FanSpeed_Get;
  53. static ADL_OVERDRIVE5_FANSPEED_SET ADL_Overdrive5_FanSpeed_Set;
  54. static ADL_OVERDRIVE5_ODPERFORMANCELEVELS_GET ADL_Overdrive5_ODPerformanceLevels_Get;
  55. static ADL_OVERDRIVE5_ODPERFORMANCELEVELS_SET ADL_Overdrive5_ODPerformanceLevels_Set;
  56. static ADL_MAIN_CONTROL_REFRESH ADL_Main_Control_Refresh;
  57. static ADL_OVERDRIVE5_POWERCONTROL_GET ADL_Overdrive5_PowerControl_Get;
  58. static ADL_OVERDRIVE5_POWERCONTROL_SET ADL_Overdrive5_PowerControl_Set;
  59. #if defined (LINUX)
  60. static void *hDLL; // Handle to .so library
  61. #else
  62. HINSTANCE hDLL; // Handle to DLL
  63. #endif
  64. static int iNumberAdapters;
  65. static LPAdapterInfo lpInfo = NULL;
  66. void init_adl(int nDevs)
  67. {
  68. int i, devices = 0, last_adapter = -1, gpu = 0, dummy = 0;
  69. #if defined (LINUX)
  70. hDLL = dlopen( "libatiadlxx.so", RTLD_LAZY|RTLD_GLOBAL);
  71. #else
  72. hDLL = LoadLibrary("atiadlxx.dll");
  73. if (hDLL == NULL)
  74. // A 32 bit calling application on 64 bit OS will fail to LoadLIbrary.
  75. // Try to load the 32 bit library (atiadlxy.dll) instead
  76. hDLL = LoadLibrary("atiadlxy.dll");
  77. #endif
  78. if (hDLL == NULL) {
  79. applog(LOG_INFO, "Unable to load ati adl library");
  80. return;
  81. }
  82. ADL_Main_Control_Create = (ADL_MAIN_CONTROL_CREATE) GetProcAddress(hDLL,"ADL_Main_Control_Create");
  83. ADL_Main_Control_Destroy = (ADL_MAIN_CONTROL_DESTROY) GetProcAddress(hDLL,"ADL_Main_Control_Destroy");
  84. ADL_Adapter_NumberOfAdapters_Get = (ADL_ADAPTER_NUMBEROFADAPTERS_GET) GetProcAddress(hDLL,"ADL_Adapter_NumberOfAdapters_Get");
  85. ADL_Adapter_AdapterInfo_Get = (ADL_ADAPTER_ADAPTERINFO_GET) GetProcAddress(hDLL,"ADL_Adapter_AdapterInfo_Get");
  86. ADL_Adapter_ID_Get = (ADL_ADAPTER_ID_GET) GetProcAddress(hDLL,"ADL_Adapter_ID_Get");
  87. ADL_Overdrive5_Temperature_Get = (ADL_OVERDRIVE5_TEMPERATURE_GET) GetProcAddress(hDLL,"ADL_Overdrive5_Temperature_Get");
  88. ADL_Adapter_Active_Get = (ADL_ADAPTER_ACTIVE_GET) GetProcAddress(hDLL, "ADL_Adapter_Active_Get");
  89. ADL_Overdrive5_CurrentActivity_Get = (ADL_OVERDRIVE5_CURRENTACTIVITY_GET) GetProcAddress(hDLL, "ADL_Overdrive5_CurrentActivity_Get");
  90. ADL_Overdrive5_ODParameters_Get = (ADL_OVERDRIVE5_ODPARAMETERS_GET) GetProcAddress(hDLL, "ADL_Overdrive5_ODParameters_Get");
  91. ADL_Overdrive5_FanSpeedInfo_Get = (ADL_OVERDRIVE5_FANSPEEDINFO_GET) GetProcAddress(hDLL, "ADL_Overdrive5_FanSpeedInfo_Get");
  92. ADL_Overdrive5_FanSpeed_Get = (ADL_OVERDRIVE5_FANSPEED_GET) GetProcAddress(hDLL, "ADL_Overdrive5_FanSpeed_Get");
  93. ADL_Overdrive5_FanSpeed_Set = (ADL_OVERDRIVE5_FANSPEED_SET) GetProcAddress(hDLL, "ADL_Overdrive5_FanSpeed_Set");
  94. ADL_Overdrive5_ODPerformanceLevels_Get = (ADL_OVERDRIVE5_ODPERFORMANCELEVELS_GET) GetProcAddress(hDLL, "ADL_Overdrive5_ODPerformanceLevels_Get");
  95. ADL_Overdrive5_ODPerformanceLevels_Set = (ADL_OVERDRIVE5_ODPERFORMANCELEVELS_SET) GetProcAddress(hDLL, "ADL_Overdrive5_ODPerformanceLevels_Set");
  96. ADL_Main_Control_Refresh = (ADL_MAIN_CONTROL_REFRESH) GetProcAddress(hDLL, "ADL_Main_Control_Refresh");
  97. ADL_Overdrive5_PowerControl_Get = (ADL_OVERDRIVE5_POWERCONTROL_GET) GetProcAddress(hDLL, "ADL_Overdrive5_PowerControl_Get");
  98. ADL_Overdrive5_PowerControl_Set = (ADL_OVERDRIVE5_POWERCONTROL_SET) GetProcAddress(hDLL, "ADL_Overdrive5_PowerControl_Set");
  99. if (!ADL_Main_Control_Create || !ADL_Main_Control_Destroy ||
  100. !ADL_Adapter_NumberOfAdapters_Get || !ADL_Adapter_AdapterInfo_Get ||
  101. !ADL_Adapter_ID_Get || !ADL_Overdrive5_Temperature_Get ||
  102. !ADL_Adapter_Active_Get || !ADL_Overdrive5_CurrentActivity_Get ||
  103. !ADL_Overdrive5_ODParameters_Get || !ADL_Overdrive5_FanSpeedInfo_Get ||
  104. !ADL_Overdrive5_FanSpeed_Get || !ADL_Overdrive5_FanSpeed_Set ||
  105. !ADL_Overdrive5_ODPerformanceLevels_Get || !ADL_Overdrive5_ODPerformanceLevels_Set ||
  106. !ADL_Main_Control_Refresh || !ADL_Overdrive5_PowerControl_Get ||
  107. !ADL_Overdrive5_PowerControl_Set) {
  108. applog(LOG_WARNING, "ATI ADL's API is missing");
  109. return;
  110. }
  111. // Initialise ADL. The second parameter is 1, which means:
  112. // retrieve adapter information only for adapters that are physically present and enabled in the system
  113. if (ADL_Main_Control_Create (ADL_Main_Memory_Alloc, 1) != ADL_OK) {
  114. applog(LOG_INFO, "ADL Initialisation Error!");
  115. return ;
  116. }
  117. if (ADL_Main_Control_Refresh() != ADL_OK) {
  118. applog(LOG_INFO, "ADL Refresh Error!");
  119. return ;
  120. }
  121. // Obtain the number of adapters for the system
  122. if (ADL_Adapter_NumberOfAdapters_Get ( &iNumberAdapters ) != ADL_OK) {
  123. applog(LOG_INFO, "Cannot get the number of adapters!\n");
  124. return ;
  125. }
  126. if (iNumberAdapters > 0) {
  127. lpInfo = malloc ( sizeof (AdapterInfo) * iNumberAdapters );
  128. memset ( lpInfo,'\0', sizeof (AdapterInfo) * iNumberAdapters );
  129. // Get the AdapterInfo structure for all adapters in the system
  130. if (ADL_Adapter_AdapterInfo_Get (lpInfo, sizeof (AdapterInfo) * iNumberAdapters) != ADL_OK) {
  131. applog(LOG_INFO, "ADL_Adapter_AdapterInfo_Get Error!");
  132. return ;
  133. }
  134. } else {
  135. applog(LOG_INFO, "No adapters found");
  136. return;
  137. }
  138. for (i = 0; i < iNumberAdapters; i++) {
  139. struct gpu_adl *ga;
  140. int iAdapterIndex;
  141. int lpAdapterID;
  142. int lpStatus;
  143. ADLODPerformanceLevels *lpOdPerformanceLevels;
  144. int lev;
  145. iAdapterIndex = lpInfo[i].iAdapterIndex;
  146. /* Get unique identifier of the adapter */
  147. if (ADL_Adapter_ID_Get(iAdapterIndex, &lpAdapterID) != ADL_OK) {
  148. applog(LOG_INFO, "Failed to ADL_Adapter_ID_Get");
  149. continue;
  150. }
  151. if (!lpAdapterID)
  152. continue;
  153. if (lpAdapterID != last_adapter) {
  154. /* We found a truly new adapter instead of a logical
  155. * one. Now since there's no way of correlating the
  156. * opencl enumerated devices and the ADL enumerated
  157. * ones, we have to assume they're in the same order.*/
  158. if (++devices > nDevs) {
  159. applog(LOG_ERR, "ADL found more devices than opencl");
  160. return;
  161. }
  162. gpu = devices - 1;
  163. last_adapter = lpAdapterID;
  164. }
  165. /* See if the adapter is an AMD device with ADL active */
  166. if (ADL_Adapter_Active_Get(iAdapterIndex, &lpStatus) != ADL_OK) {
  167. applog(LOG_INFO, "Failed to ADL_Adapter_Active_Get");
  168. continue;
  169. }
  170. if (!lpStatus)
  171. continue;
  172. /* From here on we know this device is a discrete device and
  173. * should support ADL */
  174. ga = &gpus[gpu].adl;
  175. ga->iAdapterIndex = iAdapterIndex;
  176. ga->lpAdapterID = lpAdapterID;
  177. ga->lpStatus = lpStatus;
  178. ga->DefPerfLev = NULL;
  179. if (ADL_Overdrive5_ODParameters_Get(iAdapterIndex, &ga->lpOdParameters) != ADL_OK) {
  180. applog(LOG_INFO, "Failed to ADL_Overdrive5_ODParameters_Get");
  181. continue;
  182. }
  183. lev = ga->lpOdParameters.iNumberOfPerformanceLevels - 1;
  184. /* We're only interested in the top performance level */
  185. lpOdPerformanceLevels = malloc(sizeof(ADLODPerformanceLevels) + (lev * sizeof(ADLODPerformanceLevel)));
  186. lpOdPerformanceLevels->iSize = sizeof(ADLODPerformanceLevels) + sizeof(ADLODPerformanceLevel) * lev;
  187. /* Get default performance levels first */
  188. if (ADL_Overdrive5_ODPerformanceLevels_Get(iAdapterIndex, 1, lpOdPerformanceLevels) != ADL_OK) {
  189. applog(LOG_INFO, "Failed to ADL_Overdrive5_ODPerformanceLevels_Get");
  190. continue;
  191. }
  192. /* Set the limits we'd use based on default gpu speeds */
  193. ga->maxspeed = ga->minspeed = lpOdPerformanceLevels->aLevels[lev].iEngineClock;
  194. /* Now get the current performance levels for any existing overclock */
  195. ADL_Overdrive5_ODPerformanceLevels_Get(iAdapterIndex, 0, lpOdPerformanceLevels);
  196. /* Save these values as the defaults in case we wish to reset to defaults */
  197. ga->DefPerfLev = lpOdPerformanceLevels;
  198. if (gpus[gpu].gpu_engine) {
  199. lpOdPerformanceLevels->aLevels[lev].iEngineClock = gpus[gpu].gpu_engine * 100;
  200. applog(LOG_INFO, "Setting GPU %d engine clock to %d", gpu, gpus[gpu].gpu_engine);
  201. ADL_Overdrive5_ODPerformanceLevels_Set(iAdapterIndex, lpOdPerformanceLevels);
  202. }
  203. if (gpus[gpu].gpu_memclock) {
  204. lpOdPerformanceLevels->aLevels[lev].iMemoryClock = gpus[gpu].gpu_memclock * 100;
  205. applog(LOG_INFO, "Setting GPU %d memory clock to %d", gpu, gpus[gpu].gpu_memclock);
  206. ADL_Overdrive5_ODPerformanceLevels_Set(iAdapterIndex, lpOdPerformanceLevels);
  207. }
  208. if (gpus[gpu].gpu_vddc) {
  209. lpOdPerformanceLevels->aLevels[lev].iVddc = gpus[gpu].gpu_vddc * 1000;
  210. applog(LOG_INFO, "Setting GPU %d voltage to %.3f", gpu, gpus[gpu].gpu_vddc);
  211. ADL_Overdrive5_ODPerformanceLevels_Set(iAdapterIndex, lpOdPerformanceLevels);
  212. }
  213. ADL_Overdrive5_ODPerformanceLevels_Get(iAdapterIndex, 0, lpOdPerformanceLevels);
  214. ga->iEngineClock = lpOdPerformanceLevels->aLevels[lev].iEngineClock;
  215. ga->iMemoryClock = lpOdPerformanceLevels->aLevels[lev].iMemoryClock;
  216. ga->iVddc = lpOdPerformanceLevels->aLevels[lev].iVddc;
  217. if (ga->iEngineClock < ga->minspeed)
  218. ga->minspeed = ga->iEngineClock;
  219. if (ga->iEngineClock > ga->maxspeed)
  220. ga->maxspeed = ga->iEngineClock;
  221. if (ADL_Overdrive5_FanSpeedInfo_Get(iAdapterIndex, 0, &ga->lpFanSpeedInfo) != ADL_OK) {
  222. applog(LOG_INFO, "Failed to ADL_Overdrive5_FanSpeedInfo_Get");
  223. continue;
  224. }
  225. /* Save the fanspeed values as defaults in case we reset later */
  226. ADL_Overdrive5_FanSpeed_Get(ga->iAdapterIndex, 0, &ga->DefFanSpeedValue);
  227. if (gpus[gpu].gpu_fan) {
  228. ADL_Overdrive5_FanSpeed_Get(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue);
  229. ga->lpFanSpeedValue.iFanSpeed = gpus[gpu].gpu_fan;
  230. ga->lpFanSpeedValue.iFlags = ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED;
  231. ga->lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
  232. applog(LOG_INFO, "Setting GPU %d fan speed to %d%%", gpu, gpus[gpu].gpu_fan);
  233. ADL_Overdrive5_FanSpeed_Set(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue);
  234. }
  235. /* Not fatal if powercontrol get fails */
  236. if (ADL_Overdrive5_PowerControl_Get(ga->iAdapterIndex, &ga->iPercentage, &dummy) != ADL_OK)
  237. applog(LOG_INFO, "Failed to ADL_Overdrive5_PowerControl_get");
  238. if (gpus[gpu].gpu_powertune) {
  239. ADL_Overdrive5_PowerControl_Set(ga->iAdapterIndex, gpus[gpu].gpu_powertune);
  240. ADL_Overdrive5_PowerControl_Get(ga->iAdapterIndex, &ga->iPercentage, &dummy);
  241. }
  242. /* Set some default temperatures for autotune when enabled */
  243. ga->targettemp = opt_targettemp;
  244. ga->overtemp = opt_overheattemp;
  245. if (opt_autofan)
  246. ga->autofan = true;
  247. if (opt_autoengine)
  248. ga->autoengine = true;
  249. gpus[gpu].has_adl = true;
  250. }
  251. adl_active = true;
  252. }
  253. static inline float __gpu_temp(struct gpu_adl *ga)
  254. {
  255. if (ADL_Overdrive5_Temperature_Get(ga->iAdapterIndex, 0, &ga->lpTemperature) != ADL_OK)
  256. return 0;
  257. return (float)ga->lpTemperature.iTemperature / 1000;
  258. }
  259. float gpu_temp(int gpu)
  260. {
  261. struct gpu_adl *ga;
  262. if (!gpus[gpu].has_adl || !adl_active)
  263. return 0;
  264. ga = &gpus[gpu].adl;
  265. return __gpu_temp(ga);
  266. }
  267. static inline int __gpu_engineclock(struct gpu_adl *ga)
  268. {
  269. return ga->lpActivity.iEngineClock / 100;
  270. }
  271. int gpu_engineclock(int gpu)
  272. {
  273. struct gpu_adl *ga;
  274. if (!gpus[gpu].has_adl || !adl_active)
  275. return 0;
  276. ga = &gpus[gpu].adl;
  277. if (ADL_Overdrive5_CurrentActivity_Get(ga->iAdapterIndex, &ga->lpActivity) != ADL_OK)
  278. return 0;
  279. return __gpu_engineclock(ga);
  280. }
  281. static inline int __gpu_memclock(struct gpu_adl *ga)
  282. {
  283. return ga->lpActivity.iMemoryClock / 100;
  284. }
  285. int gpu_memclock(int gpu)
  286. {
  287. struct gpu_adl *ga;
  288. if (!gpus[gpu].has_adl || !adl_active)
  289. return 0;
  290. ga = &gpus[gpu].adl;
  291. if (ADL_Overdrive5_CurrentActivity_Get(ga->iAdapterIndex, &ga->lpActivity) != ADL_OK)
  292. return 0;
  293. return __gpu_memclock(ga);
  294. }
  295. static inline float __gpu_vddc(struct gpu_adl *ga)
  296. {
  297. return (float)ga->lpActivity.iVddc / 1000;
  298. }
  299. float gpu_vddc(int gpu)
  300. {
  301. struct gpu_adl *ga;
  302. if (!gpus[gpu].has_adl || !adl_active)
  303. return 0;
  304. ga = &gpus[gpu].adl;
  305. if (ADL_Overdrive5_CurrentActivity_Get(ga->iAdapterIndex, &ga->lpActivity) != ADL_OK)
  306. return 0;
  307. return __gpu_vddc(ga);
  308. }
  309. static inline int __gpu_activity(struct gpu_adl *ga)
  310. {
  311. if (!ga->lpOdParameters.iActivityReportingSupported)
  312. return 0;
  313. return ga->lpActivity.iActivityPercent;
  314. }
  315. int gpu_activity(int gpu)
  316. {
  317. struct gpu_adl *ga;
  318. if (!gpus[gpu].has_adl || !adl_active)
  319. return 0;
  320. ga = &gpus[gpu].adl;
  321. if (ADL_Overdrive5_CurrentActivity_Get(ga->iAdapterIndex, &ga->lpActivity) != ADL_OK)
  322. return 0;
  323. return __gpu_activity(ga);
  324. }
  325. static inline int __gpu_fanspeed(struct gpu_adl *ga)
  326. {
  327. if (!(ga->lpFanSpeedInfo.iFlags & ADL_DL_FANCTRL_SUPPORTS_RPM_READ))
  328. return 0;
  329. ga->lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_RPM;
  330. if (ADL_Overdrive5_FanSpeed_Get(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue) != ADL_OK)
  331. return 0;
  332. return ga->lpFanSpeedValue.iFanSpeed;
  333. }
  334. int gpu_fanspeed(int gpu)
  335. {
  336. struct gpu_adl *ga;
  337. if (!gpus[gpu].has_adl || !adl_active)
  338. return 0;
  339. ga = &gpus[gpu].adl;
  340. return __gpu_fanspeed(ga);
  341. }
  342. static inline int __gpu_fanpercent(struct gpu_adl *ga)
  343. {
  344. if (!(ga->lpFanSpeedInfo.iFlags & ADL_DL_FANCTRL_SUPPORTS_PERCENT_READ ))
  345. return -1;
  346. ga->lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
  347. if (ADL_Overdrive5_FanSpeed_Get(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue) != ADL_OK)
  348. return -1;
  349. return ga->lpFanSpeedValue.iFanSpeed;
  350. }
  351. int gpu_fanpercent(int gpu)
  352. {
  353. struct gpu_adl *ga;
  354. if (!gpus[gpu].has_adl || !adl_active)
  355. return -1;
  356. ga = &gpus[gpu].adl;
  357. return __gpu_fanpercent(ga);
  358. }
  359. static inline int __gpu_powertune(struct gpu_adl *ga)
  360. {
  361. int dummy = 0;
  362. if (ADL_Overdrive5_PowerControl_Get(ga->iAdapterIndex, &ga->iPercentage, &dummy) != ADL_OK)
  363. return 0;
  364. return ga->iPercentage;
  365. }
  366. int gpu_powertune(int gpu)
  367. {
  368. struct gpu_adl *ga;
  369. if (!gpus[gpu].has_adl || !adl_active)
  370. return -1;
  371. ga = &gpus[gpu].adl;
  372. return __gpu_powertune(ga);
  373. }
  374. bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc,
  375. int *activity, int *fanspeed, int *fanpercent, int *powertune)
  376. {
  377. struct gpu_adl *ga;
  378. if (!gpus[gpu].has_adl || !adl_active)
  379. return false;
  380. ga = &gpus[gpu].adl;
  381. *temp = __gpu_temp(ga);
  382. if (ADL_Overdrive5_CurrentActivity_Get(ga->iAdapterIndex, &ga->lpActivity) != ADL_OK) {
  383. *engineclock = 0;
  384. *memclock = 0;
  385. *vddc = 0;
  386. *activity = 0;
  387. } else {
  388. *engineclock = __gpu_engineclock(ga);
  389. *memclock = __gpu_memclock(ga);
  390. *vddc = __gpu_vddc(ga);
  391. *activity = __gpu_activity(ga);
  392. }
  393. *fanspeed = __gpu_fanspeed(ga);
  394. *fanpercent = __gpu_fanpercent(ga);
  395. *powertune = __gpu_powertune(ga);
  396. return true;
  397. }
  398. static void get_enginerange(int gpu, int *imin, int *imax)
  399. {
  400. struct gpu_adl *ga;
  401. if (!gpus[gpu].has_adl || !adl_active) {
  402. wlogprint("Get enginerange not supported\n");
  403. return;
  404. }
  405. ga = &gpus[gpu].adl;
  406. *imin = ga->lpOdParameters.sEngineClock.iMin / 100;
  407. *imax = ga->lpOdParameters.sEngineClock.iMax / 100;
  408. }
  409. static int set_engineclock(int gpu, int iEngineClock)
  410. {
  411. ADLODPerformanceLevels *lpOdPerformanceLevels;
  412. struct gpu_adl *ga;
  413. int lev;
  414. if (!gpus[gpu].has_adl || !adl_active) {
  415. wlogprint("Set engineclock not supported\n");
  416. return 1;
  417. }
  418. iEngineClock *= 100;
  419. ga = &gpus[gpu].adl;
  420. lev = ga->lpOdParameters.iNumberOfPerformanceLevels - 1;
  421. lpOdPerformanceLevels = alloca(sizeof(ADLODPerformanceLevels) + (lev * sizeof(ADLODPerformanceLevel)));
  422. lpOdPerformanceLevels->iSize = sizeof(ADLODPerformanceLevels) + sizeof(ADLODPerformanceLevel) * lev;
  423. if (ADL_Overdrive5_ODPerformanceLevels_Get(ga->iAdapterIndex, 0, lpOdPerformanceLevels) != ADL_OK)
  424. return 1;
  425. lpOdPerformanceLevels->aLevels[lev].iEngineClock = iEngineClock;
  426. if (ADL_Overdrive5_ODPerformanceLevels_Set(ga->iAdapterIndex, lpOdPerformanceLevels) != ADL_OK)
  427. return 1;
  428. ADL_Overdrive5_ODPerformanceLevels_Get(ga->iAdapterIndex, 0, lpOdPerformanceLevels);
  429. /* Reset to old value if it fails! */
  430. if (lpOdPerformanceLevels->aLevels[lev].iEngineClock != iEngineClock) {
  431. /* Set all the parameters in case they're linked somehow */
  432. lpOdPerformanceLevels->aLevels[lev].iEngineClock = ga->iEngineClock;
  433. lpOdPerformanceLevels->aLevels[lev].iMemoryClock = ga->iMemoryClock;
  434. lpOdPerformanceLevels->aLevels[lev].iVddc = ga->iVddc;
  435. ADL_Overdrive5_ODPerformanceLevels_Set(ga->iAdapterIndex, lpOdPerformanceLevels);
  436. ADL_Overdrive5_ODPerformanceLevels_Get(ga->iAdapterIndex, 0, lpOdPerformanceLevels);
  437. return 1;
  438. }
  439. ga->iEngineClock = lpOdPerformanceLevels->aLevels[lev].iEngineClock;
  440. if (ga->iEngineClock > ga->maxspeed)
  441. ga->maxspeed = ga->iEngineClock;
  442. if (ga->iEngineClock < ga->minspeed)
  443. ga->minspeed = ga->iEngineClock;
  444. ga->iMemoryClock = lpOdPerformanceLevels->aLevels[lev].iMemoryClock;
  445. ga->iVddc = lpOdPerformanceLevels->aLevels[lev].iVddc;
  446. return 0;
  447. }
  448. static void get_memoryrange(int gpu, int *imin, int *imax)
  449. {
  450. struct gpu_adl *ga;
  451. if (!gpus[gpu].has_adl || !adl_active) {
  452. wlogprint("Get memoryrange not supported\n");
  453. return;
  454. }
  455. ga = &gpus[gpu].adl;
  456. *imin = ga->lpOdParameters.sMemoryClock.iMin / 100;
  457. *imax = ga->lpOdParameters.sMemoryClock.iMax / 100;
  458. }
  459. static int set_memoryclock(int gpu, int iMemoryClock)
  460. {
  461. ADLODPerformanceLevels *lpOdPerformanceLevels;
  462. struct gpu_adl *ga;
  463. int lev;
  464. if (!gpus[gpu].has_adl || !adl_active) {
  465. wlogprint("Set memoryclock not supported\n");
  466. return 1;
  467. }
  468. iMemoryClock *= 100;
  469. ga = &gpus[gpu].adl;
  470. lev = ga->lpOdParameters.iNumberOfPerformanceLevels - 1;
  471. lpOdPerformanceLevels = alloca(sizeof(ADLODPerformanceLevels) + (lev * sizeof(ADLODPerformanceLevel)));
  472. lpOdPerformanceLevels->iSize = sizeof(ADLODPerformanceLevels) + sizeof(ADLODPerformanceLevel) * lev;
  473. if (ADL_Overdrive5_ODPerformanceLevels_Get(ga->iAdapterIndex, 0, lpOdPerformanceLevels) != ADL_OK)
  474. return 1;
  475. lpOdPerformanceLevels->aLevels[lev].iMemoryClock = iMemoryClock;
  476. if (ADL_Overdrive5_ODPerformanceLevels_Set(ga->iAdapterIndex, lpOdPerformanceLevels) != ADL_OK)
  477. return 1;
  478. ADL_Overdrive5_ODPerformanceLevels_Get(ga->iAdapterIndex, 0, lpOdPerformanceLevels);
  479. /* Reset to old value if it fails! */
  480. if (lpOdPerformanceLevels->aLevels[lev].iMemoryClock != iMemoryClock) {
  481. /* Set all the parameters in case they're linked somehow */
  482. lpOdPerformanceLevels->aLevels[lev].iMemoryClock = ga->iEngineClock;
  483. lpOdPerformanceLevels->aLevels[lev].iMemoryClock = ga->iMemoryClock;
  484. lpOdPerformanceLevels->aLevels[lev].iVddc = ga->iVddc;
  485. ADL_Overdrive5_ODPerformanceLevels_Set(ga->iAdapterIndex, lpOdPerformanceLevels);
  486. ADL_Overdrive5_ODPerformanceLevels_Get(ga->iAdapterIndex, 0, lpOdPerformanceLevels);
  487. return 1;
  488. }
  489. ga->iEngineClock = lpOdPerformanceLevels->aLevels[lev].iEngineClock;
  490. ga->iMemoryClock = lpOdPerformanceLevels->aLevels[lev].iMemoryClock;
  491. ga->iVddc = lpOdPerformanceLevels->aLevels[lev].iVddc;
  492. return 0;
  493. }
  494. static void get_vddcrange(int gpu, float *imin, float *imax)
  495. {
  496. struct gpu_adl *ga;
  497. if (!gpus[gpu].has_adl || !adl_active) {
  498. wlogprint("Get vddcrange not supported\n");
  499. return;
  500. }
  501. ga = &gpus[gpu].adl;
  502. *imin = (float)ga->lpOdParameters.sVddc.iMin / 1000;
  503. *imax = (float)ga->lpOdParameters.sVddc.iMax / 1000;
  504. }
  505. static float curses_float(const char *query)
  506. {
  507. float ret;
  508. char *cvar;
  509. cvar = curses_input(query);
  510. ret = atof(cvar);
  511. free(cvar);
  512. return ret;
  513. }
  514. static int set_vddc(int gpu, float fVddc)
  515. {
  516. ADLODPerformanceLevels *lpOdPerformanceLevels;
  517. struct gpu_adl *ga;
  518. int iVddc, lev;
  519. if (!gpus[gpu].has_adl || !adl_active) {
  520. wlogprint("Set vddc not supported\n");
  521. return 1;
  522. }
  523. iVddc = 1000 * fVddc;
  524. ga = &gpus[gpu].adl;
  525. lev = ga->lpOdParameters.iNumberOfPerformanceLevels - 1;
  526. lpOdPerformanceLevels = alloca(sizeof(ADLODPerformanceLevels) + (lev * sizeof(ADLODPerformanceLevel)));
  527. lpOdPerformanceLevels->iSize = sizeof(ADLODPerformanceLevels) + sizeof(ADLODPerformanceLevel) * lev;
  528. if (ADL_Overdrive5_ODPerformanceLevels_Get(ga->iAdapterIndex, 0, lpOdPerformanceLevels) != ADL_OK)
  529. return 1;
  530. lpOdPerformanceLevels->aLevels[lev].iVddc = iVddc;
  531. if (ADL_Overdrive5_ODPerformanceLevels_Set(ga->iAdapterIndex, lpOdPerformanceLevels) != ADL_OK)
  532. return 1;
  533. ADL_Overdrive5_ODPerformanceLevels_Get(ga->iAdapterIndex, 0, lpOdPerformanceLevels);
  534. /* Reset to old value if it fails! */
  535. if (lpOdPerformanceLevels->aLevels[lev].iVddc != iVddc) {
  536. /* Set all the parameters in case they're linked somehow */
  537. lpOdPerformanceLevels->aLevels[lev].iEngineClock = ga->iEngineClock;
  538. lpOdPerformanceLevels->aLevels[lev].iMemoryClock = ga->iMemoryClock;
  539. lpOdPerformanceLevels->aLevels[lev].iVddc = ga->iVddc;
  540. ADL_Overdrive5_ODPerformanceLevels_Set(ga->iAdapterIndex, lpOdPerformanceLevels);
  541. ADL_Overdrive5_ODPerformanceLevels_Get(ga->iAdapterIndex, 0, lpOdPerformanceLevels);
  542. return 1;
  543. }
  544. ga->iEngineClock = lpOdPerformanceLevels->aLevels[lev].iEngineClock;
  545. ga->iMemoryClock = lpOdPerformanceLevels->aLevels[lev].iMemoryClock;
  546. ga->iVddc = lpOdPerformanceLevels->aLevels[lev].iVddc;
  547. return 0;
  548. }
  549. static void get_fanrange(int gpu, int *imin, int *imax)
  550. {
  551. struct gpu_adl *ga;
  552. if (!gpus[gpu].has_adl || !adl_active) {
  553. wlogprint("Get fanrange not supported\n");
  554. return;
  555. }
  556. ga = &gpus[gpu].adl;
  557. *imin = ga->lpFanSpeedInfo.iMinPercent;
  558. *imax = ga->lpFanSpeedInfo.iMaxPercent;
  559. }
  560. static int set_fanspeed(int gpu, int iFanSpeed)
  561. {
  562. struct gpu_adl *ga;
  563. if (!gpus[gpu].has_adl || !adl_active) {
  564. wlogprint("Set fanspeed not supported\n");
  565. return 1;
  566. }
  567. ga = &gpus[gpu].adl;
  568. if (!(ga->lpFanSpeedInfo.iFlags & (ADL_DL_FANCTRL_SUPPORTS_RPM_WRITE | ADL_DL_FANCTRL_SUPPORTS_PERCENT_WRITE )))
  569. return 1;
  570. if (ADL_Overdrive5_FanSpeed_Get(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue) != ADL_OK)
  571. return 1;
  572. ga->lpFanSpeedValue.iFlags = ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED;
  573. if ((ga->lpFanSpeedInfo.iFlags & ADL_DL_FANCTRL_SUPPORTS_RPM_WRITE) &&
  574. !(ga->lpFanSpeedInfo.iFlags & ADL_DL_FANCTRL_SUPPORTS_PERCENT_WRITE)) {
  575. /* Must convert speed to an RPM */
  576. iFanSpeed = ga->lpFanSpeedInfo.iMaxRPM * iFanSpeed / 100;
  577. ga->lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_RPM;
  578. } else
  579. ga->lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_PERCENT;
  580. ga->lpFanSpeedValue.iFanSpeed = iFanSpeed;
  581. if (ADL_Overdrive5_FanSpeed_Set(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue) != ADL_OK)
  582. return 1;
  583. return 0;
  584. }
  585. static int set_powertune(int gpu, int iPercentage)
  586. {
  587. int oldPercentage, dummy;
  588. struct gpu_adl *ga;
  589. if (!gpus[gpu].has_adl || !adl_active) {
  590. wlogprint("Set powertune not supported\n");
  591. return 1;
  592. }
  593. ga = &gpus[gpu].adl;
  594. oldPercentage = ga->iPercentage;
  595. if (ADL_Overdrive5_PowerControl_Set(ga->iAdapterIndex, iPercentage) != ADL_OK) {
  596. ADL_Overdrive5_PowerControl_Set(ga->iAdapterIndex, ga->iPercentage);
  597. return 1;
  598. }
  599. ADL_Overdrive5_PowerControl_Get(ga->iAdapterIndex, &ga->iPercentage, &dummy);
  600. return 0;
  601. }
  602. void gpu_autotune(int gpu)
  603. {
  604. int temp, fanpercent, engine, newpercent, newengine;
  605. bool fan_optimal = true;
  606. struct gpu_adl *ga;
  607. if (!gpus[gpu].has_adl || !adl_active)
  608. return;
  609. ga = &gpus[gpu].adl;
  610. temp = __gpu_temp(ga);
  611. newpercent = fanpercent = __gpu_fanpercent(ga);
  612. newengine = engine = gpu_engineclock(gpu) * 100;
  613. if (temp && fanpercent >= 0 && ga->autofan) {
  614. if (temp > ga->overtemp && fanpercent < 100) {
  615. applog(LOG_WARNING, "Overheat detected, increasing fan to 100%");
  616. newpercent = 100;
  617. } else if (temp > ga->targettemp && fanpercent < 85) {
  618. if (opt_debug)
  619. applog(LOG_DEBUG, "Temperature over target, increasing fanspeed");
  620. newpercent = fanpercent + 5;
  621. if (newpercent > 85)
  622. newpercent = 85;
  623. } else if (fanpercent && temp < ga->targettemp - opt_hysteresis) {
  624. if (opt_debug)
  625. applog(LOG_DEBUG, "Temperature %d degrees below target, decreasing fanspeed", opt_hysteresis);
  626. newpercent = fanpercent - 1;
  627. }
  628. if (newpercent > 100)
  629. newpercent = 100;
  630. else if (newpercent < 0)
  631. newpercent = 0;
  632. if (newpercent != fanpercent) {
  633. fan_optimal = false;
  634. applog(LOG_INFO, "Setting GPU %d fan percentage to %d", gpu, newpercent);
  635. set_fanspeed(gpu, newpercent);
  636. }
  637. }
  638. if (engine && ga->autoengine) {
  639. if (temp > ga->overtemp && engine > ga->minspeed) {
  640. applog(LOG_WARNING, "Overheat detected, decreasing GPU clock speed");
  641. newengine = ga->minspeed;
  642. } else if (temp > ga->targettemp + opt_hysteresis && engine > ga->minspeed && fan_optimal) {
  643. if (opt_debug)
  644. applog(LOG_DEBUG, "Temperature %d degrees over target, decreasing clock speed", opt_hysteresis);
  645. newengine = engine - ga->lpOdParameters.sEngineClock.iStep;
  646. } else if (temp < ga->targettemp && engine < ga->maxspeed) {
  647. if (opt_debug)
  648. applog(LOG_DEBUG, "Temperature below target, increasing clock speed");
  649. newengine = engine + ga->lpOdParameters.sEngineClock.iStep;
  650. }
  651. if (newengine > ga->maxspeed)
  652. newengine = ga->maxspeed;
  653. else if (newengine < ga->minspeed)
  654. newengine = ga->minspeed;
  655. if (newengine != engine) {
  656. newengine /= 100;
  657. applog(LOG_INFO, "Setting GPU %d engine clock to %d", gpu, newengine);
  658. set_engineclock(gpu, newengine);
  659. }
  660. }
  661. }
  662. void set_defaultfan(int gpu)
  663. {
  664. struct gpu_adl *ga;
  665. if (!gpus[gpu].has_adl || !adl_active)
  666. return;
  667. ga = &gpus[gpu].adl;
  668. ADL_Overdrive5_FanSpeed_Set(ga->iAdapterIndex, 0, &ga->DefFanSpeedValue);
  669. }
  670. void set_defaultengine(int gpu)
  671. {
  672. struct gpu_adl *ga;
  673. if (!gpus[gpu].has_adl || !adl_active)
  674. return;
  675. ga = &gpus[gpu].adl;
  676. ADL_Overdrive5_ODPerformanceLevels_Set(ga->iAdapterIndex, ga->DefPerfLev);
  677. }
  678. void change_autosettings(int gpu)
  679. {
  680. struct gpu_adl *ga = &gpus[gpu].adl;
  681. char input;
  682. int val;
  683. wlogprint("Target temperature: %d\n", ga->targettemp);
  684. wlogprint("Overheat temperature: %d\n", ga->overtemp);
  685. wlogprint("Hysteresis differece: %d\n", opt_hysteresis);
  686. wlogprint("Toggle [F]an auto [G]PU auto\nChange [T]arget [O]verheat [H]ysteresis\n");
  687. wlogprint("Or press any other key to continue\n");
  688. input = getch();
  689. if (!strncasecmp(&input, "f", 1)) {
  690. ga->autofan ^= true;
  691. wlogprint("Fan autotune is now %s\n", ga->autofan ? "enabled" : "disabled");
  692. if (!ga->autofan) {
  693. wlogprint("Resetting fan to startup settings\n");
  694. set_defaultfan(gpu);
  695. }
  696. } else if (!strncasecmp(&input, "g", 1)) {
  697. ga->autoengine ^= true;
  698. wlogprint("GPU engine clock autotune is now %s\n", ga->autoengine ? "enabled" : "disabled");
  699. if (!ga->autoengine) {
  700. wlogprint("Resetting GPU engine clock to startup settings\n");
  701. set_defaultengine(gpu);
  702. }
  703. } else if (!strncasecmp(&input, "t", 1)) {
  704. val = curses_int("Enter target temperature for this GPU in °C (0-100)");
  705. if (val < 0 || val > 100)
  706. wlogprint("Invalid temperature");
  707. else
  708. ga->targettemp = val;
  709. } else if (!strncasecmp(&input, "o", 1)) {
  710. wlogprint("Enter oveheat temperature for this GPU in °C (%d-100)", ga->targettemp);
  711. val = curses_int("");
  712. if (val <= ga->targettemp || val > 100)
  713. wlogprint("Invalid temperature");
  714. else
  715. ga->overtemp = val;
  716. } else if (!strncasecmp(&input, "h", 1)) {
  717. val = curses_int("Enter hysteresis temperature difference (0-10)");
  718. if (val < 1 || val > 10)
  719. wlogprint("Invalid value");
  720. else
  721. opt_hysteresis = val;
  722. }
  723. }
  724. void change_gpusettings(int gpu)
  725. {
  726. struct gpu_adl *ga = &gpus[gpu].adl;
  727. float fval, fmin = 0, fmax = 0;
  728. int val, imin = 0, imax = 0;
  729. char input;
  730. int engineclock = 0, memclock = 0, activity = 0, fanspeed = 0, fanpercent = 0, powertune = 0;
  731. float temp = 0, vddc = 0;
  732. updated:
  733. if (gpu_stats(gpu, &temp, &engineclock, &memclock, &vddc, &activity, &fanspeed, &fanpercent, &powertune))
  734. wlogprint("Temp: %.1f °C\nFan Speed: %d%% (%d RPM)\nEngine Clock: %d MHz\n"
  735. "Memory Clock: %d Mhz\nVddc: %.3f V\nActivity: %d%%\nPowertune: %d%%\n",
  736. temp, fanpercent, fanspeed, engineclock, memclock, vddc, activity, powertune);
  737. wlogprint("Fan autotune is %s\n", ga->autofan ? "enabled" : "disabled");
  738. wlogprint("GPU engine clock autotune is %s\n", ga->autoengine ? "enabled" : "disabled");
  739. wlogprint("Change [A]utomatic [E]ngine [F]an [M]emory [V]oltage [P]owertune\n");
  740. wlogprint("Or press any other key to continue\n");
  741. input = getch();
  742. if (!strncasecmp(&input, "a", 1)) {
  743. change_autosettings(gpu);
  744. } else if (!strncasecmp(&input, "e", 1)) {
  745. get_enginerange(gpu, &imin, &imax);
  746. wlogprint("Enter GPU engine clock speed (%d - %d Mhz)", imin, imax);
  747. val = curses_int("");
  748. if (val < imin || val > imax) {
  749. wlogprint("Value is outside safe range, are you sure?\n");
  750. input = getch();
  751. if (strncasecmp(&input, "y", 1))
  752. return;
  753. }
  754. if (!set_engineclock(gpu, val))
  755. wlogprint("Driver reports success but check values below\n");
  756. else
  757. wlogprint("Failed to modify engine clock speed\n");
  758. } else if (!strncasecmp(&input, "f", 1)) {
  759. get_fanrange(gpu, &imin, &imax);
  760. wlogprint("Enter fan percentage (%d - %d %)", imin, imax);
  761. val = curses_int("");
  762. if (val < imin || val > imax) {
  763. wlogprint("Value is outside safe range, are you sure?\n");
  764. input = getch();
  765. if (strncasecmp(&input, "y", 1))
  766. return;
  767. }
  768. if (!set_fanspeed(gpu, val))
  769. wlogprint("Driver reports success but check values below\n");
  770. else
  771. wlogprint("Failed to modify fan speed\n");
  772. } else if (!strncasecmp(&input, "m", 1)) {
  773. get_memoryrange(gpu, &imin, &imax);
  774. wlogprint("Enter GPU memory clock speed (%d - %d Mhz)", imin, imax);
  775. val = curses_int("");
  776. if (val < imin || val > imax) {
  777. wlogprint("Value is outside safe range, are you sure?\n");
  778. input = getch();
  779. if (strncasecmp(&input, "y", 1))
  780. return;
  781. }
  782. if (!set_memoryclock(gpu, val))
  783. wlogprint("Driver reports success but check values below\n");
  784. else
  785. wlogprint("Failed to modify memory clock speed\n");
  786. } else if (!strncasecmp(&input, "v", 1)) {
  787. get_vddcrange(gpu, &fmin, &fmax);
  788. wlogprint("Enter GPU voltage (%.3f - %.3f V)", fmin, fmax);
  789. fval = curses_float("");
  790. if (fval < fmin || fval > fmax) {
  791. wlogprint("Value is outside safe range, are you sure?\n");
  792. input = getch();
  793. if (strncasecmp(&input, "y", 1))
  794. return;
  795. }
  796. if (!set_vddc(gpu, fval))
  797. wlogprint("Driver reports success but check values below\n");
  798. else
  799. wlogprint("Failed to modify voltage\n");
  800. } else if (!strncasecmp(&input, "p", 1)) {
  801. val = curses_int("Enter powertune value (-20 - 20)");
  802. if (val < -20 || val > 20) {
  803. wlogprint("Value is outside safe range, are you sure?\n");
  804. input = getch();
  805. if (strncasecmp(&input, "y", 1))
  806. return;
  807. }
  808. if (!set_powertune(gpu, val))
  809. wlogprint("Driver reports success but check values below\n");
  810. else
  811. wlogprint("Failed to modify powertune value\n");
  812. } else
  813. return;
  814. sleep(1);
  815. goto updated;
  816. }
  817. void clear_adl(nDevs)
  818. {
  819. struct gpu_adl *ga;
  820. int i;
  821. if (!adl_active)
  822. return;
  823. /* Try to reset values to their defaults */
  824. for (i = 0; i < nDevs; i++) {
  825. ga = &gpus[i].adl;
  826. if (!gpus[i].has_adl)
  827. continue;
  828. ADL_Overdrive5_ODPerformanceLevels_Set(ga->iAdapterIndex, ga->DefPerfLev);
  829. free(ga->DefPerfLev);
  830. ADL_Overdrive5_FanSpeed_Set(ga->iAdapterIndex, 0, &ga->DefFanSpeedValue);
  831. }
  832. ADL_Main_Memory_Free ( (void **)&lpInfo );
  833. ADL_Main_Control_Destroy ();
  834. #if defined (LINUX)
  835. dlclose(hDLL);
  836. #else
  837. FreeLibrary(hDLL);
  838. #endif
  839. }
  840. #endif /* HAVE_ADL */