Skip to content

Commit ebf810a

Browse files
committed
GPU (Android): adds GPU temp detection support
1 parent 5c9a0a1 commit ebf810a

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ elseif(ANDROID)
599599
src/detection/diskio/diskio_linux.c
600600
src/detection/displayserver/displayserver_android.c
601601
src/detection/font/font_nosupport.c
602-
src/detection/gpu/gpu_nosupport.c
602+
src/detection/gpu/gpu_android.c
603603
src/detection/host/host_android.c
604604
src/detection/icons/icons_nosupport.c
605605
src/detection/initsystem/initsystem_linux.c

src/detection/gpu/gpu.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ const char* ffDetectGPU(const FFGPUOptions* options, FFlist* result)
116116
{
117117
ffListDestroy(result);
118118
ffListInitMove(result, &vulkan->gpus);
119+
120+
#ifdef __ANDROID__
121+
double ffGPUDetectTempFromTZ(void);
122+
if (options->temp && result->length == 1)
123+
FF_LIST_GET(FFGPUResult, *result, 0)->temperature = ffGPUDetectTempFromTZ();
124+
#endif
125+
119126
return NULL;
120127
}
121128
}

src/detection/gpu/gpu_android.c

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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

Comments
 (0)