Skip to content
Snippets Groups Projects
Commit 3aca6642 authored by Rolf Eike Beer's avatar Rolf Eike Beer
Browse files

SystemInformation: query memory size, CPU count, and CPU speed on BSD

Change-Id: I9d9ed23708dbc1388a04f17cbb9bb88ee6feae30
parent 61bd9b42
No related branches found
No related tags found
No related merge requests found
...@@ -86,6 +86,15 @@ typedef int siginfo_t; ...@@ -86,6 +86,15 @@ typedef int siginfo_t;
# endif # endif
#endif #endif
#if defined(__OpenBSD__) || defined(__NetBSD__)
# include <sys/param.h>
# include <sys/sysctl.h>
#endif
#if defined(__DragonFly__)
# include <sys/sysctl.h>
#endif
#ifdef __APPLE__ #ifdef __APPLE__
# include <sys/sysctl.h> # include <sys/sysctl.h>
# include <mach/vm_statistics.h> # include <mach/vm_statistics.h>
...@@ -448,6 +457,10 @@ protected: ...@@ -448,6 +457,10 @@ protected:
bool QueryQNXMemory(); bool QueryQNXMemory();
bool QueryQNXProcessor(); bool QueryQNXProcessor();
//For OpenBSD, FreeBSD, NetBSD, DragonFly
bool QueryBSDMemory();
bool QueryBSDProcessor();
// Evaluate the memory information. // Evaluate the memory information.
int QueryMemory(); int QueryMemory();
size_t TotalVirtualMemory; size_t TotalVirtualMemory;
...@@ -1257,6 +1270,8 @@ void SystemInformationImplementation::RunCPUCheck() ...@@ -1257,6 +1270,8 @@ void SystemInformationImplementation::RunCPUCheck()
this->QueryHaikuInfo(); this->QueryHaikuInfo();
#elif defined(__QNX__) #elif defined(__QNX__)
this->QueryQNXProcessor(); this->QueryQNXProcessor();
#elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
this->QueryBSDProcessor();
#else #else
this->RetreiveInformationFromCpuInfoFile(); this->RetreiveInformationFromCpuInfoFile();
#endif #endif
...@@ -1277,6 +1292,8 @@ void SystemInformationImplementation::RunMemoryCheck() ...@@ -1277,6 +1292,8 @@ void SystemInformationImplementation::RunMemoryCheck()
this->QueryHaikuInfo(); this->QueryHaikuInfo();
#elif defined(__QNX__) #elif defined(__QNX__)
this->QueryQNXMemory(); this->QueryQNXMemory();
#elif defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
this->QueryBSDMemory();
#else #else
this->QueryMemory(); this->QueryMemory();
#endif #endif
...@@ -4140,6 +4157,31 @@ bool SystemInformationImplementation::QueryQNXMemory() ...@@ -4140,6 +4157,31 @@ bool SystemInformationImplementation::QueryQNXMemory()
return false; return false;
} }
bool SystemInformationImplementation::QueryBSDMemory()
{
#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
int ctrl[2] = { CTL_HW, HW_PHYSMEM };
#if defined(HW_PHYSMEM64)
int64_t k;
ctrl[1] = HW_PHYSMEM64;
#else
int k;
#endif
size_t sz = sizeof(k);
if (sysctl(ctrl, 2, &k, &sz, NULL, 0) != 0)
{
return false;
}
this->TotalPhysicalMemory = k>>10>>10;
return true;
#else
return false;
#endif
}
bool SystemInformationImplementation::QueryQNXProcessor() bool SystemInformationImplementation::QueryQNXProcessor()
{ {
#if defined(__QNX__) #if defined(__QNX__)
...@@ -4193,6 +4235,38 @@ bool SystemInformationImplementation::QueryQNXProcessor() ...@@ -4193,6 +4235,38 @@ bool SystemInformationImplementation::QueryQNXProcessor()
#endif #endif
} }
bool SystemInformationImplementation::QueryBSDProcessor()
{
#if defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
int k;
size_t sz = sizeof(k);
int ctrl[2] = { CTL_HW, HW_NCPU };
if (sysctl(ctrl, 2, &k, &sz, NULL, 0) != 0)
{
return false;
}
this->NumberOfPhysicalCPU = k;
this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU;
#if defined(HW_CPUSPEED)
ctrl[1] = HW_CPUSPEED;
if (sysctl(ctrl, 2, &k, &sz, NULL, 0) != 0)
{
return false;
}
this->CPUSpeedInMHz = (float) k;
#endif
return true;
#else
return false;
#endif
}
/** Query the operating system information */ /** Query the operating system information */
bool SystemInformationImplementation::QueryOSInformation() bool SystemInformationImplementation::QueryOSInformation()
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment