summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/SystemInformation.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/kwsys/SystemInformation.cxx')
-rw-r--r--Source/kwsys/SystemInformation.cxx118
1 files changed, 83 insertions, 35 deletions
diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx
index 59a9abe..b20d724 100644
--- a/Source/kwsys/SystemInformation.cxx
+++ b/Source/kwsys/SystemInformation.cxx
@@ -202,7 +202,7 @@ typedef struct rlimit ResourceLimitType;
#define USE_CPUID_INTRINSICS 0
#endif
-#if USE_ASM_INSTRUCTIONS || USE_CPUID_INTRINSICS
+#if USE_ASM_INSTRUCTIONS || USE_CPUID_INTRINSICS || defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID)
# define USE_CPUID 1
#else
# define USE_CPUID 0
@@ -224,6 +224,7 @@ static bool call_cpuid(int select, int result[4])
return true;
#else
int tmp[4];
+#if defined(_MSC_VER)
// Use SEH to determine CPUID presence
__try {
_asm {
@@ -262,7 +263,24 @@ static bool call_cpuid(int select, int result[4])
return false;
}
- memcpy(result, tmp, sizeof(tmp));
+ memcpy(result, tmp, sizeof(tmp));
+#elif defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID)
+ unsigned int a, b, c, d;
+ __asm {
+ mov EAX, select;
+ cpuid
+ mov a, EAX;
+ mov b, EBX;
+ mov c, ECX;
+ mov d, EDX;
+ }
+
+ result[0] = a;
+ result[1] = b;
+ result[2] = c;
+ result[3] = d;
+#endif
+
// The cpuid instruction succeeded.
return true;
#endif
@@ -432,7 +450,7 @@ protected:
int CPUCount();
unsigned char LogicalCPUPerPhysicalCPU();
unsigned char GetAPICId();
- unsigned int IsHyperThreadingSupported();
+ bool IsHyperThreadingSupported();
static LongLong GetCyclesDifference(DELAY_FUNC, unsigned int);
// For Linux and Cygwin, /proc/cpuinfo formats are slightly different
@@ -456,7 +474,8 @@ protected:
kwsys_stl::string SysCtlBuffer;
// For Solaris
- bool QuerySolarisInfo();
+ bool QuerySolarisMemory();
+ bool QuerySolarisProcessor();
kwsys_stl::string ParseValueFromKStat(const char* arguments);
kwsys_stl::string RunProcess(kwsys_stl::vector<const char*> args);
@@ -481,9 +500,11 @@ protected:
//For AIX
bool QueryAIXMemory();
+ bool QueryProcessorBySysconf();
bool QueryProcessor();
// Evaluate the memory information.
+ bool QueryMemoryBySysconf();
bool QueryMemory();
size_t TotalVirtualMemory;
size_t AvailableVirtualMemory;
@@ -1287,7 +1308,7 @@ void SystemInformationImplementation::RunCPUCheck()
#elif defined(__APPLE__)
this->ParseSysCtl();
#elif defined (__SVR4) && defined (__sun)
- this->QuerySolarisInfo();
+ this->QuerySolarisProcessor();
#elif defined(__HAIKU__)
this->QueryHaikuInfo();
#elif defined(__QNX__)
@@ -1313,7 +1334,7 @@ void SystemInformationImplementation::RunMemoryCheck()
#if defined(__APPLE__)
this->ParseSysCtl();
#elif defined (__SVR4) && defined (__sun)
- this->QuerySolarisInfo();
+ this->QuerySolarisMemory();
#elif defined(__HAIKU__)
this->QueryHaikuInfo();
#elif defined(__QNX__)
@@ -3016,7 +3037,7 @@ bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
return true;
}
-bool SystemInformationImplementation::QueryProcessor()
+bool SystemInformationImplementation::QueryProcessorBySysconf()
{
#if defined(_SC_NPROC_ONLN) && !defined(_SC_NPROCESSORS_ONLN)
// IRIX names this slightly different
@@ -3039,6 +3060,11 @@ bool SystemInformationImplementation::QueryProcessor()
#endif
}
+bool SystemInformationImplementation::QueryProcessor()
+{
+ return this->QueryProcessorBySysconf();
+}
+
/**
Get total system RAM in units of KiB.
*/
@@ -3559,8 +3585,7 @@ bool SystemInformationImplementation::QueryAIXMemory()
#endif
}
-/** Query for the memory status */
-bool SystemInformationImplementation::QueryMemory()
+bool SystemInformationImplementation::QueryMemoryBySysconf()
{
#if defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE)
// Assume the mmap() granularity as returned by _SC_PAGESIZE is also
@@ -3597,6 +3622,12 @@ bool SystemInformationImplementation::QueryMemory()
#endif
}
+/** Query for the memory status */
+bool SystemInformationImplementation::QueryMemory()
+{
+ return this->QueryMemoryBySysconf();
+}
+
/** */
size_t SystemInformationImplementation::GetTotalVirtualMemory()
{
@@ -3729,8 +3760,13 @@ unsigned char SystemInformationImplementation::LogicalCPUPerPhysicalCPU(void)
/** Works only for windows */
-unsigned int SystemInformationImplementation::IsHyperThreadingSupported()
+bool SystemInformationImplementation::IsHyperThreadingSupported()
{
+ if (this->Features.ExtendedFeatures.SupportsHyperthreading)
+ {
+ return true;
+ }
+
#if USE_CPUID
int Regs[4] = { 0, 0, 0, 0 },
VendorId[4] = { 0, 0, 0, 0 };
@@ -3748,13 +3784,15 @@ unsigned int SystemInformationImplementation::IsHyperThreadingSupported()
if (((Regs[0] & FAMILY_ID) == PENTIUM4_ID) || (Regs[0] & EXT_FAMILY_ID))
{
- if (VendorId[1] == 'uneG')
+ if (VendorId[1] == 0x756e6547) // 'uneG'
{
- if (VendorId[3] == 'Ieni')
+ if (VendorId[3] == 0x49656e69) // 'Ieni'
{
- if (VendorId[2] == 'letn')
+ if (VendorId[2] == 0x6c65746e) // 'letn'
{
- return(Regs[3] & HT_BIT); // Genuine Intel with hyper-Threading technology
+ // Genuine Intel with hyper-Threading technology
+ this->Features.ExtendedFeatures.SupportsHyperthreading = ((Regs[3] & HT_BIT) != 0);
+ return this->Features.ExtendedFeatures.SupportsHyperthreading;
}
}
}
@@ -4251,16 +4289,40 @@ kwsys_stl::string SystemInformationImplementation::ParseValueFromKStat(const cha
return value;
}
-
/** Querying for system information from Solaris */
-bool SystemInformationImplementation::QuerySolarisInfo()
+bool SystemInformationImplementation::QuerySolarisMemory()
{
- // Parse values
- this->NumberOfPhysicalCPU = static_cast<unsigned int>(
- atoi(this->ParseValueFromKStat("-n syste_misc -s ncpus").c_str()));
- this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU;
- this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = 1;
+#if defined (__SVR4) && defined (__sun)
+ // Solaris allows querying this value by sysconf, but if this is
+ // a 32 bit process on a 64 bit host the returned memory will be
+ // limited to 4GiB. So if this is a 32 bit process or if the sysconf
+ // method fails use the kstat interface.
+#if SIZEOF_VOID_P == 8
+ if (this->QueryMemoryBySysconf())
+ {
+ return true;
+ }
+#endif
+ char* tail;
+ unsigned long totalMemory =
+ strtoul(this->ParseValueFromKStat("-s physmem").c_str(),&tail,0);
+ this->TotalPhysicalMemory = totalMemory/128;
+
+ return true;
+#else
+ return false;
+#endif
+}
+
+bool SystemInformationImplementation::QuerySolarisProcessor()
+{
+ if (!this->QueryProcessorBySysconf())
+ {
+ return false;
+ }
+
+ // Parse values
this->CPUSpeedInMHz = static_cast<float>(atoi(this->ParseValueFromKStat("-s clock_MHz").c_str()));
// Chip family
@@ -4277,20 +4339,6 @@ bool SystemInformationImplementation::QuerySolarisInfo()
this->FindManufacturer();
}
- // Cache size
- this->Features.L1CacheSize = 0;
- this->Features.L2CacheSize = 0;
-
- char* tail;
- unsigned long totalMemory =
- strtoul(this->ParseValueFromKStat("-s physmem").c_str(),&tail,0);
- this->TotalPhysicalMemory = totalMemory/128;
-
- // Undefined values (for now at least)
- this->TotalVirtualMemory = 0;
- this->AvailablePhysicalMemory = 0;
- this->AvailableVirtualMemory = 0;
-
return true;
}