+ ADLOD6PowerControlInfo powertune = {0, 0, 0, 0, 0};
+
+ if ((ADL_rc = hm_ADL_Overdrive_PowerControlInfo_Get (data.hm_adl, data.hm_device[device_id].adl, &powertune)) == ADL_OK)
+ {
+ ADL_rc = hm_ADL_Overdrive_PowerControl_Get (data.hm_adl, data.hm_device[device_id].adl, &od_power_control_status[device_id]);
+ }
+
+ if (ADL_rc != ADL_OK)
+ {
+ log_error ("ERROR: Failed to get current ADL PowerControl settings");
+
+ return (-1);
+ }
+
+ if ((ADL_rc = hm_ADL_Overdrive_PowerControl_Set (data.hm_adl, data.hm_device[device_id].adl, powertune.iMaxValue)) != ADL_OK)
+ {
+ log_error ("ERROR: Failed to set new ADL PowerControl values");
+
+ return (-1);
+ }
+
+ // clocks
+
+ memset (&od_clock_mem_status[device_id], 0, sizeof (ADLOD6MemClockState));
+
+ od_clock_mem_status[device_id].state.iNumberOfPerformanceLevels = 2;
+
+ if ((ADL_rc = hm_ADL_Overdrive_StateInfo_Get (data.hm_adl, data.hm_device[device_id].adl, ADL_OD6_GETSTATEINFO_CUSTOM_PERFORMANCE, &od_clock_mem_status[device_id])) != ADL_OK)
+ {
+ log_error ("ERROR: Failed to get ADL memory and engine clock frequency");
+
+ return (-1);
+ }
+
+ // Query capabilities only to see if profiles were not "damaged", if so output a warning but do accept the users profile settings
+
+ ADLOD6Capabilities caps = {0, 0, 0, {0, 0, 0}, {0, 0, 0}, 0, 0};
+
+ if ((ADL_rc = hm_ADL_Overdrive_Capabilities_Get (data.hm_adl, data.hm_device[device_id].adl, &caps)) != ADL_OK)
+ {
+ log_error ("ERROR: Failed to get ADL device capabilities");
+
+ return (-1);
+ }
+
+ int engine_clock_max = caps.sEngineClockRange.iMax * 0.6666;
+ int memory_clock_max = caps.sMemoryClockRange.iMax * 0.6250;
+
+ int warning_trigger_engine = (int) (0.25 * (float) engine_clock_max);
+ int warning_trigger_memory = (int) (0.25 * (float) memory_clock_max);
+
+ int engine_clock_profile_max = od_clock_mem_status[device_id].state.aLevels[1].iEngineClock;
+ int memory_clock_profile_max = od_clock_mem_status[device_id].state.aLevels[1].iMemoryClock;
+
+ // warning if profile has too low max values
+
+ if ((engine_clock_max - engine_clock_profile_max) > warning_trigger_engine)
+ {
+ log_info ("WARN: the custom profile seems to have too low maximum engine clock values. You therefore may not reach full performance");
+ }
+
+ if ((memory_clock_max - memory_clock_profile_max) > warning_trigger_memory)
+ {
+ log_info ("WARN: the custom profile seems to have too low maximum memory clock values. You therefore may not reach full performance");
+ }
+
+ ADLOD6StateInfo *performance_state = (ADLOD6StateInfo*) mycalloc (1, sizeof (ADLOD6StateInfo) + sizeof (ADLOD6PerformanceLevel));
+
+ performance_state->iNumberOfPerformanceLevels = 2;
+
+ performance_state->aLevels[0].iEngineClock = engine_clock_profile_max;
+ performance_state->aLevels[1].iEngineClock = engine_clock_profile_max;
+ performance_state->aLevels[0].iMemoryClock = memory_clock_profile_max;
+ performance_state->aLevels[1].iMemoryClock = memory_clock_profile_max;
+
+ if ((ADL_rc = hm_ADL_Overdrive_State_Set (data.hm_adl, data.hm_device[device_id].adl, ADL_OD6_SETSTATE_PERFORMANCE, performance_state)) != ADL_OK)
+ {
+ log_info ("ERROR: Failed to set ADL performance state");
+
+ return (-1);
+ }
+
+ local_free (performance_state);
+ }
+
+ // set powertune value only
+
+ if (powertune_supported != 0)
+ {
+ // powertune set
+ ADLOD6PowerControlInfo powertune = {0, 0, 0, 0, 0};
+
+ if ((ADL_rc = hm_ADL_Overdrive_PowerControlInfo_Get (data.hm_adl, data.hm_device[device_id].adl, &powertune)) != ADL_OK)
+ {
+ log_error ("ERROR: Failed to get current ADL PowerControl settings");
+
+ return (-1);
+ }
+
+ if ((ADL_rc = hm_ADL_Overdrive_PowerControl_Set (data.hm_adl, data.hm_device[device_id].adl, powertune.iMaxValue)) != ADL_OK)
+ {
+ log_error ("ERROR: Failed to set new ADL PowerControl values");
+
+ return (-1);
+ }
+ }
+ }
+ }
+
+ if (data.devices_param[device_id].device_vendor_id == VENDOR_ID_NV)
+ {
+ // first backup current value, we will restore it later
+
+ unsigned int limit;
+
+ int powertune_supported = 0;
+
+ if (hm_NVML_nvmlDeviceGetPowerManagementLimit (data.hm_nvml, 0, data.hm_device[device_id].nvml, &limit) == NVML_SUCCESS)
+ {
+ powertune_supported = 1;
+ }
+
+ // if backup worked, activate the maximum allowed
+
+ if (powertune_supported != 0)
+ {
+ unsigned int minLimit;
+ unsigned int maxLimit;
+
+ if (hm_NVML_nvmlDeviceGetPowerManagementLimitConstraints (data.hm_nvml, 0, data.hm_device[device_id].nvml, &minLimit, &maxLimit) == NVML_SUCCESS)
+ {
+ if (maxLimit > 0)
+ {
+ if (hm_NVML_nvmlDeviceSetPowerManagementLimit (data.hm_nvml, 0, data.hm_device[device_id].nvml, maxLimit) == NVML_SUCCESS)
+ {
+ // now we can be sure we need to reset later
+
+ nvml_power_limit[device_id] = limit;
+ }
+ }