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