00001 00032 // Author: Benjamin Jurke 00033 // File history: 27.02.2002 File created. 00035 00036 00037 #ifndef LLPROCESSOR_H 00038 #define LLPROCESSOR_H 00039 00040 // Options: 00042 #if LL_WINDOWS 00043 #define PROCESSOR_FREQUENCY_MEASURE_AVAILABLE 00044 #endif 00045 00046 #if LL_MSVC && _M_X64 00047 # define LL_X86_64 1 00048 # define LL_X86 1 00049 #elif LL_MSVC && _M_IX86 00050 # define LL_X86 1 00051 #elif LL_GNUC && ( defined(__amd64__) || defined(__x86_64__) ) 00052 # define LL_X86_64 1 00053 # define LL_X86 1 00054 #elif LL_GNUC && ( defined(__i386__) ) 00055 # define LL_X86 1 00056 #elif LL_GNUC && ( defined(__powerpc__) || defined(__ppc__) ) 00057 # define LL_PPC 1 00058 #endif 00059 00060 00061 typedef struct ProcessorExtensions 00062 { 00063 bool FPU_FloatingPointUnit; 00064 bool VME_Virtual8086ModeEnhancements; 00065 bool DE_DebuggingExtensions; 00066 bool PSE_PageSizeExtensions; 00067 bool TSC_TimeStampCounter; 00068 bool MSR_ModelSpecificRegisters; 00069 bool PAE_PhysicalAddressExtension; 00070 bool MCE_MachineCheckException; 00071 bool CX8_COMPXCHG8B_Instruction; 00072 bool APIC_AdvancedProgrammableInterruptController; 00073 unsigned int APIC_ID; 00074 bool SEP_FastSystemCall; 00075 bool MTRR_MemoryTypeRangeRegisters; 00076 bool PGE_PTE_GlobalFlag; 00077 bool MCA_MachineCheckArchitecture; 00078 bool CMOV_ConditionalMoveAndCompareInstructions; 00079 bool FGPAT_PageAttributeTable; 00080 bool PSE36_36bitPageSizeExtension; 00081 bool PN_ProcessorSerialNumber; 00082 bool CLFSH_CFLUSH_Instruction; 00083 unsigned int CLFLUSH_InstructionCacheLineSize; 00084 bool DS_DebugStore; 00085 bool ACPI_ThermalMonitorAndClockControl; 00086 bool EMMX_MultimediaExtensions; 00087 bool MMX_MultimediaExtensions; 00088 bool FXSR_FastStreamingSIMD_ExtensionsSaveRestore; 00089 bool SSE_StreamingSIMD_Extensions; 00090 bool SSE2_StreamingSIMD2_Extensions; 00091 bool Altivec_Extensions; 00092 bool SS_SelfSnoop; 00093 bool HT_HyperThreading; 00094 unsigned int HT_HyterThreadingSiblings; 00095 bool TM_ThermalMonitor; 00096 bool IA64_Intel64BitArchitecture; 00097 bool _3DNOW_InstructionExtensions; 00098 bool _E3DNOW_InstructionExtensions; 00099 bool AA64_AMD64BitArchitecture; 00100 } ProcessorExtensions; 00101 00102 typedef struct ProcessorCache 00103 { 00104 bool bPresent; 00105 char strSize[32]; /* Flawfinder: ignore */ 00106 unsigned int uiAssociativeWays; 00107 unsigned int uiLineSize; 00108 bool bSectored; 00109 char strCache[128]; /* Flawfinder: ignore */ 00110 } ProcessorCache; 00111 00112 typedef struct ProcessorL1Cache 00113 { 00114 ProcessorCache Instruction; 00115 ProcessorCache Data; 00116 } ProcessorL1Cache; 00117 00118 typedef struct ProcessorTLB 00119 { 00120 bool bPresent; 00121 char strPageSize[32]; /* Flawfinder: ignore */ 00122 unsigned int uiAssociativeWays; 00123 unsigned int uiEntries; 00124 char strTLB[128]; /* Flawfinder: ignore */ 00125 } ProcessorTLB; 00126 00127 typedef struct ProcessorInfo 00128 { 00129 char strVendor[16]; /* Flawfinder: ignore */ 00130 unsigned int uiFamily; 00131 unsigned int uiExtendedFamily; 00132 char strFamily[64]; /* Flawfinder: ignore */ 00133 unsigned int uiModel; 00134 unsigned int uiExtendedModel; 00135 char strModel[128]; /* Flawfinder: ignore */ 00136 unsigned int uiStepping; 00137 unsigned int uiType; 00138 char strType[64]; /* Flawfinder: ignore */ 00139 unsigned int uiBrandID; 00140 char strBrandID[64]; /* Flawfinder: ignore */ 00141 char strProcessorSerial[64]; /* Flawfinder: ignore */ 00142 unsigned long MaxSupportedLevel; 00143 unsigned long MaxSupportedExtendedLevel; 00144 ProcessorExtensions _Ext; 00145 ProcessorL1Cache _L1; 00146 ProcessorCache _L2; 00147 ProcessorCache _L3; 00148 ProcessorCache _Trace; 00149 ProcessorTLB _Instruction; 00150 ProcessorTLB _Data; 00151 } ProcessorInfo; 00152 00153 00154 // CProcessor 00155 // ========== 00156 // Class for detecting the processor name, type and available 00157 // extensions as long as it's speed. 00159 class CProcessor 00160 { 00161 // Constructor / Destructor: 00163 public: 00164 CProcessor(); 00165 00166 // Private vars: 00168 public: 00169 F64 uqwFrequency; 00170 char strCPUName[128]; /* Flawfinder: ignore */ 00171 ProcessorInfo CPUInfo; 00172 00173 // Private functions: 00175 private: 00176 bool AnalyzeIntelProcessor(); 00177 bool AnalyzeAMDProcessor(); 00178 bool AnalyzeUnknownProcessor(); 00179 bool CheckCPUIDPresence(); 00180 void DecodeProcessorConfiguration(unsigned int cfg); 00181 void TranslateProcessorConfiguration(); 00182 void GetStandardProcessorConfiguration(); 00183 void GetStandardProcessorExtensions(); 00184 00185 // Public functions: 00187 public: 00188 F64 GetCPUFrequency(unsigned int uiMeasureMSecs); 00189 const ProcessorInfo *GetCPUInfo(); 00190 bool CPUInfoToText(char *strBuffer, unsigned int uiMaxLen); 00191 bool WriteInfoTextFile(const char *strFilename); 00192 }; 00193 00194 00195 #endif