From 01f97b166222f3c1db87d05a3a00eff4e9cc340c Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 16 Oct 2013 22:56:20 -0700 Subject: [PATCH] Get cpu info from /sys where possible. Fixes #4215. May impact texture scaling performance. --- Common/ArmCPUDetect.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Common/ArmCPUDetect.cpp b/Common/ArmCPUDetect.cpp index 922a78bc05..dc86f6a824 100644 --- a/Common/ArmCPUDetect.cpp +++ b/Common/ArmCPUDetect.cpp @@ -23,6 +23,8 @@ // Only Linux platforms have /proc/cpuinfo #if !defined(BLACKBERRY) && !defined(IOS) && !defined(__SYMBIAN32__) const char procfile[] = "/proc/cpuinfo"; +// https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-devices-system-cpu +const char syscpupresentfile[] = "/sys/devices/system/cpu/present"; char *GetCPUString() { @@ -148,6 +150,25 @@ int GetCoreCount() char buf[1024]; FILE *fp; + fp = fopen(syscpupresentfile, "r"); + if (fp) + { + fgets(buf, sizeof(buf), fp); + fclose(fp); + + int low, high; + // Technically, this could be "1-2,4,8-23" but for ARM devices that seems unlikely. + int found = sscanf(buf, "%d-%d", &low, &high); + + // Only a single number, so just one slot/core (actually threads.) + if (found == 1) + return 1; + if (found == 2) + return high - low + 1; + + // Okay, let's fall back. + } + fp = fopen(procfile, "r"); if (!fp) return 0;