|
| 1 | +#include "gpu.h" |
| 2 | +#include "common/io/io.h" |
| 3 | +#include "util/stringUtils.h" |
| 4 | + |
| 5 | +#include <fcntl.h> |
| 6 | + |
| 7 | +static double parseTZDir(int dfd, FFstrbuf* buffer) |
| 8 | +{ |
| 9 | + if(!ffReadFileBufferRelative(dfd, "temp", buffer)) |
| 10 | + return FF_GPU_TEMP_UNSET; |
| 11 | + |
| 12 | + double value = ffStrbufToDouble(buffer, FF_GPU_TEMP_UNSET);// millidegree Celsius |
| 13 | + if(value == FF_GPU_TEMP_UNSET) |
| 14 | + return FF_GPU_TEMP_UNSET; |
| 15 | + |
| 16 | + if (!ffReadFileBufferRelative(dfd, "type", buffer) || ffStrbufStartsWithS(buffer, "gpu")) |
| 17 | + return FF_GPU_TEMP_UNSET; |
| 18 | + |
| 19 | + return value / 1000.; |
| 20 | +} |
| 21 | + |
| 22 | +double ffGPUDetectTempFromTZ(void) |
| 23 | +{ |
| 24 | + FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/thermal/"); |
| 25 | + if(dirp) |
| 26 | + { |
| 27 | + FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate(); |
| 28 | + int dfd = dirfd(dirp); |
| 29 | + struct dirent* entry; |
| 30 | + while((entry = readdir(dirp)) != NULL) |
| 31 | + { |
| 32 | + if(entry->d_name[0] == '.') |
| 33 | + continue; |
| 34 | + if(!ffStrStartsWith(entry->d_name, "thermal_zone")) |
| 35 | + continue; |
| 36 | + |
| 37 | + FF_AUTO_CLOSE_FD int subfd = openat(dfd, entry->d_name, O_RDONLY | O_DIRECTORY | O_CLOEXEC); |
| 38 | + if(subfd < 0) |
| 39 | + continue; |
| 40 | + |
| 41 | + double result = parseTZDir(subfd, &buffer); |
| 42 | + if (result != FF_GPU_TEMP_UNSET) |
| 43 | + return result; |
| 44 | + } |
| 45 | + } |
| 46 | + return FF_GPU_TEMP_UNSET; |
| 47 | +} |
| 48 | + |
| 49 | +const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus) |
| 50 | +{ |
| 51 | + FF_UNUSED(options, gpus); |
| 52 | + return "No permission. Fallbacks to Vulkan, OpenCL or OpenGL instead"; |
| 53 | +} |
0 commit comments