2009-09-28 19:37:35 +04:00
|
|
|
/*============================================================================
|
|
|
|
KWSys - Kitware System Library
|
|
|
|
Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
|
2008-01-08 19:38:28 +03:00
|
|
|
|
2009-09-28 19:37:35 +04:00
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
2008-01-08 19:38:28 +03:00
|
|
|
|
2009-09-28 19:37:35 +04:00
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
2008-10-17 19:29:30 +04:00
|
|
|
#ifdef _WIN32
|
|
|
|
# include <winsock.h> // WSADATA, include before sys/types.h
|
|
|
|
#endif
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
// TODO:
|
|
|
|
// We need an alternative implementation for many functions in this file
|
|
|
|
// when USE_ASM_INSTRUCTIONS gets defined as 0.
|
|
|
|
//
|
|
|
|
// Consider using these on Win32/Win64 for some of them:
|
|
|
|
//
|
|
|
|
// IsProcessorFeaturePresent
|
|
|
|
// http://msdn.microsoft.com/en-us/library/ms724482(VS.85).aspx
|
|
|
|
//
|
|
|
|
// GetProcessMemoryInfo
|
|
|
|
// http://msdn.microsoft.com/en-us/library/ms683219(VS.85).aspx
|
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
#include "kwsysPrivate.h"
|
2008-01-31 22:34:11 +03:00
|
|
|
#include KWSYS_HEADER(FundamentalType.h)
|
|
|
|
#include KWSYS_HEADER(stl/string)
|
|
|
|
#include KWSYS_HEADER(stl/vector)
|
|
|
|
#include KWSYS_HEADER(ios/iosfwd)
|
2008-01-08 19:38:28 +03:00
|
|
|
#include KWSYS_HEADER(SystemInformation.hxx)
|
|
|
|
#include KWSYS_HEADER(Process.h)
|
|
|
|
#include KWSYS_HEADER(ios/iostream)
|
2008-01-08 22:59:57 +03:00
|
|
|
#include KWSYS_HEADER(ios/sstream)
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
// Work-around CMake dependency scanning limitation. This must
|
|
|
|
// duplicate the above list of headers.
|
|
|
|
#if 0
|
|
|
|
# include "FundamentalType.h.in"
|
|
|
|
# include "SystemInformation.hxx.in"
|
|
|
|
# include "Process.h.in"
|
|
|
|
# include "Configure.hxx.in"
|
|
|
|
# include "kwsys_stl.hxx.in"
|
|
|
|
# include "kwsys_stl_vector.in"
|
|
|
|
# include "kwsys_stl_iosfwd.in"
|
|
|
|
# include "kwsys_ios_sstream.h.in"
|
|
|
|
# include "kwsys_ios_iostream.h.in"
|
2008-01-08 19:38:28 +03:00
|
|
|
#endif
|
|
|
|
|
2008-01-31 23:34:09 +03:00
|
|
|
#ifndef WIN32
|
|
|
|
# include <sys/utsname.h> // int uname(struct utsname *buf);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2009-05-20 17:50:20 +04:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <mach/vm_statistics.h>
|
|
|
|
#include <mach/host_info.h>
|
|
|
|
#include <mach/mach.h>
|
|
|
|
#include <mach/mach_types.h>
|
|
|
|
#endif
|
|
|
|
|
2008-01-31 23:34:09 +03:00
|
|
|
#ifdef __linux
|
|
|
|
# include <sys/procfs.h>
|
|
|
|
# include <sys/types.h>
|
|
|
|
# include <unistd.h>
|
|
|
|
# include <fcntl.h>
|
|
|
|
# include <ctype.h> // int isdigit(int c);
|
|
|
|
# include <errno.h> // extern int errno;
|
|
|
|
# include <sys/time.h>
|
|
|
|
#elif __hpux
|
|
|
|
# include <sys/param.h>
|
|
|
|
# include <sys/pstat.h>
|
|
|
|
#endif
|
|
|
|
|
2009-02-12 18:08:15 +03:00
|
|
|
#ifdef __HAIKU__
|
|
|
|
#include <OS.h>
|
|
|
|
#endif
|
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
#include <memory.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
namespace KWSYS_NAMESPACE
|
|
|
|
{
|
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
// Create longlong
|
|
|
|
#if KWSYS_USE_LONG_LONG
|
|
|
|
typedef long long LongLong;
|
|
|
|
#elif KWSYS_USE___INT64
|
|
|
|
typedef __int64 LongLong;
|
|
|
|
#else
|
|
|
|
# error "No Long Long"
|
|
|
|
#endif
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
// Define SystemInformationImplementation class
|
|
|
|
typedef void (*DELAY_FUNC)(unsigned int uiMS);
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
|
|
|
class SystemInformationImplementation
|
|
|
|
{
|
2008-01-31 22:34:11 +03:00
|
|
|
public:
|
|
|
|
SystemInformationImplementation ();
|
|
|
|
~SystemInformationImplementation ();
|
|
|
|
|
|
|
|
const char * GetVendorString();
|
|
|
|
const char * GetVendorID();
|
|
|
|
kwsys_stl::string GetTypeID();
|
|
|
|
kwsys_stl::string GetFamilyID();
|
|
|
|
kwsys_stl::string GetModelID();
|
|
|
|
kwsys_stl::string GetSteppingCode();
|
|
|
|
const char * GetExtendedProcessorName();
|
|
|
|
const char * GetProcessorSerialNumber();
|
|
|
|
int GetProcessorCacheSize();
|
2009-03-20 05:48:05 +03:00
|
|
|
unsigned int GetLogicalProcessorsPerPhysical();
|
2008-01-31 22:34:11 +03:00
|
|
|
float GetProcessorClockFrequency();
|
|
|
|
int GetProcessorAPICID();
|
|
|
|
int GetProcessorCacheXSize(long int);
|
|
|
|
bool DoesCPUSupportFeature(long int);
|
|
|
|
|
|
|
|
const char * GetOSName();
|
|
|
|
const char * GetHostname();
|
|
|
|
const char * GetOSRelease();
|
|
|
|
const char * GetOSVersion();
|
|
|
|
const char * GetOSPlatform();
|
|
|
|
|
|
|
|
bool Is64Bits();
|
|
|
|
|
|
|
|
unsigned int GetNumberOfLogicalCPU(); // per physical cpu
|
|
|
|
unsigned int GetNumberOfPhysicalCPU();
|
|
|
|
|
|
|
|
bool DoesCPUSupportCPUID();
|
|
|
|
|
|
|
|
// Retrieve memory information in megabyte.
|
2009-11-16 20:43:44 +03:00
|
|
|
size_t GetTotalVirtualMemory();
|
|
|
|
size_t GetAvailableVirtualMemory();
|
|
|
|
size_t GetTotalPhysicalMemory();
|
|
|
|
size_t GetAvailablePhysicalMemory();
|
2008-01-31 22:34:11 +03:00
|
|
|
|
|
|
|
/** Run the different checks */
|
|
|
|
void RunCPUCheck();
|
|
|
|
void RunOSCheck();
|
|
|
|
void RunMemoryCheck();
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-02-01 05:33:32 +03:00
|
|
|
public:
|
2008-01-31 22:34:11 +03:00
|
|
|
#define VENDOR_STRING_LENGTH (12 + 1)
|
|
|
|
#define CHIPNAME_STRING_LENGTH (48 + 1)
|
|
|
|
#define SERIALNUMBER_STRING_LENGTH (29 + 1)
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
typedef struct tagID
|
2008-01-31 22:34:11 +03:00
|
|
|
{
|
|
|
|
int Type;
|
|
|
|
int Family;
|
|
|
|
int Model;
|
|
|
|
int Revision;
|
|
|
|
int ExtendedFamily;
|
|
|
|
int ExtendedModel;
|
|
|
|
char ProcessorName[CHIPNAME_STRING_LENGTH];
|
|
|
|
char Vendor[VENDOR_STRING_LENGTH];
|
|
|
|
char SerialNumber[SERIALNUMBER_STRING_LENGTH];
|
|
|
|
} ID;
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
typedef struct tagCPUPowerManagement
|
2008-01-31 22:34:11 +03:00
|
|
|
{
|
|
|
|
bool HasVoltageID;
|
|
|
|
bool HasFrequencyID;
|
|
|
|
bool HasTempSenseDiode;
|
|
|
|
} CPUPowerManagement;
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
typedef struct tagCPUExtendedFeatures
|
2008-01-31 22:34:11 +03:00
|
|
|
{
|
|
|
|
bool Has3DNow;
|
|
|
|
bool Has3DNowPlus;
|
|
|
|
bool SupportsMP;
|
|
|
|
bool HasMMXPlus;
|
|
|
|
bool HasSSEMMX;
|
|
|
|
bool SupportsHyperthreading;
|
2009-03-20 05:48:05 +03:00
|
|
|
unsigned int LogicalProcessorsPerPhysical;
|
2008-01-31 22:34:11 +03:00
|
|
|
int APIC_ID;
|
|
|
|
CPUPowerManagement PowerManagement;
|
2009-12-11 21:08:29 +03:00
|
|
|
} CPUExtendedFeatures;
|
|
|
|
|
|
|
|
typedef struct CPUtagFeatures
|
2008-01-31 22:34:11 +03:00
|
|
|
{
|
|
|
|
bool HasFPU;
|
|
|
|
bool HasTSC;
|
|
|
|
bool HasMMX;
|
|
|
|
bool HasSSE;
|
|
|
|
bool HasSSEFP;
|
|
|
|
bool HasSSE2;
|
|
|
|
bool HasIA64;
|
|
|
|
bool HasAPIC;
|
|
|
|
bool HasCMOV;
|
|
|
|
bool HasMTRR;
|
|
|
|
bool HasACPI;
|
|
|
|
bool HasSerial;
|
|
|
|
bool HasThermal;
|
|
|
|
int CPUSpeed;
|
|
|
|
int L1CacheSize;
|
|
|
|
int L2CacheSize;
|
|
|
|
int L3CacheSize;
|
|
|
|
CPUExtendedFeatures ExtendedFeatures;
|
|
|
|
} CPUFeatures;
|
2009-12-11 21:08:29 +03:00
|
|
|
|
|
|
|
enum Manufacturer
|
2008-01-31 22:34:11 +03:00
|
|
|
{
|
2009-12-11 21:08:29 +03:00
|
|
|
AMD, Intel, NSC, UMC, Cyrix, NexGen, IDT, Rise, Transmeta, Sun, IBM,
|
|
|
|
Motorola, UnknownManufacturer
|
2008-01-31 22:34:11 +03:00
|
|
|
};
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
protected:
|
2008-01-31 22:34:11 +03:00
|
|
|
// Functions.
|
|
|
|
bool RetrieveCPUFeatures();
|
|
|
|
bool RetrieveCPUIdentity();
|
|
|
|
bool RetrieveCPUCacheDetails();
|
|
|
|
bool RetrieveClassicalCPUCacheDetails();
|
|
|
|
bool RetrieveCPUClockSpeed();
|
|
|
|
bool RetrieveClassicalCPUClockSpeed();
|
|
|
|
bool RetrieveCPUExtendedLevelSupport(int);
|
|
|
|
bool RetrieveExtendedCPUFeatures();
|
|
|
|
bool RetrieveProcessorSerialNumber();
|
|
|
|
bool RetrieveCPUPowerManagement();
|
|
|
|
bool RetrieveClassicalCPUIdentity();
|
|
|
|
bool RetrieveExtendedCPUIdentity();
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
Manufacturer ChipManufacturer;
|
|
|
|
CPUFeatures Features;
|
|
|
|
ID ChipID;
|
|
|
|
float CPUSpeedInMHz;
|
|
|
|
unsigned int NumberOfLogicalCPU;
|
|
|
|
unsigned int NumberOfPhysicalCPU;
|
|
|
|
|
|
|
|
int CPUCount();
|
|
|
|
unsigned char LogicalCPUPerPhysicalCPU();
|
|
|
|
unsigned char GetAPICId();
|
|
|
|
unsigned int IsHyperThreadingSupported();
|
|
|
|
LongLong GetCyclesDifference(DELAY_FUNC, unsigned int);
|
|
|
|
|
2008-06-01 22:40:11 +04:00
|
|
|
// For Linux and Cygwin, /proc/cpuinfo formats are slightly different
|
2008-01-31 22:34:11 +03:00
|
|
|
int RetreiveInformationFromCpuInfoFile();
|
|
|
|
kwsys_stl::string ExtractValueFromCpuInfoFile(kwsys_stl::string buffer,
|
2008-02-01 19:34:42 +03:00
|
|
|
const char* word, size_t init=0);
|
2008-01-31 22:34:11 +03:00
|
|
|
|
|
|
|
static void Delay (unsigned int);
|
|
|
|
static void DelayOverhead (unsigned int);
|
|
|
|
|
|
|
|
void FindManufacturer();
|
|
|
|
|
|
|
|
// For Mac
|
|
|
|
bool ParseSysCtl();
|
2009-10-06 19:46:16 +04:00
|
|
|
void CallSwVers();
|
2009-10-08 18:56:55 +04:00
|
|
|
void TrimNewline(kwsys_stl::string&);
|
2008-01-31 22:34:11 +03:00
|
|
|
kwsys_stl::string ExtractValueFromSysCtl(const char* word);
|
|
|
|
kwsys_stl::string SysCtlBuffer;
|
|
|
|
|
|
|
|
// For Solaris
|
|
|
|
bool QuerySolarisInfo();
|
|
|
|
kwsys_stl::string ParseValueFromKStat(const char* arguments);
|
|
|
|
kwsys_stl::string RunProcess(kwsys_stl::vector<const char*> args);
|
|
|
|
|
2009-02-12 18:08:15 +03:00
|
|
|
//For Haiku OS
|
|
|
|
bool QueryHaikuInfo();
|
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
// Evaluate the memory information.
|
|
|
|
int QueryMemory();
|
2009-11-15 23:57:06 +03:00
|
|
|
size_t TotalVirtualMemory;
|
|
|
|
size_t AvailableVirtualMemory;
|
|
|
|
size_t TotalPhysicalMemory;
|
|
|
|
size_t AvailablePhysicalMemory;
|
2008-01-31 22:34:11 +03:00
|
|
|
|
2008-02-01 19:33:14 +03:00
|
|
|
size_t CurrentPositionInFile;
|
2008-01-31 22:34:11 +03:00
|
|
|
|
|
|
|
// Operating System information
|
|
|
|
bool QueryOSInformation();
|
|
|
|
kwsys_stl::string OSName;
|
|
|
|
kwsys_stl::string Hostname;
|
|
|
|
kwsys_stl::string OSRelease;
|
|
|
|
kwsys_stl::string OSVersion;
|
|
|
|
kwsys_stl::string OSPlatform;
|
|
|
|
};
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
SystemInformation::SystemInformation()
|
2008-01-31 22:34:11 +03:00
|
|
|
{
|
|
|
|
this->Implementation = new SystemInformationImplementation;
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
SystemInformation::~SystemInformation()
|
2008-01-31 22:34:11 +03:00
|
|
|
{
|
|
|
|
delete this->Implementation;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * SystemInformation::GetVendorString()
|
|
|
|
{
|
|
|
|
return this->Implementation->GetVendorString();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
const char * SystemInformation::GetVendorID()
|
|
|
|
{
|
|
|
|
return this->Implementation->GetVendorID();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
kwsys_stl::string SystemInformation::GetTypeID()
|
|
|
|
{
|
|
|
|
return this->Implementation->GetTypeID();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
kwsys_stl::string SystemInformation::GetFamilyID()
|
|
|
|
{
|
|
|
|
return this->Implementation->GetFamilyID();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
kwsys_stl::string SystemInformation::GetModelID()
|
|
|
|
{
|
|
|
|
return this->Implementation->GetModelID();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
kwsys_stl::string SystemInformation::GetSteppingCode()
|
|
|
|
{
|
|
|
|
return this->Implementation->GetSteppingCode();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
const char * SystemInformation::GetExtendedProcessorName()
|
|
|
|
{
|
|
|
|
return this->Implementation->GetExtendedProcessorName();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
const char * SystemInformation::GetProcessorSerialNumber()
|
|
|
|
{
|
|
|
|
return this->Implementation->GetProcessorSerialNumber();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
int SystemInformation::GetProcessorCacheSize()
|
|
|
|
{
|
|
|
|
return this->Implementation->GetProcessorCacheSize();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2009-03-20 05:48:05 +03:00
|
|
|
unsigned int SystemInformation::GetLogicalProcessorsPerPhysical()
|
2008-01-31 22:34:11 +03:00
|
|
|
{
|
|
|
|
return this->Implementation->GetLogicalProcessorsPerPhysical();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
float SystemInformation::GetProcessorClockFrequency()
|
|
|
|
{
|
|
|
|
return this->Implementation->GetProcessorClockFrequency();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
int SystemInformation::GetProcessorAPICID()
|
|
|
|
{
|
|
|
|
return this->Implementation->GetProcessorAPICID();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
int SystemInformation::GetProcessorCacheXSize(long int l)
|
|
|
|
{
|
|
|
|
return this->Implementation->GetProcessorCacheXSize(l);
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformation::DoesCPUSupportFeature(long int i)
|
|
|
|
{
|
|
|
|
return this->Implementation->DoesCPUSupportFeature(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char * SystemInformation::GetOSName()
|
|
|
|
{
|
|
|
|
return this->Implementation->GetOSName();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
const char * SystemInformation::GetHostname()
|
|
|
|
{
|
|
|
|
return this->Implementation->GetHostname();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
const char * SystemInformation::GetOSRelease()
|
|
|
|
{
|
|
|
|
return this->Implementation->GetOSRelease();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
const char * SystemInformation::GetOSVersion()
|
|
|
|
{
|
|
|
|
return this->Implementation->GetOSVersion();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
const char * SystemInformation::GetOSPlatform()
|
|
|
|
{
|
|
|
|
return this->Implementation->GetOSPlatform();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemInformation::Is64Bits()
|
|
|
|
{
|
|
|
|
return this->Implementation->Is64Bits();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int SystemInformation::GetNumberOfLogicalCPU() // per physical cpu
|
|
|
|
{
|
|
|
|
return this->Implementation->GetNumberOfLogicalCPU();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
unsigned int SystemInformation::GetNumberOfPhysicalCPU()
|
|
|
|
{
|
|
|
|
return this->Implementation->GetNumberOfPhysicalCPU();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SystemInformation::DoesCPUSupportCPUID()
|
|
|
|
{
|
|
|
|
return this->Implementation->DoesCPUSupportCPUID();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve memory information in megabyte.
|
2009-11-16 20:43:44 +03:00
|
|
|
size_t SystemInformation::GetTotalVirtualMemory()
|
2008-01-31 22:34:11 +03:00
|
|
|
{
|
|
|
|
return this->Implementation->GetTotalVirtualMemory();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2009-11-16 20:43:44 +03:00
|
|
|
size_t SystemInformation::GetAvailableVirtualMemory()
|
2008-01-31 22:34:11 +03:00
|
|
|
{
|
|
|
|
return this->Implementation->GetAvailableVirtualMemory();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2009-11-16 20:43:44 +03:00
|
|
|
size_t SystemInformation::GetTotalPhysicalMemory()
|
2008-01-31 22:34:11 +03:00
|
|
|
{
|
|
|
|
return this->Implementation->GetTotalPhysicalMemory();
|
|
|
|
}
|
|
|
|
|
2009-11-16 20:43:44 +03:00
|
|
|
size_t SystemInformation::GetAvailablePhysicalMemory()
|
2008-01-31 22:34:11 +03:00
|
|
|
{
|
|
|
|
return this->Implementation->GetAvailablePhysicalMemory();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Run the different checks */
|
|
|
|
void SystemInformation::RunCPUCheck()
|
|
|
|
{
|
2008-02-01 05:33:32 +03:00
|
|
|
this->Implementation->RunCPUCheck();
|
2008-01-31 22:34:11 +03:00
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
void SystemInformation::RunOSCheck()
|
|
|
|
{
|
2008-02-01 05:33:32 +03:00
|
|
|
this->Implementation->RunOSCheck();
|
2008-01-31 22:34:11 +03:00
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
void SystemInformation::RunMemoryCheck()
|
|
|
|
{
|
2008-02-01 05:33:32 +03:00
|
|
|
this->Implementation->RunMemoryCheck();
|
2008-01-31 22:34:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// --------------------------------------------------------------
|
|
|
|
// SystemInformationImplementation starts here
|
|
|
|
|
2008-01-31 23:10:19 +03:00
|
|
|
#if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(_WIN64)
|
|
|
|
#define USE_ASM_INSTRUCTIONS 1
|
|
|
|
#else
|
|
|
|
#define USE_ASM_INSTRUCTIONS 0
|
|
|
|
#endif
|
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
#define STORE_TLBCACHE_INFO(x,y) x = (x < y) ? y : x
|
|
|
|
#define TLBCACHE_INFO_UNITS (15)
|
|
|
|
#define CLASSICAL_CPU_FREQ_LOOP 10000000
|
|
|
|
#define RDTSC_INSTRUCTION _asm _emit 0x0f _asm _emit 0x31
|
|
|
|
|
|
|
|
#define CPUID_AWARE_COMPILER
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
#define CPUID_INSTRUCTION cpuid
|
|
|
|
#else
|
|
|
|
#define CPUID_INSTRUCTION _asm _emit 0x0f _asm _emit 0xa2
|
|
|
|
#endif
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
#define MMX_FEATURE 0x00000001
|
|
|
|
#define MMX_PLUS_FEATURE 0x00000002
|
|
|
|
#define SSE_FEATURE 0x00000004
|
|
|
|
#define SSE2_FEATURE 0x00000008
|
2008-01-31 22:34:11 +03:00
|
|
|
#define AMD_3DNOW_FEATURE 0x00000010
|
2009-12-11 21:08:29 +03:00
|
|
|
#define AMD_3DNOW_PLUS_FEATURE 0x00000020
|
|
|
|
#define IA64_FEATURE 0x00000040
|
|
|
|
#define MP_CAPABLE 0x00000080
|
|
|
|
#define HYPERTHREAD_FEATURE 0x00000100
|
|
|
|
#define SERIALNUMBER_FEATURE 0x00000200
|
|
|
|
#define APIC_FEATURE 0x00000400
|
|
|
|
#define SSE_FP_FEATURE 0x00000800
|
2008-01-31 22:34:11 +03:00
|
|
|
#define SSE_MMX_FEATURE 0x00001000
|
2009-12-11 21:08:29 +03:00
|
|
|
#define CMOV_FEATURE 0x00002000
|
|
|
|
#define MTRR_FEATURE 0x00004000
|
2008-01-31 22:34:11 +03:00
|
|
|
#define L1CACHE_FEATURE 0x00008000
|
|
|
|
#define L2CACHE_FEATURE 0x00010000
|
|
|
|
#define L3CACHE_FEATURE 0x00020000
|
2009-12-11 21:08:29 +03:00
|
|
|
#define ACPI_FEATURE 0x00040000
|
|
|
|
#define THERMALMONITOR_FEATURE 0x00080000
|
|
|
|
#define TEMPSENSEDIODE_FEATURE 0x00100000
|
|
|
|
#define FREQUENCYID_FEATURE 0x00200000
|
|
|
|
#define VOLTAGEID_FREQUENCY 0x00400000
|
2008-01-31 22:34:11 +03:00
|
|
|
|
|
|
|
// Status Flag
|
|
|
|
#define HT_NOT_CAPABLE 0
|
|
|
|
#define HT_ENABLED 1
|
|
|
|
#define HT_DISABLED 2
|
|
|
|
#define HT_SUPPORTED_NOT_ENABLED 3
|
|
|
|
#define HT_CANNOT_DETECT 4
|
|
|
|
|
|
|
|
// EDX[28] Bit 28 is set if HT is supported
|
|
|
|
#define HT_BIT 0x10000000
|
|
|
|
|
|
|
|
// EAX[11:8] Bit 8-11 contains family processor ID.
|
|
|
|
#define FAMILY_ID 0x0F00
|
|
|
|
#define PENTIUM4_ID 0x0F00
|
|
|
|
// EAX[23:20] Bit 20-23 contains extended family processor ID
|
|
|
|
#define EXT_FAMILY_ID 0x0F00000
|
|
|
|
// EBX[23:16] Bit 16-23 in ebx contains the number of logical
|
|
|
|
#define NUM_LOGICAL_BITS 0x00FF0000
|
|
|
|
// processors per physical processor when execute cpuid with
|
|
|
|
// eax set to 1
|
|
|
|
// EBX[31:24] Bits 24-31 (8 bits) return the 8-bit unique
|
|
|
|
#define INITIAL_APIC_ID_BITS 0xFF000000
|
|
|
|
// initial APIC ID for the processor this code is running on.
|
|
|
|
// Default value = 0xff if HT is not supported
|
|
|
|
|
|
|
|
|
|
|
|
SystemInformationImplementation::SystemInformationImplementation()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
this->TotalVirtualMemory = 0;
|
|
|
|
this->AvailableVirtualMemory = 0;
|
|
|
|
this->TotalPhysicalMemory = 0;
|
|
|
|
this->AvailablePhysicalMemory = 0;
|
|
|
|
this->CurrentPositionInFile = 0;
|
|
|
|
this->ChipManufacturer = UnknownManufacturer;
|
|
|
|
memset(&this->Features, 0, sizeof(CPUFeatures));
|
|
|
|
memset(&this->ChipID, 0, sizeof(ID));
|
|
|
|
this->CPUSpeedInMHz = 0;
|
|
|
|
this->NumberOfLogicalCPU = 0;
|
|
|
|
this->NumberOfPhysicalCPU = 0;
|
|
|
|
this->OSName = "";
|
|
|
|
this->Hostname = "";
|
|
|
|
this->OSRelease = "";
|
|
|
|
this->OSVersion = "";
|
|
|
|
this->OSPlatform = "";
|
|
|
|
}
|
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
SystemInformationImplementation::~SystemInformationImplementation()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
void SystemInformationImplementation::RunCPUCheck()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
#ifdef WIN32
|
|
|
|
// Check to see if this processor supports CPUID.
|
2009-12-11 21:08:29 +03:00
|
|
|
bool supportsCPUID = DoesCPUSupportCPUID();
|
|
|
|
|
|
|
|
if (supportsCPUID)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
// Retrieve the CPU details.
|
|
|
|
RetrieveCPUIdentity();
|
|
|
|
RetrieveCPUFeatures();
|
2009-12-11 21:08:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// These two may be called without support for the CPUID instruction.
|
|
|
|
// (But if the instruction is there, they should be called *after*
|
|
|
|
// the above call to RetrieveCPUIdentity... that's why the two if
|
|
|
|
// blocks exist with the same "if (supportsCPUID)" logic...
|
|
|
|
//
|
|
|
|
if (!RetrieveCPUClockSpeed())
|
|
|
|
{
|
|
|
|
RetrieveClassicalCPUClockSpeed();
|
|
|
|
}
|
2008-01-08 19:38:28 +03:00
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
if (supportsCPUID)
|
|
|
|
{
|
|
|
|
// Retrieve cache information.
|
2008-01-08 19:38:28 +03:00
|
|
|
if (!RetrieveCPUCacheDetails())
|
|
|
|
{
|
|
|
|
RetrieveClassicalCPUCacheDetails();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
// Retrieve the extended CPU details.
|
|
|
|
if (!RetrieveExtendedCPUIdentity())
|
|
|
|
{
|
|
|
|
RetrieveClassicalCPUIdentity();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
RetrieveExtendedCPUFeatures();
|
2009-12-11 21:08:29 +03:00
|
|
|
RetrieveCPUPowerManagement();
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
// Now attempt to retrieve the serial number (if possible).
|
|
|
|
RetrieveProcessorSerialNumber();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
this->CPUCount();
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
#elif defined(__APPLE__)
|
|
|
|
this->ParseSysCtl();
|
|
|
|
#elif defined (__SVR4) && defined (__sun)
|
|
|
|
this->QuerySolarisInfo();
|
2009-02-12 18:08:15 +03:00
|
|
|
#elif defined(__HAIKU__)
|
|
|
|
this->QueryHaikuInfo();
|
2008-01-08 19:38:28 +03:00
|
|
|
#else
|
|
|
|
this->RetreiveInformationFromCpuInfoFile();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
void SystemInformationImplementation::RunOSCheck()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
this->QueryOSInformation();
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
void SystemInformationImplementation::RunMemoryCheck()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
this->ParseSysCtl();
|
|
|
|
#elif defined (__SVR4) && defined (__sun)
|
|
|
|
this->QuerySolarisInfo();
|
2009-02-12 18:08:15 +03:00
|
|
|
#elif defined(__HAIKU__)
|
|
|
|
this->QueryHaikuInfo();
|
2008-01-08 19:38:28 +03:00
|
|
|
#else
|
|
|
|
this->QueryMemory();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the vendor string */
|
2008-01-31 22:34:11 +03:00
|
|
|
const char * SystemInformationImplementation::GetVendorString()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->ChipID.Vendor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the OS Name */
|
2008-01-31 22:34:11 +03:00
|
|
|
const char * SystemInformationImplementation::GetOSName()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->OSName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the hostname */
|
2008-01-31 22:34:11 +03:00
|
|
|
const char* SystemInformationImplementation::GetHostname()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->Hostname.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the OS release */
|
2008-01-31 22:34:11 +03:00
|
|
|
const char* SystemInformationImplementation::GetOSRelease()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->OSRelease.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the OS version */
|
2008-01-31 22:34:11 +03:00
|
|
|
const char* SystemInformationImplementation::GetOSVersion()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->OSVersion.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the OS platform */
|
2008-01-31 22:34:11 +03:00
|
|
|
const char* SystemInformationImplementation::GetOSPlatform()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->OSPlatform.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get the vendor ID */
|
2008-01-31 22:34:11 +03:00
|
|
|
const char * SystemInformationImplementation::GetVendorID()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
// Return the vendor ID.
|
2009-12-11 21:08:29 +03:00
|
|
|
switch (this->ChipManufacturer)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
case Intel:
|
|
|
|
return "Intel Corporation";
|
|
|
|
case AMD:
|
|
|
|
return "Advanced Micro Devices";
|
|
|
|
case NSC:
|
|
|
|
return "National Semiconductor";
|
|
|
|
case Cyrix:
|
|
|
|
return "Cyrix Corp., VIA Inc.";
|
|
|
|
case NexGen:
|
|
|
|
return "NexGen Inc., Advanced Micro Devices";
|
|
|
|
case IDT:
|
|
|
|
return "IDT\\Centaur, Via Inc.";
|
|
|
|
case UMC:
|
|
|
|
return "United Microelectronics Corp.";
|
|
|
|
case Rise:
|
|
|
|
return "Rise";
|
|
|
|
case Transmeta:
|
|
|
|
return "Transmeta";
|
|
|
|
case Sun:
|
|
|
|
return "Sun Microelectronics";
|
2009-05-20 17:50:20 +04:00
|
|
|
case IBM:
|
|
|
|
return "IBM";
|
|
|
|
case Motorola:
|
|
|
|
return "Motorola";
|
2008-01-08 19:38:28 +03:00
|
|
|
default:
|
|
|
|
return "Unknown Manufacturer";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the type ID of the CPU */
|
2008-01-31 22:34:11 +03:00
|
|
|
kwsys_stl::string SystemInformationImplementation::GetTypeID()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-01-08 22:59:57 +03:00
|
|
|
kwsys_ios::ostringstream str;
|
|
|
|
str << this->ChipID.Type;
|
|
|
|
return str.str();
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the family of the CPU present */
|
2008-01-31 22:34:11 +03:00
|
|
|
kwsys_stl::string SystemInformationImplementation::GetFamilyID()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-01-08 22:59:57 +03:00
|
|
|
kwsys_ios::ostringstream str;
|
|
|
|
str << this->ChipID.Family;
|
|
|
|
return str.str();
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return the model of CPU present */
|
2008-01-31 22:34:11 +03:00
|
|
|
kwsys_stl::string SystemInformationImplementation::GetModelID()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-01-08 22:59:57 +03:00
|
|
|
kwsys_ios::ostringstream str;
|
|
|
|
str << this->ChipID.Model;
|
|
|
|
return str.str();
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the stepping code of the CPU present. */
|
2008-01-31 22:34:11 +03:00
|
|
|
kwsys_stl::string SystemInformationImplementation::GetSteppingCode()
|
2008-01-08 22:59:57 +03:00
|
|
|
{
|
|
|
|
kwsys_ios::ostringstream str;
|
|
|
|
str << this->ChipID.Revision;
|
|
|
|
return str.str();
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the stepping code of the CPU present. */
|
2008-01-31 22:34:11 +03:00
|
|
|
const char * SystemInformationImplementation::GetExtendedProcessorName()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->ChipID.ProcessorName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the serial number of the processor
|
|
|
|
* in hexadecimal: xxxx-xxxx-xxxx-xxxx-xxxx-xxxx. */
|
2008-01-31 22:34:11 +03:00
|
|
|
const char * SystemInformationImplementation::GetProcessorSerialNumber()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->ChipID.SerialNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the logical processors per physical */
|
2009-03-20 05:48:05 +03:00
|
|
|
unsigned int SystemInformationImplementation::GetLogicalProcessorsPerPhysical()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the processor clock frequency. */
|
2008-01-31 22:34:11 +03:00
|
|
|
float SystemInformationImplementation::GetProcessorClockFrequency()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->CPUSpeedInMHz;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the APIC ID. */
|
2008-01-31 22:34:11 +03:00
|
|
|
int SystemInformationImplementation::GetProcessorAPICID()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->Features.ExtendedFeatures.APIC_ID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the L1 cache size. */
|
2008-01-31 22:34:11 +03:00
|
|
|
int SystemInformationImplementation::GetProcessorCacheSize()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->Features.L1CacheSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the chosen cache size. */
|
2008-01-31 22:34:11 +03:00
|
|
|
int SystemInformationImplementation::GetProcessorCacheXSize(long int dwCacheID)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2009-12-11 21:08:29 +03:00
|
|
|
switch (dwCacheID)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
case L1CACHE_FEATURE:
|
|
|
|
return this->Features.L1CacheSize;
|
|
|
|
case L2CACHE_FEATURE:
|
|
|
|
return this->Features.L2CacheSize;
|
|
|
|
case L3CACHE_FEATURE:
|
|
|
|
return this->Features.L3CacheSize;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformationImplementation::DoesCPUSupportFeature(long int dwFeature)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
bool bHasFeature = false;
|
|
|
|
|
|
|
|
// Check for MMX instructions.
|
|
|
|
if (((dwFeature & MMX_FEATURE) != 0) && this->Features.HasMMX) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for MMX+ instructions.
|
|
|
|
if (((dwFeature & MMX_PLUS_FEATURE) != 0) && this->Features.ExtendedFeatures.HasMMXPlus) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for SSE FP instructions.
|
|
|
|
if (((dwFeature & SSE_FEATURE) != 0) && this->Features.HasSSE) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for SSE FP instructions.
|
|
|
|
if (((dwFeature & SSE_FP_FEATURE) != 0) && this->Features.HasSSEFP) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for SSE MMX instructions.
|
|
|
|
if (((dwFeature & SSE_MMX_FEATURE) != 0) && this->Features.ExtendedFeatures.HasSSEMMX) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for SSE2 instructions.
|
|
|
|
if (((dwFeature & SSE2_FEATURE) != 0) && this->Features.HasSSE2) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for 3DNow! instructions.
|
|
|
|
if (((dwFeature & AMD_3DNOW_FEATURE) != 0) && this->Features.ExtendedFeatures.Has3DNow) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for 3DNow+ instructions.
|
|
|
|
if (((dwFeature & AMD_3DNOW_PLUS_FEATURE) != 0) && this->Features.ExtendedFeatures.Has3DNowPlus) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for IA64 instructions.
|
|
|
|
if (((dwFeature & IA64_FEATURE) != 0) && this->Features.HasIA64) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for MP capable.
|
|
|
|
if (((dwFeature & MP_CAPABLE) != 0) && this->Features.ExtendedFeatures.SupportsMP) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for a serial number for the processor.
|
|
|
|
if (((dwFeature & SERIALNUMBER_FEATURE) != 0) && this->Features.HasSerial) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for a local APIC in the processor.
|
|
|
|
if (((dwFeature & APIC_FEATURE) != 0) && this->Features.HasAPIC) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for CMOV instructions.
|
|
|
|
if (((dwFeature & CMOV_FEATURE) != 0) && this->Features.HasCMOV) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for MTRR instructions.
|
|
|
|
if (((dwFeature & MTRR_FEATURE) != 0) && this->Features.HasMTRR) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for L1 cache size.
|
|
|
|
if (((dwFeature & L1CACHE_FEATURE) != 0) && (this->Features.L1CacheSize != -1)) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for L2 cache size.
|
|
|
|
if (((dwFeature & L2CACHE_FEATURE) != 0) && (this->Features.L2CacheSize != -1)) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for L3 cache size.
|
|
|
|
if (((dwFeature & L3CACHE_FEATURE) != 0) && (this->Features.L3CacheSize != -1)) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for ACPI capability.
|
|
|
|
if (((dwFeature & ACPI_FEATURE) != 0) && this->Features.HasACPI) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for thermal monitor support.
|
|
|
|
if (((dwFeature & THERMALMONITOR_FEATURE) != 0) && this->Features.HasThermal) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for temperature sensing diode support.
|
|
|
|
if (((dwFeature & TEMPSENSEDIODE_FEATURE) != 0) && this->Features.ExtendedFeatures.PowerManagement.HasTempSenseDiode) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for frequency ID support.
|
|
|
|
if (((dwFeature & FREQUENCYID_FEATURE) != 0) && this->Features.ExtendedFeatures.PowerManagement.HasFrequencyID) bHasFeature = true;
|
|
|
|
|
|
|
|
// Check for voltage ID support.
|
|
|
|
if (((dwFeature & VOLTAGEID_FREQUENCY) != 0) && this->Features.ExtendedFeatures.PowerManagement.HasVoltageID) bHasFeature = true;
|
|
|
|
|
|
|
|
return bHasFeature;
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
void SystemInformationImplementation::Delay(unsigned int uiMS)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
#ifdef WIN32
|
|
|
|
LARGE_INTEGER Frequency, StartCounter, EndCounter;
|
|
|
|
__int64 x;
|
|
|
|
|
|
|
|
// Get the frequency of the high performance counter.
|
|
|
|
if (!QueryPerformanceFrequency (&Frequency)) return;
|
|
|
|
x = Frequency.QuadPart / 1000 * uiMS;
|
|
|
|
|
|
|
|
// Get the starting position of the counter.
|
|
|
|
QueryPerformanceCounter (&StartCounter);
|
|
|
|
|
|
|
|
do {
|
|
|
|
// Get the ending position of the counter.
|
|
|
|
QueryPerformanceCounter (&EndCounter);
|
|
|
|
} while (EndCounter.QuadPart - StartCounter.QuadPart < x);
|
|
|
|
#endif
|
2008-01-09 01:20:04 +03:00
|
|
|
(void)uiMS;
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformationImplementation::DoesCPUSupportCPUID()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-02-01 19:09:39 +03:00
|
|
|
#if USE_ASM_INSTRUCTIONS
|
2008-01-08 19:38:28 +03:00
|
|
|
// Use SEH to determine CPUID presence
|
|
|
|
__try {
|
|
|
|
_asm {
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
; we must push/pop the registers <<CPUID>> writes to, as the
|
|
|
|
; optimiser doesn't know about <<CPUID>>, and so doesn't expect
|
|
|
|
; these registers to change.
|
|
|
|
push eax
|
|
|
|
push ebx
|
|
|
|
push ecx
|
|
|
|
push edx
|
|
|
|
#endif
|
|
|
|
; <<CPUID>>
|
|
|
|
mov eax, 0
|
|
|
|
CPUID_INSTRUCTION
|
|
|
|
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__except(1)
|
|
|
|
{
|
|
|
|
// Stop the class from trying to use CPUID again!
|
|
|
|
return false;
|
|
|
|
}
|
2008-05-02 17:14:37 +04:00
|
|
|
|
|
|
|
// The cpuid instruction succeeded.
|
|
|
|
return true;
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
#else
|
2008-05-02 17:14:37 +04:00
|
|
|
// Assume no cpuid instruction.
|
|
|
|
return false;
|
2008-01-08 19:38:28 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformationImplementation::RetrieveCPUFeatures()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-02-01 19:09:39 +03:00
|
|
|
#if USE_ASM_INSTRUCTIONS
|
2008-01-09 01:20:04 +03:00
|
|
|
int localCPUFeatures = 0;
|
|
|
|
int localCPUAdvanced = 0;
|
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
// Use assembly to detect CPUID information...
|
|
|
|
__try {
|
|
|
|
_asm {
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
; we must push/pop the registers <<CPUID>> writes to, as the
|
|
|
|
; optimiser doesn't know about <<CPUID>>, and so doesn't expect
|
|
|
|
; these registers to change.
|
|
|
|
push eax
|
|
|
|
push ebx
|
|
|
|
push ecx
|
|
|
|
push edx
|
|
|
|
#endif
|
|
|
|
; <<CPUID>>
|
|
|
|
; eax = 1 --> eax: CPU ID - bits 31..16 - unused, bits 15..12 - type, bits 11..8 - family, bits 7..4 - model, bits 3..0 - mask revision
|
|
|
|
; ebx: 31..24 - default APIC ID, 23..16 - logical processsor ID, 15..8 - CFLUSH chunk size , 7..0 - brand ID
|
|
|
|
; edx: CPU feature flags
|
|
|
|
mov eax,1
|
|
|
|
CPUID_INSTRUCTION
|
2008-01-09 01:20:04 +03:00
|
|
|
mov localCPUFeatures, edx
|
|
|
|
mov localCPUAdvanced, ebx
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__except(1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve the features of CPU present.
|
2009-12-11 21:08:29 +03:00
|
|
|
this->Features.HasFPU = ((localCPUFeatures & 0x00000001) != 0); // FPU Present --> Bit 0
|
|
|
|
this->Features.HasTSC = ((localCPUFeatures & 0x00000010) != 0); // TSC Present --> Bit 4
|
2008-01-09 01:20:04 +03:00
|
|
|
this->Features.HasAPIC = ((localCPUFeatures & 0x00000200) != 0); // APIC Present --> Bit 9
|
|
|
|
this->Features.HasMTRR = ((localCPUFeatures & 0x00001000) != 0); // MTRR Present --> Bit 12
|
|
|
|
this->Features.HasCMOV = ((localCPUFeatures & 0x00008000) != 0); // CMOV Present --> Bit 15
|
|
|
|
this->Features.HasSerial = ((localCPUFeatures & 0x00040000) != 0); // Serial Present --> Bit 18
|
|
|
|
this->Features.HasACPI = ((localCPUFeatures & 0x00400000) != 0); // ACPI Capable --> Bit 22
|
2009-12-11 21:08:29 +03:00
|
|
|
this->Features.HasMMX = ((localCPUFeatures & 0x00800000) != 0); // MMX Present --> Bit 23
|
|
|
|
this->Features.HasSSE = ((localCPUFeatures & 0x02000000) != 0); // SSE Present --> Bit 25
|
2008-01-09 01:20:04 +03:00
|
|
|
this->Features.HasSSE2 = ((localCPUFeatures & 0x04000000) != 0); // SSE2 Present --> Bit 26
|
2009-12-11 21:08:29 +03:00
|
|
|
this->Features.HasThermal = ((localCPUFeatures & 0x20000000) != 0); // Thermal Monitor Present --> Bit 29
|
2008-01-09 01:20:04 +03:00
|
|
|
this->Features.HasIA64 = ((localCPUFeatures & 0x40000000) != 0); // IA64 Present --> Bit 30
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
// Retrieve extended SSE capabilities if SSE is available.
|
|
|
|
if (this->Features.HasSSE) {
|
|
|
|
|
|
|
|
// Attempt to __try some SSE FP instructions.
|
|
|
|
__try
|
|
|
|
{
|
|
|
|
// Perform: orps xmm0, xmm0
|
|
|
|
_asm
|
|
|
|
{
|
|
|
|
_emit 0x0f
|
|
|
|
_emit 0x56
|
|
|
|
_emit 0xc0
|
|
|
|
}
|
|
|
|
|
|
|
|
// SSE FP capable processor.
|
|
|
|
this->Features.HasSSEFP = true;
|
|
|
|
}
|
|
|
|
__except(1)
|
|
|
|
{
|
|
|
|
// bad instruction - processor or OS cannot handle SSE FP.
|
|
|
|
this->Features.HasSSEFP = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Set the advanced SSE capabilities to not available.
|
|
|
|
this->Features.HasSSEFP = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve Intel specific extended features.
|
|
|
|
if (this->ChipManufacturer == Intel)
|
|
|
|
{
|
2008-01-09 01:20:04 +03:00
|
|
|
this->Features.ExtendedFeatures.SupportsHyperthreading = ((localCPUFeatures & 0x10000000) != 0); // Intel specific: Hyperthreading --> Bit 28
|
|
|
|
this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = (this->Features.ExtendedFeatures.SupportsHyperthreading) ? ((localCPUAdvanced & 0x00FF0000) >> 16) : 1;
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
if ((this->Features.ExtendedFeatures.SupportsHyperthreading) && (this->Features.HasAPIC))
|
|
|
|
{
|
|
|
|
// Retrieve APIC information if there is one present.
|
2008-01-09 01:20:04 +03:00
|
|
|
this->Features.ExtendedFeatures.APIC_ID = ((localCPUAdvanced & 0xFF000000) >> 24);
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
return true;
|
2009-12-11 21:08:29 +03:00
|
|
|
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Find the manufacturer given the vendor id */
|
2008-01-31 22:34:11 +03:00
|
|
|
void SystemInformationImplementation::FindManufacturer()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2009-12-11 21:08:29 +03:00
|
|
|
if (strcmp (this->ChipID.Vendor, "GenuineIntel") == 0) this->ChipManufacturer = Intel; // Intel Corp.
|
2008-01-08 19:38:28 +03:00
|
|
|
else if (strcmp (this->ChipID.Vendor, "UMC UMC UMC ") == 0) this->ChipManufacturer = UMC; // United Microelectronics Corp.
|
|
|
|
else if (strcmp (this->ChipID.Vendor, "AuthenticAMD") == 0) this->ChipManufacturer = AMD; // Advanced Micro Devices
|
|
|
|
else if (strcmp (this->ChipID.Vendor, "AMD ISBETTER") == 0) this->ChipManufacturer = AMD; // Advanced Micro Devices (1994)
|
|
|
|
else if (strcmp (this->ChipID.Vendor, "CyrixInstead") == 0) this->ChipManufacturer = Cyrix; // Cyrix Corp., VIA Inc.
|
|
|
|
else if (strcmp (this->ChipID.Vendor, "NexGenDriven") == 0) this->ChipManufacturer = NexGen; // NexGen Inc. (now AMD)
|
|
|
|
else if (strcmp (this->ChipID.Vendor, "CentaurHauls") == 0) this->ChipManufacturer = IDT; // IDT/Centaur (now VIA)
|
|
|
|
else if (strcmp (this->ChipID.Vendor, "RiseRiseRise") == 0) this->ChipManufacturer = Rise; // Rise
|
|
|
|
else if (strcmp (this->ChipID.Vendor, "GenuineTMx86") == 0) this->ChipManufacturer = Transmeta; // Transmeta
|
|
|
|
else if (strcmp (this->ChipID.Vendor, "TransmetaCPU") == 0) this->ChipManufacturer = Transmeta; // Transmeta
|
|
|
|
else if (strcmp (this->ChipID.Vendor, "Geode By NSC") == 0) this->ChipManufacturer = NSC; // National Semiconductor
|
2009-05-20 17:50:20 +04:00
|
|
|
else if (strcmp (this->ChipID.Vendor, "Sun") == 0) this->ChipManufacturer = Sun; // Sun Microelectronics
|
|
|
|
else if (strcmp (this->ChipID.Vendor, "IBM") == 0) this->ChipManufacturer = IBM; // IBM Microelectronics
|
|
|
|
else if (strcmp (this->ChipID.Vendor, "Motorola") == 0) this->ChipManufacturer = Motorola; // Motorola Microelectronics
|
2009-12-11 21:08:29 +03:00
|
|
|
else this->ChipManufacturer = UnknownManufacturer; // Unknown manufacturer
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** */
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformationImplementation::RetrieveCPUIdentity()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-01-31 23:10:19 +03:00
|
|
|
#if USE_ASM_INSTRUCTIONS
|
2008-01-09 01:20:04 +03:00
|
|
|
int localCPUVendor[3];
|
2008-01-09 01:51:05 +03:00
|
|
|
int localCPUSignature;
|
2008-01-09 01:20:04 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
// Use assembly to detect CPUID information...
|
|
|
|
__try
|
|
|
|
{
|
|
|
|
_asm
|
|
|
|
{
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
; we must push/pop the registers <<CPUID>> writes to, as the
|
|
|
|
; optimiser doesn't know about <<CPUID>>, and so doesn't expect
|
|
|
|
; these registers to change.
|
|
|
|
push eax
|
|
|
|
push ebx
|
|
|
|
push ecx
|
|
|
|
push edx
|
|
|
|
#endif
|
|
|
|
; <<CPUID>>
|
|
|
|
; eax = 0 --> eax: maximum value of CPUID instruction.
|
|
|
|
; ebx: part 1 of 3; CPU signature.
|
|
|
|
; edx: part 2 of 3; CPU signature.
|
|
|
|
; ecx: part 3 of 3; CPU signature.
|
|
|
|
mov eax, 0
|
|
|
|
CPUID_INSTRUCTION
|
2008-01-09 01:20:04 +03:00
|
|
|
mov localCPUVendor[0 * TYPE int], ebx
|
|
|
|
mov localCPUVendor[1 * TYPE int], edx
|
|
|
|
mov localCPUVendor[2 * TYPE int], ecx
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
; <<CPUID>>
|
|
|
|
; eax = 1 --> eax: CPU ID - bits 31..16 - unused, bits 15..12 - type, bits 11..8 - family, bits 7..4 - model, bits 3..0 - mask revision
|
|
|
|
; ebx: 31..24 - default APIC ID, 23..16 - logical processsor ID, 15..8 - CFLUSH chunk size , 7..0 - brand ID
|
|
|
|
; edx: CPU feature flags
|
|
|
|
mov eax,1
|
|
|
|
CPUID_INSTRUCTION
|
2008-01-09 01:20:04 +03:00
|
|
|
mov localCPUSignature, eax
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__except(1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process the returned information.
|
2008-01-09 01:20:04 +03:00
|
|
|
memcpy (this->ChipID.Vendor, &(localCPUVendor[0]), sizeof (int));
|
|
|
|
memcpy (&(this->ChipID.Vendor[4]), &(localCPUVendor[1]), sizeof (int));
|
|
|
|
memcpy (&(this->ChipID.Vendor[8]), &(localCPUVendor[2]), sizeof (int));
|
2008-01-08 19:38:28 +03:00
|
|
|
this->ChipID.Vendor[12] = '\0';
|
|
|
|
|
|
|
|
this->FindManufacturer();
|
|
|
|
|
|
|
|
// Retrieve the family of CPU present.
|
2008-01-09 01:20:04 +03:00
|
|
|
this->ChipID.ExtendedFamily = ((localCPUSignature & 0x0FF00000) >> 20); // Bits 27..20 Used
|
|
|
|
this->ChipID.ExtendedModel = ((localCPUSignature & 0x000F0000) >> 16); // Bits 19..16 Used
|
|
|
|
this->ChipID.Type = ((localCPUSignature & 0x0000F000) >> 12); // Bits 15..12 Used
|
|
|
|
this->ChipID.Family = ((localCPUSignature & 0x00000F00) >> 8); // Bits 11..8 Used
|
|
|
|
this->ChipID.Model = ((localCPUSignature & 0x000000F0) >> 4); // Bits 7..4 Used
|
|
|
|
this->ChipID.Revision = ((localCPUSignature & 0x0000000F) >> 0); // Bits 3..0 Used
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
return true;
|
2009-12-11 21:08:29 +03:00
|
|
|
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** */
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformationImplementation::RetrieveCPUCacheDetails()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-01-31 23:10:19 +03:00
|
|
|
#if USE_ASM_INSTRUCTIONS
|
2008-01-08 19:38:28 +03:00
|
|
|
int L1Cache[4] = { 0, 0, 0, 0 };
|
|
|
|
int L2Cache[4] = { 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
// Check to see if what we are about to do is supported...
|
|
|
|
if (RetrieveCPUExtendedLevelSupport (0x80000005))
|
|
|
|
{
|
|
|
|
// Use assembly to retrieve the L1 cache information ...
|
|
|
|
__try
|
|
|
|
{
|
|
|
|
_asm
|
|
|
|
{
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
; we must push/pop the registers <<CPUID>> writes to, as the
|
|
|
|
; optimiser doesn't know about <<CPUID>>, and so doesn't expect
|
|
|
|
; these registers to change.
|
|
|
|
push eax
|
|
|
|
push ebx
|
|
|
|
push ecx
|
|
|
|
push edx
|
|
|
|
#endif
|
|
|
|
; <<CPUID>>
|
|
|
|
; eax = 0x80000005 --> eax: L1 cache information - Part 1 of 4.
|
|
|
|
; ebx: L1 cache information - Part 2 of 4.
|
|
|
|
; edx: L1 cache information - Part 3 of 4.
|
|
|
|
; ecx: L1 cache information - Part 4 of 4.
|
|
|
|
mov eax, 0x80000005
|
|
|
|
CPUID_INSTRUCTION
|
|
|
|
mov L1Cache[0 * TYPE int], eax
|
|
|
|
mov L1Cache[1 * TYPE int], ebx
|
|
|
|
mov L1Cache[2 * TYPE int], ecx
|
|
|
|
mov L1Cache[3 * TYPE int], edx
|
|
|
|
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__except(1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Save the L1 data cache size (in KB) from ecx: bits 31..24 as well as data cache size from edx: bits 31..24.
|
|
|
|
this->Features.L1CacheSize = ((L1Cache[2] & 0xFF000000) >> 24);
|
|
|
|
this->Features.L1CacheSize += ((L1Cache[3] & 0xFF000000) >> 24);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Store -1 to indicate the cache could not be queried.
|
|
|
|
this->Features.L1CacheSize = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if what we are about to do is supported...
|
|
|
|
if (RetrieveCPUExtendedLevelSupport (0x80000006))
|
|
|
|
{
|
|
|
|
// Use assembly to retrieve the L2 cache information ...
|
|
|
|
__try
|
|
|
|
{
|
|
|
|
_asm
|
|
|
|
{
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
; we must push/pop the registers <<CPUID>> writes to, as the
|
|
|
|
; optimiser doesn't know about <<CPUID>>, and so doesn't expect
|
|
|
|
; these registers to change.
|
|
|
|
push eax
|
|
|
|
push ebx
|
|
|
|
push ecx
|
|
|
|
push edx
|
|
|
|
#endif
|
|
|
|
; <<CPUID>>
|
|
|
|
; eax = 0x80000006 --> eax: L2 cache information - Part 1 of 4.
|
|
|
|
; ebx: L2 cache information - Part 2 of 4.
|
|
|
|
; edx: L2 cache information - Part 3 of 4.
|
|
|
|
; ecx: L2 cache information - Part 4 of 4.
|
|
|
|
mov eax, 0x80000006
|
|
|
|
CPUID_INSTRUCTION
|
|
|
|
mov L2Cache[0 * TYPE int], eax
|
|
|
|
mov L2Cache[1 * TYPE int], ebx
|
|
|
|
mov L2Cache[2 * TYPE int], ecx
|
|
|
|
mov L2Cache[3 * TYPE int], edx
|
|
|
|
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__except(1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Save the L2 unified cache size (in KB) from ecx: bits 31..16.
|
|
|
|
this->Features.L2CacheSize = ((L2Cache[2] & 0xFFFF0000) >> 16);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Store -1 to indicate the cache could not be queried.
|
|
|
|
this->Features.L2CacheSize = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Define L3 as being not present as we cannot test for it.
|
|
|
|
this->Features.L3CacheSize = -1;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Return failure if we cannot detect either cache with this method.
|
|
|
|
return ((this->Features.L1CacheSize == -1) && (this->Features.L2CacheSize == -1)) ? false : true;
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** */
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformationImplementation::RetrieveClassicalCPUCacheDetails()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-01-31 23:10:19 +03:00
|
|
|
#if USE_ASM_INSTRUCTIONS
|
2008-01-08 19:38:28 +03:00
|
|
|
int TLBCode = -1, TLBData = -1, L1Code = -1, L1Data = -1, L1Trace = -1, L2Unified = -1, L3Unified = -1;
|
|
|
|
int TLBCacheData[4] = { 0, 0, 0, 0 };
|
|
|
|
int TLBPassCounter = 0;
|
|
|
|
int TLBCacheUnit = 0;
|
|
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
// Use assembly to retrieve the L2 cache information ...
|
|
|
|
__try {
|
|
|
|
_asm {
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
; we must push/pop the registers <<CPUID>> writes to, as the
|
|
|
|
; optimiser doesn't know about <<CPUID>>, and so doesn't expect
|
|
|
|
; these registers to change.
|
|
|
|
push eax
|
|
|
|
push ebx
|
|
|
|
push ecx
|
|
|
|
push edx
|
|
|
|
#endif
|
|
|
|
; <<CPUID>>
|
|
|
|
; eax = 2 --> eax: TLB and cache information - Part 1 of 4.
|
|
|
|
; ebx: TLB and cache information - Part 2 of 4.
|
|
|
|
; ecx: TLB and cache information - Part 3 of 4.
|
|
|
|
; edx: TLB and cache information - Part 4 of 4.
|
|
|
|
mov eax, 2
|
|
|
|
CPUID_INSTRUCTION
|
|
|
|
mov TLBCacheData[0 * TYPE int], eax
|
|
|
|
mov TLBCacheData[1 * TYPE int], ebx
|
|
|
|
mov TLBCacheData[2 * TYPE int], ecx
|
|
|
|
mov TLBCacheData[3 * TYPE int], edx
|
|
|
|
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__except(1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int bob = ((TLBCacheData[0] & 0x00FF0000) >> 16);
|
|
|
|
(void)bob;
|
|
|
|
// Process the returned TLB and cache information.
|
|
|
|
for (int nCounter = 0; nCounter < TLBCACHE_INFO_UNITS; nCounter ++)
|
|
|
|
{
|
|
|
|
// First of all - decide which unit we are dealing with.
|
|
|
|
switch (nCounter)
|
|
|
|
{
|
|
|
|
// eax: bits 8..15 : bits 16..23 : bits 24..31
|
|
|
|
case 0: TLBCacheUnit = ((TLBCacheData[0] & 0x0000FF00) >> 8); break;
|
|
|
|
case 1: TLBCacheUnit = ((TLBCacheData[0] & 0x00FF0000) >> 16); break;
|
|
|
|
case 2: TLBCacheUnit = ((TLBCacheData[0] & 0xFF000000) >> 24); break;
|
|
|
|
|
|
|
|
// ebx: bits 0..7 : bits 8..15 : bits 16..23 : bits 24..31
|
|
|
|
case 3: TLBCacheUnit = ((TLBCacheData[1] & 0x000000FF) >> 0); break;
|
|
|
|
case 4: TLBCacheUnit = ((TLBCacheData[1] & 0x0000FF00) >> 8); break;
|
|
|
|
case 5: TLBCacheUnit = ((TLBCacheData[1] & 0x00FF0000) >> 16); break;
|
|
|
|
case 6: TLBCacheUnit = ((TLBCacheData[1] & 0xFF000000) >> 24); break;
|
|
|
|
|
|
|
|
// ecx: bits 0..7 : bits 8..15 : bits 16..23 : bits 24..31
|
|
|
|
case 7: TLBCacheUnit = ((TLBCacheData[2] & 0x000000FF) >> 0); break;
|
|
|
|
case 8: TLBCacheUnit = ((TLBCacheData[2] & 0x0000FF00) >> 8); break;
|
|
|
|
case 9: TLBCacheUnit = ((TLBCacheData[2] & 0x00FF0000) >> 16); break;
|
|
|
|
case 10: TLBCacheUnit = ((TLBCacheData[2] & 0xFF000000) >> 24); break;
|
|
|
|
|
|
|
|
// edx: bits 0..7 : bits 8..15 : bits 16..23 : bits 24..31
|
|
|
|
case 11: TLBCacheUnit = ((TLBCacheData[3] & 0x000000FF) >> 0); break;
|
|
|
|
case 12: TLBCacheUnit = ((TLBCacheData[3] & 0x0000FF00) >> 8); break;
|
|
|
|
case 13: TLBCacheUnit = ((TLBCacheData[3] & 0x00FF0000) >> 16); break;
|
|
|
|
case 14: TLBCacheUnit = ((TLBCacheData[3] & 0xFF000000) >> 24); break;
|
|
|
|
|
|
|
|
// Default case - an error has occured.
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now process the resulting unit to see what it means....
|
|
|
|
switch (TLBCacheUnit)
|
|
|
|
{
|
|
|
|
case 0x00: break;
|
|
|
|
case 0x01: STORE_TLBCACHE_INFO (TLBCode, 4); break;
|
|
|
|
case 0x02: STORE_TLBCACHE_INFO (TLBCode, 4096); break;
|
|
|
|
case 0x03: STORE_TLBCACHE_INFO (TLBData, 4); break;
|
|
|
|
case 0x04: STORE_TLBCACHE_INFO (TLBData, 4096); break;
|
|
|
|
case 0x06: STORE_TLBCACHE_INFO (L1Code, 8); break;
|
|
|
|
case 0x08: STORE_TLBCACHE_INFO (L1Code, 16); break;
|
|
|
|
case 0x0a: STORE_TLBCACHE_INFO (L1Data, 8); break;
|
|
|
|
case 0x0c: STORE_TLBCACHE_INFO (L1Data, 16); break;
|
|
|
|
case 0x10: STORE_TLBCACHE_INFO (L1Data, 16); break; // <-- FIXME: IA-64 Only
|
|
|
|
case 0x15: STORE_TLBCACHE_INFO (L1Code, 16); break; // <-- FIXME: IA-64 Only
|
|
|
|
case 0x1a: STORE_TLBCACHE_INFO (L2Unified, 96); break; // <-- FIXME: IA-64 Only
|
|
|
|
case 0x22: STORE_TLBCACHE_INFO (L3Unified, 512); break;
|
|
|
|
case 0x23: STORE_TLBCACHE_INFO (L3Unified, 1024); break;
|
|
|
|
case 0x25: STORE_TLBCACHE_INFO (L3Unified, 2048); break;
|
|
|
|
case 0x29: STORE_TLBCACHE_INFO (L3Unified, 4096); break;
|
|
|
|
case 0x39: STORE_TLBCACHE_INFO (L2Unified, 128); break;
|
|
|
|
case 0x3c: STORE_TLBCACHE_INFO (L2Unified, 256); break;
|
|
|
|
case 0x40: STORE_TLBCACHE_INFO (L2Unified, 0); break; // <-- FIXME: No integrated L2 cache (P6 core) or L3 cache (P4 core).
|
|
|
|
case 0x41: STORE_TLBCACHE_INFO (L2Unified, 128); break;
|
|
|
|
case 0x42: STORE_TLBCACHE_INFO (L2Unified, 256); break;
|
|
|
|
case 0x43: STORE_TLBCACHE_INFO (L2Unified, 512); break;
|
|
|
|
case 0x44: STORE_TLBCACHE_INFO (L2Unified, 1024); break;
|
|
|
|
case 0x45: STORE_TLBCACHE_INFO (L2Unified, 2048); break;
|
|
|
|
case 0x50: STORE_TLBCACHE_INFO (TLBCode, 4096); break;
|
|
|
|
case 0x51: STORE_TLBCACHE_INFO (TLBCode, 4096); break;
|
|
|
|
case 0x52: STORE_TLBCACHE_INFO (TLBCode, 4096); break;
|
|
|
|
case 0x5b: STORE_TLBCACHE_INFO (TLBData, 4096); break;
|
|
|
|
case 0x5c: STORE_TLBCACHE_INFO (TLBData, 4096); break;
|
|
|
|
case 0x5d: STORE_TLBCACHE_INFO (TLBData, 4096); break;
|
|
|
|
case 0x66: STORE_TLBCACHE_INFO (L1Data, 8); break;
|
|
|
|
case 0x67: STORE_TLBCACHE_INFO (L1Data, 16); break;
|
|
|
|
case 0x68: STORE_TLBCACHE_INFO (L1Data, 32); break;
|
|
|
|
case 0x70: STORE_TLBCACHE_INFO (L1Trace, 12); break;
|
|
|
|
case 0x71: STORE_TLBCACHE_INFO (L1Trace, 16); break;
|
|
|
|
case 0x72: STORE_TLBCACHE_INFO (L1Trace, 32); break;
|
|
|
|
case 0x77: STORE_TLBCACHE_INFO (L1Code, 16); break; // <-- FIXME: IA-64 Only
|
|
|
|
case 0x79: STORE_TLBCACHE_INFO (L2Unified, 128); break;
|
|
|
|
case 0x7a: STORE_TLBCACHE_INFO (L2Unified, 256); break;
|
|
|
|
case 0x7b: STORE_TLBCACHE_INFO (L2Unified, 512); break;
|
|
|
|
case 0x7c: STORE_TLBCACHE_INFO (L2Unified, 1024); break;
|
|
|
|
case 0x7e: STORE_TLBCACHE_INFO (L2Unified, 256); break;
|
|
|
|
case 0x81: STORE_TLBCACHE_INFO (L2Unified, 128); break;
|
|
|
|
case 0x82: STORE_TLBCACHE_INFO (L2Unified, 256); break;
|
|
|
|
case 0x83: STORE_TLBCACHE_INFO (L2Unified, 512); break;
|
|
|
|
case 0x84: STORE_TLBCACHE_INFO (L2Unified, 1024); break;
|
|
|
|
case 0x85: STORE_TLBCACHE_INFO (L2Unified, 2048); break;
|
|
|
|
case 0x88: STORE_TLBCACHE_INFO (L3Unified, 2048); break; // <-- FIXME: IA-64 Only
|
|
|
|
case 0x89: STORE_TLBCACHE_INFO (L3Unified, 4096); break; // <-- FIXME: IA-64 Only
|
|
|
|
case 0x8a: STORE_TLBCACHE_INFO (L3Unified, 8192); break; // <-- FIXME: IA-64 Only
|
|
|
|
case 0x8d: STORE_TLBCACHE_INFO (L3Unified, 3096); break; // <-- FIXME: IA-64 Only
|
|
|
|
case 0x90: STORE_TLBCACHE_INFO (TLBCode, 262144); break; // <-- FIXME: IA-64 Only
|
|
|
|
case 0x96: STORE_TLBCACHE_INFO (TLBCode, 262144); break; // <-- FIXME: IA-64 Only
|
|
|
|
case 0x9b: STORE_TLBCACHE_INFO (TLBCode, 262144); break; // <-- FIXME: IA-64 Only
|
|
|
|
|
|
|
|
// Default case - an error has occured.
|
|
|
|
default: return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Increment the TLB pass counter.
|
|
|
|
TLBPassCounter ++;
|
|
|
|
} while ((TLBCacheData[0] & 0x000000FF) > TLBPassCounter);
|
|
|
|
|
|
|
|
// Ok - we now have the maximum TLB, L1, L2, and L3 sizes...
|
|
|
|
if ((L1Code == -1) && (L1Data == -1) && (L1Trace == -1))
|
|
|
|
{
|
|
|
|
this->Features.L1CacheSize = -1;
|
|
|
|
}
|
|
|
|
else if ((L1Code == -1) && (L1Data == -1) && (L1Trace != -1))
|
|
|
|
{
|
|
|
|
this->Features.L1CacheSize = L1Trace;
|
|
|
|
}
|
|
|
|
else if ((L1Code != -1) && (L1Data == -1))
|
|
|
|
{
|
|
|
|
this->Features.L1CacheSize = L1Code;
|
|
|
|
}
|
|
|
|
else if ((L1Code == -1) && (L1Data != -1))
|
|
|
|
{
|
|
|
|
this->Features.L1CacheSize = L1Data;
|
|
|
|
}
|
|
|
|
else if ((L1Code != -1) && (L1Data != -1))
|
|
|
|
{
|
|
|
|
this->Features.L1CacheSize = L1Code + L1Data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->Features.L1CacheSize = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ok - we now have the maximum TLB, L1, L2, and L3 sizes...
|
|
|
|
if (L2Unified == -1)
|
|
|
|
{
|
|
|
|
this->Features.L2CacheSize = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->Features.L2CacheSize = L2Unified;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ok - we now have the maximum TLB, L1, L2, and L3 sizes...
|
|
|
|
if (L3Unified == -1)
|
|
|
|
{
|
|
|
|
this->Features.L3CacheSize = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->Features.L3CacheSize = L3Unified;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2009-12-11 21:08:29 +03:00
|
|
|
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** */
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformationImplementation::RetrieveCPUClockSpeed()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2009-12-11 21:08:29 +03:00
|
|
|
bool retrieved = false;
|
|
|
|
|
2008-01-31 23:10:19 +03:00
|
|
|
#if _WIN32
|
2009-12-11 21:08:29 +03:00
|
|
|
// First of all we check to see if the RDTSC (0x0F, 0x31) instruction is
|
|
|
|
// supported. If not, we fallback to trying to read this value from the
|
|
|
|
// registry:
|
|
|
|
//
|
|
|
|
if (!this->Features.HasTSC)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2009-12-11 21:08:29 +03:00
|
|
|
HKEY hKey = NULL;
|
|
|
|
LONG err = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
|
|
|
|
"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0,
|
|
|
|
KEY_READ, &hKey);
|
|
|
|
|
|
|
|
if (ERROR_SUCCESS == err)
|
|
|
|
{
|
|
|
|
DWORD dwType = 0;
|
|
|
|
DWORD data = 0;
|
|
|
|
DWORD dwSize = sizeof(DWORD);
|
|
|
|
|
|
|
|
err = RegQueryValueEx(hKey, "~MHz", 0,
|
|
|
|
&dwType, (LPBYTE) &data, &dwSize);
|
|
|
|
|
|
|
|
if (ERROR_SUCCESS == err)
|
|
|
|
{
|
|
|
|
this->CPUSpeedInMHz = (float) data;
|
|
|
|
retrieved = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
hKey = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retrieved;
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int uiRepetitions = 1;
|
|
|
|
unsigned int uiMSecPerRepetition = 50;
|
|
|
|
__int64 i64Total = 0;
|
|
|
|
__int64 i64Overhead = 0;
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
for (unsigned int nCounter = 0; nCounter < uiRepetitions; nCounter ++)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-01-31 23:10:19 +03:00
|
|
|
i64Total += GetCyclesDifference (SystemInformationImplementation::Delay,
|
|
|
|
uiMSecPerRepetition);
|
|
|
|
i64Overhead +=
|
|
|
|
GetCyclesDifference (SystemInformationImplementation::DelayOverhead,
|
|
|
|
uiMSecPerRepetition);
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the MHz speed.
|
|
|
|
i64Total -= i64Overhead;
|
|
|
|
i64Total /= uiRepetitions;
|
|
|
|
i64Total /= uiMSecPerRepetition;
|
|
|
|
i64Total /= 1000;
|
|
|
|
|
|
|
|
// Save the CPU speed.
|
|
|
|
this->CPUSpeedInMHz = (float) i64Total;
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
retrieved = true;
|
2008-01-08 19:38:28 +03:00
|
|
|
#endif
|
2009-12-11 21:08:29 +03:00
|
|
|
|
|
|
|
return retrieved;
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** */
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformationImplementation::RetrieveClassicalCPUClockSpeed()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-01-31 23:10:19 +03:00
|
|
|
#if USE_ASM_INSTRUCTIONS
|
2008-01-08 19:38:28 +03:00
|
|
|
LARGE_INTEGER liStart, liEnd, liCountsPerSecond;
|
|
|
|
double dFrequency, dDifference;
|
|
|
|
|
|
|
|
// Attempt to get a starting tick count.
|
|
|
|
QueryPerformanceCounter (&liStart);
|
|
|
|
|
|
|
|
__try
|
|
|
|
{
|
|
|
|
_asm
|
|
|
|
{
|
|
|
|
mov eax, 0x80000000
|
|
|
|
mov ebx, CLASSICAL_CPU_FREQ_LOOP
|
|
|
|
Timer_Loop:
|
|
|
|
bsf ecx,eax
|
|
|
|
dec ebx
|
|
|
|
jnz Timer_Loop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__except(1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to get a starting tick count.
|
|
|
|
QueryPerformanceCounter (&liEnd);
|
|
|
|
|
|
|
|
// Get the difference... NB: This is in seconds....
|
|
|
|
QueryPerformanceFrequency (&liCountsPerSecond);
|
|
|
|
dDifference = (((double) liEnd.QuadPart - (double) liStart.QuadPart) / (double) liCountsPerSecond.QuadPart);
|
|
|
|
|
|
|
|
// Calculate the clock speed.
|
|
|
|
if (this->ChipID.Family == 3)
|
|
|
|
{
|
|
|
|
// 80386 processors.... Loop time is 115 cycles!
|
|
|
|
dFrequency = (((CLASSICAL_CPU_FREQ_LOOP * 115) / dDifference) / 1048576);
|
|
|
|
}
|
|
|
|
else if (this->ChipID.Family == 4)
|
|
|
|
{
|
|
|
|
// 80486 processors.... Loop time is 47 cycles!
|
|
|
|
dFrequency = (((CLASSICAL_CPU_FREQ_LOOP * 47) / dDifference) / 1048576);
|
|
|
|
}
|
|
|
|
else if (this->ChipID.Family == 5)
|
|
|
|
{
|
|
|
|
// Pentium processors.... Loop time is 43 cycles!
|
|
|
|
dFrequency = (((CLASSICAL_CPU_FREQ_LOOP * 43) / dDifference) / 1048576);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save the clock speed.
|
|
|
|
this->Features.CPUSpeed = (int) dFrequency;
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
return true;
|
2009-12-11 21:08:29 +03:00
|
|
|
|
|
|
|
#else
|
|
|
|
return false;
|
2008-01-08 19:38:28 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** */
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformationImplementation::RetrieveCPUExtendedLevelSupport(int CPULevelToCheck)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
int MaxCPUExtendedLevel = 0;
|
|
|
|
|
|
|
|
// The extended CPUID is supported by various vendors starting with the following CPU models:
|
|
|
|
//
|
|
|
|
// Manufacturer & Chip Name | Family Model Revision
|
|
|
|
//
|
|
|
|
// AMD K6, K6-2 | 5 6 x
|
|
|
|
// Cyrix GXm, Cyrix III "Joshua" | 5 4 x
|
|
|
|
// IDT C6-2 | 5 8 x
|
|
|
|
// VIA Cyrix III | 6 5 x
|
|
|
|
// Transmeta Crusoe | 5 x x
|
|
|
|
// Intel Pentium 4 | f x x
|
|
|
|
//
|
|
|
|
|
|
|
|
// We check to see if a supported processor is present...
|
|
|
|
if (this->ChipManufacturer == AMD)
|
|
|
|
{
|
|
|
|
if (this->ChipID.Family < 5) return false;
|
|
|
|
if ((this->ChipID.Family == 5) && (this->ChipID.Model < 6)) return false;
|
|
|
|
}
|
|
|
|
else if (this->ChipManufacturer == Cyrix)
|
|
|
|
{
|
|
|
|
if (this->ChipID.Family < 5) return false;
|
|
|
|
if ((this->ChipID.Family == 5) && (this->ChipID.Model < 4)) return false;
|
|
|
|
if ((this->ChipID.Family == 6) && (this->ChipID.Model < 5)) return false;
|
|
|
|
}
|
|
|
|
else if (this->ChipManufacturer == IDT)
|
|
|
|
{
|
|
|
|
if (this->ChipID.Family < 5) return false;
|
|
|
|
if ((this->ChipID.Family == 5) && (this->ChipID.Model < 8)) return false;
|
|
|
|
}
|
|
|
|
else if (this->ChipManufacturer == Transmeta)
|
|
|
|
{
|
|
|
|
if (this->ChipID.Family < 5) return false;
|
|
|
|
}
|
|
|
|
else if (this->ChipManufacturer == Intel)
|
|
|
|
{
|
|
|
|
if (this->ChipID.Family < 0xf)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 23:10:19 +03:00
|
|
|
#if USE_ASM_INSTRUCTIONS
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
// Use assembly to detect CPUID information...
|
|
|
|
__try {
|
|
|
|
_asm {
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
; we must push/pop the registers <<CPUID>> writes to, as the
|
|
|
|
; optimiser doesn't know about <<CPUID>>, and so doesn't expect
|
|
|
|
; these registers to change.
|
|
|
|
push eax
|
|
|
|
push ebx
|
|
|
|
push ecx
|
|
|
|
push edx
|
|
|
|
#endif
|
|
|
|
; <<CPUID>>
|
|
|
|
; eax = 0x80000000 --> eax: maximum supported extended level
|
|
|
|
mov eax,0x80000000
|
|
|
|
CPUID_INSTRUCTION
|
|
|
|
mov MaxCPUExtendedLevel, eax
|
|
|
|
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__except(1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Now we have to check the level wanted vs level returned...
|
|
|
|
int nLevelWanted = (CPULevelToCheck & 0x7FFFFFFF);
|
|
|
|
int nLevelReturn = (MaxCPUExtendedLevel & 0x7FFFFFFF);
|
|
|
|
|
|
|
|
// Check to see if the level provided is supported...
|
|
|
|
if (nLevelWanted > nLevelReturn)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** */
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformationImplementation::RetrieveExtendedCPUFeatures()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
// Check that we are not using an Intel processor as it does not support this.
|
|
|
|
if (this->ChipManufacturer == Intel)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if what we are about to do is supported...
|
2009-03-20 05:48:05 +03:00
|
|
|
if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000001)))
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 23:10:19 +03:00
|
|
|
#if USE_ASM_INSTRUCTIONS
|
2008-01-09 01:20:04 +03:00
|
|
|
int localCPUExtendedFeatures = 0;
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
// Use assembly to detect CPUID information...
|
|
|
|
__try
|
|
|
|
{
|
|
|
|
_asm
|
|
|
|
{
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
; we must push/pop the registers <<CPUID>> writes to, as the
|
|
|
|
; optimiser doesn't know about <<CPUID>>, and so doesn't expect
|
|
|
|
; these registers to change.
|
|
|
|
push eax
|
|
|
|
push ebx
|
|
|
|
push ecx
|
|
|
|
push edx
|
|
|
|
#endif
|
|
|
|
; <<CPUID>>
|
|
|
|
; eax = 0x80000001 --> eax: CPU ID - bits 31..16 - unused, bits 15..12 - type, bits 11..8 - family, bits 7..4 - model, bits 3..0 - mask revision
|
|
|
|
; ebx: 31..24 - default APIC ID, 23..16 - logical processsor ID, 15..8 - CFLUSH chunk size , 7..0 - brand ID
|
|
|
|
; edx: CPU feature flags
|
|
|
|
mov eax,0x80000001
|
|
|
|
CPUID_INSTRUCTION
|
2008-01-09 01:20:04 +03:00
|
|
|
mov localCPUExtendedFeatures, edx
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__except(1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve the extended features of CPU present.
|
2008-01-09 01:20:04 +03:00
|
|
|
this->Features.ExtendedFeatures.Has3DNow = ((localCPUExtendedFeatures & 0x80000000) != 0); // 3DNow Present --> Bit 31.
|
|
|
|
this->Features.ExtendedFeatures.Has3DNowPlus = ((localCPUExtendedFeatures & 0x40000000) != 0); // 3DNow+ Present -- > Bit 30.
|
|
|
|
this->Features.ExtendedFeatures.HasSSEMMX = ((localCPUExtendedFeatures & 0x00400000) != 0); // SSE MMX Present --> Bit 22.
|
|
|
|
this->Features.ExtendedFeatures.SupportsMP = ((localCPUExtendedFeatures & 0x00080000) != 0); // MP Capable -- > Bit 19.
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
// Retrieve AMD specific extended features.
|
|
|
|
if (this->ChipManufacturer == AMD)
|
|
|
|
{
|
2008-01-09 01:20:04 +03:00
|
|
|
this->Features.ExtendedFeatures.HasMMXPlus = ((localCPUExtendedFeatures & 0x00400000) != 0); // AMD specific: MMX-SSE --> Bit 22
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve Cyrix specific extended features.
|
|
|
|
if (this->ChipManufacturer == Cyrix)
|
|
|
|
{
|
2008-01-09 01:20:04 +03:00
|
|
|
this->Features.ExtendedFeatures.HasMMXPlus = ((localCPUExtendedFeatures & 0x01000000) != 0); // Cyrix specific: Extended MMX --> Bit 24
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2009-12-11 21:08:29 +03:00
|
|
|
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** */
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformationImplementation::RetrieveProcessorSerialNumber()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
// Check to see if the processor supports the processor serial number.
|
|
|
|
if (!this->Features.HasSerial)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-01-31 23:10:19 +03:00
|
|
|
#if USE_ASM_INSTRUCTIONS
|
2008-01-09 01:20:04 +03:00
|
|
|
int SerialNumber[3];
|
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
// Use assembly to detect CPUID information...
|
|
|
|
__try {
|
|
|
|
_asm {
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
; we must push/pop the registers <<CPUID>> writes to, as the
|
|
|
|
; optimiser doesn't know about <<CPUID>>, and so doesn't expect
|
|
|
|
; these registers to change.
|
|
|
|
push eax
|
|
|
|
push ebx
|
|
|
|
push ecx
|
|
|
|
push edx
|
|
|
|
#endif
|
|
|
|
; <<CPUID>>
|
|
|
|
; eax = 3 --> ebx: top 32 bits are the processor signature bits --> NB: Transmeta only ?!?
|
|
|
|
; ecx: middle 32 bits are the processor signature bits
|
|
|
|
; edx: bottom 32 bits are the processor signature bits
|
|
|
|
mov eax, 3
|
|
|
|
CPUID_INSTRUCTION
|
|
|
|
mov SerialNumber[0 * TYPE int], ebx
|
|
|
|
mov SerialNumber[1 * TYPE int], ecx
|
|
|
|
mov SerialNumber[2 * TYPE int], edx
|
|
|
|
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__except(1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process the returned information.
|
|
|
|
sprintf (this->ChipID.SerialNumber, "%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x",
|
|
|
|
((SerialNumber[0] & 0xff000000) >> 24),
|
|
|
|
((SerialNumber[0] & 0x00ff0000) >> 16),
|
|
|
|
((SerialNumber[0] & 0x0000ff00) >> 8),
|
|
|
|
((SerialNumber[0] & 0x000000ff) >> 0),
|
|
|
|
((SerialNumber[1] & 0xff000000) >> 24),
|
|
|
|
((SerialNumber[1] & 0x00ff0000) >> 16),
|
|
|
|
((SerialNumber[1] & 0x0000ff00) >> 8),
|
|
|
|
((SerialNumber[1] & 0x000000ff) >> 0),
|
|
|
|
((SerialNumber[2] & 0xff000000) >> 24),
|
|
|
|
((SerialNumber[2] & 0x00ff0000) >> 16),
|
|
|
|
((SerialNumber[2] & 0x0000ff00) >> 8),
|
|
|
|
((SerialNumber[2] & 0x000000ff) >> 0));
|
|
|
|
|
|
|
|
return true;
|
2009-12-11 21:08:29 +03:00
|
|
|
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** */
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformationImplementation::RetrieveCPUPowerManagement()
|
2009-12-11 21:08:29 +03:00
|
|
|
{
|
2008-01-08 19:38:28 +03:00
|
|
|
// Check to see if what we are about to do is supported...
|
2009-03-20 05:48:05 +03:00
|
|
|
if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000007)))
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
this->Features.ExtendedFeatures.PowerManagement.HasFrequencyID = false;
|
|
|
|
this->Features.ExtendedFeatures.PowerManagement.HasVoltageID = false;
|
|
|
|
this->Features.ExtendedFeatures.PowerManagement.HasTempSenseDiode = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-01-31 23:10:19 +03:00
|
|
|
#if USE_ASM_INSTRUCTIONS
|
2008-01-09 01:20:04 +03:00
|
|
|
int localCPUPowerManagement = 0;
|
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
// Use assembly to detect CPUID information...
|
|
|
|
__try {
|
|
|
|
_asm {
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
; we must push/pop the registers <<CPUID>> writes to, as the
|
|
|
|
; optimiser doesn't know about <<CPUID>>, and so doesn't expect
|
|
|
|
; these registers to change.
|
|
|
|
push eax
|
|
|
|
push ebx
|
|
|
|
push ecx
|
|
|
|
push edx
|
|
|
|
#endif
|
|
|
|
; <<CPUID>>
|
|
|
|
; eax = 0x80000007 --> edx: get processor power management
|
|
|
|
mov eax,0x80000007
|
|
|
|
CPUID_INSTRUCTION
|
2008-01-09 01:20:04 +03:00
|
|
|
mov localCPUPowerManagement, edx
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__except(1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for the power management capabilities of the CPU.
|
2008-01-09 01:20:04 +03:00
|
|
|
this->Features.ExtendedFeatures.PowerManagement.HasTempSenseDiode = ((localCPUPowerManagement & 0x00000001) != 0);
|
|
|
|
this->Features.ExtendedFeatures.PowerManagement.HasFrequencyID = ((localCPUPowerManagement & 0x00000002) != 0);
|
|
|
|
this->Features.ExtendedFeatures.PowerManagement.HasVoltageID = ((localCPUPowerManagement & 0x00000004) != 0);
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
return true;
|
2009-12-11 21:08:29 +03:00
|
|
|
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** */
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformationImplementation::RetrieveExtendedCPUIdentity()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
// Check to see if what we are about to do is supported...
|
2009-03-20 05:48:05 +03:00
|
|
|
if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000002)))
|
|
|
|
return false;
|
|
|
|
if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000003)))
|
|
|
|
return false;
|
|
|
|
if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000004)))
|
|
|
|
return false;
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 23:10:19 +03:00
|
|
|
#if USE_ASM_INSTRUCTIONS
|
2008-01-09 01:20:04 +03:00
|
|
|
int ProcessorNameStartPos = 0;
|
|
|
|
int CPUExtendedIdentity[12];
|
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
// Use assembly to detect CPUID information...
|
|
|
|
__try {
|
|
|
|
_asm {
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
; we must push/pop the registers <<CPUID>> writes to, as the
|
|
|
|
; optimiser doesn't know about <<CPUID>>, and so doesn't expect
|
|
|
|
; these registers to change.
|
|
|
|
push eax
|
|
|
|
push ebx
|
|
|
|
push ecx
|
|
|
|
push edx
|
|
|
|
#endif
|
|
|
|
; <<CPUID>>
|
|
|
|
; eax = 0x80000002 --> eax, ebx, ecx, edx: get processor name string (part 1)
|
|
|
|
mov eax,0x80000002
|
|
|
|
CPUID_INSTRUCTION
|
|
|
|
mov CPUExtendedIdentity[0 * TYPE int], eax
|
|
|
|
mov CPUExtendedIdentity[1 * TYPE int], ebx
|
|
|
|
mov CPUExtendedIdentity[2 * TYPE int], ecx
|
|
|
|
mov CPUExtendedIdentity[3 * TYPE int], edx
|
|
|
|
|
|
|
|
; <<CPUID>>
|
|
|
|
; eax = 0x80000003 --> eax, ebx, ecx, edx: get processor name string (part 2)
|
|
|
|
mov eax,0x80000003
|
|
|
|
CPUID_INSTRUCTION
|
|
|
|
mov CPUExtendedIdentity[4 * TYPE int], eax
|
|
|
|
mov CPUExtendedIdentity[5 * TYPE int], ebx
|
|
|
|
mov CPUExtendedIdentity[6 * TYPE int], ecx
|
|
|
|
mov CPUExtendedIdentity[7 * TYPE int], edx
|
|
|
|
|
|
|
|
; <<CPUID>>
|
|
|
|
; eax = 0x80000004 --> eax, ebx, ecx, edx: get processor name string (part 3)
|
|
|
|
mov eax,0x80000004
|
|
|
|
CPUID_INSTRUCTION
|
|
|
|
mov CPUExtendedIdentity[8 * TYPE int], eax
|
|
|
|
mov CPUExtendedIdentity[9 * TYPE int], ebx
|
|
|
|
mov CPUExtendedIdentity[10 * TYPE int], ecx
|
|
|
|
mov CPUExtendedIdentity[11 * TYPE int], edx
|
|
|
|
|
|
|
|
#ifdef CPUID_AWARE_COMPILER
|
|
|
|
pop edx
|
|
|
|
pop ecx
|
|
|
|
pop ebx
|
|
|
|
pop eax
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__except(1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Process the returned information.
|
|
|
|
memcpy (this->ChipID.ProcessorName, &(CPUExtendedIdentity[0]), sizeof (int));
|
|
|
|
memcpy (&(this->ChipID.ProcessorName[4]), &(CPUExtendedIdentity[1]), sizeof (int));
|
|
|
|
memcpy (&(this->ChipID.ProcessorName[8]), &(CPUExtendedIdentity[2]), sizeof (int));
|
|
|
|
memcpy (&(this->ChipID.ProcessorName[12]), &(CPUExtendedIdentity[3]), sizeof (int));
|
|
|
|
memcpy (&(this->ChipID.ProcessorName[16]), &(CPUExtendedIdentity[4]), sizeof (int));
|
|
|
|
memcpy (&(this->ChipID.ProcessorName[20]), &(CPUExtendedIdentity[5]), sizeof (int));
|
|
|
|
memcpy (&(this->ChipID.ProcessorName[24]), &(CPUExtendedIdentity[6]), sizeof (int));
|
|
|
|
memcpy (&(this->ChipID.ProcessorName[28]), &(CPUExtendedIdentity[7]), sizeof (int));
|
|
|
|
memcpy (&(this->ChipID.ProcessorName[32]), &(CPUExtendedIdentity[8]), sizeof (int));
|
|
|
|
memcpy (&(this->ChipID.ProcessorName[36]), &(CPUExtendedIdentity[9]), sizeof (int));
|
|
|
|
memcpy (&(this->ChipID.ProcessorName[40]), &(CPUExtendedIdentity[10]), sizeof (int));
|
|
|
|
memcpy (&(this->ChipID.ProcessorName[44]), &(CPUExtendedIdentity[11]), sizeof (int));
|
|
|
|
this->ChipID.ProcessorName[48] = '\0';
|
|
|
|
|
|
|
|
// Because some manufacturers have leading white space - we have to post-process the name.
|
|
|
|
if (this->ChipManufacturer == Intel)
|
|
|
|
{
|
|
|
|
for (int nCounter = 0; nCounter < CHIPNAME_STRING_LENGTH; nCounter ++)
|
|
|
|
{
|
|
|
|
// There will either be NULL (\0) or spaces ( ) as the leading characters.
|
|
|
|
if ((this->ChipID.ProcessorName[nCounter] != '\0') && (this->ChipID.ProcessorName[nCounter] != ' '))
|
|
|
|
{
|
|
|
|
// We have found the starting position of the name.
|
|
|
|
ProcessorNameStartPos = nCounter;
|
|
|
|
// Terminate the loop.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check to see if there is any white space at the start.
|
|
|
|
if (ProcessorNameStartPos == 0)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now move the name forward so that there is no white space.
|
|
|
|
memmove(this->ChipID.ProcessorName, &(this->ChipID.ProcessorName[ProcessorNameStartPos]), (CHIPNAME_STRING_LENGTH - ProcessorNameStartPos));
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2009-12-11 21:08:29 +03:00
|
|
|
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** */
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformationImplementation::RetrieveClassicalCPUIdentity()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
// Start by decided which manufacturer we are using....
|
|
|
|
switch (this->ChipManufacturer)
|
|
|
|
{
|
|
|
|
case Intel:
|
|
|
|
// Check the family / model / revision to determine the CPU ID.
|
|
|
|
switch (this->ChipID.Family) {
|
|
|
|
case 3:
|
|
|
|
sprintf (this->ChipID.ProcessorName, "Newer i80386 family");
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
switch (this->ChipID.Model) {
|
|
|
|
case 0: sprintf (this->ChipID.ProcessorName,"i80486DX-25/33"); break;
|
|
|
|
case 1: sprintf (this->ChipID.ProcessorName,"i80486DX-50"); break;
|
|
|
|
case 2: sprintf (this->ChipID.ProcessorName,"i80486SX"); break;
|
|
|
|
case 3: sprintf (this->ChipID.ProcessorName,"i80486DX2"); break;
|
|
|
|
case 4: sprintf (this->ChipID.ProcessorName,"i80486SL"); break;
|
|
|
|
case 5: sprintf (this->ChipID.ProcessorName,"i80486SX2"); break;
|
|
|
|
case 7: sprintf (this->ChipID.ProcessorName,"i80486DX2 WriteBack"); break;
|
|
|
|
case 8: sprintf (this->ChipID.ProcessorName,"i80486DX4"); break;
|
|
|
|
case 9: sprintf (this->ChipID.ProcessorName,"i80486DX4 WriteBack"); break;
|
|
|
|
default: sprintf (this->ChipID.ProcessorName,"Unknown 80486 family"); return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
switch (this->ChipID.Model)
|
|
|
|
{
|
|
|
|
case 0: sprintf (this->ChipID.ProcessorName,"P5 A-Step"); break;
|
|
|
|
case 1: sprintf (this->ChipID.ProcessorName,"P5"); break;
|
|
|
|
case 2: sprintf (this->ChipID.ProcessorName,"P54C"); break;
|
|
|
|
case 3: sprintf (this->ChipID.ProcessorName,"P24T OverDrive"); break;
|
|
|
|
case 4: sprintf (this->ChipID.ProcessorName,"P55C"); break;
|
|
|
|
case 7: sprintf (this->ChipID.ProcessorName,"P54C"); break;
|
|
|
|
case 8: sprintf (this->ChipID.ProcessorName,"P55C (0.25micron)"); break;
|
|
|
|
default: sprintf (this->ChipID.ProcessorName,"Unknown Pentium family"); return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
switch (this->ChipID.Model)
|
|
|
|
{
|
|
|
|
case 0: sprintf (this->ChipID.ProcessorName,"P6 A-Step"); break;
|
|
|
|
case 1: sprintf (this->ChipID.ProcessorName,"P6"); break;
|
|
|
|
case 3: sprintf (this->ChipID.ProcessorName,"Pentium II (0.28 micron)"); break;
|
|
|
|
case 5: sprintf (this->ChipID.ProcessorName,"Pentium II (0.25 micron)"); break;
|
|
|
|
case 6: sprintf (this->ChipID.ProcessorName,"Pentium II With On-Die L2 Cache"); break;
|
|
|
|
case 7: sprintf (this->ChipID.ProcessorName,"Pentium III (0.25 micron)"); break;
|
|
|
|
case 8: sprintf (this->ChipID.ProcessorName,"Pentium III (0.18 micron) With 256 KB On-Die L2 Cache "); break;
|
|
|
|
case 0xa: sprintf (this->ChipID.ProcessorName,"Pentium III (0.18 micron) With 1 Or 2 MB On-Die L2 Cache "); break;
|
|
|
|
case 0xb: sprintf (this->ChipID.ProcessorName,"Pentium III (0.13 micron) With 256 Or 512 KB On-Die L2 Cache "); break;
|
2009-05-20 17:50:20 +04:00
|
|
|
case 23: sprintf (this->ChipID.ProcessorName, "Intel(R) Core(TM)2 Duo CPU T9500 @ 2.60GHz"); break;
|
2008-01-08 19:38:28 +03:00
|
|
|
default: sprintf (this->ChipID.ProcessorName,"Unknown P6 family"); return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
sprintf (this->ChipID.ProcessorName,"Intel Merced (IA-64)");
|
|
|
|
break;
|
|
|
|
case 0xf:
|
|
|
|
// Check the extended family bits...
|
|
|
|
switch (this->ChipID.ExtendedFamily)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
switch (this->ChipID.Model)
|
|
|
|
{
|
|
|
|
case 0: sprintf (this->ChipID.ProcessorName,"Pentium IV (0.18 micron)"); break;
|
|
|
|
case 1: sprintf (this->ChipID.ProcessorName,"Pentium IV (0.18 micron)"); break;
|
|
|
|
case 2: sprintf (this->ChipID.ProcessorName,"Pentium IV (0.13 micron)"); break;
|
|
|
|
default: sprintf (this->ChipID.ProcessorName,"Unknown Pentium 4 family"); return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
sprintf (this->ChipID.ProcessorName,"Intel McKinley (IA-64)");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf (this->ChipID.ProcessorName,"Pentium");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf (this->ChipID.ProcessorName,"Unknown Intel family");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AMD:
|
|
|
|
// Check the family / model / revision to determine the CPU ID.
|
|
|
|
switch (this->ChipID.Family)
|
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
switch (this->ChipID.Model)
|
|
|
|
{
|
|
|
|
case 3: sprintf (this->ChipID.ProcessorName,"80486DX2"); break;
|
|
|
|
case 7: sprintf (this->ChipID.ProcessorName,"80486DX2 WriteBack"); break;
|
|
|
|
case 8: sprintf (this->ChipID.ProcessorName,"80486DX4"); break;
|
|
|
|
case 9: sprintf (this->ChipID.ProcessorName,"80486DX4 WriteBack"); break;
|
|
|
|
case 0xe: sprintf (this->ChipID.ProcessorName,"5x86"); break;
|
|
|
|
case 0xf: sprintf (this->ChipID.ProcessorName,"5x86WB"); break;
|
|
|
|
default: sprintf (this->ChipID.ProcessorName,"Unknown 80486 family"); return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
switch (this->ChipID.Model)
|
|
|
|
{
|
|
|
|
case 0: sprintf (this->ChipID.ProcessorName,"SSA5 (PR75, PR90, PR100)"); break;
|
|
|
|
case 1: sprintf (this->ChipID.ProcessorName,"5k86 (PR120, PR133)"); break;
|
|
|
|
case 2: sprintf (this->ChipID.ProcessorName,"5k86 (PR166)"); break;
|
|
|
|
case 3: sprintf (this->ChipID.ProcessorName,"5k86 (PR200)"); break;
|
|
|
|
case 6: sprintf (this->ChipID.ProcessorName,"K6 (0.30 micron)"); break;
|
|
|
|
case 7: sprintf (this->ChipID.ProcessorName,"K6 (0.25 micron)"); break;
|
|
|
|
case 8: sprintf (this->ChipID.ProcessorName,"K6-2"); break;
|
|
|
|
case 9: sprintf (this->ChipID.ProcessorName,"K6-III"); break;
|
|
|
|
case 0xd: sprintf (this->ChipID.ProcessorName,"K6-2+ or K6-III+ (0.18 micron)"); break;
|
|
|
|
default: sprintf (this->ChipID.ProcessorName,"Unknown 80586 family"); return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
switch (this->ChipID.Model)
|
|
|
|
{
|
2008-04-24 23:47:36 +04:00
|
|
|
case 1: sprintf (this->ChipID.ProcessorName,"Athlon- (0.25 micron)"); break;
|
|
|
|
case 2: sprintf (this->ChipID.ProcessorName,"Athlon- (0.18 micron)"); break;
|
|
|
|
case 3: sprintf (this->ChipID.ProcessorName,"Duron- (SF core)"); break;
|
|
|
|
case 4: sprintf (this->ChipID.ProcessorName,"Athlon- (Thunderbird core)"); break;
|
|
|
|
case 6: sprintf (this->ChipID.ProcessorName,"Athlon- (Palomino core)"); break;
|
|
|
|
case 7: sprintf (this->ChipID.ProcessorName,"Duron- (Morgan core)"); break;
|
2008-01-08 19:38:28 +03:00
|
|
|
case 8:
|
|
|
|
if (this->Features.ExtendedFeatures.SupportsMP)
|
2008-04-24 23:47:36 +04:00
|
|
|
sprintf (this->ChipID.ProcessorName,"Athlon - MP (Thoroughbred core)");
|
|
|
|
else sprintf (this->ChipID.ProcessorName,"Athlon - XP (Thoroughbred core)");
|
2008-01-08 19:38:28 +03:00
|
|
|
break;
|
|
|
|
default: sprintf (this->ChipID.ProcessorName,"Unknown K7 family"); return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf (this->ChipID.ProcessorName,"Unknown AMD family");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Transmeta:
|
|
|
|
switch (this->ChipID.Family)
|
|
|
|
{
|
|
|
|
case 5:
|
|
|
|
switch (this->ChipID.Model)
|
|
|
|
{
|
|
|
|
case 4: sprintf (this->ChipID.ProcessorName,"Crusoe TM3x00 and TM5x00"); break;
|
|
|
|
default: sprintf (this->ChipID.ProcessorName,"Unknown Crusoe family"); return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf (this->ChipID.ProcessorName,"Unknown Transmeta family");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Rise:
|
|
|
|
switch (this->ChipID.Family)
|
|
|
|
{
|
|
|
|
case 5:
|
|
|
|
switch (this->ChipID.Model)
|
|
|
|
{
|
|
|
|
case 0: sprintf (this->ChipID.ProcessorName,"mP6 (0.25 micron)"); break;
|
|
|
|
case 2: sprintf (this->ChipID.ProcessorName,"mP6 (0.18 micron)"); break;
|
|
|
|
default: sprintf (this->ChipID.ProcessorName,"Unknown Rise family"); return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf (this->ChipID.ProcessorName,"Unknown Rise family");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case UMC:
|
|
|
|
switch (this->ChipID.Family)
|
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
switch (this->ChipID.Model)
|
|
|
|
{
|
|
|
|
case 1: sprintf (this->ChipID.ProcessorName,"U5D"); break;
|
|
|
|
case 2: sprintf (this->ChipID.ProcessorName,"U5S"); break;
|
|
|
|
default: sprintf (this->ChipID.ProcessorName,"Unknown UMC family"); return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf (this->ChipID.ProcessorName,"Unknown UMC family");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case IDT:
|
|
|
|
switch (this->ChipID.Family)
|
|
|
|
{
|
|
|
|
case 5:
|
|
|
|
switch (this->ChipID.Model)
|
|
|
|
{
|
|
|
|
case 4: sprintf (this->ChipID.ProcessorName,"C6"); break;
|
|
|
|
case 8: sprintf (this->ChipID.ProcessorName,"C2"); break;
|
|
|
|
case 9: sprintf (this->ChipID.ProcessorName,"C3"); break;
|
|
|
|
default: sprintf (this->ChipID.ProcessorName,"Unknown IDT\\Centaur family"); return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
switch (this->ChipID.Model)
|
|
|
|
{
|
|
|
|
case 6: sprintf (this->ChipID.ProcessorName,"VIA Cyrix III - Samuel"); break;
|
|
|
|
default: sprintf (this->ChipID.ProcessorName,"Unknown IDT\\Centaur family"); return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf (this->ChipID.ProcessorName,"Unknown IDT\\Centaur family");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Cyrix:
|
|
|
|
switch (this->ChipID.Family)
|
|
|
|
{
|
|
|
|
case 4:
|
|
|
|
switch (this->ChipID.Model)
|
|
|
|
{
|
|
|
|
case 4: sprintf (this->ChipID.ProcessorName,"MediaGX GX, GXm"); break;
|
|
|
|
case 9: sprintf (this->ChipID.ProcessorName,"5x86"); break;
|
|
|
|
default: sprintf (this->ChipID.ProcessorName,"Unknown Cx5x86 family"); return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
switch (this->ChipID.Model)
|
|
|
|
{
|
|
|
|
case 2: sprintf (this->ChipID.ProcessorName,"Cx6x86"); break;
|
|
|
|
case 4: sprintf (this->ChipID.ProcessorName,"MediaGX GXm"); break;
|
|
|
|
default: sprintf (this->ChipID.ProcessorName,"Unknown Cx6x86 family"); return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
switch (this->ChipID.Model)
|
|
|
|
{
|
|
|
|
case 0: sprintf (this->ChipID.ProcessorName,"6x86MX"); break;
|
|
|
|
case 5: sprintf (this->ChipID.ProcessorName,"Cyrix M2 Core"); break;
|
|
|
|
case 6: sprintf (this->ChipID.ProcessorName,"WinChip C5A Core"); break;
|
|
|
|
case 7: sprintf (this->ChipID.ProcessorName,"WinChip C5B\\C5C Core"); break;
|
|
|
|
case 8: sprintf (this->ChipID.ProcessorName,"WinChip C5C-T Core"); break;
|
|
|
|
default: sprintf (this->ChipID.ProcessorName,"Unknown 6x86MX\\Cyrix III family"); return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf (this->ChipID.ProcessorName,"Unknown Cyrix family");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NexGen:
|
|
|
|
switch (this->ChipID.Family)
|
|
|
|
{
|
|
|
|
case 5:
|
|
|
|
switch (this->ChipID.Model)
|
|
|
|
{
|
|
|
|
case 0: sprintf (this->ChipID.ProcessorName,"Nx586 or Nx586FPU"); break;
|
|
|
|
default: sprintf (this->ChipID.ProcessorName,"Unknown NexGen family"); return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf (this->ChipID.ProcessorName,"Unknown NexGen family");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSC:
|
|
|
|
sprintf (this->ChipID.ProcessorName,"Cx486SLC \\ DLC \\ Cx486S A-Step");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sprintf (this->ChipID.ProcessorName,"Unknown family"); // We cannot identify the processor.
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** Extract a value from the CPUInfo file */
|
2008-02-01 19:34:42 +03:00
|
|
|
kwsys_stl::string SystemInformationImplementation::ExtractValueFromCpuInfoFile(kwsys_stl::string buffer,const char* word,size_t init)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-02-01 19:30:08 +03:00
|
|
|
size_t pos = buffer.find(word,init);
|
|
|
|
if(pos != buffer.npos)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
this->CurrentPositionInFile = pos;
|
|
|
|
pos = buffer.find(":",pos);
|
2008-02-01 19:30:08 +03:00
|
|
|
size_t pos2 = buffer.find("\n",pos);
|
|
|
|
if(pos!=buffer.npos && pos2!=buffer.npos)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return buffer.substr(pos+2,pos2-pos-2);
|
|
|
|
}
|
|
|
|
}
|
2008-02-01 19:33:14 +03:00
|
|
|
this->CurrentPositionInFile = buffer.npos;
|
2008-01-08 19:38:28 +03:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Query for the cpu status */
|
2008-01-31 22:34:11 +03:00
|
|
|
int SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
this->NumberOfLogicalCPU = 0;
|
|
|
|
this->NumberOfPhysicalCPU = 0;
|
2008-01-31 05:40:43 +03:00
|
|
|
kwsys_stl::string buffer;
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
FILE *fd = fopen("/proc/cpuinfo", "r" );
|
|
|
|
if ( !fd )
|
|
|
|
{
|
2008-10-17 19:29:30 +04:00
|
|
|
kwsys_ios::cout << "Problem opening /proc/cpuinfo" << kwsys_ios::endl;
|
2008-01-08 19:38:28 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-02-01 19:36:06 +03:00
|
|
|
size_t fileSize = 0;
|
2008-01-08 19:38:28 +03:00
|
|
|
while(!feof(fd))
|
|
|
|
{
|
2009-03-20 05:48:05 +03:00
|
|
|
buffer += static_cast<char>(fgetc(fd));
|
2008-01-08 19:38:28 +03:00
|
|
|
fileSize++;
|
|
|
|
}
|
|
|
|
fclose( fd );
|
|
|
|
buffer.resize(fileSize-2);
|
2008-05-31 19:23:15 +04:00
|
|
|
// Number of logical CPUs (combination of multiple processors, multi-core
|
|
|
|
// and hyperthreading)
|
2008-02-01 19:30:08 +03:00
|
|
|
size_t pos = buffer.find("processor\t");
|
|
|
|
while(pos != buffer.npos)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
this->NumberOfLogicalCPU++;
|
|
|
|
pos = buffer.find("processor\t",pos+1);
|
|
|
|
}
|
|
|
|
|
2008-06-01 22:40:11 +04:00
|
|
|
#ifdef __linux
|
2008-05-31 19:23:15 +04:00
|
|
|
// Find the largest physical id.
|
|
|
|
int maxId = -1;
|
|
|
|
kwsys_stl::string idc =
|
|
|
|
this->ExtractValueFromCpuInfoFile(buffer,"physical id");
|
2008-02-03 00:18:35 +03:00
|
|
|
while(this->CurrentPositionInFile != buffer.npos)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-05-31 19:23:15 +04:00
|
|
|
int id = atoi(idc.c_str());
|
|
|
|
if(id > maxId)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-05-31 19:23:15 +04:00
|
|
|
maxId=id;
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
2008-05-31 19:23:15 +04:00
|
|
|
idc = this->ExtractValueFromCpuInfoFile(buffer,"physical id",
|
|
|
|
this->CurrentPositionInFile+1);
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
2008-05-31 19:23:15 +04:00
|
|
|
// Physical ids returned by Linux don't distinguish cores.
|
|
|
|
// We want to record the total number of cores in this->NumberOfPhysicalCPU
|
|
|
|
// (checking only the first proc)
|
|
|
|
kwsys_stl::string cores =
|
|
|
|
this->ExtractValueFromCpuInfoFile(buffer,"cpu cores");
|
|
|
|
int numberOfCoresPerCPU=atoi(cores.c_str());
|
2009-03-20 05:48:05 +03:00
|
|
|
this->NumberOfPhysicalCPU=static_cast<unsigned int>(
|
|
|
|
numberOfCoresPerCPU*(maxId+1));
|
2008-06-01 22:40:11 +04:00
|
|
|
|
|
|
|
#else // __CYGWIN__
|
|
|
|
// does not have "physical id" entries, neither "cpu cores"
|
2008-06-02 00:11:38 +04:00
|
|
|
// this has to be fixed for hyper-threading.
|
|
|
|
kwsys_stl::string cpucount =
|
|
|
|
this->ExtractValueFromCpuInfoFile(buffer,"cpu count");
|
|
|
|
this->NumberOfPhysicalCPU=
|
|
|
|
this->NumberOfLogicalCPU = atoi(cpucount.c_str());
|
2008-06-01 22:40:11 +04:00
|
|
|
#endif
|
2008-06-02 07:40:30 +04:00
|
|
|
// gotta have one, and if this is 0 then we get a / by 0n
|
|
|
|
// beter to have a bad answer than a crash
|
|
|
|
if(this->NumberOfPhysicalCPU <= 0)
|
|
|
|
{
|
|
|
|
this->NumberOfPhysicalCPU = 1;
|
|
|
|
}
|
2008-05-31 19:23:15 +04:00
|
|
|
// LogicalProcessorsPerPhysical>1 => hyperthreading.
|
|
|
|
this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical=
|
2009-03-20 05:48:05 +03:00
|
|
|
this->NumberOfLogicalCPU/this->NumberOfPhysicalCPU;
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
// CPU speed (checking only the first proc
|
2008-01-31 05:40:43 +03:00
|
|
|
kwsys_stl::string CPUSpeed = this->ExtractValueFromCpuInfoFile(buffer,"cpu MHz");
|
2008-05-31 19:23:15 +04:00
|
|
|
this->CPUSpeedInMHz = static_cast<float>(atof(CPUSpeed.c_str()));
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
// Chip family
|
|
|
|
this->ChipID.Family = atoi(this->ExtractValueFromCpuInfoFile(buffer,"cpu family").c_str());
|
|
|
|
|
|
|
|
// Chip Vendor
|
|
|
|
strcpy(this->ChipID.Vendor,this->ExtractValueFromCpuInfoFile(buffer,"vendor_id").c_str());
|
|
|
|
this->FindManufacturer();
|
|
|
|
|
|
|
|
// Chip Model
|
|
|
|
this->ChipID.Model = atoi(this->ExtractValueFromCpuInfoFile(buffer,"model").c_str());
|
|
|
|
this->RetrieveClassicalCPUIdentity();
|
|
|
|
|
|
|
|
// L1 Cache size
|
2008-01-31 05:40:43 +03:00
|
|
|
kwsys_stl::string cacheSize = this->ExtractValueFromCpuInfoFile(buffer,"cache size");
|
2008-01-08 19:38:28 +03:00
|
|
|
pos = cacheSize.find(" KB");
|
2008-02-01 20:35:50 +03:00
|
|
|
if(pos!=cacheSize.npos)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
cacheSize = cacheSize.substr(0,pos);
|
|
|
|
}
|
|
|
|
this->Features.L1CacheSize = atoi(cacheSize.c_str());
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Query for the memory status */
|
2008-01-31 22:34:11 +03:00
|
|
|
int SystemInformationImplementation::QueryMemory()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
this->TotalVirtualMemory = 0;
|
|
|
|
this->TotalPhysicalMemory = 0;
|
|
|
|
this->AvailableVirtualMemory = 0;
|
|
|
|
this->AvailablePhysicalMemory = 0;
|
|
|
|
#ifdef __CYGWIN__
|
|
|
|
return 0;
|
2008-01-31 23:10:19 +03:00
|
|
|
#elif _WIN32
|
2008-05-03 01:22:46 +04:00
|
|
|
#if _MSC_VER < 1300
|
|
|
|
MEMORYSTATUS ms;
|
2009-11-18 19:22:38 +03:00
|
|
|
ms.dwLength = sizeof(ms);
|
2008-05-03 01:36:08 +04:00
|
|
|
GlobalMemoryStatus(&ms);
|
2008-05-03 01:22:46 +04:00
|
|
|
#define MEM_VAL(value) dw##value
|
|
|
|
#else
|
2008-05-02 19:44:26 +04:00
|
|
|
MEMORYSTATUSEX ms;
|
2009-11-18 19:22:38 +03:00
|
|
|
ms.dwLength = sizeof(ms);
|
|
|
|
if (0 == GlobalMemoryStatusEx(&ms))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2008-05-03 01:22:46 +04:00
|
|
|
#define MEM_VAL(value) ull##value
|
|
|
|
#endif
|
|
|
|
unsigned long tv = ms.MEM_VAL(TotalVirtual);
|
|
|
|
unsigned long tp = ms.MEM_VAL(TotalPhys);
|
|
|
|
unsigned long av = ms.MEM_VAL(AvailVirtual);
|
|
|
|
unsigned long ap = ms.MEM_VAL(AvailPhys);
|
2008-01-08 19:38:28 +03:00
|
|
|
this->TotalVirtualMemory = tv>>10>>10;
|
|
|
|
this->TotalPhysicalMemory = tp>>10>>10;
|
|
|
|
this->AvailableVirtualMemory = av>>10>>10;
|
|
|
|
this->AvailablePhysicalMemory = ap>>10>>10;
|
|
|
|
return 1;
|
|
|
|
#elif __linux
|
|
|
|
unsigned long tv=0;
|
|
|
|
unsigned long tp=0;
|
|
|
|
unsigned long av=0;
|
|
|
|
unsigned long ap=0;
|
|
|
|
|
2009-04-06 22:55:54 +04:00
|
|
|
char buffer[1024]; // for reading lines
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
int linuxMajor = 0;
|
|
|
|
int linuxMinor = 0;
|
|
|
|
|
|
|
|
// Find the Linux kernel version first
|
|
|
|
struct utsname unameInfo;
|
|
|
|
int errorFlag = uname(&unameInfo);
|
|
|
|
if( errorFlag!=0 )
|
|
|
|
{
|
2008-10-17 19:29:30 +04:00
|
|
|
kwsys_ios::cout << "Problem calling uname(): " << strerror(errno) << kwsys_ios::endl;
|
2008-01-08 19:38:28 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( unameInfo.release!=0 && strlen(unameInfo.release)>=3 )
|
|
|
|
{
|
|
|
|
// release looks like "2.6.3-15mdk-i686-up-4GB"
|
|
|
|
char majorChar=unameInfo.release[0];
|
|
|
|
char minorChar=unameInfo.release[2];
|
|
|
|
|
|
|
|
if( isdigit(majorChar) )
|
|
|
|
{
|
|
|
|
linuxMajor=majorChar-'0';
|
|
|
|
}
|
|
|
|
|
|
|
|
if( isdigit(minorChar) )
|
|
|
|
{
|
|
|
|
linuxMinor=minorChar-'0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE *fd = fopen("/proc/meminfo", "r" );
|
|
|
|
if ( !fd )
|
|
|
|
{
|
2008-10-17 19:29:30 +04:00
|
|
|
kwsys_ios::cout << "Problem opening /proc/meminfo" << kwsys_ios::endl;
|
2008-01-08 19:38:28 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( linuxMajor>=3 || ( (linuxMajor>=2) && (linuxMinor>=6) ) )
|
|
|
|
{
|
|
|
|
// new /proc/meminfo format since kernel 2.6.x
|
|
|
|
// Rigorously, this test should check from the developping version 2.5.x
|
|
|
|
// that introduced the new format...
|
2009-03-20 05:48:05 +03:00
|
|
|
|
2009-04-06 22:55:54 +04:00
|
|
|
enum { mMemTotal, mMemFree, mBuffers, mCached, mSwapTotal, mSwapFree };
|
|
|
|
const char* format[6] =
|
|
|
|
{ "MemTotal:%lu kB", "MemFree:%lu kB", "Buffers:%lu kB",
|
|
|
|
"Cached:%lu kB", "SwapTotal:%lu kB", "SwapFree:%lu kB" };
|
|
|
|
bool have[6] = { false, false, false, false, false, false };
|
|
|
|
unsigned long value[6];
|
|
|
|
int count = 0;
|
|
|
|
while(fgets(buffer, sizeof(buffer), fd))
|
2009-03-20 05:48:05 +03:00
|
|
|
{
|
2009-04-06 22:55:54 +04:00
|
|
|
for(int i=0; i < 6; ++i)
|
|
|
|
{
|
|
|
|
if(!have[i] && sscanf(buffer, format[i], &value[i]) == 1)
|
|
|
|
{
|
|
|
|
have[i] = true;
|
|
|
|
++count;
|
|
|
|
}
|
|
|
|
}
|
2009-03-20 05:48:05 +03:00
|
|
|
}
|
2009-04-06 22:55:54 +04:00
|
|
|
if(count == 6)
|
2009-03-20 05:48:05 +03:00
|
|
|
{
|
2009-04-06 22:55:54 +04:00
|
|
|
this->TotalPhysicalMemory = value[mMemTotal] / 1024;
|
|
|
|
this->AvailablePhysicalMemory =
|
|
|
|
(value[mMemFree] + value[mBuffers] + value[mCached]) / 1024;
|
|
|
|
this->TotalVirtualMemory = value[mSwapTotal] / 1024;
|
|
|
|
this->AvailableVirtualMemory = value[mSwapFree] / 1024;
|
2009-03-20 05:48:05 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kwsys_ios::cout << "Problem parsing /proc/meminfo" << kwsys_ios::endl;
|
|
|
|
fclose(fd);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// /proc/meminfo format for kernel older than 2.6.x
|
|
|
|
|
|
|
|
unsigned long temp;
|
|
|
|
unsigned long cachedMem;
|
|
|
|
unsigned long buffersMem;
|
2009-03-20 05:48:05 +03:00
|
|
|
char *r=fgets(buffer, sizeof(buffer), fd); // Skip "total: used:..."
|
|
|
|
int status=0;
|
|
|
|
if(r==buffer)
|
|
|
|
{
|
|
|
|
status+=fscanf(fd, "Mem: %lu %lu %lu %lu %lu %lu\n",
|
|
|
|
&tp, &temp, &ap, &temp, &buffersMem, &cachedMem);
|
|
|
|
}
|
|
|
|
if(status==6)
|
|
|
|
{
|
|
|
|
status+=fscanf(fd, "Swap: %lu %lu %lu\n", &tv, &temp, &av);
|
|
|
|
}
|
|
|
|
if(status==9)
|
|
|
|
{
|
|
|
|
this->TotalVirtualMemory = tv>>10>>10;
|
|
|
|
this->TotalPhysicalMemory = tp>>10>>10;
|
|
|
|
this->AvailableVirtualMemory = av>>10>>10;
|
|
|
|
this->AvailablePhysicalMemory = (ap+buffersMem+cachedMem)>>10>>10;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
kwsys_ios::cout << "Problem parsing /proc/meminfo" << kwsys_ios::endl;
|
|
|
|
fclose(fd);
|
|
|
|
return 0;
|
|
|
|
}
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
fclose( fd );
|
|
|
|
return 1;
|
|
|
|
#elif __hpux
|
|
|
|
unsigned long tv=0;
|
|
|
|
unsigned long tp=0;
|
|
|
|
unsigned long av=0;
|
|
|
|
unsigned long ap=0;
|
|
|
|
struct pst_static pst;
|
|
|
|
struct pst_dynamic pdy;
|
|
|
|
|
|
|
|
unsigned long ps = 0;
|
|
|
|
if (pstat_getstatic(&pst, sizeof(pst), (size_t) 1, 0) != -1)
|
|
|
|
{
|
|
|
|
ps = pst.page_size;
|
|
|
|
tp = pst.physical_memory *ps;
|
|
|
|
tv = (pst.physical_memory + pst.pst_maxmem) * ps;
|
|
|
|
if (pstat_getdynamic(&pdy, sizeof(pdy), (size_t) 1, 0) != -1)
|
|
|
|
{
|
|
|
|
ap = tp - pdy.psd_rm * ps;
|
|
|
|
av = tv - pdy.psd_vm;
|
|
|
|
this->TotalVirtualMemory = tv>>10>>10;
|
|
|
|
this->TotalPhysicalMemory = tp>>10>>10;
|
|
|
|
this->AvailableVirtualMemory = av>>10>>10;
|
|
|
|
this->AvailablePhysicalMemory = ap>>10>>10;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/** */
|
2009-11-16 20:43:44 +03:00
|
|
|
size_t SystemInformationImplementation::GetTotalVirtualMemory()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->TotalVirtualMemory;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** */
|
2009-11-16 20:43:44 +03:00
|
|
|
size_t SystemInformationImplementation::GetAvailableVirtualMemory()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->AvailableVirtualMemory;
|
|
|
|
}
|
|
|
|
|
2009-11-16 20:43:44 +03:00
|
|
|
size_t SystemInformationImplementation::GetTotalPhysicalMemory()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->TotalPhysicalMemory;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** */
|
2009-11-16 20:43:44 +03:00
|
|
|
size_t SystemInformationImplementation::GetAvailablePhysicalMemory()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->AvailablePhysicalMemory;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get Cycle differences */
|
2008-01-31 22:34:11 +03:00
|
|
|
LongLong SystemInformationImplementation::GetCyclesDifference (DELAY_FUNC DelayFunction,
|
2008-01-09 01:20:04 +03:00
|
|
|
unsigned int uiParameter)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-01-31 23:10:19 +03:00
|
|
|
#if USE_ASM_INSTRUCTIONS
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
unsigned int edx1, eax1;
|
|
|
|
unsigned int edx2, eax2;
|
|
|
|
|
|
|
|
// Calculate the frequency of the CPU instructions.
|
|
|
|
__try {
|
|
|
|
_asm {
|
|
|
|
push uiParameter ; push parameter param
|
|
|
|
mov ebx, DelayFunction ; store func in ebx
|
|
|
|
|
|
|
|
RDTSC_INSTRUCTION
|
|
|
|
|
|
|
|
mov esi, eax ; esi = eax
|
|
|
|
mov edi, edx ; edi = edx
|
|
|
|
|
|
|
|
call ebx ; call the delay functions
|
|
|
|
|
|
|
|
RDTSC_INSTRUCTION
|
|
|
|
|
|
|
|
pop ebx
|
|
|
|
|
|
|
|
mov edx2, edx ; edx2 = edx
|
|
|
|
mov eax2, eax ; eax2 = eax
|
|
|
|
|
|
|
|
mov edx1, edi ; edx2 = edi
|
|
|
|
mov eax1, esi ; eax2 = esi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__except(1)
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((((__int64) edx2 << 32) + eax2) - (((__int64) edx1 << 32) + eax1));
|
|
|
|
|
|
|
|
#else
|
2008-01-09 01:20:04 +03:00
|
|
|
(void)DelayFunction;
|
|
|
|
(void)uiParameter;
|
2008-01-08 19:38:28 +03:00
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** Compute the delay overhead */
|
2008-01-31 22:34:11 +03:00
|
|
|
void SystemInformationImplementation::DelayOverhead(unsigned int uiMS)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-01-31 23:10:19 +03:00
|
|
|
#if _WIN32
|
2008-01-08 19:38:28 +03:00
|
|
|
LARGE_INTEGER Frequency, StartCounter, EndCounter;
|
|
|
|
__int64 x;
|
|
|
|
|
|
|
|
// Get the frequency of the high performance counter.
|
|
|
|
if(!QueryPerformanceFrequency (&Frequency))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
x = Frequency.QuadPart / 1000 * uiMS;
|
|
|
|
|
|
|
|
// Get the starting position of the counter.
|
|
|
|
QueryPerformanceCounter (&StartCounter);
|
|
|
|
|
|
|
|
do {
|
|
|
|
// Get the ending position of the counter.
|
|
|
|
QueryPerformanceCounter (&EndCounter);
|
|
|
|
} while (EndCounter.QuadPart - StartCounter.QuadPart == x);
|
|
|
|
#endif
|
2008-01-09 01:20:04 +03:00
|
|
|
(void)uiMS;
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Return the number of logical CPU per physical CPUs Works only for windows */
|
2008-01-31 22:34:11 +03:00
|
|
|
unsigned char SystemInformationImplementation::LogicalCPUPerPhysicalCPU(void)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
unsigned int Regebx = 0;
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 23:10:19 +03:00
|
|
|
#if USE_ASM_INSTRUCTIONS
|
2008-01-08 19:38:28 +03:00
|
|
|
if (!this->IsHyperThreadingSupported())
|
|
|
|
{
|
2008-12-16 01:19:26 +03:00
|
|
|
return static_cast<unsigned char>(1); // HT not supported
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
__asm
|
|
|
|
{
|
|
|
|
mov eax, 1
|
|
|
|
cpuid
|
|
|
|
mov Regebx, ebx
|
|
|
|
}
|
|
|
|
#endif
|
2009-05-20 17:50:20 +04:00
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
size_t len = 4;
|
|
|
|
int cores_per_package = 0;
|
|
|
|
int err = sysctlbyname("machdep.cpu.cores_per_package", &cores_per_package, &len, NULL, 0);
|
|
|
|
if (err != 0)
|
|
|
|
{
|
|
|
|
return 1; // That name was not found, default to 1
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return static_cast<unsigned char>(cores_per_package);
|
|
|
|
}
|
|
|
|
#endif
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-12-16 01:19:26 +03:00
|
|
|
return static_cast<unsigned char> ((Regebx & NUM_LOGICAL_BITS) >> 16);
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** Works only for windows */
|
2008-01-31 22:34:11 +03:00
|
|
|
unsigned int SystemInformationImplementation::IsHyperThreadingSupported()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-01-31 23:10:19 +03:00
|
|
|
#if USE_ASM_INSTRUCTIONS
|
2008-01-08 19:38:28 +03:00
|
|
|
unsigned int Regedx = 0,
|
|
|
|
Regeax = 0,
|
|
|
|
VendorId[3] = {0, 0, 0};
|
|
|
|
__try // Verify cpuid instruction is supported
|
|
|
|
{
|
|
|
|
__asm
|
|
|
|
{
|
|
|
|
xor eax, eax // call cpuid with eax = 0
|
|
|
|
cpuid // Get vendor id string
|
|
|
|
mov VendorId, ebx
|
|
|
|
mov VendorId + 4, edx
|
|
|
|
mov VendorId + 8, ecx
|
|
|
|
|
|
|
|
mov eax, 1 // call cpuid with eax = 1
|
|
|
|
cpuid
|
|
|
|
mov Regeax, eax // eax contains family processor type
|
|
|
|
mov Regedx, edx // edx has info about the availability of hyper-Threading
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__except (EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
return(0); // cpuid is unavailable
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((Regeax & FAMILY_ID) == PENTIUM4_ID) || (Regeax & EXT_FAMILY_ID))
|
|
|
|
{
|
|
|
|
if (VendorId[0] == 'uneG')
|
|
|
|
{
|
|
|
|
if (VendorId[1] == 'Ieni')
|
|
|
|
{
|
|
|
|
if (VendorId[2] == 'letn')
|
|
|
|
{
|
|
|
|
return(Regedx & HT_BIT); // Genuine Intel with hyper-Threading technology
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return 0; // Not genuine Intel processor
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** Return the APIC Id. Works only for windows. */
|
2008-01-31 22:34:11 +03:00
|
|
|
unsigned char SystemInformationImplementation::GetAPICId()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
unsigned int Regebx = 0;
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-31 23:10:19 +03:00
|
|
|
#if USE_ASM_INSTRUCTIONS
|
2008-01-08 19:38:28 +03:00
|
|
|
if (!this->IsHyperThreadingSupported())
|
|
|
|
{
|
2008-12-16 01:19:26 +03:00
|
|
|
return static_cast<unsigned char>(-1); // HT not supported
|
2008-01-08 19:38:28 +03:00
|
|
|
} // Logical processor = 1
|
|
|
|
__asm
|
|
|
|
{
|
|
|
|
mov eax, 1
|
|
|
|
cpuid
|
|
|
|
mov Regebx, ebx
|
|
|
|
}
|
|
|
|
#endif
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-12-16 01:19:26 +03:00
|
|
|
return static_cast<unsigned char>((Regebx & INITIAL_APIC_ID_BITS) >> 24);
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** Count the number of CPUs. Works only on windows. */
|
2008-01-31 22:34:11 +03:00
|
|
|
int SystemInformationImplementation::CPUCount()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-01-31 23:10:19 +03:00
|
|
|
#if _WIN32
|
2008-01-08 19:38:28 +03:00
|
|
|
unsigned char StatusFlag = 0;
|
|
|
|
SYSTEM_INFO info;
|
|
|
|
|
|
|
|
this->NumberOfPhysicalCPU = 0;
|
|
|
|
this->NumberOfLogicalCPU = 0;
|
|
|
|
info.dwNumberOfProcessors = 0;
|
|
|
|
GetSystemInfo (&info);
|
|
|
|
|
|
|
|
// Number of physical processors in a non-Intel system
|
|
|
|
// or in a 32-bit Intel system with Hyper-Threading technology disabled
|
|
|
|
this->NumberOfPhysicalCPU = (unsigned char) info.dwNumberOfProcessors;
|
|
|
|
|
|
|
|
if (this->IsHyperThreadingSupported())
|
|
|
|
{
|
|
|
|
unsigned char HT_Enabled = 0;
|
|
|
|
this->NumberOfLogicalCPU = this->LogicalCPUPerPhysicalCPU();
|
|
|
|
if (this->NumberOfLogicalCPU >= 1) // >1 Doesn't mean HT is enabled in the BIOS
|
|
|
|
{
|
|
|
|
HANDLE hCurrentProcessHandle;
|
2008-02-01 19:30:08 +03:00
|
|
|
#ifndef _WIN64
|
|
|
|
# define DWORD_PTR DWORD
|
|
|
|
#endif
|
|
|
|
DWORD_PTR dwProcessAffinity;
|
|
|
|
DWORD_PTR dwSystemAffinity;
|
2008-01-08 19:38:28 +03:00
|
|
|
DWORD dwAffinityMask;
|
|
|
|
|
|
|
|
// Calculate the appropriate shifts and mask based on the
|
|
|
|
// number of logical processors.
|
2008-02-01 00:37:52 +03:00
|
|
|
unsigned int i = 1;
|
2008-01-08 19:38:28 +03:00
|
|
|
unsigned char PHY_ID_MASK = 0xFF;
|
2008-05-02 17:14:37 +04:00
|
|
|
//unsigned char PHY_ID_SHIFT = 0;
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
while (i < this->NumberOfLogicalCPU)
|
|
|
|
{
|
|
|
|
i *= 2;
|
|
|
|
PHY_ID_MASK <<= 1;
|
2008-05-02 17:14:37 +04:00
|
|
|
// PHY_ID_SHIFT++;
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
hCurrentProcessHandle = GetCurrentProcess();
|
|
|
|
GetProcessAffinityMask(hCurrentProcessHandle, &dwProcessAffinity,
|
|
|
|
&dwSystemAffinity);
|
|
|
|
|
|
|
|
// Check if available process affinity mask is equal to the
|
|
|
|
// available system affinity mask
|
|
|
|
if (dwProcessAffinity != dwSystemAffinity)
|
|
|
|
{
|
|
|
|
StatusFlag = HT_CANNOT_DETECT;
|
|
|
|
this->NumberOfPhysicalCPU = (unsigned char)-1;
|
|
|
|
return StatusFlag;
|
|
|
|
}
|
|
|
|
|
|
|
|
dwAffinityMask = 1;
|
|
|
|
while (dwAffinityMask != 0 && dwAffinityMask <= dwProcessAffinity)
|
|
|
|
{
|
|
|
|
// Check if this CPU is available
|
|
|
|
if (dwAffinityMask & dwProcessAffinity)
|
|
|
|
{
|
|
|
|
if (SetProcessAffinityMask(hCurrentProcessHandle,
|
|
|
|
dwAffinityMask))
|
|
|
|
{
|
2008-02-01 00:37:52 +03:00
|
|
|
unsigned char APIC_ID, LOG_ID;
|
2008-01-08 19:38:28 +03:00
|
|
|
Sleep(0); // Give OS time to switch CPU
|
|
|
|
|
|
|
|
APIC_ID = GetAPICId();
|
|
|
|
LOG_ID = APIC_ID & ~PHY_ID_MASK;
|
|
|
|
|
|
|
|
if (LOG_ID != 0)
|
|
|
|
{
|
|
|
|
HT_Enabled = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dwAffinityMask = dwAffinityMask << 1;
|
|
|
|
}
|
|
|
|
// Reset the processor affinity
|
|
|
|
SetProcessAffinityMask(hCurrentProcessHandle, dwProcessAffinity);
|
|
|
|
|
|
|
|
if (this->NumberOfLogicalCPU == 1) // Normal P4 : HT is disabled in hardware
|
|
|
|
{
|
|
|
|
StatusFlag = HT_DISABLED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (HT_Enabled)
|
|
|
|
{
|
|
|
|
// Total physical processors in a Hyper-Threading enabled system.
|
|
|
|
this->NumberOfPhysicalCPU /= (this->NumberOfLogicalCPU);
|
|
|
|
StatusFlag = HT_ENABLED;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
StatusFlag = HT_SUPPORTED_NOT_ENABLED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Processors do not have Hyper-Threading technology
|
|
|
|
StatusFlag = HT_NOT_CAPABLE;
|
|
|
|
this->NumberOfLogicalCPU = 1;
|
|
|
|
}
|
|
|
|
return StatusFlag;
|
2008-01-09 01:20:04 +03:00
|
|
|
#else
|
|
|
|
return 0;
|
2008-01-08 19:38:28 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** Return the number of logical CPUs on the system */
|
2008-01-31 22:34:11 +03:00
|
|
|
unsigned int SystemInformationImplementation::GetNumberOfLogicalCPU()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->NumberOfLogicalCPU;
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** Return the number of physical CPUs on the system */
|
2008-01-31 22:34:11 +03:00
|
|
|
unsigned int SystemInformationImplementation::GetNumberOfPhysicalCPU()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->NumberOfPhysicalCPU;
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2009-05-20 17:50:20 +04:00
|
|
|
/** For Mac use sysctlbyname calls to find system info */
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformationImplementation::ParseSysCtl()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2009-05-20 17:50:20 +04:00
|
|
|
#if defined(__APPLE__)
|
|
|
|
int err = 0;
|
|
|
|
uint64_t value = 0;
|
|
|
|
size_t len = sizeof(value);
|
|
|
|
sysctlbyname("hw.memsize", &value, &len, NULL, 0);
|
2009-11-15 23:57:06 +03:00
|
|
|
this->TotalPhysicalMemory = static_cast< size_t >( value/1048576 );
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
// Parse values for Mac
|
|
|
|
this->AvailablePhysicalMemory = 0;
|
2009-05-20 17:50:20 +04:00
|
|
|
vm_statistics_data_t vmstat;
|
|
|
|
mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
|
|
|
|
if ( host_statistics(mach_host_self(), HOST_VM_INFO,
|
|
|
|
(host_info_t) &vmstat, &count) == KERN_SUCCESS )
|
|
|
|
{
|
|
|
|
err = sysctlbyname("hw.pagesize", &value, &len, NULL, 0);
|
|
|
|
int64_t available_memory = vmstat.free_count * value;
|
2009-11-15 23:57:06 +03:00
|
|
|
this->AvailablePhysicalMemory = static_cast< size_t >( available_memory / 1048576 );
|
2009-05-20 17:50:20 +04:00
|
|
|
}
|
2008-01-08 19:38:28 +03:00
|
|
|
|
2009-05-20 17:50:20 +04:00
|
|
|
#ifdef VM_SWAPUSAGE
|
|
|
|
// Virtual memory.
|
|
|
|
int mib[2] = { CTL_VM, VM_SWAPUSAGE };
|
|
|
|
size_t miblen = sizeof(mib) / sizeof(mib[0]);
|
|
|
|
struct xsw_usage swap;
|
|
|
|
len = sizeof(struct xsw_usage);
|
|
|
|
err = sysctl(mib, miblen, &swap, &len, NULL, 0);
|
|
|
|
if (err == 0)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2009-11-15 23:57:06 +03:00
|
|
|
this->AvailableVirtualMemory = static_cast< size_t >( swap.xsu_avail/1048576 );
|
|
|
|
this->TotalVirtualMemory = static_cast< size_t >( swap.xsu_total/1048576 );
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
2009-05-20 17:50:20 +04:00
|
|
|
#else
|
|
|
|
this->AvailableVirtualMemory = 0;
|
|
|
|
this->TotalVirtualMemory = 0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// CPU Info
|
|
|
|
len = sizeof(this->NumberOfPhysicalCPU);
|
|
|
|
sysctlbyname("hw.physicalcpu", &this->NumberOfPhysicalCPU, &len, NULL, 0);
|
|
|
|
sysctlbyname("hw.logicalcpu", &this->NumberOfLogicalCPU, &len, NULL, 0);
|
|
|
|
this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical =
|
|
|
|
this->LogicalCPUPerPhysicalCPU();
|
|
|
|
|
|
|
|
len = sizeof(value);
|
|
|
|
sysctlbyname("hw.cpufrequency", &value, &len, NULL, 0);
|
2009-11-15 23:57:06 +03:00
|
|
|
this->CPUSpeedInMHz = static_cast< float >( value )/ 1048576;
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
|
|
|
|
// Chip family
|
2009-05-20 17:50:20 +04:00
|
|
|
len = sizeof(this->ChipID.Family);
|
|
|
|
//Seems only the intel chips will have this name so if this fails it is
|
|
|
|
//probably a PPC machine
|
|
|
|
err = sysctlbyname("machdep.cpu.family",
|
|
|
|
&this->ChipID.Family, &len, NULL, 0);
|
|
|
|
if (err != 0) // Go back to names we know but are less descriptive
|
|
|
|
{
|
|
|
|
this->ChipID.Family = 0;
|
|
|
|
char retBuf[32];
|
|
|
|
::memset(retBuf, 0, 32);
|
|
|
|
len = 32;
|
|
|
|
err = sysctlbyname("hw.machine", &retBuf, &len, NULL, 0);
|
|
|
|
kwsys_stl::string machineBuf(retBuf);
|
|
|
|
if (machineBuf.find_first_of("Power") != kwsys_stl::string::npos)
|
|
|
|
{
|
|
|
|
strcpy(this->ChipID.Vendor, "IBM");
|
|
|
|
len = 4;
|
|
|
|
err = sysctlbyname("hw.cputype", &this->ChipID.Family, &len, NULL, 0);
|
|
|
|
err = sysctlbyname("hw.cpusubtype", &this->ChipID.Model, &len, NULL, 0);
|
|
|
|
this->FindManufacturer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // Should be an Intel Chip.
|
|
|
|
{
|
|
|
|
len = sizeof(this->ChipID.Family);
|
|
|
|
err =
|
|
|
|
sysctlbyname("machdep.cpu.family", &this->ChipID.Family, &len, NULL, 0);
|
|
|
|
|
|
|
|
char retBuf[128];
|
|
|
|
::memset(retBuf, 0, 128);
|
|
|
|
len = 128;
|
|
|
|
err = sysctlbyname("machdep.cpu.vendor", retBuf, &len, NULL, 0);
|
|
|
|
// Chip Vendor
|
|
|
|
strcpy(this->ChipID.Vendor,retBuf);
|
|
|
|
this->FindManufacturer();
|
|
|
|
|
|
|
|
len=CHIPNAME_STRING_LENGTH;
|
|
|
|
err =
|
|
|
|
sysctlbyname("machdep.cpu.brand_string",
|
|
|
|
this->ChipID.ProcessorName, &len, NULL, 0);
|
2008-01-08 19:38:28 +03:00
|
|
|
|
2009-05-20 17:50:20 +04:00
|
|
|
// Chip Model
|
|
|
|
len = sizeof(value);
|
|
|
|
err = sysctlbyname("machdep.cpu.model", &value, &len, NULL, 0);
|
2009-11-15 23:57:06 +03:00
|
|
|
this->ChipID.Model = static_cast< int >( value );
|
2009-05-20 17:50:20 +04:00
|
|
|
}
|
2008-01-08 19:38:28 +03:00
|
|
|
// Cache size
|
2009-05-20 17:50:20 +04:00
|
|
|
len = sizeof(value);
|
|
|
|
err = sysctlbyname("hw.l1icachesize", &value, &len, NULL, 0);
|
2009-11-15 23:57:06 +03:00
|
|
|
this->Features.L1CacheSize = static_cast< int >( value );
|
2009-05-20 17:50:20 +04:00
|
|
|
err = sysctlbyname("hw.l2cachesize", &value, &len, NULL, 0);
|
2009-11-15 23:57:06 +03:00
|
|
|
this->Features.L2CacheSize = static_cast< int >( value );
|
2009-05-20 17:50:20 +04:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
return true;
|
2009-05-20 17:50:20 +04:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** Extract a value from sysctl command */
|
2008-01-31 22:34:11 +03:00
|
|
|
kwsys_stl::string SystemInformationImplementation::ExtractValueFromSysCtl(const char* word)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-02-01 19:30:08 +03:00
|
|
|
size_t pos = this->SysCtlBuffer.find(word);
|
|
|
|
if(pos != this->SysCtlBuffer.npos)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
pos = this->SysCtlBuffer.find(": ",pos);
|
2008-02-01 19:30:08 +03:00
|
|
|
size_t pos2 = this->SysCtlBuffer.find("\n",pos);
|
|
|
|
if(pos!=this->SysCtlBuffer.npos && pos2!=this->SysCtlBuffer.npos)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
return this->SysCtlBuffer.substr(pos+2,pos2-pos-2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** Run a given process */
|
2008-01-31 22:34:11 +03:00
|
|
|
kwsys_stl::string SystemInformationImplementation::RunProcess(kwsys_stl::vector<const char*> args)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-01-31 05:40:43 +03:00
|
|
|
kwsys_stl::string buffer = "";
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
// Run the application
|
|
|
|
kwsysProcess* gp = kwsysProcess_New();
|
|
|
|
kwsysProcess_SetCommand(gp, &*args.begin());
|
|
|
|
kwsysProcess_SetOption(gp,kwsysProcess_Option_HideWindow,1);
|
|
|
|
|
|
|
|
kwsysProcess_Execute(gp);
|
|
|
|
|
|
|
|
char* data = NULL;
|
|
|
|
int length;
|
|
|
|
double timeout = 255;
|
|
|
|
|
|
|
|
while(kwsysProcess_WaitForData(gp,&data,&length,&timeout)) // wait for 1s
|
|
|
|
{
|
|
|
|
for(int i=0;i<length;i++)
|
|
|
|
{
|
|
|
|
buffer += data[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
kwsysProcess_WaitForExit(gp, 0);
|
|
|
|
|
2008-02-01 19:09:39 +03:00
|
|
|
int result = 0;
|
2008-01-08 19:38:28 +03:00
|
|
|
switch(kwsysProcess_GetState(gp))
|
|
|
|
{
|
|
|
|
case kwsysProcess_State_Exited:
|
|
|
|
{
|
|
|
|
result = kwsysProcess_GetExitValue(gp);
|
|
|
|
} break;
|
|
|
|
case kwsysProcess_State_Error:
|
|
|
|
{
|
2008-01-31 16:21:27 +03:00
|
|
|
kwsys_ios::cerr << "Error: Could not run " << args[0] << ":\n";
|
|
|
|
kwsys_ios::cerr << kwsysProcess_GetErrorString(gp) << "\n";
|
2008-01-08 19:38:28 +03:00
|
|
|
} break;
|
|
|
|
case kwsysProcess_State_Exception:
|
|
|
|
{
|
2008-01-31 16:21:27 +03:00
|
|
|
kwsys_ios::cerr << "Error: " << args[0]
|
2008-01-08 19:38:28 +03:00
|
|
|
<< " terminated with an exception: "
|
|
|
|
<< kwsysProcess_GetExceptionString(gp) << "\n";
|
|
|
|
} break;
|
|
|
|
case kwsysProcess_State_Starting:
|
|
|
|
case kwsysProcess_State_Executing:
|
|
|
|
case kwsysProcess_State_Expired:
|
|
|
|
case kwsysProcess_State_Killed:
|
|
|
|
{
|
|
|
|
// Should not get here.
|
2008-01-31 16:21:27 +03:00
|
|
|
kwsys_ios::cerr << "Unexpected ending state after running " << args[0]
|
2008-10-17 19:29:30 +04:00
|
|
|
<< kwsys_ios::endl;
|
2008-01-08 19:38:28 +03:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
kwsysProcess_Delete(gp);
|
2008-02-01 19:09:39 +03:00
|
|
|
if(result)
|
|
|
|
{
|
|
|
|
kwsys_ios::cerr << "Error " << args[0] << " returned :" << result << "\n";
|
|
|
|
}
|
2008-01-08 19:38:28 +03:00
|
|
|
return buffer;
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
|
2008-01-31 22:34:11 +03:00
|
|
|
kwsys_stl::string SystemInformationImplementation::ParseValueFromKStat(const char* arguments)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-01-31 05:40:43 +03:00
|
|
|
kwsys_stl::vector<const char*> args;
|
2008-01-08 19:38:28 +03:00
|
|
|
args.clear();
|
|
|
|
args.push_back("kstat");
|
|
|
|
args.push_back("-p");
|
|
|
|
|
2008-01-31 05:40:43 +03:00
|
|
|
kwsys_stl::string command = arguments;
|
2008-02-01 19:36:06 +03:00
|
|
|
size_t start = command.npos;
|
2008-02-01 19:30:08 +03:00
|
|
|
size_t pos = command.find(' ',0);
|
|
|
|
while(pos!=command.npos)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
bool inQuotes = false;
|
|
|
|
// Check if we are between quotes
|
2008-02-01 19:30:08 +03:00
|
|
|
size_t b0 = command.find('"',0);
|
|
|
|
size_t b1 = command.find('"',b0+1);
|
|
|
|
while(b0 != command.npos && b1 != command.npos && b1>b0)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
if(pos>b0 && pos<b1)
|
|
|
|
{
|
|
|
|
inQuotes = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
b0 = command.find('"',b1+1);
|
|
|
|
b1 = command.find('"',b0+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!inQuotes)
|
|
|
|
{
|
2008-01-31 05:40:43 +03:00
|
|
|
kwsys_stl::string arg = command.substr(start+1,pos-start-1);
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
// Remove the quotes if any
|
2008-02-01 19:30:08 +03:00
|
|
|
size_t quotes = arg.find('"');
|
2008-02-01 20:35:50 +03:00
|
|
|
while(quotes != arg.npos)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
arg.erase(quotes,1);
|
|
|
|
quotes = arg.find('"');
|
|
|
|
}
|
|
|
|
args.push_back(arg.c_str());
|
|
|
|
start = pos;
|
|
|
|
}
|
|
|
|
pos = command.find(' ',pos+1);
|
|
|
|
}
|
2008-01-31 05:40:43 +03:00
|
|
|
kwsys_stl::string lastArg = command.substr(start+1,command.size()-start-1);
|
2008-01-08 19:38:28 +03:00
|
|
|
args.push_back(lastArg.c_str());
|
|
|
|
|
|
|
|
args.push_back(0);
|
|
|
|
|
2008-01-31 05:40:43 +03:00
|
|
|
kwsys_stl::string buffer = this->RunProcess(args);
|
2008-01-08 19:38:28 +03:00
|
|
|
|
2008-01-31 05:40:43 +03:00
|
|
|
kwsys_stl::string value = "";
|
2008-02-01 19:40:55 +03:00
|
|
|
for(size_t i=buffer.size()-1;i>0;i--)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
if(buffer[i] == ' ' || buffer[i] == '\t')
|
|
|
|
{
|
|
|
|
break;
|
2009-10-06 22:55:48 +04:00
|
|
|
}
|
2008-01-08 19:38:28 +03:00
|
|
|
if(buffer[i] != '\n' && buffer[i] != '\r')
|
|
|
|
{
|
2008-01-31 05:40:43 +03:00
|
|
|
kwsys_stl::string val = value;
|
2008-01-08 19:38:28 +03:00
|
|
|
value = buffer[i];
|
|
|
|
value += val;
|
2009-10-06 22:55:48 +04:00
|
|
|
}
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** Querying for system information from Solaris */
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformationImplementation::QuerySolarisInfo()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
// Parse values
|
2009-03-20 05:48:05 +03:00
|
|
|
this->NumberOfPhysicalCPU = static_cast<unsigned int>(
|
|
|
|
atoi(this->ParseValueFromKStat("-n syste_misc -s ncpus").c_str()));
|
2008-01-08 19:38:28 +03:00
|
|
|
this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU;
|
|
|
|
|
|
|
|
if(this->NumberOfPhysicalCPU!=0)
|
|
|
|
{
|
|
|
|
this->NumberOfLogicalCPU /= this->NumberOfPhysicalCPU;
|
|
|
|
}
|
|
|
|
|
2008-12-16 01:19:26 +03:00
|
|
|
this->CPUSpeedInMHz = static_cast<float>(atoi(this->ParseValueFromKStat("-s clock_MHz").c_str()));
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
// Chip family
|
|
|
|
this->ChipID.Family = 0;
|
|
|
|
|
|
|
|
// Chip Vendor
|
|
|
|
strcpy(this->ChipID.Vendor,"Sun");
|
|
|
|
this->FindManufacturer();
|
|
|
|
|
|
|
|
// Chip Model
|
|
|
|
sprintf(this->ChipID.ProcessorName,"%s",this->ParseValueFromKStat("-s cpu_type").c_str());
|
|
|
|
this->ChipID.Model = 0;
|
|
|
|
|
|
|
|
// 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/1024;
|
|
|
|
this->TotalPhysicalMemory *= 8192;
|
|
|
|
this->TotalPhysicalMemory /= 1024;
|
|
|
|
|
|
|
|
// Undefined values (for now at least)
|
|
|
|
this->TotalVirtualMemory = 0;
|
|
|
|
this->AvailablePhysicalMemory = 0;
|
|
|
|
this->AvailableVirtualMemory = 0;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2009-02-12 18:08:15 +03:00
|
|
|
/** Querying for system information from Haiku OS */
|
|
|
|
bool SystemInformationImplementation::QueryHaikuInfo()
|
|
|
|
{
|
|
|
|
#if defined(__HAIKU__)
|
|
|
|
|
|
|
|
system_info info;
|
|
|
|
get_system_info(&info);
|
|
|
|
|
|
|
|
this->NumberOfPhysicalCPU = info.cpu_count;
|
|
|
|
this->CPUSpeedInMHz = info.cpu_clock_speed / 1000000.0F;
|
|
|
|
|
|
|
|
// Physical Memory
|
|
|
|
this->TotalPhysicalMemory = (info.max_pages * B_PAGE_SIZE) / (1024 * 1024) ;
|
|
|
|
this->AvailablePhysicalMemory = this->TotalPhysicalMemory -
|
|
|
|
((info.used_pages * B_PAGE_SIZE) / (1024 * 1024));
|
|
|
|
|
|
|
|
|
|
|
|
// NOTE: get_system_info_etc is currently a private call so just set to 0
|
|
|
|
// until it becomes public
|
|
|
|
this->TotalVirtualMemory = 0;
|
|
|
|
this->AvailableVirtualMemory = 0;
|
|
|
|
|
|
|
|
// Retrieve cpuid_info union for cpu 0
|
|
|
|
cpuid_info cpu_info;
|
|
|
|
get_cpuid(&cpu_info, 0, 0);
|
|
|
|
|
|
|
|
// Chip Vendor
|
|
|
|
// Use a temporary buffer so that we can add NULL termination to the string
|
|
|
|
char vbuf[13];
|
|
|
|
strncpy(vbuf, cpu_info.eax_0.vendor_id, 12);
|
|
|
|
vbuf[12] = '\0';
|
|
|
|
strcpy(this->ChipID.Vendor,vbuf);
|
|
|
|
|
|
|
|
this->FindManufacturer();
|
|
|
|
|
|
|
|
// Retrieve cpuid_info union for cpu 0 this time using a register value of 1
|
|
|
|
get_cpuid(&cpu_info, 1, 0);
|
|
|
|
|
|
|
|
this->NumberOfLogicalCPU = cpu_info.eax_1.logical_cpus;
|
|
|
|
|
|
|
|
// Chip type
|
|
|
|
this->ChipID.Type = cpu_info.eax_1.type;
|
|
|
|
|
|
|
|
// Chip family
|
|
|
|
this->ChipID.Family = cpu_info.eax_1.family;
|
|
|
|
|
|
|
|
// Chip Model
|
|
|
|
this->ChipID.Model = cpu_info.eax_1.model;
|
|
|
|
|
|
|
|
// Chip Revision
|
|
|
|
this->ChipID.Revision = cpu_info.eax_1.stepping;
|
|
|
|
|
|
|
|
// Chip Extended Family
|
|
|
|
this->ChipID.ExtendedFamily = cpu_info.eax_1.extended_family;
|
|
|
|
|
|
|
|
// Chip Extended Model
|
|
|
|
this->ChipID.ExtendedModel = cpu_info.eax_1.extended_model;
|
|
|
|
|
|
|
|
// Get ChipID.ProcessorName from other information already gathered
|
|
|
|
this->RetrieveClassicalCPUIdentity();
|
|
|
|
|
|
|
|
// Cache size
|
|
|
|
this->Features.L1CacheSize = 0;
|
|
|
|
this->Features.L2CacheSize = 0;
|
|
|
|
|
|
|
|
return true;
|
2009-12-11 21:08:29 +03:00
|
|
|
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2009-02-12 18:08:15 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** Query the operating system information */
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformationImplementation::QueryOSInformation()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-01-31 22:50:08 +03:00
|
|
|
#if _WIN32
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
this->OSName = "Windows";
|
|
|
|
|
|
|
|
OSVERSIONINFOEX osvi;
|
|
|
|
BOOL bIsWindows64Bit;
|
|
|
|
BOOL bOsVersionInfoEx;
|
2008-05-02 17:14:37 +04:00
|
|
|
char operatingSystem[256];
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
// Try calling GetVersionEx using the OSVERSIONINFOEX structure.
|
|
|
|
ZeroMemory (&osvi, sizeof (OSVERSIONINFOEX));
|
|
|
|
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
|
2008-02-03 16:20:11 +03:00
|
|
|
bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi);
|
|
|
|
if (!bOsVersionInfoEx)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
|
|
|
|
if (!GetVersionEx ((OSVERSIONINFO *) &osvi))
|
|
|
|
{
|
2008-01-31 23:10:19 +03:00
|
|
|
return false;
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (osvi.dwPlatformId)
|
|
|
|
{
|
|
|
|
case VER_PLATFORM_WIN32_NT:
|
|
|
|
// Test for the product.
|
|
|
|
if (osvi.dwMajorVersion <= 4)
|
|
|
|
{
|
|
|
|
this->OSRelease = "NT";
|
|
|
|
}
|
|
|
|
if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
|
|
|
|
{
|
|
|
|
this->OSRelease = "2000";
|
|
|
|
}
|
|
|
|
if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
|
|
|
|
{
|
|
|
|
this->OSRelease = "XP";
|
|
|
|
}
|
2008-02-01 05:33:32 +03:00
|
|
|
#ifdef VER_NT_WORKSTATION
|
2008-01-08 19:38:28 +03:00
|
|
|
// Test for product type.
|
|
|
|
if (bOsVersionInfoEx)
|
|
|
|
{
|
|
|
|
if (osvi.wProductType == VER_NT_WORKSTATION)
|
|
|
|
{
|
2008-10-17 03:30:49 +04:00
|
|
|
if (osvi.dwMajorVersion == 6)
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-10-17 03:30:49 +04:00
|
|
|
this->OSRelease = "Vista";
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
2008-10-17 03:30:49 +04:00
|
|
|
// VER_SUITE_PERSONAL may not be defined
|
|
|
|
#ifdef VER_SUITE_PERSONAL
|
|
|
|
else
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-10-17 03:30:49 +04:00
|
|
|
if (osvi.wSuiteMask & VER_SUITE_PERSONAL)
|
|
|
|
{
|
|
|
|
this->OSRelease += " Personal";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->OSRelease += " Professional";
|
|
|
|
}
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
2008-02-01 00:37:52 +03:00
|
|
|
#endif
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
else if (osvi.wProductType == VER_NT_SERVER)
|
|
|
|
{
|
|
|
|
// Check for .NET Server instead of Windows XP.
|
|
|
|
if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
|
|
|
|
{
|
|
|
|
this->OSRelease = ".NET";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Continue with the type detection.
|
|
|
|
if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
|
|
|
|
{
|
|
|
|
this->OSRelease += " DataCenter Server";
|
|
|
|
}
|
|
|
|
else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
|
|
|
|
{
|
|
|
|
this->OSRelease += " Advanced Server";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->OSRelease += " Server";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-17 03:30:49 +04:00
|
|
|
sprintf (operatingSystem, "%s (Build %ld)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
|
2008-01-08 19:38:28 +03:00
|
|
|
this->OSVersion = operatingSystem;
|
2008-02-01 05:33:32 +03:00
|
|
|
}
|
2008-01-08 19:38:28 +03:00
|
|
|
else
|
2008-02-01 05:33:32 +03:00
|
|
|
#endif // VER_NT_WORKSTATION
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
|
|
|
HKEY hKey;
|
|
|
|
char szProductType[80];
|
|
|
|
DWORD dwBufLen;
|
|
|
|
|
|
|
|
// Query the registry to retrieve information.
|
|
|
|
RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 0, KEY_QUERY_VALUE, &hKey);
|
|
|
|
RegQueryValueEx (hKey, "ProductType", NULL, NULL, (LPBYTE) szProductType, &dwBufLen);
|
|
|
|
RegCloseKey (hKey);
|
|
|
|
|
|
|
|
if (lstrcmpi ("WINNT", szProductType) == 0)
|
|
|
|
{
|
|
|
|
this->OSRelease += " Professional";
|
|
|
|
}
|
|
|
|
if (lstrcmpi ("LANMANNT", szProductType) == 0)
|
|
|
|
{
|
|
|
|
// Decide between Windows 2000 Advanced Server and Windows .NET Enterprise Server.
|
|
|
|
if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
|
|
|
|
{
|
|
|
|
this->OSRelease += " Standard Server";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->OSRelease += " Server";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lstrcmpi ("SERVERNT", szProductType) == 0)
|
|
|
|
{
|
|
|
|
// Decide between Windows 2000 Advanced Server and Windows .NET Enterprise Server.
|
|
|
|
if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
|
|
|
|
{
|
|
|
|
this->OSRelease += " Enterprise Server";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this->OSRelease += " Advanced Server";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display version, service pack (if any), and build number.
|
|
|
|
if (osvi.dwMajorVersion <= 4)
|
|
|
|
{
|
|
|
|
// NB: NT 4.0 and earlier.
|
2008-05-11 06:48:53 +04:00
|
|
|
sprintf (operatingSystem, "version %ld.%ld %s (Build %ld)",
|
2008-01-08 19:38:28 +03:00
|
|
|
osvi.dwMajorVersion,
|
|
|
|
osvi.dwMinorVersion,
|
|
|
|
osvi.szCSDVersion,
|
|
|
|
osvi.dwBuildNumber & 0xFFFF);
|
|
|
|
this->OSVersion = operatingSystem;
|
|
|
|
}
|
|
|
|
else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
|
|
|
|
{
|
|
|
|
// Windows XP and .NET server.
|
|
|
|
typedef BOOL (CALLBACK* LPFNPROC) (HANDLE, BOOL *);
|
|
|
|
HINSTANCE hKernelDLL;
|
|
|
|
LPFNPROC DLLProc;
|
|
|
|
|
|
|
|
// Load the Kernel32 DLL.
|
|
|
|
hKernelDLL = LoadLibrary ("kernel32");
|
|
|
|
if (hKernelDLL != NULL) {
|
|
|
|
// Only XP and .NET Server support IsWOW64Process so... Load dynamically!
|
|
|
|
DLLProc = (LPFNPROC) GetProcAddress (hKernelDLL, "IsWow64Process");
|
|
|
|
|
|
|
|
// If the function address is valid, call the function.
|
|
|
|
if (DLLProc != NULL) (DLLProc) (GetCurrentProcess (), &bIsWindows64Bit);
|
|
|
|
else bIsWindows64Bit = false;
|
|
|
|
|
|
|
|
// Free the DLL module.
|
|
|
|
FreeLibrary (hKernelDLL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Windows 2000 and everything else.
|
2008-10-17 03:30:49 +04:00
|
|
|
sprintf (operatingSystem,"%s (Build %ld)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
|
2008-01-08 19:38:28 +03:00
|
|
|
this->OSVersion = operatingSystem;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VER_PLATFORM_WIN32_WINDOWS:
|
|
|
|
// Test for the product.
|
|
|
|
if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
|
|
|
|
{
|
|
|
|
this->OSRelease = "95";
|
|
|
|
if(osvi.szCSDVersion[1] == 'C')
|
|
|
|
{
|
|
|
|
this->OSRelease += "OSR 2.5";
|
|
|
|
}
|
|
|
|
else if(osvi.szCSDVersion[1] == 'B')
|
|
|
|
{
|
|
|
|
this->OSRelease += "OSR 2";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
|
|
|
|
{
|
|
|
|
this->OSRelease = "98";
|
|
|
|
if (osvi.szCSDVersion[1] == 'A' )
|
|
|
|
{
|
|
|
|
this->OSRelease += "SE";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
|
|
|
|
{
|
|
|
|
this->OSRelease = "Me";
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VER_PLATFORM_WIN32s:
|
|
|
|
this->OSRelease = "Win32s";
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
this->OSRelease = "Unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the hostname
|
|
|
|
WORD wVersionRequested;
|
|
|
|
WSADATA wsaData;
|
|
|
|
char name[255];
|
|
|
|
wVersionRequested = MAKEWORD(2,0);
|
|
|
|
|
|
|
|
if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
|
|
|
|
{
|
|
|
|
gethostname(name,sizeof(name));
|
|
|
|
WSACleanup( );
|
|
|
|
}
|
|
|
|
this->Hostname = name;
|
2009-10-09 19:10:06 +04:00
|
|
|
|
|
|
|
const char* arch = getenv("PROCESSOR_ARCHITECTURE");
|
|
|
|
if(arch)
|
|
|
|
{
|
|
|
|
this->OSPlatform = arch;
|
|
|
|
}
|
2008-01-08 19:38:28 +03:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
struct utsname unameInfo;
|
|
|
|
int errorFlag = uname(&unameInfo);
|
2008-01-09 01:20:04 +03:00
|
|
|
if(errorFlag == 0)
|
|
|
|
{
|
|
|
|
this->OSName = unameInfo.sysname;
|
|
|
|
this->Hostname = unameInfo.nodename;
|
|
|
|
this->OSRelease = unameInfo.release;
|
|
|
|
this->OSVersion = unameInfo.version;
|
|
|
|
this->OSPlatform = unameInfo.machine;
|
|
|
|
}
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2009-10-06 19:46:16 +04:00
|
|
|
#ifdef __APPLE__
|
|
|
|
this->CallSwVers();
|
|
|
|
#endif
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2009-10-06 19:46:16 +04:00
|
|
|
void SystemInformationImplementation::CallSwVers()
|
|
|
|
{
|
|
|
|
#ifdef __APPLE__
|
|
|
|
kwsys_stl::string output;
|
|
|
|
kwsys_stl::vector<const char*> args;
|
|
|
|
args.clear();
|
|
|
|
|
2009-10-06 22:55:48 +04:00
|
|
|
args.push_back("sw_vers");
|
2009-10-06 19:46:16 +04:00
|
|
|
args.push_back("-productName");
|
2009-10-06 22:55:48 +04:00
|
|
|
args.push_back(0);
|
2009-10-06 19:46:16 +04:00
|
|
|
output = this->RunProcess(args);
|
2009-10-08 18:56:55 +04:00
|
|
|
this->TrimNewline(output);
|
2009-10-06 19:46:16 +04:00
|
|
|
this->OSName = output;
|
2009-10-06 22:55:48 +04:00
|
|
|
args.clear();
|
2009-10-06 19:46:16 +04:00
|
|
|
|
2009-10-06 22:55:48 +04:00
|
|
|
args.push_back("sw_vers");
|
2009-10-06 19:46:16 +04:00
|
|
|
args.push_back("-productVersion");
|
2009-10-06 22:55:48 +04:00
|
|
|
args.push_back(0);
|
2009-10-06 19:46:16 +04:00
|
|
|
output = this->RunProcess(args);
|
2009-10-08 18:56:55 +04:00
|
|
|
this->TrimNewline(output);
|
2009-10-06 19:46:16 +04:00
|
|
|
this->OSRelease = output;
|
2009-10-06 22:55:48 +04:00
|
|
|
args.clear();
|
2009-10-06 19:46:16 +04:00
|
|
|
|
2009-10-06 22:55:48 +04:00
|
|
|
args.push_back("sw_vers");
|
2009-10-06 19:46:16 +04:00
|
|
|
args.push_back("-buildVersion");
|
2009-10-06 22:55:48 +04:00
|
|
|
args.push_back(0);
|
2009-10-06 19:46:16 +04:00
|
|
|
output = this->RunProcess(args);
|
2009-10-08 18:56:55 +04:00
|
|
|
this->TrimNewline(output);
|
2009-10-06 19:46:16 +04:00
|
|
|
this->OSVersion = output;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2009-10-08 18:56:55 +04:00
|
|
|
void SystemInformationImplementation::TrimNewline(kwsys_stl::string& output)
|
|
|
|
{
|
|
|
|
// remove \r
|
|
|
|
kwsys_stl::string::size_type pos=0;
|
|
|
|
while((pos = output.find("\r", pos)) != kwsys_stl::string::npos)
|
|
|
|
{
|
|
|
|
output.erase(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove \n
|
|
|
|
pos = 0;
|
|
|
|
while((pos = output.find("\n", pos)) != kwsys_stl::string::npos)
|
|
|
|
{
|
|
|
|
output.erase(pos);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
/** Return true if the machine is 64 bits */
|
2008-01-31 22:34:11 +03:00
|
|
|
bool SystemInformationImplementation::Is64Bits()
|
2008-01-08 19:38:28 +03:00
|
|
|
{
|
2008-02-03 16:14:38 +03:00
|
|
|
return (sizeof(void*) == 8);
|
2008-01-08 19:38:28 +03:00
|
|
|
}
|
|
|
|
|
2009-12-11 21:08:29 +03:00
|
|
|
|
2008-01-08 19:38:28 +03:00
|
|
|
} // namespace @KWSYS_NAMESPACE@
|