nearly complete sysfs hw-mangement, cleanup

This commit is contained in:
Philipp Otterbein committed 2017-01-17 13:25:44 +01:00
1 parent 934d23aba4
commit 19c9715ec2
9 files changed
+705 -426

No files matched your search

+15 -17
View File
@@ -18,7 +18,7 @@
#include "miner.h"
bool adl_active;
bool adl_active = false;
#if defined(HAVE_ADL) && (defined(__unix__) || defined (WIN32))
@@ -123,8 +123,6 @@ static ADL_OVERDRIVE6_POWERCONTROL_SET ADL_Overdrive6_PowerControl_Set;
static int iNumberAdapters;
static LPAdapterInfo lpInfo = NULL;
int adl_set_fanspeed(int gpu, float iFanSpeed);
static float __gpu_temp(struct gpu_adl *ga);
char *adl_error_desc(int error)
{
@@ -1457,20 +1455,20 @@ void init_adl(int nDevs)
}
}
gpu_temp = &adl_gpu_temp;
gpu_engineclock = &adl_gpu_engineclock;
gpu_memclock = &adl_gpu_memclock;
gpu_vddc = &adl_gpu_vddc;
gpu_activity = &adl_gpu_activity;
gpu_fanspeed = &adl_gpu_fanspeed;
gpu_fanpercent = &adl_gpu_fanpercent;
gpu_autotune = &adl_gpu_autotune;
set_powertune = &adl_set_powertune;
set_vddc = &adl_set_vddc;
set_engineclock = &adl_set_engineclock;
set_memoryclock = &adl_set_memoryclock;
set_fanspeed = &adl_set_fanspeed;
gpu_stats = &adl_gpu_stats;
gpu_temp = &adl_gpu_temp;
gpu_engineclock = &adl_gpu_engineclock;
gpu_memclock = &adl_gpu_memclock;
gpu_vddc = &adl_gpu_vddc;
gpu_activity = &adl_gpu_activity;
gpu_fanspeed = &adl_gpu_fanspeed;
gpu_fanpercent = &adl_gpu_fanpercent;
gpu_autotune = &adl_gpu_autotune;
set_powertune = &adl_set_powertune;
set_vddc = &adl_set_vddc;
set_engineclock = &adl_set_engineclock;
set_memoryclock = &adl_set_memoryclock;
set_fanspeed = &adl_set_fanspeed;
gpu_stats = &adl_gpu_stats;
}
void change_gpusettings(int gpu)
-11
View File
@@ -10,18 +10,7 @@ extern int opt_overheattemp;
#ifdef HAVE_ADL
void init_adl(int nDevs);
float adl_gpu_temp(int gpu);
int adl_gpu_engineclock(int gpu);
int adl_gpu_memclock(int gpu);
float adl_gpu_vddc(int gpu);
int adl_gpu_activity(int gpu);
int adl_gpu_fanspeed(int gpu);
float adl_gpu_fanpercent(int gpu);
int adl_set_powertune(int gpu, int iPercentage);
bool adl_gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc,
int *activity, int *fanspeed, int *fanpercent, int *powertune);
void change_gpusettings(int gpu);
void adl_gpu_autotune(int gpu, enum dev_enable *denable);
void clear_adl(int nDevs);
#else /* HAVE_ADL */
+21 -20
View File
@@ -1516,30 +1516,31 @@ static json_t *build_profile_settings_json(json_t *object, struct profile *profi
if (!build_profile_json_add(object, "worksize", profile->worksize, default_profile.worksize, isdefault, parentkey, profile->profile_no))
return NULL;
// gpu_engine
if (!build_profile_json_add(object, "gpu-engine", profile->gpu_engine, default_profile.gpu_engine, isdefault, parentkey, profile->profile_no))
return NULL;
// gpu_memclock
if (!build_profile_json_add(object, "gpu-memclock", profile->gpu_memclock, default_profile.gpu_memclock, isdefault, parentkey, profile->profile_no))
return NULL;
// gpu_fan
if (!build_profile_json_add(object, "gpu-fan", profile->gpu_fan, default_profile.gpu_fan, isdefault, parentkey, profile->profile_no))
return NULL;
// gpu-powertune
if (!build_profile_json_add(object, "gpu-powertune", profile->gpu_powertune, default_profile.gpu_powertune, isdefault, parentkey, profile->profile_no))
return NULL;
// gpu-vddc
if (!build_profile_json_add(object, "gpu-vddc", profile->gpu_vddc, default_profile.gpu_vddc, isdefault, parentkey, profile->profile_no))
return NULL;
#ifdef HAVE_ADL
// gpu_engine
if (!build_profile_json_add(object, "gpu-engine", profile->gpu_engine, default_profile.gpu_engine, isdefault, parentkey, profile->profile_no))
return NULL;
// gpu_memclock
if (!build_profile_json_add(object, "gpu-memclock", profile->gpu_memclock, default_profile.gpu_memclock, isdefault, parentkey, profile->profile_no))
return NULL;
// gpu_threads
if (!build_profile_json_add(object, "gpu-threads", profile->gpu_threads, default_profile.gpu_threads, isdefault, parentkey, profile->profile_no))
return NULL;
// gpu_fan
if (!build_profile_json_add(object, "gpu-fan", profile->gpu_fan, default_profile.gpu_fan, isdefault, parentkey, profile->profile_no))
return NULL;
// gpu-powertune
if (!build_profile_json_add(object, "gpu-powertune", profile->gpu_powertune, default_profile.gpu_powertune, isdefault, parentkey, profile->profile_no))
return NULL;
// gpu-vddc
if (!build_profile_json_add(object, "gpu-vddc", profile->gpu_vddc, default_profile.gpu_vddc, isdefault, parentkey, profile->profile_no))
return NULL;
#endif
return object;
+9 -9
View File
@@ -421,14 +421,14 @@ char *set_gpu_powertune(char *arg)
if (nextptr == NULL)
return "Invalid parameters for set gpu powertune";
val = atoi(nextptr);
if (val < -99 || val > 99)
if (val < -99 || val > 499)
return "Invalid value passed to set_gpu_powertune";
gpus[device++].gpu_powertune = val;
while ((nextptr = strtok(NULL, ",")) != NULL) {
val = atoi(nextptr);
if (val < -99 || val > 99)
if (val < -99 || val > 499)
return "Invalid value passed to set_gpu_powertune";
gpus[device++].gpu_powertune = val;
@@ -484,7 +484,7 @@ char *set_temp_overheat(char *arg)
return "Invalid value passed to set temp overheat";
gpus[device].adl.overtemp = val;
gpus[device++].sysfs_info.OverHeatTemp = val;
gpus[device++].sysfs_info.overheat_temp = val;
while ((nextptr = strtok(NULL, ",")) != NULL) {
val = atoi(nextptr);
@@ -492,12 +492,12 @@ char *set_temp_overheat(char *arg)
return "Invalid value passed to set temp overheat";
gpus[device].adl.overtemp = val;
gpus[device++].sysfs_info.OverHeatTemp = val;
gpus[device++].sysfs_info.overheat_temp = val;
}
if (device == 1) {
for (i = device; i < MAX_GPUDEVICES; i++) {
gpus[i].adl.overtemp = val;
gpus[i].sysfs_info.OverHeatTemp = val;
gpus[i].sysfs_info.overheat_temp = val;
}
}
@@ -518,7 +518,7 @@ char *set_temp_target(char *arg)
tt = &gpus[device].adl.targettemp;
*tt = val;
tt = &gpus[device++].sysfs_info.TargetTemp;
tt = &gpus[device++].sysfs_info.target_temp;
*tt = val;
while ((nextptr = strtok(NULL, ",")) != NULL) {
@@ -528,14 +528,14 @@ char *set_temp_target(char *arg)
tt = &gpus[device].adl.targettemp;
*tt = val;
tt = &gpus[device++].sysfs_info.TargetTemp;
tt = &gpus[device++].sysfs_info.target_temp;
*tt = val;
}
if (device == 1) {
for (i = device; i < MAX_GPUDEVICES; i++) {
tt = &gpus[i].adl.targettemp;
*tt = val;
tt = &gpus[i].sysfs_info.TargetTemp;
tt = &gpus[i].sysfs_info.target_temp;
*tt = val;
}
}
@@ -1668,7 +1668,7 @@ struct device_drv opencl_drv = {
/*.name = */ "GPU",
/*.drv_detect = */ opencl_detect,
/*.reinit_device = */ reinit_opencl_device,
#ifdef HAVE_ADL
#if (defined HAVE_ADL) || (defined __linux__)
/*.get_statline_before = */ get_opencl_statline_before,
#else
NULL,
+23 -8
View File
@@ -528,14 +528,29 @@ struct sgminer_pool_stats {
};
typedef struct _gpu_sysfs_info {
char *HWMonPath;
uint32_t MinFanSpeed;
uint32_t MaxFanSpeed;
uint32_t OverHeatTemp;
uint32_t TargetTemp;
float TgtFanSpeed;
float LastFanSpeed;
float LastTemp;
pthread_mutex_t rw_lock;
uint8_t *pptable;
uint8_t *default_pptable;
size_t pptable_size;
uint32_t min_fanspeed;
uint32_t max_fanspeed;
uint32_t overheat_temp;
uint32_t target_temp;
uint32_t ctr;
uint32_t last_ctr;
float target_fanpercent;
float last_temp;
int sclk_entry_size;
int sclk_ind;
int engineclock;
int memclock;
int fd_temp;
int fd_fan;
int fd_pptable;
int fd_mclk;
int fd_sclk;
int fd_pwm;
uint8_t pcie_index[3];
} gpu_sysfs_info;
struct _eth_dag_t;
+50 -29
View File
@@ -136,6 +136,27 @@ int clDevicesNum(void) {
for (j = 0; j < numDevices; j++) {
clGetDeviceInfo(devices[j], CL_DEVICE_NAME, sizeof(pbuff), pbuff, NULL);
applog(LOG_INFO, "\t%i\t%s", j, pbuff);
#ifndef CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD
#define CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD 1
#define CL_DEVICE_TOPOLOGY_AMD 0x4037
typedef union
{
struct { cl_uint type; cl_uint data[5]; } raw;
struct { cl_uint type; cl_char unused[17]; cl_char bus; cl_char device; cl_char function; } pcie;
} cl_device_topology_amd;
#endif
cl_device_topology_amd topology;
status = clGetDeviceInfo (devices[j], CL_DEVICE_TOPOLOGY_AMD, sizeof(cl_device_topology_amd), &topology, NULL);
memset(gpus[j].sysfs_info.pcie_index, 0xff, sizeof(gpus[j].sysfs_info.pcie_index));
if (status == CL_SUCCESS && topology.raw.type == CL_DEVICE_TOPOLOGY_TYPE_PCIE_AMD) {
uint8_t *pcie_index = gpus[j].sysfs_info.pcie_index;
pcie_index[0] = topology.pcie.bus;
pcie_index[1] = topology.pcie.device;
pcie_index[2] = topology.pcie.function;
applog(LOG_DEBUG, "GPU%d: detected PCIe topology 0000:%.2x:%.2x.%.1x", j, pcie_index[0], pcie_index[1], pcie_index[2]);
}
}
free(devices);
}
@@ -254,7 +275,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize, algorithm_t *alg
applog(LOG_INFO, "List of devices:");
for (int i = 0; i < numDevices; ++i) {
for (int i = 0; i < numDevices; ++i) {
size_t tmpsize;
if (clGetDeviceInfo(devices[i], CL_DEVICE_NAME, 0, NULL, &tmpsize) != CL_SUCCESS) {
applog(LOG_ERR, "Error while getting the length of the name for GPU #%d.", i);
@@ -265,13 +286,13 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize, algorithm_t *alg
pbuff[i] = (char *)alloca(sizeof(char) * (tmpsize + 1));
if (clGetDeviceInfo(devices[i], CL_DEVICE_NAME, sizeof(char) * tmpsize, pbuff[i], NULL) != CL_SUCCESS) {
applog(LOG_ERR, "Error while attempting to get device information.");
return NULL;
return NULL;
}
applog(LOG_INFO, "\t%i\t%s", i, pbuff[i]);
}
}
applog(LOG_INFO, "Selected %d: %s", gpu, pbuff[gpu]);
applog(LOG_INFO, "Selected %d: %s", gpu, pbuff[gpu]);
strncpy(name, pbuff[gpu], nameSize);
status = create_opencl_context(&clState->context, &platform);
@@ -309,8 +330,8 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize, algorithm_t *alg
// Source: http://www.amd.com/us/Documents/GCN_Architecture_whitepaper.pdf
clState->compute_shaders = compute_units << 6;
applog(LOG_INFO, "Maximum work size for this GPU (%d) is %d.", gpu, clState->max_work_size);
applog(LOG_INFO, "Your GPU (#%d) has %d compute units, and all AMD cards in the 7 series or newer (GCN cards) \
have 64 shaders per compute unit - this means it has %d shaders.", gpu, compute_units, clState->compute_shaders);
applog(LOG_INFO, "Your GPU (#%d) has %d compute units, and all AMD cards in the 7 series or newer (GCN cards) \
have 64 shaders per compute unit - this means it has %d shaders.", gpu, compute_units, clState->compute_shaders);
status = clGetDeviceInfo(devices[gpu], CL_DEVICE_MAX_MEM_ALLOC_SIZE, sizeof(cl_ulong), (void *)&cgpu->max_alloc, NULL);
if (status != CL_SUCCESS) {
@@ -728,16 +749,16 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize, algorithm_t *alg
// Build information
strcpy(build_data->source_filename, filename);
strcpy(build_data->platform, name);
strcpy(build_data->sgminer_path, sgminer_path);
strcpy(build_data->platform, name);
strcpy(build_data->sgminer_path, sgminer_path);
build_data->kernel_path = (*opt_kernel_path) ? opt_kernel_path : NULL;
build_data->work_size = clState->wsize;
build_data->opencl_version = get_opencl_version(devices[gpu]);
strcpy(build_data->binary_filename, filename);
build_data->binary_filename[strlen(filename) - 3] = 0x00; // And one NULL terminator, cutting off the .cl suffix.
strcat(build_data->binary_filename, pbuff[gpu]);
build_data->binary_filename[strlen(filename) - 3] = 0x00; // And one NULL terminator, cutting off the .cl suffix.
strcat(build_data->binary_filename, pbuff[gpu]);
if (clState->goffset) {
strcat(build_data->binary_filename, "g");
@@ -783,7 +804,7 @@ _clState *initCl(unsigned int gpu, char *name, size_t nameSize, algorithm_t *alg
for (int i = 0; i < clState->n_extra_kernels; i++) {
clState->extra_kernels[i] = clCreateKernel(clState->program, kernel_names[i], &status);
if (status != CL_SUCCESS) {
applog(LOG_ERR, "Error %d: Creating Kernel \"%s\" from program. (clCreateKernel)", status, kernel_names[i]);
applog(LOG_ERR, "Error %d: Creating Kernel \"%s\" from program. (clCreateKernel)", status, kernel_names[i]);
return NULL;
}
}
@@ -959,7 +980,7 @@ out:
* 2 greater >= required amount earlier */
if (bufsize > cgpu->max_alloc) {
applog(LOG_WARNING, "Maximum buffer memory device %d supports says %lu",
gpu, (unsigned long)(cgpu->max_alloc));
gpu, (unsigned long)(cgpu->max_alloc));
applog(LOG_WARNING, "Your settings come to %lu", (unsigned long)bufsize);
}
@@ -967,35 +988,35 @@ out:
// need additionnal buffers
clState->buffer1 = clCreateBuffer(clState->context, CL_MEM_READ_WRITE, buf1size, NULL, &status);
if (status != CL_SUCCESS && !clState->buffer1) {
applog(LOG_DEBUG, "Error %d: clCreateBuffer (buffer1), decrease TC or increase LG", status);
return NULL;
applog(LOG_DEBUG, "Error %d: clCreateBuffer (buffer1), decrease TC or increase LG", status);
return NULL;
}
clState->buffer2 = clCreateBuffer(clState->context, CL_MEM_READ_WRITE, buf2size, NULL, &status);
if (status != CL_SUCCESS && !clState->buffer2) {
applog(LOG_DEBUG, "Error %d: clCreateBuffer (buffer2), decrease TC or increase LG", status);
return NULL;
applog(LOG_DEBUG, "Error %d: clCreateBuffer (buffer2), decrease TC or increase LG", status);
return NULL;
}
clState->buffer3 = clCreateBuffer(clState->context, CL_MEM_READ_WRITE, buf3size, NULL, &status);
if (status != CL_SUCCESS && !clState->buffer3) {
applog(LOG_DEBUG, "Error %d: clCreateBuffer (buffer3), decrease TC or increase LG", status);
return NULL;
applog(LOG_DEBUG, "Error %d: clCreateBuffer (buffer3), decrease TC or increase LG", status);
return NULL;
}
}
else if (algorithm->type == ALGO_LYRA2REV2) {
// need additionnal buffers
clState->buffer1 = clCreateBuffer(clState->context, CL_MEM_READ_WRITE, buf1size, NULL, &status);
if (status != CL_SUCCESS && !clState->buffer1) {
applog(LOG_DEBUG, "Error %d: clCreateBuffer (buffer1), decrease TC or increase LG", status);
return NULL;
applog(LOG_DEBUG, "Error %d: clCreateBuffer (buffer1), decrease TC or increase LG", status);
return NULL;
}
}
else {
clState->buffer1 = clCreateBuffer(clState->context, CL_MEM_READ_WRITE, bufsize, NULL, &status); // we don't need that much just tired...
if (status != CL_SUCCESS && !clState->buffer1) {
applog(LOG_DEBUG, "Error %d: clCreateBuffer (buffer1), decrease TC or increase LG", status);
return NULL;
applog(LOG_DEBUG, "Error %d: clCreateBuffer (buffer1), decrease TC or increase LG", status);
return NULL;
}
}
@@ -1012,27 +1033,27 @@ out:
if (algorithm->type == ALGO_CRYPTONIGHT) {
size_t GlobalThreads;
readbufsize = 76UL;
set_threads_hashes(1, clState->compute_shaders, &GlobalThreads, 1, &cgpu->intensity, &cgpu->xintensity, &cgpu->rawintensity, &cgpu->algorithm);
for (int i = 0; i < 4; ++i) {
clState->BranchBuffer[i] = clCreateBuffer(clState->context, CL_MEM_READ_WRITE, sizeof(cl_uint) * (GlobalThreads + 2), NULL, &status);
if (status != CL_SUCCESS) {
applog(LOG_ERR, "Error %d when creating branch buffer %d.\n", status, i);
return NULL;
}
}
clState->States = clCreateBuffer(clState->context, CL_MEM_READ_WRITE, 200 * GlobalThreads, NULL, &status);
if(status != CL_SUCCESS) {
applog(LOG_ERR, "Error %d when creating Cryptonight state buffer.\n", status);
return NULL;
}
clState->Scratchpads = clCreateBuffer(clState->context, CL_MEM_READ_WRITE, (1 << 21) * GlobalThreads, NULL, &status);
if(status != CL_SUCCESS) {
applog(LOG_ERR, "Error %d when creating Cryptonight scratchpads buffer.\n", status);
return NULL;
+11 -143
View File
@@ -55,6 +55,7 @@ char *curly = ":D";
#include "miner.h"
#include "findnonce.h"
#include "adl.h"
#include "sysfs-gpu-controls.h"
#include "driver-opencl.h"
#include "bench_block.h"
@@ -5506,6 +5507,11 @@ static void hashmeter(int thr_id, struct timeval *diff,
showlog = true;
cgtime(&total_tv_end);
struct timeval runtime;
timersub(&total_tv_end, &launch_time, &runtime);
double runtime_secs = runtime.tv_sec + 1e-6 * runtime.tv_usec;
applog(LOG_DEBUG, "total hashes: %g, total runtime / s: %g", 1e6 * total_mhashes_done, runtime_secs);
local_secs = (double)total_diff.tv_sec + ((double)total_diff.tv_usec / 1000000.0);
decay_time(&total_rolling, local_mhashes_done / local_secs, local_secs);
global_hashrate = ((unsigned long long)lround(total_rolling)) * 1000000;
@@ -7342,141 +7348,6 @@ static void get_work_prepare_thread(struct thr_info *mythr, struct work *work)
//apply switcher options
apply_switcher_options(pool_switch_options, work->pool);
//devices
/*if(opt_isset(pool_switch_options, SWITCHER_APPLY_DEVICE))
{
//reset devices flags
opt_devs_enabled = 0;
for (i = 0; i < MAX_DEVICES; i++)
devices_enabled[i] = false;
//assign pool devices if any
if(!empty_string((opt = get_pool_setting(work->pool->devices, ((!empty_string(default_profile.devices))?default_profile.devices:"all"))))) {
set_devices((char *)opt);
}
}
//lookup gap
if(opt_isset(pool_switch_options, SWITCHER_APPLY_LG))
{
if(!empty_string((opt = get_pool_setting(work->pool->lookup_gap, default_profile.lookup_gap))))
set_lookup_gap((char *)opt);
}
//raw intensity from pool
if(opt_isset(pool_switch_options, SWITCHER_APPLY_RAWINT))
{
applog(LOG_DEBUG, "Switching to rawintensity: pool = %s, default = %s", work->pool->rawintensity, default_profile.rawintensity);
opt = get_pool_setting(work->pool->rawintensity, default_profile.rawintensity);
applog(LOG_DEBUG, "rawintensity -> %s", opt);
set_rawintensity(opt);
}
//xintensity
else if(opt_isset(pool_switch_options, SWITCHER_APPLY_XINT))
{
applog(LOG_DEBUG, "Switching to xintensity: pool = %s, default = %s", work->pool->xintensity, default_profile.xintensity);
opt = get_pool_setting(work->pool->xintensity, default_profile.xintensity);
applog(LOG_DEBUG, "xintensity -> %s", opt);
set_xintensity(opt);
}
//intensity
else if(opt_isset(pool_switch_options, SWITCHER_APPLY_INT))
{
applog(LOG_DEBUG, "Switching to intensity: pool = %s, default = %s", work->pool->intensity, default_profile.intensity);
opt = get_pool_setting(work->pool->intensity, default_profile.intensity);
applog(LOG_DEBUG, "intensity -> %s", opt);
set_intensity(opt);
}
//default basic intensity
else if(opt_isset(pool_switch_options, SWITCHER_APPLY_INT8))
{
default_profile.intensity = strdup("8");
set_intensity(default_profile.intensity);
}
//shaders
if(opt_isset(pool_switch_options, SWITCHER_APPLY_SHADER))
{
if(!empty_string((opt = get_pool_setting(work->pool->shaders, default_profile.shaders))))
set_shaders((char *)opt);
}
//thread-concurrency
if(opt_isset(pool_switch_options, SWITCHER_APPLY_TC))
{
// neoscrypt - if not specified set TC to 0 so that TC will be calculated by intensity settings
if (work->pool->algorithm.type == ALGO_NEOSCRYPT) {
opt = ((empty_string(work->pool->thread_concurrency))?"0":get_pool_setting(work->pool->thread_concurrency, default_profile.thread_concurrency));
}
// otherwise use pool/profile setting or default to default profile setting
else {
opt = get_pool_setting(work->pool->thread_concurrency, default_profile.thread_concurrency);
}
if(!empty_string(opt)) {
set_thread_concurrency((char *)opt);
}
}
//worksize
if(opt_isset(pool_switch_options, SWITCHER_APPLY_WORKSIZE))
{
if(!empty_string((opt = get_pool_setting(work->pool->worksize, default_profile.worksize))))
set_worksize(opt);
}
#ifdef HAVE_ADL
//GPU clock
if(opt_isset(pool_switch_options, SWITCHER_APPLY_GPU_ENGINE))
{
if(!empty_string((opt = get_pool_setting(work->pool->gpu_engine, default_profile.gpu_engine))))
set_gpu_engine((char *)opt);
}
//GPU memory clock
if(opt_isset(pool_switch_options, SWITCHER_APPLY_GPU_MEMCLOCK))
{
if(!empty_string((opt = get_pool_setting(work->pool->gpu_memclock, default_profile.gpu_memclock))))
set_gpu_memclock((char *)opt);
}
//GPU fans
if(opt_isset(pool_switch_options, SWITCHER_APPLY_GPU_FAN))
{
if(!empty_string((opt = get_pool_setting(work->pool->gpu_fan, default_profile.gpu_fan))))
set_gpu_fan((char *)opt);
}
//GPU powertune
if(opt_isset(pool_switch_options, SWITCHER_APPLY_GPU_POWERTUNE))
{
if(!empty_string((opt = get_pool_setting(work->pool->gpu_powertune, default_profile.gpu_powertune))))
set_gpu_powertune((char *)opt);
}
//GPU vddc
if(opt_isset(pool_switch_options, SWITCHER_APPLY_GPU_VDDC))
{
if(!empty_string((opt = get_pool_setting(work->pool->gpu_vddc, default_profile.gpu_vddc))))
set_gpu_vddc((char *)opt);
}
//apply gpu settings
for (i = 0; i < nDevs; i++)
{
if(opt_isset(pool_switch_options, SWITCHER_APPLY_GPU_ENGINE))
set_engineclock(i, gpus[i].min_engine);
if(opt_isset(pool_switch_options, SWITCHER_APPLY_GPU_MEMCLOCK))
set_memoryclock(i, gpus[i].gpu_memclock);
if(opt_isset(pool_switch_options, SWITCHER_APPLY_GPU_FAN))
set_fanspeed(i, gpus[i].min_fan);
if(opt_isset(pool_switch_options, SWITCHER_APPLY_GPU_POWERTUNE))
set_powertune(i, gpus[i].gpu_powertune);
if(opt_isset(pool_switch_options, SWITCHER_APPLY_GPU_VDDC))
set_vddc(i, gpus[i].gpu_vddc);
}
#endif
*/
// Change algorithm for each thread (thread_prepare calls initCl)
if(opt_isset(pool_switch_options, SWITCHER_SOFT_RESET))
applog(LOG_DEBUG, "Soft Reset... Restarting threads...");
@@ -8510,9 +8381,8 @@ static void *watchdog_thread(void __maybe_unused *userdata)
denable = &cgpu->deven;
snprintf(dev_str, sizeof(dev_str), "%s%d", cgpu->drv->name, gpu);
if (adl_active && cgpu->has_adl || cgpu->has_sysfs_hwcontrols)
gpu_autotune(gpu, denable);
if (opt_debug && cgpu->has_adl) {
gpu_autotune(gpu, denable);
if (opt_debug) {
int engineclock = 0, memclock = 0, activity = 0, fanspeed = 0, fanpercent = 0, powertune = 0;
float temp = 0, vddc = 0;
@@ -8539,13 +8409,10 @@ static void *watchdog_thread(void __maybe_unused *userdata)
dev_error(cgpu, REASON_DEV_SICK_IDLE_60);
event_notify("gpu_sick");
#ifdef HAVE_ADL
if (adl_active && cgpu->has_adl && gpu_activity(gpu) > 50) {
if (gpu_activity(gpu) > 50) {
applog(LOG_ERR, "GPU still showing activity suggesting a hard hang.");
applog(LOG_ERR, "Will not attempt to auto-restart it.");
} else
#endif
if (opt_restart) {
} else if (opt_restart) {
applog(LOG_ERR, "%s: Attempting to restart", dev_str);
reinit_device(cgpu);
}
@@ -8679,6 +8546,7 @@ static void clean_up(bool restarting)
#ifdef HAVE_ADL
clear_adl(nDevs);
#endif
sysfs_cleanup(nDevs);
cgtime(&total_tv_end);
#ifdef WIN32
timeEndPeriod(1);
+575 -183
View File
@@ -3,166 +3,499 @@
#include <dirent.h>
#include "miner.h"
#include "pptable_v1_0.h"
#include "sysfs-gpu-controls.h"
bool initialized = false;
bool has_sysfs_hwcontrols = false;
bool opt_reorder = false;
int opt_hysteresis = 3;
int opt_targettemp = 80;
int opt_overheattemp = 90;
int opt_overheattemp = 85;
int sysfs_gpu_engineclock(int gpu) { }
int sysfs_gpu_memclock(int gpu) { }
float sysfs_gpu_vddc(int gpu) { }
int sysfs_gpu_activity(int gpu) { }
int sysfs_gpu_fanspeed(int gpu) { return(-1); }
int sysfs_set_vddc(int gpu, float fVddc) { }
int sysfs_set_engineclock(int gpu, int iEngineClock) { }
int sysfs_set_memoryclock(int gpu, int iMemoryClock) { }
int sysfs_set_powertune(int gpu, int iPercentage) { }
float sysfs_gpu_vddc(int gpu) { return -1; }
int sysfs_gpu_activity(int gpu) { return -1; }
int sysfs_set_vddc(int gpu, float fVddc) { return 1; }
#ifndef __linux__
void GetGPUHWMonPath(char **HWMonPath, uint32_t GPUIdx)
static void sysfs_init(gpu_sysfs_info *info, int gpu_idx)
{
*HWMonPath = NULL;
memset(info, 0, sizeof(gpu_sysfs_info));
info->fd_fan = info->fd_temp = info->fd_pptable = -1;
}
#else
// Must be freed by caller unless NULL
void GetGPUHWMonPath(char **HWMonPath, uint32_t GPUIdx)
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
static void sysfs_init(gpu_sysfs_info *info, int gpu_idx)
{
DIR *hwmon;
char TempPath[256];
char path[256];
struct dirent *inner_hwmon;
// Set it to NULL (indicating failure) until we need to use it
*HWMonPath = NULL;
sprintf(TempPath, "/sys/class/drm/card%d/device/hwmon", GPUIdx);
hwmon = opendir(TempPath);
if(hwmon == NULL)
info->fd_pptable = info->fd_fan = info->fd_temp = info->fd_pwm = -1;
snprintf(path, sizeof(path), "/sys/bus/pci/devices/0000:%.2x:%.2x.%.1x/",
info->pcie_index[0], info->pcie_index[1], info->pcie_index[2]);
size_t len = strlen(path);
snprintf(path + len, sizeof(path) - len, "pp_table");
int fd = open(path, O_RDONLY | O_RSYNC);
bool success = false;
if (fd != -1) {
int size = lseek(fd, 0, SEEK_END);
if (size > 0) {
lseek(fd, 0, SEEK_SET);
info->pptable = (uint8_t*) malloc(size);
info->default_pptable = (uint8_t*) malloc(size);
info->pptable_size = read(fd, info->pptable, size);
memcpy(info->default_pptable, info->pptable, info->pptable_size);
info->fd_pptable = open(path, O_WRONLY | O_DSYNC);
success = (info->fd_pptable != -1 && info->pptable_size > 0);
}
close(fd);
}
if (!success) {
if (info->fd_pptable != -1) {
close(info->fd_pptable);
info->fd_pptable = -1;
}
applog(LOG_DEBUG, "Failed to open/read %s", path);
}
else
pthread_mutex_init(&info->rw_lock, NULL);
snprintf(path + len, sizeof(path) - len, "pp_dpm_sclk");
info->fd_sclk = open(path, O_RDONLY | O_RSYNC);
if (info->fd_sclk == -1)
applog(LOG_DEBUG, "Failed to open %s", path);
snprintf(path + len, sizeof(path) - len, "pp_dpm_mclk");
info->fd_mclk = open(path, O_RDONLY | O_RSYNC);
if (info->fd_mclk == -1)
applog(LOG_DEBUG, "Failed to open %s", path);
snprintf(path + len, sizeof(path) - len, "hwmon");
len += 5;
DIR *hwmon = opendir(path);
if (hwmon == NULL) {
applog(LOG_DEBUG, "Failed to open hwmon directory for GPU%d", gpu_idx);
return;
}
for(;;)
{
while (true) {
inner_hwmon = readdir(hwmon);
if (inner_hwmon == NULL)
if (inner_hwmon == NULL) {
closedir(hwmon);
applog(LOG_DEBUG, "Failed to parse hwmon directory for GPU%d", gpu_idx);
return;
}
if (inner_hwmon->d_type != DT_DIR)
continue;
if (!memcmp(inner_hwmon->d_name, "hwmon", 5))
break;
}
*HWMonPath = (char *)malloc(sizeof(char) * (256 + strlen(inner_hwmon->d_name)));
sprintf(*HWMonPath, "/sys/class/drm/card%d/device/hwmon/%s", GPUIdx, inner_hwmon->d_name);
return;
snprintf(path + len, sizeof(path) - len, "/%s/", inner_hwmon->d_name);
len = strlen(path);
closedir(hwmon);
snprintf(path + len, sizeof(path) - len, "pwm1");
info->fd_fan = open(path, O_RDWR | O_RSYNC | O_DSYNC);
if (info->fd_fan == -1)
applog(LOG_DEBUG, "Failed to open %s", path);
else
pthread_mutex_init(&info->rw_lock, NULL);
char buf[17] = {0};
snprintf(path + len, sizeof(path) - len, "pwm1_min");
fd = open(path, O_RDONLY | O_RSYNC);
info->min_fanspeed = 0;
if (fd != -1) {
int bytes_read = read(fd, &buf, sizeof(buf) - 1);
if (bytes_read > 0)
info->min_fanspeed = strtoul(buf, NULL, 10);
else
applog(LOG_DEBUG, "Failed to read %s", path);
close(fd);
}
else
applog(LOG_DEBUG, "Failed to open %s", path);
snprintf(path + len, sizeof(path) - len, "pwm1_max");
fd = open(path, O_RDONLY | O_RSYNC);
info->max_fanspeed = 255;
if (fd != -1) {
int bytes_read = read(fd, &buf, sizeof(buf) - 1);
if (bytes_read > 0) {
buf[bytes_read] = '\0';
info->max_fanspeed = strtoul(buf, NULL, 10);
}
else
applog(LOG_DEBUG, "Failed to read %s", path);
close(fd);
}
else
applog(LOG_DEBUG, "Failed to open %s", path);
snprintf(path + len, sizeof(path) - len, "temp1_input");
info->fd_temp = open(path, O_RDONLY | O_RSYNC);
if (info->fd_temp == -1)
applog(LOG_DEBUG, "Failed to open %s", path);
snprintf(path + len, sizeof(path) - len, "fan1_input");
info->fd_pwm = open(path, O_RDONLY | O_RSYNC);
if (info->fd_pwm == -1)
applog(LOG_DEBUG, "Failed to open %s", path);
}
#endif
int ReadSysFSFile(uint8_t *Buffer, char *Filename, uint32_t BufSize)
static int parse_dpm_clk_table(int fd)
{
FILE *fd;
int BytesRead;
fd = fopen(Filename, "rb");
if(!fd)
return -1;
BytesRead = fread(Buffer, sizeof(uint8_t), BufSize, fd);
fclose(fd);
return BytesRead;
char buf[1024];
int ret = -1;
#ifdef __linux__
if (has_sysfs_hwcontrols && fd != -1) {
lseek(fd, 0, SEEK_SET);
size_t len = read(fd, buf, sizeof(buf) - 1);
if (len > 0) {
buf[len] = '\0';
char *ptr = strtok(buf, "\n");
while (ptr != NULL) {
int index;
int freq;
char active_str[3] = {0};
sscanf(ptr, "%d: %dMhz%s", &index, &freq, active_str);
if (active_str[0] == '*' || active_str[1] == '*') {
ret = freq;
break;
}
ptr = strtok(NULL, "\n");
}
}
}
#endif
return ret;
}
int WriteSysFSFile(uint8_t *Buffer, char *Filename, uint32_t BufSize)
int sysfs_gpu_engineclock(int gpu)
{
FILE *fd;
int BytesWritten;
fd = fopen(Filename, "wb");
if(!fd)
return -1;
BytesWritten = fwrite(Buffer, sizeof(uint8_t), BufSize, fd);
fclose(fd);
return BytesWritten;
return parse_dpm_clk_table(gpus[gpu].sysfs_info.fd_sclk);
}
int sysfs_gpu_memclock(int gpu)
{
return parse_dpm_clk_table(gpus[gpu].sysfs_info.fd_mclk);
}
float sysfs_gpu_temp(int gpu)
{
char TempFileName[513];
char TempBuf[33];
int BytesRead;
snprintf(TempFileName, 512, "%s/temp1_input", gpus[gpu].sysfs_info.HWMonPath);
BytesRead = ReadSysFSFile(TempBuf, TempFileName, 32);
if (BytesRead <= 0)
return 0.f;
TempBuf[BytesRead] = 0x00;
return strtof(TempBuf, NULL) / 1000.f;
gpu_sysfs_info *info = &gpus[gpu].sysfs_info;
char temp_str[17];
float ret = -1.f;
#ifdef __linux__
if (has_sysfs_hwcontrols && info->fd_temp != -1) {
lseek(info->fd_temp, 0, SEEK_SET);
int bytes_read = read(info->fd_temp, &temp_str, sizeof(temp_str) - 1);
if (bytes_read > 0) {
temp_str[bytes_read] = '\0';
ret = strtol(temp_str, NULL, 10) / 1000.f;
}
}
#endif
return ret;
}
int fanpercent_to_speed(int gpu, float percent)
static int fanpercent_to_speed(gpu_sysfs_info *info, float fanpercent)
{
int min = gpus[gpu].sysfs_info.MinFanSpeed;
int max = gpus[gpu].sysfs_info.MaxFanSpeed;
int min = info->min_fanspeed;
int max = info->max_fanspeed;
float range = max - min;
float res = percent / 100.f * range + min + 0.5f;
return res;
float speed = fanpercent / 100.f * range + min + 0.5f;
return speed;
}
float fanspeed_to_percent(int gpu, int speed)
static float fanspeed_to_percent(gpu_sysfs_info *info, int speed)
{
int min = gpus[gpu].sysfs_info.MinFanSpeed;
int max = gpus[gpu].sysfs_info.MaxFanSpeed;
int min = info->min_fanspeed;
int max = info->max_fanspeed;
float range = max - min;
float res = (speed - min) / range * 100.f;
return res;
float fanpercent = (speed - min) / range * 100.f;
return fanpercent;
}
int sysfs_gpu_fanspeed(int gpu)
{
gpu_sysfs_info *info = &gpus[gpu].sysfs_info;
char speed_str[17];
int ret = -1;
#ifdef __linux__
if (has_sysfs_hwcontrols && info->fd_pwm != -1) {
lseek(info->fd_pwm, 0, SEEK_SET);
int bytes_read = read(info->fd_pwm, speed_str, sizeof(speed_str) - 1);
if (bytes_read > 0) {
speed_str[bytes_read] = '\0';
ret = strtoul(speed_str, NULL, 10);
}
}
#endif
return ret;
}
float sysfs_gpu_fanpercent(int gpu)
{
char PWM1FileName[513], SpeedStr[33];
int BytesRead, Speed;
snprintf(PWM1FileName, 512, "%s/pwm1", gpus[gpu].sysfs_info.HWMonPath);
BytesRead = ReadSysFSFile(SpeedStr, PWM1FileName, 32);
if(BytesRead <= 0)
return -1;
SpeedStr[BytesRead] = 0x00;
Speed = strtoul(SpeedStr, NULL, 10);
return fanspeed_to_percent(gpu, Speed);
gpu_sysfs_info *info = &gpus[gpu].sysfs_info;
char speed_str[17];
float ret = -1.f;
#ifdef __linux__
if (has_sysfs_hwcontrols && info->fd_fan != -1) {
pthread_mutex_lock(&info->rw_lock);
lseek(info->fd_fan, 0, SEEK_SET);
int bytes_read = read(info->fd_fan, speed_str, sizeof(speed_str) - 1);
pthread_mutex_unlock(&info->rw_lock);
if (bytes_read > 0) {
speed_str[bytes_read] = '\0';
unsigned long speed = strtoul(speed_str, NULL, 10);
ret = fanspeed_to_percent(info, speed);
}
}
#endif
return ret;
}
int sysfs_set_fanspeed(int gpu, float FanSpeed)
static int __set_fanspeed(gpu_sysfs_info *info, float fanpercent)
{
char PWM1FileName[513], Setting[33];
int speed = fanpercent_to_speed(gpu, FanSpeed);
char speed_str[17];
int speed = fanpercent_to_speed(info, fanpercent);
int ret = 1;
snprintf(speed_str, sizeof(speed_str), "%d", speed);
#ifdef __linux__
if (info->fd_fan != -1) {
pthread_mutex_lock(&info->rw_lock);
lseek(info->fd_fan, 0, SEEK_SET);
ret = (write(info->fd_fan, speed_str, strlen(speed_str)) <= 0);
pthread_mutex_unlock(&info->rw_lock);
if (!ret)
info->target_fanpercent = fanpercent;
}
#endif
return ret;
}
int sysfs_set_fanspeed(int gpu, float fanpercent)
{
int ret = 1;
if (has_sysfs_hwcontrols && gpus[gpu].has_sysfs_hwcontrols) {
gpu_sysfs_info *info = &gpus[gpu].sysfs_info;
applog(LOG_DEBUG, "GPU%d: set fanpercent to %.3g%%", gpu, fanpercent);
ret = __set_fanspeed(info, fanpercent);
}
return ret;
}
static Tonga_State_Array *get_state_array(uint8_t *pptable)
{
Tonga_POWERPLAYTABLE *header = (Tonga_POWERPLAYTABLE*) pptable;
return (Tonga_State_Array*) (pptable + header->usStateArrayOffset);
}
static Tonga_MCLK_Dependency_Table *get_mclk_table(uint8_t *pptable)
{
Tonga_POWERPLAYTABLE *header = (Tonga_POWERPLAYTABLE*) pptable;
return (Tonga_MCLK_Dependency_Table*) (pptable + header->usMclkDependencyTableOffset);
}
static Tonga_SCLK_Dependency_Table *get_sclk_table(uint8_t *pptable)
{
Tonga_POWERPLAYTABLE *header = (Tonga_POWERPLAYTABLE*) pptable;
return (Tonga_SCLK_Dependency_Table*) (pptable + header->usSclkDependencyTableOffset);
}
static Tonga_SCLK_Dependency_Record *get_sclk_record(Tonga_SCLK_Dependency_Table *sclk_tbl, int idx)
{
Tonga_SCLK_Dependency_Record *record = NULL;
if (/*idx < sclk_tbl->ucNumEntries &&*/ sclk_tbl->ucRevId <= 1) {
int entry_size = (sclk_tbl->ucRevId == 0 ? sizeof(Tonga_SCLK_Dependency_Record) : sizeof(Polaris_SCLK_Dependency_Record));
record = (Tonga_SCLK_Dependency_Record*) ((uint8_t*) sclk_tbl->entries + idx * entry_size);
}
return record;
}
static int __apply_pptable(gpu_sysfs_info *info)
{
#ifdef __linux__
lseek(info->fd_pptable, 0, SEEK_SET);
int bytes_written = write(info->fd_pptable, info->pptable, info->pptable_size);
if (opt_autofan && info->target_fanpercent >= 0)
__set_fanspeed(info, info->target_fanpercent); // restore fan settings
return (bytes_written != info->pptable_size);
#else
return 0;
#endif
}
int sysfs_set_powertune(int gpu, int power_limit)
{
gpu_sysfs_info *info = &gpus[gpu].sysfs_info;
int ret = 1;
if (has_sysfs_hwcontrols && power_limit > 0 && info->fd_pptable != -1) {
applog(LOG_DEBUG, "GPU%d: set power limit to %dW", gpu, power_limit);
pthread_mutex_lock(&info->rw_lock);
Tonga_POWERPLAYTABLE *header = (Tonga_POWERPLAYTABLE*) info->pptable;
Tonga_PowerTune_Table *power_tbl = (Tonga_PowerTune_Table*) (info->pptable + header->usPowerTuneTableOffset);
Tonga_PowerTune_Table *default_power_tbl = (Tonga_PowerTune_Table*) (info->default_pptable + header->usPowerTuneTableOffset);
power_tbl->usTDC = (float) default_power_tbl->usTDC * power_limit / default_power_tbl->usMaximumPowerDeliveryLimit;
power_tbl->usMaximumPowerDeliveryLimit = power_limit;
ret = __apply_pptable(info);
pthread_mutex_unlock(&info->rw_lock);
}
return ret;
}
static int gpu_powertune(int gpu)
{
int ret = 0;
gpu_sysfs_info *info = &gpus[gpu].sysfs_info;
if (has_sysfs_hwcontrols && info->fd_pptable != -1) {
Tonga_POWERPLAYTABLE *header = (Tonga_POWERPLAYTABLE*) info->pptable;
Tonga_PowerTune_Table *power_tbl = (Tonga_PowerTune_Table*) (info->pptable + header->usPowerTuneTableOffset);
ret = power_tbl->usMaximumPowerDeliveryLimit;
}
return ret;
}
static bool __set_engineclock(struct cgpu_info *cgpu, int iEngineClock)
{
gpu_sysfs_info *info = &cgpu->sysfs_info;
int engineclock = info->engineclock;
if (cgpu->min_engine > 0)
iEngineClock = MAX(iEngineClock, cgpu->min_engine);
if (cgpu->gpu_engine > 0)
iEngineClock = MIN(iEngineClock, cgpu->gpu_engine);
applog(LOG_DEBUG, "GPU%d: set engineclock to %dMHz", cgpu->device_id, iEngineClock);
iEngineClock *= 100;
Tonga_SCLK_Dependency_Table *sclk_tbl = get_sclk_table(info->pptable);
//replace current sclk table with default table
size_t sclk_tbl_size = (uintptr_t) get_sclk_record(sclk_tbl, sclk_tbl->ucNumEntries) - (uintptr_t) sclk_tbl;
memcpy(sclk_tbl, get_sclk_table(info->default_pptable), sclk_tbl_size);
//parse pp_table
Tonga_SCLK_Dependency_Record *prev_record = NULL, *record;
int idx = sclk_tbl->ucNumEntries - 1;
for (; idx >= 0; idx--) {
record = get_sclk_record(sclk_tbl, idx);
if (iEngineClock > record->ulSclk)
break;
prev_record = record;
}
if (prev_record != NULL)
record = prev_record;
//set new values
if (idx >= 0) {
record->ulSclk = iEngineClock;
info->engineclock = iEngineClock / 100;
}
else
info->engineclock = record->ulSclk / 100;
idx = MIN(idx + 1, sclk_tbl->ucNumEntries - 1);
get_state_array(info->pptable)->entries[1].ucEngineClockIndexHigh = idx;
info->sclk_ind = idx;
return (engineclock != info->engineclock);
}
int sysfs_set_engineclock(int gpu, int iEngineClock)
{
struct cgpu_info *cgpu = &gpus[gpu];
gpu_sysfs_info *info = &cgpu->sysfs_info;
int ret = !has_sysfs_hwcontrols || info->fd_pptable == -1;
if (!ret) {
pthread_mutex_lock(&info->rw_lock);
bool updated = __set_engineclock(cgpu, iEngineClock);
if (updated)
ret = __apply_pptable(info);
pthread_mutex_unlock(&info->rw_lock);
}
return ret;
}
static bool __change_engineclock(struct cgpu_info *cgpu, bool increase)
{
gpu_sysfs_info *info = &cgpu->sysfs_info;
gpus[gpu].sysfs_info.TgtFanSpeed = FanSpeed;
snprintf(PWM1FileName, 512, "%s/pwm1", gpus[gpu].sysfs_info.HWMonPath);
snprintf(Setting, 32, "%d", speed);
return (WriteSysFSFile(Setting, PWM1FileName, strlen(Setting)) > 0 ? 0 : -1);
Tonga_SCLK_Dependency_Table *sclk_tbl = get_sclk_table(info->default_pptable);
Tonga_SCLK_Dependency_Record *record = get_sclk_record(sclk_tbl, info->sclk_ind);
bool updated = false;
if (increase) {
//check whether the power state can be increased
if (info->sclk_ind + 1 < sclk_tbl->ucNumEntries) {
record = get_sclk_record(sclk_tbl, ++info->sclk_ind);
updated = __set_engineclock(cgpu, record->ulSclk / 100);
}
else if (cgpu->gpu_engine > 0)
updated = __set_engineclock(cgpu, cgpu->gpu_engine);
}
else {
//check whether the power state can be decreased
if (info->sclk_ind - 1 >= 0) {
record = get_sclk_record(sclk_tbl, --info->sclk_ind);
updated = __set_engineclock(cgpu, record->ulSclk / 100);
}
else if (cgpu->min_engine > 0)
updated = __set_engineclock(cgpu, cgpu->min_engine);
}
return updated;
}
static bool __set_memoryclock(struct cgpu_info *cgpu, int iMemoryClock)
{
gpu_sysfs_info *info = &cgpu->sysfs_info;
applog(LOG_DEBUG, "GPU%d: set memoryclock %dMHz", cgpu->device_id, iMemoryClock);
int memclock = info->memclock;
Tonga_MCLK_Dependency_Table* mclk_tbl = get_mclk_table(info->pptable);
Tonga_MCLK_Dependency_Record *record = &mclk_tbl->entries[1];
record->ulMclk = iMemoryClock * 100;
info->memclock = iMemoryClock;
return (memclock != info->memclock);
}
int sysfs_set_memoryclock(int gpu, int iMemoryClock)
{
struct cgpu_info *cgpu = &gpus[gpu];
gpu_sysfs_info *info = &cgpu->sysfs_info;
int ret = !has_sysfs_hwcontrols || info->fd_pptable == -1;
if (!ret) {
pthread_mutex_lock(&info->rw_lock);
bool updated = __set_memoryclock(cgpu, iMemoryClock);
if (updated)
ret = __apply_pptable(info);
pthread_mutex_unlock(&info->rw_lock);
}
return ret;
}
/* Returns whether the fanspeed is optimal already or not. The fan_window bool
@@ -171,51 +504,51 @@ int sysfs_set_fanspeed(int gpu, float FanSpeed)
static bool sysfs_fan_autotune(int gpu, int temp, float fanpercent, int lasttemp, bool *fan_window)
{
struct cgpu_info *cgpu = &gpus[gpu];
gpu_sysfs_info *SysFSInfo = &gpus[gpu].sysfs_info;
gpu_sysfs_info *info = &gpus[gpu].sysfs_info;
int tdiff = temp - lasttemp;
int top = gpus[gpu].gpu_fan;
int bot = gpus[gpu].min_fan;
float newpercent = SysFSInfo->TgtFanSpeed;//fanpercent;
float newpercent = info->target_fanpercent;//fanpercent;
float iMin = 0, iMax = 100;
if (temp > SysFSInfo->OverHeatTemp && fanpercent < iMax) {
applog(LOG_WARNING, "Overheat detected on GPU %d, increasing fan to 100%% (temp was %d, overtemp is %d)\n", gpu, temp, SysFSInfo->OverHeatTemp);
if (!opt_autoengine && temp > info->overheat_temp && fanpercent < iMax) {
applog(LOG_WARNING, "Overheat detected on GPU %d, increasing fan to 100%% (temp was %d, overtemp is %d)\n", gpu, temp, info->overheat_temp);
newpercent = iMax;
dev_error(cgpu, REASON_DEV_OVER_HEAT);
}
else if (temp > SysFSInfo->TargetTemp && fanpercent < top && tdiff >= 0) {
else if (temp > info->target_temp && fanpercent < top && tdiff >= 0) {
applog(LOG_DEBUG, "Temperature over target, increasing fanspeed");
if (temp > SysFSInfo->TargetTemp + opt_hysteresis)
newpercent = SysFSInfo->TgtFanSpeed + 10;
if (temp > info->target_temp + opt_hysteresis)
newpercent = info->target_fanpercent + 10;
else
newpercent = SysFSInfo->TgtFanSpeed + 5;
newpercent = info->target_fanpercent + 5;
if (newpercent > top)
newpercent = top;
}
else if (fanpercent > bot && temp < SysFSInfo->TargetTemp - opt_hysteresis) {
else if (fanpercent > bot && temp < info->target_temp - opt_hysteresis) {
/* Detect large swings of 5 degrees or more and change fan by
* a proportion more */
if(tdiff <= 0) {
if (tdiff <= 0) {
applog(LOG_DEBUG, "Temperature %d degrees below target, decreasing fanspeed", opt_hysteresis);
newpercent = SysFSInfo->TgtFanSpeed - 1 + tdiff / 5;
newpercent = info->target_fanpercent - 1 + tdiff / 5;
}
else if (tdiff >= 5) {
applog(LOG_DEBUG, "Temperature climbed %d while below target, increasing fanspeed", tdiff);
newpercent = SysFSInfo->TgtFanSpeed + tdiff / 5;
newpercent = info->target_fanpercent + tdiff / 5;
}
}
else {
/* We're in the optimal range, make minor adjustments if the
* temp is still drifting */
if (fanpercent > bot && tdiff < 0 && lasttemp < SysFSInfo->TargetTemp) {
if (fanpercent > bot && tdiff < 0 && lasttemp < info->target_temp) {
applog(LOG_DEBUG, "Temperature dropping while in target range, decreasing fanspeed");
newpercent = SysFSInfo->TgtFanSpeed + tdiff;
newpercent = info->target_fanpercent + tdiff;
}
else if (fanpercent < top && tdiff > 0 && temp > SysFSInfo->TargetTemp - opt_hysteresis) {
else if (fanpercent < top && tdiff > 0 && temp > info->target_temp - opt_hysteresis) {
applog(LOG_DEBUG, "Temperature rising while in target range, increasing fanspeed");
newpercent = SysFSInfo->TgtFanSpeed + tdiff;
newpercent = info->target_fanpercent + tdiff;
}
}
@@ -224,13 +557,13 @@ static bool sysfs_fan_autotune(int gpu, int temp, float fanpercent, int lasttemp
else if (newpercent < iMin)
newpercent = iMin;
if (newpercent <= top)
if (newpercent < top)
*fan_window = true;
else
*fan_window = false;
if (newpercent != fanpercent) {
applog(LOG_INFO, "Setting GPU %d fan percentage to %d", gpu, newpercent);
applog(LOG_INFO, "Setting GPU %d fan percentage to %g", gpu, newpercent);
set_fanspeed(gpu, newpercent);
@@ -247,90 +580,149 @@ static bool sysfs_fan_autotune(int gpu, int temp, float fanpercent, int lasttemp
void sysfs_gpu_autotune(int gpu, enum dev_enable *denable)
{
bool dummy;
struct cgpu_info *cgpu = &gpus[gpu];
if (!has_sysfs_hwcontrols || !cgpu->has_sysfs_hwcontrols)
return;
gpu_sysfs_info *info = &cgpu->sysfs_info;
bool fan_window = true;
int temp = sysfs_gpu_temp(gpu);
int fanpercent = sysfs_gpu_fanpercent(gpu) + 0.5f;
sysfs_fan_autotune(gpu, temp, gpus[gpu].sysfs_info.TgtFanSpeed, gpus[gpu].sysfs_info.LastTemp, &dummy);
gpu[gpus].sysfs_info.LastTemp = temp;
if (temp && fanpercent >= 0 && opt_autofan)
sysfs_fan_autotune(gpu, temp, info->target_fanpercent, info->last_temp, &fan_window);
info->last_temp = temp;
uint32_t ctr_diff = info->ctr++ - info->last_ctr;
if (opt_autoengine && info->fd_pptable != 1) {
bool updated = false;
pthread_mutex_lock(&info->rw_lock);
if (temp > cgpu->cutofftemp && *denable == DEV_ENABLED) {
applog(LOG_WARNING, "Hit thermal cutoff limit on GPU %d, disabling!", gpu);
updated = __set_engineclock(cgpu, cgpu->min_engine);
*denable = DEV_RECOVER;
dev_error(cgpu, REASON_DEV_THERMAL_CUTOFF);
}
else if (temp > info->overheat_temp && *denable == DEV_ENABLED) {
applog(LOG_WARNING, "Overheat detected, decreasing GPU %d clock speed", gpu);
updated = __change_engineclock(cgpu, false);
dev_error(cgpu, REASON_DEV_OVER_HEAT);
/* Only try to tune engine speed up if this GPU is not disabled */
}
else if (temp < info->overheat_temp - opt_hysteresis && fan_window && ctr_diff >= 6 && *denable == DEV_ENABLED) {
applog(LOG_DEBUG, "Temperature below overheat, increasing clock speed");
updated = __change_engineclock(cgpu, true);
info->last_ctr = info->ctr;
}
else if (temp < info->target_temp && *denable == DEV_RECOVER && opt_restart) {
applog(LOG_NOTICE, "Device recovered to temperature below target, re-enabling");
*denable = DEV_ENABLED;
for (int i = 0; i < cgpu->threads; i++)
cgsem_post(&cgpu->thr[i]->sem);
}
if (updated)
__apply_pptable(info);
pthread_mutex_unlock(&info->rw_lock);
}
}
bool sysfs_gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc,
int *activity, int *fanspeed, int *fanpercent, int *powertune)
{
if (!gpus[gpu].has_sysfs_hwcontrols)
if (!has_sysfs_hwcontrols || !gpus[gpu].has_sysfs_hwcontrols)
return false;
*temp = gpu_temp(gpu);
*fanspeed = 0;
*fanpercent = gpu_fanpercent(gpu);
*engineclock = 0;
*memclock = 0;
*fanspeed = gpu_fanspeed(gpu);
*fanpercent = gpu_fanpercent(gpu) + 0.5f;
*engineclock = gpu_engineclock(gpu);
*memclock = gpu_memclock(gpu);
*vddc = 0;
*activity = 0;
*powertune = gpu_powertune(gpu);
return true;
}
void sysfs_cleanup(int nDevs)
{
#ifdef __linux__
if (!has_sysfs_hwcontrols)
return;
has_sysfs_hwcontrols = false;
for (int i = 0; i < nDevs; i++) {
gpus[i].has_sysfs_hwcontrols = false;
gpu_sysfs_info *info = &gpus[i].sysfs_info;
// only overwrite pptable to default -> fd and memory are not released
if (info->pptable != NULL && info->fd_pptable != -1) {
pthread_mutex_lock(&info->rw_lock);
memcpy(info->pptable, info->default_pptable, info->pptable_size);
lseek(info->fd_pptable, 0, SEEK_SET);
write(info->fd_pptable, info->pptable, info->pptable_size);
pthread_mutex_unlock(&info->rw_lock);
}
}
#endif
}
bool init_sysfs_hwcontrols(int nDevs)
{
for(int i = 0; i < nDevs; ++i)
{
// Set gpus[i].sysfs_info.HWMonPath
GetGPUHWMonPath(&gpus[i].sysfs_info.HWMonPath, i);
if(gpus[i].sysfs_info.HWMonPath)
{
char PWMSettingBuf[33];
char FileNameBuf[513];
int BytesRead;
bool MinFanReadSuccess = false;
snprintf(FileNameBuf, 512, "%s/pwm1_min", gpus[i].sysfs_info.HWMonPath);
BytesRead = ReadSysFSFile(PWMSettingBuf, FileNameBuf, 512);
if(BytesRead > 0)
{
PWMSettingBuf[BytesRead] = 0x00;
gpus[i].sysfs_info.MinFanSpeed = strtoul(PWMSettingBuf, NULL, 10);
MinFanReadSuccess = true;
}
snprintf(FileNameBuf, 512, "%s/pwm1_max", gpus[i].sysfs_info.HWMonPath);
BytesRead = ReadSysFSFile(PWMSettingBuf, FileNameBuf, 512);
if((BytesRead > 0) && MinFanReadSuccess)
{
gpus[i].has_sysfs_hwcontrols = true;
PWMSettingBuf[BytesRead] = 0x00;
gpus[i].sysfs_info.MaxFanSpeed = strtoul(PWMSettingBuf, NULL, 10);
}
gpus[i].sysfs_info.LastTemp = sysfs_gpu_temp(i);
if(!gpus[i].sysfs_info.OverHeatTemp) gpus[i].sysfs_info.OverHeatTemp = opt_overheattemp;
if(!gpus[i].sysfs_info.TargetTemp) gpus[i].sysfs_info.TargetTemp = opt_targettemp;
gpu_temp = &sysfs_gpu_temp;
gpu_engineclock = &sysfs_gpu_engineclock;
gpu_memclock = &sysfs_gpu_memclock;
gpu_vddc = &sysfs_gpu_vddc;
gpu_activity = &sysfs_gpu_activity;
gpu_fanspeed = &sysfs_gpu_fanspeed;
gpu_fanpercent = &sysfs_gpu_fanpercent;
set_powertune = &sysfs_set_powertune;
set_vddc = &sysfs_set_vddc;
set_fanspeed = &sysfs_set_fanspeed;
set_engineclock = &sysfs_set_engineclock;
set_memoryclock = &sysfs_set_memoryclock;
gpu_stats = &sysfs_gpu_stats;
gpu_autotune = &sysfs_gpu_autotune;
extern bool opt_noadl;
if (opt_noadl) {
extern bool adl_active;
adl_active = false;
has_sysfs_hwcontrols = false;
for (int i = 0; i < nDevs; i++) {
gpus[i].has_adl = false;
gpus[i].has_sysfs_hwcontrols = false;
}
return false;
}
for (int i = 0; i < nDevs; ++i) {
gpu_sysfs_info *info = &gpus[i].sysfs_info;
if (!initialized)
sysfs_init(info, i);
info->target_fanpercent = sysfs_gpu_fanpercent(i);
info->last_temp = sysfs_gpu_temp(i);
if (!info->overheat_temp)
info->overheat_temp = opt_overheattemp;
if (!info->target_temp)
info->target_temp = opt_targettemp;
if(gpus[i].has_sysfs_hwcontrols) has_sysfs_hwcontrols = true;
gpus[i].has_sysfs_hwcontrols = (info->fd_temp != -1) & (info->fd_fan != -1);
Tonga_POWERPLAYTABLE *header = (Tonga_POWERPLAYTABLE*) info->pptable;
COMMON_TABLE_HEADER *common_hdr = (COMMON_TABLE_HEADER*) &header->sHeader;
//enable pptable support only for Tonga, Polaris and Fiji (?)
if (info->fd_pptable != -1 &&
(common_hdr->ucTableFormatRevision != 7 || common_hdr->ucTableContentRevision != 1 || header->ucTableRevision != 0)) {
close(info->fd_pptable);
info->fd_pptable = -1;
applog(LOG_WARNING, "No sysfs pptable support for GPU%d (%s)", i, gpus[i].name);
}
if (gpus[i].has_sysfs_hwcontrols)
has_sysfs_hwcontrols = true;
}
initialized = true;
if(has_sysfs_hwcontrols)
{
gpu_temp = &sysfs_gpu_temp;
gpu_engineclock = &sysfs_gpu_engineclock;
gpu_memclock = &sysfs_gpu_memclock;
gpu_vddc = &sysfs_gpu_vddc;
gpu_activity = &sysfs_gpu_activity;
gpu_fanspeed = &sysfs_gpu_fanspeed;
gpu_fanpercent = &sysfs_gpu_fanpercent;
set_powertune = &sysfs_set_powertune;
set_vddc = &sysfs_set_vddc;
set_fanspeed = &sysfs_set_fanspeed;
set_engineclock = &sysfs_set_engineclock;
set_memoryclock = &sysfs_set_memoryclock;
gpu_stats = &sysfs_gpu_stats;
gpu_autotune = &sysfs_gpu_autotune;
}
return(has_sysfs_hwcontrols);
return has_sysfs_hwcontrols;
}
+1 -6
View File
@@ -1,14 +1,9 @@
#ifndef __SYSFS_GPU_CONTROLS_H
#define __SYSFS_GPU_CONTROLS_H
#include "miner.h"
extern bool has_sysfs_hwcontrols;
extern bool opt_reorder;
extern int opt_hysteresis;
extern int opt_targettemp;
extern int opt_overheattemp;
void sysfs_cleanup(int);
bool init_sysfs_hwcontrols(int nDevs);
float sysfs_gpu_temp(int gpu);
int sysfs_gpu_engineclock(int gpu);