1 /*=========================================================================
4 Module: $RCSfile: SystemInformation.cxx,v $
6 Date: $Date: 2008/02/03 13:20:11 $
7 Version: $Revision: 1.22 $
8 Copyright (c) 2005 Insight Consortium. All rights reserved.
9 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
15 =========================================================================*/
16 #include "kwsysPrivate.h"
17 #include KWSYS_HEADER(FundamentalType.h)
18 #include KWSYS_HEADER(stl/string)
19 #include KWSYS_HEADER(stl/vector)
20 #include KWSYS_HEADER(ios/iosfwd)
21 #include KWSYS_HEADER(SystemInformation.hxx)
22 #include KWSYS_HEADER(Process.h)
23 #include KWSYS_HEADER(ios/iostream)
24 #include KWSYS_HEADER(ios/sstream)
25 // Work-around CMake dependency scanning limitation. This must
26 // duplicate the above list of headers.
28 # include "FundamentalType.h.in"
29 # include "SystemInformation.hxx.in"
30 # include "Process.h.in"
31 # include "Configure.hxx.in"
32 # include "kwsys_stl.hxx.in"
33 # include "kwsys_stl_vector.in"
34 # include "kwsys_stl_iosfwd.in"
35 # include "kwsys_ios_sstream.h.in"
36 # include "kwsys_ios_iostream.h.in"
41 # include <sys/utsname.h> // int uname(struct utsname *buf);
49 # include <sys/procfs.h>
50 # include <sys/types.h>
53 # include <ctype.h> // int isdigit(int c);
54 # include <errno.h> // extern int errno;
55 # include <sys/time.h>
57 # include <sys/param.h>
58 # include <sys/pstat.h>
68 namespace KWSYS_NAMESPACE
72 #if KWSYS_USE_LONG_LONG
73 typedef long long LongLong
;
74 #elif KWSYS_USE___INT64
75 typedef __int64 LongLong
;
77 # error "No Long Long"
80 // Define SystemInformationImplementation class
81 typedef void (*DELAY_FUNC
)(unsigned int uiMS
);
83 class SystemInformationImplementation
87 SystemInformationImplementation ();
88 ~SystemInformationImplementation ();
90 const char * GetVendorString();
91 const char * GetVendorID();
92 kwsys_stl::string
GetTypeID();
93 kwsys_stl::string
GetFamilyID();
94 kwsys_stl::string
GetModelID();
95 kwsys_stl::string
GetSteppingCode();
96 const char * GetExtendedProcessorName();
97 const char * GetProcessorSerialNumber();
98 int GetProcessorCacheSize();
99 int GetLogicalProcessorsPerPhysical();
100 float GetProcessorClockFrequency();
101 int GetProcessorAPICID();
102 int GetProcessorCacheXSize(long int);
103 bool DoesCPUSupportFeature(long int);
105 const char * GetOSName();
106 const char * GetHostname();
107 const char * GetOSRelease();
108 const char * GetOSVersion();
109 const char * GetOSPlatform();
113 unsigned int GetNumberOfLogicalCPU(); // per physical cpu
114 unsigned int GetNumberOfPhysicalCPU();
116 bool DoesCPUSupportCPUID();
118 // Retrieve memory information in megabyte.
119 unsigned long GetTotalVirtualMemory();
120 unsigned long GetAvailableVirtualMemory();
121 unsigned long GetTotalPhysicalMemory();
122 unsigned long GetAvailablePhysicalMemory();
124 /** Run the different checks */
127 void RunMemoryCheck();
129 #define VENDOR_STRING_LENGTH (12 + 1)
130 #define CHIPNAME_STRING_LENGTH (48 + 1)
131 #define SERIALNUMBER_STRING_LENGTH (29 + 1)
141 char ProcessorName
[CHIPNAME_STRING_LENGTH
];
142 char Vendor
[VENDOR_STRING_LENGTH
];
143 char SerialNumber
[SERIALNUMBER_STRING_LENGTH
];
146 typedef struct tagCPUPowerManagement
150 bool HasTempSenseDiode
;
151 } CPUPowerManagement
;
153 typedef struct tagCPUExtendedFeatures
160 bool SupportsHyperthreading
;
161 int LogicalProcessorsPerPhysical
;
163 CPUPowerManagement PowerManagement
;
164 } CPUExtendedFeatures
;
166 typedef struct CPUtagFeatures
185 CPUExtendedFeatures ExtendedFeatures
;
190 AMD
, Intel
, NSC
, UMC
, Cyrix
, NexGen
, IDT
, Rise
, Transmeta
, Sun
, UnknownManufacturer
195 bool RetrieveCPUFeatures();
196 bool RetrieveCPUIdentity();
197 bool RetrieveCPUCacheDetails();
198 bool RetrieveClassicalCPUCacheDetails();
199 bool RetrieveCPUClockSpeed();
200 bool RetrieveClassicalCPUClockSpeed();
201 bool RetrieveCPUExtendedLevelSupport(int);
202 bool RetrieveExtendedCPUFeatures();
203 bool RetrieveProcessorSerialNumber();
204 bool RetrieveCPUPowerManagement();
205 bool RetrieveClassicalCPUIdentity();
206 bool RetrieveExtendedCPUIdentity();
208 Manufacturer ChipManufacturer
;
209 CPUFeatures Features
;
212 unsigned int NumberOfLogicalCPU
;
213 unsigned int NumberOfPhysicalCPU
;
216 unsigned char LogicalCPUPerPhysicalCPU();
217 unsigned char GetAPICId();
218 unsigned int IsHyperThreadingSupported();
219 LongLong
GetCyclesDifference(DELAY_FUNC
, unsigned int);
222 int RetreiveInformationFromCpuInfoFile();
223 kwsys_stl::string
ExtractValueFromCpuInfoFile(kwsys_stl::string buffer
,
224 const char* word
, size_t init
=0);
226 static void Delay (unsigned int);
227 static void DelayOverhead (unsigned int);
229 void FindManufacturer();
233 kwsys_stl::string
ExtractValueFromSysCtl(const char* word
);
234 kwsys_stl::string SysCtlBuffer
;
237 bool QuerySolarisInfo();
238 kwsys_stl::string
ParseValueFromKStat(const char* arguments
);
239 kwsys_stl::string
RunProcess(kwsys_stl::vector
<const char*> args
);
241 // Evaluate the memory information.
243 unsigned long TotalVirtualMemory
;
244 unsigned long AvailableVirtualMemory
;
245 unsigned long TotalPhysicalMemory
;
246 unsigned long AvailablePhysicalMemory
;
248 size_t CurrentPositionInFile
;
250 // Operating System information
251 bool QueryOSInformation();
252 kwsys_stl::string OSName
;
253 kwsys_stl::string Hostname
;
254 kwsys_stl::string OSRelease
;
255 kwsys_stl::string OSVersion
;
256 kwsys_stl::string OSPlatform
;
263 SystemInformation::SystemInformation()
265 this->Implementation
= new SystemInformationImplementation
;
268 SystemInformation::~SystemInformation ()
270 delete this->Implementation
;
273 const char * SystemInformation::GetVendorString()
275 return this->Implementation
->GetVendorString();
277 const char * SystemInformation::GetVendorID()
279 return this->Implementation
->GetVendorID();
281 kwsys_stl::string
SystemInformation::GetTypeID()
283 return this->Implementation
->GetTypeID();
285 kwsys_stl::string
SystemInformation::GetFamilyID()
287 return this->Implementation
->GetFamilyID();
289 kwsys_stl::string
SystemInformation::GetModelID()
291 return this->Implementation
->GetModelID();
293 kwsys_stl::string
SystemInformation::GetSteppingCode()
295 return this->Implementation
->GetSteppingCode();
297 const char * SystemInformation::GetExtendedProcessorName()
299 return this->Implementation
->GetExtendedProcessorName();
301 const char * SystemInformation::GetProcessorSerialNumber()
303 return this->Implementation
->GetProcessorSerialNumber();
305 int SystemInformation::GetProcessorCacheSize()
307 return this->Implementation
->GetProcessorCacheSize();
309 int SystemInformation::GetLogicalProcessorsPerPhysical()
311 return this->Implementation
->GetLogicalProcessorsPerPhysical();
313 float SystemInformation::GetProcessorClockFrequency()
315 return this->Implementation
->GetProcessorClockFrequency();
317 int SystemInformation::GetProcessorAPICID()
319 return this->Implementation
->GetProcessorAPICID();
321 int SystemInformation::GetProcessorCacheXSize(long int l
)
323 return this->Implementation
->GetProcessorCacheXSize(l
);
325 bool SystemInformation::DoesCPUSupportFeature(long int i
)
327 return this->Implementation
->DoesCPUSupportFeature(i
);
330 const char * SystemInformation::GetOSName()
332 return this->Implementation
->GetOSName();
334 const char * SystemInformation::GetHostname()
336 return this->Implementation
->GetHostname();
338 const char * SystemInformation::GetOSRelease()
340 return this->Implementation
->GetOSRelease();
342 const char * SystemInformation::GetOSVersion()
344 return this->Implementation
->GetOSVersion();
346 const char * SystemInformation::GetOSPlatform()
348 return this->Implementation
->GetOSPlatform();
351 bool SystemInformation::Is64Bits()
353 return this->Implementation
->Is64Bits();
356 unsigned int SystemInformation::GetNumberOfLogicalCPU() // per physical cpu
358 return this->Implementation
->GetNumberOfLogicalCPU();
360 unsigned int SystemInformation::GetNumberOfPhysicalCPU()
362 return this->Implementation
->GetNumberOfPhysicalCPU();
365 bool SystemInformation::DoesCPUSupportCPUID()
367 return this->Implementation
->DoesCPUSupportCPUID();
370 // Retrieve memory information in megabyte.
371 unsigned long SystemInformation::GetTotalVirtualMemory()
373 return this->Implementation
->GetTotalVirtualMemory();
375 unsigned long SystemInformation::GetAvailableVirtualMemory()
377 return this->Implementation
->GetAvailableVirtualMemory();
379 unsigned long SystemInformation::GetTotalPhysicalMemory()
381 return this->Implementation
->GetTotalPhysicalMemory();
384 unsigned long SystemInformation::GetAvailablePhysicalMemory()
386 return this->Implementation
->GetAvailablePhysicalMemory();
389 /** Run the different checks */
390 void SystemInformation::RunCPUCheck()
392 this->Implementation
->RunCPUCheck();
394 void SystemInformation::RunOSCheck()
396 this->Implementation
->RunOSCheck();
398 void SystemInformation::RunMemoryCheck()
400 this->Implementation
->RunMemoryCheck();
405 // --------------------------------------------------------------
406 // SystemInformationImplementation starts here
408 #if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(_WIN64)
409 #define USE_ASM_INSTRUCTIONS 1
411 #define USE_ASM_INSTRUCTIONS 0
414 #define STORE_TLBCACHE_INFO(x,y) x = (x < y) ? y : x
415 #define TLBCACHE_INFO_UNITS (15)
416 #define CLASSICAL_CPU_FREQ_LOOP 10000000
417 #define RDTSC_INSTRUCTION _asm _emit 0x0f _asm _emit 0x31
419 #define CPUID_AWARE_COMPILER
420 #ifdef CPUID_AWARE_COMPILER
421 #define CPUID_INSTRUCTION cpuid
423 #define CPUID_INSTRUCTION _asm _emit 0x0f _asm _emit 0xa2
426 #define MMX_FEATURE 0x00000001
427 #define MMX_PLUS_FEATURE 0x00000002
428 #define SSE_FEATURE 0x00000004
429 #define SSE2_FEATURE 0x00000008
430 #define AMD_3DNOW_FEATURE 0x00000010
431 #define AMD_3DNOW_PLUS_FEATURE 0x00000020
432 #define IA64_FEATURE 0x00000040
433 #define MP_CAPABLE 0x00000080
434 #define HYPERTHREAD_FEATURE 0x00000100
435 #define SERIALNUMBER_FEATURE 0x00000200
436 #define APIC_FEATURE 0x00000400
437 #define SSE_FP_FEATURE 0x00000800
438 #define SSE_MMX_FEATURE 0x00001000
439 #define CMOV_FEATURE 0x00002000
440 #define MTRR_FEATURE 0x00004000
441 #define L1CACHE_FEATURE 0x00008000
442 #define L2CACHE_FEATURE 0x00010000
443 #define L3CACHE_FEATURE 0x00020000
444 #define ACPI_FEATURE 0x00040000
445 #define THERMALMONITOR_FEATURE 0x00080000
446 #define TEMPSENSEDIODE_FEATURE 0x00100000
447 #define FREQUENCYID_FEATURE 0x00200000
448 #define VOLTAGEID_FREQUENCY 0x00400000
451 #define HT_NOT_CAPABLE 0
453 #define HT_DISABLED 2
454 #define HT_SUPPORTED_NOT_ENABLED 3
455 #define HT_CANNOT_DETECT 4
457 // EDX[28] Bit 28 is set if HT is supported
458 #define HT_BIT 0x10000000
460 // EAX[11:8] Bit 8-11 contains family processor ID.
461 #define FAMILY_ID 0x0F00
462 #define PENTIUM4_ID 0x0F00
463 // EAX[23:20] Bit 20-23 contains extended family processor ID
464 #define EXT_FAMILY_ID 0x0F00000
465 // EBX[23:16] Bit 16-23 in ebx contains the number of logical
466 #define NUM_LOGICAL_BITS 0x00FF0000
467 // processors per physical processor when execute cpuid with
469 // EBX[31:24] Bits 24-31 (8 bits) return the 8-bit unique
470 #define INITIAL_APIC_ID_BITS 0xFF000000
471 // initial APIC ID for the processor this code is running on.
472 // Default value = 0xff if HT is not supported
476 SystemInformationImplementation::SystemInformationImplementation()
478 this->TotalVirtualMemory
= 0;
479 this->AvailableVirtualMemory
= 0;
480 this->TotalPhysicalMemory
= 0;
481 this->AvailablePhysicalMemory
= 0;
482 this->CurrentPositionInFile
= 0;
483 this->ChipManufacturer
= UnknownManufacturer
;
484 memset(&this->Features
, 0, sizeof(CPUFeatures
));
485 memset(&this->ChipID
, 0, sizeof(ID
));
486 this->CPUSpeedInMHz
= 0;
487 this->NumberOfLogicalCPU
= 0;
488 this->NumberOfPhysicalCPU
= 0;
491 this->OSRelease
= "";
492 this->OSVersion
= "";
493 this->OSPlatform
= "";
496 SystemInformationImplementation::~SystemInformationImplementation()
500 void SystemInformationImplementation::RunCPUCheck()
503 // Check to see if this processor supports CPUID.
504 if (DoesCPUSupportCPUID())
506 // Retrieve the CPU details.
507 RetrieveCPUIdentity();
508 RetrieveCPUFeatures();
509 if (!RetrieveCPUClockSpeed())
511 RetrieveClassicalCPUClockSpeed();
514 // Attempt to retrieve cache information.
515 if (!RetrieveCPUCacheDetails())
517 RetrieveClassicalCPUCacheDetails();
519 // Retrieve the extended CPU details.
520 if (!RetrieveExtendedCPUIdentity())
522 RetrieveClassicalCPUIdentity();
524 RetrieveExtendedCPUFeatures();
526 // Now attempt to retrieve the serial number (if possible).
527 RetrieveProcessorSerialNumber();
530 #elif defined(__APPLE__)
532 #elif defined (__SVR4) && defined (__sun)
533 this->QuerySolarisInfo();
535 this->RetreiveInformationFromCpuInfoFile();
539 void SystemInformationImplementation::RunOSCheck()
541 this->QueryOSInformation();
544 void SystemInformationImplementation::RunMemoryCheck()
546 #if defined(__APPLE__)
548 #elif defined (__SVR4) && defined (__sun)
549 this->QuerySolarisInfo();
555 /** Get the vendor string */
556 const char * SystemInformationImplementation::GetVendorString()
558 return this->ChipID
.Vendor
;
561 /** Get the OS Name */
562 const char * SystemInformationImplementation::GetOSName()
564 return this->OSName
.c_str();
567 /** Get the hostname */
568 const char* SystemInformationImplementation::GetHostname()
570 return this->Hostname
.c_str();
573 /** Get the OS release */
574 const char* SystemInformationImplementation::GetOSRelease()
576 return this->OSRelease
.c_str();
579 /** Get the OS version */
580 const char* SystemInformationImplementation::GetOSVersion()
582 return this->OSVersion
.c_str();
585 /** Get the OS platform */
586 const char* SystemInformationImplementation::GetOSPlatform()
588 return this->OSPlatform
.c_str();
591 /** Get the vendor ID */
592 const char * SystemInformationImplementation::GetVendorID()
594 // Return the vendor ID.
595 switch (this->ChipManufacturer
)
598 return "Intel Corporation";
600 return "Advanced Micro Devices";
602 return "National Semiconductor";
604 return "Cyrix Corp., VIA Inc.";
606 return "NexGen Inc., Advanced Micro Devices";
608 return "IDT\\Centaur, Via Inc.";
610 return "United Microelectronics Corp.";
616 return "Sun Microelectronics";
618 return "Unknown Manufacturer";
622 /** Return the type ID of the CPU */
623 kwsys_stl::string
SystemInformationImplementation::GetTypeID()
625 kwsys_ios::ostringstream str
;
626 str
<< this->ChipID
.Type
;
630 /** Return the family of the CPU present */
631 kwsys_stl::string
SystemInformationImplementation::GetFamilyID()
633 kwsys_ios::ostringstream str
;
634 str
<< this->ChipID
.Family
;
638 // Return the model of CPU present */
639 kwsys_stl::string
SystemInformationImplementation::GetModelID()
641 kwsys_ios::ostringstream str
;
642 str
<< this->ChipID
.Model
;
646 /** Return the stepping code of the CPU present. */
647 kwsys_stl::string
SystemInformationImplementation::GetSteppingCode()
649 kwsys_ios::ostringstream str
;
650 str
<< this->ChipID
.Revision
;
654 /** Return the stepping code of the CPU present. */
655 const char * SystemInformationImplementation::GetExtendedProcessorName()
657 return this->ChipID
.ProcessorName
;
660 /** Return the serial number of the processor
661 * in hexadecimal: xxxx-xxxx-xxxx-xxxx-xxxx-xxxx. */
662 const char * SystemInformationImplementation::GetProcessorSerialNumber()
664 return this->ChipID
.SerialNumber
;
667 /** Return the logical processors per physical */
668 int SystemInformationImplementation::GetLogicalProcessorsPerPhysical()
670 return this->Features
.ExtendedFeatures
.LogicalProcessorsPerPhysical
;
673 /** Return the processor clock frequency. */
674 float SystemInformationImplementation::GetProcessorClockFrequency()
676 return this->CPUSpeedInMHz
;
679 /** Return the APIC ID. */
680 int SystemInformationImplementation::GetProcessorAPICID()
682 return this->Features
.ExtendedFeatures
.APIC_ID
;
685 /** Return the L1 cache size. */
686 int SystemInformationImplementation::GetProcessorCacheSize()
688 return this->Features
.L1CacheSize
;
691 /** Return the chosen cache size. */
692 int SystemInformationImplementation::GetProcessorCacheXSize(long int dwCacheID
)
696 case L1CACHE_FEATURE
:
697 return this->Features
.L1CacheSize
;
698 case L2CACHE_FEATURE
:
699 return this->Features
.L2CacheSize
;
700 case L3CACHE_FEATURE
:
701 return this->Features
.L3CacheSize
;
706 bool SystemInformationImplementation::DoesCPUSupportFeature(long int dwFeature
)
708 bool bHasFeature
= false;
710 // Check for MMX instructions.
711 if (((dwFeature
& MMX_FEATURE
) != 0) && this->Features
.HasMMX
) bHasFeature
= true;
713 // Check for MMX+ instructions.
714 if (((dwFeature
& MMX_PLUS_FEATURE
) != 0) && this->Features
.ExtendedFeatures
.HasMMXPlus
) bHasFeature
= true;
716 // Check for SSE FP instructions.
717 if (((dwFeature
& SSE_FEATURE
) != 0) && this->Features
.HasSSE
) bHasFeature
= true;
719 // Check for SSE FP instructions.
720 if (((dwFeature
& SSE_FP_FEATURE
) != 0) && this->Features
.HasSSEFP
) bHasFeature
= true;
722 // Check for SSE MMX instructions.
723 if (((dwFeature
& SSE_MMX_FEATURE
) != 0) && this->Features
.ExtendedFeatures
.HasSSEMMX
) bHasFeature
= true;
725 // Check for SSE2 instructions.
726 if (((dwFeature
& SSE2_FEATURE
) != 0) && this->Features
.HasSSE2
) bHasFeature
= true;
728 // Check for 3DNow! instructions.
729 if (((dwFeature
& AMD_3DNOW_FEATURE
) != 0) && this->Features
.ExtendedFeatures
.Has3DNow
) bHasFeature
= true;
731 // Check for 3DNow+ instructions.
732 if (((dwFeature
& AMD_3DNOW_PLUS_FEATURE
) != 0) && this->Features
.ExtendedFeatures
.Has3DNowPlus
) bHasFeature
= true;
734 // Check for IA64 instructions.
735 if (((dwFeature
& IA64_FEATURE
) != 0) && this->Features
.HasIA64
) bHasFeature
= true;
737 // Check for MP capable.
738 if (((dwFeature
& MP_CAPABLE
) != 0) && this->Features
.ExtendedFeatures
.SupportsMP
) bHasFeature
= true;
740 // Check for a serial number for the processor.
741 if (((dwFeature
& SERIALNUMBER_FEATURE
) != 0) && this->Features
.HasSerial
) bHasFeature
= true;
743 // Check for a local APIC in the processor.
744 if (((dwFeature
& APIC_FEATURE
) != 0) && this->Features
.HasAPIC
) bHasFeature
= true;
746 // Check for CMOV instructions.
747 if (((dwFeature
& CMOV_FEATURE
) != 0) && this->Features
.HasCMOV
) bHasFeature
= true;
749 // Check for MTRR instructions.
750 if (((dwFeature
& MTRR_FEATURE
) != 0) && this->Features
.HasMTRR
) bHasFeature
= true;
752 // Check for L1 cache size.
753 if (((dwFeature
& L1CACHE_FEATURE
) != 0) && (this->Features
.L1CacheSize
!= -1)) bHasFeature
= true;
755 // Check for L2 cache size.
756 if (((dwFeature
& L2CACHE_FEATURE
) != 0) && (this->Features
.L2CacheSize
!= -1)) bHasFeature
= true;
758 // Check for L3 cache size.
759 if (((dwFeature
& L3CACHE_FEATURE
) != 0) && (this->Features
.L3CacheSize
!= -1)) bHasFeature
= true;
761 // Check for ACPI capability.
762 if (((dwFeature
& ACPI_FEATURE
) != 0) && this->Features
.HasACPI
) bHasFeature
= true;
764 // Check for thermal monitor support.
765 if (((dwFeature
& THERMALMONITOR_FEATURE
) != 0) && this->Features
.HasThermal
) bHasFeature
= true;
767 // Check for temperature sensing diode support.
768 if (((dwFeature
& TEMPSENSEDIODE_FEATURE
) != 0) && this->Features
.ExtendedFeatures
.PowerManagement
.HasTempSenseDiode
) bHasFeature
= true;
770 // Check for frequency ID support.
771 if (((dwFeature
& FREQUENCYID_FEATURE
) != 0) && this->Features
.ExtendedFeatures
.PowerManagement
.HasFrequencyID
) bHasFeature
= true;
773 // Check for voltage ID support.
774 if (((dwFeature
& VOLTAGEID_FREQUENCY
) != 0) && this->Features
.ExtendedFeatures
.PowerManagement
.HasVoltageID
) bHasFeature
= true;
779 void SystemInformationImplementation::Delay(unsigned int uiMS
)
782 LARGE_INTEGER Frequency
, StartCounter
, EndCounter
;
785 // Get the frequency of the high performance counter.
786 if (!QueryPerformanceFrequency (&Frequency
)) return;
787 x
= Frequency
.QuadPart
/ 1000 * uiMS
;
789 // Get the starting position of the counter.
790 QueryPerformanceCounter (&StartCounter
);
793 // Get the ending position of the counter.
794 QueryPerformanceCounter (&EndCounter
);
795 } while (EndCounter
.QuadPart
- StartCounter
.QuadPart
< x
);
800 bool SystemInformationImplementation::DoesCPUSupportCPUID()
802 int CPUIDPresent
= 0;
804 #if USE_ASM_INSTRUCTIONS
805 // Use SEH to determine CPUID presence
808 #ifdef CPUID_AWARE_COMPILER
809 ; we must push
/pop the registers
<<CPUID
>> writes to
, as the
810 ; optimiser doesn
't know about <<CPUID>>, and so doesn't expect
811 ; these registers to change
.
821 #ifdef CPUID_AWARE_COMPILER
831 // Stop the class from trying to use CPUID again!
832 CPUIDPresent
= false;
836 CPUIDPresent
= false;
839 // Return true to indicate support or false to indicate lack.
840 return (CPUIDPresent
== 0) ? true : false;
843 bool SystemInformationImplementation::RetrieveCPUFeatures()
845 #if USE_ASM_INSTRUCTIONS
846 int localCPUFeatures
= 0;
847 int localCPUAdvanced
= 0;
850 // Use assembly to detect CPUID information...
853 #ifdef CPUID_AWARE_COMPILER
854 ; we must push
/pop the registers
<<CPUID
>> writes to
, as the
855 ; optimiser doesn
't know about <<CPUID>>, and so doesn't expect
856 ; these registers to change
.
863 ; 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
864 ; ebx
: 31..24 - default APIC ID
, 23..16 - logical processsor ID
, 15..8 - CFLUSH chunk size
, 7..0 - brand ID
865 ; edx
: CPU feature flags
868 mov localCPUFeatures
, edx
869 mov localCPUAdvanced
, ebx
871 #ifdef CPUID_AWARE_COMPILER
884 // Retrieve the features of CPU present.
885 this->Features
.HasFPU
= ((localCPUFeatures
& 0x00000001) != 0); // FPU Present --> Bit 0
886 this->Features
.HasTSC
= ((localCPUFeatures
& 0x00000010) != 0); // TSC Present --> Bit 4
887 this->Features
.HasAPIC
= ((localCPUFeatures
& 0x00000200) != 0); // APIC Present --> Bit 9
888 this->Features
.HasMTRR
= ((localCPUFeatures
& 0x00001000) != 0); // MTRR Present --> Bit 12
889 this->Features
.HasCMOV
= ((localCPUFeatures
& 0x00008000) != 0); // CMOV Present --> Bit 15
890 this->Features
.HasSerial
= ((localCPUFeatures
& 0x00040000) != 0); // Serial Present --> Bit 18
891 this->Features
.HasACPI
= ((localCPUFeatures
& 0x00400000) != 0); // ACPI Capable --> Bit 22
892 this->Features
.HasMMX
= ((localCPUFeatures
& 0x00800000) != 0); // MMX Present --> Bit 23
893 this->Features
.HasSSE
= ((localCPUFeatures
& 0x02000000) != 0); // SSE Present --> Bit 25
894 this->Features
.HasSSE2
= ((localCPUFeatures
& 0x04000000) != 0); // SSE2 Present --> Bit 26
895 this->Features
.HasThermal
= ((localCPUFeatures
& 0x20000000) != 0); // Thermal Monitor Present --> Bit 29
896 this->Features
.HasIA64
= ((localCPUFeatures
& 0x40000000) != 0); // IA64 Present --> Bit 30
898 // Retrieve extended SSE capabilities if SSE is available.
899 if (this->Features
.HasSSE
) {
901 // Attempt to __try some SSE FP instructions.
904 // Perform: orps xmm0, xmm0
912 // SSE FP capable processor.
913 this->Features
.HasSSEFP
= true;
917 // bad instruction - processor or OS cannot handle SSE FP.
918 this->Features
.HasSSEFP
= false;
923 // Set the advanced SSE capabilities to not available.
924 this->Features
.HasSSEFP
= false;
927 // Retrieve Intel specific extended features.
928 if (this->ChipManufacturer
== Intel
)
930 this->Features
.ExtendedFeatures
.SupportsHyperthreading
= ((localCPUFeatures
& 0x10000000) != 0); // Intel specific: Hyperthreading --> Bit 28
931 this->Features
.ExtendedFeatures
.LogicalProcessorsPerPhysical
= (this->Features
.ExtendedFeatures
.SupportsHyperthreading
) ? ((localCPUAdvanced
& 0x00FF0000) >> 16) : 1;
933 if ((this->Features
.ExtendedFeatures
.SupportsHyperthreading
) && (this->Features
.HasAPIC
))
935 // Retrieve APIC information if there is one present.
936 this->Features
.ExtendedFeatures
.APIC_ID
= ((localCPUAdvanced
& 0xFF000000) >> 24);
944 /** Find the manufacturer given the vendor id */
945 void SystemInformationImplementation::FindManufacturer()
947 if (strcmp (this->ChipID
.Vendor
, "GenuineIntel") == 0) this->ChipManufacturer
= Intel
; // Intel Corp.
948 else if (strcmp (this->ChipID
.Vendor
, "UMC UMC UMC ") == 0) this->ChipManufacturer
= UMC
; // United Microelectronics Corp.
949 else if (strcmp (this->ChipID
.Vendor
, "AuthenticAMD") == 0) this->ChipManufacturer
= AMD
; // Advanced Micro Devices
950 else if (strcmp (this->ChipID
.Vendor
, "AMD ISBETTER") == 0) this->ChipManufacturer
= AMD
; // Advanced Micro Devices (1994)
951 else if (strcmp (this->ChipID
.Vendor
, "CyrixInstead") == 0) this->ChipManufacturer
= Cyrix
; // Cyrix Corp., VIA Inc.
952 else if (strcmp (this->ChipID
.Vendor
, "NexGenDriven") == 0) this->ChipManufacturer
= NexGen
; // NexGen Inc. (now AMD)
953 else if (strcmp (this->ChipID
.Vendor
, "CentaurHauls") == 0) this->ChipManufacturer
= IDT
; // IDT/Centaur (now VIA)
954 else if (strcmp (this->ChipID
.Vendor
, "RiseRiseRise") == 0) this->ChipManufacturer
= Rise
; // Rise
955 else if (strcmp (this->ChipID
.Vendor
, "GenuineTMx86") == 0) this->ChipManufacturer
= Transmeta
; // Transmeta
956 else if (strcmp (this->ChipID
.Vendor
, "TransmetaCPU") == 0) this->ChipManufacturer
= Transmeta
; // Transmeta
957 else if (strcmp (this->ChipID
.Vendor
, "Geode By NSC") == 0) this->ChipManufacturer
= NSC
; // National Semiconductor
958 else if (strcmp (this->ChipID
.Vendor
, "Sun") == 0) this->ChipManufacturer
= Sun
; // Sun Microelectronics
959 else this->ChipManufacturer
= UnknownManufacturer
; // Unknown manufacturer
963 bool SystemInformationImplementation::RetrieveCPUIdentity()
965 #if USE_ASM_INSTRUCTIONS
966 int localCPUVendor
[3];
967 int localCPUSignature
;
969 // Use assembly to detect CPUID information...
974 #ifdef CPUID_AWARE_COMPILER
975 ; we must push
/pop the registers
<<CPUID
>> writes to
, as the
976 ; optimiser doesn
't know about <<CPUID>>, and so doesn't expect
977 ; these registers to change
.
984 ; eax
= 0 --> eax
: maximum value of CPUID instruction
.
985 ; ebx
: part
1 of
3; CPU signature
.
986 ; edx
: part
2 of
3; CPU signature
.
987 ; ecx
: part
3 of
3; CPU signature
.
990 mov localCPUVendor
[0 * TYPE
int], ebx
991 mov localCPUVendor
[1 * TYPE
int], edx
992 mov localCPUVendor
[2 * TYPE
int], ecx
995 ; 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
996 ; ebx
: 31..24 - default APIC ID
, 23..16 - logical processsor ID
, 15..8 - CFLUSH chunk size
, 7..0 - brand ID
997 ; edx
: CPU feature flags
1000 mov localCPUSignature
, eax
1002 #ifdef CPUID_AWARE_COMPILER
1015 // Process the returned information.
1016 memcpy (this->ChipID
.Vendor
, &(localCPUVendor
[0]), sizeof (int));
1017 memcpy (&(this->ChipID
.Vendor
[4]), &(localCPUVendor
[1]), sizeof (int));
1018 memcpy (&(this->ChipID
.Vendor
[8]), &(localCPUVendor
[2]), sizeof (int));
1019 this->ChipID
.Vendor
[12] = '\0';
1021 this->FindManufacturer();
1023 // Retrieve the family of CPU present.
1024 this->ChipID
.ExtendedFamily
= ((localCPUSignature
& 0x0FF00000) >> 20); // Bits 27..20 Used
1025 this->ChipID
.ExtendedModel
= ((localCPUSignature
& 0x000F0000) >> 16); // Bits 19..16 Used
1026 this->ChipID
.Type
= ((localCPUSignature
& 0x0000F000) >> 12); // Bits 15..12 Used
1027 this->ChipID
.Family
= ((localCPUSignature
& 0x00000F00) >> 8); // Bits 11..8 Used
1028 this->ChipID
.Model
= ((localCPUSignature
& 0x000000F0) >> 4); // Bits 7..4 Used
1029 this->ChipID
.Revision
= ((localCPUSignature
& 0x0000000F) >> 0); // Bits 3..0 Used
1036 bool SystemInformationImplementation::RetrieveCPUCacheDetails()
1038 #if USE_ASM_INSTRUCTIONS
1039 int L1Cache
[4] = { 0, 0, 0, 0 };
1040 int L2Cache
[4] = { 0, 0, 0, 0 };
1042 // Check to see if what we are about to do is supported...
1043 if (RetrieveCPUExtendedLevelSupport (0x80000005))
1045 // Use assembly to retrieve the L1 cache information ...
1050 #ifdef CPUID_AWARE_COMPILER
1051 ; we must push
/pop the registers
<<CPUID
>> writes to
, as the
1052 ; optimiser doesn
't know about <<CPUID>>, and so doesn't expect
1053 ; these registers to change
.
1060 ; eax
= 0x80000005 --> eax
: L1 cache information
- Part
1 of
4.
1061 ; ebx
: L1 cache information
- Part
2 of
4.
1062 ; edx
: L1 cache information
- Part
3 of
4.
1063 ; ecx
: L1 cache information
- Part
4 of
4.
1066 mov L1Cache
[0 * TYPE
int], eax
1067 mov L1Cache
[1 * TYPE
int], ebx
1068 mov L1Cache
[2 * TYPE
int], ecx
1069 mov L1Cache
[3 * TYPE
int], edx
1071 #ifdef CPUID_AWARE_COMPILER
1083 // Save the L1 data cache size (in KB) from ecx: bits 31..24 as well as data cache size from edx: bits 31..24.
1084 this->Features
.L1CacheSize
= ((L1Cache
[2] & 0xFF000000) >> 24);
1085 this->Features
.L1CacheSize
+= ((L1Cache
[3] & 0xFF000000) >> 24);
1089 // Store -1 to indicate the cache could not be queried.
1090 this->Features
.L1CacheSize
= -1;
1093 // Check to see if what we are about to do is supported...
1094 if (RetrieveCPUExtendedLevelSupport (0x80000006))
1096 // Use assembly to retrieve the L2 cache information ...
1101 #ifdef CPUID_AWARE_COMPILER
1102 ; we must push
/pop the registers
<<CPUID
>> writes to
, as the
1103 ; optimiser doesn
't know about <<CPUID>>, and so doesn't expect
1104 ; these registers to change
.
1111 ; eax
= 0x80000006 --> eax
: L2 cache information
- Part
1 of
4.
1112 ; ebx
: L2 cache information
- Part
2 of
4.
1113 ; edx
: L2 cache information
- Part
3 of
4.
1114 ; ecx
: L2 cache information
- Part
4 of
4.
1117 mov L2Cache
[0 * TYPE
int], eax
1118 mov L2Cache
[1 * TYPE
int], ebx
1119 mov L2Cache
[2 * TYPE
int], ecx
1120 mov L2Cache
[3 * TYPE
int], edx
1122 #ifdef CPUID_AWARE_COMPILER
1134 // Save the L2 unified cache size (in KB) from ecx: bits 31..16.
1135 this->Features
.L2CacheSize
= ((L2Cache
[2] & 0xFFFF0000) >> 16);
1139 // Store -1 to indicate the cache could not be queried.
1140 this->Features
.L2CacheSize
= -1;
1143 // Define L3 as being not present as we cannot test for it.
1144 this->Features
.L3CacheSize
= -1;
1148 // Return failure if we cannot detect either cache with this method.
1149 return ((this->Features
.L1CacheSize
== -1) && (this->Features
.L2CacheSize
== -1)) ? false : true;
1153 bool SystemInformationImplementation::RetrieveClassicalCPUCacheDetails()
1155 #if USE_ASM_INSTRUCTIONS
1156 int TLBCode
= -1, TLBData
= -1, L1Code
= -1, L1Data
= -1, L1Trace
= -1, L2Unified
= -1, L3Unified
= -1;
1157 int TLBCacheData
[4] = { 0, 0, 0, 0 };
1158 int TLBPassCounter
= 0;
1159 int TLBCacheUnit
= 0;
1163 // Use assembly to retrieve the L2 cache information ...
1166 #ifdef CPUID_AWARE_COMPILER
1167 ; we must push
/pop the registers
<<CPUID
>> writes to
, as the
1168 ; optimiser doesn
't know about <<CPUID>>, and so doesn't expect
1169 ; these registers to change
.
1176 ; eax
= 2 --> eax
: TLB
and cache information
- Part
1 of
4.
1177 ; ebx
: TLB
and cache information
- Part
2 of
4.
1178 ; ecx
: TLB
and cache information
- Part
3 of
4.
1179 ; edx
: TLB
and cache information
- Part
4 of
4.
1182 mov TLBCacheData
[0 * TYPE
int], eax
1183 mov TLBCacheData
[1 * TYPE
int], ebx
1184 mov TLBCacheData
[2 * TYPE
int], ecx
1185 mov TLBCacheData
[3 * TYPE
int], edx
1187 #ifdef CPUID_AWARE_COMPILER
1200 int bob
= ((TLBCacheData
[0] & 0x00FF0000) >> 16);
1202 // Process the returned TLB and cache information.
1203 for (int nCounter
= 0; nCounter
< TLBCACHE_INFO_UNITS
; nCounter
++)
1205 // First of all - decide which unit we are dealing with.
1208 // eax: bits 8..15 : bits 16..23 : bits 24..31
1209 case 0: TLBCacheUnit
= ((TLBCacheData
[0] & 0x0000FF00) >> 8); break;
1210 case 1: TLBCacheUnit
= ((TLBCacheData
[0] & 0x00FF0000) >> 16); break;
1211 case 2: TLBCacheUnit
= ((TLBCacheData
[0] & 0xFF000000) >> 24); break;
1213 // ebx: bits 0..7 : bits 8..15 : bits 16..23 : bits 24..31
1214 case 3: TLBCacheUnit
= ((TLBCacheData
[1] & 0x000000FF) >> 0); break;
1215 case 4: TLBCacheUnit
= ((TLBCacheData
[1] & 0x0000FF00) >> 8); break;
1216 case 5: TLBCacheUnit
= ((TLBCacheData
[1] & 0x00FF0000) >> 16); break;
1217 case 6: TLBCacheUnit
= ((TLBCacheData
[1] & 0xFF000000) >> 24); break;
1219 // ecx: bits 0..7 : bits 8..15 : bits 16..23 : bits 24..31
1220 case 7: TLBCacheUnit
= ((TLBCacheData
[2] & 0x000000FF) >> 0); break;
1221 case 8: TLBCacheUnit
= ((TLBCacheData
[2] & 0x0000FF00) >> 8); break;
1222 case 9: TLBCacheUnit
= ((TLBCacheData
[2] & 0x00FF0000) >> 16); break;
1223 case 10: TLBCacheUnit
= ((TLBCacheData
[2] & 0xFF000000) >> 24); break;
1225 // edx: bits 0..7 : bits 8..15 : bits 16..23 : bits 24..31
1226 case 11: TLBCacheUnit
= ((TLBCacheData
[3] & 0x000000FF) >> 0); break;
1227 case 12: TLBCacheUnit
= ((TLBCacheData
[3] & 0x0000FF00) >> 8); break;
1228 case 13: TLBCacheUnit
= ((TLBCacheData
[3] & 0x00FF0000) >> 16); break;
1229 case 14: TLBCacheUnit
= ((TLBCacheData
[3] & 0xFF000000) >> 24); break;
1231 // Default case - an error has occured.
1232 default: return false;
1235 // Now process the resulting unit to see what it means....
1236 switch (TLBCacheUnit
)
1239 case 0x01: STORE_TLBCACHE_INFO (TLBCode
, 4); break;
1240 case 0x02: STORE_TLBCACHE_INFO (TLBCode
, 4096); break;
1241 case 0x03: STORE_TLBCACHE_INFO (TLBData
, 4); break;
1242 case 0x04: STORE_TLBCACHE_INFO (TLBData
, 4096); break;
1243 case 0x06: STORE_TLBCACHE_INFO (L1Code
, 8); break;
1244 case 0x08: STORE_TLBCACHE_INFO (L1Code
, 16); break;
1245 case 0x0a: STORE_TLBCACHE_INFO (L1Data
, 8); break;
1246 case 0x0c: STORE_TLBCACHE_INFO (L1Data
, 16); break;
1247 case 0x10: STORE_TLBCACHE_INFO (L1Data
, 16); break; // <-- FIXME: IA-64 Only
1248 case 0x15: STORE_TLBCACHE_INFO (L1Code
, 16); break; // <-- FIXME: IA-64 Only
1249 case 0x1a: STORE_TLBCACHE_INFO (L2Unified
, 96); break; // <-- FIXME: IA-64 Only
1250 case 0x22: STORE_TLBCACHE_INFO (L3Unified
, 512); break;
1251 case 0x23: STORE_TLBCACHE_INFO (L3Unified
, 1024); break;
1252 case 0x25: STORE_TLBCACHE_INFO (L3Unified
, 2048); break;
1253 case 0x29: STORE_TLBCACHE_INFO (L3Unified
, 4096); break;
1254 case 0x39: STORE_TLBCACHE_INFO (L2Unified
, 128); break;
1255 case 0x3c: STORE_TLBCACHE_INFO (L2Unified
, 256); break;
1256 case 0x40: STORE_TLBCACHE_INFO (L2Unified
, 0); break; // <-- FIXME: No integrated L2 cache (P6 core) or L3 cache (P4 core).
1257 case 0x41: STORE_TLBCACHE_INFO (L2Unified
, 128); break;
1258 case 0x42: STORE_TLBCACHE_INFO (L2Unified
, 256); break;
1259 case 0x43: STORE_TLBCACHE_INFO (L2Unified
, 512); break;
1260 case 0x44: STORE_TLBCACHE_INFO (L2Unified
, 1024); break;
1261 case 0x45: STORE_TLBCACHE_INFO (L2Unified
, 2048); break;
1262 case 0x50: STORE_TLBCACHE_INFO (TLBCode
, 4096); break;
1263 case 0x51: STORE_TLBCACHE_INFO (TLBCode
, 4096); break;
1264 case 0x52: STORE_TLBCACHE_INFO (TLBCode
, 4096); break;
1265 case 0x5b: STORE_TLBCACHE_INFO (TLBData
, 4096); break;
1266 case 0x5c: STORE_TLBCACHE_INFO (TLBData
, 4096); break;
1267 case 0x5d: STORE_TLBCACHE_INFO (TLBData
, 4096); break;
1268 case 0x66: STORE_TLBCACHE_INFO (L1Data
, 8); break;
1269 case 0x67: STORE_TLBCACHE_INFO (L1Data
, 16); break;
1270 case 0x68: STORE_TLBCACHE_INFO (L1Data
, 32); break;
1271 case 0x70: STORE_TLBCACHE_INFO (L1Trace
, 12); break;
1272 case 0x71: STORE_TLBCACHE_INFO (L1Trace
, 16); break;
1273 case 0x72: STORE_TLBCACHE_INFO (L1Trace
, 32); break;
1274 case 0x77: STORE_TLBCACHE_INFO (L1Code
, 16); break; // <-- FIXME: IA-64 Only
1275 case 0x79: STORE_TLBCACHE_INFO (L2Unified
, 128); break;
1276 case 0x7a: STORE_TLBCACHE_INFO (L2Unified
, 256); break;
1277 case 0x7b: STORE_TLBCACHE_INFO (L2Unified
, 512); break;
1278 case 0x7c: STORE_TLBCACHE_INFO (L2Unified
, 1024); break;
1279 case 0x7e: STORE_TLBCACHE_INFO (L2Unified
, 256); break;
1280 case 0x81: STORE_TLBCACHE_INFO (L2Unified
, 128); break;
1281 case 0x82: STORE_TLBCACHE_INFO (L2Unified
, 256); break;
1282 case 0x83: STORE_TLBCACHE_INFO (L2Unified
, 512); break;
1283 case 0x84: STORE_TLBCACHE_INFO (L2Unified
, 1024); break;
1284 case 0x85: STORE_TLBCACHE_INFO (L2Unified
, 2048); break;
1285 case 0x88: STORE_TLBCACHE_INFO (L3Unified
, 2048); break; // <-- FIXME: IA-64 Only
1286 case 0x89: STORE_TLBCACHE_INFO (L3Unified
, 4096); break; // <-- FIXME: IA-64 Only
1287 case 0x8a: STORE_TLBCACHE_INFO (L3Unified
, 8192); break; // <-- FIXME: IA-64 Only
1288 case 0x8d: STORE_TLBCACHE_INFO (L3Unified
, 3096); break; // <-- FIXME: IA-64 Only
1289 case 0x90: STORE_TLBCACHE_INFO (TLBCode
, 262144); break; // <-- FIXME: IA-64 Only
1290 case 0x96: STORE_TLBCACHE_INFO (TLBCode
, 262144); break; // <-- FIXME: IA-64 Only
1291 case 0x9b: STORE_TLBCACHE_INFO (TLBCode
, 262144); break; // <-- FIXME: IA-64 Only
1293 // Default case - an error has occured.
1294 default: return false;
1298 // Increment the TLB pass counter.
1300 } while ((TLBCacheData
[0] & 0x000000FF) > TLBPassCounter
);
1302 // Ok - we now have the maximum TLB, L1, L2, and L3 sizes...
1303 if ((L1Code
== -1) && (L1Data
== -1) && (L1Trace
== -1))
1305 this->Features
.L1CacheSize
= -1;
1307 else if ((L1Code
== -1) && (L1Data
== -1) && (L1Trace
!= -1))
1309 this->Features
.L1CacheSize
= L1Trace
;
1311 else if ((L1Code
!= -1) && (L1Data
== -1))
1313 this->Features
.L1CacheSize
= L1Code
;
1315 else if ((L1Code
== -1) && (L1Data
!= -1))
1317 this->Features
.L1CacheSize
= L1Data
;
1319 else if ((L1Code
!= -1) && (L1Data
!= -1))
1321 this->Features
.L1CacheSize
= L1Code
+ L1Data
;
1325 this->Features
.L1CacheSize
= -1;
1328 // Ok - we now have the maximum TLB, L1, L2, and L3 sizes...
1329 if (L2Unified
== -1)
1331 this->Features
.L2CacheSize
= -1;
1335 this->Features
.L2CacheSize
= L2Unified
;
1338 // Ok - we now have the maximum TLB, L1, L2, and L3 sizes...
1339 if (L3Unified
== -1)
1341 this->Features
.L3CacheSize
= -1;
1345 this->Features
.L3CacheSize
= L3Unified
;
1353 bool SystemInformationImplementation::RetrieveCPUClockSpeed()
1356 // First of all we check to see if the RDTSC (0x0F, 0x31) instruction is supported.
1357 if (!this->Features
.HasTSC
)
1362 unsigned int uiRepetitions
= 1;
1363 unsigned int uiMSecPerRepetition
= 50;
1364 __int64 i64Total
= 0;
1365 __int64 i64Overhead
= 0;
1367 for (unsigned int nCounter
= 0; nCounter
< uiRepetitions
; nCounter
++)
1369 i64Total
+= GetCyclesDifference (SystemInformationImplementation::Delay
,
1370 uiMSecPerRepetition
);
1372 GetCyclesDifference (SystemInformationImplementation::DelayOverhead
,
1373 uiMSecPerRepetition
);
1376 // Calculate the MHz speed.
1377 i64Total
-= i64Overhead
;
1378 i64Total
/= uiRepetitions
;
1379 i64Total
/= uiMSecPerRepetition
;
1382 // Save the CPU speed.
1383 this->CPUSpeedInMHz
= (float) i64Total
;
1392 bool SystemInformationImplementation::RetrieveClassicalCPUClockSpeed()
1394 #if USE_ASM_INSTRUCTIONS
1395 LARGE_INTEGER liStart
, liEnd
, liCountsPerSecond
;
1396 double dFrequency
, dDifference
;
1398 // Attempt to get a starting tick count.
1399 QueryPerformanceCounter (&liStart
);
1406 mov ebx
, CLASSICAL_CPU_FREQ_LOOP
1418 // Attempt to get a starting tick count.
1419 QueryPerformanceCounter (&liEnd
);
1421 // Get the difference... NB: This is in seconds....
1422 QueryPerformanceFrequency (&liCountsPerSecond
);
1423 dDifference
= (((double) liEnd
.QuadPart
- (double) liStart
.QuadPart
) / (double) liCountsPerSecond
.QuadPart
);
1425 // Calculate the clock speed.
1426 if (this->ChipID
.Family
== 3)
1428 // 80386 processors.... Loop time is 115 cycles!
1429 dFrequency
= (((CLASSICAL_CPU_FREQ_LOOP
* 115) / dDifference
) / 1048576);
1431 else if (this->ChipID
.Family
== 4)
1433 // 80486 processors.... Loop time is 47 cycles!
1434 dFrequency
= (((CLASSICAL_CPU_FREQ_LOOP
* 47) / dDifference
) / 1048576);
1436 else if (this->ChipID
.Family
== 5)
1438 // Pentium processors.... Loop time is 43 cycles!
1439 dFrequency
= (((CLASSICAL_CPU_FREQ_LOOP
* 43) / dDifference
) / 1048576);
1442 // Save the clock speed.
1443 this->Features
.CPUSpeed
= (int) dFrequency
;
1450 bool SystemInformationImplementation::RetrieveCPUExtendedLevelSupport(int CPULevelToCheck
)
1452 int MaxCPUExtendedLevel
= 0;
1454 // The extended CPUID is supported by various vendors starting with the following CPU models:
1456 // Manufacturer & Chip Name | Family Model Revision
1458 // AMD K6, K6-2 | 5 6 x
1459 // Cyrix GXm, Cyrix III "Joshua" | 5 4 x
1461 // VIA Cyrix III | 6 5 x
1462 // Transmeta Crusoe | 5 x x
1463 // Intel Pentium 4 | f x x
1466 // We check to see if a supported processor is present...
1467 if (this->ChipManufacturer
== AMD
)
1469 if (this->ChipID
.Family
< 5) return false;
1470 if ((this->ChipID
.Family
== 5) && (this->ChipID
.Model
< 6)) return false;
1472 else if (this->ChipManufacturer
== Cyrix
)
1474 if (this->ChipID
.Family
< 5) return false;
1475 if ((this->ChipID
.Family
== 5) && (this->ChipID
.Model
< 4)) return false;
1476 if ((this->ChipID
.Family
== 6) && (this->ChipID
.Model
< 5)) return false;
1478 else if (this->ChipManufacturer
== IDT
)
1480 if (this->ChipID
.Family
< 5) return false;
1481 if ((this->ChipID
.Family
== 5) && (this->ChipID
.Model
< 8)) return false;
1483 else if (this->ChipManufacturer
== Transmeta
)
1485 if (this->ChipID
.Family
< 5) return false;
1487 else if (this->ChipManufacturer
== Intel
)
1489 if (this->ChipID
.Family
< 0xf)
1495 #if USE_ASM_INSTRUCTIONS
1497 // Use assembly to detect CPUID information...
1500 #ifdef CPUID_AWARE_COMPILER
1501 ; we must push
/pop the registers
<<CPUID
>> writes to
, as the
1502 ; optimiser doesn
't know about <<CPUID>>, and so doesn't expect
1503 ; these registers to change
.
1510 ; eax
= 0x80000000 --> eax
: maximum supported extended level
1513 mov MaxCPUExtendedLevel
, eax
1515 #ifdef CPUID_AWARE_COMPILER
1529 // Now we have to check the level wanted vs level returned...
1530 int nLevelWanted
= (CPULevelToCheck
& 0x7FFFFFFF);
1531 int nLevelReturn
= (MaxCPUExtendedLevel
& 0x7FFFFFFF);
1533 // Check to see if the level provided is supported...
1534 if (nLevelWanted
> nLevelReturn
)
1543 bool SystemInformationImplementation::RetrieveExtendedCPUFeatures()
1546 // Check that we are not using an Intel processor as it does not support this.
1547 if (this->ChipManufacturer
== Intel
)
1552 // Check to see if what we are about to do is supported...
1553 if (!RetrieveCPUExtendedLevelSupport (0x80000001))
1557 #if USE_ASM_INSTRUCTIONS
1558 int localCPUExtendedFeatures
= 0;
1560 // Use assembly to detect CPUID information...
1565 #ifdef CPUID_AWARE_COMPILER
1566 ; we must push
/pop the registers
<<CPUID
>> writes to
, as the
1567 ; optimiser doesn
't know about <<CPUID>>, and so doesn't expect
1568 ; these registers to change
.
1575 ; 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
1576 ; ebx
: 31..24 - default APIC ID
, 23..16 - logical processsor ID
, 15..8 - CFLUSH chunk size
, 7..0 - brand ID
1577 ; edx
: CPU feature flags
1580 mov localCPUExtendedFeatures
, edx
1582 #ifdef CPUID_AWARE_COMPILER
1595 // Retrieve the extended features of CPU present.
1596 this->Features
.ExtendedFeatures
.Has3DNow
= ((localCPUExtendedFeatures
& 0x80000000) != 0); // 3DNow Present --> Bit 31.
1597 this->Features
.ExtendedFeatures
.Has3DNowPlus
= ((localCPUExtendedFeatures
& 0x40000000) != 0); // 3DNow+ Present -- > Bit 30.
1598 this->Features
.ExtendedFeatures
.HasSSEMMX
= ((localCPUExtendedFeatures
& 0x00400000) != 0); // SSE MMX Present --> Bit 22.
1599 this->Features
.ExtendedFeatures
.SupportsMP
= ((localCPUExtendedFeatures
& 0x00080000) != 0); // MP Capable -- > Bit 19.
1601 // Retrieve AMD specific extended features.
1602 if (this->ChipManufacturer
== AMD
)
1604 this->Features
.ExtendedFeatures
.HasMMXPlus
= ((localCPUExtendedFeatures
& 0x00400000) != 0); // AMD specific: MMX-SSE --> Bit 22
1607 // Retrieve Cyrix specific extended features.
1608 if (this->ChipManufacturer
== Cyrix
)
1610 this->Features
.ExtendedFeatures
.HasMMXPlus
= ((localCPUExtendedFeatures
& 0x01000000) != 0); // Cyrix specific: Extended MMX --> Bit 24
1618 bool SystemInformationImplementation::RetrieveProcessorSerialNumber()
1620 // Check to see if the processor supports the processor serial number.
1621 if (!this->Features
.HasSerial
)
1626 #if USE_ASM_INSTRUCTIONS
1627 int SerialNumber
[3];
1630 // Use assembly to detect CPUID information...
1633 #ifdef CPUID_AWARE_COMPILER
1634 ; we must push
/pop the registers
<<CPUID
>> writes to
, as the
1635 ; optimiser doesn
't know about <<CPUID>>, and so doesn't expect
1636 ; these registers to change
.
1643 ; eax
= 3 --> ebx
: top
32 bits are the processor signature bits
--> NB
: Transmeta only
?!?
1644 ; ecx
: middle
32 bits are the processor signature bits
1645 ; edx
: bottom
32 bits are the processor signature bits
1648 mov SerialNumber
[0 * TYPE
int], ebx
1649 mov SerialNumber
[1 * TYPE
int], ecx
1650 mov SerialNumber
[2 * TYPE
int], edx
1652 #ifdef CPUID_AWARE_COMPILER
1665 // Process the returned information.
1666 sprintf (this->ChipID
.SerialNumber
, "%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x",
1667 ((SerialNumber
[0] & 0xff000000) >> 24),
1668 ((SerialNumber
[0] & 0x00ff0000) >> 16),
1669 ((SerialNumber
[0] & 0x0000ff00) >> 8),
1670 ((SerialNumber
[0] & 0x000000ff) >> 0),
1671 ((SerialNumber
[1] & 0xff000000) >> 24),
1672 ((SerialNumber
[1] & 0x00ff0000) >> 16),
1673 ((SerialNumber
[1] & 0x0000ff00) >> 8),
1674 ((SerialNumber
[1] & 0x000000ff) >> 0),
1675 ((SerialNumber
[2] & 0xff000000) >> 24),
1676 ((SerialNumber
[2] & 0x00ff0000) >> 16),
1677 ((SerialNumber
[2] & 0x0000ff00) >> 8),
1678 ((SerialNumber
[2] & 0x000000ff) >> 0));
1685 bool SystemInformationImplementation::RetrieveCPUPowerManagement()
1687 // Check to see if what we are about to do is supported...
1688 if (!RetrieveCPUExtendedLevelSupport (0x80000007))
1690 this->Features
.ExtendedFeatures
.PowerManagement
.HasFrequencyID
= false;
1691 this->Features
.ExtendedFeatures
.PowerManagement
.HasVoltageID
= false;
1692 this->Features
.ExtendedFeatures
.PowerManagement
.HasTempSenseDiode
= false;
1696 #if USE_ASM_INSTRUCTIONS
1697 int localCPUPowerManagement
= 0;
1700 // Use assembly to detect CPUID information...
1703 #ifdef CPUID_AWARE_COMPILER
1704 ; we must push
/pop the registers
<<CPUID
>> writes to
, as the
1705 ; optimiser doesn
't know about <<CPUID>>, and so doesn't expect
1706 ; these registers to change
.
1713 ; eax
= 0x80000007 --> edx
: get processor power management
1716 mov localCPUPowerManagement
, edx
1718 #ifdef CPUID_AWARE_COMPILER
1731 // Check for the power management capabilities of the CPU.
1732 this->Features
.ExtendedFeatures
.PowerManagement
.HasTempSenseDiode
= ((localCPUPowerManagement
& 0x00000001) != 0);
1733 this->Features
.ExtendedFeatures
.PowerManagement
.HasFrequencyID
= ((localCPUPowerManagement
& 0x00000002) != 0);
1734 this->Features
.ExtendedFeatures
.PowerManagement
.HasVoltageID
= ((localCPUPowerManagement
& 0x00000004) != 0);
1742 bool SystemInformationImplementation::RetrieveExtendedCPUIdentity()
1744 // Check to see if what we are about to do is supported...
1745 if (!RetrieveCPUExtendedLevelSupport(0x80000002)) return false;
1746 if (!RetrieveCPUExtendedLevelSupport(0x80000003)) return false;
1747 if (!RetrieveCPUExtendedLevelSupport(0x80000004)) return false;
1749 #if USE_ASM_INSTRUCTIONS
1750 int ProcessorNameStartPos
= 0;
1751 int CPUExtendedIdentity
[12];
1753 // Use assembly to detect CPUID information...
1756 #ifdef CPUID_AWARE_COMPILER
1757 ; we must push
/pop the registers
<<CPUID
>> writes to
, as the
1758 ; optimiser doesn
't know about <<CPUID>>, and so doesn't expect
1759 ; these registers to change
.
1766 ; eax
= 0x80000002 --> eax
, ebx
, ecx
, edx
: get processor name
string (part
1)
1769 mov CPUExtendedIdentity
[0 * TYPE
int], eax
1770 mov CPUExtendedIdentity
[1 * TYPE
int], ebx
1771 mov CPUExtendedIdentity
[2 * TYPE
int], ecx
1772 mov CPUExtendedIdentity
[3 * TYPE
int], edx
1775 ; eax
= 0x80000003 --> eax
, ebx
, ecx
, edx
: get processor name
string (part
2)
1778 mov CPUExtendedIdentity
[4 * TYPE
int], eax
1779 mov CPUExtendedIdentity
[5 * TYPE
int], ebx
1780 mov CPUExtendedIdentity
[6 * TYPE
int], ecx
1781 mov CPUExtendedIdentity
[7 * TYPE
int], edx
1784 ; eax
= 0x80000004 --> eax
, ebx
, ecx
, edx
: get processor name
string (part
3)
1787 mov CPUExtendedIdentity
[8 * TYPE
int], eax
1788 mov CPUExtendedIdentity
[9 * TYPE
int], ebx
1789 mov CPUExtendedIdentity
[10 * TYPE
int], ecx
1790 mov CPUExtendedIdentity
[11 * TYPE
int], edx
1792 #ifdef CPUID_AWARE_COMPILER
1805 // Process the returned information.
1806 memcpy (this->ChipID
.ProcessorName
, &(CPUExtendedIdentity
[0]), sizeof (int));
1807 memcpy (&(this->ChipID
.ProcessorName
[4]), &(CPUExtendedIdentity
[1]), sizeof (int));
1808 memcpy (&(this->ChipID
.ProcessorName
[8]), &(CPUExtendedIdentity
[2]), sizeof (int));
1809 memcpy (&(this->ChipID
.ProcessorName
[12]), &(CPUExtendedIdentity
[3]), sizeof (int));
1810 memcpy (&(this->ChipID
.ProcessorName
[16]), &(CPUExtendedIdentity
[4]), sizeof (int));
1811 memcpy (&(this->ChipID
.ProcessorName
[20]), &(CPUExtendedIdentity
[5]), sizeof (int));
1812 memcpy (&(this->ChipID
.ProcessorName
[24]), &(CPUExtendedIdentity
[6]), sizeof (int));
1813 memcpy (&(this->ChipID
.ProcessorName
[28]), &(CPUExtendedIdentity
[7]), sizeof (int));
1814 memcpy (&(this->ChipID
.ProcessorName
[32]), &(CPUExtendedIdentity
[8]), sizeof (int));
1815 memcpy (&(this->ChipID
.ProcessorName
[36]), &(CPUExtendedIdentity
[9]), sizeof (int));
1816 memcpy (&(this->ChipID
.ProcessorName
[40]), &(CPUExtendedIdentity
[10]), sizeof (int));
1817 memcpy (&(this->ChipID
.ProcessorName
[44]), &(CPUExtendedIdentity
[11]), sizeof (int));
1818 this->ChipID
.ProcessorName
[48] = '\0';
1820 // Because some manufacturers have leading white space - we have to post-process the name.
1821 if (this->ChipManufacturer
== Intel
)
1823 for (int nCounter
= 0; nCounter
< CHIPNAME_STRING_LENGTH
; nCounter
++)
1825 // There will either be NULL (\0) or spaces ( ) as the leading characters.
1826 if ((this->ChipID
.ProcessorName
[nCounter
] != '\0') && (this->ChipID
.ProcessorName
[nCounter
] != ' '))
1828 // We have found the starting position of the name.
1829 ProcessorNameStartPos
= nCounter
;
1830 // Terminate the loop.
1835 // Check to see if there is any white space at the start.
1836 if (ProcessorNameStartPos
== 0)
1841 // Now move the name forward so that there is no white space.
1842 memmove(this->ChipID
.ProcessorName
, &(this->ChipID
.ProcessorName
[ProcessorNameStartPos
]), (CHIPNAME_STRING_LENGTH
- ProcessorNameStartPos
));
1850 bool SystemInformationImplementation::RetrieveClassicalCPUIdentity()
1852 // Start by decided which manufacturer we are using....
1853 switch (this->ChipManufacturer
)
1856 // Check the family / model / revision to determine the CPU ID.
1857 switch (this->ChipID
.Family
) {
1859 sprintf (this->ChipID
.ProcessorName
, "Newer i80386 family");
1862 switch (this->ChipID
.Model
) {
1863 case 0: sprintf (this->ChipID
.ProcessorName
,"i80486DX-25/33"); break;
1864 case 1: sprintf (this->ChipID
.ProcessorName
,"i80486DX-50"); break;
1865 case 2: sprintf (this->ChipID
.ProcessorName
,"i80486SX"); break;
1866 case 3: sprintf (this->ChipID
.ProcessorName
,"i80486DX2"); break;
1867 case 4: sprintf (this->ChipID
.ProcessorName
,"i80486SL"); break;
1868 case 5: sprintf (this->ChipID
.ProcessorName
,"i80486SX2"); break;
1869 case 7: sprintf (this->ChipID
.ProcessorName
,"i80486DX2 WriteBack"); break;
1870 case 8: sprintf (this->ChipID
.ProcessorName
,"i80486DX4"); break;
1871 case 9: sprintf (this->ChipID
.ProcessorName
,"i80486DX4 WriteBack"); break;
1872 default: sprintf (this->ChipID
.ProcessorName
,"Unknown 80486 family"); return false;
1876 switch (this->ChipID
.Model
)
1878 case 0: sprintf (this->ChipID
.ProcessorName
,"P5 A-Step"); break;
1879 case 1: sprintf (this->ChipID
.ProcessorName
,"P5"); break;
1880 case 2: sprintf (this->ChipID
.ProcessorName
,"P54C"); break;
1881 case 3: sprintf (this->ChipID
.ProcessorName
,"P24T OverDrive"); break;
1882 case 4: sprintf (this->ChipID
.ProcessorName
,"P55C"); break;
1883 case 7: sprintf (this->ChipID
.ProcessorName
,"P54C"); break;
1884 case 8: sprintf (this->ChipID
.ProcessorName
,"P55C (0.25micron)"); break;
1885 default: sprintf (this->ChipID
.ProcessorName
,"Unknown Pentium family"); return false;
1889 switch (this->ChipID
.Model
)
1891 case 0: sprintf (this->ChipID
.ProcessorName
,"P6 A-Step"); break;
1892 case 1: sprintf (this->ChipID
.ProcessorName
,"P6"); break;
1893 case 3: sprintf (this->ChipID
.ProcessorName
,"Pentium II (0.28 micron)"); break;
1894 case 5: sprintf (this->ChipID
.ProcessorName
,"Pentium II (0.25 micron)"); break;
1895 case 6: sprintf (this->ChipID
.ProcessorName
,"Pentium II With On-Die L2 Cache"); break;
1896 case 7: sprintf (this->ChipID
.ProcessorName
,"Pentium III (0.25 micron)"); break;
1897 case 8: sprintf (this->ChipID
.ProcessorName
,"Pentium III (0.18 micron) With 256 KB On-Die L2 Cache "); break;
1898 case 0xa: sprintf (this->ChipID
.ProcessorName
,"Pentium III (0.18 micron) With 1 Or 2 MB On-Die L2 Cache "); break;
1899 case 0xb: sprintf (this->ChipID
.ProcessorName
,"Pentium III (0.13 micron) With 256 Or 512 KB On-Die L2 Cache "); break;
1900 default: sprintf (this->ChipID
.ProcessorName
,"Unknown P6 family"); return false;
1904 sprintf (this->ChipID
.ProcessorName
,"Intel Merced (IA-64)");
1907 // Check the extended family bits...
1908 switch (this->ChipID
.ExtendedFamily
)
1911 switch (this->ChipID
.Model
)
1913 case 0: sprintf (this->ChipID
.ProcessorName
,"Pentium IV (0.18 micron)"); break;
1914 case 1: sprintf (this->ChipID
.ProcessorName
,"Pentium IV (0.18 micron)"); break;
1915 case 2: sprintf (this->ChipID
.ProcessorName
,"Pentium IV (0.13 micron)"); break;
1916 default: sprintf (this->ChipID
.ProcessorName
,"Unknown Pentium 4 family"); return false;
1920 sprintf (this->ChipID
.ProcessorName
,"Intel McKinley (IA-64)");
1923 sprintf (this->ChipID
.ProcessorName
,"Pentium");
1927 sprintf (this->ChipID
.ProcessorName
,"Unknown Intel family");
1933 // Check the family / model / revision to determine the CPU ID.
1934 switch (this->ChipID
.Family
)
1937 switch (this->ChipID
.Model
)
1939 case 3: sprintf (this->ChipID
.ProcessorName
,"80486DX2"); break;
1940 case 7: sprintf (this->ChipID
.ProcessorName
,"80486DX2 WriteBack"); break;
1941 case 8: sprintf (this->ChipID
.ProcessorName
,"80486DX4"); break;
1942 case 9: sprintf (this->ChipID
.ProcessorName
,"80486DX4 WriteBack"); break;
1943 case 0xe: sprintf (this->ChipID
.ProcessorName
,"5x86"); break;
1944 case 0xf: sprintf (this->ChipID
.ProcessorName
,"5x86WB"); break;
1945 default: sprintf (this->ChipID
.ProcessorName
,"Unknown 80486 family"); return false;
1949 switch (this->ChipID
.Model
)
1951 case 0: sprintf (this->ChipID
.ProcessorName
,"SSA5 (PR75, PR90, PR100)"); break;
1952 case 1: sprintf (this->ChipID
.ProcessorName
,"5k86 (PR120, PR133)"); break;
1953 case 2: sprintf (this->ChipID
.ProcessorName
,"5k86 (PR166)"); break;
1954 case 3: sprintf (this->ChipID
.ProcessorName
,"5k86 (PR200)"); break;
1955 case 6: sprintf (this->ChipID
.ProcessorName
,"K6 (0.30 micron)"); break;
1956 case 7: sprintf (this->ChipID
.ProcessorName
,"K6 (0.25 micron)"); break;
1957 case 8: sprintf (this->ChipID
.ProcessorName
,"K6-2"); break;
1958 case 9: sprintf (this->ChipID
.ProcessorName
,"K6-III"); break;
1959 case 0xd: sprintf (this->ChipID
.ProcessorName
,"K6-2+ or K6-III+ (0.18 micron)"); break;
1960 default: sprintf (this->ChipID
.ProcessorName
,"Unknown 80586 family"); return false;
1964 switch (this->ChipID
.Model
)
1966 case 1: sprintf (this->ChipID
.ProcessorName
,"Athlonâ„¢ (0.25 micron)"); break;
1967 case 2: sprintf (this->ChipID
.ProcessorName
,"Athlonâ„¢ (0.18 micron)"); break;
1968 case 3: sprintf (this->ChipID
.ProcessorName
,"Duronâ„¢ (SF core)"); break;
1969 case 4: sprintf (this->ChipID
.ProcessorName
,"Athlonâ„¢ (Thunderbird core)"); break;
1970 case 6: sprintf (this->ChipID
.ProcessorName
,"Athlonâ„¢ (Palomino core)"); break;
1971 case 7: sprintf (this->ChipID
.ProcessorName
,"Duronâ„¢ (Morgan core)"); break;
1973 if (this->Features
.ExtendedFeatures
.SupportsMP
)
1974 sprintf (this->ChipID
.ProcessorName
,"Athlonâ„¢ MP (Thoroughbred core)");
1975 else sprintf (this->ChipID
.ProcessorName
,"Athlonâ„¢ XP (Thoroughbred core)");
1977 default: sprintf (this->ChipID
.ProcessorName
,"Unknown K7 family"); return false;
1981 sprintf (this->ChipID
.ProcessorName
,"Unknown AMD family");
1987 switch (this->ChipID
.Family
)
1990 switch (this->ChipID
.Model
)
1992 case 4: sprintf (this->ChipID
.ProcessorName
,"Crusoe TM3x00 and TM5x00"); break;
1993 default: sprintf (this->ChipID
.ProcessorName
,"Unknown Crusoe family"); return false;
1997 sprintf (this->ChipID
.ProcessorName
,"Unknown Transmeta family");
2003 switch (this->ChipID
.Family
)
2006 switch (this->ChipID
.Model
)
2008 case 0: sprintf (this->ChipID
.ProcessorName
,"mP6 (0.25 micron)"); break;
2009 case 2: sprintf (this->ChipID
.ProcessorName
,"mP6 (0.18 micron)"); break;
2010 default: sprintf (this->ChipID
.ProcessorName
,"Unknown Rise family"); return false;
2014 sprintf (this->ChipID
.ProcessorName
,"Unknown Rise family");
2020 switch (this->ChipID
.Family
)
2023 switch (this->ChipID
.Model
)
2025 case 1: sprintf (this->ChipID
.ProcessorName
,"U5D"); break;
2026 case 2: sprintf (this->ChipID
.ProcessorName
,"U5S"); break;
2027 default: sprintf (this->ChipID
.ProcessorName
,"Unknown UMC family"); return false;
2031 sprintf (this->ChipID
.ProcessorName
,"Unknown UMC family");
2037 switch (this->ChipID
.Family
)
2040 switch (this->ChipID
.Model
)
2042 case 4: sprintf (this->ChipID
.ProcessorName
,"C6"); break;
2043 case 8: sprintf (this->ChipID
.ProcessorName
,"C2"); break;
2044 case 9: sprintf (this->ChipID
.ProcessorName
,"C3"); break;
2045 default: sprintf (this->ChipID
.ProcessorName
,"Unknown IDT\\Centaur family"); return false;
2049 switch (this->ChipID
.Model
)
2051 case 6: sprintf (this->ChipID
.ProcessorName
,"VIA Cyrix III - Samuel"); break;
2052 default: sprintf (this->ChipID
.ProcessorName
,"Unknown IDT\\Centaur family"); return false;
2056 sprintf (this->ChipID
.ProcessorName
,"Unknown IDT\\Centaur family");
2062 switch (this->ChipID
.Family
)
2065 switch (this->ChipID
.Model
)
2067 case 4: sprintf (this->ChipID
.ProcessorName
,"MediaGX GX, GXm"); break;
2068 case 9: sprintf (this->ChipID
.ProcessorName
,"5x86"); break;
2069 default: sprintf (this->ChipID
.ProcessorName
,"Unknown Cx5x86 family"); return false;
2073 switch (this->ChipID
.Model
)
2075 case 2: sprintf (this->ChipID
.ProcessorName
,"Cx6x86"); break;
2076 case 4: sprintf (this->ChipID
.ProcessorName
,"MediaGX GXm"); break;
2077 default: sprintf (this->ChipID
.ProcessorName
,"Unknown Cx6x86 family"); return false;
2081 switch (this->ChipID
.Model
)
2083 case 0: sprintf (this->ChipID
.ProcessorName
,"6x86MX"); break;
2084 case 5: sprintf (this->ChipID
.ProcessorName
,"Cyrix M2 Core"); break;
2085 case 6: sprintf (this->ChipID
.ProcessorName
,"WinChip C5A Core"); break;
2086 case 7: sprintf (this->ChipID
.ProcessorName
,"WinChip C5B\\C5C Core"); break;
2087 case 8: sprintf (this->ChipID
.ProcessorName
,"WinChip C5C-T Core"); break;
2088 default: sprintf (this->ChipID
.ProcessorName
,"Unknown 6x86MX\\Cyrix III family"); return false;
2092 sprintf (this->ChipID
.ProcessorName
,"Unknown Cyrix family");
2098 switch (this->ChipID
.Family
)
2101 switch (this->ChipID
.Model
)
2103 case 0: sprintf (this->ChipID
.ProcessorName
,"Nx586 or Nx586FPU"); break;
2104 default: sprintf (this->ChipID
.ProcessorName
,"Unknown NexGen family"); return false;
2108 sprintf (this->ChipID
.ProcessorName
,"Unknown NexGen family");
2114 sprintf (this->ChipID
.ProcessorName
,"Cx486SLC \\ DLC \\ Cx486S A-Step");
2117 sprintf (this->ChipID
.ProcessorName
,"Unknown family"); // We cannot identify the processor.
2124 /** Extract a value from the CPUInfo file */
2125 kwsys_stl::string
SystemInformationImplementation::ExtractValueFromCpuInfoFile(kwsys_stl::string buffer
,const char* word
,size_t init
)
2127 size_t pos
= buffer
.find(word
,init
);
2128 if(pos
!= buffer
.npos
)
2130 this->CurrentPositionInFile
= pos
;
2131 pos
= buffer
.find(":",pos
);
2132 size_t pos2
= buffer
.find("\n",pos
);
2133 if(pos
!=buffer
.npos
&& pos2
!=buffer
.npos
)
2135 return buffer
.substr(pos
+2,pos2
-pos
-2);
2138 this->CurrentPositionInFile
= buffer
.npos
;
2142 /** Query for the cpu status */
2143 int SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
2145 this->NumberOfLogicalCPU
= 0;
2146 this->NumberOfPhysicalCPU
= 0;
2147 kwsys_stl::string buffer
;
2149 FILE *fd
= fopen("/proc/cpuinfo", "r" );
2152 kwsys_ios::cout
<< "Problem opening /proc/cpuinfo" << kwsys_stl::endl
;
2156 size_t fileSize
= 0;
2159 buffer
+= fgetc(fd
);
2164 buffer
.resize(fileSize
-2);
2167 size_t pos
= buffer
.find("processor\t");
2168 while(pos
!= buffer
.npos
)
2170 this->NumberOfLogicalCPU
++;
2171 this->NumberOfPhysicalCPU
++;
2172 pos
= buffer
.find("processor\t",pos
+1);
2175 // Count the number of physical ids that are the same
2177 kwsys_stl::string idc
= this->ExtractValueFromCpuInfoFile(buffer
,"physical id");
2179 while(this->CurrentPositionInFile
!= buffer
.npos
)
2181 int id
= atoi(idc
.c_str());
2184 this->NumberOfPhysicalCPU
--;
2187 idc
= this->ExtractValueFromCpuInfoFile(buffer
,"physical id",this->CurrentPositionInFile
+1);
2190 if(this->NumberOfPhysicalCPU
>0)
2192 this->NumberOfLogicalCPU
/= this->NumberOfPhysicalCPU
;
2195 // CPU speed (checking only the first proc
2196 kwsys_stl::string CPUSpeed
= this->ExtractValueFromCpuInfoFile(buffer
,"cpu MHz");
2197 this->CPUSpeedInMHz
= (float)atof(CPUSpeed
.c_str());
2200 this->ChipID
.Family
= atoi(this->ExtractValueFromCpuInfoFile(buffer
,"cpu family").c_str());
2203 strcpy(this->ChipID
.Vendor
,this->ExtractValueFromCpuInfoFile(buffer
,"vendor_id").c_str());
2204 this->FindManufacturer();
2207 this->ChipID
.Model
= atoi(this->ExtractValueFromCpuInfoFile(buffer
,"model").c_str());
2208 this->RetrieveClassicalCPUIdentity();
2211 kwsys_stl::string cacheSize
= this->ExtractValueFromCpuInfoFile(buffer
,"cache size");
2212 pos
= cacheSize
.find(" KB");
2213 if(pos
!=cacheSize
.npos
)
2215 cacheSize
= cacheSize
.substr(0,pos
);
2217 this->Features
.L1CacheSize
= atoi(cacheSize
.c_str());
2223 /** Query for the memory status */
2224 int SystemInformationImplementation::QueryMemory()
2226 this->TotalVirtualMemory
= 0;
2227 this->TotalPhysicalMemory
= 0;
2228 this->AvailableVirtualMemory
= 0;
2229 this->AvailablePhysicalMemory
= 0;
2234 GlobalMemoryStatus(&ms
);
2236 unsigned long tv
= ms
.dwTotalVirtual
;
2237 unsigned long tp
= ms
.dwTotalPhys
;
2238 unsigned long av
= ms
.dwAvailVirtual
;
2239 unsigned long ap
= ms
.dwAvailPhys
;
2240 this->TotalVirtualMemory
= tv
>>10>>10;
2241 this->TotalPhysicalMemory
= tp
>>10>>10;
2242 this->AvailableVirtualMemory
= av
>>10>>10;
2243 this->AvailablePhysicalMemory
= ap
>>10>>10;
2251 char buffer
[1024]; // for skipping unused lines
2256 // Find the Linux kernel version first
2257 struct utsname unameInfo
;
2258 int errorFlag
= uname(&unameInfo
);
2261 kwsys_ios::cout
<< "Problem calling uname(): " << strerror(errno
) << kwsys_stl::endl
;
2265 if( unameInfo
.release
!=0 && strlen(unameInfo
.release
)>=3 )
2267 // release looks like "2.6.3-15mdk-i686-up-4GB"
2268 char majorChar
=unameInfo
.release
[0];
2269 char minorChar
=unameInfo
.release
[2];
2271 if( isdigit(majorChar
) )
2273 linuxMajor
=majorChar
-'0';
2276 if( isdigit(minorChar
) )
2278 linuxMinor
=minorChar
-'0';
2282 FILE *fd
= fopen("/proc/meminfo", "r" );
2285 kwsys_ios::cout
<< "Problem opening /proc/meminfo" << kwsys_stl::endl
;
2289 if( linuxMajor
>=3 || ( (linuxMajor
>=2) && (linuxMinor
>=6) ) )
2291 // new /proc/meminfo format since kernel 2.6.x
2292 // Rigorously, this test should check from the developping version 2.5.x
2293 // that introduced the new format...
2299 fscanf(fd
,"MemTotal:%ld kB\n", &this->TotalPhysicalMemory
);
2300 fscanf(fd
,"MemFree:%ld kB\n", &freeMem
);
2301 fscanf(fd
,"Buffers:%ld kB\n", &buffersMem
);
2302 fscanf(fd
,"Cached:%ld kB\n", &cachedMem
);
2304 this->TotalPhysicalMemory
/= 1024;
2305 this->AvailablePhysicalMemory
= freeMem
+cachedMem
+buffersMem
;
2306 this->AvailablePhysicalMemory
/= 1024;
2308 // Skip SwapCached, Active, Inactive, HighTotal, HighFree, LowTotal
2313 fgets(buffer
, sizeof(buffer
), fd
); // skip a line
2317 fscanf(fd
,"SwapTotal:%ld kB\n", &this->TotalVirtualMemory
);
2318 fscanf(fd
,"SwapFree:%ld kB\n", &this->AvailableVirtualMemory
);
2320 this->TotalVirtualMemory
/= 1024;
2321 this->AvailableVirtualMemory
/= 1024;
2325 // /proc/meminfo format for kernel older than 2.6.x
2328 unsigned long cachedMem
;
2329 unsigned long buffersMem
;
2330 fgets(buffer
, sizeof(buffer
), fd
); // Skip "total: used:..."
2332 fscanf(fd
, "Mem: %lu %lu %lu %lu %lu %lu\n",
2333 &tp
, &temp
, &ap
, &temp
, &buffersMem
, &cachedMem
);
2334 fscanf(fd
, "Swap: %lu %lu %lu\n", &tv
, &temp
, &av
);
2336 this->TotalVirtualMemory
= tv
>>10>>10;
2337 this->TotalPhysicalMemory
= tp
>>10>>10;
2338 this->AvailableVirtualMemory
= av
>>10>>10;
2339 this->AvailablePhysicalMemory
= (ap
+buffersMem
+cachedMem
)>>10>>10;
2348 struct pst_static pst
;
2349 struct pst_dynamic pdy
;
2351 unsigned long ps
= 0;
2352 if (pstat_getstatic(&pst
, sizeof(pst
), (size_t) 1, 0) != -1)
2355 tp
= pst
.physical_memory
*ps
;
2356 tv
= (pst
.physical_memory
+ pst
.pst_maxmem
) * ps
;
2357 if (pstat_getdynamic(&pdy
, sizeof(pdy
), (size_t) 1, 0) != -1)
2359 ap
= tp
- pdy
.psd_rm
* ps
;
2360 av
= tv
- pdy
.psd_vm
;
2361 this->TotalVirtualMemory
= tv
>>10>>10;
2362 this->TotalPhysicalMemory
= tp
>>10>>10;
2363 this->AvailableVirtualMemory
= av
>>10>>10;
2364 this->AvailablePhysicalMemory
= ap
>>10>>10;
2377 unsigned long SystemInformationImplementation::GetTotalVirtualMemory()
2379 return this->TotalVirtualMemory
;
2383 unsigned long SystemInformationImplementation::GetAvailableVirtualMemory()
2385 return this->AvailableVirtualMemory
;
2388 unsigned long SystemInformationImplementation::GetTotalPhysicalMemory()
2390 return this->TotalPhysicalMemory
;
2394 unsigned long SystemInformationImplementation::GetAvailablePhysicalMemory()
2396 return this->AvailablePhysicalMemory
;
2399 /** Get Cycle differences */
2400 LongLong
SystemInformationImplementation::GetCyclesDifference (DELAY_FUNC DelayFunction
,
2401 unsigned int uiParameter
)
2403 #if USE_ASM_INSTRUCTIONS
2405 unsigned int edx1
, eax1
;
2406 unsigned int edx2
, eax2
;
2408 // Calculate the frequency of the CPU instructions.
2411 push uiParameter
; push parameter param
2412 mov ebx
, DelayFunction
; store func in ebx
2416 mov esi
, eax
; esi
= eax
2417 mov edi
, edx
; edi
= edx
2419 call ebx
; call the delay functions
2425 mov edx2
, edx
; edx2
= edx
2426 mov eax2
, eax
; eax2
= eax
2428 mov edx1
, edi
; edx2
= edi
2429 mov eax1
, esi
; eax2
= esi
2437 return ((((__int64
) edx2
<< 32) + eax2
) - (((__int64
) edx1
<< 32) + eax1
));
2440 (void)DelayFunction
;
2446 /** Compute the delay overhead */
2447 void SystemInformationImplementation::DelayOverhead(unsigned int uiMS
)
2450 LARGE_INTEGER Frequency
, StartCounter
, EndCounter
;
2453 // Get the frequency of the high performance counter.
2454 if(!QueryPerformanceFrequency (&Frequency
))
2458 x
= Frequency
.QuadPart
/ 1000 * uiMS
;
2460 // Get the starting position of the counter.
2461 QueryPerformanceCounter (&StartCounter
);
2464 // Get the ending position of the counter.
2465 QueryPerformanceCounter (&EndCounter
);
2466 } while (EndCounter
.QuadPart
- StartCounter
.QuadPart
== x
);
2471 /** Return the number of logical CPU per physical CPUs Works only for windows */
2472 unsigned char SystemInformationImplementation::LogicalCPUPerPhysicalCPU(void)
2474 unsigned int Regebx
= 0;
2475 #if USE_ASM_INSTRUCTIONS
2476 if (!this->IsHyperThreadingSupported())
2478 return (unsigned char) 1; // HT not supported
2487 return (unsigned char) ((Regebx
& NUM_LOGICAL_BITS
) >> 16);
2490 /** Works only for windows */
2491 unsigned int SystemInformationImplementation::IsHyperThreadingSupported()
2493 #if USE_ASM_INSTRUCTIONS
2494 unsigned int Regedx
= 0,
2496 VendorId
[3] = {0, 0, 0};
2497 __try
// Verify cpuid instruction is supported
2501 xor eax
, eax
// call cpuid with eax = 0
2502 cpuid
// Get vendor id string
2504 mov VendorId
+ 4, edx
2505 mov VendorId
+ 8, ecx
2507 mov eax
, 1 // call cpuid with eax = 1
2509 mov Regeax
, eax
// eax contains family processor type
2510 mov Regedx
, edx
// edx has info about the availability of hyper-Threading
2513 __except (EXCEPTION_EXECUTE_HANDLER
)
2515 return(0); // cpuid is unavailable
2518 if (((Regeax
& FAMILY_ID
) == PENTIUM4_ID
) || (Regeax
& EXT_FAMILY_ID
))
2520 if (VendorId
[0] == 'uneG')
2522 if (VendorId
[1] == 'Ieni')
2524 if (VendorId
[2] == 'letn')
2526 return(Regedx
& HT_BIT
); // Genuine Intel with hyper-Threading technology
2533 return 0; // Not genuine Intel processor
2536 /** Return the APIC Id. Works only for windows. */
2537 unsigned char SystemInformationImplementation::GetAPICId()
2539 unsigned int Regebx
= 0;
2540 #if USE_ASM_INSTRUCTIONS
2541 if (!this->IsHyperThreadingSupported())
2543 return (unsigned char) -1; // HT not supported
2544 } // Logical processor = 1
2552 return (unsigned char) ((Regebx
& INITIAL_APIC_ID_BITS
) >> 24);
2555 /** Count the number of CPUs. Works only on windows. */
2556 int SystemInformationImplementation::CPUCount()
2559 unsigned char StatusFlag
= 0;
2562 this->NumberOfPhysicalCPU
= 0;
2563 this->NumberOfLogicalCPU
= 0;
2564 info
.dwNumberOfProcessors
= 0;
2565 GetSystemInfo (&info
);
2567 // Number of physical processors in a non-Intel system
2568 // or in a 32-bit Intel system with Hyper-Threading technology disabled
2569 this->NumberOfPhysicalCPU
= (unsigned char) info
.dwNumberOfProcessors
;
2571 if (this->IsHyperThreadingSupported())
2573 unsigned char HT_Enabled
= 0;
2574 this->NumberOfLogicalCPU
= this->LogicalCPUPerPhysicalCPU();
2575 if (this->NumberOfLogicalCPU
>= 1) // >1 Doesn't mean HT is enabled in the BIOS
2577 HANDLE hCurrentProcessHandle
;
2579 # define DWORD_PTR DWORD
2581 DWORD_PTR dwProcessAffinity
;
2582 DWORD_PTR dwSystemAffinity
;
2583 DWORD dwAffinityMask
;
2585 // Calculate the appropriate shifts and mask based on the
2586 // number of logical processors.
2588 unsigned char PHY_ID_MASK
= 0xFF;
2589 unsigned char PHY_ID_SHIFT
= 0;
2591 while (i
< this->NumberOfLogicalCPU
)
2598 hCurrentProcessHandle
= GetCurrentProcess();
2599 GetProcessAffinityMask(hCurrentProcessHandle
, &dwProcessAffinity
,
2602 // Check if available process affinity mask is equal to the
2603 // available system affinity mask
2604 if (dwProcessAffinity
!= dwSystemAffinity
)
2606 StatusFlag
= HT_CANNOT_DETECT
;
2607 this->NumberOfPhysicalCPU
= (unsigned char)-1;
2612 while (dwAffinityMask
!= 0 && dwAffinityMask
<= dwProcessAffinity
)
2614 // Check if this CPU is available
2615 if (dwAffinityMask
& dwProcessAffinity
)
2617 if (SetProcessAffinityMask(hCurrentProcessHandle
,
2620 unsigned char APIC_ID
, LOG_ID
;
2621 Sleep(0); // Give OS time to switch CPU
2623 APIC_ID
= GetAPICId();
2624 LOG_ID
= APIC_ID
& ~PHY_ID_MASK
;
2632 dwAffinityMask
= dwAffinityMask
<< 1;
2634 // Reset the processor affinity
2635 SetProcessAffinityMask(hCurrentProcessHandle
, dwProcessAffinity
);
2637 if (this->NumberOfLogicalCPU
== 1) // Normal P4 : HT is disabled in hardware
2639 StatusFlag
= HT_DISABLED
;
2645 // Total physical processors in a Hyper-Threading enabled system.
2646 this->NumberOfPhysicalCPU
/= (this->NumberOfLogicalCPU
);
2647 StatusFlag
= HT_ENABLED
;
2651 StatusFlag
= HT_SUPPORTED_NOT_ENABLED
;
2658 // Processors do not have Hyper-Threading technology
2659 StatusFlag
= HT_NOT_CAPABLE
;
2660 this->NumberOfLogicalCPU
= 1;
2668 /** Return the number of logical CPUs on the system */
2669 unsigned int SystemInformationImplementation::GetNumberOfLogicalCPU()
2671 return this->NumberOfLogicalCPU
;
2674 /** Return the number of physical CPUs on the system */
2675 unsigned int SystemInformationImplementation::GetNumberOfPhysicalCPU()
2677 return this->NumberOfPhysicalCPU
;
2680 /** For Mac we Parse the sysctl -a output */
2681 bool SystemInformationImplementation::ParseSysCtl()
2683 // Extract the arguments from the command line
2684 kwsys_stl::vector
<const char*> args
;
2685 args
.push_back("sysctl");
2686 args
.push_back("-a");
2689 this->SysCtlBuffer
= this->RunProcess(args
);
2691 // Parse values for Mac
2692 this->TotalPhysicalMemory
= atoi(this->ExtractValueFromSysCtl("hw.memsize:").c_str())/(1024*1024);
2693 this->TotalVirtualMemory
= 0;
2694 this->AvailablePhysicalMemory
= 0;
2695 this->AvailableVirtualMemory
= 0;
2697 this->NumberOfPhysicalCPU
= atoi(this->ExtractValueFromSysCtl("hw.physicalcpu:").c_str());
2698 this->NumberOfLogicalCPU
= atoi(this->ExtractValueFromSysCtl("hw.logicalcpu:").c_str());
2700 if(this->NumberOfPhysicalCPU
!=0)
2702 this->NumberOfLogicalCPU
/= this->NumberOfPhysicalCPU
;
2705 this->CPUSpeedInMHz
= atoi(this->ExtractValueFromSysCtl("hw.cpufrequency:").c_str());
2706 this->CPUSpeedInMHz
/= 1000000;
2709 this->ChipID
.Family
= atoi(this->ExtractValueFromSysCtl("machdep.cpu.family:").c_str());
2712 strcpy(this->ChipID
.Vendor
,this->ExtractValueFromSysCtl("machdep.cpu.vendor:").c_str());
2713 this->FindManufacturer();
2716 this->ChipID
.Model
= atoi(this->ExtractValueFromSysCtl("machdep.cpu.model:").c_str());
2717 this->RetrieveClassicalCPUIdentity();
2720 this->Features
.L1CacheSize
= atoi(this->ExtractValueFromSysCtl("hw.l1icachesize:").c_str());
2721 this->Features
.L2CacheSize
= atoi(this->ExtractValueFromSysCtl("hw.l2cachesize:").c_str());
2726 /** Extract a value from sysctl command */
2727 kwsys_stl::string
SystemInformationImplementation::ExtractValueFromSysCtl(const char* word
)
2729 size_t pos
= this->SysCtlBuffer
.find(word
);
2730 if(pos
!= this->SysCtlBuffer
.npos
)
2732 pos
= this->SysCtlBuffer
.find(": ",pos
);
2733 size_t pos2
= this->SysCtlBuffer
.find("\n",pos
);
2734 if(pos
!=this->SysCtlBuffer
.npos
&& pos2
!=this->SysCtlBuffer
.npos
)
2736 return this->SysCtlBuffer
.substr(pos
+2,pos2
-pos
-2);
2742 /** Run a given process */
2743 kwsys_stl::string
SystemInformationImplementation::RunProcess(kwsys_stl::vector
<const char*> args
)
2745 kwsys_stl::string buffer
= "";
2747 // Run the application
2748 kwsysProcess
* gp
= kwsysProcess_New();
2749 kwsysProcess_SetCommand(gp
, &*args
.begin());
2750 kwsysProcess_SetOption(gp
,kwsysProcess_Option_HideWindow
,1);
2752 kwsysProcess_Execute(gp
);
2756 double timeout
= 255;
2758 while(kwsysProcess_WaitForData(gp
,&data
,&length
,&timeout
)) // wait for 1s
2760 for(int i
=0;i
<length
;i
++)
2765 kwsysProcess_WaitForExit(gp
, 0);
2768 switch(kwsysProcess_GetState(gp
))
2770 case kwsysProcess_State_Exited
:
2772 result
= kwsysProcess_GetExitValue(gp
);
2774 case kwsysProcess_State_Error
:
2776 kwsys_ios::cerr
<< "Error: Could not run " << args
[0] << ":\n";
2777 kwsys_ios::cerr
<< kwsysProcess_GetErrorString(gp
) << "\n";
2779 case kwsysProcess_State_Exception
:
2781 kwsys_ios::cerr
<< "Error: " << args
[0]
2782 << " terminated with an exception: "
2783 << kwsysProcess_GetExceptionString(gp
) << "\n";
2785 case kwsysProcess_State_Starting
:
2786 case kwsysProcess_State_Executing
:
2787 case kwsysProcess_State_Expired
:
2788 case kwsysProcess_State_Killed
:
2790 // Should not get here.
2791 kwsys_ios::cerr
<< "Unexpected ending state after running " << args
[0]
2795 kwsysProcess_Delete(gp
);
2798 kwsys_ios::cerr
<< "Error " << args
[0] << " returned :" << result
<< "\n";
2804 kwsys_stl::string
SystemInformationImplementation::ParseValueFromKStat(const char* arguments
)
2806 kwsys_stl::vector
<const char*> args
;
2808 args
.push_back("kstat");
2809 args
.push_back("-p");
2811 kwsys_stl::string command
= arguments
;
2812 size_t start
= command
.npos
;
2813 size_t pos
= command
.find(' ',0);
2814 while(pos
!=command
.npos
)
2816 bool inQuotes
= false;
2817 // Check if we are between quotes
2818 size_t b0
= command
.find('"',0);
2819 size_t b1
= command
.find('"',b0
+1);
2820 while(b0
!= command
.npos
&& b1
!= command
.npos
&& b1
>b0
)
2822 if(pos
>b0
&& pos
<b1
)
2827 b0
= command
.find('"',b1
+1);
2828 b1
= command
.find('"',b0
+1);
2833 kwsys_stl::string arg
= command
.substr(start
+1,pos
-start
-1);
2835 // Remove the quotes if any
2836 size_t quotes
= arg
.find('"');
2837 while(quotes
!= arg
.npos
)
2839 arg
.erase(quotes
,1);
2840 quotes
= arg
.find('"');
2842 args
.push_back(arg
.c_str());
2845 pos
= command
.find(' ',pos
+1);
2847 kwsys_stl::string lastArg
= command
.substr(start
+1,command
.size()-start
-1);
2848 args
.push_back(lastArg
.c_str());
2852 kwsys_stl::string buffer
= this->RunProcess(args
);
2854 kwsys_stl::string value
= "";
2855 for(size_t i
=buffer
.size()-1;i
>0;i
--)
2857 if(buffer
[i
] == ' ' || buffer
[i
] == '\t')
2861 if(buffer
[i
] != '\n' && buffer
[i
] != '\r')
2863 kwsys_stl::string val
= value
;
2871 /** Querying for system information from Solaris */
2872 bool SystemInformationImplementation::QuerySolarisInfo()
2875 this->NumberOfPhysicalCPU
= atoi(this->ParseValueFromKStat("-n systethis->misc -s ncpus").c_str());
2876 this->NumberOfLogicalCPU
= this->NumberOfPhysicalCPU
;
2878 if(this->NumberOfPhysicalCPU
!=0)
2880 this->NumberOfLogicalCPU
/= this->NumberOfPhysicalCPU
;
2883 this->CPUSpeedInMHz
= atoi(this->ParseValueFromKStat("-s clock_MHz").c_str());
2886 this->ChipID
.Family
= 0;
2889 strcpy(this->ChipID
.Vendor
,"Sun");
2890 this->FindManufacturer();
2893 sprintf(this->ChipID
.ProcessorName
,"%s",this->ParseValueFromKStat("-s cpu_type").c_str());
2894 this->ChipID
.Model
= 0;
2897 this->Features
.L1CacheSize
= 0;
2898 this->Features
.L2CacheSize
= 0;
2901 unsigned long totalMemory
=
2902 strtoul(this->ParseValueFromKStat("-s physmem").c_str(),&tail
,0);
2903 this->TotalPhysicalMemory
= totalMemory
/1024;
2904 this->TotalPhysicalMemory
*= 8192;
2905 this->TotalPhysicalMemory
/= 1024;
2907 // Undefined values (for now at least)
2908 this->TotalVirtualMemory
= 0;
2909 this->AvailablePhysicalMemory
= 0;
2910 this->AvailableVirtualMemory
= 0;
2915 /** Query the operating system information */
2916 bool SystemInformationImplementation::QueryOSInformation()
2920 this->OSName
= "Windows";
2922 OSVERSIONINFOEX osvi
;
2923 BOOL bIsWindows64Bit
;
2924 BOOL bOsVersionInfoEx
;
2925 char * operatingSystem
= new char [256];
2927 // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
2928 ZeroMemory (&osvi
, sizeof (OSVERSIONINFOEX
));
2929 osvi
.dwOSVersionInfoSize
= sizeof (OSVERSIONINFOEX
);
2930 bOsVersionInfoEx
= GetVersionEx ((OSVERSIONINFO
*) &osvi
);
2931 if (!bOsVersionInfoEx
)
2933 osvi
.dwOSVersionInfoSize
= sizeof (OSVERSIONINFO
);
2934 if (!GetVersionEx ((OSVERSIONINFO
*) &osvi
))
2940 switch (osvi
.dwPlatformId
)
2942 case VER_PLATFORM_WIN32_NT
:
2943 // Test for the product.
2944 if (osvi
.dwMajorVersion
<= 4)
2946 this->OSRelease
= "NT";
2948 if (osvi
.dwMajorVersion
== 5 && osvi
.dwMinorVersion
== 0)
2950 this->OSRelease
= "2000";
2952 if (osvi
.dwMajorVersion
== 5 && osvi
.dwMinorVersion
== 1)
2954 this->OSRelease
= "XP";
2956 #ifdef VER_NT_WORKSTATION
2957 // Test for product type.
2958 if (bOsVersionInfoEx
)
2960 if (osvi
.wProductType
== VER_NT_WORKSTATION
)
2962 // VER_SUITE_PERSONAL may not be defined
2963 #ifdef VER_SUITE_PERSONAL
2964 if (osvi
.wSuiteMask
& VER_SUITE_PERSONAL
)
2966 this->OSRelease
+= " Personal";
2970 this->OSRelease
+= " Professional";
2974 else if (osvi
.wProductType
== VER_NT_SERVER
)
2976 // Check for .NET Server instead of Windows XP.
2977 if (osvi
.dwMajorVersion
== 5 && osvi
.dwMinorVersion
== 1)
2979 this->OSRelease
= ".NET";
2982 // Continue with the type detection.
2983 if (osvi
.wSuiteMask
& VER_SUITE_DATACENTER
)
2985 this->OSRelease
+= " DataCenter Server";
2987 else if (osvi
.wSuiteMask
& VER_SUITE_ENTERPRISE
)
2989 this->OSRelease
+= " Advanced Server";
2993 this->OSRelease
+= " Server";
2997 sprintf (operatingSystem
, "%s(Build %d)", osvi
.szCSDVersion
, osvi
.dwBuildNumber
& 0xFFFF);
2998 this->OSVersion
= operatingSystem
;
3001 #endif // VER_NT_WORKSTATION
3004 char szProductType
[80];
3007 // Query the registry to retrieve information.
3008 RegOpenKeyEx (HKEY_LOCAL_MACHINE
, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 0, KEY_QUERY_VALUE
, &hKey
);
3009 RegQueryValueEx (hKey
, "ProductType", NULL
, NULL
, (LPBYTE
) szProductType
, &dwBufLen
);
3012 if (lstrcmpi ("WINNT", szProductType
) == 0)
3014 this->OSRelease
+= " Professional";
3016 if (lstrcmpi ("LANMANNT", szProductType
) == 0)
3018 // Decide between Windows 2000 Advanced Server and Windows .NET Enterprise Server.
3019 if (osvi
.dwMajorVersion
== 5 && osvi
.dwMinorVersion
== 1)
3021 this->OSRelease
+= " Standard Server";
3025 this->OSRelease
+= " Server";
3028 if (lstrcmpi ("SERVERNT", szProductType
) == 0)
3030 // Decide between Windows 2000 Advanced Server and Windows .NET Enterprise Server.
3031 if (osvi
.dwMajorVersion
== 5 && osvi
.dwMinorVersion
== 1)
3033 this->OSRelease
+= " Enterprise Server";
3037 this->OSRelease
+= " Advanced Server";
3042 // Display version, service pack (if any), and build number.
3043 if (osvi
.dwMajorVersion
<= 4)
3045 // NB: NT 4.0 and earlier.
3046 sprintf (operatingSystem
, "version %d.%d %s (Build %d)",
3047 osvi
.dwMajorVersion
,
3048 osvi
.dwMinorVersion
,
3050 osvi
.dwBuildNumber
& 0xFFFF);
3051 this->OSVersion
= operatingSystem
;
3053 else if (osvi
.dwMajorVersion
== 5 && osvi
.dwMinorVersion
== 1)
3055 // Windows XP and .NET server.
3056 typedef BOOL (CALLBACK
* LPFNPROC
) (HANDLE
, BOOL
*);
3057 HINSTANCE hKernelDLL
;
3060 // Load the Kernel32 DLL.
3061 hKernelDLL
= LoadLibrary ("kernel32");
3062 if (hKernelDLL
!= NULL
) {
3063 // Only XP and .NET Server support IsWOW64Process so... Load dynamically!
3064 DLLProc
= (LPFNPROC
) GetProcAddress (hKernelDLL
, "IsWow64Process");
3066 // If the function address is valid, call the function.
3067 if (DLLProc
!= NULL
) (DLLProc
) (GetCurrentProcess (), &bIsWindows64Bit
);
3068 else bIsWindows64Bit
= false;
3070 // Free the DLL module.
3071 FreeLibrary (hKernelDLL
);
3076 // Windows 2000 and everything else.
3077 sprintf (operatingSystem
,"%s(Build %d)", osvi
.szCSDVersion
, osvi
.dwBuildNumber
& 0xFFFF);
3078 this->OSVersion
= operatingSystem
;
3082 case VER_PLATFORM_WIN32_WINDOWS
:
3083 // Test for the product.
3084 if (osvi
.dwMajorVersion
== 4 && osvi
.dwMinorVersion
== 0)
3086 this->OSRelease
= "95";
3087 if(osvi
.szCSDVersion
[1] == 'C')
3089 this->OSRelease
+= "OSR 2.5";
3091 else if(osvi
.szCSDVersion
[1] == 'B')
3093 this->OSRelease
+= "OSR 2";
3097 if (osvi
.dwMajorVersion
== 4 && osvi
.dwMinorVersion
== 10)
3099 this->OSRelease
= "98";
3100 if (osvi
.szCSDVersion
[1] == 'A' )
3102 this->OSRelease
+= "SE";
3106 if (osvi
.dwMajorVersion
== 4 && osvi
.dwMinorVersion
== 90)
3108 this->OSRelease
= "Me";
3112 case VER_PLATFORM_WIN32s
:
3113 this->OSRelease
= "Win32s";
3117 this->OSRelease
= "Unknown";
3120 delete [] operatingSystem
;
3121 operatingSystem
= 0;
3124 WORD wVersionRequested
;
3127 wVersionRequested
= MAKEWORD(2,0);
3129 if ( WSAStartup( wVersionRequested
, &wsaData
) == 0 )
3131 gethostname(name
,sizeof(name
));
3134 this->Hostname
= name
;
3138 struct utsname unameInfo
;
3139 int errorFlag
= uname(&unameInfo
);
3142 this->OSName
= unameInfo
.sysname
;
3143 this->Hostname
= unameInfo
.nodename
;
3144 this->OSRelease
= unameInfo
.release
;
3145 this->OSVersion
= unameInfo
.version
;
3146 this->OSPlatform
= unameInfo
.machine
;
3154 /** Return true if the machine is 64 bits */
3155 bool SystemInformationImplementation::Is64Bits()
3157 return (sizeof(void*) == 8);
3160 } // namespace @KWSYS_NAMESPACE@