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
|
/*
* $Id: x86info.c,v 1.74 2003/02/07 14:49:08 davej Exp $
* This file is part of x86info.
* (C) 2001 Dave Jones.
*
* Licensed under the terms of the GNU GPL License version 2.
*
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#ifndef linux
#ifdef __WIN32__
#include <sys/types.h>
#include <windows.h>
#else
#include <sys/types.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#endif /* __WIN32__ */
#endif /* linux */
#include "x86info.h"
int show_bench=0;
int show_bios=0;
int show_bluesmoke=0;
int show_bugs=0;
int show_cacheinfo=0;
int show_connector=0;
int show_eblcr=0;
int show_flags=0;
int show_msr=0;
int show_microcode=0;
int show_mtrr=0;
int show_pm=0;
int show_registers=0;
int show_urls=0;
static int show_mptable=0;
static int show_MHz=0;
int verbose=0;
int silent = 0;
int used_UP = 0;
int user_is_root = 1;
int need_root = 0;
unsigned int nrCPUs=1, nrSMPCPUs;
void usage (char *programname)
{
printf ("Usage: %s [<switches>]\n\
-a, --all\n\
--bench\n\
--bios\n\
--bugs\n\
-c, --cache\n\
--connector\n\
-f, --flags\n\
-mhz, --mhz\n\
--microcode\n\
-mp, --mptable\n\
-m, --msr\n\
--mult\n\
--mtrr\n\
--pm\n\
-r, --registers\n\
-s, --show-bluesmoke\n\
-u, --urls\n\
-v, --verbose\n\
\n", programname);
exit (0);
}
static void parse_command_line (int argc, char **argv)
{
char **argp, *arg;
for (argp = argv+1; argp <= argv + argc && (arg = *argp); argp++) {
if ((!strcmp(arg, "-a") || !strcmp(arg, "--all"))) {
show_bench = 1;
show_bios = 1;
show_bluesmoke = 1;
show_bugs = 1;
show_cacheinfo = 1;
show_connector = 1;
show_eblcr =1;
show_flags = 1;
show_microcode = 1;
show_mptable =1;
show_msr = 1;
show_MHz = 1;
show_mtrr = 1;
show_pm = 1;
show_registers = 1;
show_urls = 1;
need_root = 1;
}
if (!strcmp(arg, "--bench"))
show_bench = 1;
if (!strcmp(arg, "--bios")) {
need_root = 1;
show_bios = 1;
}
if (!strcmp(arg, "--bugs"))
show_bugs = 1;
if ((!strcmp(arg, "-c") || !strcmp(arg, "--cache")))
show_cacheinfo = 1;
if (!strcmp(arg, "--connector"))
show_connector = 1;
if ((!strcmp(arg, "-f") || !strcmp(arg, "--flags")))
show_flags = 1;
if ((!strcmp(arg, "-m") || !strcmp(arg, "--msr"))) {
need_root = 1;
show_msr = 1;
}
if (!strcmp(arg, "--microcode")) {
need_root = 1;
show_microcode = 1;
}
if ((!strcmp(arg, "-mhz") || !strcmp(arg, "--mhz")))
show_MHz = 1;
if ((!strcmp(arg, "-mp") || !strcmp(arg, "--mptable"))) {
need_root = 1;
show_mptable = 1;
}
if (!strcmp(arg, "--mtrr")) {
need_root = 1;
show_mtrr = 1;
}
if (!strcmp(arg, "--mult")) {
need_root = 1;
show_eblcr = 1;
}
if (!strcmp(arg, "--pm"))
show_pm = 1;
if ((!strcmp(arg, "-r") || !strcmp(arg, "--registers")))
show_registers = 1;
if ((!strcmp(arg, "-s") || !strcmp(arg, "--show-bluesmoke"))) {
need_root = 1;
show_bluesmoke = 1;
}
if ((!strcmp(arg, "-u") || !strcmp(arg, "--urls")))
show_urls = 1;
if ((!strcmp(arg, "-v") || !strcmp(arg, "--verbose")))
verbose = 1;
if ((!strcmp(arg, "?") || !strcmp(arg, "--help")))
usage(argv[0]);
}
}
void separator(void)
{
int j;
for (j=0; j<74; j++)
printf ("-");
printf ("\n");
}
int main (int argc, char **argv)
{
unsigned int i;
struct cpudata *cpu, *head=NULL, *tmp;
parse_command_line(argc, argv);
if (!silent) {
printf ("x86info v1.12. Dave Jones 2001-2003\n");
printf ("Feedback to <davej@suse.de>.\n\n");
}
if ((HaveCPUID())==0) {
printf ("No CPUID instruction available.\n");
printf ("No further information available for this CPU.\n");
return(0);
}
if (getuid()!=0)
user_is_root=0;
if (need_root && !user_is_root)
printf ("Need to be root to use specified options.\n");
#if defined __WIN32__
{
SYSTEM_INFO sys_info;
GetSystemInfo(&sys_info);
nrCPUs = sys_info.dwNumberOfProcessors;
}
#elif defined _SC_NPROCESSORS_CONF /* Linux */
nrCPUs = sysconf (_SC_NPROCESSORS_CONF);
#else /* BSD */
{
int mib[2] = { CTL_HW, HW_NCPU };
size_t len;
len = sizeof(nrCPUs);
sysctl(mib, 2, &nrCPUs, &len, NULL, 0);
}
#endif /* __WIN32__ */
if (!silent) {
printf ("Found %u CPU", nrCPUs);
if (nrCPUs > 1)
printf ("s");
/* Check mptable if present. This way we get number of CPUs
on SMP systems that have booted UP kernels. */
if (user_is_root) {
issmp (&nrSMPCPUs, 0);
if (nrSMPCPUs > nrCPUs) {
printf (", but found %d CPUs in MPTable.", nrSMPCPUs);
}
}
printf ("\n");
}
/*
* can't have less than 1 CPU, or more than
* 65535 (some arbitrary large number)
*/
if ((nrCPUs < 1) || (nrCPUs > 65535)) {
printf("CPU count is bogus: defaulting to 1 CPU.\n");
nrCPUs = 1;
}
if (show_mptable && user_is_root)
issmp (&nrSMPCPUs, 1);
separator();
/* Iterate over the linked list. */
for (i=0; i<nrCPUs; i++) {
cpu = malloc (sizeof (struct cpudata));
if (!cpu) {
printf ("Out of memory\n");
return -1;
}
memset (cpu, 0, sizeof(struct cpudata));
if (!head) {
head = cpu;
} else {
cpu->next = head;
head = cpu;
}
cpu->number = i;
if (!silent && nrCPUs!=1)
printf ("CPU #%u\n", i+1);
identify (cpu);
show_info (cpu);
/*
* Doing this per-cpu is a problem, as we can't
* schedule userspace code per-cpu.
* Although running nrCPUs * threads would probably work.
*
* Could also experiment with the new scheduler binding syscalls.
*/
if (show_MHz)
estimate_MHz(i);
if (show_bench)
show_benchmarks();
if (nrCPUs>1)
separator();
if (cpu->next)
cpu = cpu->next;
}
/* Tear down the linked list. */
cpu = head;
for (i=0; i<nrCPUs; i++) {
if (cpu->datasheet_url)
free(cpu->datasheet_url);
if (cpu->errata_url)
free(cpu->errata_url);
tmp = cpu->next;
free (cpu);
cpu = tmp;
}
if (nrCPUs > 1 && used_UP==1 && (!silent)) {
printf ("WARNING: Detected SMP, but unable to access cpuid driver.\n");
printf ("Used Uniprocessor CPU routines. Results inaccurate.\n");
}
return (0);
}
|