Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1519 from Fneufneu/freebsd_cpu

Freebsd cpu infos
  • Loading branch information...
commit 41c67e2c8d155dfadc6f5d413b9034738e74b438 2 parents 552580d + d10fa2b
@Fneufneu Fneufneu authored
Showing with 92 additions and 0 deletions.
  1. +92 −0 xbmc/utils/CPUInfo.cpp
View
92 xbmc/utils/CPUInfo.cpp
@@ -31,6 +31,12 @@
#endif
#endif
+#if defined(TARGET_FREEBSD)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <sys/resource.h>
+#endif
+
#if defined(TARGET_LINUX) && defined(__ARM_NEON__) && !defined(TARGET_ANDROID)
#include <fcntl.h>
#include <unistd.h>
@@ -196,6 +202,27 @@ CCPUInfo::CCPUInfo(void)
CoreInfo core;
m_cores[0] = core;
+#elif defined(TARGET_FREEBSD)
+ size_t len;
+ int i;
+ char cpumodel[512];
+
+ len = sizeof(m_cpuCount);
+ if (sysctlbyname("hw.ncpu", &m_cpuCount, &len, NULL, 0) != 0)
+ m_cpuCount = 1;
+
+ len = sizeof(cpumodel);
+ if (sysctlbyname("hw.model", &cpumodel, &len, NULL, 0) != 0)
+ (void)strncpy(cpumodel, "Unknown", 8);
+ m_cpuModel = cpumodel;
+
+ for (i = 0; i < m_cpuCount; i++)
+ {
+ CoreInfo core;
+ core.m_id = i;
+ core.m_strModel = m_cpuModel;
+ m_cores[core.m_id] = core;
+ }
#else
m_fProcStat = fopen("/proc/stat", "r");
m_fProcTemperature = fopen("/proc/acpi/thermal_zone/THM0/temperature", "r");
@@ -448,6 +475,12 @@ float CCPUInfo::getCPUFrequency()
return float(dwMHz);
else
return 0.f;
+#elif defined(TARGET_FREEBSD)
+ int hz = 0;
+ size_t len = sizeof(hz);
+ if (sysctlbyname("dev.cpu.0.freq", &hz, &len, NULL, 0) != 0)
+ hz = 0;
+ return (float)hz;
#else
float mhz = 0.f;
char buf[256],
@@ -575,6 +608,65 @@ bool CCPUInfo::readProcStat(unsigned long long& user, unsigned long long& nice,
io = 0;
+#elif defined(TARGET_FREEBSD)
+ long *cptimes;
+ size_t len;
+ int i;
+
+ len = sizeof(long) * 32 * CPUSTATES;
+ if (sysctlbyname("kern.cp_times", NULL, &len, NULL, 0) != 0)
+ return false;
+ cptimes = (long*)malloc(len);
+ if (cptimes == NULL)
+ return false;
+ if (sysctlbyname("kern.cp_times", cptimes, &len, NULL, 0) != 0)
+ {
+ free(cptimes);
+ return false;
+ }
+ user = 0;
+ nice = 0;
+ system = 0;
+ idle = 0;
+ io = 0;
+ for (i = 0; i < m_cpuCount; i++)
+ {
+ long coreUser, coreNice, coreSystem, coreIdle, coreIO;
+ double total;
+
+ coreUser = cptimes[i * CPUSTATES + CP_USER];
+ coreNice = cptimes[i * CPUSTATES + CP_NICE];
+ coreSystem = cptimes[i * CPUSTATES + CP_SYS];
+ coreIO = cptimes[i * CPUSTATES + CP_INTR];
+ coreIdle = cptimes[i * CPUSTATES + CP_IDLE];
+
+ map<int, CoreInfo>::iterator iter = m_cores.find(i);
+ if (iter != m_cores.end())
+ {
+ coreUser -= iter->second.m_user;
+ coreNice -= iter->second.m_nice;
+ coreSystem -= iter->second.m_system;
+ coreIdle -= iter->second.m_idle;
+ coreIO -= iter->second.m_io;
+
+ total = (double)(coreUser + coreNice + coreSystem + coreIdle + coreIO);
+ if(total != 0.0f)
+ iter->second.m_fPct = ((double)(coreUser + coreNice + coreSystem) * 100.0) / total;
+
+ iter->second.m_user += coreUser;
+ iter->second.m_nice += coreNice;
+ iter->second.m_system += coreSystem;
+ iter->second.m_idle += coreIdle;
+ iter->second.m_io += coreIO;
+
+ user += coreUser;
+ nice += coreNice;
+ system += coreSystem;
+ idle += coreIdle;
+ io += coreIO;
+ }
+ }
+ free(cptimes);
#else
if (m_fProcStat == NULL)
return false;
Please sign in to comment.
Something went wrong with that request. Please try again.