llprocessor.h
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:5k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llprocessor.h
  3.  * @brief Code to figure out the processor. Originally by Benjamin Jurke.
  4.  *
  5.  * $LicenseInfo:firstyear=2002&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2002-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. // Author: Benjamin Jurke
  33. // File history: 27.02.2002   File created.
  34. ///////////////////////////////////////////
  35. #ifndef LLPROCESSOR_H
  36. #define LLPROCESSOR_H
  37. // Options:
  38. ///////////
  39. #if LL_WINDOWS
  40. #define PROCESSOR_FREQUENCY_MEASURE_AVAILABLE
  41. #endif
  42. #if LL_MSVC && _M_X64
  43. #      define LL_X86_64 1
  44. #      define LL_X86 1
  45. #elif LL_MSVC && _M_IX86
  46. #      define LL_X86 1
  47. #elif LL_GNUC && ( defined(__amd64__) || defined(__x86_64__) )
  48. #      define LL_X86_64 1
  49. #      define LL_X86 1
  50. #elif LL_GNUC && ( defined(__i386__) )
  51. #      define LL_X86 1
  52. #elif LL_GNUC && ( defined(__powerpc__) || defined(__ppc__) )
  53. #      define LL_PPC 1
  54. #endif
  55. struct ProcessorExtensions
  56. {
  57. bool FPU_FloatingPointUnit;
  58. bool VME_Virtual8086ModeEnhancements;
  59. bool DE_DebuggingExtensions;
  60. bool PSE_PageSizeExtensions;
  61. bool TSC_TimeStampCounter;
  62. bool MSR_ModelSpecificRegisters;
  63. bool PAE_PhysicalAddressExtension;
  64. bool MCE_MachineCheckException;
  65. bool CX8_COMPXCHG8B_Instruction;
  66. bool APIC_AdvancedProgrammableInterruptController;
  67. unsigned int APIC_ID;
  68. bool SEP_FastSystemCall;
  69. bool MTRR_MemoryTypeRangeRegisters;
  70. bool PGE_PTE_GlobalFlag;
  71. bool MCA_MachineCheckArchitecture;
  72. bool CMOV_ConditionalMoveAndCompareInstructions;
  73. bool FGPAT_PageAttributeTable;
  74. bool PSE36_36bitPageSizeExtension;
  75. bool PN_ProcessorSerialNumber;
  76. bool CLFSH_CFLUSH_Instruction;
  77. unsigned int CLFLUSH_InstructionCacheLineSize;
  78. bool DS_DebugStore;
  79. bool ACPI_ThermalMonitorAndClockControl;
  80. bool EMMX_MultimediaExtensions;
  81. bool MMX_MultimediaExtensions;
  82. bool FXSR_FastStreamingSIMD_ExtensionsSaveRestore;
  83. bool SSE_StreamingSIMD_Extensions;
  84. bool SSE2_StreamingSIMD2_Extensions;
  85. bool Altivec_Extensions;
  86. bool SS_SelfSnoop;
  87. bool HT_HyperThreading;
  88. unsigned int HT_HyterThreadingSiblings;
  89. bool TM_ThermalMonitor;
  90. bool IA64_Intel64BitArchitecture;
  91. bool _3DNOW_InstructionExtensions;
  92. bool _E3DNOW_InstructionExtensions;
  93. bool AA64_AMD64BitArchitecture;
  94. };
  95. struct ProcessorCache
  96. {
  97. bool bPresent;
  98. char strSize[32]; /* Flawfinder: ignore */
  99. unsigned int uiAssociativeWays;
  100. unsigned int uiLineSize;
  101. bool bSectored;
  102. char strCache[128]; /* Flawfinder: ignore */
  103. };
  104. struct ProcessorL1Cache
  105. {
  106.     ProcessorCache Instruction;
  107. ProcessorCache Data;
  108. };
  109. struct ProcessorTLB
  110. {
  111. bool bPresent;
  112. char strPageSize[32]; /* Flawfinder: ignore */
  113. unsigned int uiAssociativeWays;
  114. unsigned int uiEntries;
  115. char strTLB[128]; /* Flawfinder: ignore */
  116. };
  117. struct ProcessorInfo
  118. {
  119. char strVendor[16]; /* Flawfinder: ignore */
  120. unsigned int uiFamily;
  121. unsigned int uiExtendedFamily;
  122. char strFamily[64]; /* Flawfinder: ignore */
  123. unsigned int uiModel;
  124. unsigned int uiExtendedModel;
  125. char strModel[128]; /* Flawfinder: ignore */
  126. unsigned int uiStepping;
  127. unsigned int uiType;
  128. char strType[64]; /* Flawfinder: ignore */
  129. unsigned int uiBrandID;
  130. char strBrandID[64]; /* Flawfinder: ignore */
  131. char strProcessorSerial[64]; /* Flawfinder: ignore */
  132. unsigned long MaxSupportedLevel;
  133. unsigned long MaxSupportedExtendedLevel;
  134. ProcessorExtensions _Ext;
  135. ProcessorL1Cache _L1;
  136. ProcessorCache _L2;
  137. ProcessorCache _L3;
  138. ProcessorCache _Trace;
  139. ProcessorTLB _Instruction;
  140. ProcessorTLB _Data;
  141. };
  142. // CProcessor
  143. // ==========
  144. // Class for detecting the processor name, type and available
  145. // extensions as long as it's speed.
  146. /////////////////////////////////////////////////////////////
  147. class CProcessor
  148. {
  149. // Constructor / Destructor:
  150. ////////////////////////////
  151. public:
  152. CProcessor();
  153. // Private vars:
  154. ////////////////
  155. public:
  156. F64 uqwFrequency;
  157. char strCPUName[128]; /* Flawfinder: ignore */
  158. ProcessorInfo CPUInfo;
  159. // Private functions:
  160. /////////////////////
  161. private:
  162. bool AnalyzeIntelProcessor();
  163. bool AnalyzeAMDProcessor();
  164. bool AnalyzeUnknownProcessor();
  165. bool CheckCPUIDPresence();
  166. void DecodeProcessorConfiguration(unsigned int cfg);
  167. void TranslateProcessorConfiguration();
  168. void GetStandardProcessorConfiguration();
  169. void GetStandardProcessorExtensions();
  170. // Public functions:
  171. ////////////////////
  172. public:
  173. F64 GetCPUFrequency(unsigned int uiMeasureMSecs);
  174. const ProcessorInfo *GetCPUInfo();
  175. bool CPUInfoToText(char *strBuffer, unsigned int uiMaxLen);
  176. bool WriteInfoTextFile(const std::string& strFilename);
  177. };
  178. #endif