1
/* Re-written from scratch 3 March 2001 */
2
/* Handles intel chips on Linux architecture */
3
/* by Vince Weaver <vince@deater.net> */
7
#include <stdlib.h> /* atof */
9
#include "../sysinfo.h"
10
#include "../include/generic.h"
12
int get_cpu_info(cpu_info_t *cpu_info) {
15
char temp_string[256];
16
char vendor_string[256],model_string[256],plain_model[256];
19
float megahertz=0.0,bogomips=0.0;
21
vendor_string[0]=model_string[0]=plain_model[0]=0;
23
/* We get all of our info here from /proc/cpuinfo */
24
if ((fff=fopen(get_cpuinfo_file(),"r") )!=NULL) {
26
while ( (fgets(temp_string,255,fff)!=NULL) ) {
28
if (cpu_count==0) { /* Assume all CPU's in SMP system are the same */
29
if ( !(strncmp(temp_string,"vendor_id",9)) ||
30
!(strncmp(temp_string,"vid",3)) ) { /* 1.2.13 kernels */
31
strncpy(vendor_string,parse_line(temp_string),255);
34
if ( !(strncmp(temp_string,"model name",9)) ) {
35
strncpy(model_string,parse_line(temp_string),255);
36
clip_lf(model_string,255);
38
else { /* for older (pre 2.2.x) kernels */
39
if (!(strncmp(temp_string,"model",5))) {
40
if (strncmp(parse_line(temp_string),"unknown",7)) {
41
strncpy(plain_model,parse_line(temp_string),255);
42
clip_lf(plain_model,255);
47
if ( !(strncmp(temp_string,"cpu MHz",6))) {
48
megahertz=atof(parse_line(temp_string));
51
/* We use this for cpu's w/o cpuinfo (386s and 486s) */
52
if ( !(strncmp(temp_string,"cpu family",10))) {
53
family=atoi(parse_line(temp_string));
55
/* Old legacy stuff (2.0.x kernels and earlier) */
56
if ( !(strncmp(temp_string,"cpu ",5))) {
57
strncpy(plain_model,parse_line(temp_string),255);
58
clip_lf(plain_model,255);
62
/* Ugh why must people play with capitalization */
63
if ( !(strncmp(temp_string,"bogomips",8)) ||
64
!(strncmp(temp_string,"BogoMips",8)) ||
65
!(strncmp(temp_string,"BogoMIPS",8))) {
66
bogomips+=atof(parse_line(temp_string));
67
cpu_count++; /* Cheating way to detect number of intel CPU's */
72
/* Re-arrange some of the strings for best results */
73
if (model_string[0]==0) { /* For 1.2.13 Kernels */
74
if (strlen(plain_model)>1) strncpy(model_string,plain_model,63);
77
if (model_string[0]==0) {
78
strncpy(cpu_info->chip_type,"Unknown",9);
80
else strncpy(cpu_info->chip_type,model_string,63);
82
strncpy(cpu_info->chip_vendor,"Unknown",9);
85
if (cpu_count<1) cpu_count=1;
87
cpu_info->num_cpus=cpu_count;
88
cpu_info->bogomips=bogomips;
90
/*********************************************************/
91
/* Vendor specific fixups */
92
/*********************************************************/
98
if (!strncmp(vendor_string,"AuthenticAMD",12)) {
99
strncpy(cpu_info->chip_vendor,"AMD",4);
101
if (!(strncmp(model_string,"AMD Sempron",11))) {
102
strncpy(cpu_info->chip_type,"Sempron",8);
105
/* Clean-up K6 model info */
106
if (strstr(model_string,"K6")!=NULL) {
108
strncpy(cpu_info->chip_type,"K6",3);
111
if ( !(strncmp(model_string,"AMD-K6tm",8)))
112
strncpy(cpu_info->chip_type,"K6",3);
114
/* Counter-intuitive, but the following are correct */
115
if ( !(strncmp(model_string,"AMD-K6(tm)-III",14)))
116
strncpy(cpu_info->chip_type,"K6-2+",6);
117
else if ( !(strncmp(model_string,"AMD-K6(tm)",10)))
118
strncpy(cpu_info->chip_type,"K6-2",5);
119
if ( !(strncmp(model_string,"K6-2",4)))
120
strncpy(cpu_info->chip_type,"K6-2",5);
121
if (strstr(model_string,"3D+")!=NULL) {
122
strncpy(cpu_info->chip_type,"K6-III",7);
127
if (strstr(model_string,"K5")!=NULL) {
128
strncpy(cpu_info->chip_type,"K5",3);
131
/* Some old K7's were reported as such */
132
if (strstr(model_string,"K7")!=NULL) {
133
strncpy(cpu_info->chip_type,"Athlon",7);
137
if (strstr(model_string,"Athlon(tm) 64")!=NULL) {
138
strncpy(cpu_info->chip_type,"Athlon 64",10);
140
if (strstr(model_string,"Athlon")!=NULL) {
141
strncpy(cpu_info->chip_type,"Athlon",7);
144
/* Specialty Athlons */
145
/* Should we support MP too? */
146
/* Should we decode the Speed ratings too (ie, 1600+) */
147
if (!strncmp(model_string,"AMD Athlon",10)) {
148
if (strstr(model_string,"XP")!=NULL) {
149
strncpy(cpu_info->chip_type,"Athlon XP",10);
154
if (strstr(model_string,"Duron")!=NULL) {
155
strncpy(cpu_info->chip_type,"Duron",6);
158
if (strstr(model_string,"Unknown")!=NULL) {
159
strncpy(cpu_info->chip_type,"Unknown",8);
163
if (strstr(model_string,"Opteron")!=NULL) {
164
strncpy(cpu_info->chip_type,"Opteron",8);
169
/* Work around old kernels */
170
if (model_string[0]==0) {
171
if (plain_model[0]=='9') {
172
strncpy(cpu_info->chip_type,"K6-III",7);
178
/* ***************** */
180
/* ***************** */
181
if ( !(strncmp(vendor_string,"CentaurHauls",12))) {
182
/* centaur cpuid is fully customizable, but this */
183
/* should catch the common case */
184
strncpy(cpu_info->chip_vendor,"Centaur",8);
186
/* Is this the proper thing to do? It looks silly */
187
/* calling them "Centaur VIA" chips */
188
if (strstr(model_string,"VIA")!=NULL) {
189
strncpy(cpu_info->chip_vendor,"VIA",4);
191
strcpy(cpu_info->chip_type,model_string+4);
195
/* *************** */
197
/* *************** */
198
if (!strncmp(vendor_string,"CyrixInstead",12)) {
199
strncpy(cpu_info->chip_vendor,"Cyrix",6);
201
if ( strstr(model_string,"MediaGX")!=NULL)
202
strncpy(cpu_info->chip_type,"MediaGX",8);
204
if ( strstr(model_string,"Geode")!=NULL)
205
strncpy(cpu_info->chip_type,"Geode",6);
207
if ( !(strncmp(model_string,"6x86L",5)))
208
strncpy(cpu_info->chip_type,"6x86",5);
209
if ( !(strncmp(model_string,"6x86M",5)))
210
strncpy(cpu_info->chip_type,"6x86MMX",8);
211
if ( !(strncmp(model_string,"M III",5)))
212
strncpy(cpu_info->chip_type,"MIII",5);
213
else if ( !(strncmp(model_string,"M II",4)))
214
strncpy(cpu_info->chip_type,"MII",4);
217
/* *************** */
219
/* *************** */
220
if (!strncmp(vendor_string,"GenuineIntel",12)) {
221
strncpy(cpu_info->chip_vendor,"Intel",6);
223
if (!(strncmp(model_string,"Pentium",7))) {
224
if (strstr(model_string,"75")!=NULL) {
225
strncpy(cpu_info->chip_type,"Pentium",8);
227
if (strstr(model_string,"90")!=NULL) {
228
strncpy(cpu_info->chip_type,"Pentium",8);
230
if (strstr(model_string,"Pro")!=NULL) {
231
strncpy(cpu_info->chip_type,"Pentium Pro",12);
233
if (strstr(model_string,"II")!=NULL) {
234
strncpy(cpu_info->chip_type,"Pentium II",11);
236
if (strstr(model_string,"III")!=NULL) {
237
strncpy(cpu_info->chip_type,"Pentium III",12);
239
if (strstr(model_string,"IV")!=NULL) {
240
strncpy(cpu_info->chip_type,"Pentium IV",11);
243
if (!(strncmp(model_string,"Intel(R) Pentium(R) 4",21))) {
244
strncpy(cpu_info->chip_type,"Pentium 4",10);
247
if (strstr(model_string,"Pentium(R) M")!=NULL) {
248
strncpy(cpu_info->chip_type,"Pentium M",10);
250
if (strstr(model_string,"Pentium(R) III")!=NULL) {
251
strncpy(cpu_info->chip_type,"Pentium III",12);
253
if (strstr(model_string,"Xeon(TM) MP")!=NULL) {
254
strncpy(cpu_info->chip_type,"Xeon MP",8);
256
if (strstr(model_string,"Pentium(R) 4 - M")!=NULL) {
257
strncpy(cpu_info->chip_type,"Pentium 4 M",12);
264
if ( !(strncmp(model_string,"Intel(R) Xeon(TM) CPU",21)) ||
265
!(strncmp(model_string,"Intel(R) Genuine CPU",19)) ||
266
!(strncmp(model_string,"Intel(R) XEON(TM)",17))) {
267
strncpy(cpu_info->chip_type,"Pentium 4 Xeon",16);
271
/* Should we handle all the various Celeron */
272
/* types separately?? */
273
if (strstr(model_string,"Celeron")!=NULL) {
274
strncpy(cpu_info->chip_type,"Celeron",8);
278
/* Fix up some older kernels */
279
if (model_string[0]==0) {
280
if (plain_model[0]=='5') {
281
strncpy(cpu_info->chip_type,"Pentium II",11);
284
if (!strncmp(model_string,"00/07",5)) {
285
strncpy(cpu_info->chip_type,"Pentium III",12);
292
if ( !(strncmp(vendor_string,"NexGenDriven",12))) {
293
strncpy(cpu_info->chip_vendor,"NexGen",7);
296
/* ********************************** */
297
/* National Semiconductor Geode Chips */
298
/* ********************************** */
299
if ( !(strncmp(vendor_string,"Geode by NSC",12))) {
300
strncpy(cpu_info->chip_vendor,"NSC",4);
301
strncpy(cpu_info->chip_type,"Geode",6);
307
if ( !(strncmp(vendor_string,"RiseRiseRise",12))) {
308
strncpy(cpu_info->chip_vendor,"Rise",5);
314
if ( !(strncmp(vendor_string,"GenuineTMx86",12)) ||
315
!(strncmp(vendor_string,"TransmetaCPU",12))) {
316
strncpy(cpu_info->chip_vendor,"Transmeta",10);
318
if (strstr(model_string,"Crusoe")!=NULL) {
319
strncpy(cpu_info->chip_type,"Crusoe",7);
326
if ( !(strncmp(vendor_string,"UMC UMC UMC",11))) {
327
strncpy(cpu_info->chip_vendor,"UMC",4);
329
if (!(strncmp(model_string,"SX",2))) {
330
strncpy(cpu_info->chip_type,"486SX",6);
334
/* ****************************** */
335
/* Try to handle cpus w/o cpuinfo */
336
/* ****************************** */
337
if ( !(strncmp(cpu_info->chip_vendor,"Unknown",7))) {
339
sprintf(temp_string,"%i86",family);
340
strncpy(cpu_info->chip_type,temp_string,4);
343
if (plain_model!=NULL) {
344
strncpy(cpu_info->chip_type,plain_model,63);
349
cpu_info->megahertz=0.0;
351
/* Handle Pretty_printing */
352
if (get_pretty_printing()) {
355
cpu_info->megahertz=fix_megahertz(25,megahertz);
358
/* restore RAW vendor string. Do we want this? */
359
strncpy(cpu_info->chip_type,model_string,64);
360
cpu_info->megahertz=megahertz;
366
/* Not implemented on ix86 */
367
int get_hardware_info(char hardware_string[256]) {
372
/* Some architectures might have better ways of detecting RAM size */
373
long int get_arch_specific_mem_size(void) {
374
/* We have no special way of detecting RAM */