annotate cpuinfo.c @ 30884:53901d222e8a

Announce SMP support for Win32. Don't hardcode dwNumberOfProcessors=1 for Win32 anymore; the mutex/event code is still far from perfect, but now good enough that I can't find any codecs that breaks with this (tested on a quad with various codecs). This tells codecs they can use more than one core if they want to (some already did, by launching multiple threads even when told there was only a single core).
author sesse
date Wed, 17 Mar 2010 23:33:26 +0000
parents f5ecd7dd58e8
children dd7f15a3fb1b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30429
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
1 /*
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
2 * small utility to extract CPU information
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
3 * Used by configure to set CPU optimization levels on some operating
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
4 * systems where /proc/cpuinfo is non-existent or unreliable.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
5 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
6 * This file is part of MPlayer.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
7 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
8 * MPlayer is free software; you can redistribute it and/or modify
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
9 * it under the terms of the GNU General Public License as published by
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
11 * (at your option) any later version.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
12 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
13 * MPlayer is distributed in the hope that it will be useful,
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
16 * GNU General Public License for more details.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
17 *
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
18 * You should have received a copy of the GNU General Public License along
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
c1a3f1bbba26 Add license header to all top-level files missing them.
diego
parents: 29072
diff changeset
21 */
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
22
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
23 #include <stdio.h>
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
24 #include <sys/time.h>
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
25 #include <stdlib.h>
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
26 #include <string.h>
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
27 #include <unistd.h>
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
28
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
29 #ifdef __MINGW32__
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
30 #define MISSING_USLEEP
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
31 #include <windows.h>
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
32 #define sleep(t) Sleep(1000*t);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
33 #endif
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
34
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
35 #ifdef __BEOS__
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
36 #define usleep(t) snooze(t)
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
37 #endif
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
38
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
39 #ifdef M_UNIX
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
40 typedef long long int64_t;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
41 #define MISSING_USLEEP
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
42 #else
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
43 #include <inttypes.h>
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
44 #endif
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
45
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
46 #define CPUID_FEATURE_DEF(bit, desc, description) \
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
47 { bit, desc }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
48
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
49 typedef struct cpuid_regs {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
50 unsigned int eax;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
51 unsigned int ebx;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
52 unsigned int ecx;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
53 unsigned int edx;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
54 } cpuid_regs_t;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
55
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
56 static cpuid_regs_t
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
57 cpuid(int func) {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
58 cpuid_regs_t regs;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
59 #define CPUID ".byte 0x0f, 0xa2; "
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
60 #ifdef __x86_64__
27754
08d18fe9da52 Change all occurrences of asm and __asm to __asm__, same as was done for FFmpeg.
diego
parents: 24964
diff changeset
61 __asm__("mov %%rbx, %%rsi\n\t"
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
62 #else
27754
08d18fe9da52 Change all occurrences of asm and __asm to __asm__, same as was done for FFmpeg.
diego
parents: 24964
diff changeset
63 __asm__("mov %%ebx, %%esi\n\t"
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
64 #endif
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
65 CPUID"\n\t"
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
66 #ifdef __x86_64__
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
67 "xchg %%rsi, %%rbx\n\t"
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
68 #else
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
69 "xchg %%esi, %%ebx\n\t"
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
70 #endif
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
71 : "=a" (regs.eax), "=S" (regs.ebx), "=c" (regs.ecx), "=d" (regs.edx)
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
72 : "0" (func));
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
73 return regs;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
74 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
75
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
76
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
77 static int64_t
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
78 rdtsc(void)
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
79 {
30715
f5ecd7dd58e8 10l correct type for =a and =d constraints under x86-32
zuxy
parents: 30714
diff changeset
80 uint32_t hi, lo;
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
81 #define RDTSC ".byte 0x0f, 0x31; "
30714
313cc6c3fddb Replace =A with =a and =d; make frequency calculation correct under x86-64
zuxy
parents: 30429
diff changeset
82 __asm__ volatile (RDTSC : "=a"(lo), "=d"(hi) : );
30715
f5ecd7dd58e8 10l correct type for =a and =d constraints under x86-32
zuxy
parents: 30714
diff changeset
83 return (uint64_t) hi << 32 | lo;
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
84 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
85
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
86 static const char*
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
87 brandname(int i)
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
88 {
28597
96dfe52d18ff cosmetics: const static --> static const, avoids the debug mode warning:
diego
parents: 27774
diff changeset
89 static const char* brandmap[] = {
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
90 NULL,
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
91 "Intel(R) Celeron(R) processor",
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
92 "Intel(R) Pentium(R) III processor",
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
93 "Intel(R) Pentium(R) III Xeon(tm) processor",
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
94 "Intel(R) Pentium(R) III processor",
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
95 NULL,
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
96 "Mobile Intel(R) Pentium(R) III processor-M",
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
97 "Mobile Intel(R) Celeron(R) processor"
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
98 };
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
99
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
100 if (i >= sizeof(brandmap))
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
101 return NULL;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
102 else
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
103 return brandmap[i];
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
104 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
105
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
106 static void
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
107 store32(char *d, unsigned int v)
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
108 {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
109 d[0] = v & 0xff;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
110 d[1] = (v >> 8) & 0xff;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
111 d[2] = (v >> 16) & 0xff;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
112 d[3] = (v >> 24) & 0xff;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
113 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
114
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
115
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
116 int
28599
3ff0da40013d cosmetics: Replace unused 'argc/argv' in main declarations by 'void'.
diego
parents: 28597
diff changeset
117 main(void)
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
118 {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
119 cpuid_regs_t regs, regs_ext;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
120 char idstr[13];
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
121 unsigned max_cpuid;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
122 unsigned max_ext_cpuid;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
123 unsigned int amd_flags;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
124 unsigned int amd_flags2;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
125 const char *model_name = NULL;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
126 int i;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
127 char processor_name[49];
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
128
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
129 regs = cpuid(0);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
130 max_cpuid = regs.eax;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
131 /* printf("%d CPUID function codes\n", max_cpuid+1); */
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
132
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
133 store32(idstr+0, regs.ebx);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
134 store32(idstr+4, regs.edx);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
135 store32(idstr+8, regs.ecx);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
136 idstr[12] = 0;
23346
932c22238e5d 10l: cosmetic: more trailing whitespaces removed
zuxy
parents: 23345
diff changeset
137 printf("vendor_id\t: %s\n", idstr);
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
138
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
139 regs_ext = cpuid((1<<31) + 0);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
140 max_ext_cpuid = regs_ext.eax;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
141 if (max_ext_cpuid >= (1<<31) + 1) {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
142 regs_ext = cpuid((1<<31) + 1);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
143 amd_flags = regs_ext.edx;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
144 amd_flags2 = regs_ext.ecx;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
145
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
146 if (max_ext_cpuid >= (1<<31) + 4) {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
147 for (i = 2; i <= 4; i++) {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
148 regs_ext = cpuid((1<<31) + i);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
149 store32(processor_name + (i-2)*16, regs_ext.eax);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
150 store32(processor_name + (i-2)*16 + 4, regs_ext.ebx);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
151 store32(processor_name + (i-2)*16 + 8, regs_ext.ecx);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
152 store32(processor_name + (i-2)*16 + 12, regs_ext.edx);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
153 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
154 processor_name[48] = 0;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
155 model_name = processor_name;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
156 while (*model_name == ' ') {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
157 model_name++;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
158 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
159 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
160 } else {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
161 amd_flags = 0;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
162 amd_flags2 = 0;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
163 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
164
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
165 if (max_cpuid >= 1) {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
166 static struct {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
167 int bit;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
168 char *desc;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
169 } cap[] = {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
170 CPUID_FEATURE_DEF(0, "fpu", "Floating-point unit on-chip"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
171 CPUID_FEATURE_DEF(1, "vme", "Virtual Mode Enhancements"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
172 CPUID_FEATURE_DEF(2, "de", "Debugging Extension"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
173 CPUID_FEATURE_DEF(3, "pse", "Page Size Extension"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
174 CPUID_FEATURE_DEF(4, "tsc", "Time Stamp Counter"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
175 CPUID_FEATURE_DEF(5, "msr", "Pentium Processor MSR"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
176 CPUID_FEATURE_DEF(6, "pae", "Physical Address Extension"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
177 CPUID_FEATURE_DEF(7, "mce", "Machine Check Exception"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
178 CPUID_FEATURE_DEF(8, "cx8", "CMPXCHG8B Instruction Supported"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
179 CPUID_FEATURE_DEF(9, "apic", "On-chip APIC Hardware Enabled"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
180 CPUID_FEATURE_DEF(11, "sep", "SYSENTER and SYSEXIT"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
181 CPUID_FEATURE_DEF(12, "mtrr", "Memory Type Range Registers"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
182 CPUID_FEATURE_DEF(13, "pge", "PTE Global Bit"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
183 CPUID_FEATURE_DEF(14, "mca", "Machine Check Architecture"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
184 CPUID_FEATURE_DEF(15, "cmov", "Conditional Move/Compare Instruction"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
185 CPUID_FEATURE_DEF(16, "pat", "Page Attribute Table"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
186 CPUID_FEATURE_DEF(17, "pse36", "Page Size Extension 36-bit"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
187 CPUID_FEATURE_DEF(18, "pn", "Processor Serial Number"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
188 CPUID_FEATURE_DEF(19, "clflush", "CFLUSH instruction"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
189 CPUID_FEATURE_DEF(21, "dts", "Debug Store"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
190 CPUID_FEATURE_DEF(22, "acpi", "Thermal Monitor and Clock Ctrl"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
191 CPUID_FEATURE_DEF(23, "mmx", "MMX Technology"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
192 CPUID_FEATURE_DEF(24, "fxsr", "FXSAVE/FXRSTOR"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
193 CPUID_FEATURE_DEF(25, "sse", "SSE Extensions"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
194 CPUID_FEATURE_DEF(26, "sse2", "SSE2 Extensions"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
195 CPUID_FEATURE_DEF(27, "ss", "Self Snoop"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
196 CPUID_FEATURE_DEF(28, "ht", "Multi-threading"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
197 CPUID_FEATURE_DEF(29, "tm", "Therm. Monitor"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
198 CPUID_FEATURE_DEF(30, "ia64", "IA-64 Processor"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
199 CPUID_FEATURE_DEF(31, "pbe", "Pend. Brk. EN."),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
200 { -1 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
201 };
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
202 static struct {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
203 int bit;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
204 char *desc;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
205 } cap2[] = {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
206 CPUID_FEATURE_DEF(0, "pni", "SSE3 Extensions"),
29072
4520c6c724a6 More flags; sync with Linux kernel.
zuxy
parents: 29038
diff changeset
207 CPUID_FEATURE_DEF(1, "pclmulqdq", "Carryless Multiplication"),
4520c6c724a6 More flags; sync with Linux kernel.
zuxy
parents: 29038
diff changeset
208 CPUID_FEATURE_DEF(2, "dtes64", "64-bit Debug Store"),
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
209 CPUID_FEATURE_DEF(3, "monitor", "MONITOR/MWAIT"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
210 CPUID_FEATURE_DEF(4, "ds_cpl", "CPL Qualified Debug Store"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
211 CPUID_FEATURE_DEF(5, "vmx", "Virtual Machine Extensions"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
212 CPUID_FEATURE_DEF(6, "smx", "Safer Mode Extensions"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
213 CPUID_FEATURE_DEF(7, "est", "Enhanced Intel SpeedStep Technology"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
214 CPUID_FEATURE_DEF(8, "tm2", "Thermal Monitor 2"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
215 CPUID_FEATURE_DEF(9, "ssse3", "Supplemental SSE3"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
216 CPUID_FEATURE_DEF(10, "cid", "L1 Context ID"),
29072
4520c6c724a6 More flags; sync with Linux kernel.
zuxy
parents: 29038
diff changeset
217 CPUID_FEATURE_DEF(12, "fma", "Fused Multiply Add"),
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
218 CPUID_FEATURE_DEF(13, "cx16", "CMPXCHG16B Available"),
23345
ec89cf1d721e Cosmetic: remove trailing whitespaces
zuxy
parents: 23344
diff changeset
219 CPUID_FEATURE_DEF(14, "xtpr", "xTPR Disable"),
ec89cf1d721e Cosmetic: remove trailing whitespaces
zuxy
parents: 23344
diff changeset
220 CPUID_FEATURE_DEF(15, "pdcm", "Perf/Debug Capability MSR"),
ec89cf1d721e Cosmetic: remove trailing whitespaces
zuxy
parents: 23344
diff changeset
221 CPUID_FEATURE_DEF(18, "dca", "Direct Cache Access"),
24964
195a578e07d4 Sync with Linux kernel with some latest feature bits.
zuxy
parents: 23804
diff changeset
222 CPUID_FEATURE_DEF(19, "sse4_1", "SSE4.1 Extensions"),
195a578e07d4 Sync with Linux kernel with some latest feature bits.
zuxy
parents: 23804
diff changeset
223 CPUID_FEATURE_DEF(20, "sse4_2", "SSE4.2 Extensions"),
29072
4520c6c724a6 More flags; sync with Linux kernel.
zuxy
parents: 29038
diff changeset
224 CPUID_FEATURE_DEF(21, "x2apic", "x2APIC Feature"),
4520c6c724a6 More flags; sync with Linux kernel.
zuxy
parents: 29038
diff changeset
225 CPUID_FEATURE_DEF(22, "movbe", "MOVBE Instruction"),
23345
ec89cf1d721e Cosmetic: remove trailing whitespaces
zuxy
parents: 23344
diff changeset
226 CPUID_FEATURE_DEF(23, "popcnt", "Pop Count Instruction"),
29072
4520c6c724a6 More flags; sync with Linux kernel.
zuxy
parents: 29038
diff changeset
227 CPUID_FEATURE_DEF(25, "aes", "AES Instruction"),
4520c6c724a6 More flags; sync with Linux kernel.
zuxy
parents: 29038
diff changeset
228 CPUID_FEATURE_DEF(26, "xsave", "XSAVE/XRSTOR Extensions"),
4520c6c724a6 More flags; sync with Linux kernel.
zuxy
parents: 29038
diff changeset
229 CPUID_FEATURE_DEF(27, "osxsave", "XSAVE/XRSTOR Enabled in the OS"),
4520c6c724a6 More flags; sync with Linux kernel.
zuxy
parents: 29038
diff changeset
230 CPUID_FEATURE_DEF(28, "avx", "Advanced Vector Extension"),
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
231 { -1 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
232 };
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
233 static struct {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
234 int bit;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
235 char *desc;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
236 } cap_amd[] = {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
237 CPUID_FEATURE_DEF(11, "syscall", "SYSCALL and SYSRET"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
238 CPUID_FEATURE_DEF(19, "mp", "MP Capable"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
239 CPUID_FEATURE_DEF(20, "nx", "No-Execute Page Protection"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
240 CPUID_FEATURE_DEF(22, "mmxext", "MMX Technology (AMD Extensions)"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
241 CPUID_FEATURE_DEF(25, "fxsr_opt", "Fast FXSAVE/FXRSTOR"),
23344
57692910afd4 New tags introduced for AMD K10 and Intel Penryn
zuxy
parents: 23009
diff changeset
242 CPUID_FEATURE_DEF(26, "pdpe1gb", "PDP Entry for 1GiB Page"),
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
243 CPUID_FEATURE_DEF(27, "rdtscp", "RDTSCP Instruction"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
244 CPUID_FEATURE_DEF(29, "lm", "Long Mode Capable"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
245 CPUID_FEATURE_DEF(30, "3dnowext", "3DNow! Extensions"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
246 CPUID_FEATURE_DEF(31, "3dnow", "3DNow!"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
247 { -1 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
248 };
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
249 static struct {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
250 int bit;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
251 char *desc;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
252 } cap_amd2[] = {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
253 CPUID_FEATURE_DEF(0, "lahf_lm", "LAHF/SAHF Supported in 64-bit Mode"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
254 CPUID_FEATURE_DEF(1, "cmp_legacy", "Chip Multi-Core"),
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
255 CPUID_FEATURE_DEF(2, "svm", "Secure Virtual Machine"),
23344
57692910afd4 New tags introduced for AMD K10 and Intel Penryn
zuxy
parents: 23009
diff changeset
256 CPUID_FEATURE_DEF(3, "extapic", "Extended APIC Space"),
29072
4520c6c724a6 More flags; sync with Linux kernel.
zuxy
parents: 29038
diff changeset
257 CPUID_FEATURE_DEF(4, "cr8_legacy", "CR8 Available in Legacy Mode"),
23344
57692910afd4 New tags introduced for AMD K10 and Intel Penryn
zuxy
parents: 23009
diff changeset
258 CPUID_FEATURE_DEF(5, "abm", "Advanced Bit Manipulation"),
57692910afd4 New tags introduced for AMD K10 and Intel Penryn
zuxy
parents: 23009
diff changeset
259 CPUID_FEATURE_DEF(6, "sse4a", "SSE4A Extensions"),
57692910afd4 New tags introduced for AMD K10 and Intel Penryn
zuxy
parents: 23009
diff changeset
260 CPUID_FEATURE_DEF(7, "misalignsse", "Misaligned SSE Mode"),
57692910afd4 New tags introduced for AMD K10 and Intel Penryn
zuxy
parents: 23009
diff changeset
261 CPUID_FEATURE_DEF(8, "3dnowprefetch", "3DNow! Prefetch/PrefetchW"),
57692910afd4 New tags introduced for AMD K10 and Intel Penryn
zuxy
parents: 23009
diff changeset
262 CPUID_FEATURE_DEF(9, "osvw", "OS Visible Workaround"),
23804
10ac5a193118 Explanation for CPUID flag 'ibs'
zuxy
parents: 23346
diff changeset
263 CPUID_FEATURE_DEF(10, "ibs", "Instruction Based Sampling"),
24964
195a578e07d4 Sync with Linux kernel with some latest feature bits.
zuxy
parents: 23804
diff changeset
264 CPUID_FEATURE_DEF(11, "sse5", "SSE5 Extensions"),
195a578e07d4 Sync with Linux kernel with some latest feature bits.
zuxy
parents: 23804
diff changeset
265 CPUID_FEATURE_DEF(12, "skinit", "SKINIT, STGI, and DEV Support"),
195a578e07d4 Sync with Linux kernel with some latest feature bits.
zuxy
parents: 23804
diff changeset
266 CPUID_FEATURE_DEF(13, "wdt", "Watchdog Timer Support"),
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
267 { -1 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
268 };
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
269 unsigned int family, model, stepping;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
270
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
271 regs = cpuid(1);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
272 family = (regs.eax >> 8) & 0xf;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
273 model = (regs.eax >> 4) & 0xf;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
274 stepping = regs.eax & 0xf;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
275
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
276 if (family == 0xf)
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
277 family += (regs.eax >> 20) & 0xff;
23009
41d042563508 Intel's Conroe-L makes use of extended models, so adjust CPU detection
diego
parents: 22932
diff changeset
278 if (family == 0xf || family == 6)
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
279 model += ((regs.eax >> 16) & 0xf) << 4;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
280
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
281 printf("cpu family\t: %d\n"
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
282 "model\t\t: %d\n"
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
283 "stepping\t: %d\n" ,
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
284 family,
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
285 model,
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
286 stepping);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
287
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
288 if (strstr(idstr, "Intel") && !model_name) {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
289 if (family == 6 && model == 0xb && stepping == 1)
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
290 model_name = "Intel (R) Celeron (R) processor";
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
291 else
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
292 model_name = brandname(regs.ebx & 0xf);
23346
932c22238e5d 10l: cosmetic: more trailing whitespaces removed
zuxy
parents: 23345
diff changeset
293 }
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
294
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
295 printf("flags\t\t:");
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
296 for (i = 0; cap[i].bit >= 0; i++) {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
297 if (regs.edx & (1 << cap[i].bit)) {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
298 printf(" %s", cap[i].desc);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
299 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
300 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
301 for (i = 0; cap2[i].bit >= 0; i++) {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
302 if (regs.ecx & (1 << cap2[i].bit)) {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
303 printf(" %s", cap2[i].desc);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
304 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
305 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
306 /* k6_mtrr is supported by some AMD K6-2/K6-III CPUs but
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
307 it is not indicated by a CPUID feature bit, so we
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
308 have to check the family, model and stepping instead. */
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
309 if (strstr(idstr, "AMD") &&
23346
932c22238e5d 10l: cosmetic: more trailing whitespaces removed
zuxy
parents: 23345
diff changeset
310 family == 5 &&
28931
8912d496b5e2 Add some parentheses to silence the warnings:
diego
parents: 28599
diff changeset
311 (model >= 9 || (model == 8 && stepping >= 8)))
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
312 printf(" %s", "k6_mtrr");
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
313 /* similar for cyrix_arr. */
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
314 if (strstr(idstr, "Cyrix") &&
28931
8912d496b5e2 Add some parentheses to silence the warnings:
diego
parents: 28599
diff changeset
315 (family == 5 && (model < 4 || family == 6)))
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
316 printf(" %s", "cyrix_arr");
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
317 /* as well as centaur_mcr. */
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
318 if (strstr(idstr, "Centaur") &&
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
319 family == 5)
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
320 printf(" %s", "centaur_mcr");
23346
932c22238e5d 10l: cosmetic: more trailing whitespaces removed
zuxy
parents: 23345
diff changeset
321
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
322 for (i = 0; cap_amd[i].bit >= 0; i++) {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
323 if (amd_flags & (1 << cap_amd[i].bit)) {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
324 printf(" %s", cap_amd[i].desc);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
325 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
326 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
327 for (i = 0; cap_amd2[i].bit >= 0; i++) {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
328 if (amd_flags2 & (1 << cap_amd2[i].bit)) {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
329 printf(" %s", cap_amd2[i].desc);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
330 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
331 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
332 printf("\n");
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
333
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
334 if (regs.edx & (1 << 4)) {
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
335 int64_t tsc_start, tsc_end;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
336 struct timeval tv_start, tv_end;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
337 int usec_delay;
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
338
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
339 tsc_start = rdtsc();
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
340 gettimeofday(&tv_start, NULL);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
341 #ifdef MISSING_USLEEP
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
342 sleep(1);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
343 #else
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
344 usleep(100000);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
345 #endif
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
346 tsc_end = rdtsc();
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
347 gettimeofday(&tv_end, NULL);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
348
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
349 usec_delay = 1000000 * (tv_end.tv_sec - tv_start.tv_sec)
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
350 + (tv_end.tv_usec - tv_start.tv_usec);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
351
23345
ec89cf1d721e Cosmetic: remove trailing whitespaces
zuxy
parents: 23344
diff changeset
352 printf("cpu MHz\t\t: %.3f\n",
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
353 (double)(tsc_end-tsc_start) / usec_delay);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
354 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
355 }
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
356
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
357 printf("model name\t: ");
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
358 if (model_name)
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
359 printf("%s\n", model_name);
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
360 else
23346
932c22238e5d 10l: cosmetic: more trailing whitespaces removed
zuxy
parents: 23345
diff changeset
361 printf("Unknown %s CPU\n", idstr);
22932
d8cfd3a1300e Move TOOLS/cpuinfo.c into the root directory.
diego
parents:
diff changeset
362 }