30
INL_IMPLEMENT_GLOBAL_OBJECT(NCPU);
32
//============================================================================
33
// Calculate and log the amount of RAM in the machine
34
//============================================================================
35
static t_u64 GetTotalPhysRAM_MB()
38
MEMORYSTATUSEX theStatus;
39
ZeroMemory(&theStatus,sizeof(theStatus));
40
theStatus.dwLength = sizeof(theStatus);
41
GlobalMemoryStatusEx(&theStatus);
43
return theStatus.ullTotalPhys/(1024*1024);
46
//============================================================================
47
// Read the CPU speed from the registry
48
//============================================================================
49
static DWORD GetCPUSpeedFromRegistry(DWORD dwCPU)
56
_sntprintf_s(szKey, 256, sizeof(szKey)/sizeof(wchar_t), TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\%d\\"), dwCPU);
59
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
66
if(RegQueryValueEx(hKey, TEXT("~MHz"), NULL, NULL, (LPBYTE)&dwSpeed, &dwLen) != ERROR_SUCCESS)
77
void NCPU::Constructor()
79
unsigned nHighestFeature;
80
unsigned nHighestFeatureEx;
84
Memset(&m_CPUInfo, 0, sizeof(m_CPUInfo));
85
Memset(&m_CPUFeatures, 0, sizeof(m_CPUFeatures));
87
// Get CPU manufacturer and highest CPUID
90
nHighestFeature = (unsigned)nBuff[0];
91
*(int*)&szMan[0] = nBuff[1];
92
*(int*)&szMan[4] = nBuff[3];
93
*(int*)&szMan[8] = nBuff[2];
96
if(strcmp(szMan, "AuthenticAMD") == 0)
98
m_CPUInfo.m_CPUType = CPU_AMD;
100
else if(strcmp(szMan, "GenuineIntel") == 0)
102
m_CPUInfo.m_CPUType = CPU_INTEL;
106
m_CPUInfo.m_CPUType = CPU_UNKNOWN;
111
// Get highest extended feature
112
__cpuid(nBuff, 0x80000000);
113
nHighestFeatureEx = (unsigned)nBuff[0];
115
// Get processor brand name
116
if(nHighestFeatureEx >= 0x80000004)
120
__cpuid((int*)&szCPUName[0], 0x80000002);
121
__cpuid((int*)&szCPUName[16], 0x80000003);
122
__cpuid((int*)&szCPUName[32], 0x80000004);
125
m_CPUBrandString = szCPUName;
126
// for(int i=(int)strlen(szCPUName)-1; i>=0; --i)
128
// if(szCPUName[i] == ' ')
129
// szCPUName[i] = '\0';
136
if(nHighestFeature >= 1)
141
m_CPUInfo.m_CPUSteppingID = nBuff[0] & 0xf;
142
m_CPUInfo.m_CPUModel = (nBuff[0] >> 4) & 0xf;
143
m_CPUInfo.m_CPUFamily = (nBuff[0] >> 8) & 0xf;
144
//m_CPUInfo.nProcessorType = (nBuff[0] >> 12) & 0x3;
145
m_CPUInfo.m_CPUExtModel = (nBuff[0] >> 16) & 0xf;
146
m_CPUInfo.m_CPUExtFamily = (nBuff[0] >> 20) & 0xff;
147
//nBrandIndex = nBuff[1] & 0xff;
148
m_CPUInfo.m_CPUNumLogicalProcessors = ((nBuff[1] >> 16) & 0xff);
154
m_CPUFeatures.m_HasFPU = true;
156
m_CPUFeatures.m_HasMMX = true;
158
m_CPUFeatures.m_HasSSE = true;
160
m_CPUFeatures.m_HasSSE2 = true;
162
m_CPUFeatures.m_HasSSE3 = true;
164
m_CPUFeatures.m_HasSSE41 = true;
166
m_CPUFeatures.m_HasSSE42 = true;
169
if(m_CPUInfo.m_CPUType == CPU_INTEL)
172
m_CPUFeatures.m_HasSSSE3 = true;
174
m_CPUFeatures.m_HasEST = true;
178
m_CPUFeatures.m_HasHTT = true;
182
if(m_CPUInfo.m_CPUType == CPU_AMD)
184
// Get extended features
185
__cpuid(nBuff, 0x80000000);
186
if(nHighestFeatureEx >= 0x80000001)
188
__cpuid(nBuff, 0x80000001);
190
m_CPUFeatures.m_Has3DNow = true;
192
m_CPUFeatures.m_Has3DNowExt = true;
194
m_CPUFeatures.m_HasAMDMMX = true;
197
// // Get level 1 cache size
198
// if(nHighestFeatureEx >= 0x80000005)
200
// __cpuid(nBuff, 0x80000005);
201
// ELog::Get().SystemFormat(L"PERF : L1 cache size: %dK\n", ((unsigned)nBuff[2])>>24);
205
if(nHighestFeatureEx >= 0x80000001)
207
__cpuid(nBuff, 0x80000001);
208
if(nBuff[3] & 1 << 29)
209
m_CPUFeatures.m_Hasx64 = true;
213
m_CPUInfo.m_CPUSpeed = GetCPUSpeedFromRegistry(0);
214
m_MemInfo.m_PhysicalMemorySize = GetTotalPhysRAM_MB();
217
unsigned int dw = 0x00000001;
218
m_IsLittleEndian = (*( (char*)&dw ) ? true : false);
222
// if(nHighestFeatureEx >= 0x80000006)
224
// __cpuid(nBuff, 0x80000006);
225
// ELog::Get().SystemFormat(L"PERF : L2 cache size: %dK\n", ((unsigned)nBuff[2])>>16);
229
// ELog::Get().SystemFormat(L"PERF : CPU Features: %S\n", szFeatures);
231
// // Get misc system info
232
// SYSTEM_INFO theInfo;
233
// GetSystemInfo(&theInfo);
235
// // Log number of CPUs and speeds
236
// ELog::Get().SystemFormat(L"PERF : Number of CPUs: %d\n", theInfo.dwNumberOfProcessors);
237
// for(DWORD i=0; i<theInfo.dwNumberOfProcessors; ++i)
239
// DWORD dwCPUSpeed = ReadCPUSpeedFromRegistry(i);
240
// ELog::Get().SystemFormat(L"PERF : * CPU %d speed: ~%dMHz\n", i, dwCPUSpeed);
245
void NCPU::Destructor()
250
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
251
LPFN_ISWOW64PROCESS fnIsWow64Process;
254
//============================================================================
256
//============================================================================
260
int PointerSize = sizeof(ptr);
261
OSVERSIONINFOEX osInfo;
265
ZeroMemory(&sysInfo, sizeof(sysInfo));
266
GetSystemInfo(&sysInfo);
269
ZeroMemory(&osInfo, sizeof(osInfo));
270
osInfo.dwOSVersionInfoSize = sizeof(osInfo);
271
if(!GetVersionEx((OSVERSIONINFO*)&osInfo))
273
ZeroMemory(&osInfo, sizeof(osInfo));
274
osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
275
GetVersionEx((OSVERSIONINFO*)&osInfo);
279
if(osInfo.dwPlatformId == 1)
281
if((osInfo.dwMajorVersion == 4) && (osInfo.dwMinorVersion == 0))
282
m_OSInfo.m_OSType = OS_WIN95;
283
else if((osInfo.dwMajorVersion == 4) && (osInfo.dwMinorVersion == 10))
284
m_OSInfo.m_OSType = OS_WIN98;
285
else if((osInfo.dwMajorVersion == 4) && (osInfo.dwMinorVersion == 90))
286
m_OSInfo.m_OSType = OS_WINME;
288
m_OSInfo.m_OSType = OS_UNKNOWN;
292
else if(osInfo.dwPlatformId == 2)
294
if((osInfo.dwMajorVersion == 4) && (osInfo.dwMinorVersion == 0))
296
m_OSInfo.m_OSType = OS_WINNT40;
298
else if((osInfo.dwMajorVersion == 5) && (osInfo.dwMinorVersion == 0))
300
m_OSInfo.m_OSType = OS_WIN2000;
302
else if((osInfo.dwMajorVersion == 5) && (osInfo.dwMinorVersion == 1))
304
m_OSInfo.m_OSType = OS_WINXP;
306
else if((osInfo.dwMajorVersion == 5) && (osInfo.dwMinorVersion == 2))
308
if(GetSystemMetrics(89)) // SM_SERVERR2 == 89
310
m_OSInfo.m_OSType = OS_WINSERVER2003R2;
312
else if((osInfo.wProductType == VER_NT_WORKSTATION) &&
313
(sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64))
315
m_OSInfo.m_OSType = OS_WINXP64;
319
m_OSInfo.m_OSType = OS_WINSERVER2003;
322
else if((osInfo.dwMajorVersion == 6) && (osInfo.dwMinorVersion == 0))
324
m_OSInfo.m_OSType = OS_WINVISTA;
325
BOOL bIsWow64 = FALSE;
326
fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
327
if(fnIsWow64Process != NULL)
329
if(!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
332
inlWin32MessageBox(NULL, TEXT("Error"), MBTYPE_Ok, MBICON_Error, MBMODAL_ApplicationModal,
333
TEXT("Failed to getOS info.\nThe program will exit."));
338
if((PointerSize == 4) && bIsWow64)
340
// This is Vista 64 bits
341
m_OSInfo.m_OSType = OS_WINVISTA64;
346
// This is Vista 64 bits
347
m_OSInfo.m_OSType = OS_WINVISTA64;
352
m_OSInfo.m_OSType = OS_UNKNOWN;
357
m_OSInfo.m_OSType = OS_UNKNOWN;
361
bool NCPU::IsBigEndian()
363
return !m_IsLittleEndian;
366
bool NCPU::IsLittleEndian()
368
return m_IsLittleEndian;
30
INL_IMPLEMENT_GLOBAL_OBJECT(NCPU);
32
//============================================================================
33
// Calculate and log the amount of RAM in the machine
34
//============================================================================
35
static t_u64 GetTotalPhysRAM_MB()
38
MEMORYSTATUSEX theStatus;
39
ZeroMemory(&theStatus,sizeof(theStatus));
40
theStatus.dwLength = sizeof(theStatus);
41
GlobalMemoryStatusEx(&theStatus);
43
return theStatus.ullTotalPhys/(1024*1024);
46
//============================================================================
47
// Read the CPU speed from the registry
48
//============================================================================
49
static DWORD GetCPUSpeedFromRegistry(DWORD dwCPU)
56
_sntprintf_s(szKey, 256, sizeof(szKey)/sizeof(wchar_t), TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\%d\\"), dwCPU);
59
if(RegOpenKeyEx(HKEY_LOCAL_MACHINE, szKey, 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
66
if(RegQueryValueEx(hKey, TEXT("~MHz"), NULL, NULL, (LPBYTE)&dwSpeed, &dwLen) != ERROR_SUCCESS)
77
void NCPU::Constructor()
79
unsigned nHighestFeature;
80
unsigned nHighestFeatureEx;
84
Memset(&m_CPUInfo, 0, sizeof(m_CPUInfo));
85
Memset(&m_CPUFeatures, 0, sizeof(m_CPUFeatures));
87
// Get CPU manufacturer and highest CPUID
90
nHighestFeature = (unsigned)nBuff[0];
91
*(int*)&szMan[0] = nBuff[1];
92
*(int*)&szMan[4] = nBuff[3];
93
*(int*)&szMan[8] = nBuff[2];
96
if(strcmp(szMan, "AuthenticAMD") == 0)
98
m_CPUInfo.m_CPUType = CPU_AMD;
100
else if(strcmp(szMan, "GenuineIntel") == 0)
102
m_CPUInfo.m_CPUType = CPU_INTEL;
106
m_CPUInfo.m_CPUType = CPU_UNKNOWN;
111
// Get highest extended feature
112
__cpuid(nBuff, 0x80000000);
113
nHighestFeatureEx = (unsigned)nBuff[0];
115
// Get processor brand name
116
if(nHighestFeatureEx >= 0x80000004)
120
__cpuid((int*)&szCPUName[0], 0x80000002);
121
__cpuid((int*)&szCPUName[16], 0x80000003);
122
__cpuid((int*)&szCPUName[32], 0x80000004);
125
m_CPUBrandString = szCPUName;
126
// for(int i=(int)strlen(szCPUName)-1; i>=0; --i)
128
// if(szCPUName[i] == ' ')
129
// szCPUName[i] = '\0';
136
if(nHighestFeature >= 1)
141
m_CPUInfo.m_CPUSteppingID = nBuff[0] & 0xf;
142
m_CPUInfo.m_CPUModel = (nBuff[0] >> 4) & 0xf;
143
m_CPUInfo.m_CPUFamily = (nBuff[0] >> 8) & 0xf;
144
//m_CPUInfo.nProcessorType = (nBuff[0] >> 12) & 0x3;
145
m_CPUInfo.m_CPUExtModel = (nBuff[0] >> 16) & 0xf;
146
m_CPUInfo.m_CPUExtFamily = (nBuff[0] >> 20) & 0xff;
147
//nBrandIndex = nBuff[1] & 0xff;
148
m_CPUInfo.m_CPUNumLogicalProcessors = ((nBuff[1] >> 16) & 0xff);
154
m_CPUFeatures.m_HasFPU = true;
156
m_CPUFeatures.m_HasMMX = true;
158
m_CPUFeatures.m_HasSSE = true;
160
m_CPUFeatures.m_HasSSE2 = true;
162
m_CPUFeatures.m_HasSSE3 = true;
164
m_CPUFeatures.m_HasSSE41 = true;
166
m_CPUFeatures.m_HasSSE42 = true;
169
if(m_CPUInfo.m_CPUType == CPU_INTEL)
172
m_CPUFeatures.m_HasSSSE3 = true;
174
m_CPUFeatures.m_HasEST = true;
178
m_CPUFeatures.m_HasHTT = true;
182
if(m_CPUInfo.m_CPUType == CPU_AMD)
184
// Get extended features
185
__cpuid(nBuff, 0x80000000);
186
if(nHighestFeatureEx >= 0x80000001)
188
__cpuid(nBuff, 0x80000001);
190
m_CPUFeatures.m_Has3DNow = true;
192
m_CPUFeatures.m_Has3DNowExt = true;
194
m_CPUFeatures.m_HasAMDMMX = true;
197
// // Get level 1 cache size
198
// if(nHighestFeatureEx >= 0x80000005)
200
// __cpuid(nBuff, 0x80000005);
201
// ELog::Get().SystemFormat(L"PERF : L1 cache size: %dK\n", ((unsigned)nBuff[2])>>24);
205
if(nHighestFeatureEx >= 0x80000001)
207
__cpuid(nBuff, 0x80000001);
208
if(nBuff[3] & 1 << 29)
209
m_CPUFeatures.m_Hasx64 = true;
213
m_CPUInfo.m_CPUSpeed = GetCPUSpeedFromRegistry(0);
214
m_MemInfo.m_PhysicalMemorySize = GetTotalPhysRAM_MB();
217
unsigned int dw = 0x00000001;
218
m_IsLittleEndian = (*( (char*)&dw ) ? true : false);
222
// if(nHighestFeatureEx >= 0x80000006)
224
// __cpuid(nBuff, 0x80000006);
225
// ELog::Get().SystemFormat(L"PERF : L2 cache size: %dK\n", ((unsigned)nBuff[2])>>16);
229
// ELog::Get().SystemFormat(L"PERF : CPU Features: %S\n", szFeatures);
231
// // Get misc system info
232
// SYSTEM_INFO theInfo;
233
// GetSystemInfo(&theInfo);
235
// // Log number of CPUs and speeds
236
// ELog::Get().SystemFormat(L"PERF : Number of CPUs: %d\n", theInfo.dwNumberOfProcessors);
237
// for(DWORD i=0; i<theInfo.dwNumberOfProcessors; ++i)
239
// DWORD dwCPUSpeed = ReadCPUSpeedFromRegistry(i);
240
// ELog::Get().SystemFormat(L"PERF : * CPU %d speed: ~%dMHz\n", i, dwCPUSpeed);
245
void NCPU::Destructor()
250
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
251
LPFN_ISWOW64PROCESS fnIsWow64Process;
254
//============================================================================
256
//============================================================================
260
int PointerSize = sizeof(ptr);
261
OSVERSIONINFOEX osInfo;
265
ZeroMemory(&sysInfo, sizeof(sysInfo));
266
GetSystemInfo(&sysInfo);
269
ZeroMemory(&osInfo, sizeof(osInfo));
270
osInfo.dwOSVersionInfoSize = sizeof(osInfo);
271
if(!GetVersionEx((OSVERSIONINFO*)&osInfo))
273
ZeroMemory(&osInfo, sizeof(osInfo));
274
osInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
275
GetVersionEx((OSVERSIONINFO*)&osInfo);
279
if(osInfo.dwPlatformId == 1)
281
if((osInfo.dwMajorVersion == 4) && (osInfo.dwMinorVersion == 0))
282
m_OSInfo.m_OSType = OS_WIN95;
283
else if((osInfo.dwMajorVersion == 4) && (osInfo.dwMinorVersion == 10))
284
m_OSInfo.m_OSType = OS_WIN98;
285
else if((osInfo.dwMajorVersion == 4) && (osInfo.dwMinorVersion == 90))
286
m_OSInfo.m_OSType = OS_WINME;
288
m_OSInfo.m_OSType = OS_UNKNOWN;
292
else if(osInfo.dwPlatformId == 2)
294
if((osInfo.dwMajorVersion == 4) && (osInfo.dwMinorVersion == 0))
296
m_OSInfo.m_OSType = OS_WINNT40;
298
else if((osInfo.dwMajorVersion == 5) && (osInfo.dwMinorVersion == 0))
300
m_OSInfo.m_OSType = OS_WIN2000;
302
else if((osInfo.dwMajorVersion == 5) && (osInfo.dwMinorVersion == 1))
304
m_OSInfo.m_OSType = OS_WINXP;
306
else if((osInfo.dwMajorVersion == 5) && (osInfo.dwMinorVersion == 2))
308
if(GetSystemMetrics(89)) // SM_SERVERR2 == 89
310
m_OSInfo.m_OSType = OS_WINSERVER2003R2;
312
else if((osInfo.wProductType == VER_NT_WORKSTATION) &&
313
(sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64))
315
m_OSInfo.m_OSType = OS_WINXP64;
319
m_OSInfo.m_OSType = OS_WINSERVER2003;
322
else if((osInfo.dwMajorVersion == 6) && (osInfo.dwMinorVersion == 0))
324
m_OSInfo.m_OSType = OS_WINVISTA;
325
BOOL bIsWow64 = FALSE;
326
fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
327
if(fnIsWow64Process != NULL)
329
if(!fnIsWow64Process(GetCurrentProcess(), &bIsWow64))
332
inlWin32MessageBox(NULL, TEXT("Error"), MBTYPE_Ok, MBICON_Error, MBMODAL_ApplicationModal,
333
TEXT("Failed to getOS info.\nThe program will exit."));
338
if((PointerSize == 4) && bIsWow64)
340
// This is Vista 64 bits
341
m_OSInfo.m_OSType = OS_WINVISTA64;
346
// This is Vista 64 bits
347
m_OSInfo.m_OSType = OS_WINVISTA64;
352
m_OSInfo.m_OSType = OS_UNKNOWN;
357
m_OSInfo.m_OSType = OS_UNKNOWN;
361
bool NCPU::IsBigEndian()
363
return !m_IsLittleEndian;
366
bool NCPU::IsLittleEndian()
368
return m_IsLittleEndian;