SystemInformation.cxx 102 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383
  1. /*=========================================================================
  2. Program: BatchMake
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2005 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifdef _WIN32
  14. # include <winsock.h> // WSADATA, include before sys/types.h
  15. #endif
  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.
  27. #if 0
  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"
  37. #endif
  38. #ifndef WIN32
  39. # include <sys/utsname.h> // int uname(struct utsname *buf);
  40. #endif
  41. #ifdef _WIN32
  42. # include <windows.h>
  43. #endif
  44. #ifdef __APPLE__
  45. #include <sys/sysctl.h>
  46. #include <mach/vm_statistics.h>
  47. #include <mach/host_info.h>
  48. #include <mach/mach.h>
  49. #include <mach/mach_types.h>
  50. #endif
  51. #ifdef __linux
  52. # include <sys/procfs.h>
  53. # include <sys/types.h>
  54. # include <unistd.h>
  55. # include <fcntl.h>
  56. # include <ctype.h> // int isdigit(int c);
  57. # include <errno.h> // extern int errno;
  58. # include <sys/time.h>
  59. #elif __hpux
  60. # include <sys/param.h>
  61. # include <sys/pstat.h>
  62. #endif
  63. #ifdef __HAIKU__
  64. #include <OS.h>
  65. #endif
  66. #include <memory.h>
  67. #include <stdlib.h>
  68. #include <stdio.h>
  69. #include <string.h>
  70. namespace KWSYS_NAMESPACE
  71. {
  72. // Create longlong
  73. #if KWSYS_USE_LONG_LONG
  74. typedef long long LongLong;
  75. #elif KWSYS_USE___INT64
  76. typedef __int64 LongLong;
  77. #else
  78. # error "No Long Long"
  79. #endif
  80. // Define SystemInformationImplementation class
  81. typedef void (*DELAY_FUNC)(unsigned int uiMS);
  82. class SystemInformationImplementation
  83. {
  84. public:
  85. SystemInformationImplementation ();
  86. ~SystemInformationImplementation ();
  87. const char * GetVendorString();
  88. const char * GetVendorID();
  89. kwsys_stl::string GetTypeID();
  90. kwsys_stl::string GetFamilyID();
  91. kwsys_stl::string GetModelID();
  92. kwsys_stl::string GetSteppingCode();
  93. const char * GetExtendedProcessorName();
  94. const char * GetProcessorSerialNumber();
  95. int GetProcessorCacheSize();
  96. unsigned int GetLogicalProcessorsPerPhysical();
  97. float GetProcessorClockFrequency();
  98. int GetProcessorAPICID();
  99. int GetProcessorCacheXSize(long int);
  100. bool DoesCPUSupportFeature(long int);
  101. const char * GetOSName();
  102. const char * GetHostname();
  103. const char * GetOSRelease();
  104. const char * GetOSVersion();
  105. const char * GetOSPlatform();
  106. bool Is64Bits();
  107. unsigned int GetNumberOfLogicalCPU(); // per physical cpu
  108. unsigned int GetNumberOfPhysicalCPU();
  109. bool DoesCPUSupportCPUID();
  110. // Retrieve memory information in megabyte.
  111. unsigned long GetTotalVirtualMemory();
  112. unsigned long GetAvailableVirtualMemory();
  113. unsigned long GetTotalPhysicalMemory();
  114. unsigned long GetAvailablePhysicalMemory();
  115. /** Run the different checks */
  116. void RunCPUCheck();
  117. void RunOSCheck();
  118. void RunMemoryCheck();
  119. public:
  120. #define VENDOR_STRING_LENGTH (12 + 1)
  121. #define CHIPNAME_STRING_LENGTH (48 + 1)
  122. #define SERIALNUMBER_STRING_LENGTH (29 + 1)
  123. typedef struct tagID
  124. {
  125. int Type;
  126. int Family;
  127. int Model;
  128. int Revision;
  129. int ExtendedFamily;
  130. int ExtendedModel;
  131. char ProcessorName[CHIPNAME_STRING_LENGTH];
  132. char Vendor[VENDOR_STRING_LENGTH];
  133. char SerialNumber[SERIALNUMBER_STRING_LENGTH];
  134. } ID;
  135. typedef struct tagCPUPowerManagement
  136. {
  137. bool HasVoltageID;
  138. bool HasFrequencyID;
  139. bool HasTempSenseDiode;
  140. } CPUPowerManagement;
  141. typedef struct tagCPUExtendedFeatures
  142. {
  143. bool Has3DNow;
  144. bool Has3DNowPlus;
  145. bool SupportsMP;
  146. bool HasMMXPlus;
  147. bool HasSSEMMX;
  148. bool SupportsHyperthreading;
  149. unsigned int LogicalProcessorsPerPhysical;
  150. int APIC_ID;
  151. CPUPowerManagement PowerManagement;
  152. } CPUExtendedFeatures;
  153. typedef struct CPUtagFeatures
  154. {
  155. bool HasFPU;
  156. bool HasTSC;
  157. bool HasMMX;
  158. bool HasSSE;
  159. bool HasSSEFP;
  160. bool HasSSE2;
  161. bool HasIA64;
  162. bool HasAPIC;
  163. bool HasCMOV;
  164. bool HasMTRR;
  165. bool HasACPI;
  166. bool HasSerial;
  167. bool HasThermal;
  168. int CPUSpeed;
  169. int L1CacheSize;
  170. int L2CacheSize;
  171. int L3CacheSize;
  172. CPUExtendedFeatures ExtendedFeatures;
  173. } CPUFeatures;
  174. enum Manufacturer
  175. {
  176. AMD, Intel, NSC, UMC, Cyrix, NexGen, IDT, Rise, Transmeta, Sun, IBM, Motorola, UnknownManufacturer
  177. };
  178. protected:
  179. // Functions.
  180. bool RetrieveCPUFeatures();
  181. bool RetrieveCPUIdentity();
  182. bool RetrieveCPUCacheDetails();
  183. bool RetrieveClassicalCPUCacheDetails();
  184. bool RetrieveCPUClockSpeed();
  185. bool RetrieveClassicalCPUClockSpeed();
  186. bool RetrieveCPUExtendedLevelSupport(int);
  187. bool RetrieveExtendedCPUFeatures();
  188. bool RetrieveProcessorSerialNumber();
  189. bool RetrieveCPUPowerManagement();
  190. bool RetrieveClassicalCPUIdentity();
  191. bool RetrieveExtendedCPUIdentity();
  192. Manufacturer ChipManufacturer;
  193. CPUFeatures Features;
  194. ID ChipID;
  195. float CPUSpeedInMHz;
  196. unsigned int NumberOfLogicalCPU;
  197. unsigned int NumberOfPhysicalCPU;
  198. int CPUCount();
  199. unsigned char LogicalCPUPerPhysicalCPU();
  200. unsigned char GetAPICId();
  201. unsigned int IsHyperThreadingSupported();
  202. LongLong GetCyclesDifference(DELAY_FUNC, unsigned int);
  203. // For Linux and Cygwin, /proc/cpuinfo formats are slightly different
  204. int RetreiveInformationFromCpuInfoFile();
  205. kwsys_stl::string ExtractValueFromCpuInfoFile(kwsys_stl::string buffer,
  206. const char* word, size_t init=0);
  207. static void Delay (unsigned int);
  208. static void DelayOverhead (unsigned int);
  209. void FindManufacturer();
  210. // For Mac
  211. bool ParseSysCtl();
  212. kwsys_stl::string ExtractValueFromSysCtl(const char* word);
  213. kwsys_stl::string SysCtlBuffer;
  214. // For Solaris
  215. bool QuerySolarisInfo();
  216. kwsys_stl::string ParseValueFromKStat(const char* arguments);
  217. kwsys_stl::string RunProcess(kwsys_stl::vector<const char*> args);
  218. //For Haiku OS
  219. bool QueryHaikuInfo();
  220. // Evaluate the memory information.
  221. int QueryMemory();
  222. unsigned long TotalVirtualMemory;
  223. unsigned long AvailableVirtualMemory;
  224. unsigned long TotalPhysicalMemory;
  225. unsigned long AvailablePhysicalMemory;
  226. size_t CurrentPositionInFile;
  227. // Operating System information
  228. bool QueryOSInformation();
  229. kwsys_stl::string OSName;
  230. kwsys_stl::string Hostname;
  231. kwsys_stl::string OSRelease;
  232. kwsys_stl::string OSVersion;
  233. kwsys_stl::string OSPlatform;
  234. };
  235. SystemInformation::SystemInformation()
  236. {
  237. this->Implementation = new SystemInformationImplementation;
  238. }
  239. SystemInformation::~SystemInformation ()
  240. {
  241. delete this->Implementation;
  242. }
  243. const char * SystemInformation::GetVendorString()
  244. {
  245. return this->Implementation->GetVendorString();
  246. }
  247. const char * SystemInformation::GetVendorID()
  248. {
  249. return this->Implementation->GetVendorID();
  250. }
  251. kwsys_stl::string SystemInformation::GetTypeID()
  252. {
  253. return this->Implementation->GetTypeID();
  254. }
  255. kwsys_stl::string SystemInformation::GetFamilyID()
  256. {
  257. return this->Implementation->GetFamilyID();
  258. }
  259. kwsys_stl::string SystemInformation::GetModelID()
  260. {
  261. return this->Implementation->GetModelID();
  262. }
  263. kwsys_stl::string SystemInformation::GetSteppingCode()
  264. {
  265. return this->Implementation->GetSteppingCode();
  266. }
  267. const char * SystemInformation::GetExtendedProcessorName()
  268. {
  269. return this->Implementation->GetExtendedProcessorName();
  270. }
  271. const char * SystemInformation::GetProcessorSerialNumber()
  272. {
  273. return this->Implementation->GetProcessorSerialNumber();
  274. }
  275. int SystemInformation::GetProcessorCacheSize()
  276. {
  277. return this->Implementation->GetProcessorCacheSize();
  278. }
  279. unsigned int SystemInformation::GetLogicalProcessorsPerPhysical()
  280. {
  281. return this->Implementation->GetLogicalProcessorsPerPhysical();
  282. }
  283. float SystemInformation::GetProcessorClockFrequency()
  284. {
  285. return this->Implementation->GetProcessorClockFrequency();
  286. }
  287. int SystemInformation::GetProcessorAPICID()
  288. {
  289. return this->Implementation->GetProcessorAPICID();
  290. }
  291. int SystemInformation::GetProcessorCacheXSize(long int l)
  292. {
  293. return this->Implementation->GetProcessorCacheXSize(l);
  294. }
  295. bool SystemInformation::DoesCPUSupportFeature(long int i)
  296. {
  297. return this->Implementation->DoesCPUSupportFeature(i);
  298. }
  299. const char * SystemInformation::GetOSName()
  300. {
  301. return this->Implementation->GetOSName();
  302. }
  303. const char * SystemInformation::GetHostname()
  304. {
  305. return this->Implementation->GetHostname();
  306. }
  307. const char * SystemInformation::GetOSRelease()
  308. {
  309. return this->Implementation->GetOSRelease();
  310. }
  311. const char * SystemInformation::GetOSVersion()
  312. {
  313. return this->Implementation->GetOSVersion();
  314. }
  315. const char * SystemInformation::GetOSPlatform()
  316. {
  317. return this->Implementation->GetOSPlatform();
  318. }
  319. bool SystemInformation::Is64Bits()
  320. {
  321. return this->Implementation->Is64Bits();
  322. }
  323. unsigned int SystemInformation::GetNumberOfLogicalCPU() // per physical cpu
  324. {
  325. return this->Implementation->GetNumberOfLogicalCPU();
  326. }
  327. unsigned int SystemInformation::GetNumberOfPhysicalCPU()
  328. {
  329. return this->Implementation->GetNumberOfPhysicalCPU();
  330. }
  331. bool SystemInformation::DoesCPUSupportCPUID()
  332. {
  333. return this->Implementation->DoesCPUSupportCPUID();
  334. }
  335. // Retrieve memory information in megabyte.
  336. unsigned long SystemInformation::GetTotalVirtualMemory()
  337. {
  338. return this->Implementation->GetTotalVirtualMemory();
  339. }
  340. unsigned long SystemInformation::GetAvailableVirtualMemory()
  341. {
  342. return this->Implementation->GetAvailableVirtualMemory();
  343. }
  344. unsigned long SystemInformation::GetTotalPhysicalMemory()
  345. {
  346. return this->Implementation->GetTotalPhysicalMemory();
  347. }
  348. unsigned long SystemInformation::GetAvailablePhysicalMemory()
  349. {
  350. return this->Implementation->GetAvailablePhysicalMemory();
  351. }
  352. /** Run the different checks */
  353. void SystemInformation::RunCPUCheck()
  354. {
  355. this->Implementation->RunCPUCheck();
  356. }
  357. void SystemInformation::RunOSCheck()
  358. {
  359. this->Implementation->RunOSCheck();
  360. }
  361. void SystemInformation::RunMemoryCheck()
  362. {
  363. this->Implementation->RunMemoryCheck();
  364. }
  365. // --------------------------------------------------------------
  366. // SystemInformationImplementation starts here
  367. #if defined(_MSC_VER) && (_MSC_VER >= 1300) && !defined(_WIN64)
  368. #define USE_ASM_INSTRUCTIONS 1
  369. #else
  370. #define USE_ASM_INSTRUCTIONS 0
  371. #endif
  372. #define STORE_TLBCACHE_INFO(x,y) x = (x < y) ? y : x
  373. #define TLBCACHE_INFO_UNITS (15)
  374. #define CLASSICAL_CPU_FREQ_LOOP 10000000
  375. #define RDTSC_INSTRUCTION _asm _emit 0x0f _asm _emit 0x31
  376. #define CPUID_AWARE_COMPILER
  377. #ifdef CPUID_AWARE_COMPILER
  378. #define CPUID_INSTRUCTION cpuid
  379. #else
  380. #define CPUID_INSTRUCTION _asm _emit 0x0f _asm _emit 0xa2
  381. #endif
  382. #define MMX_FEATURE 0x00000001
  383. #define MMX_PLUS_FEATURE 0x00000002
  384. #define SSE_FEATURE 0x00000004
  385. #define SSE2_FEATURE 0x00000008
  386. #define AMD_3DNOW_FEATURE 0x00000010
  387. #define AMD_3DNOW_PLUS_FEATURE 0x00000020
  388. #define IA64_FEATURE 0x00000040
  389. #define MP_CAPABLE 0x00000080
  390. #define HYPERTHREAD_FEATURE 0x00000100
  391. #define SERIALNUMBER_FEATURE 0x00000200
  392. #define APIC_FEATURE 0x00000400
  393. #define SSE_FP_FEATURE 0x00000800
  394. #define SSE_MMX_FEATURE 0x00001000
  395. #define CMOV_FEATURE 0x00002000
  396. #define MTRR_FEATURE 0x00004000
  397. #define L1CACHE_FEATURE 0x00008000
  398. #define L2CACHE_FEATURE 0x00010000
  399. #define L3CACHE_FEATURE 0x00020000
  400. #define ACPI_FEATURE 0x00040000
  401. #define THERMALMONITOR_FEATURE 0x00080000
  402. #define TEMPSENSEDIODE_FEATURE 0x00100000
  403. #define FREQUENCYID_FEATURE 0x00200000
  404. #define VOLTAGEID_FREQUENCY 0x00400000
  405. // Status Flag
  406. #define HT_NOT_CAPABLE 0
  407. #define HT_ENABLED 1
  408. #define HT_DISABLED 2
  409. #define HT_SUPPORTED_NOT_ENABLED 3
  410. #define HT_CANNOT_DETECT 4
  411. // EDX[28] Bit 28 is set if HT is supported
  412. #define HT_BIT 0x10000000
  413. // EAX[11:8] Bit 8-11 contains family processor ID.
  414. #define FAMILY_ID 0x0F00
  415. #define PENTIUM4_ID 0x0F00
  416. // EAX[23:20] Bit 20-23 contains extended family processor ID
  417. #define EXT_FAMILY_ID 0x0F00000
  418. // EBX[23:16] Bit 16-23 in ebx contains the number of logical
  419. #define NUM_LOGICAL_BITS 0x00FF0000
  420. // processors per physical processor when execute cpuid with
  421. // eax set to 1
  422. // EBX[31:24] Bits 24-31 (8 bits) return the 8-bit unique
  423. #define INITIAL_APIC_ID_BITS 0xFF000000
  424. // initial APIC ID for the processor this code is running on.
  425. // Default value = 0xff if HT is not supported
  426. SystemInformationImplementation::SystemInformationImplementation()
  427. {
  428. this->TotalVirtualMemory = 0;
  429. this->AvailableVirtualMemory = 0;
  430. this->TotalPhysicalMemory = 0;
  431. this->AvailablePhysicalMemory = 0;
  432. this->CurrentPositionInFile = 0;
  433. this->ChipManufacturer = UnknownManufacturer;
  434. memset(&this->Features, 0, sizeof(CPUFeatures));
  435. memset(&this->ChipID, 0, sizeof(ID));
  436. this->CPUSpeedInMHz = 0;
  437. this->NumberOfLogicalCPU = 0;
  438. this->NumberOfPhysicalCPU = 0;
  439. this->OSName = "";
  440. this->Hostname = "";
  441. this->OSRelease = "";
  442. this->OSVersion = "";
  443. this->OSPlatform = "";
  444. }
  445. SystemInformationImplementation::~SystemInformationImplementation()
  446. {
  447. }
  448. void SystemInformationImplementation::RunCPUCheck()
  449. {
  450. #ifdef WIN32
  451. // Check to see if this processor supports CPUID.
  452. if (DoesCPUSupportCPUID())
  453. {
  454. // Retrieve the CPU details.
  455. RetrieveCPUIdentity();
  456. RetrieveCPUFeatures();
  457. if (!RetrieveCPUClockSpeed())
  458. {
  459. RetrieveClassicalCPUClockSpeed();
  460. }
  461. // Attempt to retrieve cache information.
  462. if (!RetrieveCPUCacheDetails())
  463. {
  464. RetrieveClassicalCPUCacheDetails();
  465. }
  466. // Retrieve the extended CPU details.
  467. if (!RetrieveExtendedCPUIdentity())
  468. {
  469. RetrieveClassicalCPUIdentity();
  470. }
  471. RetrieveExtendedCPUFeatures();
  472. // Now attempt to retrieve the serial number (if possible).
  473. RetrieveProcessorSerialNumber();
  474. }
  475. this->CPUCount();
  476. #elif defined(__APPLE__)
  477. this->ParseSysCtl();
  478. #elif defined (__SVR4) && defined (__sun)
  479. this->QuerySolarisInfo();
  480. #elif defined(__HAIKU__)
  481. this->QueryHaikuInfo();
  482. #else
  483. this->RetreiveInformationFromCpuInfoFile();
  484. #endif
  485. }
  486. void SystemInformationImplementation::RunOSCheck()
  487. {
  488. this->QueryOSInformation();
  489. }
  490. void SystemInformationImplementation::RunMemoryCheck()
  491. {
  492. #if defined(__APPLE__)
  493. this->ParseSysCtl();
  494. #elif defined (__SVR4) && defined (__sun)
  495. this->QuerySolarisInfo();
  496. #elif defined(__HAIKU__)
  497. this->QueryHaikuInfo();
  498. #else
  499. this->QueryMemory();
  500. #endif
  501. }
  502. /** Get the vendor string */
  503. const char * SystemInformationImplementation::GetVendorString()
  504. {
  505. return this->ChipID.Vendor;
  506. }
  507. /** Get the OS Name */
  508. const char * SystemInformationImplementation::GetOSName()
  509. {
  510. return this->OSName.c_str();
  511. }
  512. /** Get the hostname */
  513. const char* SystemInformationImplementation::GetHostname()
  514. {
  515. return this->Hostname.c_str();
  516. }
  517. /** Get the OS release */
  518. const char* SystemInformationImplementation::GetOSRelease()
  519. {
  520. return this->OSRelease.c_str();
  521. }
  522. /** Get the OS version */
  523. const char* SystemInformationImplementation::GetOSVersion()
  524. {
  525. return this->OSVersion.c_str();
  526. }
  527. /** Get the OS platform */
  528. const char* SystemInformationImplementation::GetOSPlatform()
  529. {
  530. return this->OSPlatform.c_str();
  531. }
  532. /** Get the vendor ID */
  533. const char * SystemInformationImplementation::GetVendorID()
  534. {
  535. // Return the vendor ID.
  536. switch (this->ChipManufacturer)
  537. {
  538. case Intel:
  539. return "Intel Corporation";
  540. case AMD:
  541. return "Advanced Micro Devices";
  542. case NSC:
  543. return "National Semiconductor";
  544. case Cyrix:
  545. return "Cyrix Corp., VIA Inc.";
  546. case NexGen:
  547. return "NexGen Inc., Advanced Micro Devices";
  548. case IDT:
  549. return "IDT\\Centaur, Via Inc.";
  550. case UMC:
  551. return "United Microelectronics Corp.";
  552. case Rise:
  553. return "Rise";
  554. case Transmeta:
  555. return "Transmeta";
  556. case Sun:
  557. return "Sun Microelectronics";
  558. case IBM:
  559. return "IBM";
  560. case Motorola:
  561. return "Motorola";
  562. default:
  563. return "Unknown Manufacturer";
  564. }
  565. }
  566. /** Return the type ID of the CPU */
  567. kwsys_stl::string SystemInformationImplementation::GetTypeID()
  568. {
  569. kwsys_ios::ostringstream str;
  570. str << this->ChipID.Type;
  571. return str.str();
  572. }
  573. /** Return the family of the CPU present */
  574. kwsys_stl::string SystemInformationImplementation::GetFamilyID()
  575. {
  576. kwsys_ios::ostringstream str;
  577. str << this->ChipID.Family;
  578. return str.str();
  579. }
  580. // Return the model of CPU present */
  581. kwsys_stl::string SystemInformationImplementation::GetModelID()
  582. {
  583. kwsys_ios::ostringstream str;
  584. str << this->ChipID.Model;
  585. return str.str();
  586. }
  587. /** Return the stepping code of the CPU present. */
  588. kwsys_stl::string SystemInformationImplementation::GetSteppingCode()
  589. {
  590. kwsys_ios::ostringstream str;
  591. str << this->ChipID.Revision;
  592. return str.str();
  593. }
  594. /** Return the stepping code of the CPU present. */
  595. const char * SystemInformationImplementation::GetExtendedProcessorName()
  596. {
  597. return this->ChipID.ProcessorName;
  598. }
  599. /** Return the serial number of the processor
  600. * in hexadecimal: xxxx-xxxx-xxxx-xxxx-xxxx-xxxx. */
  601. const char * SystemInformationImplementation::GetProcessorSerialNumber()
  602. {
  603. return this->ChipID.SerialNumber;
  604. }
  605. /** Return the logical processors per physical */
  606. unsigned int SystemInformationImplementation::GetLogicalProcessorsPerPhysical()
  607. {
  608. return this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical;
  609. }
  610. /** Return the processor clock frequency. */
  611. float SystemInformationImplementation::GetProcessorClockFrequency()
  612. {
  613. return this->CPUSpeedInMHz;
  614. }
  615. /** Return the APIC ID. */
  616. int SystemInformationImplementation::GetProcessorAPICID()
  617. {
  618. return this->Features.ExtendedFeatures.APIC_ID;
  619. }
  620. /** Return the L1 cache size. */
  621. int SystemInformationImplementation::GetProcessorCacheSize()
  622. {
  623. return this->Features.L1CacheSize;
  624. }
  625. /** Return the chosen cache size. */
  626. int SystemInformationImplementation::GetProcessorCacheXSize(long int dwCacheID)
  627. {
  628. switch (dwCacheID)
  629. {
  630. case L1CACHE_FEATURE:
  631. return this->Features.L1CacheSize;
  632. case L2CACHE_FEATURE:
  633. return this->Features.L2CacheSize;
  634. case L3CACHE_FEATURE:
  635. return this->Features.L3CacheSize;
  636. }
  637. return -1;
  638. }
  639. bool SystemInformationImplementation::DoesCPUSupportFeature(long int dwFeature)
  640. {
  641. bool bHasFeature = false;
  642. // Check for MMX instructions.
  643. if (((dwFeature & MMX_FEATURE) != 0) && this->Features.HasMMX) bHasFeature = true;
  644. // Check for MMX+ instructions.
  645. if (((dwFeature & MMX_PLUS_FEATURE) != 0) && this->Features.ExtendedFeatures.HasMMXPlus) bHasFeature = true;
  646. // Check for SSE FP instructions.
  647. if (((dwFeature & SSE_FEATURE) != 0) && this->Features.HasSSE) bHasFeature = true;
  648. // Check for SSE FP instructions.
  649. if (((dwFeature & SSE_FP_FEATURE) != 0) && this->Features.HasSSEFP) bHasFeature = true;
  650. // Check for SSE MMX instructions.
  651. if (((dwFeature & SSE_MMX_FEATURE) != 0) && this->Features.ExtendedFeatures.HasSSEMMX) bHasFeature = true;
  652. // Check for SSE2 instructions.
  653. if (((dwFeature & SSE2_FEATURE) != 0) && this->Features.HasSSE2) bHasFeature = true;
  654. // Check for 3DNow! instructions.
  655. if (((dwFeature & AMD_3DNOW_FEATURE) != 0) && this->Features.ExtendedFeatures.Has3DNow) bHasFeature = true;
  656. // Check for 3DNow+ instructions.
  657. if (((dwFeature & AMD_3DNOW_PLUS_FEATURE) != 0) && this->Features.ExtendedFeatures.Has3DNowPlus) bHasFeature = true;
  658. // Check for IA64 instructions.
  659. if (((dwFeature & IA64_FEATURE) != 0) && this->Features.HasIA64) bHasFeature = true;
  660. // Check for MP capable.
  661. if (((dwFeature & MP_CAPABLE) != 0) && this->Features.ExtendedFeatures.SupportsMP) bHasFeature = true;
  662. // Check for a serial number for the processor.
  663. if (((dwFeature & SERIALNUMBER_FEATURE) != 0) && this->Features.HasSerial) bHasFeature = true;
  664. // Check for a local APIC in the processor.
  665. if (((dwFeature & APIC_FEATURE) != 0) && this->Features.HasAPIC) bHasFeature = true;
  666. // Check for CMOV instructions.
  667. if (((dwFeature & CMOV_FEATURE) != 0) && this->Features.HasCMOV) bHasFeature = true;
  668. // Check for MTRR instructions.
  669. if (((dwFeature & MTRR_FEATURE) != 0) && this->Features.HasMTRR) bHasFeature = true;
  670. // Check for L1 cache size.
  671. if (((dwFeature & L1CACHE_FEATURE) != 0) && (this->Features.L1CacheSize != -1)) bHasFeature = true;
  672. // Check for L2 cache size.
  673. if (((dwFeature & L2CACHE_FEATURE) != 0) && (this->Features.L2CacheSize != -1)) bHasFeature = true;
  674. // Check for L3 cache size.
  675. if (((dwFeature & L3CACHE_FEATURE) != 0) && (this->Features.L3CacheSize != -1)) bHasFeature = true;
  676. // Check for ACPI capability.
  677. if (((dwFeature & ACPI_FEATURE) != 0) && this->Features.HasACPI) bHasFeature = true;
  678. // Check for thermal monitor support.
  679. if (((dwFeature & THERMALMONITOR_FEATURE) != 0) && this->Features.HasThermal) bHasFeature = true;
  680. // Check for temperature sensing diode support.
  681. if (((dwFeature & TEMPSENSEDIODE_FEATURE) != 0) && this->Features.ExtendedFeatures.PowerManagement.HasTempSenseDiode) bHasFeature = true;
  682. // Check for frequency ID support.
  683. if (((dwFeature & FREQUENCYID_FEATURE) != 0) && this->Features.ExtendedFeatures.PowerManagement.HasFrequencyID) bHasFeature = true;
  684. // Check for voltage ID support.
  685. if (((dwFeature & VOLTAGEID_FREQUENCY) != 0) && this->Features.ExtendedFeatures.PowerManagement.HasVoltageID) bHasFeature = true;
  686. return bHasFeature;
  687. }
  688. void SystemInformationImplementation::Delay(unsigned int uiMS)
  689. {
  690. #ifdef WIN32
  691. LARGE_INTEGER Frequency, StartCounter, EndCounter;
  692. __int64 x;
  693. // Get the frequency of the high performance counter.
  694. if (!QueryPerformanceFrequency (&Frequency)) return;
  695. x = Frequency.QuadPart / 1000 * uiMS;
  696. // Get the starting position of the counter.
  697. QueryPerformanceCounter (&StartCounter);
  698. do {
  699. // Get the ending position of the counter.
  700. QueryPerformanceCounter (&EndCounter);
  701. } while (EndCounter.QuadPart - StartCounter.QuadPart < x);
  702. #endif
  703. (void)uiMS;
  704. }
  705. bool SystemInformationImplementation::DoesCPUSupportCPUID()
  706. {
  707. #if USE_ASM_INSTRUCTIONS
  708. // Use SEH to determine CPUID presence
  709. __try {
  710. _asm {
  711. #ifdef CPUID_AWARE_COMPILER
  712. ; we must push/pop the registers <<CPUID>> writes to, as the
  713. ; optimiser doesn't know about <<CPUID>>, and so doesn't expect
  714. ; these registers to change.
  715. push eax
  716. push ebx
  717. push ecx
  718. push edx
  719. #endif
  720. ; <<CPUID>>
  721. mov eax, 0
  722. CPUID_INSTRUCTION
  723. #ifdef CPUID_AWARE_COMPILER
  724. pop edx
  725. pop ecx
  726. pop ebx
  727. pop eax
  728. #endif
  729. }
  730. }
  731. __except(1)
  732. {
  733. // Stop the class from trying to use CPUID again!
  734. return false;
  735. }
  736. // The cpuid instruction succeeded.
  737. return true;
  738. #else
  739. // Assume no cpuid instruction.
  740. return false;
  741. #endif
  742. }
  743. bool SystemInformationImplementation::RetrieveCPUFeatures()
  744. {
  745. #if USE_ASM_INSTRUCTIONS
  746. int localCPUFeatures = 0;
  747. int localCPUAdvanced = 0;
  748. // Use assembly to detect CPUID information...
  749. __try {
  750. _asm {
  751. #ifdef CPUID_AWARE_COMPILER
  752. ; we must push/pop the registers <<CPUID>> writes to, as the
  753. ; optimiser doesn't know about <<CPUID>>, and so doesn't expect
  754. ; these registers to change.
  755. push eax
  756. push ebx
  757. push ecx
  758. push edx
  759. #endif
  760. ; <<CPUID>>
  761. ; 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
  762. ; ebx: 31..24 - default APIC ID, 23..16 - logical processsor ID, 15..8 - CFLUSH chunk size , 7..0 - brand ID
  763. ; edx: CPU feature flags
  764. mov eax,1
  765. CPUID_INSTRUCTION
  766. mov localCPUFeatures, edx
  767. mov localCPUAdvanced, ebx
  768. #ifdef CPUID_AWARE_COMPILER
  769. pop edx
  770. pop ecx
  771. pop ebx
  772. pop eax
  773. #endif
  774. }
  775. }
  776. __except(1)
  777. {
  778. return false;
  779. }
  780. // Retrieve the features of CPU present.
  781. this->Features.HasFPU = ((localCPUFeatures & 0x00000001) != 0); // FPU Present --> Bit 0
  782. this->Features.HasTSC = ((localCPUFeatures & 0x00000010) != 0); // TSC Present --> Bit 4
  783. this->Features.HasAPIC = ((localCPUFeatures & 0x00000200) != 0); // APIC Present --> Bit 9
  784. this->Features.HasMTRR = ((localCPUFeatures & 0x00001000) != 0); // MTRR Present --> Bit 12
  785. this->Features.HasCMOV = ((localCPUFeatures & 0x00008000) != 0); // CMOV Present --> Bit 15
  786. this->Features.HasSerial = ((localCPUFeatures & 0x00040000) != 0); // Serial Present --> Bit 18
  787. this->Features.HasACPI = ((localCPUFeatures & 0x00400000) != 0); // ACPI Capable --> Bit 22
  788. this->Features.HasMMX = ((localCPUFeatures & 0x00800000) != 0); // MMX Present --> Bit 23
  789. this->Features.HasSSE = ((localCPUFeatures & 0x02000000) != 0); // SSE Present --> Bit 25
  790. this->Features.HasSSE2 = ((localCPUFeatures & 0x04000000) != 0); // SSE2 Present --> Bit 26
  791. this->Features.HasThermal = ((localCPUFeatures & 0x20000000) != 0); // Thermal Monitor Present --> Bit 29
  792. this->Features.HasIA64 = ((localCPUFeatures & 0x40000000) != 0); // IA64 Present --> Bit 30
  793. // Retrieve extended SSE capabilities if SSE is available.
  794. if (this->Features.HasSSE) {
  795. // Attempt to __try some SSE FP instructions.
  796. __try
  797. {
  798. // Perform: orps xmm0, xmm0
  799. _asm
  800. {
  801. _emit 0x0f
  802. _emit 0x56
  803. _emit 0xc0
  804. }
  805. // SSE FP capable processor.
  806. this->Features.HasSSEFP = true;
  807. }
  808. __except(1)
  809. {
  810. // bad instruction - processor or OS cannot handle SSE FP.
  811. this->Features.HasSSEFP = false;
  812. }
  813. }
  814. else
  815. {
  816. // Set the advanced SSE capabilities to not available.
  817. this->Features.HasSSEFP = false;
  818. }
  819. // Retrieve Intel specific extended features.
  820. if (this->ChipManufacturer == Intel)
  821. {
  822. this->Features.ExtendedFeatures.SupportsHyperthreading = ((localCPUFeatures & 0x10000000) != 0); // Intel specific: Hyperthreading --> Bit 28
  823. this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = (this->Features.ExtendedFeatures.SupportsHyperthreading) ? ((localCPUAdvanced & 0x00FF0000) >> 16) : 1;
  824. if ((this->Features.ExtendedFeatures.SupportsHyperthreading) && (this->Features.HasAPIC))
  825. {
  826. // Retrieve APIC information if there is one present.
  827. this->Features.ExtendedFeatures.APIC_ID = ((localCPUAdvanced & 0xFF000000) >> 24);
  828. }
  829. }
  830. #endif
  831. return true;
  832. }
  833. /** Find the manufacturer given the vendor id */
  834. void SystemInformationImplementation::FindManufacturer()
  835. {
  836. if (strcmp (this->ChipID.Vendor, "GenuineIntel") == 0) this->ChipManufacturer = Intel; // Intel Corp.
  837. else if (strcmp (this->ChipID.Vendor, "UMC UMC UMC ") == 0) this->ChipManufacturer = UMC; // United Microelectronics Corp.
  838. else if (strcmp (this->ChipID.Vendor, "AuthenticAMD") == 0) this->ChipManufacturer = AMD; // Advanced Micro Devices
  839. else if (strcmp (this->ChipID.Vendor, "AMD ISBETTER") == 0) this->ChipManufacturer = AMD; // Advanced Micro Devices (1994)
  840. else if (strcmp (this->ChipID.Vendor, "CyrixInstead") == 0) this->ChipManufacturer = Cyrix; // Cyrix Corp., VIA Inc.
  841. else if (strcmp (this->ChipID.Vendor, "NexGenDriven") == 0) this->ChipManufacturer = NexGen; // NexGen Inc. (now AMD)
  842. else if (strcmp (this->ChipID.Vendor, "CentaurHauls") == 0) this->ChipManufacturer = IDT; // IDT/Centaur (now VIA)
  843. else if (strcmp (this->ChipID.Vendor, "RiseRiseRise") == 0) this->ChipManufacturer = Rise; // Rise
  844. else if (strcmp (this->ChipID.Vendor, "GenuineTMx86") == 0) this->ChipManufacturer = Transmeta; // Transmeta
  845. else if (strcmp (this->ChipID.Vendor, "TransmetaCPU") == 0) this->ChipManufacturer = Transmeta; // Transmeta
  846. else if (strcmp (this->ChipID.Vendor, "Geode By NSC") == 0) this->ChipManufacturer = NSC; // National Semiconductor
  847. else if (strcmp (this->ChipID.Vendor, "Sun") == 0) this->ChipManufacturer = Sun; // Sun Microelectronics
  848. else if (strcmp (this->ChipID.Vendor, "IBM") == 0) this->ChipManufacturer = IBM; // IBM Microelectronics
  849. else if (strcmp (this->ChipID.Vendor, "Motorola") == 0) this->ChipManufacturer = Motorola; // Motorola Microelectronics
  850. else this->ChipManufacturer = UnknownManufacturer; // Unknown manufacturer
  851. }
  852. /** */
  853. bool SystemInformationImplementation::RetrieveCPUIdentity()
  854. {
  855. #if USE_ASM_INSTRUCTIONS
  856. int localCPUVendor[3];
  857. int localCPUSignature;
  858. // Use assembly to detect CPUID information...
  859. __try
  860. {
  861. _asm
  862. {
  863. #ifdef CPUID_AWARE_COMPILER
  864. ; we must push/pop the registers <<CPUID>> writes to, as the
  865. ; optimiser doesn't know about <<CPUID>>, and so doesn't expect
  866. ; these registers to change.
  867. push eax
  868. push ebx
  869. push ecx
  870. push edx
  871. #endif
  872. ; <<CPUID>>
  873. ; eax = 0 --> eax: maximum value of CPUID instruction.
  874. ; ebx: part 1 of 3; CPU signature.
  875. ; edx: part 2 of 3; CPU signature.
  876. ; ecx: part 3 of 3; CPU signature.
  877. mov eax, 0
  878. CPUID_INSTRUCTION
  879. mov localCPUVendor[0 * TYPE int], ebx
  880. mov localCPUVendor[1 * TYPE int], edx
  881. mov localCPUVendor[2 * TYPE int], ecx
  882. ; <<CPUID>>
  883. ; 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
  884. ; ebx: 31..24 - default APIC ID, 23..16 - logical processsor ID, 15..8 - CFLUSH chunk size , 7..0 - brand ID
  885. ; edx: CPU feature flags
  886. mov eax,1
  887. CPUID_INSTRUCTION
  888. mov localCPUSignature, eax
  889. #ifdef CPUID_AWARE_COMPILER
  890. pop edx
  891. pop ecx
  892. pop ebx
  893. pop eax
  894. #endif
  895. }
  896. }
  897. __except(1)
  898. {
  899. return false;
  900. }
  901. // Process the returned information.
  902. memcpy (this->ChipID.Vendor, &(localCPUVendor[0]), sizeof (int));
  903. memcpy (&(this->ChipID.Vendor[4]), &(localCPUVendor[1]), sizeof (int));
  904. memcpy (&(this->ChipID.Vendor[8]), &(localCPUVendor[2]), sizeof (int));
  905. this->ChipID.Vendor[12] = '\0';
  906. this->FindManufacturer();
  907. // Retrieve the family of CPU present.
  908. this->ChipID.ExtendedFamily = ((localCPUSignature & 0x0FF00000) >> 20); // Bits 27..20 Used
  909. this->ChipID.ExtendedModel = ((localCPUSignature & 0x000F0000) >> 16); // Bits 19..16 Used
  910. this->ChipID.Type = ((localCPUSignature & 0x0000F000) >> 12); // Bits 15..12 Used
  911. this->ChipID.Family = ((localCPUSignature & 0x00000F00) >> 8); // Bits 11..8 Used
  912. this->ChipID.Model = ((localCPUSignature & 0x000000F0) >> 4); // Bits 7..4 Used
  913. this->ChipID.Revision = ((localCPUSignature & 0x0000000F) >> 0); // Bits 3..0 Used
  914. #endif
  915. return true;
  916. }
  917. /** */
  918. bool SystemInformationImplementation::RetrieveCPUCacheDetails()
  919. {
  920. #if USE_ASM_INSTRUCTIONS
  921. int L1Cache[4] = { 0, 0, 0, 0 };
  922. int L2Cache[4] = { 0, 0, 0, 0 };
  923. // Check to see if what we are about to do is supported...
  924. if (RetrieveCPUExtendedLevelSupport (0x80000005))
  925. {
  926. // Use assembly to retrieve the L1 cache information ...
  927. __try
  928. {
  929. _asm
  930. {
  931. #ifdef CPUID_AWARE_COMPILER
  932. ; we must push/pop the registers <<CPUID>> writes to, as the
  933. ; optimiser doesn't know about <<CPUID>>, and so doesn't expect
  934. ; these registers to change.
  935. push eax
  936. push ebx
  937. push ecx
  938. push edx
  939. #endif
  940. ; <<CPUID>>
  941. ; eax = 0x80000005 --> eax: L1 cache information - Part 1 of 4.
  942. ; ebx: L1 cache information - Part 2 of 4.
  943. ; edx: L1 cache information - Part 3 of 4.
  944. ; ecx: L1 cache information - Part 4 of 4.
  945. mov eax, 0x80000005
  946. CPUID_INSTRUCTION
  947. mov L1Cache[0 * TYPE int], eax
  948. mov L1Cache[1 * TYPE int], ebx
  949. mov L1Cache[2 * TYPE int], ecx
  950. mov L1Cache[3 * TYPE int], edx
  951. #ifdef CPUID_AWARE_COMPILER
  952. pop edx
  953. pop ecx
  954. pop ebx
  955. pop eax
  956. #endif
  957. }
  958. }
  959. __except(1)
  960. {
  961. return false;
  962. }
  963. // Save the L1 data cache size (in KB) from ecx: bits 31..24 as well as data cache size from edx: bits 31..24.
  964. this->Features.L1CacheSize = ((L1Cache[2] & 0xFF000000) >> 24);
  965. this->Features.L1CacheSize += ((L1Cache[3] & 0xFF000000) >> 24);
  966. }
  967. else
  968. {
  969. // Store -1 to indicate the cache could not be queried.
  970. this->Features.L1CacheSize = -1;
  971. }
  972. // Check to see if what we are about to do is supported...
  973. if (RetrieveCPUExtendedLevelSupport (0x80000006))
  974. {
  975. // Use assembly to retrieve the L2 cache information ...
  976. __try
  977. {
  978. _asm
  979. {
  980. #ifdef CPUID_AWARE_COMPILER
  981. ; we must push/pop the registers <<CPUID>> writes to, as the
  982. ; optimiser doesn't know about <<CPUID>>, and so doesn't expect
  983. ; these registers to change.
  984. push eax
  985. push ebx
  986. push ecx
  987. push edx
  988. #endif
  989. ; <<CPUID>>
  990. ; eax = 0x80000006 --> eax: L2 cache information - Part 1 of 4.
  991. ; ebx: L2 cache information - Part 2 of 4.
  992. ; edx: L2 cache information - Part 3 of 4.
  993. ; ecx: L2 cache information - Part 4 of 4.
  994. mov eax, 0x80000006
  995. CPUID_INSTRUCTION
  996. mov L2Cache[0 * TYPE int], eax
  997. mov L2Cache[1 * TYPE int], ebx
  998. mov L2Cache[2 * TYPE int], ecx
  999. mov L2Cache[3 * TYPE int], edx
  1000. #ifdef CPUID_AWARE_COMPILER
  1001. pop edx
  1002. pop ecx
  1003. pop ebx
  1004. pop eax
  1005. #endif
  1006. }
  1007. }
  1008. __except(1)
  1009. {
  1010. return false;
  1011. }
  1012. // Save the L2 unified cache size (in KB) from ecx: bits 31..16.
  1013. this->Features.L2CacheSize = ((L2Cache[2] & 0xFFFF0000) >> 16);
  1014. }
  1015. else
  1016. {
  1017. // Store -1 to indicate the cache could not be queried.
  1018. this->Features.L2CacheSize = -1;
  1019. }
  1020. // Define L3 as being not present as we cannot test for it.
  1021. this->Features.L3CacheSize = -1;
  1022. #endif
  1023. // Return failure if we cannot detect either cache with this method.
  1024. return ((this->Features.L1CacheSize == -1) && (this->Features.L2CacheSize == -1)) ? false : true;
  1025. }
  1026. /** */
  1027. bool SystemInformationImplementation::RetrieveClassicalCPUCacheDetails()
  1028. {
  1029. #if USE_ASM_INSTRUCTIONS
  1030. int TLBCode = -1, TLBData = -1, L1Code = -1, L1Data = -1, L1Trace = -1, L2Unified = -1, L3Unified = -1;
  1031. int TLBCacheData[4] = { 0, 0, 0, 0 };
  1032. int TLBPassCounter = 0;
  1033. int TLBCacheUnit = 0;
  1034. do {
  1035. // Use assembly to retrieve the L2 cache information ...
  1036. __try {
  1037. _asm {
  1038. #ifdef CPUID_AWARE_COMPILER
  1039. ; we must push/pop the registers <<CPUID>> writes to, as the
  1040. ; optimiser doesn't know about <<CPUID>>, and so doesn't expect
  1041. ; these registers to change.
  1042. push eax
  1043. push ebx
  1044. push ecx
  1045. push edx
  1046. #endif
  1047. ; <<CPUID>>
  1048. ; eax = 2 --> eax: TLB and cache information - Part 1 of 4.
  1049. ; ebx: TLB and cache information - Part 2 of 4.
  1050. ; ecx: TLB and cache information - Part 3 of 4.
  1051. ; edx: TLB and cache information - Part 4 of 4.
  1052. mov eax, 2
  1053. CPUID_INSTRUCTION
  1054. mov TLBCacheData[0 * TYPE int], eax
  1055. mov TLBCacheData[1 * TYPE int], ebx
  1056. mov TLBCacheData[2 * TYPE int], ecx
  1057. mov TLBCacheData[3 * TYPE int], edx
  1058. #ifdef CPUID_AWARE_COMPILER
  1059. pop edx
  1060. pop ecx
  1061. pop ebx
  1062. pop eax
  1063. #endif
  1064. }
  1065. }
  1066. __except(1)
  1067. {
  1068. return false;
  1069. }
  1070. int bob = ((TLBCacheData[0] & 0x00FF0000) >> 16);
  1071. (void)bob;
  1072. // Process the returned TLB and cache information.
  1073. for (int nCounter = 0; nCounter < TLBCACHE_INFO_UNITS; nCounter ++)
  1074. {
  1075. // First of all - decide which unit we are dealing with.
  1076. switch (nCounter)
  1077. {
  1078. // eax: bits 8..15 : bits 16..23 : bits 24..31
  1079. case 0: TLBCacheUnit = ((TLBCacheData[0] & 0x0000FF00) >> 8); break;
  1080. case 1: TLBCacheUnit = ((TLBCacheData[0] & 0x00FF0000) >> 16); break;
  1081. case 2: TLBCacheUnit = ((TLBCacheData[0] & 0xFF000000) >> 24); break;
  1082. // ebx: bits 0..7 : bits 8..15 : bits 16..23 : bits 24..31
  1083. case 3: TLBCacheUnit = ((TLBCacheData[1] & 0x000000FF) >> 0); break;
  1084. case 4: TLBCacheUnit = ((TLBCacheData[1] & 0x0000FF00) >> 8); break;
  1085. case 5: TLBCacheUnit = ((TLBCacheData[1] & 0x00FF0000) >> 16); break;
  1086. case 6: TLBCacheUnit = ((TLBCacheData[1] & 0xFF000000) >> 24); break;
  1087. // ecx: bits 0..7 : bits 8..15 : bits 16..23 : bits 24..31
  1088. case 7: TLBCacheUnit = ((TLBCacheData[2] & 0x000000FF) >> 0); break;
  1089. case 8: TLBCacheUnit = ((TLBCacheData[2] & 0x0000FF00) >> 8); break;
  1090. case 9: TLBCacheUnit = ((TLBCacheData[2] & 0x00FF0000) >> 16); break;
  1091. case 10: TLBCacheUnit = ((TLBCacheData[2] & 0xFF000000) >> 24); break;
  1092. // edx: bits 0..7 : bits 8..15 : bits 16..23 : bits 24..31
  1093. case 11: TLBCacheUnit = ((TLBCacheData[3] & 0x000000FF) >> 0); break;
  1094. case 12: TLBCacheUnit = ((TLBCacheData[3] & 0x0000FF00) >> 8); break;
  1095. case 13: TLBCacheUnit = ((TLBCacheData[3] & 0x00FF0000) >> 16); break;
  1096. case 14: TLBCacheUnit = ((TLBCacheData[3] & 0xFF000000) >> 24); break;
  1097. // Default case - an error has occured.
  1098. default: return false;
  1099. }
  1100. // Now process the resulting unit to see what it means....
  1101. switch (TLBCacheUnit)
  1102. {
  1103. case 0x00: break;
  1104. case 0x01: STORE_TLBCACHE_INFO (TLBCode, 4); break;
  1105. case 0x02: STORE_TLBCACHE_INFO (TLBCode, 4096); break;
  1106. case 0x03: STORE_TLBCACHE_INFO (TLBData, 4); break;
  1107. case 0x04: STORE_TLBCACHE_INFO (TLBData, 4096); break;
  1108. case 0x06: STORE_TLBCACHE_INFO (L1Code, 8); break;
  1109. case 0x08: STORE_TLBCACHE_INFO (L1Code, 16); break;
  1110. case 0x0a: STORE_TLBCACHE_INFO (L1Data, 8); break;
  1111. case 0x0c: STORE_TLBCACHE_INFO (L1Data, 16); break;
  1112. case 0x10: STORE_TLBCACHE_INFO (L1Data, 16); break; // <-- FIXME: IA-64 Only
  1113. case 0x15: STORE_TLBCACHE_INFO (L1Code, 16); break; // <-- FIXME: IA-64 Only
  1114. case 0x1a: STORE_TLBCACHE_INFO (L2Unified, 96); break; // <-- FIXME: IA-64 Only
  1115. case 0x22: STORE_TLBCACHE_INFO (L3Unified, 512); break;
  1116. case 0x23: STORE_TLBCACHE_INFO (L3Unified, 1024); break;
  1117. case 0x25: STORE_TLBCACHE_INFO (L3Unified, 2048); break;
  1118. case 0x29: STORE_TLBCACHE_INFO (L3Unified, 4096); break;
  1119. case 0x39: STORE_TLBCACHE_INFO (L2Unified, 128); break;
  1120. case 0x3c: STORE_TLBCACHE_INFO (L2Unified, 256); break;
  1121. case 0x40: STORE_TLBCACHE_INFO (L2Unified, 0); break; // <-- FIXME: No integrated L2 cache (P6 core) or L3 cache (P4 core).
  1122. case 0x41: STORE_TLBCACHE_INFO (L2Unified, 128); break;
  1123. case 0x42: STORE_TLBCACHE_INFO (L2Unified, 256); break;
  1124. case 0x43: STORE_TLBCACHE_INFO (L2Unified, 512); break;
  1125. case 0x44: STORE_TLBCACHE_INFO (L2Unified, 1024); break;
  1126. case 0x45: STORE_TLBCACHE_INFO (L2Unified, 2048); break;
  1127. case 0x50: STORE_TLBCACHE_INFO (TLBCode, 4096); break;
  1128. case 0x51: STORE_TLBCACHE_INFO (TLBCode, 4096); break;
  1129. case 0x52: STORE_TLBCACHE_INFO (TLBCode, 4096); break;
  1130. case 0x5b: STORE_TLBCACHE_INFO (TLBData, 4096); break;
  1131. case 0x5c: STORE_TLBCACHE_INFO (TLBData, 4096); break;
  1132. case 0x5d: STORE_TLBCACHE_INFO (TLBData, 4096); break;
  1133. case 0x66: STORE_TLBCACHE_INFO (L1Data, 8); break;
  1134. case 0x67: STORE_TLBCACHE_INFO (L1Data, 16); break;
  1135. case 0x68: STORE_TLBCACHE_INFO (L1Data, 32); break;
  1136. case 0x70: STORE_TLBCACHE_INFO (L1Trace, 12); break;
  1137. case 0x71: STORE_TLBCACHE_INFO (L1Trace, 16); break;
  1138. case 0x72: STORE_TLBCACHE_INFO (L1Trace, 32); break;
  1139. case 0x77: STORE_TLBCACHE_INFO (L1Code, 16); break; // <-- FIXME: IA-64 Only
  1140. case 0x79: STORE_TLBCACHE_INFO (L2Unified, 128); break;
  1141. case 0x7a: STORE_TLBCACHE_INFO (L2Unified, 256); break;
  1142. case 0x7b: STORE_TLBCACHE_INFO (L2Unified, 512); break;
  1143. case 0x7c: STORE_TLBCACHE_INFO (L2Unified, 1024); break;
  1144. case 0x7e: STORE_TLBCACHE_INFO (L2Unified, 256); break;
  1145. case 0x81: STORE_TLBCACHE_INFO (L2Unified, 128); break;
  1146. case 0x82: STORE_TLBCACHE_INFO (L2Unified, 256); break;
  1147. case 0x83: STORE_TLBCACHE_INFO (L2Unified, 512); break;
  1148. case 0x84: STORE_TLBCACHE_INFO (L2Unified, 1024); break;
  1149. case 0x85: STORE_TLBCACHE_INFO (L2Unified, 2048); break;
  1150. case 0x88: STORE_TLBCACHE_INFO (L3Unified, 2048); break; // <-- FIXME: IA-64 Only
  1151. case 0x89: STORE_TLBCACHE_INFO (L3Unified, 4096); break; // <-- FIXME: IA-64 Only
  1152. case 0x8a: STORE_TLBCACHE_INFO (L3Unified, 8192); break; // <-- FIXME: IA-64 Only
  1153. case 0x8d: STORE_TLBCACHE_INFO (L3Unified, 3096); break; // <-- FIXME: IA-64 Only
  1154. case 0x90: STORE_TLBCACHE_INFO (TLBCode, 262144); break; // <-- FIXME: IA-64 Only
  1155. case 0x96: STORE_TLBCACHE_INFO (TLBCode, 262144); break; // <-- FIXME: IA-64 Only
  1156. case 0x9b: STORE_TLBCACHE_INFO (TLBCode, 262144); break; // <-- FIXME: IA-64 Only
  1157. // Default case - an error has occured.
  1158. default: return false;
  1159. }
  1160. }
  1161. // Increment the TLB pass counter.
  1162. TLBPassCounter ++;
  1163. } while ((TLBCacheData[0] & 0x000000FF) > TLBPassCounter);
  1164. // Ok - we now have the maximum TLB, L1, L2, and L3 sizes...
  1165. if ((L1Code == -1) && (L1Data == -1) && (L1Trace == -1))
  1166. {
  1167. this->Features.L1CacheSize = -1;
  1168. }
  1169. else if ((L1Code == -1) && (L1Data == -1) && (L1Trace != -1))
  1170. {
  1171. this->Features.L1CacheSize = L1Trace;
  1172. }
  1173. else if ((L1Code != -1) && (L1Data == -1))
  1174. {
  1175. this->Features.L1CacheSize = L1Code;
  1176. }
  1177. else if ((L1Code == -1) && (L1Data != -1))
  1178. {
  1179. this->Features.L1CacheSize = L1Data;
  1180. }
  1181. else if ((L1Code != -1) && (L1Data != -1))
  1182. {
  1183. this->Features.L1CacheSize = L1Code + L1Data;
  1184. }
  1185. else
  1186. {
  1187. this->Features.L1CacheSize = -1;
  1188. }
  1189. // Ok - we now have the maximum TLB, L1, L2, and L3 sizes...
  1190. if (L2Unified == -1)
  1191. {
  1192. this->Features.L2CacheSize = -1;
  1193. }
  1194. else
  1195. {
  1196. this->Features.L2CacheSize = L2Unified;
  1197. }
  1198. // Ok - we now have the maximum TLB, L1, L2, and L3 sizes...
  1199. if (L3Unified == -1)
  1200. {
  1201. this->Features.L3CacheSize = -1;
  1202. }
  1203. else
  1204. {
  1205. this->Features.L3CacheSize = L3Unified;
  1206. }
  1207. #endif
  1208. return true;
  1209. }
  1210. /** */
  1211. bool SystemInformationImplementation::RetrieveCPUClockSpeed()
  1212. {
  1213. #if _WIN32
  1214. // First of all we check to see if the RDTSC (0x0F, 0x31) instruction is supported.
  1215. if (!this->Features.HasTSC)
  1216. {
  1217. return false;
  1218. }
  1219. unsigned int uiRepetitions = 1;
  1220. unsigned int uiMSecPerRepetition = 50;
  1221. __int64 i64Total = 0;
  1222. __int64 i64Overhead = 0;
  1223. for (unsigned int nCounter = 0; nCounter < uiRepetitions; nCounter ++)
  1224. {
  1225. i64Total += GetCyclesDifference (SystemInformationImplementation::Delay,
  1226. uiMSecPerRepetition);
  1227. i64Overhead +=
  1228. GetCyclesDifference (SystemInformationImplementation::DelayOverhead,
  1229. uiMSecPerRepetition);
  1230. }
  1231. // Calculate the MHz speed.
  1232. i64Total -= i64Overhead;
  1233. i64Total /= uiRepetitions;
  1234. i64Total /= uiMSecPerRepetition;
  1235. i64Total /= 1000;
  1236. // Save the CPU speed.
  1237. this->CPUSpeedInMHz = (float) i64Total;
  1238. return true;
  1239. #else
  1240. return false;
  1241. #endif
  1242. }
  1243. /** */
  1244. bool SystemInformationImplementation::RetrieveClassicalCPUClockSpeed()
  1245. {
  1246. #if USE_ASM_INSTRUCTIONS
  1247. LARGE_INTEGER liStart, liEnd, liCountsPerSecond;
  1248. double dFrequency, dDifference;
  1249. // Attempt to get a starting tick count.
  1250. QueryPerformanceCounter (&liStart);
  1251. __try
  1252. {
  1253. _asm
  1254. {
  1255. mov eax, 0x80000000
  1256. mov ebx, CLASSICAL_CPU_FREQ_LOOP
  1257. Timer_Loop:
  1258. bsf ecx,eax
  1259. dec ebx
  1260. jnz Timer_Loop
  1261. }
  1262. }
  1263. __except(1)
  1264. {
  1265. return false;
  1266. }
  1267. // Attempt to get a starting tick count.
  1268. QueryPerformanceCounter (&liEnd);
  1269. // Get the difference... NB: This is in seconds....
  1270. QueryPerformanceFrequency (&liCountsPerSecond);
  1271. dDifference = (((double) liEnd.QuadPart - (double) liStart.QuadPart) / (double) liCountsPerSecond.QuadPart);
  1272. // Calculate the clock speed.
  1273. if (this->ChipID.Family == 3)
  1274. {
  1275. // 80386 processors.... Loop time is 115 cycles!
  1276. dFrequency = (((CLASSICAL_CPU_FREQ_LOOP * 115) / dDifference) / 1048576);
  1277. }
  1278. else if (this->ChipID.Family == 4)
  1279. {
  1280. // 80486 processors.... Loop time is 47 cycles!
  1281. dFrequency = (((CLASSICAL_CPU_FREQ_LOOP * 47) / dDifference) / 1048576);
  1282. }
  1283. else if (this->ChipID.Family == 5)
  1284. {
  1285. // Pentium processors.... Loop time is 43 cycles!
  1286. dFrequency = (((CLASSICAL_CPU_FREQ_LOOP * 43) / dDifference) / 1048576);
  1287. }
  1288. // Save the clock speed.
  1289. this->Features.CPUSpeed = (int) dFrequency;
  1290. #else
  1291. return true;
  1292. #endif
  1293. }
  1294. /** */
  1295. bool SystemInformationImplementation::RetrieveCPUExtendedLevelSupport(int CPULevelToCheck)
  1296. {
  1297. int MaxCPUExtendedLevel = 0;
  1298. // The extended CPUID is supported by various vendors starting with the following CPU models:
  1299. //
  1300. // Manufacturer & Chip Name | Family Model Revision
  1301. //
  1302. // AMD K6, K6-2 | 5 6 x
  1303. // Cyrix GXm, Cyrix III "Joshua" | 5 4 x
  1304. // IDT C6-2 | 5 8 x
  1305. // VIA Cyrix III | 6 5 x
  1306. // Transmeta Crusoe | 5 x x
  1307. // Intel Pentium 4 | f x x
  1308. //
  1309. // We check to see if a supported processor is present...
  1310. if (this->ChipManufacturer == AMD)
  1311. {
  1312. if (this->ChipID.Family < 5) return false;
  1313. if ((this->ChipID.Family == 5) && (this->ChipID.Model < 6)) return false;
  1314. }
  1315. else if (this->ChipManufacturer == Cyrix)
  1316. {
  1317. if (this->ChipID.Family < 5) return false;
  1318. if ((this->ChipID.Family == 5) && (this->ChipID.Model < 4)) return false;
  1319. if ((this->ChipID.Family == 6) && (this->ChipID.Model < 5)) return false;
  1320. }
  1321. else if (this->ChipManufacturer == IDT)
  1322. {
  1323. if (this->ChipID.Family < 5) return false;
  1324. if ((this->ChipID.Family == 5) && (this->ChipID.Model < 8)) return false;
  1325. }
  1326. else if (this->ChipManufacturer == Transmeta)
  1327. {
  1328. if (this->ChipID.Family < 5) return false;
  1329. }
  1330. else if (this->ChipManufacturer == Intel)
  1331. {
  1332. if (this->ChipID.Family < 0xf)
  1333. {
  1334. return false;
  1335. }
  1336. }
  1337. #if USE_ASM_INSTRUCTIONS
  1338. // Use assembly to detect CPUID information...
  1339. __try {
  1340. _asm {
  1341. #ifdef CPUID_AWARE_COMPILER
  1342. ; we must push/pop the registers <<CPUID>> writes to, as the
  1343. ; optimiser doesn't know about <<CPUID>>, and so doesn't expect
  1344. ; these registers to change.
  1345. push eax
  1346. push ebx
  1347. push ecx
  1348. push edx
  1349. #endif
  1350. ; <<CPUID>>
  1351. ; eax = 0x80000000 --> eax: maximum supported extended level
  1352. mov eax,0x80000000
  1353. CPUID_INSTRUCTION
  1354. mov MaxCPUExtendedLevel, eax
  1355. #ifdef CPUID_AWARE_COMPILER
  1356. pop edx
  1357. pop ecx
  1358. pop ebx
  1359. pop eax
  1360. #endif
  1361. }
  1362. }
  1363. __except(1)
  1364. {
  1365. return false;
  1366. }
  1367. #endif
  1368. // Now we have to check the level wanted vs level returned...
  1369. int nLevelWanted = (CPULevelToCheck & 0x7FFFFFFF);
  1370. int nLevelReturn = (MaxCPUExtendedLevel & 0x7FFFFFFF);
  1371. // Check to see if the level provided is supported...
  1372. if (nLevelWanted > nLevelReturn)
  1373. {
  1374. return false;
  1375. }
  1376. return true;
  1377. }
  1378. /** */
  1379. bool SystemInformationImplementation::RetrieveExtendedCPUFeatures()
  1380. {
  1381. // Check that we are not using an Intel processor as it does not support this.
  1382. if (this->ChipManufacturer == Intel)
  1383. {
  1384. return false;
  1385. }
  1386. // Check to see if what we are about to do is supported...
  1387. if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000001)))
  1388. {
  1389. return false;
  1390. }
  1391. #if USE_ASM_INSTRUCTIONS
  1392. int localCPUExtendedFeatures = 0;
  1393. // Use assembly to detect CPUID information...
  1394. __try
  1395. {
  1396. _asm
  1397. {
  1398. #ifdef CPUID_AWARE_COMPILER
  1399. ; we must push/pop the registers <<CPUID>> writes to, as the
  1400. ; optimiser doesn't know about <<CPUID>>, and so doesn't expect
  1401. ; these registers to change.
  1402. push eax
  1403. push ebx
  1404. push ecx
  1405. push edx
  1406. #endif
  1407. ; <<CPUID>>
  1408. ; 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
  1409. ; ebx: 31..24 - default APIC ID, 23..16 - logical processsor ID, 15..8 - CFLUSH chunk size , 7..0 - brand ID
  1410. ; edx: CPU feature flags
  1411. mov eax,0x80000001
  1412. CPUID_INSTRUCTION
  1413. mov localCPUExtendedFeatures, edx
  1414. #ifdef CPUID_AWARE_COMPILER
  1415. pop edx
  1416. pop ecx
  1417. pop ebx
  1418. pop eax
  1419. #endif
  1420. }
  1421. }
  1422. __except(1)
  1423. {
  1424. return false;
  1425. }
  1426. // Retrieve the extended features of CPU present.
  1427. this->Features.ExtendedFeatures.Has3DNow = ((localCPUExtendedFeatures & 0x80000000) != 0); // 3DNow Present --> Bit 31.
  1428. this->Features.ExtendedFeatures.Has3DNowPlus = ((localCPUExtendedFeatures & 0x40000000) != 0); // 3DNow+ Present -- > Bit 30.
  1429. this->Features.ExtendedFeatures.HasSSEMMX = ((localCPUExtendedFeatures & 0x00400000) != 0); // SSE MMX Present --> Bit 22.
  1430. this->Features.ExtendedFeatures.SupportsMP = ((localCPUExtendedFeatures & 0x00080000) != 0); // MP Capable -- > Bit 19.
  1431. // Retrieve AMD specific extended features.
  1432. if (this->ChipManufacturer == AMD)
  1433. {
  1434. this->Features.ExtendedFeatures.HasMMXPlus = ((localCPUExtendedFeatures & 0x00400000) != 0); // AMD specific: MMX-SSE --> Bit 22
  1435. }
  1436. // Retrieve Cyrix specific extended features.
  1437. if (this->ChipManufacturer == Cyrix)
  1438. {
  1439. this->Features.ExtendedFeatures.HasMMXPlus = ((localCPUExtendedFeatures & 0x01000000) != 0); // Cyrix specific: Extended MMX --> Bit 24
  1440. }
  1441. #endif
  1442. return true;
  1443. }
  1444. /** */
  1445. bool SystemInformationImplementation::RetrieveProcessorSerialNumber()
  1446. {
  1447. // Check to see if the processor supports the processor serial number.
  1448. if (!this->Features.HasSerial)
  1449. {
  1450. return false;
  1451. }
  1452. #if USE_ASM_INSTRUCTIONS
  1453. int SerialNumber[3];
  1454. // Use assembly to detect CPUID information...
  1455. __try {
  1456. _asm {
  1457. #ifdef CPUID_AWARE_COMPILER
  1458. ; we must push/pop the registers <<CPUID>> writes to, as the
  1459. ; optimiser doesn't know about <<CPUID>>, and so doesn't expect
  1460. ; these registers to change.
  1461. push eax
  1462. push ebx
  1463. push ecx
  1464. push edx
  1465. #endif
  1466. ; <<CPUID>>
  1467. ; eax = 3 --> ebx: top 32 bits are the processor signature bits --> NB: Transmeta only ?!?
  1468. ; ecx: middle 32 bits are the processor signature bits
  1469. ; edx: bottom 32 bits are the processor signature bits
  1470. mov eax, 3
  1471. CPUID_INSTRUCTION
  1472. mov SerialNumber[0 * TYPE int], ebx
  1473. mov SerialNumber[1 * TYPE int], ecx
  1474. mov SerialNumber[2 * TYPE int], edx
  1475. #ifdef CPUID_AWARE_COMPILER
  1476. pop edx
  1477. pop ecx
  1478. pop ebx
  1479. pop eax
  1480. #endif
  1481. }
  1482. }
  1483. __except(1)
  1484. {
  1485. return false;
  1486. }
  1487. // Process the returned information.
  1488. sprintf (this->ChipID.SerialNumber, "%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x",
  1489. ((SerialNumber[0] & 0xff000000) >> 24),
  1490. ((SerialNumber[0] & 0x00ff0000) >> 16),
  1491. ((SerialNumber[0] & 0x0000ff00) >> 8),
  1492. ((SerialNumber[0] & 0x000000ff) >> 0),
  1493. ((SerialNumber[1] & 0xff000000) >> 24),
  1494. ((SerialNumber[1] & 0x00ff0000) >> 16),
  1495. ((SerialNumber[1] & 0x0000ff00) >> 8),
  1496. ((SerialNumber[1] & 0x000000ff) >> 0),
  1497. ((SerialNumber[2] & 0xff000000) >> 24),
  1498. ((SerialNumber[2] & 0x00ff0000) >> 16),
  1499. ((SerialNumber[2] & 0x0000ff00) >> 8),
  1500. ((SerialNumber[2] & 0x000000ff) >> 0));
  1501. #endif
  1502. return true;
  1503. }
  1504. /** */
  1505. bool SystemInformationImplementation::RetrieveCPUPowerManagement()
  1506. {
  1507. // Check to see if what we are about to do is supported...
  1508. if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000007)))
  1509. {
  1510. this->Features.ExtendedFeatures.PowerManagement.HasFrequencyID = false;
  1511. this->Features.ExtendedFeatures.PowerManagement.HasVoltageID = false;
  1512. this->Features.ExtendedFeatures.PowerManagement.HasTempSenseDiode = false;
  1513. return false;
  1514. }
  1515. #if USE_ASM_INSTRUCTIONS
  1516. int localCPUPowerManagement = 0;
  1517. // Use assembly to detect CPUID information...
  1518. __try {
  1519. _asm {
  1520. #ifdef CPUID_AWARE_COMPILER
  1521. ; we must push/pop the registers <<CPUID>> writes to, as the
  1522. ; optimiser doesn't know about <<CPUID>>, and so doesn't expect
  1523. ; these registers to change.
  1524. push eax
  1525. push ebx
  1526. push ecx
  1527. push edx
  1528. #endif
  1529. ; <<CPUID>>
  1530. ; eax = 0x80000007 --> edx: get processor power management
  1531. mov eax,0x80000007
  1532. CPUID_INSTRUCTION
  1533. mov localCPUPowerManagement, edx
  1534. #ifdef CPUID_AWARE_COMPILER
  1535. pop edx
  1536. pop ecx
  1537. pop ebx
  1538. pop eax
  1539. #endif
  1540. }
  1541. }
  1542. __except(1)
  1543. {
  1544. return false;
  1545. }
  1546. // Check for the power management capabilities of the CPU.
  1547. this->Features.ExtendedFeatures.PowerManagement.HasTempSenseDiode = ((localCPUPowerManagement & 0x00000001) != 0);
  1548. this->Features.ExtendedFeatures.PowerManagement.HasFrequencyID = ((localCPUPowerManagement & 0x00000002) != 0);
  1549. this->Features.ExtendedFeatures.PowerManagement.HasVoltageID = ((localCPUPowerManagement & 0x00000004) != 0);
  1550. #endif
  1551. return true;
  1552. }
  1553. /** */
  1554. bool SystemInformationImplementation::RetrieveExtendedCPUIdentity()
  1555. {
  1556. // Check to see if what we are about to do is supported...
  1557. if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000002)))
  1558. return false;
  1559. if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000003)))
  1560. return false;
  1561. if (!RetrieveCPUExtendedLevelSupport(static_cast<int>(0x80000004)))
  1562. return false;
  1563. #if USE_ASM_INSTRUCTIONS
  1564. int ProcessorNameStartPos = 0;
  1565. int CPUExtendedIdentity[12];
  1566. // Use assembly to detect CPUID information...
  1567. __try {
  1568. _asm {
  1569. #ifdef CPUID_AWARE_COMPILER
  1570. ; we must push/pop the registers <<CPUID>> writes to, as the
  1571. ; optimiser doesn't know about <<CPUID>>, and so doesn't expect
  1572. ; these registers to change.
  1573. push eax
  1574. push ebx
  1575. push ecx
  1576. push edx
  1577. #endif
  1578. ; <<CPUID>>
  1579. ; eax = 0x80000002 --> eax, ebx, ecx, edx: get processor name string (part 1)
  1580. mov eax,0x80000002
  1581. CPUID_INSTRUCTION
  1582. mov CPUExtendedIdentity[0 * TYPE int], eax
  1583. mov CPUExtendedIdentity[1 * TYPE int], ebx
  1584. mov CPUExtendedIdentity[2 * TYPE int], ecx
  1585. mov CPUExtendedIdentity[3 * TYPE int], edx
  1586. ; <<CPUID>>
  1587. ; eax = 0x80000003 --> eax, ebx, ecx, edx: get processor name string (part 2)
  1588. mov eax,0x80000003
  1589. CPUID_INSTRUCTION
  1590. mov CPUExtendedIdentity[4 * TYPE int], eax
  1591. mov CPUExtendedIdentity[5 * TYPE int], ebx
  1592. mov CPUExtendedIdentity[6 * TYPE int], ecx
  1593. mov CPUExtendedIdentity[7 * TYPE int], edx
  1594. ; <<CPUID>>
  1595. ; eax = 0x80000004 --> eax, ebx, ecx, edx: get processor name string (part 3)
  1596. mov eax,0x80000004
  1597. CPUID_INSTRUCTION
  1598. mov CPUExtendedIdentity[8 * TYPE int], eax
  1599. mov CPUExtendedIdentity[9 * TYPE int], ebx
  1600. mov CPUExtendedIdentity[10 * TYPE int], ecx
  1601. mov CPUExtendedIdentity[11 * TYPE int], edx
  1602. #ifdef CPUID_AWARE_COMPILER
  1603. pop edx
  1604. pop ecx
  1605. pop ebx
  1606. pop eax
  1607. #endif
  1608. }
  1609. }
  1610. __except(1)
  1611. {
  1612. return false;
  1613. }
  1614. // Process the returned information.
  1615. memcpy (this->ChipID.ProcessorName, &(CPUExtendedIdentity[0]), sizeof (int));
  1616. memcpy (&(this->ChipID.ProcessorName[4]), &(CPUExtendedIdentity[1]), sizeof (int));
  1617. memcpy (&(this->ChipID.ProcessorName[8]), &(CPUExtendedIdentity[2]), sizeof (int));
  1618. memcpy (&(this->ChipID.ProcessorName[12]), &(CPUExtendedIdentity[3]), sizeof (int));
  1619. memcpy (&(this->ChipID.ProcessorName[16]), &(CPUExtendedIdentity[4]), sizeof (int));
  1620. memcpy (&(this->ChipID.ProcessorName[20]), &(CPUExtendedIdentity[5]), sizeof (int));
  1621. memcpy (&(this->ChipID.ProcessorName[24]), &(CPUExtendedIdentity[6]), sizeof (int));
  1622. memcpy (&(this->ChipID.ProcessorName[28]), &(CPUExtendedIdentity[7]), sizeof (int));
  1623. memcpy (&(this->ChipID.ProcessorName[32]), &(CPUExtendedIdentity[8]), sizeof (int));
  1624. memcpy (&(this->ChipID.ProcessorName[36]), &(CPUExtendedIdentity[9]), sizeof (int));
  1625. memcpy (&(this->ChipID.ProcessorName[40]), &(CPUExtendedIdentity[10]), sizeof (int));
  1626. memcpy (&(this->ChipID.ProcessorName[44]), &(CPUExtendedIdentity[11]), sizeof (int));
  1627. this->ChipID.ProcessorName[48] = '\0';
  1628. // Because some manufacturers have leading white space - we have to post-process the name.
  1629. if (this->ChipManufacturer == Intel)
  1630. {
  1631. for (int nCounter = 0; nCounter < CHIPNAME_STRING_LENGTH; nCounter ++)
  1632. {
  1633. // There will either be NULL (\0) or spaces ( ) as the leading characters.
  1634. if ((this->ChipID.ProcessorName[nCounter] != '\0') && (this->ChipID.ProcessorName[nCounter] != ' '))
  1635. {
  1636. // We have found the starting position of the name.
  1637. ProcessorNameStartPos = nCounter;
  1638. // Terminate the loop.
  1639. break;
  1640. }
  1641. }
  1642. // Check to see if there is any white space at the start.
  1643. if (ProcessorNameStartPos == 0)
  1644. {
  1645. return true;
  1646. }
  1647. // Now move the name forward so that there is no white space.
  1648. memmove(this->ChipID.ProcessorName, &(this->ChipID.ProcessorName[ProcessorNameStartPos]), (CHIPNAME_STRING_LENGTH - ProcessorNameStartPos));
  1649. }
  1650. #endif
  1651. return true;
  1652. }
  1653. /** */
  1654. bool SystemInformationImplementation::RetrieveClassicalCPUIdentity()
  1655. {
  1656. // Start by decided which manufacturer we are using....
  1657. switch (this->ChipManufacturer)
  1658. {
  1659. case Intel:
  1660. // Check the family / model / revision to determine the CPU ID.
  1661. switch (this->ChipID.Family) {
  1662. case 3:
  1663. sprintf (this->ChipID.ProcessorName, "Newer i80386 family");
  1664. break;
  1665. case 4:
  1666. switch (this->ChipID.Model) {
  1667. case 0: sprintf (this->ChipID.ProcessorName,"i80486DX-25/33"); break;
  1668. case 1: sprintf (this->ChipID.ProcessorName,"i80486DX-50"); break;
  1669. case 2: sprintf (this->ChipID.ProcessorName,"i80486SX"); break;
  1670. case 3: sprintf (this->ChipID.ProcessorName,"i80486DX2"); break;
  1671. case 4: sprintf (this->ChipID.ProcessorName,"i80486SL"); break;
  1672. case 5: sprintf (this->ChipID.ProcessorName,"i80486SX2"); break;
  1673. case 7: sprintf (this->ChipID.ProcessorName,"i80486DX2 WriteBack"); break;
  1674. case 8: sprintf (this->ChipID.ProcessorName,"i80486DX4"); break;
  1675. case 9: sprintf (this->ChipID.ProcessorName,"i80486DX4 WriteBack"); break;
  1676. default: sprintf (this->ChipID.ProcessorName,"Unknown 80486 family"); return false;
  1677. }
  1678. break;
  1679. case 5:
  1680. switch (this->ChipID.Model)
  1681. {
  1682. case 0: sprintf (this->ChipID.ProcessorName,"P5 A-Step"); break;
  1683. case 1: sprintf (this->ChipID.ProcessorName,"P5"); break;
  1684. case 2: sprintf (this->ChipID.ProcessorName,"P54C"); break;
  1685. case 3: sprintf (this->ChipID.ProcessorName,"P24T OverDrive"); break;
  1686. case 4: sprintf (this->ChipID.ProcessorName,"P55C"); break;
  1687. case 7: sprintf (this->ChipID.ProcessorName,"P54C"); break;
  1688. case 8: sprintf (this->ChipID.ProcessorName,"P55C (0.25micron)"); break;
  1689. default: sprintf (this->ChipID.ProcessorName,"Unknown Pentium family"); return false;
  1690. }
  1691. break;
  1692. case 6:
  1693. switch (this->ChipID.Model)
  1694. {
  1695. case 0: sprintf (this->ChipID.ProcessorName,"P6 A-Step"); break;
  1696. case 1: sprintf (this->ChipID.ProcessorName,"P6"); break;
  1697. case 3: sprintf (this->ChipID.ProcessorName,"Pentium II (0.28 micron)"); break;
  1698. case 5: sprintf (this->ChipID.ProcessorName,"Pentium II (0.25 micron)"); break;
  1699. case 6: sprintf (this->ChipID.ProcessorName,"Pentium II With On-Die L2 Cache"); break;
  1700. case 7: sprintf (this->ChipID.ProcessorName,"Pentium III (0.25 micron)"); break;
  1701. case 8: sprintf (this->ChipID.ProcessorName,"Pentium III (0.18 micron) With 256 KB On-Die L2 Cache "); break;
  1702. case 0xa: sprintf (this->ChipID.ProcessorName,"Pentium III (0.18 micron) With 1 Or 2 MB On-Die L2 Cache "); break;
  1703. case 0xb: sprintf (this->ChipID.ProcessorName,"Pentium III (0.13 micron) With 256 Or 512 KB On-Die L2 Cache "); break;
  1704. case 23: sprintf (this->ChipID.ProcessorName, "Intel(R) Core(TM)2 Duo CPU T9500 @ 2.60GHz"); break;
  1705. default: sprintf (this->ChipID.ProcessorName,"Unknown P6 family"); return false;
  1706. }
  1707. break;
  1708. case 7:
  1709. sprintf (this->ChipID.ProcessorName,"Intel Merced (IA-64)");
  1710. break;
  1711. case 0xf:
  1712. // Check the extended family bits...
  1713. switch (this->ChipID.ExtendedFamily)
  1714. {
  1715. case 0:
  1716. switch (this->ChipID.Model)
  1717. {
  1718. case 0: sprintf (this->ChipID.ProcessorName,"Pentium IV (0.18 micron)"); break;
  1719. case 1: sprintf (this->ChipID.ProcessorName,"Pentium IV (0.18 micron)"); break;
  1720. case 2: sprintf (this->ChipID.ProcessorName,"Pentium IV (0.13 micron)"); break;
  1721. default: sprintf (this->ChipID.ProcessorName,"Unknown Pentium 4 family"); return false;
  1722. }
  1723. break;
  1724. case 1:
  1725. sprintf (this->ChipID.ProcessorName,"Intel McKinley (IA-64)");
  1726. break;
  1727. default:
  1728. sprintf (this->ChipID.ProcessorName,"Pentium");
  1729. }
  1730. break;
  1731. default:
  1732. sprintf (this->ChipID.ProcessorName,"Unknown Intel family");
  1733. return false;
  1734. }
  1735. break;
  1736. case AMD:
  1737. // Check the family / model / revision to determine the CPU ID.
  1738. switch (this->ChipID.Family)
  1739. {
  1740. case 4:
  1741. switch (this->ChipID.Model)
  1742. {
  1743. case 3: sprintf (this->ChipID.ProcessorName,"80486DX2"); break;
  1744. case 7: sprintf (this->ChipID.ProcessorName,"80486DX2 WriteBack"); break;
  1745. case 8: sprintf (this->ChipID.ProcessorName,"80486DX4"); break;
  1746. case 9: sprintf (this->ChipID.ProcessorName,"80486DX4 WriteBack"); break;
  1747. case 0xe: sprintf (this->ChipID.ProcessorName,"5x86"); break;
  1748. case 0xf: sprintf (this->ChipID.ProcessorName,"5x86WB"); break;
  1749. default: sprintf (this->ChipID.ProcessorName,"Unknown 80486 family"); return false;
  1750. }
  1751. break;
  1752. case 5:
  1753. switch (this->ChipID.Model)
  1754. {
  1755. case 0: sprintf (this->ChipID.ProcessorName,"SSA5 (PR75, PR90, PR100)"); break;
  1756. case 1: sprintf (this->ChipID.ProcessorName,"5k86 (PR120, PR133)"); break;
  1757. case 2: sprintf (this->ChipID.ProcessorName,"5k86 (PR166)"); break;
  1758. case 3: sprintf (this->ChipID.ProcessorName,"5k86 (PR200)"); break;
  1759. case 6: sprintf (this->ChipID.ProcessorName,"K6 (0.30 micron)"); break;
  1760. case 7: sprintf (this->ChipID.ProcessorName,"K6 (0.25 micron)"); break;
  1761. case 8: sprintf (this->ChipID.ProcessorName,"K6-2"); break;
  1762. case 9: sprintf (this->ChipID.ProcessorName,"K6-III"); break;
  1763. case 0xd: sprintf (this->ChipID.ProcessorName,"K6-2+ or K6-III+ (0.18 micron)"); break;
  1764. default: sprintf (this->ChipID.ProcessorName,"Unknown 80586 family"); return false;
  1765. }
  1766. break;
  1767. case 6:
  1768. switch (this->ChipID.Model)
  1769. {
  1770. case 1: sprintf (this->ChipID.ProcessorName,"Athlon- (0.25 micron)"); break;
  1771. case 2: sprintf (this->ChipID.ProcessorName,"Athlon- (0.18 micron)"); break;
  1772. case 3: sprintf (this->ChipID.ProcessorName,"Duron- (SF core)"); break;
  1773. case 4: sprintf (this->ChipID.ProcessorName,"Athlon- (Thunderbird core)"); break;
  1774. case 6: sprintf (this->ChipID.ProcessorName,"Athlon- (Palomino core)"); break;
  1775. case 7: sprintf (this->ChipID.ProcessorName,"Duron- (Morgan core)"); break;
  1776. case 8:
  1777. if (this->Features.ExtendedFeatures.SupportsMP)
  1778. sprintf (this->ChipID.ProcessorName,"Athlon - MP (Thoroughbred core)");
  1779. else sprintf (this->ChipID.ProcessorName,"Athlon - XP (Thoroughbred core)");
  1780. break;
  1781. default: sprintf (this->ChipID.ProcessorName,"Unknown K7 family"); return false;
  1782. }
  1783. break;
  1784. default:
  1785. sprintf (this->ChipID.ProcessorName,"Unknown AMD family");
  1786. return false;
  1787. }
  1788. break;
  1789. case Transmeta:
  1790. switch (this->ChipID.Family)
  1791. {
  1792. case 5:
  1793. switch (this->ChipID.Model)
  1794. {
  1795. case 4: sprintf (this->ChipID.ProcessorName,"Crusoe TM3x00 and TM5x00"); break;
  1796. default: sprintf (this->ChipID.ProcessorName,"Unknown Crusoe family"); return false;
  1797. }
  1798. break;
  1799. default:
  1800. sprintf (this->ChipID.ProcessorName,"Unknown Transmeta family");
  1801. return false;
  1802. }
  1803. break;
  1804. case Rise:
  1805. switch (this->ChipID.Family)
  1806. {
  1807. case 5:
  1808. switch (this->ChipID.Model)
  1809. {
  1810. case 0: sprintf (this->ChipID.ProcessorName,"mP6 (0.25 micron)"); break;
  1811. case 2: sprintf (this->ChipID.ProcessorName,"mP6 (0.18 micron)"); break;
  1812. default: sprintf (this->ChipID.ProcessorName,"Unknown Rise family"); return false;
  1813. }
  1814. break;
  1815. default:
  1816. sprintf (this->ChipID.ProcessorName,"Unknown Rise family");
  1817. return false;
  1818. }
  1819. break;
  1820. case UMC:
  1821. switch (this->ChipID.Family)
  1822. {
  1823. case 4:
  1824. switch (this->ChipID.Model)
  1825. {
  1826. case 1: sprintf (this->ChipID.ProcessorName,"U5D"); break;
  1827. case 2: sprintf (this->ChipID.ProcessorName,"U5S"); break;
  1828. default: sprintf (this->ChipID.ProcessorName,"Unknown UMC family"); return false;
  1829. }
  1830. break;
  1831. default:
  1832. sprintf (this->ChipID.ProcessorName,"Unknown UMC family");
  1833. return false;
  1834. }
  1835. break;
  1836. case IDT:
  1837. switch (this->ChipID.Family)
  1838. {
  1839. case 5:
  1840. switch (this->ChipID.Model)
  1841. {
  1842. case 4: sprintf (this->ChipID.ProcessorName,"C6"); break;
  1843. case 8: sprintf (this->ChipID.ProcessorName,"C2"); break;
  1844. case 9: sprintf (this->ChipID.ProcessorName,"C3"); break;
  1845. default: sprintf (this->ChipID.ProcessorName,"Unknown IDT\\Centaur family"); return false;
  1846. }
  1847. break;
  1848. case 6:
  1849. switch (this->ChipID.Model)
  1850. {
  1851. case 6: sprintf (this->ChipID.ProcessorName,"VIA Cyrix III - Samuel"); break;
  1852. default: sprintf (this->ChipID.ProcessorName,"Unknown IDT\\Centaur family"); return false;
  1853. }
  1854. break;
  1855. default:
  1856. sprintf (this->ChipID.ProcessorName,"Unknown IDT\\Centaur family");
  1857. return false;
  1858. }
  1859. break;
  1860. case Cyrix:
  1861. switch (this->ChipID.Family)
  1862. {
  1863. case 4:
  1864. switch (this->ChipID.Model)
  1865. {
  1866. case 4: sprintf (this->ChipID.ProcessorName,"MediaGX GX, GXm"); break;
  1867. case 9: sprintf (this->ChipID.ProcessorName,"5x86"); break;
  1868. default: sprintf (this->ChipID.ProcessorName,"Unknown Cx5x86 family"); return false;
  1869. }
  1870. break;
  1871. case 5:
  1872. switch (this->ChipID.Model)
  1873. {
  1874. case 2: sprintf (this->ChipID.ProcessorName,"Cx6x86"); break;
  1875. case 4: sprintf (this->ChipID.ProcessorName,"MediaGX GXm"); break;
  1876. default: sprintf (this->ChipID.ProcessorName,"Unknown Cx6x86 family"); return false;
  1877. }
  1878. break;
  1879. case 6:
  1880. switch (this->ChipID.Model)
  1881. {
  1882. case 0: sprintf (this->ChipID.ProcessorName,"6x86MX"); break;
  1883. case 5: sprintf (this->ChipID.ProcessorName,"Cyrix M2 Core"); break;
  1884. case 6: sprintf (this->ChipID.ProcessorName,"WinChip C5A Core"); break;
  1885. case 7: sprintf (this->ChipID.ProcessorName,"WinChip C5B\\C5C Core"); break;
  1886. case 8: sprintf (this->ChipID.ProcessorName,"WinChip C5C-T Core"); break;
  1887. default: sprintf (this->ChipID.ProcessorName,"Unknown 6x86MX\\Cyrix III family"); return false;
  1888. }
  1889. break;
  1890. default:
  1891. sprintf (this->ChipID.ProcessorName,"Unknown Cyrix family");
  1892. return false;
  1893. }
  1894. break;
  1895. case NexGen:
  1896. switch (this->ChipID.Family)
  1897. {
  1898. case 5:
  1899. switch (this->ChipID.Model)
  1900. {
  1901. case 0: sprintf (this->ChipID.ProcessorName,"Nx586 or Nx586FPU"); break;
  1902. default: sprintf (this->ChipID.ProcessorName,"Unknown NexGen family"); return false;
  1903. }
  1904. break;
  1905. default:
  1906. sprintf (this->ChipID.ProcessorName,"Unknown NexGen family");
  1907. return false;
  1908. }
  1909. break;
  1910. case NSC:
  1911. sprintf (this->ChipID.ProcessorName,"Cx486SLC \\ DLC \\ Cx486S A-Step");
  1912. break;
  1913. default:
  1914. sprintf (this->ChipID.ProcessorName,"Unknown family"); // We cannot identify the processor.
  1915. return false;
  1916. }
  1917. return true;
  1918. }
  1919. /** Extract a value from the CPUInfo file */
  1920. kwsys_stl::string SystemInformationImplementation::ExtractValueFromCpuInfoFile(kwsys_stl::string buffer,const char* word,size_t init)
  1921. {
  1922. size_t pos = buffer.find(word,init);
  1923. if(pos != buffer.npos)
  1924. {
  1925. this->CurrentPositionInFile = pos;
  1926. pos = buffer.find(":",pos);
  1927. size_t pos2 = buffer.find("\n",pos);
  1928. if(pos!=buffer.npos && pos2!=buffer.npos)
  1929. {
  1930. return buffer.substr(pos+2,pos2-pos-2);
  1931. }
  1932. }
  1933. this->CurrentPositionInFile = buffer.npos;
  1934. return "";
  1935. }
  1936. /** Query for the cpu status */
  1937. int SystemInformationImplementation::RetreiveInformationFromCpuInfoFile()
  1938. {
  1939. this->NumberOfLogicalCPU = 0;
  1940. this->NumberOfPhysicalCPU = 0;
  1941. kwsys_stl::string buffer;
  1942. FILE *fd = fopen("/proc/cpuinfo", "r" );
  1943. if ( !fd )
  1944. {
  1945. kwsys_ios::cout << "Problem opening /proc/cpuinfo" << kwsys_ios::endl;
  1946. return 0;
  1947. }
  1948. size_t fileSize = 0;
  1949. while(!feof(fd))
  1950. {
  1951. buffer += static_cast<char>(fgetc(fd));
  1952. fileSize++;
  1953. }
  1954. fclose( fd );
  1955. buffer.resize(fileSize-2);
  1956. // Number of logical CPUs (combination of multiple processors, multi-core
  1957. // and hyperthreading)
  1958. size_t pos = buffer.find("processor\t");
  1959. while(pos != buffer.npos)
  1960. {
  1961. this->NumberOfLogicalCPU++;
  1962. pos = buffer.find("processor\t",pos+1);
  1963. }
  1964. #ifdef __linux
  1965. // Find the largest physical id.
  1966. int maxId = -1;
  1967. kwsys_stl::string idc =
  1968. this->ExtractValueFromCpuInfoFile(buffer,"physical id");
  1969. while(this->CurrentPositionInFile != buffer.npos)
  1970. {
  1971. int id = atoi(idc.c_str());
  1972. if(id > maxId)
  1973. {
  1974. maxId=id;
  1975. }
  1976. idc = this->ExtractValueFromCpuInfoFile(buffer,"physical id",
  1977. this->CurrentPositionInFile+1);
  1978. }
  1979. // Physical ids returned by Linux don't distinguish cores.
  1980. // We want to record the total number of cores in this->NumberOfPhysicalCPU
  1981. // (checking only the first proc)
  1982. kwsys_stl::string cores =
  1983. this->ExtractValueFromCpuInfoFile(buffer,"cpu cores");
  1984. int numberOfCoresPerCPU=atoi(cores.c_str());
  1985. this->NumberOfPhysicalCPU=static_cast<unsigned int>(
  1986. numberOfCoresPerCPU*(maxId+1));
  1987. #else // __CYGWIN__
  1988. // does not have "physical id" entries, neither "cpu cores"
  1989. // this has to be fixed for hyper-threading.
  1990. kwsys_stl::string cpucount =
  1991. this->ExtractValueFromCpuInfoFile(buffer,"cpu count");
  1992. this->NumberOfPhysicalCPU=
  1993. this->NumberOfLogicalCPU = atoi(cpucount.c_str());
  1994. #endif
  1995. // gotta have one, and if this is 0 then we get a / by 0n
  1996. // beter to have a bad answer than a crash
  1997. if(this->NumberOfPhysicalCPU <= 0)
  1998. {
  1999. this->NumberOfPhysicalCPU = 1;
  2000. }
  2001. // LogicalProcessorsPerPhysical>1 => hyperthreading.
  2002. this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical=
  2003. this->NumberOfLogicalCPU/this->NumberOfPhysicalCPU;
  2004. // CPU speed (checking only the first proc
  2005. kwsys_stl::string CPUSpeed = this->ExtractValueFromCpuInfoFile(buffer,"cpu MHz");
  2006. this->CPUSpeedInMHz = static_cast<float>(atof(CPUSpeed.c_str()));
  2007. // Chip family
  2008. this->ChipID.Family = atoi(this->ExtractValueFromCpuInfoFile(buffer,"cpu family").c_str());
  2009. // Chip Vendor
  2010. strcpy(this->ChipID.Vendor,this->ExtractValueFromCpuInfoFile(buffer,"vendor_id").c_str());
  2011. this->FindManufacturer();
  2012. // Chip Model
  2013. this->ChipID.Model = atoi(this->ExtractValueFromCpuInfoFile(buffer,"model").c_str());
  2014. this->RetrieveClassicalCPUIdentity();
  2015. // L1 Cache size
  2016. kwsys_stl::string cacheSize = this->ExtractValueFromCpuInfoFile(buffer,"cache size");
  2017. pos = cacheSize.find(" KB");
  2018. if(pos!=cacheSize.npos)
  2019. {
  2020. cacheSize = cacheSize.substr(0,pos);
  2021. }
  2022. this->Features.L1CacheSize = atoi(cacheSize.c_str());
  2023. return 1;
  2024. }
  2025. /** Query for the memory status */
  2026. int SystemInformationImplementation::QueryMemory()
  2027. {
  2028. this->TotalVirtualMemory = 0;
  2029. this->TotalPhysicalMemory = 0;
  2030. this->AvailableVirtualMemory = 0;
  2031. this->AvailablePhysicalMemory = 0;
  2032. #ifdef __CYGWIN__
  2033. return 0;
  2034. #elif _WIN32
  2035. #if _MSC_VER < 1300
  2036. MEMORYSTATUS ms;
  2037. GlobalMemoryStatus(&ms);
  2038. #define MEM_VAL(value) dw##value
  2039. #else
  2040. MEMORYSTATUSEX ms;
  2041. GlobalMemoryStatusEx(&ms);
  2042. #define MEM_VAL(value) ull##value
  2043. #endif
  2044. unsigned long tv = ms.MEM_VAL(TotalVirtual);
  2045. unsigned long tp = ms.MEM_VAL(TotalPhys);
  2046. unsigned long av = ms.MEM_VAL(AvailVirtual);
  2047. unsigned long ap = ms.MEM_VAL(AvailPhys);
  2048. this->TotalVirtualMemory = tv>>10>>10;
  2049. this->TotalPhysicalMemory = tp>>10>>10;
  2050. this->AvailableVirtualMemory = av>>10>>10;
  2051. this->AvailablePhysicalMemory = ap>>10>>10;
  2052. return 1;
  2053. #elif __linux
  2054. unsigned long tv=0;
  2055. unsigned long tp=0;
  2056. unsigned long av=0;
  2057. unsigned long ap=0;
  2058. char buffer[1024]; // for reading lines
  2059. int linuxMajor = 0;
  2060. int linuxMinor = 0;
  2061. // Find the Linux kernel version first
  2062. struct utsname unameInfo;
  2063. int errorFlag = uname(&unameInfo);
  2064. if( errorFlag!=0 )
  2065. {
  2066. kwsys_ios::cout << "Problem calling uname(): " << strerror(errno) << kwsys_ios::endl;
  2067. return 0;
  2068. }
  2069. if( unameInfo.release!=0 && strlen(unameInfo.release)>=3 )
  2070. {
  2071. // release looks like "2.6.3-15mdk-i686-up-4GB"
  2072. char majorChar=unameInfo.release[0];
  2073. char minorChar=unameInfo.release[2];
  2074. if( isdigit(majorChar) )
  2075. {
  2076. linuxMajor=majorChar-'0';
  2077. }
  2078. if( isdigit(minorChar) )
  2079. {
  2080. linuxMinor=minorChar-'0';
  2081. }
  2082. }
  2083. FILE *fd = fopen("/proc/meminfo", "r" );
  2084. if ( !fd )
  2085. {
  2086. kwsys_ios::cout << "Problem opening /proc/meminfo" << kwsys_ios::endl;
  2087. return 0;
  2088. }
  2089. if( linuxMajor>=3 || ( (linuxMajor>=2) && (linuxMinor>=6) ) )
  2090. {
  2091. // new /proc/meminfo format since kernel 2.6.x
  2092. // Rigorously, this test should check from the developping version 2.5.x
  2093. // that introduced the new format...
  2094. enum { mMemTotal, mMemFree, mBuffers, mCached, mSwapTotal, mSwapFree };
  2095. const char* format[6] =
  2096. { "MemTotal:%lu kB", "MemFree:%lu kB", "Buffers:%lu kB",
  2097. "Cached:%lu kB", "SwapTotal:%lu kB", "SwapFree:%lu kB" };
  2098. bool have[6] = { false, false, false, false, false, false };
  2099. unsigned long value[6];
  2100. int count = 0;
  2101. while(fgets(buffer, sizeof(buffer), fd))
  2102. {
  2103. for(int i=0; i < 6; ++i)
  2104. {
  2105. if(!have[i] && sscanf(buffer, format[i], &value[i]) == 1)
  2106. {
  2107. have[i] = true;
  2108. ++count;
  2109. }
  2110. }
  2111. }
  2112. if(count == 6)
  2113. {
  2114. this->TotalPhysicalMemory = value[mMemTotal] / 1024;
  2115. this->AvailablePhysicalMemory =
  2116. (value[mMemFree] + value[mBuffers] + value[mCached]) / 1024;
  2117. this->TotalVirtualMemory = value[mSwapTotal] / 1024;
  2118. this->AvailableVirtualMemory = value[mSwapFree] / 1024;
  2119. }
  2120. else
  2121. {
  2122. kwsys_ios::cout << "Problem parsing /proc/meminfo" << kwsys_ios::endl;
  2123. fclose(fd);
  2124. return 0;
  2125. }
  2126. }
  2127. else
  2128. {
  2129. // /proc/meminfo format for kernel older than 2.6.x
  2130. unsigned long temp;
  2131. unsigned long cachedMem;
  2132. unsigned long buffersMem;
  2133. char *r=fgets(buffer, sizeof(buffer), fd); // Skip "total: used:..."
  2134. int status=0;
  2135. if(r==buffer)
  2136. {
  2137. status+=fscanf(fd, "Mem: %lu %lu %lu %lu %lu %lu\n",
  2138. &tp, &temp, &ap, &temp, &buffersMem, &cachedMem);
  2139. }
  2140. if(status==6)
  2141. {
  2142. status+=fscanf(fd, "Swap: %lu %lu %lu\n", &tv, &temp, &av);
  2143. }
  2144. if(status==9)
  2145. {
  2146. this->TotalVirtualMemory = tv>>10>>10;
  2147. this->TotalPhysicalMemory = tp>>10>>10;
  2148. this->AvailableVirtualMemory = av>>10>>10;
  2149. this->AvailablePhysicalMemory = (ap+buffersMem+cachedMem)>>10>>10;
  2150. }
  2151. else
  2152. {
  2153. kwsys_ios::cout << "Problem parsing /proc/meminfo" << kwsys_ios::endl;
  2154. fclose(fd);
  2155. return 0;
  2156. }
  2157. }
  2158. fclose( fd );
  2159. return 1;
  2160. #elif __hpux
  2161. unsigned long tv=0;
  2162. unsigned long tp=0;
  2163. unsigned long av=0;
  2164. unsigned long ap=0;
  2165. struct pst_static pst;
  2166. struct pst_dynamic pdy;
  2167. unsigned long ps = 0;
  2168. if (pstat_getstatic(&pst, sizeof(pst), (size_t) 1, 0) != -1)
  2169. {
  2170. ps = pst.page_size;
  2171. tp = pst.physical_memory *ps;
  2172. tv = (pst.physical_memory + pst.pst_maxmem) * ps;
  2173. if (pstat_getdynamic(&pdy, sizeof(pdy), (size_t) 1, 0) != -1)
  2174. {
  2175. ap = tp - pdy.psd_rm * ps;
  2176. av = tv - pdy.psd_vm;
  2177. this->TotalVirtualMemory = tv>>10>>10;
  2178. this->TotalPhysicalMemory = tp>>10>>10;
  2179. this->AvailableVirtualMemory = av>>10>>10;
  2180. this->AvailablePhysicalMemory = ap>>10>>10;
  2181. return 1;
  2182. }
  2183. }
  2184. return 0;
  2185. #else
  2186. return 0;
  2187. #endif
  2188. }
  2189. /** */
  2190. unsigned long SystemInformationImplementation::GetTotalVirtualMemory()
  2191. {
  2192. return this->TotalVirtualMemory;
  2193. }
  2194. /** */
  2195. unsigned long SystemInformationImplementation::GetAvailableVirtualMemory()
  2196. {
  2197. return this->AvailableVirtualMemory;
  2198. }
  2199. unsigned long SystemInformationImplementation::GetTotalPhysicalMemory()
  2200. {
  2201. return this->TotalPhysicalMemory;
  2202. }
  2203. /** */
  2204. unsigned long SystemInformationImplementation::GetAvailablePhysicalMemory()
  2205. {
  2206. return this->AvailablePhysicalMemory;
  2207. }
  2208. /** Get Cycle differences */
  2209. LongLong SystemInformationImplementation::GetCyclesDifference (DELAY_FUNC DelayFunction,
  2210. unsigned int uiParameter)
  2211. {
  2212. #if USE_ASM_INSTRUCTIONS
  2213. unsigned int edx1, eax1;
  2214. unsigned int edx2, eax2;
  2215. // Calculate the frequency of the CPU instructions.
  2216. __try {
  2217. _asm {
  2218. push uiParameter ; push parameter param
  2219. mov ebx, DelayFunction ; store func in ebx
  2220. RDTSC_INSTRUCTION
  2221. mov esi, eax ; esi = eax
  2222. mov edi, edx ; edi = edx
  2223. call ebx ; call the delay functions
  2224. RDTSC_INSTRUCTION
  2225. pop ebx
  2226. mov edx2, edx ; edx2 = edx
  2227. mov eax2, eax ; eax2 = eax
  2228. mov edx1, edi ; edx2 = edi
  2229. mov eax1, esi ; eax2 = esi
  2230. }
  2231. }
  2232. __except(1)
  2233. {
  2234. return -1;
  2235. }
  2236. return ((((__int64) edx2 << 32) + eax2) - (((__int64) edx1 << 32) + eax1));
  2237. #else
  2238. (void)DelayFunction;
  2239. (void)uiParameter;
  2240. return -1;
  2241. #endif
  2242. }
  2243. /** Compute the delay overhead */
  2244. void SystemInformationImplementation::DelayOverhead(unsigned int uiMS)
  2245. {
  2246. #if _WIN32
  2247. LARGE_INTEGER Frequency, StartCounter, EndCounter;
  2248. __int64 x;
  2249. // Get the frequency of the high performance counter.
  2250. if(!QueryPerformanceFrequency (&Frequency))
  2251. {
  2252. return;
  2253. }
  2254. x = Frequency.QuadPart / 1000 * uiMS;
  2255. // Get the starting position of the counter.
  2256. QueryPerformanceCounter (&StartCounter);
  2257. do {
  2258. // Get the ending position of the counter.
  2259. QueryPerformanceCounter (&EndCounter);
  2260. } while (EndCounter.QuadPart - StartCounter.QuadPart == x);
  2261. #endif
  2262. (void)uiMS;
  2263. }
  2264. /** Return the number of logical CPU per physical CPUs Works only for windows */
  2265. unsigned char SystemInformationImplementation::LogicalCPUPerPhysicalCPU(void)
  2266. {
  2267. unsigned int Regebx = 0;
  2268. #if USE_ASM_INSTRUCTIONS
  2269. if (!this->IsHyperThreadingSupported())
  2270. {
  2271. return static_cast<unsigned char>(1); // HT not supported
  2272. }
  2273. __asm
  2274. {
  2275. mov eax, 1
  2276. cpuid
  2277. mov Regebx, ebx
  2278. }
  2279. #endif
  2280. #ifdef __APPLE__
  2281. size_t len = 4;
  2282. int cores_per_package = 0;
  2283. int err = sysctlbyname("machdep.cpu.cores_per_package", &cores_per_package, &len, NULL, 0);
  2284. if (err != 0)
  2285. {
  2286. return 1; // That name was not found, default to 1
  2287. }
  2288. else
  2289. {
  2290. return static_cast<unsigned char>(cores_per_package);
  2291. }
  2292. #endif
  2293. return static_cast<unsigned char> ((Regebx & NUM_LOGICAL_BITS) >> 16);
  2294. }
  2295. /** Works only for windows */
  2296. unsigned int SystemInformationImplementation::IsHyperThreadingSupported()
  2297. {
  2298. #if USE_ASM_INSTRUCTIONS
  2299. unsigned int Regedx = 0,
  2300. Regeax = 0,
  2301. VendorId[3] = {0, 0, 0};
  2302. __try // Verify cpuid instruction is supported
  2303. {
  2304. __asm
  2305. {
  2306. xor eax, eax // call cpuid with eax = 0
  2307. cpuid // Get vendor id string
  2308. mov VendorId, ebx
  2309. mov VendorId + 4, edx
  2310. mov VendorId + 8, ecx
  2311. mov eax, 1 // call cpuid with eax = 1
  2312. cpuid
  2313. mov Regeax, eax // eax contains family processor type
  2314. mov Regedx, edx // edx has info about the availability of hyper-Threading
  2315. }
  2316. }
  2317. __except (EXCEPTION_EXECUTE_HANDLER)
  2318. {
  2319. return(0); // cpuid is unavailable
  2320. }
  2321. if (((Regeax & FAMILY_ID) == PENTIUM4_ID) || (Regeax & EXT_FAMILY_ID))
  2322. {
  2323. if (VendorId[0] == 'uneG')
  2324. {
  2325. if (VendorId[1] == 'Ieni')
  2326. {
  2327. if (VendorId[2] == 'letn')
  2328. {
  2329. return(Regedx & HT_BIT); // Genuine Intel with hyper-Threading technology
  2330. }
  2331. }
  2332. }
  2333. }
  2334. #endif
  2335. return 0; // Not genuine Intel processor
  2336. }
  2337. /** Return the APIC Id. Works only for windows. */
  2338. unsigned char SystemInformationImplementation::GetAPICId()
  2339. {
  2340. unsigned int Regebx = 0;
  2341. #if USE_ASM_INSTRUCTIONS
  2342. if (!this->IsHyperThreadingSupported())
  2343. {
  2344. return static_cast<unsigned char>(-1); // HT not supported
  2345. } // Logical processor = 1
  2346. __asm
  2347. {
  2348. mov eax, 1
  2349. cpuid
  2350. mov Regebx, ebx
  2351. }
  2352. #endif
  2353. return static_cast<unsigned char>((Regebx & INITIAL_APIC_ID_BITS) >> 24);
  2354. }
  2355. /** Count the number of CPUs. Works only on windows. */
  2356. int SystemInformationImplementation::CPUCount()
  2357. {
  2358. #if _WIN32
  2359. unsigned char StatusFlag = 0;
  2360. SYSTEM_INFO info;
  2361. this->NumberOfPhysicalCPU = 0;
  2362. this->NumberOfLogicalCPU = 0;
  2363. info.dwNumberOfProcessors = 0;
  2364. GetSystemInfo (&info);
  2365. // Number of physical processors in a non-Intel system
  2366. // or in a 32-bit Intel system with Hyper-Threading technology disabled
  2367. this->NumberOfPhysicalCPU = (unsigned char) info.dwNumberOfProcessors;
  2368. if (this->IsHyperThreadingSupported())
  2369. {
  2370. unsigned char HT_Enabled = 0;
  2371. this->NumberOfLogicalCPU = this->LogicalCPUPerPhysicalCPU();
  2372. if (this->NumberOfLogicalCPU >= 1) // >1 Doesn't mean HT is enabled in the BIOS
  2373. {
  2374. HANDLE hCurrentProcessHandle;
  2375. #ifndef _WIN64
  2376. # define DWORD_PTR DWORD
  2377. #endif
  2378. DWORD_PTR dwProcessAffinity;
  2379. DWORD_PTR dwSystemAffinity;
  2380. DWORD dwAffinityMask;
  2381. // Calculate the appropriate shifts and mask based on the
  2382. // number of logical processors.
  2383. unsigned int i = 1;
  2384. unsigned char PHY_ID_MASK = 0xFF;
  2385. //unsigned char PHY_ID_SHIFT = 0;
  2386. while (i < this->NumberOfLogicalCPU)
  2387. {
  2388. i *= 2;
  2389. PHY_ID_MASK <<= 1;
  2390. // PHY_ID_SHIFT++;
  2391. }
  2392. hCurrentProcessHandle = GetCurrentProcess();
  2393. GetProcessAffinityMask(hCurrentProcessHandle, &dwProcessAffinity,
  2394. &dwSystemAffinity);
  2395. // Check if available process affinity mask is equal to the
  2396. // available system affinity mask
  2397. if (dwProcessAffinity != dwSystemAffinity)
  2398. {
  2399. StatusFlag = HT_CANNOT_DETECT;
  2400. this->NumberOfPhysicalCPU = (unsigned char)-1;
  2401. return StatusFlag;
  2402. }
  2403. dwAffinityMask = 1;
  2404. while (dwAffinityMask != 0 && dwAffinityMask <= dwProcessAffinity)
  2405. {
  2406. // Check if this CPU is available
  2407. if (dwAffinityMask & dwProcessAffinity)
  2408. {
  2409. if (SetProcessAffinityMask(hCurrentProcessHandle,
  2410. dwAffinityMask))
  2411. {
  2412. unsigned char APIC_ID, LOG_ID;
  2413. Sleep(0); // Give OS time to switch CPU
  2414. APIC_ID = GetAPICId();
  2415. LOG_ID = APIC_ID & ~PHY_ID_MASK;
  2416. if (LOG_ID != 0)
  2417. {
  2418. HT_Enabled = 1;
  2419. }
  2420. }
  2421. }
  2422. dwAffinityMask = dwAffinityMask << 1;
  2423. }
  2424. // Reset the processor affinity
  2425. SetProcessAffinityMask(hCurrentProcessHandle, dwProcessAffinity);
  2426. if (this->NumberOfLogicalCPU == 1) // Normal P4 : HT is disabled in hardware
  2427. {
  2428. StatusFlag = HT_DISABLED;
  2429. }
  2430. else
  2431. {
  2432. if (HT_Enabled)
  2433. {
  2434. // Total physical processors in a Hyper-Threading enabled system.
  2435. this->NumberOfPhysicalCPU /= (this->NumberOfLogicalCPU);
  2436. StatusFlag = HT_ENABLED;
  2437. }
  2438. else
  2439. {
  2440. StatusFlag = HT_SUPPORTED_NOT_ENABLED;
  2441. }
  2442. }
  2443. }
  2444. }
  2445. else
  2446. {
  2447. // Processors do not have Hyper-Threading technology
  2448. StatusFlag = HT_NOT_CAPABLE;
  2449. this->NumberOfLogicalCPU = 1;
  2450. }
  2451. return StatusFlag;
  2452. #else
  2453. return 0;
  2454. #endif
  2455. }
  2456. /** Return the number of logical CPUs on the system */
  2457. unsigned int SystemInformationImplementation::GetNumberOfLogicalCPU()
  2458. {
  2459. return this->NumberOfLogicalCPU;
  2460. }
  2461. /** Return the number of physical CPUs on the system */
  2462. unsigned int SystemInformationImplementation::GetNumberOfPhysicalCPU()
  2463. {
  2464. return this->NumberOfPhysicalCPU;
  2465. }
  2466. /** For Mac use sysctlbyname calls to find system info */
  2467. bool SystemInformationImplementation::ParseSysCtl()
  2468. {
  2469. #if defined(__APPLE__)
  2470. int err = 0;
  2471. uint64_t value = 0;
  2472. size_t len = sizeof(value);
  2473. sysctlbyname("hw.memsize", &value, &len, NULL, 0);
  2474. this->TotalPhysicalMemory = value/1048576;
  2475. // Parse values for Mac
  2476. this->AvailablePhysicalMemory = 0;
  2477. vm_statistics_data_t vmstat;
  2478. mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
  2479. if ( host_statistics(mach_host_self(), HOST_VM_INFO,
  2480. (host_info_t) &vmstat, &count) == KERN_SUCCESS )
  2481. {
  2482. err = sysctlbyname("hw.pagesize", &value, &len, NULL, 0);
  2483. int64_t available_memory = vmstat.free_count * value;
  2484. this->AvailablePhysicalMemory = available_memory / 1048576;
  2485. }
  2486. // Virtual memory.
  2487. int mib[2] = { CTL_VM, VM_SWAPUSAGE };
  2488. size_t miblen = sizeof(mib) / sizeof(mib[0]);
  2489. struct xsw_usage swap;
  2490. len = sizeof(struct xsw_usage);
  2491. err = sysctl(mib, miblen, &swap, &len, NULL, 0);
  2492. if (err == 0)
  2493. {
  2494. this->AvailableVirtualMemory = swap.xsu_avail/1048576;
  2495. this->TotalVirtualMemory = swap.xsu_total/1048576;
  2496. }
  2497. // CPU Info
  2498. len = sizeof(this->NumberOfPhysicalCPU);
  2499. sysctlbyname("hw.physicalcpu", &this->NumberOfPhysicalCPU, &len, NULL, 0);
  2500. sysctlbyname("hw.logicalcpu", &this->NumberOfLogicalCPU, &len, NULL, 0);
  2501. this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical =
  2502. this->LogicalCPUPerPhysicalCPU();
  2503. len = sizeof(value);
  2504. sysctlbyname("hw.cpufrequency", &value, &len, NULL, 0);
  2505. this->CPUSpeedInMHz = value / 1048576;
  2506. // Chip family
  2507. len = sizeof(this->ChipID.Family);
  2508. //Seems only the intel chips will have this name so if this fails it is
  2509. //probably a PPC machine
  2510. err = sysctlbyname("machdep.cpu.family",
  2511. &this->ChipID.Family, &len, NULL, 0);
  2512. if (err != 0) // Go back to names we know but are less descriptive
  2513. {
  2514. this->ChipID.Family = 0;
  2515. char retBuf[32];
  2516. ::memset(retBuf, 0, 32);
  2517. len = 32;
  2518. err = sysctlbyname("hw.machine", &retBuf, &len, NULL, 0);
  2519. kwsys_stl::string machineBuf(retBuf);
  2520. if (machineBuf.find_first_of("Power") != kwsys_stl::string::npos)
  2521. {
  2522. strcpy(this->ChipID.Vendor, "IBM");
  2523. len = 4;
  2524. err = sysctlbyname("hw.cputype", &this->ChipID.Family, &len, NULL, 0);
  2525. err = sysctlbyname("hw.cpusubtype", &this->ChipID.Model, &len, NULL, 0);
  2526. this->FindManufacturer();
  2527. }
  2528. }
  2529. else // Should be an Intel Chip.
  2530. {
  2531. len = sizeof(this->ChipID.Family);
  2532. int err =
  2533. sysctlbyname("machdep.cpu.family", &this->ChipID.Family, &len, NULL, 0);
  2534. char retBuf[128];
  2535. ::memset(retBuf, 0, 128);
  2536. len = 128;
  2537. err = sysctlbyname("machdep.cpu.vendor", retBuf, &len, NULL, 0);
  2538. // Chip Vendor
  2539. strcpy(this->ChipID.Vendor,retBuf);
  2540. this->FindManufacturer();
  2541. len=CHIPNAME_STRING_LENGTH;
  2542. err =
  2543. sysctlbyname("machdep.cpu.brand_string",
  2544. this->ChipID.ProcessorName, &len, NULL, 0);
  2545. // Chip Model
  2546. len = sizeof(value);
  2547. err = sysctlbyname("machdep.cpu.model", &value, &len, NULL, 0);
  2548. this->ChipID.Model = value;
  2549. }
  2550. // Cache size
  2551. len = sizeof(value);
  2552. err = sysctlbyname("hw.l1icachesize", &value, &len, NULL, 0);
  2553. this->Features.L1CacheSize = value;
  2554. err = sysctlbyname("hw.l2cachesize", &value, &len, NULL, 0);
  2555. this->Features.L2CacheSize = value;
  2556. return true;
  2557. #else
  2558. return false;
  2559. #endif
  2560. }
  2561. /** Extract a value from sysctl command */
  2562. kwsys_stl::string SystemInformationImplementation::ExtractValueFromSysCtl(const char* word)
  2563. {
  2564. size_t pos = this->SysCtlBuffer.find(word);
  2565. if(pos != this->SysCtlBuffer.npos)
  2566. {
  2567. pos = this->SysCtlBuffer.find(": ",pos);
  2568. size_t pos2 = this->SysCtlBuffer.find("\n",pos);
  2569. if(pos!=this->SysCtlBuffer.npos && pos2!=this->SysCtlBuffer.npos)
  2570. {
  2571. return this->SysCtlBuffer.substr(pos+2,pos2-pos-2);
  2572. }
  2573. }
  2574. return "";
  2575. }
  2576. /** Run a given process */
  2577. kwsys_stl::string SystemInformationImplementation::RunProcess(kwsys_stl::vector<const char*> args)
  2578. {
  2579. kwsys_stl::string buffer = "";
  2580. // Run the application
  2581. kwsysProcess* gp = kwsysProcess_New();
  2582. kwsysProcess_SetCommand(gp, &*args.begin());
  2583. kwsysProcess_SetOption(gp,kwsysProcess_Option_HideWindow,1);
  2584. kwsysProcess_Execute(gp);
  2585. char* data = NULL;
  2586. int length;
  2587. double timeout = 255;
  2588. while(kwsysProcess_WaitForData(gp,&data,&length,&timeout)) // wait for 1s
  2589. {
  2590. for(int i=0;i<length;i++)
  2591. {
  2592. buffer += data[i];
  2593. }
  2594. }
  2595. kwsysProcess_WaitForExit(gp, 0);
  2596. int result = 0;
  2597. switch(kwsysProcess_GetState(gp))
  2598. {
  2599. case kwsysProcess_State_Exited:
  2600. {
  2601. result = kwsysProcess_GetExitValue(gp);
  2602. } break;
  2603. case kwsysProcess_State_Error:
  2604. {
  2605. kwsys_ios::cerr << "Error: Could not run " << args[0] << ":\n";
  2606. kwsys_ios::cerr << kwsysProcess_GetErrorString(gp) << "\n";
  2607. } break;
  2608. case kwsysProcess_State_Exception:
  2609. {
  2610. kwsys_ios::cerr << "Error: " << args[0]
  2611. << " terminated with an exception: "
  2612. << kwsysProcess_GetExceptionString(gp) << "\n";
  2613. } break;
  2614. case kwsysProcess_State_Starting:
  2615. case kwsysProcess_State_Executing:
  2616. case kwsysProcess_State_Expired:
  2617. case kwsysProcess_State_Killed:
  2618. {
  2619. // Should not get here.
  2620. kwsys_ios::cerr << "Unexpected ending state after running " << args[0]
  2621. << kwsys_ios::endl;
  2622. } break;
  2623. }
  2624. kwsysProcess_Delete(gp);
  2625. if(result)
  2626. {
  2627. kwsys_ios::cerr << "Error " << args[0] << " returned :" << result << "\n";
  2628. }
  2629. return buffer;
  2630. }
  2631. kwsys_stl::string SystemInformationImplementation::ParseValueFromKStat(const char* arguments)
  2632. {
  2633. kwsys_stl::vector<const char*> args;
  2634. args.clear();
  2635. args.push_back("kstat");
  2636. args.push_back("-p");
  2637. kwsys_stl::string command = arguments;
  2638. size_t start = command.npos;
  2639. size_t pos = command.find(' ',0);
  2640. while(pos!=command.npos)
  2641. {
  2642. bool inQuotes = false;
  2643. // Check if we are between quotes
  2644. size_t b0 = command.find('"',0);
  2645. size_t b1 = command.find('"',b0+1);
  2646. while(b0 != command.npos && b1 != command.npos && b1>b0)
  2647. {
  2648. if(pos>b0 && pos<b1)
  2649. {
  2650. inQuotes = true;
  2651. break;
  2652. }
  2653. b0 = command.find('"',b1+1);
  2654. b1 = command.find('"',b0+1);
  2655. }
  2656. if(!inQuotes)
  2657. {
  2658. kwsys_stl::string arg = command.substr(start+1,pos-start-1);
  2659. // Remove the quotes if any
  2660. size_t quotes = arg.find('"');
  2661. while(quotes != arg.npos)
  2662. {
  2663. arg.erase(quotes,1);
  2664. quotes = arg.find('"');
  2665. }
  2666. args.push_back(arg.c_str());
  2667. start = pos;
  2668. }
  2669. pos = command.find(' ',pos+1);
  2670. }
  2671. kwsys_stl::string lastArg = command.substr(start+1,command.size()-start-1);
  2672. args.push_back(lastArg.c_str());
  2673. args.push_back(0);
  2674. kwsys_stl::string buffer = this->RunProcess(args);
  2675. kwsys_stl::string value = "";
  2676. for(size_t i=buffer.size()-1;i>0;i--)
  2677. {
  2678. if(buffer[i] == ' ' || buffer[i] == '\t')
  2679. {
  2680. break;
  2681. }
  2682. if(buffer[i] != '\n' && buffer[i] != '\r')
  2683. {
  2684. kwsys_stl::string val = value;
  2685. value = buffer[i];
  2686. value += val;
  2687. }
  2688. }
  2689. return value;
  2690. }
  2691. /** Querying for system information from Solaris */
  2692. bool SystemInformationImplementation::QuerySolarisInfo()
  2693. {
  2694. // Parse values
  2695. this->NumberOfPhysicalCPU = static_cast<unsigned int>(
  2696. atoi(this->ParseValueFromKStat("-n syste_misc -s ncpus").c_str()));
  2697. this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU;
  2698. if(this->NumberOfPhysicalCPU!=0)
  2699. {
  2700. this->NumberOfLogicalCPU /= this->NumberOfPhysicalCPU;
  2701. }
  2702. this->CPUSpeedInMHz = static_cast<float>(atoi(this->ParseValueFromKStat("-s clock_MHz").c_str()));
  2703. // Chip family
  2704. this->ChipID.Family = 0;
  2705. // Chip Vendor
  2706. strcpy(this->ChipID.Vendor,"Sun");
  2707. this->FindManufacturer();
  2708. // Chip Model
  2709. sprintf(this->ChipID.ProcessorName,"%s",this->ParseValueFromKStat("-s cpu_type").c_str());
  2710. this->ChipID.Model = 0;
  2711. // Cache size
  2712. this->Features.L1CacheSize = 0;
  2713. this->Features.L2CacheSize = 0;
  2714. char* tail;
  2715. unsigned long totalMemory =
  2716. strtoul(this->ParseValueFromKStat("-s physmem").c_str(),&tail,0);
  2717. this->TotalPhysicalMemory = totalMemory/1024;
  2718. this->TotalPhysicalMemory *= 8192;
  2719. this->TotalPhysicalMemory /= 1024;
  2720. // Undefined values (for now at least)
  2721. this->TotalVirtualMemory = 0;
  2722. this->AvailablePhysicalMemory = 0;
  2723. this->AvailableVirtualMemory = 0;
  2724. return true;
  2725. }
  2726. /** Querying for system information from Haiku OS */
  2727. bool SystemInformationImplementation::QueryHaikuInfo()
  2728. {
  2729. #if defined(__HAIKU__)
  2730. system_info info;
  2731. get_system_info(&info);
  2732. this->NumberOfPhysicalCPU = info.cpu_count;
  2733. this->CPUSpeedInMHz = info.cpu_clock_speed / 1000000.0F;
  2734. // Physical Memory
  2735. this->TotalPhysicalMemory = (info.max_pages * B_PAGE_SIZE) / (1024 * 1024) ;
  2736. this->AvailablePhysicalMemory = this->TotalPhysicalMemory -
  2737. ((info.used_pages * B_PAGE_SIZE) / (1024 * 1024));
  2738. // NOTE: get_system_info_etc is currently a private call so just set to 0
  2739. // until it becomes public
  2740. this->TotalVirtualMemory = 0;
  2741. this->AvailableVirtualMemory = 0;
  2742. // Retrieve cpuid_info union for cpu 0
  2743. cpuid_info cpu_info;
  2744. get_cpuid(&cpu_info, 0, 0);
  2745. // Chip Vendor
  2746. // Use a temporary buffer so that we can add NULL termination to the string
  2747. char vbuf[13];
  2748. strncpy(vbuf, cpu_info.eax_0.vendor_id, 12);
  2749. vbuf[12] = '\0';
  2750. strcpy(this->ChipID.Vendor,vbuf);
  2751. this->FindManufacturer();
  2752. // Retrieve cpuid_info union for cpu 0 this time using a register value of 1
  2753. get_cpuid(&cpu_info, 1, 0);
  2754. this->NumberOfLogicalCPU = cpu_info.eax_1.logical_cpus;
  2755. // Chip type
  2756. this->ChipID.Type = cpu_info.eax_1.type;
  2757. // Chip family
  2758. this->ChipID.Family = cpu_info.eax_1.family;
  2759. // Chip Model
  2760. this->ChipID.Model = cpu_info.eax_1.model;
  2761. // Chip Revision
  2762. this->ChipID.Revision = cpu_info.eax_1.stepping;
  2763. // Chip Extended Family
  2764. this->ChipID.ExtendedFamily = cpu_info.eax_1.extended_family;
  2765. // Chip Extended Model
  2766. this->ChipID.ExtendedModel = cpu_info.eax_1.extended_model;
  2767. // Get ChipID.ProcessorName from other information already gathered
  2768. this->RetrieveClassicalCPUIdentity();
  2769. // Cache size
  2770. this->Features.L1CacheSize = 0;
  2771. this->Features.L2CacheSize = 0;
  2772. #endif
  2773. return true;
  2774. }
  2775. /** Query the operating system information */
  2776. bool SystemInformationImplementation::QueryOSInformation()
  2777. {
  2778. #if _WIN32
  2779. this->OSName = "Windows";
  2780. OSVERSIONINFOEX osvi;
  2781. BOOL bIsWindows64Bit;
  2782. BOOL bOsVersionInfoEx;
  2783. char operatingSystem[256];
  2784. // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
  2785. ZeroMemory (&osvi, sizeof (OSVERSIONINFOEX));
  2786. osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX);
  2787. bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi);
  2788. if (!bOsVersionInfoEx)
  2789. {
  2790. osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
  2791. if (!GetVersionEx ((OSVERSIONINFO *) &osvi))
  2792. {
  2793. return false;
  2794. }
  2795. }
  2796. switch (osvi.dwPlatformId)
  2797. {
  2798. case VER_PLATFORM_WIN32_NT:
  2799. // Test for the product.
  2800. if (osvi.dwMajorVersion <= 4)
  2801. {
  2802. this->OSRelease = "NT";
  2803. }
  2804. if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
  2805. {
  2806. this->OSRelease = "2000";
  2807. }
  2808. if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
  2809. {
  2810. this->OSRelease = "XP";
  2811. }
  2812. #ifdef VER_NT_WORKSTATION
  2813. // Test for product type.
  2814. if (bOsVersionInfoEx)
  2815. {
  2816. if (osvi.wProductType == VER_NT_WORKSTATION)
  2817. {
  2818. if (osvi.dwMajorVersion == 6)
  2819. {
  2820. this->OSRelease = "Vista";
  2821. }
  2822. // VER_SUITE_PERSONAL may not be defined
  2823. #ifdef VER_SUITE_PERSONAL
  2824. else
  2825. {
  2826. if (osvi.wSuiteMask & VER_SUITE_PERSONAL)
  2827. {
  2828. this->OSRelease += " Personal";
  2829. }
  2830. else
  2831. {
  2832. this->OSRelease += " Professional";
  2833. }
  2834. }
  2835. #endif
  2836. }
  2837. else if (osvi.wProductType == VER_NT_SERVER)
  2838. {
  2839. // Check for .NET Server instead of Windows XP.
  2840. if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
  2841. {
  2842. this->OSRelease = ".NET";
  2843. }
  2844. // Continue with the type detection.
  2845. if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
  2846. {
  2847. this->OSRelease += " DataCenter Server";
  2848. }
  2849. else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
  2850. {
  2851. this->OSRelease += " Advanced Server";
  2852. }
  2853. else
  2854. {
  2855. this->OSRelease += " Server";
  2856. }
  2857. }
  2858. sprintf (operatingSystem, "%s (Build %ld)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
  2859. this->OSVersion = operatingSystem;
  2860. }
  2861. else
  2862. #endif // VER_NT_WORKSTATION
  2863. {
  2864. HKEY hKey;
  2865. char szProductType[80];
  2866. DWORD dwBufLen;
  2867. // Query the registry to retrieve information.
  2868. RegOpenKeyEx (HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 0, KEY_QUERY_VALUE, &hKey);
  2869. RegQueryValueEx (hKey, "ProductType", NULL, NULL, (LPBYTE) szProductType, &dwBufLen);
  2870. RegCloseKey (hKey);
  2871. if (lstrcmpi ("WINNT", szProductType) == 0)
  2872. {
  2873. this->OSRelease += " Professional";
  2874. }
  2875. if (lstrcmpi ("LANMANNT", szProductType) == 0)
  2876. {
  2877. // Decide between Windows 2000 Advanced Server and Windows .NET Enterprise Server.
  2878. if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
  2879. {
  2880. this->OSRelease += " Standard Server";
  2881. }
  2882. else
  2883. {
  2884. this->OSRelease += " Server";
  2885. }
  2886. }
  2887. if (lstrcmpi ("SERVERNT", szProductType) == 0)
  2888. {
  2889. // Decide between Windows 2000 Advanced Server and Windows .NET Enterprise Server.
  2890. if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
  2891. {
  2892. this->OSRelease += " Enterprise Server";
  2893. }
  2894. else
  2895. {
  2896. this->OSRelease += " Advanced Server";
  2897. }
  2898. }
  2899. }
  2900. // Display version, service pack (if any), and build number.
  2901. if (osvi.dwMajorVersion <= 4)
  2902. {
  2903. // NB: NT 4.0 and earlier.
  2904. sprintf (operatingSystem, "version %ld.%ld %s (Build %ld)",
  2905. osvi.dwMajorVersion,
  2906. osvi.dwMinorVersion,
  2907. osvi.szCSDVersion,
  2908. osvi.dwBuildNumber & 0xFFFF);
  2909. this->OSVersion = operatingSystem;
  2910. }
  2911. else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
  2912. {
  2913. // Windows XP and .NET server.
  2914. typedef BOOL (CALLBACK* LPFNPROC) (HANDLE, BOOL *);
  2915. HINSTANCE hKernelDLL;
  2916. LPFNPROC DLLProc;
  2917. // Load the Kernel32 DLL.
  2918. hKernelDLL = LoadLibrary ("kernel32");
  2919. if (hKernelDLL != NULL) {
  2920. // Only XP and .NET Server support IsWOW64Process so... Load dynamically!
  2921. DLLProc = (LPFNPROC) GetProcAddress (hKernelDLL, "IsWow64Process");
  2922. // If the function address is valid, call the function.
  2923. if (DLLProc != NULL) (DLLProc) (GetCurrentProcess (), &bIsWindows64Bit);
  2924. else bIsWindows64Bit = false;
  2925. // Free the DLL module.
  2926. FreeLibrary (hKernelDLL);
  2927. }
  2928. }
  2929. else
  2930. {
  2931. // Windows 2000 and everything else.
  2932. sprintf (operatingSystem,"%s (Build %ld)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
  2933. this->OSVersion = operatingSystem;
  2934. }
  2935. break;
  2936. case VER_PLATFORM_WIN32_WINDOWS:
  2937. // Test for the product.
  2938. if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
  2939. {
  2940. this->OSRelease = "95";
  2941. if(osvi.szCSDVersion[1] == 'C')
  2942. {
  2943. this->OSRelease += "OSR 2.5";
  2944. }
  2945. else if(osvi.szCSDVersion[1] == 'B')
  2946. {
  2947. this->OSRelease += "OSR 2";
  2948. }
  2949. }
  2950. if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
  2951. {
  2952. this->OSRelease = "98";
  2953. if (osvi.szCSDVersion[1] == 'A' )
  2954. {
  2955. this->OSRelease += "SE";
  2956. }
  2957. }
  2958. if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
  2959. {
  2960. this->OSRelease = "Me";
  2961. }
  2962. break;
  2963. case VER_PLATFORM_WIN32s:
  2964. this->OSRelease = "Win32s";
  2965. break;
  2966. default:
  2967. this->OSRelease = "Unknown";
  2968. break;
  2969. }
  2970. // Get the hostname
  2971. WORD wVersionRequested;
  2972. WSADATA wsaData;
  2973. char name[255];
  2974. wVersionRequested = MAKEWORD(2,0);
  2975. if ( WSAStartup( wVersionRequested, &wsaData ) == 0 )
  2976. {
  2977. gethostname(name,sizeof(name));
  2978. WSACleanup( );
  2979. }
  2980. this->Hostname = name;
  2981. #else
  2982. struct utsname unameInfo;
  2983. int errorFlag = uname(&unameInfo);
  2984. if(errorFlag == 0)
  2985. {
  2986. this->OSName = unameInfo.sysname;
  2987. this->Hostname = unameInfo.nodename;
  2988. this->OSRelease = unameInfo.release;
  2989. this->OSVersion = unameInfo.version;
  2990. this->OSPlatform = unameInfo.machine;
  2991. }
  2992. #endif
  2993. return true;
  2994. }
  2995. /** Return true if the machine is 64 bits */
  2996. bool SystemInformationImplementation::Is64Bits()
  2997. {
  2998. return (sizeof(void*) == 8);
  2999. }
  3000. } // namespace @KWSYS_NAMESPACE@