Skip to content

Commit

Permalink
introduce sysfs hw-control fallback path
Browse files Browse the repository at this point in the history
  • Loading branch information
NaN-git committed Jan 19, 2017
1 parent e2b978e commit d196356
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions sysfs-gpu-controls.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ static void sysfs_init(gpu_sysfs_info *info, int gpu_idx)
info->pcie_index[0], info->pcie_index[1], info->pcie_index[2]);
size_t len = strlen(path);

snprintf(path + len, sizeof(path) - len, "hwmon");
DIR *hwmon = opendir(path);
if (hwmon == NULL) {
applog(LOG_DEBUG, "Failed to open hwmon directory %s for GPU%d", path, gpu_idx);
snprintf(path, sizeof(path), "/sys/class/drm/card%d/device/hwmon", gpu_idx);
len = strlen(path) - 5;
hwmon = opendir(path);
if (hwmon == NULL) {
applog(LOG_DEBUG, "Failed to open hwmon directory %s for GPU%d", path, gpu_idx);
return;
}
}

snprintf(path + len, sizeof(path) - len, "pp_table");
int fd = open(path, O_RDONLY | O_RSYNC);
bool success = false;
Expand Down Expand Up @@ -84,14 +97,6 @@ static void sysfs_init(gpu_sysfs_info *info, int gpu_idx)
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;
}

while (true) {
inner_hwmon = readdir(hwmon);
if (inner_hwmon == NULL) {
Expand All @@ -105,7 +110,7 @@ static void sysfs_init(gpu_sysfs_info *info, int gpu_idx)
break;
}

snprintf(path + len, sizeof(path) - len, "/%s/", inner_hwmon->d_name);
snprintf(path + len, sizeof(path) - len, "hwmon/%s/", inner_hwmon->d_name);
len = strlen(path);
closedir(hwmon);

Expand Down

0 comments on commit d196356

Please sign in to comment.