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