2025-08-28 14:24:40 +08:00
|
|
|
#include "gpu.h"
|
2026-01-06 09:48:38 +08:00
|
|
|
#include "common/io.h"
|
|
|
|
|
#include "common/stringUtils.h"
|
2025-08-28 14:24:40 +08:00
|
|
|
|
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
static double parseTZDir(int dfd, FFstrbuf* buffer) {
|
|
|
|
|
if (!ffReadFileBufferRelative(dfd, "type", buffer) || !ffStrbufStartsWithS(buffer, "gpu")) {
|
2025-08-28 14:24:40 +08:00
|
|
|
return FF_GPU_TEMP_UNSET;
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2025-08-28 14:24:40 +08:00
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
if (!ffReadFileBufferRelative(dfd, "temp", buffer)) {
|
2025-08-28 14:24:40 +08:00
|
|
|
return FF_GPU_TEMP_UNSET;
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2025-08-28 14:24:40 +08:00
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
double value = ffStrbufToDouble(buffer, FF_GPU_TEMP_UNSET); // millidegree Celsius
|
|
|
|
|
if (value == FF_GPU_TEMP_UNSET) {
|
2025-08-28 14:24:40 +08:00
|
|
|
return FF_GPU_TEMP_UNSET;
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2025-08-28 14:24:40 +08:00
|
|
|
|
|
|
|
|
return value / 1000.;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
double ffGPUDetectTempFromTZ(void) {
|
2025-08-28 14:24:40 +08:00
|
|
|
FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/thermal/");
|
2026-03-29 09:28:49 +08:00
|
|
|
if (dirp) {
|
2025-08-28 14:24:40 +08:00
|
|
|
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
|
|
|
|
|
int dfd = dirfd(dirp);
|
|
|
|
|
struct dirent* entry;
|
2026-03-29 09:28:49 +08:00
|
|
|
while ((entry = readdir(dirp)) != NULL) {
|
|
|
|
|
if (entry->d_name[0] == '.') {
|
2025-08-28 14:24:40 +08:00
|
|
|
continue;
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
|
|
|
|
if (!ffStrStartsWith(entry->d_name, "thermal_zone")) {
|
2025-08-28 14:24:40 +08:00
|
|
|
continue;
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2025-08-28 14:24:40 +08:00
|
|
|
|
|
|
|
|
FF_AUTO_CLOSE_FD int subfd = openat(dfd, entry->d_name, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
|
2026-03-29 09:28:49 +08:00
|
|
|
if (subfd < 0) {
|
2025-08-28 14:24:40 +08:00
|
|
|
continue;
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2025-08-28 14:24:40 +08:00
|
|
|
|
|
|
|
|
double result = parseTZDir(subfd, &buffer);
|
2026-03-29 09:28:49 +08:00
|
|
|
if (result != FF_GPU_TEMP_UNSET) {
|
2025-08-28 14:24:40 +08:00
|
|
|
return result;
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2025-08-28 14:24:40 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return FF_GPU_TEMP_UNSET;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
const char* ffDetectGPUImpl(const FFGPUOptions* options, FFlist* gpus) {
|
2025-08-28 14:24:40 +08:00
|
|
|
FF_UNUSED(options, gpus);
|
|
|
|
|
return "No permission. Fallbacks to Vulkan, OpenCL or OpenGL instead";
|
|
|
|
|
}
|