Merge lp:~noskcaj/ubuntu/saucy/i7z/i7z into lp:ubuntu/saucy/i7z
- Saucy (13.10)
- i7z
- Merge into saucy
Proposed by
Jackson Doak
Status: | Approved |
---|---|
Approved by: | Matt Fischer |
Approved revision: | 5 |
Proposed branch: | lp:~noskcaj/ubuntu/saucy/i7z/i7z |
Merge into: | lp:ubuntu/saucy/i7z |
Diff against target: |
4075 lines (+3363/-553) 21 files modified
.pc/applied-patches (+3/-1) .pc/fix-insecure-tempfile.patch/GUI/i7z_GUI.cpp (+687/-0) .pc/fix-insecure-tempfile.patch/helper_functions.c (+753/-0) .pc/fix-insecure-tempfile.patch/i7z_Single_Socket.c (+1216/-0) .pc/hyphen-used-as-minus-sign.patch/doc/i7z.man (+28/-0) .pc/install-i7z_rw_registers.patch/Makefile (+63/-0) .pc/install-i7z_rw_registers.patch/i7z_rw_registers.rb (+435/-0) .pc/install-i7z_rw_registers/Makefile (+0/-63) .pc/install-i7z_rw_registers/i7z_rw_registers.rb (+0/-435) GUI/i7z_GUI.cpp (+7/-8) debian/changelog (+16/-0) debian/control (+2/-2) debian/patches/fix-insecure-tempfile.patch (+76/-0) debian/patches/hyphen-used-as-minus-sign.patch (+28/-0) debian/patches/install-i7z_rw_registers (+0/-26) debian/patches/install-i7z_rw_registers.patch (+30/-0) debian/patches/series (+3/-1) debian/watch (+0/-1) doc/i7z.man (+9/-9) helper_functions.c (+4/-7) i7z_Single_Socket.c (+3/-0) |
To merge this branch: | bzr merge lp:~noskcaj/ubuntu/saucy/i7z/i7z |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Matt Fischer (community) | Approve | ||
Review via email: mp+180258@code.launchpad.net |
Commit message
Description of the change
Merge from debian unstable. Fixes an RC bug.
To post a comment you must log in.
lp:~noskcaj/ubuntu/saucy/i7z/i7z
updated
- 5. By Jackson Doak
-
Fix debian/control
Revision history for this message
Matt Fischer (mfisch) wrote : | # |
Looks good. Uploaded
review:
Approve
Unmerged revisions
- 5. By Jackson Doak
-
Fix debian/control
- 4. By Jackson Doak
-
* Merge from debian unstable. Remaining changes:
- debian/control: Future-proof by adding x32 to the architecture list
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file '.pc/applied-patches' |
2 | --- .pc/applied-patches 2013-03-16 21:16:14 +0000 |
3 | +++ .pc/applied-patches 2013-08-15 05:58:18 +0000 |
4 | @@ -1,1 +1,3 @@ |
5 | -install-i7z_rw_registers |
6 | +install-i7z_rw_registers.patch |
7 | +hyphen-used-as-minus-sign.patch |
8 | +fix-insecure-tempfile.patch |
9 | |
10 | === added directory '.pc/fix-insecure-tempfile.patch' |
11 | === added file '.pc/fix-insecure-tempfile.patch/.timestamp' |
12 | === added directory '.pc/fix-insecure-tempfile.patch/GUI' |
13 | === added file '.pc/fix-insecure-tempfile.patch/GUI/i7z_GUI.cpp' |
14 | --- .pc/fix-insecure-tempfile.patch/GUI/i7z_GUI.cpp 1970-01-01 00:00:00 +0000 |
15 | +++ .pc/fix-insecure-tempfile.patch/GUI/i7z_GUI.cpp 2013-08-15 05:58:18 +0000 |
16 | @@ -0,0 +1,687 @@ |
17 | +/* ----------------------------------------------------------------------- * |
18 | + * |
19 | + * Copyright 2009 Abhishek Jaiantilal |
20 | + * |
21 | + * Under GPL v2 |
22 | + * |
23 | + * ----------------------------------------------------------------------- */ |
24 | +#include <memory.h> |
25 | +#include <errno.h> |
26 | +#include <stdio.h> |
27 | +#include <fcntl.h> |
28 | +#include <unistd.h> |
29 | +#include <stdlib.h> |
30 | +#include <getopt.h> |
31 | +#include <inttypes.h> |
32 | +#include <sys/types.h> |
33 | +#include <sys/time.h> |
34 | +#include <time.h> |
35 | +#include <math.h> |
36 | + |
37 | +#include <QApplication> |
38 | +#include <QPushButton> |
39 | +#include <QProgressBar> |
40 | +#include <QWidget> |
41 | +#include <QVBoxLayout> |
42 | +#include <QGridLayout> |
43 | +#include <QLabel> |
44 | +#include <QThread> |
45 | +#include <QTimer> |
46 | +#include <QTime> |
47 | + |
48 | + |
49 | +#ifndef UINT32_MAX |
50 | +# define UINT32_MAX (4294967295U) |
51 | +#endif |
52 | +#include "../helper_functions.c" |
53 | + |
54 | +#define MAX_PROCESSORS_GUI 12 |
55 | + |
56 | +bool global_in_i7z_main_thread = false; |
57 | +int socket_list[MAX_PROCESSORS_GUI]; |
58 | +int core_list[MAX_PROCESSORS_GUI]; |
59 | +struct cpu_heirarchy_info chi; |
60 | +struct cpu_socket_info socket_0, socket_1; |
61 | +unsigned int numCPUs; |
62 | +struct program_options prog_options; |
63 | + |
64 | +void Construct_Socket_Information_in_GUI(unsigned int *numCPUs) { |
65 | + int socket_0_num=0, socket_1_num=1; |
66 | + socket_0.max_cpu=0; |
67 | + socket_0.socket_num=0; |
68 | + int i; |
69 | + for(i=0;i < 8; i++) |
70 | + socket_0.processor_num[i]=-1; |
71 | + socket_1.max_cpu=0; |
72 | + socket_1.socket_num=1; |
73 | + |
74 | + for(i=0;i < 8; i++) |
75 | + socket_1.processor_num[i]=-1; |
76 | + |
77 | + construct_CPU_Heirarchy_info(&chi); |
78 | + construct_sibling_list(&chi); |
79 | +// print_CPU_Heirarchy(chi); |
80 | + construct_socket_information(&chi, &socket_0, &socket_1, socket_0_num, socket_1_num); |
81 | +// print_socket_information(&socket_0); |
82 | +// print_socket_information(&socket_1); |
83 | + *numCPUs = socket_0.num_physical_cores + socket_1.num_physical_cores; |
84 | + |
85 | + //// FOR DEBUGGING DUAL SOCKET CODE ON SINGLE SOCKET, UNCOMMENT BELOW 2 lines |
86 | +// memcpy(&socket_1, &socket_0, sizeof(struct cpu_socket_info)); |
87 | +// socket_1.socket_num=0; |
88 | + |
89 | + |
90 | +// print_socket_information(&socket_0); |
91 | +// print_socket_information(&socket_1); |
92 | + *numCPUs = socket_0.num_physical_cores + socket_1.num_physical_cores; |
93 | +// printf("My Widget: Num Processors %d\n",*numCPUs); |
94 | + |
95 | + int k, ii; |
96 | + k=0; |
97 | + for (ii = 0; ii < socket_0.num_physical_cores ; ii++) { |
98 | + if ( socket_0.processor_num[ii] != -1) { |
99 | + core_list[k] = socket_0.processor_num[ii]; |
100 | + socket_list[k] = 0; |
101 | + k++; |
102 | + } |
103 | + } |
104 | + for (ii = 0; ii < socket_1.num_physical_cores ; ii++) { |
105 | + if ( socket_1.processor_num[ii] != -1) { |
106 | + core_list[k] = socket_1.processor_num[ii]; |
107 | + socket_list[k] = 1; |
108 | + k++; |
109 | + } |
110 | + } |
111 | +} |
112 | + |
113 | +class MyThread:public QThread |
114 | +{ |
115 | +public: |
116 | + MyThread (); |
117 | + void run (); |
118 | + double *FREQ, *MULT; |
119 | + long double *C0_TIME, *C1_TIME, *C3_TIME, *C6_TIME; |
120 | +}; |
121 | + |
122 | +MyThread::MyThread () |
123 | +{ |
124 | + Construct_Socket_Information_in_GUI(&numCPUs); |
125 | + |
126 | + //allocate space for the variables |
127 | + FREQ = (double *) malloc (sizeof (double) * numCPUs); |
128 | + MULT = (double *) malloc (sizeof (double) * numCPUs); |
129 | + C0_TIME = (long double *) malloc (sizeof (long double) * numCPUs); |
130 | + C1_TIME = (long double *) malloc (sizeof (long double) * numCPUs); |
131 | + C3_TIME = (long double *) malloc (sizeof (long double) * numCPUs); |
132 | + C6_TIME = (long double *) malloc (sizeof (long double) * numCPUs); |
133 | + |
134 | + int i; |
135 | + for (i = 0; i < (int)numCPUs; i++) |
136 | + { |
137 | + FREQ[i] = 0; |
138 | + MULT[i] = 0; |
139 | + C0_TIME[i] = 0; |
140 | + C1_TIME[i] = 0; |
141 | + C3_TIME[i] = 0; |
142 | + C6_TIME[i] = 0; |
143 | + } |
144 | +} |
145 | + |
146 | + |
147 | +void |
148 | +MyThread::run () |
149 | +{ |
150 | + |
151 | + print_CPU_Heirarchy(chi); |
152 | + |
153 | + int i, ii; |
154 | + |
155 | + //MSR number and hi:low bit of that MSR |
156 | + //This msr contains a lot of stuff, per socket wise |
157 | + //one can pass any core number and then get in multiplier etc |
158 | + int PLATFORM_INFO_MSR = 206; //CE 15:8 |
159 | + int PLATFORM_INFO_MSR_low = 8; |
160 | + int PLATFORM_INFO_MSR_high = 15; |
161 | + |
162 | + ////To find out if Turbo is enabled use the below msr and bit 38 |
163 | + ////bit for TURBO is 38 |
164 | + ////msr reading is now moved into tubo_status |
165 | + //int IA32_MISC_ENABLE = 416; |
166 | + //int TURBO_FLAG_low = 38; |
167 | + //int TURBO_FLAG_high = 38; |
168 | + |
169 | + |
170 | + //int MSR_TURBO_RATIO_LIMIT = 429; |
171 | + |
172 | + int CPU_NUM; |
173 | + int CPU_Multiplier; |
174 | + float BLCK; |
175 | + char TURBO_MODE; |
176 | + |
177 | + printf("i7z DEBUG: GUI VERSION DOESN'T SUPPORT CORE OFFLINING\n"); |
178 | + sleep (1); |
179 | + |
180 | + // 3B defines till Max 4 Core and the rest bit values from 32:63 were reserved. |
181 | + // int MAX_TURBO_1C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 7, 0); |
182 | + // int MAX_TURBO_2C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 15, 8); |
183 | + // int MAX_TURBO_3C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 23, 16); |
184 | + // int MAX_TURBO_4C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 31, 24); |
185 | + |
186 | + |
187 | + //CPUINFO is wrong for i7 but correct for the number of physical and logical cores present |
188 | + //If Hyperthreading is enabled then, multiple logical processors will share a common CORE ID |
189 | + //http://www.redhat.com/magazine/022aug06/departments/tips_tricks/ |
190 | + system ("cat /proc/cpuinfo |grep MHz|sed 's/cpu\\sMHz\\s*:\\s//'|tail -n 1 > /tmp/cpufreq.txt"); |
191 | + system ("grep \"core id\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numPhysical.txt"); |
192 | + system ("grep \"processor\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numLogical.txt"); |
193 | + |
194 | + |
195 | + //Open the parsed cpufreq file and obtain the cpufreq from /proc/cpuinfo |
196 | + FILE *tmp_file; |
197 | + tmp_file = fopen ("/tmp/cpufreq.txt", "r"); |
198 | + char tmp_str[30]; |
199 | + fgets (tmp_str, 30, tmp_file); |
200 | + double cpu_freq_cpuinfo = atof (tmp_str); |
201 | + fclose (tmp_file); |
202 | + |
203 | + unsigned int numPhysicalCores, numLogicalCores; |
204 | + numPhysicalCores = socket_0.num_physical_cores + socket_1.num_physical_cores; |
205 | + numLogicalCores = socket_0.num_logical_cores + socket_1.num_logical_cores; |
206 | +// printf("My thread: Num Processors %d\n",numCPUs); |
207 | + |
208 | + int error_indx; |
209 | + |
210 | + //estimate the freq using the estimate_MHz() code that is almost mhz accurate |
211 | + cpu_freq_cpuinfo = estimate_MHz (); |
212 | + |
213 | + //We just need one CPU (we use Core-0) to figure out the multiplier and the bus clock freq. |
214 | + CPU_NUM = 0; |
215 | + CPU_Multiplier = |
216 | + get_msr_value (CPU_NUM, PLATFORM_INFO_MSR, PLATFORM_INFO_MSR_high, |
217 | + PLATFORM_INFO_MSR_low, &error_indx); |
218 | + BLCK = cpu_freq_cpuinfo / CPU_Multiplier; |
219 | + TURBO_MODE = turbo_status (); //get_msr_value(CPU_NUM,IA32_MISC_ENABLE, TURBO_FLAG_high,TURBO_FLAG_low); |
220 | + |
221 | + //to find how many cpus are enabled, we could have used sysconf but that will just give the logical numbers |
222 | + //if HT is enabled then the threads of the same core have the same C-state residency number so... |
223 | + //Its imperative to figure out the number of physical and number of logical cores. |
224 | + //sysconf(_SC_NPROCESSORS_ONLN); |
225 | + |
226 | + |
227 | + bool HT_ON; |
228 | + char HT_ON_str[30]; |
229 | + if (numLogicalCores > numPhysicalCores) |
230 | + { |
231 | + strcpy (HT_ON_str, "Hyper Threading ON"); |
232 | + HT_ON = true; |
233 | + } |
234 | + else |
235 | + { |
236 | + strcpy (HT_ON_str, "Hyper Threading OFF"); |
237 | + HT_ON = false; |
238 | + } |
239 | + |
240 | + float TRUE_CPU_FREQ; |
241 | + if (TURBO_MODE == 1) |
242 | + { |
243 | + TRUE_CPU_FREQ = BLCK * ((double)CPU_Multiplier + 1); |
244 | + } |
245 | + else |
246 | + { |
247 | + TRUE_CPU_FREQ = BLCK * ((double)CPU_Multiplier); |
248 | + } |
249 | + |
250 | + |
251 | + int IA32_PERF_GLOBAL_CTRL = 911; //3BF |
252 | + int IA32_PERF_GLOBAL_CTRL_Value = |
253 | + get_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 63, 0,&error_indx); |
254 | + int IA32_FIXED_CTR_CTL = 909; //38D |
255 | + int IA32_FIXED_CTR_CTL_Value = |
256 | + get_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 63, 0,&error_indx); |
257 | + |
258 | + //printf("IA32_PERF_GLOBAL_CTRL %d\n",IA32_PERF_GLOBAL_CTRL_Value); |
259 | + //printf("IA32_FIXED_CTR_CTL %d\n",IA32_FIXED_CTR_CTL_Value); |
260 | + |
261 | + unsigned long long int CPU_CLK_UNHALTED_CORE, CPU_CLK_UNHALTED_REF, |
262 | + CPU_CLK_C3, CPU_CLK_C6, CPU_CLK_C1; |
263 | + |
264 | + CPU_CLK_UNHALTED_CORE = get_msr_value (CPU_NUM, 778, 63, 0,&error_indx); |
265 | + CPU_CLK_UNHALTED_REF = get_msr_value (CPU_NUM, 779, 63, 0,&error_indx); |
266 | + |
267 | + unsigned long long int old_val_CORE[numCPUs], new_val_CORE[numCPUs]; |
268 | + unsigned long long int old_val_REF[numCPUs], new_val_REF[numCPUs]; |
269 | + unsigned long long int old_val_C3[numCPUs], new_val_C3[numCPUs]; |
270 | + unsigned long long int old_val_C6[numCPUs], new_val_C6[numCPUs]; |
271 | +// unsigned long int old_val_C1[numCPUs], new_val_C1[numCPUs]; |
272 | + |
273 | + unsigned long long int old_TSC[numCPUs], new_TSC[numCPUs]; |
274 | + |
275 | + struct timeval tvstart[numCPUs], tvstop[numCPUs]; |
276 | + |
277 | + struct timespec one_second_sleep; |
278 | + one_second_sleep.tv_sec = 0; |
279 | + one_second_sleep.tv_nsec = 999999999; // 1000msec |
280 | + |
281 | + |
282 | + unsigned long int IA32_MPERF = get_msr_value (CPU_NUM, 231, 7, 0,&error_indx); |
283 | + unsigned long int IA32_APERF = get_msr_value (CPU_NUM, 232, 7, 0,&error_indx); |
284 | +// mvprintw(12,0,"Wait...\n"); refresh(); |
285 | + nanosleep (&one_second_sleep, NULL); |
286 | + IA32_MPERF = get_msr_value (CPU_NUM, 231, 7, 0, &error_indx) - IA32_MPERF; |
287 | + IA32_APERF = get_msr_value (CPU_NUM, 232, 7, 0, &error_indx) - IA32_APERF; |
288 | + |
289 | + //printf("Diff. i n APERF = %u, MPERF = %d\n", IA32_MPERF, IA32_APERF); |
290 | + |
291 | + long double C0_time[numCPUs], C1_time[numCPUs], C3_time[numCPUs], C6_time[numCPUs]; |
292 | + double _FREQ[numCPUs], _MULT[numCPUs]; |
293 | + |
294 | +// mvprintw(12,0,"Current Freqs\n"); |
295 | + |
296 | + int kk=11; |
297 | + double estimated_mhz; |
298 | + for (;;) |
299 | + { |
300 | + Construct_Socket_Information_in_GUI(&numCPUs); |
301 | + |
302 | + if (kk>10) { |
303 | + kk=0; |
304 | + for (ii = 0; ii < (int)numCPUs; ii++) |
305 | + { |
306 | + CPU_NUM = core_list[ii]; |
307 | + IA32_PERF_GLOBAL_CTRL_Value = get_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 63, 0, &error_indx); |
308 | + set_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 0x700000003LLU); |
309 | + |
310 | + IA32_FIXED_CTR_CTL_Value = get_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 63, 0, &error_indx); |
311 | + set_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 819); |
312 | + |
313 | + IA32_PERF_GLOBAL_CTRL_Value = get_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 63, 0, &error_indx); |
314 | + IA32_FIXED_CTR_CTL_Value = get_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 63, 0, &error_indx); |
315 | + |
316 | + old_val_CORE[ii] = get_msr_value (CPU_NUM, 778, 63, 0,&error_indx); |
317 | + old_val_REF[ii] = get_msr_value (CPU_NUM, 779, 63, 0,&error_indx); |
318 | + old_val_C3[ii] = get_msr_value (CPU_NUM, 1020, 63, 0,&error_indx); |
319 | + old_val_C6[ii] = get_msr_value (CPU_NUM, 1021, 63, 0,&error_indx); |
320 | + old_TSC[ii] = rdtsc (); |
321 | + } |
322 | + } |
323 | + kk++; |
324 | + |
325 | + nanosleep (&one_second_sleep, NULL); |
326 | + |
327 | + estimated_mhz = estimate_MHz(); |
328 | + |
329 | + for (i = 0; i < (int)numCPUs; i++) |
330 | + { |
331 | + CPU_NUM = core_list[i]; |
332 | + new_val_CORE[i] = get_msr_value (CPU_NUM, 778, 63, 0,&error_indx); |
333 | + new_val_REF[i] = get_msr_value (CPU_NUM, 779, 63, 0,&error_indx); |
334 | + new_val_C3[i] = get_msr_value (CPU_NUM, 1020, 63, 0,&error_indx); |
335 | + new_val_C6[i] = get_msr_value (CPU_NUM, 1021, 63, 0,&error_indx); |
336 | + new_TSC[i] = rdtsc (); |
337 | + if (old_val_CORE[i] > new_val_CORE[i]) |
338 | + { |
339 | + CPU_CLK_UNHALTED_CORE = |
340 | + (3.40282366921e38 - old_val_CORE[i]) + new_val_CORE[i]; |
341 | + } |
342 | + else |
343 | + { |
344 | + CPU_CLK_UNHALTED_CORE = new_val_CORE[i] - old_val_CORE[i]; |
345 | + } |
346 | + |
347 | + //number of TSC cycles while its in halted state |
348 | + if ((new_TSC[i] - old_TSC[i]) < CPU_CLK_UNHALTED_CORE) |
349 | + CPU_CLK_C1 = 0; |
350 | + else |
351 | + CPU_CLK_C1 = ((new_TSC[i] - old_TSC[i]) - CPU_CLK_UNHALTED_CORE); |
352 | + |
353 | + if (old_val_REF[i] > new_val_REF[i]) |
354 | + { |
355 | + CPU_CLK_UNHALTED_REF = |
356 | + (3.40282366921e38 - old_val_REF[i]) + new_val_REF[i]; |
357 | + } |
358 | + else |
359 | + { |
360 | + CPU_CLK_UNHALTED_REF = new_val_REF[i] - old_val_REF[i]; |
361 | + } |
362 | + |
363 | + if (old_val_C3[i] > new_val_C3[i]) |
364 | + { |
365 | + CPU_CLK_C3 = (3.40282366921e38 - old_val_C3[i]) + new_val_C3[i]; |
366 | + } |
367 | + else |
368 | + { |
369 | + CPU_CLK_C3 = new_val_C3[i] - old_val_C3[i]; |
370 | + } |
371 | + |
372 | + if (old_val_C6[i] > new_val_C6[i]) |
373 | + { |
374 | + CPU_CLK_C6 = (3.40282366921e38 - old_val_C6[i]) + new_val_C6[i]; |
375 | + } |
376 | + else |
377 | + { |
378 | + CPU_CLK_C6 = new_val_C6[i] - old_val_C6[i]; |
379 | + } |
380 | + |
381 | + _FREQ[i] = |
382 | + estimated_mhz * ((long double) CPU_CLK_UNHALTED_CORE / |
383 | + (long double) CPU_CLK_UNHALTED_REF); |
384 | + _MULT[i] = _FREQ[i] / BLCK; |
385 | + |
386 | + C0_time[i] = |
387 | + ((long double) CPU_CLK_UNHALTED_REF / |
388 | + (long double) (new_TSC[i] - old_TSC[i])); |
389 | + long double c1_time = |
390 | + ((long double) CPU_CLK_C1 / |
391 | + (long double) (new_TSC[i] - old_TSC[i])); |
392 | + C3_time[i] = |
393 | + ((long double) CPU_CLK_C3 / |
394 | + (long double) (new_TSC[i] - old_TSC[i])); |
395 | + C6_time[i] = |
396 | + ((long double) CPU_CLK_C6 / |
397 | + (long double) (new_TSC[i] - old_TSC[i])); |
398 | + |
399 | + //C1_time[i] -= C3_time[i] + C6_time[i]; |
400 | + C1_time[i] = c1_time - (C3_time[i] + C6_time[i]) ; |
401 | + if (!isnan(c1_time) && !isinf(c1_time)) { |
402 | + if (C1_time[i] <= 0) { |
403 | + C1_time[i]=0; |
404 | + } |
405 | + } |
406 | + |
407 | + if (C0_time[i] < 1e-2) { |
408 | + if (C0_time[i] > 1e-4) C0_time[i] = 0.01; |
409 | + else C0_time[i] = 0; |
410 | + } |
411 | + |
412 | + if (C1_time[i] < 1e-2) { |
413 | + if (C1_time[i] > 1e-4) C1_time[i] = 0.01; |
414 | + else C1_time[i] = 0; |
415 | + } |
416 | + |
417 | + if (C3_time[i] < 1e-2) { |
418 | + if (C3_time[i] > 1e-4) C3_time[i] = 0.01; |
419 | + else C3_time[i] = 0; |
420 | + } |
421 | + |
422 | + if (C6_time[i] < 1e-2) { |
423 | + if (C6_time[i] > 1e-4) C6_time[i] = 0.01; |
424 | + else C6_time[i] = 0; |
425 | + } |
426 | + } |
427 | +// printf("Hello"); |
428 | +// for(i=0;i<numCPUs;i++){ |
429 | +// printf("%g %Lg %Lg %Lg %Lg %lld %llu\n",_FREQ[i],C0_time[i]*100,C1_time[i]*100,C3_time[i]*100,C6_time[i]*100,CPU_CLK_UNHALTED_REF,(new_TSC[i] - old_TSC[i])); |
430 | +// printf("%g %llu %llu %llu %llu %llu\n",_FREQ[i],CPU_CLK_UNHALTED_REF,CPU_CLK_C1,CPU_CLK_C3,CPU_CLK_C6,(new_TSC[i] - old_TSC[i])); |
431 | +// printf("%llu %llu %lld\n",new_TSC[i], old_TSC[i],new_TSC[i]- old_TSC[i]); |
432 | +// } |
433 | + TRUE_CPU_FREQ = 0; |
434 | + for (i = 0; i < (int)numCPUs; i++) |
435 | + if (_FREQ[i] > TRUE_CPU_FREQ) |
436 | + TRUE_CPU_FREQ = _FREQ[i]; |
437 | + |
438 | + memcpy (old_val_CORE, new_val_CORE, sizeof (unsigned long int) * numCPUs); |
439 | + memcpy (old_val_REF, new_val_REF, sizeof (unsigned long int) * numCPUs); |
440 | + memcpy (old_val_C3, new_val_C3, sizeof (unsigned long int) * numCPUs); |
441 | + memcpy (old_val_C6, new_val_C6, sizeof (unsigned long int) * numCPUs); |
442 | + memcpy (tvstart, tvstop, sizeof (struct timeval) * numCPUs); |
443 | + memcpy (old_TSC, new_TSC, sizeof (unsigned long long int) * numCPUs); |
444 | + |
445 | + memcpy (FREQ, _FREQ, sizeof (double) * numCPUs); |
446 | + memcpy (MULT, _MULT, sizeof (double) * numCPUs); |
447 | + memcpy (C0_TIME, C0_time, sizeof (long double) * numCPUs); |
448 | + memcpy (C1_TIME, C1_time, sizeof (long double) * numCPUs); |
449 | + memcpy (C3_TIME, C3_time, sizeof (long double) * numCPUs); |
450 | + memcpy (C6_TIME, C6_time, sizeof (long double) * numCPUs); |
451 | + global_in_i7z_main_thread = true; |
452 | + } |
453 | + |
454 | +} |
455 | + |
456 | +class MyWidget:public QWidget |
457 | +{ |
458 | +Q_OBJECT public: |
459 | + QProgressBar * C0_l[MAX_PROCESSORS_GUI], *C1_l[MAX_PROCESSORS_GUI], *C3_l[MAX_PROCESSORS_GUI], *C6_l[MAX_PROCESSORS_GUI]; |
460 | + QLabel *C0, *C1, *C3, *C6; |
461 | + QLabel *Freq_[MAX_PROCESSORS_GUI]; |
462 | + QLabel *StatusMessage0, *StatusMessage1, *Curr_Freq0, *Curr_Freq1; |
463 | + QLabel *ProcNames[MAX_PROCESSORS_GUI]; |
464 | + MyWidget (QWidget * parent = 0); |
465 | + MyThread *mythread; |
466 | + int curr_numCPUs; |
467 | + |
468 | +private slots: |
469 | + void UpdateWidget (); |
470 | +}; |
471 | + |
472 | +MyWidget::MyWidget (QWidget * parent):QWidget (parent) |
473 | +{ |
474 | + |
475 | + Print_Version_Information(); |
476 | + |
477 | + // |
478 | + //Print_Information_Processor (); |
479 | + bool cpuNehalem, cpuSandybridge; |
480 | + Print_Information_Processor (&cpuNehalem, &cpuSandybridge); |
481 | + |
482 | + Test_Or_Make_MSR_DEVICE_FILES (); |
483 | + |
484 | + Construct_Socket_Information_in_GUI(&numCPUs); |
485 | + |
486 | + char processor_str[100]; |
487 | +// printf("MyWidget: Num Processors %d\n",numCPUs); |
488 | + int i; |
489 | + |
490 | + for (i = 0; i < (int)numCPUs; i++) |
491 | + { |
492 | + C0_l[i] = new QProgressBar; |
493 | + C0_l[i]->setMaximum (99); |
494 | + C0_l[i]->setMinimum (0); |
495 | + C1_l[i] = new QProgressBar; |
496 | + C1_l[i]->setMaximum (99); |
497 | + C1_l[i]->setMinimum (0); |
498 | + C3_l[i] = new QProgressBar; |
499 | + C3_l[i]->setMaximum (99); |
500 | + C3_l[i]->setMinimum (0); |
501 | + C6_l[i] = new QProgressBar; |
502 | + C6_l[i]->setMaximum (99); |
503 | + C6_l[i]->setMinimum (0); |
504 | + Freq_[i] = new QLabel (tr ("")); |
505 | + } |
506 | + |
507 | + QGridLayout * layout1 = new QGridLayout; |
508 | + |
509 | + curr_numCPUs = numCPUs; |
510 | + for (i = 0; i < (int)numCPUs; i++) |
511 | + { |
512 | + layout1->addWidget (C0_l[i], i + 1, 1); |
513 | + layout1->addWidget (C1_l[i], i + 1, 2); |
514 | + layout1->addWidget (C3_l[i], i + 1, 3); |
515 | + layout1->addWidget (C6_l[i], i + 1, 4); |
516 | + } |
517 | + |
518 | + C0 = new QLabel (tr ("C0")); |
519 | + C0->setAlignment (Qt::AlignCenter); |
520 | + C1 = new QLabel (tr ("C1")); |
521 | + C1->setAlignment (Qt::AlignCenter); |
522 | + C3 = new QLabel (tr ("C3")); |
523 | + C3->setAlignment (Qt::AlignCenter); |
524 | + C6 = new QLabel (tr ("C6")); |
525 | + C6->setAlignment (Qt::AlignCenter); |
526 | + |
527 | + snprintf(processor_str, 100, "Core-1 [id:%d,socket:%d]",core_list[0],socket_list[0]); |
528 | + ProcNames[0] = new QLabel (tr (processor_str)); |
529 | + |
530 | + snprintf(processor_str, 100, "Core-2 [id:%d,socket:%d]",core_list[1],socket_list[1]); |
531 | + ProcNames[1] = new QLabel (tr (processor_str)); |
532 | + |
533 | + snprintf(processor_str, 100, "Core-3 [id:%d,socket:%d]",core_list[2],socket_list[2]); |
534 | + ProcNames[2] = new QLabel (tr (processor_str)); |
535 | + |
536 | + snprintf(processor_str, 100, "Core-4 [id:%d,socket:%d]",core_list[3],socket_list[3]); |
537 | + ProcNames[3] = new QLabel (tr (processor_str)); |
538 | + |
539 | + snprintf(processor_str, 100, "Core-5 [id:%d,socket:%d]",core_list[4],socket_list[4]); |
540 | + ProcNames[4] = new QLabel (tr (processor_str)); |
541 | + |
542 | + snprintf(processor_str, 100, "Core-6 [id:%d,socket:%d]",core_list[5],socket_list[5]); |
543 | + ProcNames[5] = new QLabel (tr (processor_str)); |
544 | + |
545 | + snprintf(processor_str, 100, "Core-7 [id:%d,socket:%d]",core_list[6],socket_list[6]); |
546 | + ProcNames[6] = new QLabel (tr (processor_str)); |
547 | + |
548 | + snprintf(processor_str, 100, "Core-8 [id:%d,socket:%d]",core_list[7],socket_list[7]); |
549 | + ProcNames[7] = new QLabel (tr (processor_str)); |
550 | + |
551 | + snprintf(processor_str, 100, "Core-9 [id:%d,socket:%d]",core_list[8],socket_list[8]); |
552 | + ProcNames[8] = new QLabel (tr (processor_str)); |
553 | + |
554 | + snprintf(processor_str, 100, "Core-10 [id:%d,socket:%d]",core_list[9],socket_list[9]); |
555 | + ProcNames[9] = new QLabel (tr (processor_str)); |
556 | + |
557 | + snprintf(processor_str, 100, "Core-11 [id:%d,socket:%d]",core_list[10],socket_list[10]); |
558 | + ProcNames[10] = new QLabel (tr (processor_str)); |
559 | + |
560 | + snprintf(processor_str, 100, "Core-12 [id:%d,socket:%d]",core_list[11],socket_list[11]); |
561 | + ProcNames[11] = new QLabel (tr (processor_str)); |
562 | + |
563 | + StatusMessage0 = new QLabel (tr ("Wait")); |
564 | + Curr_Freq0 = new QLabel (tr ("Wait")); |
565 | + |
566 | + if ( (socket_0.num_physical_cores > 0) && (socket_1.num_physical_cores > 0)) { |
567 | + StatusMessage1 = new QLabel (tr ("Wait")); |
568 | + Curr_Freq1 = new QLabel (tr ("Wait")); |
569 | + } |
570 | + |
571 | + for (i = 0; i < (int)numCPUs; i++) { |
572 | + layout1->addWidget (ProcNames[i], i + 1, 0); |
573 | + } |
574 | + |
575 | + layout1->addWidget (C0, 0, 1); |
576 | + layout1->addWidget (C1, 0, 2); |
577 | + layout1->addWidget (C3, 0, 3); |
578 | + layout1->addWidget (C6, 0, 4); |
579 | + |
580 | + for (i = 0; i < (int)numCPUs; i++) |
581 | + layout1->addWidget (Freq_[i], i + 1, 5); |
582 | + |
583 | + layout1->addWidget (StatusMessage0, numCPUs + 1, 4); |
584 | + layout1->addWidget (Curr_Freq0, numCPUs + 1, 5); |
585 | + if ( (socket_0.num_physical_cores > 0) && (socket_1.num_physical_cores > 0)) { |
586 | + layout1->addWidget (StatusMessage1, numCPUs + 2, 4); |
587 | + layout1->addWidget (Curr_Freq1, numCPUs + 2, 5); |
588 | + } |
589 | + QTimer *timer = new QTimer (this); |
590 | + connect (timer, SIGNAL (timeout ()), this, SLOT (UpdateWidget ())); |
591 | + timer->start (1000); |
592 | + |
593 | + mythread = new MyThread (); |
594 | + mythread->start (); |
595 | + |
596 | + setLayout (layout1); |
597 | +} |
598 | + |
599 | +void |
600 | +MyWidget::UpdateWidget () |
601 | +{ |
602 | + char processor_str[100]; |
603 | + snprintf(processor_str, 100, "Core-1 [id:%d,socket:%d]",core_list[0],socket_list[0]); |
604 | + ProcNames[0]->setText(tr (processor_str)); |
605 | + snprintf(processor_str, 100, "Core-2 [id:%d,socket:%d]",core_list[1],socket_list[1]); |
606 | + ProcNames[1]->setText(tr (processor_str)); |
607 | + snprintf(processor_str, 100, "Core-3 [id:%d,socket:%d]",core_list[2],socket_list[2]); |
608 | + ProcNames[2]->setText(tr (processor_str)); |
609 | + snprintf(processor_str, 100, "Core-4 [id:%d,socket:%d]",core_list[3],socket_list[3]); |
610 | + ProcNames[3]->setText(tr (processor_str)); |
611 | + snprintf(processor_str, 100, "Core-5 [id:%d,socket:%d]",core_list[4],socket_list[4]); |
612 | + ProcNames[4]->setText(tr (processor_str)); |
613 | + snprintf(processor_str, 100, "Core-6 [id:%d,socket:%d]",core_list[5],socket_list[5]); |
614 | + ProcNames[5]->setText(tr (processor_str)); |
615 | + snprintf(processor_str, 100, "Core-7 [id:%d,socket:%d]",core_list[6],socket_list[6]); |
616 | + ProcNames[6]->setText(tr (processor_str)); |
617 | + snprintf(processor_str, 100, "Core-8 [id:%d,socket:%d]",core_list[7],socket_list[7]); |
618 | + ProcNames[7]->setText(tr (processor_str)); |
619 | + snprintf(processor_str, 100, "Core-9 [id:%d,socket:%d]",core_list[8],socket_list[8]); |
620 | + ProcNames[8]->setText(tr (processor_str)); |
621 | + snprintf(processor_str, 100, "Core-10 [id:%d,socket:%d]",core_list[9],socket_list[9]); |
622 | + ProcNames[9]->setText(tr (processor_str)); |
623 | + snprintf(processor_str, 100, "Core-11 [id:%d,socket:%d]",core_list[10],socket_list[10]); |
624 | + ProcNames[10]->setText(tr (processor_str)); |
625 | + snprintf(processor_str, 100, "Core-12 [id:%d,socket:%d]",core_list[11],socket_list[11]); |
626 | + ProcNames[11]->setText(tr (processor_str)); |
627 | + |
628 | +//Have to make sure that the constructor is being called correct. |
629 | +//the below code logic is that if a core goes offline, call the constructor |
630 | +//so as to replot all the widgets. |
631 | + /* printf("Number of Cores %d\n",numCPUs); |
632 | + if(numCPUs != curr_numCPUs){ |
633 | + curr_numCPUs = numCPUs; |
634 | + printf("Number of Cores changed\n"); |
635 | + MyWidget (0); |
636 | + }*/ |
637 | + |
638 | +// printf("UpdateWidget: Num Processors %d\n",numCPUs); |
639 | + int i; |
640 | + char val2set[100]; |
641 | + for (i = 0; i < (int)numCPUs; i++) |
642 | + { |
643 | + snprintf (val2set, 100, "%0.2f Mhz", mythread->FREQ[i]); |
644 | + Freq_[i]->setText (val2set); |
645 | + } |
646 | + |
647 | + for (i = 0; i < (int)numCPUs; i++) |
648 | + { |
649 | + C0_l[i]->setValue (mythread->C0_TIME[i] * 100); |
650 | + C1_l[i]->setValue (mythread->C1_TIME[i] * 100); |
651 | + C3_l[i]->setValue (mythread->C3_TIME[i] * 100); |
652 | + C6_l[i]->setValue (mythread->C6_TIME[i] * 100); |
653 | + } |
654 | + |
655 | + float Max_Freq_socket0 = 0; |
656 | + float Max_Freq_socket1 = 0; |
657 | + int num_socket0_cpus, num_socket1_cpus; |
658 | + |
659 | + for (i = 0; i < (int)numCPUs; i++) |
660 | + { |
661 | + if ( (mythread->FREQ[i] > Max_Freq_socket0) && (!isnan(mythread->FREQ[i])) && |
662 | + (!isinf(mythread->FREQ[i])) && (socket_list[i] == socket_0.socket_num) ) { |
663 | + Max_Freq_socket0 = mythread->FREQ[i]; |
664 | + num_socket0_cpus++; |
665 | + } |
666 | + if ( (mythread->FREQ[i] > Max_Freq_socket1) && (!isnan(mythread->FREQ[i])) && |
667 | + (!isinf(mythread->FREQ[i])) && (socket_list[i] == socket_1.socket_num) ) { |
668 | + Max_Freq_socket1 = mythread->FREQ[i]; |
669 | + num_socket1_cpus++; |
670 | + } |
671 | + } |
672 | + if (socket_0.num_physical_cores > 0) { |
673 | + StatusMessage0->setText ("Socket[0] Freq:"); |
674 | + snprintf (val2set, 100, "%0.2f Mhz", Max_Freq_socket0); |
675 | + Curr_Freq0->setText (val2set); |
676 | + } |
677 | + if (socket_1.num_physical_cores > 0) { |
678 | + StatusMessage1->setText ("Socket[1] Freq:"); |
679 | + snprintf (val2set, 100, "%0.2f Mhz", Max_Freq_socket1); |
680 | + Curr_Freq1->setText (val2set); |
681 | + } |
682 | +} |
683 | + |
684 | + |
685 | + |
686 | +int |
687 | +main (int argc, char *argv[]) |
688 | +{ |
689 | + char hostname[1024]; |
690 | + hostname[1023] = '\0'; |
691 | + gethostname(hostname, 1023); |
692 | + |
693 | + QApplication app (argc, argv); |
694 | + |
695 | + char str_display[1050]; |
696 | + snprintf(str_display, 1050, "i7z @ %s", hostname); |
697 | + MyWidget i7z_widget; |
698 | + i7z_widget.setWindowTitle(str_display); |
699 | + i7z_widget.show (); |
700 | + return app.exec (); |
701 | +} |
702 | + |
703 | +#include "i7z_GUI.moc" |
704 | |
705 | === added file '.pc/fix-insecure-tempfile.patch/helper_functions.c' |
706 | --- .pc/fix-insecure-tempfile.patch/helper_functions.c 1970-01-01 00:00:00 +0000 |
707 | +++ .pc/fix-insecure-tempfile.patch/helper_functions.c 2013-08-15 05:58:18 +0000 |
708 | @@ -0,0 +1,753 @@ |
709 | +/* This file is modified from source available at http://www.kernel.org/pub/linux/utils/cpu/msr-tools/ |
710 | + for Model specific cpu registers |
711 | + Modified to take i7 into account by Abhishek Jaiantilal abhishek.jaiantilal@colorado.edu |
712 | + |
713 | +// Information about i7's MSR in |
714 | +// http://download.intel.com/design/processor/applnots/320354.pdf |
715 | +// Appendix B of http://www.intel.com/Assets/PDF/manual/253669.pdf |
716 | + |
717 | +//about rdmsr |
718 | +#ident "$Id: rdmsr.c,v 1.4 2004/07/20 15:54:59 hpa Exp $" |
719 | + ----------------------------------------------------------------------- * |
720 | + * |
721 | + * Copyright 2000 Transmeta Corporation - All Rights Reserved |
722 | + * |
723 | + * This program is free software; you can redistribute it and/or modify |
724 | + * it under the terms of the GNU General Public License as published by |
725 | + * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, |
726 | + * Boston, MA 02110-1301, USA; |
727 | + * either version 2 of the License, or (at your option) any later |
728 | + * version; incorporated herein by reference. |
729 | + * |
730 | + * ----------------------------------------------------------------------- */ |
731 | +#include <memory.h> |
732 | +#include <errno.h> |
733 | +#include <stdio.h> |
734 | +#include <fcntl.h> |
735 | +#include <unistd.h> |
736 | +#include <stdlib.h> |
737 | +#include <getopt.h> |
738 | +#include <inttypes.h> |
739 | +#include <sys/types.h> |
740 | +#include <sys/time.h> |
741 | +#include <time.h> |
742 | +#include <assert.h> |
743 | +#include <math.h> |
744 | +#include "i7z.h" |
745 | + |
746 | +//#define ULLONG_MAX 18446744073709551615 |
747 | + |
748 | +extern struct program_options prog_options; |
749 | +bool E7_mp_present=false; |
750 | + |
751 | +/////////////////////////////////////////READ TEMPERATURE//////////////////////////////////////////// |
752 | +#define IA32_THERM_STATUS 0x19C |
753 | +#define IA32_TEMPERATURE_TARGET 0x1a2 |
754 | +#define IA32_PACKAGE_THERM_STATUS 0x1b1 |
755 | + |
756 | +int Get_Bits_Value(unsigned long val,int highbit, int lowbit){ |
757 | + unsigned long data = val; |
758 | + int bits = highbit - lowbit + 1; |
759 | + if(bits<64){ |
760 | + data >>= lowbit; |
761 | + data &= (1ULL<<bits) - 1; |
762 | + } |
763 | + return(data); |
764 | +} |
765 | + |
766 | +// a nice document to read is 322683.pdf from intel |
767 | +int Read_Thermal_Status_CPU(int cpu_num){ |
768 | + int error_indx; |
769 | + unsigned long val= get_msr_value(cpu_num,IA32_THERM_STATUS,63,0,&error_indx); |
770 | + int digital_readout = Get_Bits_Value(val,23,16); |
771 | + bool thermal_status = Get_Bits_Value(val,32,31); |
772 | + |
773 | + val= get_msr_value(cpu_num,IA32_TEMPERATURE_TARGET,63,0,&error_indx); |
774 | + int PROCHOT_temp = Get_Bits_Value(val,23,16); |
775 | + |
776 | + //temperature is prochot - digital readout |
777 | + if (thermal_status) |
778 | + return(PROCHOT_temp - digital_readout); |
779 | + else |
780 | + return(-1); |
781 | +} |
782 | + |
783 | +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
784 | + |
785 | + |
786 | + |
787 | +void |
788 | +print_family_info (struct family_info *proc_info) |
789 | +{ |
790 | + //print CPU info |
791 | + printf ("i7z DEBUG: Stepping %x\n", proc_info->stepping); |
792 | + printf ("i7z DEBUG: Model %x\n", proc_info->model); |
793 | + printf ("i7z DEBUG: Family %x\n", proc_info->family); |
794 | + printf ("i7z DEBUG: Processor Type %x\n", proc_info->processor_type); |
795 | + printf ("i7z DEBUG: Extended Model %x\n", proc_info->extended_model); |
796 | + // printf(" Extended Family %x\n", (short int*)(&proc_info->extended_family)); |
797 | + // printf(" Extended Family %d\n", proc_info->extended_family); |
798 | +} |
799 | + |
800 | +static inline void cpuid (unsigned int info, unsigned int *eax, unsigned int *ebx, |
801 | + unsigned int *ecx, unsigned int *edx) |
802 | +{ |
803 | + unsigned int _eax = info, _ebx, _ecx, _edx; |
804 | + asm volatile ("mov %%ebx, %%edi;" // save ebx (for PIC) |
805 | + "cpuid;" |
806 | + "mov %%ebx, %%esi;" // pass to caller |
807 | + "mov %%edi, %%ebx;" // restore ebx |
808 | + :"+a" (_eax), "=S" (_ebx), "=c" (_ecx), "=d" (_edx) |
809 | + : /* inputs: eax is handled above */ |
810 | + :"edi" /* clobbers: we hit edi directly */); |
811 | + if (eax) *eax = _eax; |
812 | + if (ebx) *ebx = _ebx; |
813 | + if (ecx) *ecx = _ecx; |
814 | + if (edx) *edx = _edx; |
815 | +} |
816 | + |
817 | +static inline void get_vendor (char *vendor_string) |
818 | +{ |
819 | + //get vendor name |
820 | + unsigned int a, b, c, d; |
821 | + cpuid (0, &a, &b, &c, &d); |
822 | + memcpy (vendor_string, &b, 4); |
823 | + memcpy (&vendor_string[4], &d, 4); |
824 | + memcpy (&vendor_string[8], &c, 4); |
825 | + vendor_string[12] = '\0'; |
826 | + // printf("Vendor %s\n",vendor_string); |
827 | +} |
828 | + |
829 | +int turbo_status () |
830 | +{ |
831 | + //turbo state flag |
832 | + unsigned int eax; |
833 | + cpuid (6, &eax, NULL, NULL, NULL); |
834 | + |
835 | + //printf("eax %d\n",(eax&0x2)>>1); |
836 | + |
837 | + return ((eax & 0x2) >> 1); |
838 | +} |
839 | + |
840 | +static inline void get_familyinformation (struct family_info *proc_info) |
841 | +{ |
842 | + //get info about CPU |
843 | + unsigned int b; |
844 | + cpuid (1, &b, NULL, NULL, NULL); |
845 | + // printf ("eax %x\n", b); |
846 | + proc_info->stepping = b & 0x0000000F; //bits 3:0 |
847 | + proc_info->model = (b & 0x000000F0) >> 4; //bits 7:4 |
848 | + proc_info->family = (b & 0x00000F00) >> 8; //bits 11:8 |
849 | + proc_info->processor_type = (b & 0x00007000) >> 12; //bits 13:12 |
850 | + proc_info->extended_model = (b & 0x000F0000) >> 16; //bits 19:16 |
851 | + proc_info->extended_family = (b & 0x0FF00000) >> 20; //bits 27:20 |
852 | +} |
853 | + |
854 | +double estimate_MHz () |
855 | +{ |
856 | + //copied blantantly from http://www.cs.helsinki.fi/linux/linux-kernel/2001-37/0256.html |
857 | + /* |
858 | + * $Id: MHz.c,v 1.4 2001/05/21 18:58:01 davej Exp $ |
859 | + * This file is part of x86info. |
860 | + * (C) 2001 Dave Jones. |
861 | + * |
862 | + * Licensed under the terms of the GNU GPL License version 2. |
863 | + * |
864 | + * Estimate CPU MHz routine by Andrea Arcangeli <andrea@suse.de> |
865 | + * Small changes by David Sterba <sterd9am@ss1000.ms.mff.cuni.cz> |
866 | + * |
867 | + */ |
868 | + struct timezone tz; |
869 | + struct timeval tvstart, tvstop; |
870 | + unsigned long long int cycles[2]; /* gotta be 64 bit */ |
871 | + unsigned long long int microseconds; /* total time taken */ |
872 | + |
873 | + memset (&tz, 0, sizeof (tz)); |
874 | + |
875 | + /* get this function in cached memory */ |
876 | + gettimeofday (&tvstart, &tz); |
877 | + cycles[0] = rdtsc (); |
878 | + gettimeofday (&tvstart, &tz); |
879 | + |
880 | + /* we don't trust that this is any specific length of time */ |
881 | + //1 sec will cause rdtsc to overlap multiple times perhaps. 100msecs is a good spot |
882 | + usleep (10000); |
883 | + |
884 | + cycles[1] = rdtsc (); |
885 | + gettimeofday (&tvstop, &tz); |
886 | + microseconds = ((tvstop.tv_sec - tvstart.tv_sec) * 1000000) + |
887 | + (tvstop.tv_usec - tvstart.tv_usec); |
888 | + |
889 | + unsigned long long int elapsed = 0; |
890 | + if (cycles[1] < cycles[0]) |
891 | + { |
892 | + //printf("c0 = %llu c1 = %llu",cycles[0],cycles[1]); |
893 | + elapsed = UINT32_MAX - cycles[0]; |
894 | + elapsed = elapsed + cycles[1]; |
895 | + //printf("c0 = %llu c1 = %llu max = %llu elapsed=%llu\n",cycles[0], cycles[1], UINT32_MAX,elapsed); |
896 | + } |
897 | + else |
898 | + { |
899 | + elapsed = cycles[1] - cycles[0]; |
900 | + //printf("\nc0 = %llu c1 = %llu elapsed=%llu\n",cycles[0], cycles[1],elapsed); |
901 | + } |
902 | + |
903 | + double mhz = elapsed / microseconds; |
904 | + |
905 | + |
906 | + //printf("%llg MHz processor (estimate). diff cycles=%llu microseconds=%llu \n", mhz, elapsed, microseconds); |
907 | + //printf("%g elapsed %llu microseconds %llu\n",mhz, elapsed, microseconds); |
908 | + return (mhz); |
909 | +} |
910 | + |
911 | +/* Number of decimal digits for a certain number of bits */ |
912 | +/* (int) ceil(log(2^n)/log(10)) */ |
913 | +int decdigits[] = { |
914 | + 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 5, 5, |
915 | + 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, |
916 | + 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 13, 14, 14, 14, 15, |
917 | + 15, 15, 16, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 19, 19, |
918 | + 20 |
919 | +}; |
920 | + |
921 | +#define mo_hex 0x01 |
922 | +#define mo_dec 0x02 |
923 | +#define mo_oct 0x03 |
924 | +#define mo_raw 0x04 |
925 | +#define mo_uns 0x05 |
926 | +#define mo_chx 0x06 |
927 | +#define mo_mask 0x0f |
928 | +#define mo_fill 0x40 |
929 | +#define mo_c 0x80 |
930 | + |
931 | +const char *program; |
932 | + |
933 | + |
934 | +uint64_t get_msr_value (int cpu, uint32_t reg, unsigned int highbit, |
935 | + unsigned int lowbit, int* error_indx) |
936 | +{ |
937 | + uint64_t data; |
938 | + int fd; |
939 | + // char *pat; |
940 | + // int width; |
941 | + char msr_file_name[64]; |
942 | + int bits; |
943 | + *error_indx =0; |
944 | + |
945 | + sprintf (msr_file_name, "/dev/cpu/%d/msr", cpu); |
946 | + fd = open (msr_file_name, O_RDONLY); |
947 | + if (fd < 0) |
948 | + { |
949 | + if (errno == ENXIO) |
950 | + { |
951 | + //fprintf (stderr, "rdmsr: No CPU %d\n", cpu); |
952 | + *error_indx = 1; |
953 | + return 1; |
954 | + } else if (errno == EIO) { |
955 | + //fprintf (stderr, "rdmsr: CPU %d doesn't support MSRs\n", cpu); |
956 | + *error_indx = 1; |
957 | + return 1; |
958 | + } else { |
959 | + //perror ("rdmsr:open"); |
960 | + *error_indx = 1; |
961 | + return 1; |
962 | + //exit (127); |
963 | + } |
964 | + } |
965 | + |
966 | + if (pread (fd, &data, sizeof data, reg) != sizeof data) |
967 | + { |
968 | + perror ("rdmsr:pread"); |
969 | + exit (127); |
970 | + } |
971 | + |
972 | + close (fd); |
973 | + |
974 | + bits = highbit - lowbit + 1; |
975 | + if (bits < 64) |
976 | + { |
977 | + /* Show only part of register */ |
978 | + data >>= lowbit; |
979 | + data &= (1ULL << bits) - 1; |
980 | + } |
981 | + |
982 | + /* Make sure we get sign correct */ |
983 | + if (data & (1ULL << (bits - 1))) |
984 | + { |
985 | + data &= ~(1ULL << (bits - 1)); |
986 | + data = -data; |
987 | + } |
988 | + |
989 | + *error_indx = 0; |
990 | + return (data); |
991 | +} |
992 | + |
993 | +uint64_t set_msr_value (int cpu, uint32_t reg, uint64_t data) |
994 | +{ |
995 | + int fd; |
996 | + char msr_file_name[64]; |
997 | + |
998 | + sprintf (msr_file_name, "/dev/cpu/%d/msr", cpu); |
999 | + fd = open (msr_file_name, O_WRONLY); |
1000 | + if (fd < 0) |
1001 | + { |
1002 | + if (errno == ENXIO) |
1003 | + { |
1004 | + fprintf (stderr, "wrmsr: No CPU %d\n", cpu); |
1005 | + exit (2); |
1006 | + } else if (errno == EIO) { |
1007 | + fprintf (stderr, "wrmsr: CPU %d doesn't support MSRs\n", cpu); |
1008 | + exit (3); |
1009 | + } else { |
1010 | + perror ("wrmsr:open"); |
1011 | + exit (127); |
1012 | + } |
1013 | + } |
1014 | + |
1015 | + if (pwrite (fd, &data, sizeof data, reg) != sizeof data) |
1016 | + { |
1017 | + perror ("wrmsr:pwrite"); |
1018 | + exit (127); |
1019 | + } |
1020 | + close(fd); |
1021 | + return(1); |
1022 | +} |
1023 | + |
1024 | + |
1025 | +#ifdef USE_INTEL_CPUID |
1026 | +void get_CPUs_info (unsigned int *num_Logical_OS, |
1027 | + unsigned int *num_Logical_process, |
1028 | + unsigned int *num_Processor_Core, |
1029 | + |
1030 | + unsigned int *num_Physical_Socket); |
1031 | + |
1032 | +#endif |
1033 | + |
1034 | + |
1035 | +//Below code |
1036 | +/* ----------------------------------------------------------------------- * |
1037 | + * |
1038 | + * Copyright 2010 Abhishek Jaiantilal |
1039 | + * |
1040 | + * Under GPL v2 |
1041 | + * |
1042 | + * ----------------------------------------------------------------------- */ |
1043 | + |
1044 | +void Print_Version_Information() |
1045 | +{ |
1046 | + printf ("i7z DEBUG: i7z version: %s\n",i7z_VERSION_INFO); |
1047 | +} |
1048 | + |
1049 | + |
1050 | +//sets whether its nehalem or sandy bridge |
1051 | +void Print_Information_Processor(bool* nehalem, bool* sandy_bridge) |
1052 | +{ |
1053 | + struct family_info proc_info; |
1054 | + |
1055 | + char vendor_string[13]; |
1056 | + memset(vendor_string,0,13); |
1057 | + |
1058 | + get_vendor (vendor_string); |
1059 | + vendor_string[12] = '\0'; |
1060 | + |
1061 | + //look at the blurb below for why strcmp is done byte by byte |
1062 | + /* |
1063 | + bool equal_string = true; |
1064 | + char const* genuine_intel_str = "GenuineIntel"; |
1065 | + int i; |
1066 | + for(i=0; i<12;i++) { |
1067 | + if (vendor_string[i] != genuine_intel_str[i]) |
1068 | + equal_string = false; |
1069 | + } |
1070 | + */ |
1071 | + // somehow using strcmp or strncmp is crashing the app when using -O2, -O3 with gcc-4.7 |
1072 | + // (strncmp (vendor_string, "GenuineIntel",12) == 0) |
1073 | + // (strcmp (vendor_string, "GenuineIntel",12) == 0) |
1074 | + |
1075 | + if (strcmp (vendor_string, "GenuineIntel") == 0) { |
1076 | + //if (equal_string) { |
1077 | + printf ("i7z DEBUG: Found Intel Processor\n"); |
1078 | + } else { |
1079 | + printf |
1080 | + ("this was designed to be a intel proc utility. You can perhaps mod it for your machine?\n"); |
1081 | + exit (1); |
1082 | + } |
1083 | + |
1084 | + get_familyinformation (&proc_info); |
1085 | + print_family_info (&proc_info); |
1086 | + |
1087 | + //printf("%x %x",proc_info.extended_model,proc_info.family); |
1088 | + |
1089 | + //check if its nehalem or exit |
1090 | + //Info from page 641 of Intel Manual 3B |
1091 | + //Extended model and Model can help determine the right cpu |
1092 | + |
1093 | + //furthermore from pdf 241618.pdf from intel |
1094 | + //page 24, got the following info |
1095 | + |
1096 | + //extended model is either 0x1 or 0x2 |
1097 | + //check on model number as follows |
1098 | + //extended model, model no - processor type |
1099 | + //0x1, 0xA - i7, 45nm |
1100 | + //0x1, 0xE - i7, i5, Xeon, 45nm |
1101 | + //0x2, 0xE - Xeon MP, 45nm //e.g. x75xx processors |
1102 | + //0x2, 0xF - Xeon MP, 32nm //e.g. e7-48xx processors |
1103 | + //0x2, 0xC - i7, Xeon, 32nm |
1104 | + //0x2, 0x5 - i3, i5, i7 mobile processors, 32nm |
1105 | + //0x2, 0xA - i7, 32nm |
1106 | + |
1107 | + //http://ark.intel.com/SSPECQDF.aspx |
1108 | + //http://software.intel.com/en-us/articles/intel-processor-identification-with-cpuid-model-and-family-numbers/ |
1109 | + printf("i7z DEBUG: msr = Model Specific Register\n"); |
1110 | + if (proc_info.family >= 0x6) |
1111 | + { |
1112 | + if (proc_info.extended_model == 0x1) |
1113 | + { |
1114 | + switch (proc_info.model) |
1115 | + { |
1116 | + case 0xA: |
1117 | + printf ("i7z DEBUG: Detected a nehalem (i7) - 45nm\n"); |
1118 | + break; |
1119 | + case 0xE: |
1120 | + case 0xF: |
1121 | + printf ("i7z DEBUG: Detected a nehalem (i7/i5/Xeon) - 45nm\n"); |
1122 | + break; |
1123 | + default: |
1124 | + printf ("i7z DEBUG: Unknown processor, not exactly based on Nehalem\n"); |
1125 | + //exit (1); |
1126 | + } |
1127 | + *nehalem = true; |
1128 | + *sandy_bridge = false; |
1129 | + } else if (proc_info.extended_model == 0x2) { |
1130 | + switch (proc_info.model) |
1131 | + { |
1132 | + case 0xE: |
1133 | + printf ("i7z DEBUG: Detected a Xeon MP - 45nm (7500, 6500 series)\n"); |
1134 | + *nehalem = true; |
1135 | + *sandy_bridge = false; |
1136 | + break; |
1137 | + case 0xF: |
1138 | + printf ("i7z DEBUG: Detected a Xeon MP - 32nm (E7 series)\n"); |
1139 | + *nehalem = true; |
1140 | + *sandy_bridge = false; |
1141 | + E7_mp_present = true; |
1142 | + break; |
1143 | + case 0xC: |
1144 | + *nehalem = true; |
1145 | + *sandy_bridge = false; |
1146 | + printf ("i7z DEBUG: Detected an i7/Xeon - 32 nm (westmere)\n"); |
1147 | + break; |
1148 | + case 0x5: |
1149 | + *nehalem = true; |
1150 | + *sandy_bridge = false; |
1151 | + printf ("i7z DEBUG: Detected an i3/i5/i7 - 32nm (westmere - 1st generation core)\n"); |
1152 | + break; |
1153 | + case 0xD: |
1154 | + *nehalem = false; |
1155 | + *sandy_bridge = true; |
1156 | + printf ("i7z DEBUG: Detected an i7 - 32nm (haven't seen this version around, do write to me with the model number)\n"); |
1157 | + break; |
1158 | + case 0xA: |
1159 | + *nehalem = false; |
1160 | + *sandy_bridge = true; |
1161 | + printf ("i7z DEBUG: Detected an i3/i5/i7 - 32nm (sandy bridge - 2nd generation core)\n"); |
1162 | + break; |
1163 | + default: |
1164 | + printf ("i7z DEBUG: Unknown processor, not exactly based on Nehalem\n"); |
1165 | + printf("i7z DEBUG: detected a newer model of ivy bridge processor\n"); |
1166 | + printf("i7z DEBUG: my coder doesn't know about it, can you send the following info to him?\n"); |
1167 | + printf("i7z DEBUG: model %x, extended model %x, proc_family %x\n", proc_info.model, proc_info.extended_model, proc_info.family); |
1168 | + //exit (1); |
1169 | + } |
1170 | + } else if (proc_info.extended_model == 0x3) { |
1171 | + switch (proc_info.model) |
1172 | + { |
1173 | + case 0xA: |
1174 | + printf ("i7z DEBUG: Detected an ivy bridege processor\n"); |
1175 | + *nehalem = false; |
1176 | + *sandy_bridge = true; |
1177 | + break; |
1178 | + default: |
1179 | + printf("i7z DEBUG: detected a newer model of ivy bridge processor\n"); |
1180 | + printf("i7z DEBUG: my coder doesn't know about it, can you send the following info to him?\n"); |
1181 | + printf("i7z DEBUG: model %x, extended model %x, proc_family %x\n", proc_info.model, proc_info.extended_model, proc_info.family); |
1182 | + sleep(5); |
1183 | + } |
1184 | + } else { |
1185 | + printf ("i7z DEBUG: Unknown processor, not exactly based on Nehalem, Sandy bridge or Ivy Bridge\n"); |
1186 | + //exit (1); |
1187 | + } |
1188 | + } else { |
1189 | + printf ("i7z DEBUG: Unknown processor, not exactly based on Nehalem\n"); |
1190 | + exit (1); |
1191 | + } |
1192 | + |
1193 | +} |
1194 | + |
1195 | +void Test_Or_Make_MSR_DEVICE_FILES() |
1196 | +{ |
1197 | + //test if the msr file exists |
1198 | + if (access ("/dev/cpu/0/msr", F_OK) == 0) |
1199 | + { |
1200 | + printf ("i7z DEBUG: msr device files exist /dev/cpu/*/msr\n"); |
1201 | + if (access ("/dev/cpu/0/msr", W_OK) == 0) |
1202 | + { |
1203 | + //a system mght have been set with msr allowable to be written |
1204 | + //by a normal user so... |
1205 | + //Do nothing. |
1206 | + printf ("i7z DEBUG: You have write permissions to msr device files\n"); |
1207 | + } else { |
1208 | + printf ("i7z DEBUG: You DONOT have write permissions to msr device files\n"); |
1209 | + printf ("i7z DEBUG: A solution is to run this program as root\n"); |
1210 | + exit (1); |
1211 | + } |
1212 | + } else { |
1213 | + printf ("i7z DEBUG: msr device files DONOT exist, trying out a makedev script\n"); |
1214 | + if (geteuid () == 0) |
1215 | + { |
1216 | + //Try the Makedev script |
1217 | + //sourced from MAKEDEV-cpuid-msr script in msr-tools |
1218 | + system ("msr_major=202; \ |
1219 | + cpuid_major=203; \ |
1220 | + n=0; \ |
1221 | + while [ $n -lt 16 ]; do \ |
1222 | + mkdir -m 0755 -p /dev/cpu/$n; \ |
1223 | + mknod /dev/cpu/$n/msr -m 0600 c $msr_major $n; \ |
1224 | + mknod /dev/cpu/$n/cpuid -m 0444 c $cpuid_major $n; \ |
1225 | + n=`expr $n + 1`; \ |
1226 | + done; \ |
1227 | + "); |
1228 | + printf ("i7z DEBUG: modprobbing for msr\n"); |
1229 | + system ("modprobe msr"); |
1230 | + } else { |
1231 | + printf ("i7z DEBUG: You DONOT have root privileges, mknod to create device entries won't work out\n"); |
1232 | + printf ("i7z DEBUG: A solution is to run this program as root\n"); |
1233 | + exit (1); |
1234 | + } |
1235 | + } |
1236 | +} |
1237 | +double cpufreq_info() |
1238 | +{ |
1239 | + //CPUINFO is wrong for i7 but correct for the number of physical and logical cores present |
1240 | + //If Hyperthreading is enabled then, multiple logical processors will share a common CORE ID |
1241 | + //http://www.redhat.com/magazine/022aug06/departments/tips_tricks/ |
1242 | + system |
1243 | + ("cat /proc/cpuinfo |grep MHz|sed 's/cpu\\sMHz\\s*:\\s//'|tail -n 1 > /tmp/cpufreq.txt"); |
1244 | + |
1245 | + |
1246 | + //Open the parsed cpufreq file and obtain the cpufreq from /proc/cpuinfo |
1247 | + FILE *tmp_file; |
1248 | + tmp_file = fopen ("/tmp/cpufreq.txt", "r"); |
1249 | + char tmp_str[30]; |
1250 | + fgets (tmp_str, 30, tmp_file); |
1251 | + fclose (tmp_file); |
1252 | + return atof(tmp_str); |
1253 | +} |
1254 | + |
1255 | +int check_and_return_processor(char*strinfo) |
1256 | +{ |
1257 | + char *t1; |
1258 | + if (strstr(strinfo,"processor") !=NULL) { |
1259 | + strtok(strinfo,":"); |
1260 | + t1 = strtok(NULL, " "); |
1261 | + return(atoi(t1)); |
1262 | + } else { |
1263 | + return(-1); |
1264 | + } |
1265 | +} |
1266 | + |
1267 | +int check_and_return_physical_id(char*strinfo) |
1268 | +{ |
1269 | + char *t1; |
1270 | + if (strstr(strinfo,"physical id") !=NULL) { |
1271 | + strtok(strinfo,":"); |
1272 | + t1 = strtok(NULL, " "); |
1273 | + return(atoi(t1)); |
1274 | + } else { |
1275 | + return(-1); |
1276 | + } |
1277 | +} |
1278 | + |
1279 | +int check_and_return_core_id(char*strinfo) |
1280 | +{ |
1281 | + char *t1; |
1282 | + if (strstr(strinfo,"core id") !=NULL) { |
1283 | + strtok(strinfo,":"); |
1284 | + t1 = strtok(NULL, " "); |
1285 | + return(atoi(t1)); |
1286 | + } else { |
1287 | + return(-1); |
1288 | + } |
1289 | +} |
1290 | + |
1291 | +void construct_sibling_list(struct cpu_heirarchy_info* chi) |
1292 | +{ |
1293 | + int i,j,core_id,socket_id; |
1294 | + for (i=0;i< chi->max_online_cpu ;i++) { |
1295 | + assert(i < MAX_HI_PROCESSORS); |
1296 | + chi->sibling_num[i]=-1; |
1297 | + } |
1298 | + |
1299 | + chi->HT=false; |
1300 | + for (i=0;i< chi->max_online_cpu ;i++) { |
1301 | + assert(i < MAX_HI_PROCESSORS); |
1302 | + core_id = chi->coreid_num[i]; |
1303 | + socket_id = chi->package_num[i]; |
1304 | + for (j=i+1;j< chi->max_online_cpu ;j++) { |
1305 | + assert(j < MAX_HI_PROCESSORS); |
1306 | + if (chi->coreid_num[j] == core_id && chi->package_num[j] == socket_id) { |
1307 | + chi->sibling_num[j] = i; |
1308 | + chi->sibling_num[i] = j; |
1309 | + chi->display_cores[i] = 1; |
1310 | + chi->display_cores[j] = -1; |
1311 | + chi->HT=true; |
1312 | + continue; |
1313 | + } |
1314 | + } |
1315 | + } |
1316 | + //for cores that donot have a sibling put in 1 |
1317 | + for (i=0;i< chi->max_online_cpu ;i++) { |
1318 | + assert(i < MAX_HI_PROCESSORS); |
1319 | + if (chi->sibling_num[i] ==-1) |
1320 | + chi->display_cores[i] = 1; |
1321 | + } |
1322 | +} |
1323 | + |
1324 | +void construct_socket_information(struct cpu_heirarchy_info* chi, |
1325 | + struct cpu_socket_info* socket_0,struct cpu_socket_info* socket_1, |
1326 | + int socket_0_num, int socket_1_num) |
1327 | +{ |
1328 | + int i; |
1329 | + |
1330 | + socket_0->max_cpu=0; |
1331 | + socket_0->num_physical_cores=0; |
1332 | + socket_0->num_logical_cores=0; |
1333 | + socket_1->max_cpu=0; |
1334 | + socket_1->num_physical_cores=0; |
1335 | + socket_1->num_logical_cores=0; |
1336 | + |
1337 | + |
1338 | + for (i=0;i< chi->max_online_cpu ;i++) { |
1339 | + assert(i < MAX_HI_PROCESSORS); |
1340 | + if (chi->display_cores[i]!=-1) { |
1341 | + if (chi->package_num[i]==socket_0_num) { |
1342 | + assert(socket_0->max_cpu < MAX_SK_PROCESSORS); |
1343 | + socket_0->processor_num[socket_0->max_cpu]=chi->processor_num[i]; |
1344 | + socket_0->max_cpu++; |
1345 | + socket_0->num_physical_cores++; |
1346 | + socket_0->num_logical_cores++; |
1347 | + } |
1348 | + if (chi->package_num[i]==socket_1_num) { |
1349 | + assert(socket_1->max_cpu < MAX_SK_PROCESSORS); |
1350 | + socket_1->processor_num[socket_1->max_cpu]=chi->processor_num[i]; |
1351 | + socket_1->max_cpu++; |
1352 | + socket_1->num_physical_cores++; |
1353 | + socket_1->num_logical_cores++; |
1354 | + } |
1355 | + } else { |
1356 | + if (chi->package_num[i]==socket_0_num) { |
1357 | + socket_0->num_logical_cores++; |
1358 | + } |
1359 | + if (chi->package_num[i]==socket_1_num) { |
1360 | + socket_1->num_logical_cores++; |
1361 | + } |
1362 | + } |
1363 | + } |
1364 | +} |
1365 | + |
1366 | +void print_socket_information(struct cpu_socket_info* socket) |
1367 | +{ |
1368 | + int i; |
1369 | + char socket_list[200]=""; |
1370 | + |
1371 | + for (i=0;i< socket->max_cpu ;i++) { |
1372 | + assert(i < MAX_SK_PROCESSORS); |
1373 | + if (socket->processor_num[i]!=-1) { |
1374 | + sprintf(socket_list,"%s%d,",socket_list,socket->processor_num[i]); |
1375 | + } |
1376 | + } |
1377 | + printf("Socket-%d [num of cpus %d physical %d logical %d] %s\n",socket->socket_num,socket->max_cpu,socket->num_physical_cores,socket->num_logical_cores,socket_list); |
1378 | +} |
1379 | + |
1380 | +void construct_CPU_Heirarchy_info(struct cpu_heirarchy_info* chi) |
1381 | +{ |
1382 | + FILE *fp = fopen("/proc/cpuinfo","r"); |
1383 | + char strinfo[200]; |
1384 | + |
1385 | + int processor_num, physicalid_num, coreid_num; |
1386 | + int it_processor_num=-1, it_physicalid_num=-1, it_coreid_num=-1; |
1387 | + int tmp_processor_num, tmp_physicalid_num, tmp_coreid_num; |
1388 | + int old_processor_num=-1; |
1389 | + |
1390 | + memset(chi, 0, sizeof(*chi)); |
1391 | + |
1392 | + if (fp!=NULL) { |
1393 | + while ( fgets(strinfo,200,fp) != NULL) { |
1394 | + // printf(strinfo); |
1395 | + tmp_processor_num = check_and_return_processor(strinfo); |
1396 | + tmp_physicalid_num = check_and_return_physical_id(strinfo); |
1397 | + tmp_coreid_num = check_and_return_core_id(strinfo); |
1398 | + |
1399 | + |
1400 | + if (tmp_processor_num != -1) { |
1401 | + it_processor_num++; |
1402 | + processor_num = tmp_processor_num; |
1403 | + assert(it_processor_num < MAX_HI_PROCESSORS); |
1404 | + chi->processor_num[it_processor_num] = processor_num; |
1405 | + } |
1406 | + if (tmp_physicalid_num != -1) { |
1407 | + it_physicalid_num++; |
1408 | + physicalid_num = tmp_physicalid_num; |
1409 | + assert(it_physicalid_num < MAX_HI_PROCESSORS); |
1410 | + chi->package_num[it_physicalid_num] = physicalid_num; |
1411 | + } |
1412 | + if (tmp_coreid_num != -1) { |
1413 | + it_coreid_num++; |
1414 | + coreid_num = tmp_coreid_num; |
1415 | + assert(it_coreid_num < MAX_HI_PROCESSORS); |
1416 | + chi->coreid_num[it_coreid_num] = coreid_num; |
1417 | + } |
1418 | + if (processor_num != old_processor_num) { |
1419 | + old_processor_num = processor_num; |
1420 | + } |
1421 | + } |
1422 | + } |
1423 | + chi->max_online_cpu = it_processor_num+1; |
1424 | + fclose(fp); |
1425 | +} |
1426 | + |
1427 | +void print_CPU_Heirarchy(struct cpu_heirarchy_info chi) |
1428 | +{ |
1429 | + int i; |
1430 | + printf("\n------------------------------\n--[core id]--- Other information\n-------------------------------------\n"); |
1431 | + for (i=0;i < chi.max_online_cpu;i++) { |
1432 | + assert(i < MAX_HI_PROCESSORS); |
1433 | + printf("--[%d] Processor number %d\n",i,chi.processor_num[i]); |
1434 | + printf("--[%d] Socket number/Hyperthreaded Sibling number %d,%d\n",i,chi.package_num[i],chi.sibling_num[i]); |
1435 | + printf("--[%d] Core id number %d\n",i,chi.coreid_num[i]); |
1436 | + printf("--[%d] Display core in i7z Tool: %s\n\n",i,(chi.display_cores[i]==1)?"Yes":"No"); |
1437 | + } |
1438 | +} |
1439 | + |
1440 | +int in_core_list(int ii,int* core_list) |
1441 | +{ |
1442 | + int i; |
1443 | + int in=0; |
1444 | + for (i=0;i<8;i++) { |
1445 | + if (ii == core_list[i]) { |
1446 | + in=1; |
1447 | + break; |
1448 | + } |
1449 | + } |
1450 | + return(in); |
1451 | +} |
1452 | + |
1453 | +bool file_exists(char* filename) |
1454 | +{ |
1455 | + if (access(filename, F_OK) == 0) |
1456 | + { |
1457 | + return true; |
1458 | + } else { |
1459 | + return false; |
1460 | + } |
1461 | +} |
1462 | |
1463 | === added file '.pc/fix-insecure-tempfile.patch/i7z_Single_Socket.c' |
1464 | --- .pc/fix-insecure-tempfile.patch/i7z_Single_Socket.c 1970-01-01 00:00:00 +0000 |
1465 | +++ .pc/fix-insecure-tempfile.patch/i7z_Single_Socket.c 2013-08-15 05:58:18 +0000 |
1466 | @@ -0,0 +1,1216 @@ |
1467 | +//i7z_Single_Socket.c |
1468 | +/* ----------------------------------------------------------------------- * |
1469 | + * |
1470 | + * Copyright 2010 Abhishek Jaiantilal |
1471 | + * |
1472 | + * Under GPL v2 |
1473 | + * |
1474 | + * ----------------------------------------------------------------------- */ |
1475 | +#include <memory.h> |
1476 | +#include <errno.h> |
1477 | +#include <stdio.h> |
1478 | +#include <fcntl.h> |
1479 | +#include <unistd.h> |
1480 | +#include <stdlib.h> |
1481 | +#include <getopt.h> |
1482 | +#include <inttypes.h> |
1483 | +#include <sys/types.h> |
1484 | +#include <sys/time.h> |
1485 | +#include <time.h> |
1486 | +#include <math.h> |
1487 | +#include <assert.h> |
1488 | +#include <ncurses.h> |
1489 | +#include "i7z.h" |
1490 | + |
1491 | +#define U_L_I unsigned long int |
1492 | +#define U_L_L_I unsigned long long int |
1493 | +#define numCPUs_max MAX_PROCESSORS |
1494 | + |
1495 | +extern int socket_0_num, socket_1_num; |
1496 | +extern bool E7_mp_present; |
1497 | +extern int numPhysicalCores, numLogicalCores; |
1498 | +extern double TRUE_CPU_FREQ; |
1499 | +int Read_Thermal_Status_CPU(int cpu_num); |
1500 | + |
1501 | +extern struct program_options prog_options; |
1502 | +extern FILE *fp_log_file_freq; |
1503 | + |
1504 | +struct timespec global_ts; |
1505 | + |
1506 | +extern char* CPU_FREQUENCY_LOGGING_FILE_single; |
1507 | +extern char* CPU_FREQUENCY_LOGGING_FILE_dual; |
1508 | +extern bool use_ncurses; |
1509 | + |
1510 | +void logCpuFreq_single_ts( struct timespec*); |
1511 | + |
1512 | + |
1513 | +void print_i7z_socket_single(struct cpu_socket_info socket_0, int printw_offset, int PLATFORM_INFO_MSR, int PLATFORM_INFO_MSR_high, int PLATFORM_INFO_MSR_low, |
1514 | + int* online_cpus, double cpu_freq_cpuinfo, struct timespec one_second_sleep, char TURBO_MODE, |
1515 | + char* HT_ON_str, int* kk_1, U_L_L_I * old_val_CORE, U_L_L_I * old_val_REF, U_L_L_I * old_val_C3, U_L_L_I * old_val_C6, U_L_L_I * old_val_C7, |
1516 | + U_L_L_I * old_TSC, int estimated_mhz, U_L_L_I * new_val_CORE, U_L_L_I * new_val_REF, U_L_L_I * new_val_C3, |
1517 | + U_L_L_I * new_val_C6, U_L_L_I * new_val_C7, U_L_L_I * new_TSC, double* _FREQ, double* _MULT, long double * C0_time, long double * C1_time, |
1518 | + long double * C3_time, long double * C6_time, long double * C7_time, struct timeval* tvstart, struct timeval* tvstop, int *max_observed_cpu); |
1519 | + |
1520 | +void print_i7z_single (); |
1521 | + |
1522 | +int Single_Socket () |
1523 | +{ |
1524 | + //zero up the file before doing anything |
1525 | + if(prog_options.logging!=0){ |
1526 | + fp_log_file_freq = fopen(CPU_FREQUENCY_LOGGING_FILE_single,"w"); |
1527 | + fclose(fp_log_file_freq); |
1528 | + } |
1529 | + |
1530 | + |
1531 | + printf ("i7z DEBUG: In i7z Single_Socket()\n"); |
1532 | + |
1533 | + if (prog_options.i7_version.sandy_bridge) |
1534 | + printf ("i7z DEBUG: guessing Sandy Bridge\n"); |
1535 | + else |
1536 | + printf ("i7z DEBUG: guessing Nehalem\n"); |
1537 | + |
1538 | + |
1539 | + sleep (3); |
1540 | + |
1541 | + if (use_ncurses){ |
1542 | + //int row, col; |
1543 | + /* to store the number of rows and * |
1544 | + * the number of colums of the screen * |
1545 | + * for NCURSES */ |
1546 | + //Setup stuff for ncurses |
1547 | + initscr (); /* start the curses mode */ |
1548 | + start_color (); |
1549 | + //getmaxyx (stdscr, row, col); /* get the number of rows and columns */ |
1550 | + refresh (); |
1551 | + //Setup for ncurses completed |
1552 | + } |
1553 | + print_i7z_single(); |
1554 | + exit (0); |
1555 | + return (1); |
1556 | +} |
1557 | + |
1558 | +void print_i7z_socket_single(struct cpu_socket_info socket_0, int printw_offset, int PLATFORM_INFO_MSR, int PLATFORM_INFO_MSR_high, int PLATFORM_INFO_MSR_low, |
1559 | + int* online_cpus, double cpu_freq_cpuinfo, struct timespec one_second_sleep, char TURBO_MODE, |
1560 | + char* HT_ON_str, int* kk_1, U_L_L_I * old_val_CORE, U_L_L_I * old_val_REF, U_L_L_I * old_val_C3, U_L_L_I * old_val_C6, U_L_L_I * old_val_C7, |
1561 | + U_L_L_I * old_TSC, int estimated_mhz, U_L_L_I * new_val_CORE, U_L_L_I * new_val_REF, U_L_L_I * new_val_C3, |
1562 | + U_L_L_I * new_val_C6, U_L_L_I * new_val_C7, U_L_L_I * new_TSC, double* _FREQ, double* _MULT, long double * C0_time, long double * C1_time, |
1563 | + long double * C3_time, long double * C6_time, long double * C7_time, struct timeval* tvstart, struct timeval* tvstop, int *max_observed_cpu) |
1564 | +{ |
1565 | + int numPhysicalCores, numLogicalCores; |
1566 | + double TRUE_CPU_FREQ; |
1567 | + |
1568 | + //Print a slew of information on the ncurses window |
1569 | + mvprintw (0, 0, "Cpu speed from cpuinfo %0.2fMhz\n", cpu_freq_cpuinfo); |
1570 | + mvprintw (1, 0, |
1571 | + "cpuinfo might be wrong if cpufreq is enabled. To guess correctly try estimating via tsc\n"); |
1572 | + mvprintw (2, 0, "Linux's inbuilt cpu_khz code emulated now\n\n"); |
1573 | + |
1574 | + |
1575 | + //estimate the freq using the estimate_MHz() code that is almost mhz accurate |
1576 | + cpu_freq_cpuinfo = estimate_MHz (); |
1577 | + mvprintw (3, 0, "True Frequency (without accounting Turbo) %0.0f MHz\n", |
1578 | + cpu_freq_cpuinfo); |
1579 | + |
1580 | + int i, ii; |
1581 | + //int k; |
1582 | + int CPU_NUM; |
1583 | + int* core_list; |
1584 | + unsigned long int IA32_MPERF, IA32_APERF; |
1585 | + int CPU_Multiplier, error_indx; |
1586 | + unsigned long long int CPU_CLK_UNHALTED_CORE, CPU_CLK_UNHALTED_REF, CPU_CLK_C3, CPU_CLK_C6, CPU_CLK_C1, CPU_CLK_C7; |
1587 | + //current blck value |
1588 | + float BLCK; |
1589 | + |
1590 | + char print_core[32]; |
1591 | + long double c1_time; |
1592 | + |
1593 | + //use this variable to monitor the max number of cores ever online |
1594 | + *max_observed_cpu = (socket_0.max_cpu > *max_observed_cpu)? socket_0.max_cpu: *max_observed_cpu; |
1595 | + |
1596 | + int core_list_size_phy, core_list_size_log; |
1597 | + if (socket_0.max_cpu > 0) { |
1598 | + //set the variable print_core to 0, use it to check if a core is online and doesnt |
1599 | + //have any garbage values |
1600 | + memset(print_core, 0, 6*sizeof(char)); |
1601 | + |
1602 | + //We just need one CPU (we use Core-1) to figure out the multiplier and the bus clock freq. |
1603 | + //multiplier doesnt automatically include turbo |
1604 | + //note turbo is not guaranteed, only promised |
1605 | + //So this msr will only reflect the actual multiplier, rest has to be figured out |
1606 | + |
1607 | + //Now get all the information about the socket from the structure |
1608 | + CPU_NUM = socket_0.processor_num[0]; |
1609 | + core_list = socket_0.processor_num; |
1610 | + core_list_size_phy = socket_0.num_physical_cores; |
1611 | + core_list_size_log = socket_0.num_logical_cores; |
1612 | + |
1613 | + /*if (CPU_NUM == -1) |
1614 | + { |
1615 | + sleep (1); //sleep for a bit hoping that the offline socket becomes online |
1616 | + continue; |
1617 | + }*/ |
1618 | + //number of CPUs is as told via cpuinfo |
1619 | + int numCPUs = socket_0.num_physical_cores; |
1620 | + |
1621 | + CPU_Multiplier = get_msr_value (CPU_NUM, PLATFORM_INFO_MSR, PLATFORM_INFO_MSR_high, PLATFORM_INFO_MSR_low, &error_indx); |
1622 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
1623 | + |
1624 | + //Blck is basically the true speed divided by the multiplier |
1625 | + BLCK = cpu_freq_cpuinfo / CPU_Multiplier; |
1626 | + |
1627 | + //Use Core-1 as the one to check for the turbo limit |
1628 | + //Core number shouldnt matter |
1629 | + |
1630 | + //bits from 0-63 in this store the various maximum turbo limits |
1631 | + int MSR_TURBO_RATIO_LIMIT = 429; |
1632 | + // 3B defines till Max 4 Core and the rest bit values from 32:63 were reserved. |
1633 | + int MAX_TURBO_1C=0, MAX_TURBO_2C=0, MAX_TURBO_3C=0, |
1634 | + MAX_TURBO_4C=0, MAX_TURBO_5C=0, MAX_TURBO_6C=0; |
1635 | + |
1636 | + if ( E7_mp_present){ |
1637 | + //e7 mp dont have 429 register so dont read the register. |
1638 | + } else { |
1639 | + //Bits:0-7 - core1 |
1640 | + MAX_TURBO_1C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 7, 0, &error_indx); |
1641 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
1642 | + //Bits:15-8 - core2 |
1643 | + MAX_TURBO_2C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 15, 8, &error_indx); |
1644 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
1645 | + //Bits:23-16 - core3 |
1646 | + MAX_TURBO_3C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 23, 16, &error_indx); |
1647 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
1648 | + //Bits:31-24 - core4 |
1649 | + MAX_TURBO_4C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 31, 24, &error_indx); |
1650 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
1651 | + |
1652 | + //gulftown/Hexacore support |
1653 | + //technically these should be the bits to get for core 5,6 |
1654 | + //Bits:39-32 - core4 |
1655 | + MAX_TURBO_5C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 39, 32, &error_indx); |
1656 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
1657 | + //Bits:47-40 - core4 |
1658 | + MAX_TURBO_6C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 47, 40, &error_indx); |
1659 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
1660 | + } |
1661 | + //fflush (stdout); |
1662 | + //sleep (1); |
1663 | + |
1664 | + char string_ptr1[200], string_ptr2[200]; |
1665 | + |
1666 | + int IA32_PERF_GLOBAL_CTRL = 911; //38F |
1667 | + int IA32_PERF_GLOBAL_CTRL_Value; |
1668 | + IA32_PERF_GLOBAL_CTRL_Value = get_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 63, 0, &error_indx); |
1669 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
1670 | + RETURN_IF_TRUE(online_cpus[0]==-1); |
1671 | + |
1672 | + int IA32_FIXED_CTR_CTL = 909; //38D |
1673 | + int IA32_FIXED_CTR_CTL_Value; |
1674 | + IA32_FIXED_CTR_CTL_Value = get_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 63, 0, &error_indx); |
1675 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
1676 | + RETURN_IF_TRUE(online_cpus[0]==-1); |
1677 | + |
1678 | + |
1679 | + IA32_MPERF = get_msr_value (CPU_NUM, 231, 7, 0, &error_indx); |
1680 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
1681 | + RETURN_IF_TRUE(online_cpus[0]==-1); |
1682 | + |
1683 | + IA32_APERF = get_msr_value (CPU_NUM, 232, 7, 0, &error_indx); |
1684 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
1685 | + RETURN_IF_TRUE(online_cpus[0]==-1); |
1686 | + |
1687 | + CPU_CLK_UNHALTED_CORE = get_msr_value (CPU_NUM, 778, 63, 0, &error_indx); |
1688 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
1689 | + RETURN_IF_TRUE(online_cpus[0]==-1); |
1690 | + |
1691 | + CPU_CLK_UNHALTED_REF = get_msr_value (CPU_NUM, 779, 63, 0, &error_indx); |
1692 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
1693 | + RETURN_IF_TRUE(online_cpus[0]==-1); |
1694 | + |
1695 | + //SLEEP FOR 1 SECOND (500ms is also alright) |
1696 | + nanosleep (&one_second_sleep, NULL); |
1697 | + IA32_MPERF = get_msr_value (CPU_NUM, 231, 7, 0, &error_indx) - IA32_MPERF; |
1698 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
1699 | + RETURN_IF_TRUE(online_cpus[0]==-1); |
1700 | + |
1701 | + IA32_APERF = get_msr_value (CPU_NUM, 232, 7, 0, &error_indx) - IA32_APERF; |
1702 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
1703 | + RETURN_IF_TRUE(online_cpus[0]==-1); |
1704 | + |
1705 | + mvprintw (4 + printw_offset, 0," CPU Multiplier %dx || Bus clock frequency (BCLK) %0.2f MHz \n", CPU_Multiplier, BLCK); |
1706 | + |
1707 | + if (numCPUs <= 0) { |
1708 | + sprintf (string_ptr1, " Max TURBO Multiplier (if Enabled) with 0 cores is"); |
1709 | + sprintf (string_ptr2, " %dx/%dx ", MAX_TURBO_1C, MAX_TURBO_2C); |
1710 | + } |
1711 | + if (numCPUs >= 1 && numCPUs < 4) { |
1712 | + sprintf (string_ptr1, " Max TURBO Multiplier (if Enabled) with 1/2 Cores is"); |
1713 | + sprintf (string_ptr2, " "); |
1714 | + } |
1715 | + if (numCPUs >= 2 && numCPUs < 6) { |
1716 | + sprintf (string_ptr1, " Max TURBO Multiplier (if Enabled) with 1/2/3/4 Cores is"); |
1717 | + sprintf (string_ptr2, " %dx/%dx/%dx/%dx ", MAX_TURBO_1C, MAX_TURBO_2C, MAX_TURBO_3C, MAX_TURBO_4C); |
1718 | + } |
1719 | + if (numCPUs >= 2 && numCPUs >= 6) { // Gulftown 6-cores, Nehalem-EX |
1720 | + sprintf (string_ptr1, " Max TURBO Multiplier (if Enabled) with 1/2/3/4/5/6 Cores is"); |
1721 | + sprintf (string_ptr2, " %dx/%dx/%dx/%dx/%dx/%dx ", MAX_TURBO_1C, MAX_TURBO_2C, MAX_TURBO_3C, MAX_TURBO_4C, |
1722 | + MAX_TURBO_5C, MAX_TURBO_6C); |
1723 | + } |
1724 | + |
1725 | + numCPUs = core_list_size_phy; |
1726 | + numPhysicalCores = core_list_size_phy; |
1727 | + numLogicalCores = core_list_size_log; |
1728 | + |
1729 | + //if (socket_0.socket_num == 0) { |
1730 | + mvprintw (19, 0, "C0 = Processor running without halting"); |
1731 | + mvprintw (20, 0, "C1 = Processor running with halts (States >C0 are power saver)"); |
1732 | + mvprintw (21, 0, "C3 = Cores running with PLL turned off and core cache turned off"); |
1733 | + mvprintw (22, 0, "C6 = Everything in C3 + core state saved to last level cache"); |
1734 | + mvprintw (23, 0, " Above values in table are in percentage over the last 1 sec"); |
1735 | +// mvprintw (24, 0, "Total Logical Cores: [%d], Total Physical Cores: [%d] \n", numLogicalCores, numPhysicalCores); |
1736 | + mvprintw (24, 0, "[core-id] refers to core-id number in /proc/cpuinfo"); |
1737 | + mvprintw (25, 0, "'Garbage Values' message printed when garbage values are read"); |
1738 | + mvprintw (26, 0, " Ctrl+C to exit"); |
1739 | + //} |
1740 | + |
1741 | + mvprintw (6 + printw_offset, 0, "Socket [%d] - [physical cores=%d, logical cores=%d, max online cores ever=%d] \n", socket_0.socket_num, numPhysicalCores, numLogicalCores,*max_observed_cpu); |
1742 | + |
1743 | + mvprintw (9 + printw_offset, 0, "%s %s\n", string_ptr1, string_ptr2); |
1744 | + |
1745 | + if (TURBO_MODE == 1) { |
1746 | + mvprintw (7 + printw_offset, 0, " TURBO ENABLED on %d Cores, %s\n", numPhysicalCores, HT_ON_str); |
1747 | + TRUE_CPU_FREQ = BLCK * ((double) CPU_Multiplier + 1); |
1748 | + mvprintw (8 + printw_offset, 0, " Max Frequency without considering Turbo %0.2f MHz (%0.2f x [%d]) \n", TRUE_CPU_FREQ, BLCK, CPU_Multiplier + 1); |
1749 | + } else { |
1750 | + mvprintw (7 + printw_offset, 0, " TURBO DISABLED on %d Cores, %s\n", numPhysicalCores, HT_ON_str); |
1751 | + TRUE_CPU_FREQ = BLCK * ((double) CPU_Multiplier); |
1752 | + mvprintw (8 + printw_offset, 0," Max Frequency without considering Turbo %0.2f MHz (%0.2f x [%d]) \n", TRUE_CPU_FREQ, BLCK, CPU_Multiplier); |
1753 | + } |
1754 | + |
1755 | + //Primarily for 32-bit users, found that after sometimes the counters loopback, so inorder |
1756 | + //to prevent loopback, reset the counters back to 0 after 10 iterations roughly 10 secs |
1757 | + if (*kk_1 > 10) { |
1758 | + *kk_1 = 0; |
1759 | + for (i = 0; i < numCPUs; i++) { |
1760 | + //Set up the performance counters and then start reading from them |
1761 | + assert(i < MAX_SK_PROCESSORS); |
1762 | + CPU_NUM = core_list[i]; |
1763 | + ii = core_list[i]; |
1764 | + assert(i < MAX_PROCESSORS); //online_cpus[i] |
1765 | + assert(ii < numCPUs_max); |
1766 | + |
1767 | + IA32_PERF_GLOBAL_CTRL_Value = get_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 63, 0, &error_indx); |
1768 | + SET_IF_TRUE(error_indx,online_cpus[i],-1); |
1769 | + CONTINUE_IF_TRUE(online_cpus[i]==-1); |
1770 | + |
1771 | + set_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 0x700000003LLU); |
1772 | + |
1773 | + IA32_FIXED_CTR_CTL_Value = get_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 63, 0, &error_indx); |
1774 | + SET_IF_TRUE(error_indx,online_cpus[i],-1); |
1775 | + CONTINUE_IF_TRUE(online_cpus[i]==-1); |
1776 | + |
1777 | + set_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 819); |
1778 | + |
1779 | + IA32_PERF_GLOBAL_CTRL_Value = get_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 63, 0, &error_indx); |
1780 | + SET_IF_TRUE(error_indx,online_cpus[i],-1); |
1781 | + CONTINUE_IF_TRUE(online_cpus[i]==-1); |
1782 | + |
1783 | + IA32_FIXED_CTR_CTL_Value = get_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 63, 0, &error_indx); |
1784 | + SET_IF_TRUE(error_indx,online_cpus[i],-1); |
1785 | + CONTINUE_IF_TRUE(online_cpus[i]==-1); |
1786 | + |
1787 | + old_val_CORE[ii] = get_msr_value (CPU_NUM, 778, 63, 0, &error_indx); |
1788 | + SET_IF_TRUE(error_indx,online_cpus[i],-1); |
1789 | + CONTINUE_IF_TRUE(online_cpus[i]==-1); |
1790 | + |
1791 | + old_val_REF[ii] = get_msr_value (CPU_NUM, 779, 63, 0, &error_indx); |
1792 | + SET_IF_TRUE(error_indx,online_cpus[i],-1); |
1793 | + CONTINUE_IF_TRUE(online_cpus[i]==-1); |
1794 | + |
1795 | + old_val_C3[ii] = get_msr_value (CPU_NUM, 1020, 63, 0, &error_indx); |
1796 | + SET_IF_TRUE(error_indx,online_cpus[i],-1); |
1797 | + CONTINUE_IF_TRUE(online_cpus[i]==-1); |
1798 | + |
1799 | + old_val_C6[ii] = get_msr_value (CPU_NUM, 1021, 63, 0, &error_indx); |
1800 | + SET_IF_TRUE(error_indx,online_cpus[i],-1); |
1801 | + CONTINUE_IF_TRUE(online_cpus[i]==-1); |
1802 | + |
1803 | + if(prog_options.i7_version.sandy_bridge){ |
1804 | + //table b-20 in 325384 and only for sandy bridge |
1805 | + old_val_C7[ii] = get_msr_value (CPU_NUM, 1022, 63, 0, &error_indx); |
1806 | + SET_IF_TRUE(error_indx,online_cpus[i],-1); |
1807 | + CONTINUE_IF_TRUE(online_cpus[i]==-1); |
1808 | + } |
1809 | + |
1810 | + old_TSC[ii] = rdtsc (); |
1811 | + } |
1812 | + } |
1813 | + (*kk_1)++; |
1814 | + nanosleep (&one_second_sleep, NULL); |
1815 | + if(prog_options.i7_version.sandy_bridge){ |
1816 | + mvprintw (11 + printw_offset, 0, "\tCore [core-id] :Actual Freq (Mult.)\t C0%% Halt(C1)%% C3 %% C6 %% C7 %% Temp\n"); |
1817 | + }else{ |
1818 | + mvprintw (11 + printw_offset, 0, "\tCore [core-id] :Actual Freq (Mult.)\t C0%% Halt(C1)%% C3 %% C6 %% Temp\n"); |
1819 | + } |
1820 | + //estimate the CPU speed |
1821 | + estimated_mhz = estimate_MHz (); |
1822 | + |
1823 | + for (i = 0; i < numCPUs; i++) { |
1824 | + //read from the performance counters |
1825 | + //things like halted unhalted core cycles |
1826 | + |
1827 | + assert(i < MAX_SK_PROCESSORS); |
1828 | + CPU_NUM = core_list[i]; |
1829 | + ii = core_list[i]; |
1830 | + assert(i < MAX_PROCESSORS); //online_cpus[i] |
1831 | + assert(ii < numCPUs_max); |
1832 | + |
1833 | + new_val_CORE[ii] = get_msr_value (CPU_NUM, 778, 63, 0, &error_indx); |
1834 | + SET_IF_TRUE(error_indx,online_cpus[i],-1); |
1835 | + CONTINUE_IF_TRUE(online_cpus[i]==-1); |
1836 | + |
1837 | + new_val_REF[ii] = get_msr_value (CPU_NUM, 779, 63, 0, &error_indx); |
1838 | + SET_IF_TRUE(error_indx,online_cpus[i],-1); |
1839 | + CONTINUE_IF_TRUE(online_cpus[i]==-1); |
1840 | + |
1841 | + new_val_C3[ii] = get_msr_value (CPU_NUM, 1020, 63, 0, &error_indx); |
1842 | + SET_IF_TRUE(error_indx,online_cpus[i],-1); |
1843 | + CONTINUE_IF_TRUE(online_cpus[i]==-1); |
1844 | + |
1845 | + new_val_C6[ii] = get_msr_value (CPU_NUM, 1021, 63, 0, &error_indx); |
1846 | + SET_IF_TRUE(error_indx,online_cpus[i],-1); |
1847 | + CONTINUE_IF_TRUE(online_cpus[i]==-1); |
1848 | + |
1849 | + if(prog_options.i7_version.sandy_bridge){ |
1850 | + new_val_C7[ii] = get_msr_value (CPU_NUM, 1022, 63, 0, &error_indx); |
1851 | + SET_IF_TRUE(error_indx,online_cpus[i],-1); |
1852 | + CONTINUE_IF_TRUE(online_cpus[i]==-1); |
1853 | + } |
1854 | + |
1855 | + new_TSC[ii] = rdtsc (); |
1856 | + |
1857 | + if (old_val_CORE[ii] > new_val_CORE[ii]) { //handle overflow |
1858 | + CPU_CLK_UNHALTED_CORE = (UINT64_MAX - old_val_CORE[ii]) + new_val_CORE[ii]; |
1859 | + } else { |
1860 | + CPU_CLK_UNHALTED_CORE = new_val_CORE[ii] - old_val_CORE[ii]; |
1861 | + } |
1862 | + |
1863 | + //number of TSC cycles while its in halted state |
1864 | + if ((new_TSC[ii] - old_TSC[ii]) < CPU_CLK_UNHALTED_CORE) { |
1865 | + CPU_CLK_C1 = 0; |
1866 | + } else { |
1867 | + CPU_CLK_C1 = ((new_TSC[ii] - old_TSC[ii]) - CPU_CLK_UNHALTED_CORE); |
1868 | + } |
1869 | + |
1870 | + if (old_val_REF[ii] > new_val_REF[ii]) { //handle overflow |
1871 | + CPU_CLK_UNHALTED_REF = (UINT64_MAX - old_val_REF[ii]) + new_val_REF[ii]; //3.40282366921e38 |
1872 | + } else { |
1873 | + CPU_CLK_UNHALTED_REF = new_val_REF[ii] - old_val_REF[ii]; |
1874 | + } |
1875 | + |
1876 | + if (old_val_C3[ii] > new_val_C3[ii]) { //handle overflow |
1877 | + CPU_CLK_C3 = (UINT64_MAX - old_val_C3[ii]) + new_val_C3[ii]; |
1878 | + } else { |
1879 | + CPU_CLK_C3 = new_val_C3[ii] - old_val_C3[ii]; |
1880 | + } |
1881 | + |
1882 | + if (old_val_C6[ii] > new_val_C6[ii]) { //handle overflow |
1883 | + CPU_CLK_C6 = (UINT64_MAX - old_val_C6[ii]) + new_val_C6[ii]; |
1884 | + } else { |
1885 | + CPU_CLK_C6 = new_val_C6[ii] - old_val_C6[ii]; |
1886 | + } |
1887 | + |
1888 | + if(prog_options.i7_version.sandy_bridge){ |
1889 | + if (old_val_C7[ii] > new_val_C7[ii]) { //handle overflow |
1890 | + CPU_CLK_C7 = (UINT64_MAX - old_val_C7[ii]) + new_val_C7[ii]; |
1891 | + } else { |
1892 | + CPU_CLK_C7 = new_val_C7[ii] - old_val_C7[ii]; |
1893 | + } |
1894 | + } |
1895 | + |
1896 | + _FREQ[ii] = |
1897 | + THRESHOLD_BETWEEN_0_6000(estimated_mhz * ((long double) CPU_CLK_UNHALTED_CORE / |
1898 | + (long double) CPU_CLK_UNHALTED_REF)); |
1899 | + _MULT[ii] = _FREQ[ii] / BLCK; |
1900 | + |
1901 | + C0_time[ii] = ((long double) CPU_CLK_UNHALTED_REF / |
1902 | + (long double) (new_TSC[ii] - old_TSC[ii])); |
1903 | + C1_time[ii] = ((long double) CPU_CLK_C1 / |
1904 | + (long double) (new_TSC[ii] - old_TSC[ii])); |
1905 | + C3_time[ii] = ((long double) CPU_CLK_C3 / |
1906 | + (long double) (new_TSC[ii] - old_TSC[ii])); |
1907 | + C6_time[ii] = ((long double) CPU_CLK_C6 / |
1908 | + (long double) (new_TSC[ii] - old_TSC[ii])); |
1909 | + |
1910 | + if(prog_options.i7_version.sandy_bridge){ |
1911 | + C7_time[ii] = ((long double) CPU_CLK_C7 / |
1912 | + (long double) (new_TSC[ii] - old_TSC[ii])); |
1913 | + } |
1914 | + |
1915 | + if (C0_time[ii] < 1e-2) { |
1916 | + if (C0_time[ii] > 1e-4) { |
1917 | + C0_time[ii] = 0.01; |
1918 | + } else { |
1919 | + C0_time[ii] = 0; |
1920 | + } |
1921 | + } |
1922 | + if (C1_time[ii] < 1e-2) { |
1923 | + if (C1_time[ii] > 1e-4) { |
1924 | + C1_time[ii] = 0.01; |
1925 | + } else { |
1926 | + C1_time[ii] = 0; |
1927 | + } |
1928 | + } |
1929 | + if (C3_time[ii] < 1e-2) { |
1930 | + if (C3_time[ii] > 1e-4) { |
1931 | + C3_time[ii] = 0.01; |
1932 | + } else { |
1933 | + C3_time[ii] = 0; |
1934 | + } |
1935 | + } |
1936 | + if (C6_time[ii] < 1e-2) { |
1937 | + if (C6_time[ii] > 1e-4) { |
1938 | + C6_time[ii] = 0.01; |
1939 | + } else { |
1940 | + C6_time[ii] = 0; |
1941 | + } |
1942 | + } |
1943 | + if(prog_options.i7_version.sandy_bridge){ |
1944 | + if (C7_time[ii] < 1e-2) { |
1945 | + if (C7_time[ii] > 1e-4) { |
1946 | + C7_time[ii] = 0.01; |
1947 | + } else { |
1948 | + C7_time[ii] = 0; |
1949 | + } |
1950 | + } |
1951 | + } |
1952 | + } |
1953 | + //CHECK IF ALL COUNTERS ARE CORRECT AND NO GARBAGE VALUES ARE PRESENT |
1954 | + //If there is any garbage values set print_core[i] to 0 |
1955 | + for (ii = 0; ii < numCPUs; ii++) { |
1956 | + assert(ii < MAX_SK_PROCESSORS); |
1957 | + i = core_list[ii]; |
1958 | + if(prog_options.i7_version.sandy_bridge){ |
1959 | + if ( !IS_THIS_BETWEEN_0_100(C0_time[i] * 100) || |
1960 | + !IS_THIS_BETWEEN_0_100(C1_time[i] * 100 - (C3_time[i] + C6_time[i]) * 100) || |
1961 | + !IS_THIS_BETWEEN_0_100(C3_time[i] * 100) || |
1962 | + !IS_THIS_BETWEEN_0_100(C6_time[i] * 100) || |
1963 | + !IS_THIS_BETWEEN_0_100(C7_time[i] * 100) || |
1964 | + isinf(_FREQ[i]) ) |
1965 | + print_core[ii]=0; |
1966 | + else |
1967 | + print_core[ii]=1; |
1968 | + }else{ |
1969 | + if ( !IS_THIS_BETWEEN_0_100(C0_time[i] * 100) || |
1970 | + !IS_THIS_BETWEEN_0_100(C1_time[i] * 100 - (C3_time[i] + C6_time[i]) * 100) || |
1971 | + !IS_THIS_BETWEEN_0_100(C3_time[i] * 100) || |
1972 | + !IS_THIS_BETWEEN_0_100(C6_time[i] * 100) || |
1973 | + isinf(_FREQ[i]) ) |
1974 | + print_core[ii]=0; |
1975 | + else |
1976 | + print_core[ii]=1; |
1977 | + } |
1978 | + } |
1979 | + |
1980 | + //Now print the information about the cores. Print garbage values message if there is garbage |
1981 | + for (ii = 0; ii < numCPUs; ii++) { |
1982 | + assert(ii < MAX_SK_PROCESSORS); |
1983 | + i = core_list[ii]; |
1984 | + |
1985 | + if(prog_options.i7_version.sandy_bridge){ |
1986 | + //there is a bit of leeway to be had as the total counts might deviate |
1987 | + //if this happens c1_time might be negative so just adjust so that it is thresholded to 0 |
1988 | + c1_time = C1_time[i] * 100 - (C3_time[i] + C6_time[i] + C7_time[i]) * 100; |
1989 | + if (!isnan(c1_time) && !isinf(c1_time)) { |
1990 | + if (c1_time <= 0) { |
1991 | + c1_time=0; |
1992 | + } |
1993 | + } |
1994 | + if (print_core[ii]) |
1995 | + mvprintw (12 + ii + printw_offset, 0, "\tCore %d [%d]:\t %0.2f (%.2fx)\t%4.3Lg\t%4.3Lg\t%4.3Lg\t%4.3Lg\t%4.3Lg\t%d\n", |
1996 | + ii + 1, core_list[ii], _FREQ[i], _MULT[i], THRESHOLD_BETWEEN_0_100(C0_time[i] * 100), |
1997 | + THRESHOLD_BETWEEN_0_100(c1_time), THRESHOLD_BETWEEN_0_100(C3_time[i] * 100), THRESHOLD_BETWEEN_0_100(C6_time[i] * 100),THRESHOLD_BETWEEN_0_100(C7_time[i] * 100), |
1998 | + Read_Thermal_Status_CPU(core_list[ii])); //C0_time[i]*100+C1_time[i]*100 around 100 |
1999 | + else |
2000 | + mvprintw (12 + ii + printw_offset, 0, "\tCore %d [%d]:\t Garbage Values\n", ii + 1, core_list[ii]); |
2001 | + }else{ |
2002 | + //there is a bit of leeway to be had as the total counts might deviate |
2003 | + //if this happens c1_time might be negative so just adjust so that it is thresholded to 0 |
2004 | + c1_time = C1_time[i] * 100 - (C3_time[i] + C6_time[i]) * 100; |
2005 | + if (!isnan(c1_time) && !isinf(c1_time)) { |
2006 | + if (c1_time <= 0) { |
2007 | + c1_time=0; |
2008 | + } |
2009 | + } |
2010 | + if (print_core[ii]) |
2011 | + mvprintw (12 + ii + printw_offset, 0, "\tCore %d [%d]:\t %0.2f (%.2fx)\t%4.3Lg\t%4.3Lg\t%4.3Lg\t%4.3Lg\t%d\n", |
2012 | + ii + 1, core_list[ii], _FREQ[i], _MULT[i], THRESHOLD_BETWEEN_0_100(C0_time[i] * 100), |
2013 | + THRESHOLD_BETWEEN_0_100(c1_time), THRESHOLD_BETWEEN_0_100(C3_time[i] * 100), THRESHOLD_BETWEEN_0_100(C6_time[i] * 100),Read_Thermal_Status_CPU(core_list[ii])); //C0_time[i]*100+C1_time[i]*100 around 100 |
2014 | + else |
2015 | + mvprintw (12 + ii + printw_offset, 0, "\tCore %d [%d]:\t Garbage Values\n", ii + 1, core_list[ii]); |
2016 | + } |
2017 | + } |
2018 | + |
2019 | + /*k=0; |
2020 | + for (ii = 00; ii < *max_observed_cpu; ii++) |
2021 | + { |
2022 | + if (in_core_list(ii,core_list)){ |
2023 | + continue; |
2024 | + }else{ |
2025 | + mvprintw (12 + k + numCPUs + printw_offset, 0, "\tProcessor %d [%d]: OFFLINE\n", k + numCPUs + 1, ii); |
2026 | + } |
2027 | + k++; |
2028 | + }*/ |
2029 | + |
2030 | + //FOR THE REST OF THE CORES (i.e. the offline cores+non-present cores=6 ) |
2031 | + //I have space allocated for 6 cores to be printed per socket so from all the present cores |
2032 | + //till 6 print a blank line |
2033 | + |
2034 | + //for(ii=*max_observed_cpu; ii<6; ii++) |
2035 | + for (ii = numCPUs; ii<6; ii++) |
2036 | + mvprintw (12 + ii + printw_offset, 0, "\n"); |
2037 | + |
2038 | + TRUE_CPU_FREQ = 0; |
2039 | + |
2040 | + logOpenFile_single(); |
2041 | + |
2042 | + //time_t time_to_save; |
2043 | + //logCpuFreq_single_d(time(&time_to_save)); |
2044 | + clock_gettime(CLOCK_REALTIME, &global_ts); |
2045 | + logCpuFreq_single_ts( &global_ts); |
2046 | + |
2047 | + logCpuCstates_single_ts( &global_ts); |
2048 | + |
2049 | + for (ii = 0; ii < numCPUs; ii++) { |
2050 | + assert(ii < MAX_SK_PROCESSORS); |
2051 | + i = core_list[ii]; |
2052 | + if ( (_FREQ[i] > TRUE_CPU_FREQ) && (print_core[ii]) && !isinf(_FREQ[i]) ) { |
2053 | + TRUE_CPU_FREQ = _FREQ[i]; |
2054 | + } |
2055 | + if ( (print_core[ii]) && !isinf(_FREQ[i]) ) { |
2056 | + logCpuFreq_single(_FREQ[i]); |
2057 | + } |
2058 | + logCpuCstates_single_c(" ["); |
2059 | + logCpuCstates_single((float)THRESHOLD_BETWEEN_0_100(C0_time[i] * 100)); logCpuCstates_single_c(","); |
2060 | + c1_time = C1_time[i] * 100 - (C3_time[i] + C6_time[i] + C7_time[i]) * 100; |
2061 | + logCpuCstates_single((float)THRESHOLD_BETWEEN_0_100(c1_time)); logCpuCstates_single_c(","); |
2062 | + logCpuCstates_single((float)THRESHOLD_BETWEEN_0_100(C3_time[i] * 100)); logCpuCstates_single_c(","); |
2063 | + logCpuCstates_single((float)THRESHOLD_BETWEEN_0_100(C6_time[i] * 100)); |
2064 | + if(prog_options.i7_version.sandy_bridge){ |
2065 | + logCpuCstates_single_c(","); |
2066 | + logCpuCstates_single((float)THRESHOLD_BETWEEN_0_100(C7_time[i] * 100)); |
2067 | + } |
2068 | + logCpuCstates_single_c("]\t"); |
2069 | + } |
2070 | + // logCpuCstates_single_c("\n"); |
2071 | + logCloseFile_single(); |
2072 | + |
2073 | + mvprintw (10 + printw_offset, 0, |
2074 | + " Real Current Frequency %0.2f MHz [%0.2f x %0.2f] (Max of below)\n", TRUE_CPU_FREQ, BLCK, TRUE_CPU_FREQ/BLCK); |
2075 | + |
2076 | + refresh (); |
2077 | + |
2078 | + //shift the new values to the old counter values |
2079 | + //so that the next time we use those to find the difference |
2080 | + memcpy (old_val_CORE, new_val_CORE, |
2081 | + sizeof (*old_val_CORE) * numCPUs); |
2082 | + memcpy (old_val_REF, new_val_REF, sizeof (*old_val_REF) * numCPUs); |
2083 | + memcpy (old_val_C3, new_val_C3, sizeof (*old_val_C3) * numCPUs); |
2084 | + memcpy (old_val_C6, new_val_C6, sizeof (*old_val_C6) * numCPUs); |
2085 | + |
2086 | + if(prog_options.i7_version.sandy_bridge){ |
2087 | + memcpy (old_val_C7, new_val_C7, sizeof (*old_val_C7) * numCPUs); |
2088 | + } |
2089 | + |
2090 | + memcpy (tvstart, tvstop, sizeof (*tvstart) * numCPUs); |
2091 | + memcpy (old_TSC, new_TSC, sizeof (*old_TSC) * numCPUs); |
2092 | + } else { |
2093 | + // If all the cores in the socket go offline, just erase the whole screen |
2094 | + //WELL for single socket machine this code will never be executed. lol |
2095 | + //atleast 1 core will be online so ... |
2096 | + //for (ii = 0 ; ii<14; ii++) |
2097 | + // mvprintw (3 + ii + printw_offset, 0, "Ending up here\n"); |
2098 | + //print_socket_information(&socket_0); |
2099 | + } |
2100 | + |
2101 | +} |
2102 | + |
2103 | +void print_i7z_single () |
2104 | +{ |
2105 | + struct cpu_heirarchy_info chi; |
2106 | + struct cpu_socket_info socket_0={.max_cpu=0, .socket_num=0, .processor_num={-1,-1,-1,-1,-1,-1,-1,-1}}; |
2107 | + struct cpu_socket_info socket_1={.max_cpu=0, .socket_num=1, .processor_num={-1,-1,-1,-1,-1,-1,-1,-1}}; |
2108 | + |
2109 | + construct_CPU_Heirarchy_info(&chi); |
2110 | + construct_sibling_list(&chi); |
2111 | +// print_CPU_Heirarchy(chi); |
2112 | + construct_socket_information(&chi, &socket_0, &socket_1, socket_0_num, socket_1_num); |
2113 | +// print_socket_information(&socket_0); |
2114 | +// print_socket_information(&socket_1); |
2115 | + |
2116 | + int printw_offset = (0) * 14; |
2117 | + |
2118 | + //Make an array size max 8 (to accomdate Nehalem-EXEX -lol) to store the core-num that are candidates for a given socket |
2119 | + //removing it from here as it is already allocated in the function |
2120 | + //int *core_list, core_list_size_phy, core_list_size_log; |
2121 | + |
2122 | + //iterator |
2123 | + int i; |
2124 | + |
2125 | + //turbo_mode enabled/disabled flag |
2126 | + char TURBO_MODE; |
2127 | + |
2128 | + double cpu_freq_cpuinfo; |
2129 | + |
2130 | + cpu_freq_cpuinfo = cpufreq_info (); |
2131 | + //estimate the freq using the estimate_MHz() code that is almost mhz accurate |
2132 | + cpu_freq_cpuinfo = estimate_MHz (); |
2133 | + |
2134 | + //Print a slew of information on the ncurses window |
2135 | + //I already print that in the loop so.. |
2136 | + mvprintw (0, 0, "WAIT .... "); |
2137 | + |
2138 | + |
2139 | + //estimate the freq using the estimate_MHz() code that is almost mhz accurate |
2140 | + cpu_freq_cpuinfo = estimate_MHz (); |
2141 | + mvprintw (3, 0, "True Frequency (without accounting Turbo) %0.0f MHz\n", |
2142 | + cpu_freq_cpuinfo); |
2143 | + |
2144 | + |
2145 | + //MSR number and hi:low bit of that MSR |
2146 | + //This msr contains a lot of stuff, per socket wise |
2147 | + //one can pass any core number and then get in multiplier etc |
2148 | + int PLATFORM_INFO_MSR = 206; //CE 15:8 |
2149 | + int PLATFORM_INFO_MSR_low = 8; |
2150 | + int PLATFORM_INFO_MSR_high = 15; |
2151 | + |
2152 | + unsigned long long int old_val_CORE[2][numCPUs_max], new_val_CORE[2][numCPUs_max]; |
2153 | + unsigned long long int old_val_REF[2][numCPUs_max], new_val_REF[2][numCPUs_max]; |
2154 | + unsigned long long int old_val_C3[2][numCPUs_max], new_val_C3[2][numCPUs_max]; |
2155 | + unsigned long long int old_val_C6[2][numCPUs_max], new_val_C6[2][numCPUs_max]; |
2156 | + unsigned long long int old_val_C7[2][numCPUs_max], new_val_C7[2][numCPUs_max]; |
2157 | + |
2158 | + unsigned long long int old_TSC[2][numCPUs_max], new_TSC[2][numCPUs_max]; |
2159 | + long double C0_time[2][numCPUs_max], C1_time[2][numCPUs_max], |
2160 | + C3_time[2][numCPUs_max], C6_time[2][numCPUs_max], C7_time[2][numCPUs_max]; |
2161 | + double _FREQ[2][numCPUs_max], _MULT[2][numCPUs_max]; |
2162 | + struct timeval tvstart[2][numCPUs_max], tvstop[2][numCPUs_max]; |
2163 | + |
2164 | + struct timespec one_second_sleep; |
2165 | + one_second_sleep.tv_sec = 0; |
2166 | + one_second_sleep.tv_nsec = 499999999; // 500msec |
2167 | + |
2168 | + |
2169 | + |
2170 | + //Get turbo mode status by reading msr within turbo_status |
2171 | + TURBO_MODE = turbo_status (); |
2172 | + |
2173 | + //Flags and other things about HT. |
2174 | + int HT_ON; |
2175 | + char HT_ON_str[30]; |
2176 | + |
2177 | + int kk_1 = 11; |
2178 | + |
2179 | + //below variables is used to monitor if any cores went offline etc. |
2180 | + int online_cpus[MAX_PROCESSORS]; //Max 2 x Nehalem-EX with total 32 threads |
2181 | + |
2182 | + double estimated_mhz=0; |
2183 | + int socket_num; |
2184 | + |
2185 | + //below variables stores how many cpus were observed till date for the socket |
2186 | + int max_cpus_observed=0; |
2187 | + |
2188 | + for (;;) { |
2189 | + construct_CPU_Heirarchy_info(&chi); |
2190 | + construct_sibling_list(&chi); |
2191 | + construct_socket_information(&chi, &socket_0, &socket_1, socket_0_num, socket_1_num); |
2192 | + |
2193 | + |
2194 | + //HT enabled if num logical > num physical cores |
2195 | + if (chi.HT==1) { |
2196 | + strncpy (HT_ON_str, "Hyper Threading ON\0", 30); |
2197 | + HT_ON = 1; |
2198 | + } else { |
2199 | + strncpy (HT_ON_str, "Hyper Threading OFF\0", 30); |
2200 | + HT_ON = 0; |
2201 | + } |
2202 | + |
2203 | + refresh (); |
2204 | + |
2205 | + SET_ONLINE_ARRAY_PLUS1(online_cpus) |
2206 | + |
2207 | + //In the function calls below socket_num is set to the socket to print for |
2208 | + //printw_offset is the offset gap between the printing of the two sockets |
2209 | + //kk_1 and kk_2 are the variables that have to be set, i have to use them internally |
2210 | + //so in future if there are more sockets to be printed, add more kk_* |
2211 | + socket_num=0; |
2212 | + printw_offset=0; |
2213 | + |
2214 | + //printf("socket0 max cpu %d\n",socket_0.max_cpu); |
2215 | + //printf("socket1 max cpu %d\n",socket_0.max_cpu); |
2216 | + |
2217 | + |
2218 | + //below code in (else case) is to handle when for 2 sockets system, cpu1 is populated and cpu0 is empty. |
2219 | + //single socket code but in an intelligent manner and not assuming that cpu0 is always populated before cpu1 |
2220 | + if(socket_0.max_cpu>1){ |
2221 | + socket_num=0; |
2222 | + print_i7z_socket_single(socket_0, printw_offset, PLATFORM_INFO_MSR, PLATFORM_INFO_MSR_high, PLATFORM_INFO_MSR_low, |
2223 | + online_cpus, cpu_freq_cpuinfo, one_second_sleep, TURBO_MODE, HT_ON_str, &kk_1, old_val_CORE[socket_num], |
2224 | + old_val_REF[socket_num], old_val_C3[socket_num], old_val_C6[socket_num],old_val_C7[socket_num], |
2225 | + old_TSC[socket_num], estimated_mhz, new_val_CORE[socket_num], new_val_REF[socket_num], new_val_C3[socket_num], |
2226 | + new_val_C6[socket_num],new_val_C7[socket_num], new_TSC[socket_num], _FREQ[socket_num], _MULT[socket_num], C0_time[socket_num], C1_time[socket_num], |
2227 | + C3_time[socket_num], C6_time[socket_num],C7_time[socket_num], tvstart[socket_num], tvstop[socket_num], &max_cpus_observed); |
2228 | + }else{ |
2229 | + socket_num=1; |
2230 | + print_i7z_socket_single(socket_1, printw_offset, PLATFORM_INFO_MSR, PLATFORM_INFO_MSR_high, PLATFORM_INFO_MSR_low, |
2231 | + online_cpus, cpu_freq_cpuinfo, one_second_sleep, TURBO_MODE, HT_ON_str, &kk_1, old_val_CORE[socket_num], |
2232 | + old_val_REF[socket_num], old_val_C3[socket_num], old_val_C6[socket_num],old_val_C7[socket_num], |
2233 | + old_TSC[socket_num], estimated_mhz, new_val_CORE[socket_num], new_val_REF[socket_num], new_val_C3[socket_num], |
2234 | + new_val_C6[socket_num],new_val_C7[socket_num], new_TSC[socket_num], _FREQ[socket_num], _MULT[socket_num], C0_time[socket_num], C1_time[socket_num], |
2235 | + C3_time[socket_num], C6_time[socket_num],C7_time[socket_num], tvstart[socket_num], tvstop[socket_num], &max_cpus_observed); |
2236 | + } |
2237 | + } |
2238 | + |
2239 | +} |
2240 | + |
2241 | + |
2242 | +/*int Single_Socket(){ |
2243 | + int row, col; // to store the number of rows and // |
2244 | + // the number of colums of the screen // |
2245 | + // for NCURSES // |
2246 | + |
2247 | + printf ("i7z DEBUG: In i7z Single_Socket()\n"); |
2248 | + |
2249 | + sleep (3); |
2250 | + |
2251 | + //iterator |
2252 | + int i; |
2253 | + |
2254 | + int error_indx; |
2255 | + //cpu multiplier |
2256 | + int CPU_Multiplier; |
2257 | + //current blck value |
2258 | + float BLCK; |
2259 | + //turbo_mode enabled/disabled flag |
2260 | + char TURBO_MODE; |
2261 | + |
2262 | + int online_cpus[8]; |
2263 | + SET_ONLINE_ARRAY_PLUS1(online_cpus) |
2264 | + |
2265 | + //Use Core-1 as the one to check for the turbo limit |
2266 | + //Core number shouldnt matter |
2267 | + int CPU_NUM = 0; |
2268 | + //bits from 0-63 in this store the various maximum turbo limits |
2269 | + int MSR_TURBO_RATIO_LIMIT = 429; |
2270 | + // 3B defines till Max 4 Core and the rest bit values from 32:63 were reserved. |
2271 | + //Bits:0-7 - core1 |
2272 | + int MAX_TURBO_1C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 7, 0, &error_indx); |
2273 | + //Bits:15-8 - core2 |
2274 | + int MAX_TURBO_2C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 15, 8, &error_indx); |
2275 | + //Bits:23-16 - core3 |
2276 | + int MAX_TURBO_3C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 23, 16, &error_indx); |
2277 | + //Bits:31-24 - core4 |
2278 | + int MAX_TURBO_4C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 31, 24, &error_indx); |
2279 | + |
2280 | + //gulftown/Hexacore support |
2281 | + //technically these should be the bits to get for core 5,6 |
2282 | + //Bits:39-32 - core4 |
2283 | + int MAX_TURBO_5C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 39, 32, &error_indx); |
2284 | + //Bits:47-40 - core4 |
2285 | + int MAX_TURBO_6C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 47, 40, &error_indx); |
2286 | + |
2287 | + |
2288 | + |
2289 | + //CPUINFO is wrong for i7 but correct for the number of physical and logical cores present |
2290 | + //If Hyperthreading is enabled then, multiple logical processors will share a common CORE ID |
2291 | + //http://www.redhat.com/magazine/022aug06/departments/tips_tricks/ |
2292 | + system |
2293 | + ("cat /proc/cpuinfo |grep MHz|sed 's/cpu\\sMHz\\s*:\\s//'|tail -n 1 > /tmp/cpufreq.txt"); |
2294 | + system |
2295 | + ("grep \"core id\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numPhysical.txt"); |
2296 | + system |
2297 | + ("grep \"processor\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numLogical.txt"); |
2298 | + //At this step, /tmp/numPhysical contains number of physical cores in machine and |
2299 | + // /tmp/numPhysical contains number of logical cores in machine |
2300 | + |
2301 | + |
2302 | + //Open the parsed cpufreq file and obtain the cpufreq from /proc/cpuinfo |
2303 | + FILE *tmp_file; |
2304 | + tmp_file = fopen ("/tmp/cpufreq.txt", "r"); |
2305 | + char tmp_str[30]; |
2306 | + fgets (tmp_str, 30, tmp_file); |
2307 | + double cpu_freq_cpuinfo = atof (tmp_str); |
2308 | + fclose (tmp_file); |
2309 | + |
2310 | + //Parse the numPhysical and numLogical file to obtain the number of physical and logical core |
2311 | + tmp_file = fopen ("/tmp/numPhysical.txt", "r"); |
2312 | + fgets (tmp_str, 30, tmp_file); |
2313 | + numPhysicalCores = atoi (tmp_str); |
2314 | + fclose (tmp_file); |
2315 | + |
2316 | + tmp_file = fopen ("/tmp/numLogical.txt", "r"); |
2317 | + fgets (tmp_str, 30, tmp_file); |
2318 | + numLogicalCores = atoi (tmp_str); |
2319 | + fclose (tmp_file); |
2320 | + //reading of the number of cores is done |
2321 | + |
2322 | + fflush (stdout); |
2323 | + sleep (1); |
2324 | + |
2325 | + //Setup stuff for ncurses |
2326 | + initscr (); // start the curses mode |
2327 | + start_color (); |
2328 | + getmaxyx (stdscr, row, col); // get the number of rows and columns |
2329 | + refresh (); |
2330 | + //Setup for ncurses completed |
2331 | + |
2332 | + //Print a slew of information on the ncurses window |
2333 | + mvprintw (0, 0, "Cpu speed from cpuinfo %0.2fMhz\n", cpu_freq_cpuinfo); |
2334 | + mvprintw (1, 0, |
2335 | + "cpuinfo might be wrong if cpufreq is enabled. To guess correctly try estimating via tsc\n"); |
2336 | + mvprintw (2, 0, "Linux's inbuilt cpu_khz code emulated now\n\n"); |
2337 | + |
2338 | + |
2339 | + //estimate the freq using the estimate_MHz() code that is almost mhz accurate |
2340 | + cpu_freq_cpuinfo = estimate_MHz (); |
2341 | + mvprintw (3, 0, "True Frequency (without accounting Turbo) %0.0f MHz\n", |
2342 | + cpu_freq_cpuinfo); |
2343 | + |
2344 | + |
2345 | + //MSR number and hi:low bit of that MSR |
2346 | + //This msr contains a lot of stuff, per socket wise |
2347 | + //one can pass any core number and then get in multiplier etc |
2348 | + int PLATFORM_INFO_MSR = 206; //CE 15:8 |
2349 | + int PLATFORM_INFO_MSR_low = 8; |
2350 | + int PLATFORM_INFO_MSR_high = 15; |
2351 | + |
2352 | + //We just need one CPU (we use Core-1) to figure out the multiplier and the bus clock freq. |
2353 | + //multiplier doesnt automatically include turbo |
2354 | + //note turbo is not guaranteed, only promised |
2355 | + //So this msr will only reflect the actual multiplier, rest has to be figured out |
2356 | + CPU_NUM = 0; |
2357 | + CPU_Multiplier = get_msr_value (CPU_NUM, PLATFORM_INFO_MSR, PLATFORM_INFO_MSR_high, PLATFORM_INFO_MSR_low, &error_indx); |
2358 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
2359 | + |
2360 | + //Blck is basically the true speed divided by the multiplier |
2361 | + BLCK = cpu_freq_cpuinfo / CPU_Multiplier; |
2362 | + mvprintw (4, 0, |
2363 | + "CPU Multiplier %dx || Bus clock frequency (BCLK) %0.2f MHz \n", |
2364 | + CPU_Multiplier, BLCK); |
2365 | + |
2366 | + //Get turbo mode status by reading msr within turbo_status |
2367 | + TURBO_MODE = turbo_status (); //get_msr_value(CPU_NUM,IA32_MISC_ENABLE, TURBO_FLAG_high,TURBO_FLAG_low); |
2368 | + |
2369 | + //to find how many cpus are enabled, we could have used sysconf but that will just give the logical numbers |
2370 | + //if HT is enabled then the threads of the same core have the same C-state residency number so... |
2371 | + //Its imperative to figure out the number of physical and number of logical cores. |
2372 | + //sysconf(_SC_NPROCESSORS_ONLN); |
2373 | + |
2374 | + //number of CPUs is as told via cpuinfo |
2375 | + int numCPUs = numPhysicalCores; |
2376 | + |
2377 | + //Flags and other things about HT. |
2378 | + int HT_ON; |
2379 | + char HT_ON_str[30]; |
2380 | + |
2381 | + //HT enabled if num logical > num physical cores |
2382 | + if (numLogicalCores > numPhysicalCores) |
2383 | + { |
2384 | + //printf("Multiplier %d \n", CPU_Multiplier); |
2385 | + strncpy (HT_ON_str, "Hyper Threading ON\0", 30); |
2386 | + HT_ON = 1; |
2387 | + //printf("Multiplier %d \n", CPU_Multiplier); |
2388 | + } |
2389 | + else |
2390 | + { |
2391 | + //printf("Multiplier %d \n", CPU_Multiplier); |
2392 | + strncpy (HT_ON_str, "Hyper Threading OFF\0", 30); |
2393 | + HT_ON = 0; |
2394 | + //printf("Multiplier %d \n", CPU_Multiplier); |
2395 | + } |
2396 | + |
2397 | + //printf("Multiplier %d \n", CPU_Multiplier); |
2398 | + |
2399 | + if (TURBO_MODE == 1) |
2400 | + { // && (CPU_Multiplier+1)==MAX_TURBO_2C){ |
2401 | + mvprintw (5, 0, "TURBO ENABLED on %d Cores, %s\n", numPhysicalCores, |
2402 | + HT_ON_str); |
2403 | + TRUE_CPU_FREQ = BLCK * ((double) CPU_Multiplier + 1); |
2404 | + mvprintw (6, 0, "True Frequency %0.2f MHz (%0.2f x [%d]) \n", |
2405 | + TRUE_CPU_FREQ, BLCK, CPU_Multiplier + 1); |
2406 | + } |
2407 | + else |
2408 | + { |
2409 | + mvprintw (5, 0, "TURBO DISABLED on %d Cores, %s\n", |
2410 | + numPhysicalCores, HT_ON_str); |
2411 | + TRUE_CPU_FREQ = BLCK * ((double) CPU_Multiplier); |
2412 | + mvprintw (6, 0, "True Frequency %0.2f MHz (%0.2f x [%d]) \n", |
2413 | + TRUE_CPU_FREQ, BLCK, CPU_Multiplier); |
2414 | + } |
2415 | + |
2416 | + |
2417 | + if (numCPUs >= 2) |
2418 | + {mvprintw (7, 0," Max TURBO (if Enabled) with 1/2 Core active %dx / %dx\n", MAX_TURBO_1C, MAX_TURBO_2C);} |
2419 | + if (numCPUs >= 4) |
2420 | + {mvprintw (8, 0," Max TURBO (if Enabled) with 3/4 Cores active %dx / %dx\n", MAX_TURBO_3C, MAX_TURBO_4C);} |
2421 | + if (numCPUs >= 6) |
2422 | + {mvprintw (9, 0," Max TURBO (if Enabled) with 5/6 Cores active %dx / %dx\n", MAX_TURBO_5C, MAX_TURBO_6C);} |
2423 | + |
2424 | + mvprintw (22, 0, "C0 = Processor running without halting"); |
2425 | + mvprintw (23, 0, |
2426 | + "C1 = Processor running with halts (States >C0 are power saver)"); |
2427 | + mvprintw (24, 0, |
2428 | + "C3 = Cores running with PLL turned off and core cache turned off"); |
2429 | + mvprintw (25, 0, |
2430 | + "C6 = Everything in C3 + core state saved to last level cache"); |
2431 | + mvprintw (26, 0, |
2432 | + " Above values in table are in percentage over the last 1 sec"); |
2433 | + mvprintw (27, 0, |
2434 | + " Total Logical Cores: [%d], Total Physical Cores: [%d] \n", |
2435 | + numLogicalCores, numPhysicalCores); |
2436 | + |
2437 | + mvprintw (29, 0, " Ctrl+C to exit"); |
2438 | + |
2439 | + |
2440 | + int IA32_PERF_GLOBAL_CTRL = 911; //38F |
2441 | + int IA32_PERF_GLOBAL_CTRL_Value = get_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 63, 0, &error_indx); |
2442 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
2443 | + int IA32_FIXED_CTR_CTL = 909; //38D |
2444 | + int IA32_FIXED_CTR_CTL_Value = get_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 63, 0, &error_indx); |
2445 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
2446 | + |
2447 | + //printf("IA32_PERF_GLOBAL_CTRL %d\n",IA32_PERF_GLOBAL_CTRL_Value); |
2448 | + //printf("IA32_FIXED_CTR_CTL %d\n",IA32_FIXED_CTR_CTL_Value); |
2449 | + |
2450 | + unsigned long long int CPU_CLK_UNHALTED_CORE, CPU_CLK_UNHALTED_REF, |
2451 | + CPU_CLK_C3, CPU_CLK_C6, CPU_CLK_C1; |
2452 | + |
2453 | + CPU_CLK_UNHALTED_CORE = get_msr_value (CPU_NUM, 778, 63, 0, &error_indx); |
2454 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
2455 | + CPU_CLK_UNHALTED_REF = get_msr_value (CPU_NUM, 779, 63, 0, &error_indx); |
2456 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
2457 | + |
2458 | + unsigned long long int old_val_CORE[numCPUs], new_val_CORE[numCPUs]; |
2459 | + unsigned long long int old_val_REF[numCPUs], new_val_REF[numCPUs]; |
2460 | + unsigned long long int old_val_C3[numCPUs], new_val_C3[numCPUs]; |
2461 | + unsigned long long int old_val_C6[numCPUs], new_val_C6[numCPUs]; |
2462 | + // unsigned long int old_val_C1[numCPUs], new_val_C1[numCPUs]; |
2463 | + |
2464 | + unsigned long long int old_TSC[numCPUs], new_TSC[numCPUs]; |
2465 | + |
2466 | + struct timeval tvstart[numCPUs], tvstop[numCPUs]; |
2467 | + |
2468 | + struct timespec one_second_sleep; |
2469 | + one_second_sleep.tv_sec = 0; |
2470 | + one_second_sleep.tv_nsec = 999999999; // 1000msec |
2471 | + |
2472 | + |
2473 | + unsigned long int IA32_MPERF = get_msr_value (CPU_NUM, 231, 7, 0, &error_indx); |
2474 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
2475 | + unsigned long int IA32_APERF = get_msr_value (CPU_NUM, 232, 7, 0, &error_indx); |
2476 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
2477 | + mvprintw (11, 0, "Wait...\n"); |
2478 | + refresh (); |
2479 | + nanosleep (&one_second_sleep, NULL); |
2480 | + IA32_MPERF = get_msr_value (CPU_NUM, 231, 7, 0, &error_indx) - IA32_MPERF; |
2481 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
2482 | + IA32_APERF = get_msr_value (CPU_NUM, 232, 7, 0, &error_indx) - IA32_APERF; |
2483 | + SET_IF_TRUE(error_indx,online_cpus[0],-1); |
2484 | + |
2485 | + //printf("Diff. i n APERF = %u, MPERF = %d\n", IA32_MPERF, IA32_APERF); |
2486 | + |
2487 | + long double C0_time[numCPUs], C1_time[numCPUs], C3_time[numCPUs], |
2488 | + C6_time[numCPUs]; |
2489 | + double _FREQ[numCPUs], _MULT[numCPUs]; |
2490 | + refresh (); |
2491 | + |
2492 | + mvprintw (11, 0, "Current Freqs\n"); |
2493 | + |
2494 | + int kk=11, ii; |
2495 | + |
2496 | + double estimated_mhz; |
2497 | + for (;;) |
2498 | + { |
2499 | + SET_ONLINE_ARRAY_PLUS1(online_cpus) |
2500 | + if (kk > 10){ |
2501 | + kk=0; |
2502 | + for (ii = 0; ii < numCPUs; ii++) |
2503 | + { |
2504 | + //Set up the performance counters and then start reading from them |
2505 | + CPU_NUM = ii; |
2506 | + IA32_PERF_GLOBAL_CTRL_Value = get_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 63, 0, &error_indx); |
2507 | + SET_IF_TRUE(error_indx,online_cpus[ii],-1); |
2508 | + CONTINUE_IF_TRUE(online_cpus[ii]==-1); |
2509 | + |
2510 | + set_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 0x700000003LLU); |
2511 | + |
2512 | + IA32_FIXED_CTR_CTL_Value = get_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 63, 0, &error_indx); |
2513 | + SET_IF_TRUE(error_indx,online_cpus[ii],-1); |
2514 | + CONTINUE_IF_TRUE(online_cpus[ii]==-1); |
2515 | + |
2516 | + set_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 819); |
2517 | + |
2518 | + IA32_PERF_GLOBAL_CTRL_Value = get_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 63, 0, &error_indx); |
2519 | + SET_IF_TRUE(error_indx,online_cpus[ii],-1); |
2520 | + CONTINUE_IF_TRUE(online_cpus[ii]==-1); |
2521 | + |
2522 | + IA32_FIXED_CTR_CTL_Value = get_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 63, 0, &error_indx); |
2523 | + SET_IF_TRUE(error_indx,online_cpus[ii],-1); |
2524 | + CONTINUE_IF_TRUE(online_cpus[ii]==-1); |
2525 | + |
2526 | + old_val_CORE[ii] = get_msr_value (CPU_NUM, 778, 63, 0, &error_indx); |
2527 | + SET_IF_TRUE(error_indx,online_cpus[ii],-1); |
2528 | + CONTINUE_IF_TRUE(online_cpus[ii]==-1); |
2529 | + |
2530 | + old_val_REF[ii] = get_msr_value (CPU_NUM, 779, 63, 0, &error_indx); |
2531 | + SET_IF_TRUE(error_indx,online_cpus[ii],-1); |
2532 | + CONTINUE_IF_TRUE(online_cpus[ii]==-1); |
2533 | + |
2534 | + old_val_C3[ii] = get_msr_value (CPU_NUM, 1020, 63, 0, &error_indx); |
2535 | + SET_IF_TRUE(error_indx,online_cpus[ii],-1); |
2536 | + CONTINUE_IF_TRUE(online_cpus[ii]==-1); |
2537 | + |
2538 | + old_val_C6[ii] = get_msr_value (CPU_NUM, 1021, 63, 0, &error_indx); |
2539 | + SET_IF_TRUE(error_indx,online_cpus[ii],-1); |
2540 | + CONTINUE_IF_TRUE(online_cpus[ii]==-1); |
2541 | + |
2542 | + old_TSC[ii] = rdtsc (); |
2543 | + } |
2544 | + } |
2545 | + kk++; |
2546 | + nanosleep (&one_second_sleep, NULL); |
2547 | + mvprintw (13, 0, |
2548 | + "\tProcessor :Actual Freq (Mult.) C0%% Halt(C1)%% C3 %% C6 %%\n"); |
2549 | + |
2550 | + estimated_mhz = estimate_MHz (); |
2551 | + for (i = 0; i < numCPUs; i++) |
2552 | + { |
2553 | + //read from the performance counters |
2554 | + //things like halted unhalted core cycles |
2555 | + |
2556 | + CPU_NUM = i; |
2557 | + new_val_CORE[i] = get_msr_value (CPU_NUM, 778, 63, 0, &error_indx); |
2558 | + SET_IF_TRUE(error_indx,online_cpus[i],-1); |
2559 | + CONTINUE_IF_TRUE(online_cpus[i]==-1); |
2560 | + |
2561 | + new_val_REF[i] = get_msr_value (CPU_NUM, 779, 63, 0, &error_indx); |
2562 | + SET_IF_TRUE(error_indx,online_cpus[i],-1); |
2563 | + CONTINUE_IF_TRUE(online_cpus[i]==-1); |
2564 | + |
2565 | + new_val_C3[i] = get_msr_value (CPU_NUM, 1020, 63, 0, &error_indx); |
2566 | + SET_IF_TRUE(error_indx,online_cpus[i],-1); |
2567 | + CONTINUE_IF_TRUE(online_cpus[i]==-1); |
2568 | + |
2569 | + new_val_C6[i] = get_msr_value (CPU_NUM, 1021, 63, 0, &error_indx); |
2570 | + SET_IF_TRUE(error_indx,online_cpus[i],-1); |
2571 | + CONTINUE_IF_TRUE(online_cpus[i]==-1); |
2572 | + |
2573 | + new_TSC[i] = rdtsc (); |
2574 | + |
2575 | + if (old_val_CORE[i] > new_val_CORE[i]) |
2576 | + { //handle overflow |
2577 | + CPU_CLK_UNHALTED_CORE = (UINT64_MAX - old_val_CORE[i]) + new_val_CORE[i]; |
2578 | + }else{ |
2579 | + CPU_CLK_UNHALTED_CORE = new_val_CORE[i] - old_val_CORE[i]; |
2580 | + } |
2581 | + |
2582 | + //number of TSC cycles while its in halted state |
2583 | + if ((new_TSC[i] - old_TSC[i]) < CPU_CLK_UNHALTED_CORE) |
2584 | + {CPU_CLK_C1 = 0;} |
2585 | + else |
2586 | + {CPU_CLK_C1 = ((new_TSC[i] - old_TSC[i]) - CPU_CLK_UNHALTED_CORE);} |
2587 | + |
2588 | + if (old_val_REF[i] > new_val_REF[i]) |
2589 | + { //handle overflow |
2590 | + CPU_CLK_UNHALTED_REF = (UINT64_MAX - old_val_REF[i]) + new_val_REF[i]; //3.40282366921e38 |
2591 | + }else{ |
2592 | + CPU_CLK_UNHALTED_REF = new_val_REF[i] - old_val_REF[i]; |
2593 | + } |
2594 | + |
2595 | + if (old_val_C3[i] > new_val_C3[i]) |
2596 | + { //handle overflow |
2597 | + CPU_CLK_C3 = (UINT64_MAX - old_val_C3[i]) + new_val_C3[i]; |
2598 | + }else{ |
2599 | + CPU_CLK_C3 = new_val_C3[i] - old_val_C3[i]; |
2600 | + } |
2601 | + |
2602 | + if (old_val_C6[i] > new_val_C6[i]) |
2603 | + { //handle overflow |
2604 | + CPU_CLK_C6 = (UINT64_MAX - old_val_C6[i]) + new_val_C6[i]; |
2605 | + }else{ |
2606 | + CPU_CLK_C6 = new_val_C6[i] - old_val_C6[i]; |
2607 | + } |
2608 | + |
2609 | + _FREQ[i] = |
2610 | + estimated_mhz * ((long double) CPU_CLK_UNHALTED_CORE / |
2611 | + (long double) CPU_CLK_UNHALTED_REF); |
2612 | + _MULT[i] = _FREQ[i] / BLCK; |
2613 | + |
2614 | + C0_time[i] = ((long double) CPU_CLK_UNHALTED_REF / |
2615 | + (long double) (new_TSC[i] - old_TSC[i])); |
2616 | + C1_time[i] = ((long double) CPU_CLK_C1 / |
2617 | + (long double) (new_TSC[i] - old_TSC[i])); |
2618 | + C3_time[i] = ((long double) CPU_CLK_C3 / |
2619 | + (long double) (new_TSC[i] - old_TSC[i])); |
2620 | + C6_time[i] = ((long double) CPU_CLK_C6 / |
2621 | + (long double) (new_TSC[i] - old_TSC[i])); |
2622 | + |
2623 | + if (C0_time[i] < 1e-2) |
2624 | + { |
2625 | + if (C0_time[i] > 1e-4) {C0_time[i] = 0.01;} |
2626 | + else {C0_time[i] = 0;} |
2627 | + } |
2628 | + if (C1_time[i] < 1e-2) |
2629 | + { |
2630 | + if (C1_time[i] > 1e-4) {C1_time[i] = 0.01;} |
2631 | + else {C1_time[i] = 0;} |
2632 | + } |
2633 | + if (C3_time[i] < 1e-2) |
2634 | + { |
2635 | + if (C3_time[i] > 1e-4) {C3_time[i] = 0.01;} |
2636 | + else {C3_time[i] = 0;} |
2637 | + } |
2638 | + if (C6_time[i] < 1e-2) |
2639 | + { |
2640 | + if (C6_time[i] > 1e-4) {C6_time[i] = 0.01;} |
2641 | + else {C6_time[i] = 0;} |
2642 | + } |
2643 | + //printf("%lld - %lld", CPU_CLK_C6, (new_TSC[i] - old_TSC[i])); |
2644 | + } |
2645 | + |
2646 | + for (i = 0; i < numCPUs; i++){ |
2647 | + if(online_cpus[i]==-1){ |
2648 | + mvprintw (14 + i, 0, "\tProcessor %d: OFFLINE\n",i + 1); |
2649 | + }else{ |
2650 | + mvprintw (14 + i, 0, "\tProcessor %d: %0.2f (%.2fx)\t%4.3Lg\t%4.3Lg\t%4.3Lg\t%4.3Lg\n", i + 1, _FREQ[i], _MULT[i], |
2651 | + C0_time[i] * 100 , C1_time[i]* 100 - (C3_time[i] + C6_time[i] )* 100, C3_time[i]* 100 , C6_time[i]* 100); //C0_time[i]*100+C1_time[i]*100 around 100 |
2652 | + } |
2653 | + } |
2654 | + |
2655 | + |
2656 | + TRUE_CPU_FREQ = 0; |
2657 | + for (i = 0; i < numCPUs; i++) |
2658 | + { |
2659 | + if (_FREQ[i] > TRUE_CPU_FREQ) |
2660 | + { |
2661 | + TRUE_CPU_FREQ = _FREQ[i]; |
2662 | + mvprintw (12, 0, |
2663 | + "True Frequency %0.2f MHz (Intel specifies largest of below to be running Freq)\n", |
2664 | + TRUE_CPU_FREQ); |
2665 | + } |
2666 | + } |
2667 | + |
2668 | + refresh (); |
2669 | + |
2670 | + //shift the new values to the old counter values |
2671 | + //so that the next time we use those to find the difference |
2672 | + memcpy (old_val_CORE, new_val_CORE, |
2673 | + sizeof (unsigned long int) * numCPUs); |
2674 | + memcpy (old_val_REF, new_val_REF, sizeof (unsigned long int) * numCPUs); |
2675 | + memcpy (old_val_C3, new_val_C3, sizeof (unsigned long int) * numCPUs); |
2676 | + memcpy (old_val_C6, new_val_C6, sizeof (unsigned long int) * numCPUs); |
2677 | + memcpy (tvstart, tvstop, sizeof (struct timeval) * numCPUs); |
2678 | + memcpy (old_TSC, new_TSC, sizeof (unsigned long long int) * numCPUs); |
2679 | + } //ENDOF INFINITE FOR LOOP |
2680 | + exit (0); |
2681 | + return (1); |
2682 | +}*/ |
2683 | |
2684 | === added directory '.pc/hyphen-used-as-minus-sign.patch' |
2685 | === added file '.pc/hyphen-used-as-minus-sign.patch/.timestamp' |
2686 | === added directory '.pc/hyphen-used-as-minus-sign.patch/doc' |
2687 | === added file '.pc/hyphen-used-as-minus-sign.patch/doc/i7z.man' |
2688 | --- .pc/hyphen-used-as-minus-sign.patch/doc/i7z.man 1970-01-01 00:00:00 +0000 |
2689 | +++ .pc/hyphen-used-as-minus-sign.patch/doc/i7z.man 2013-08-15 05:58:18 +0000 |
2690 | @@ -0,0 +1,28 @@ |
2691 | +.TH i7z 1 "20 July 2012" |
2692 | +.SH NAME |
2693 | +i7z \- A better i7 (and now i3, i5) reporting tool for Linux. |
2694 | +.SH SYNOPSIS |
2695 | +\fBi7z [OPTION]\fP, [OPTION] is optional. i7z needs to be run in super user (root) mode. |
2696 | +.SH DESCRIPTION |
2697 | +i7z runs the i7z, ncurses based, program without any options. i7z will print out the C-states and temperature for i3, i5 and i7 based Core processors from Intel (including Nehalems, Sandy Bridge and Ivy Bridge). |
2698 | +.SH OPTIONS |
2699 | +.TP |
2700 | +\fB-h, --help \fPshow the list of options available with the i7z tool. |
2701 | +.TP |
2702 | +\fB-w [a|l], --write [a,l] \fPLogging of the frequencies can be turned on with this options. Option "-w a" or "--write a" will append to the log file. Option "-w l" or "--write l" will replace the log file. |
2703 | +.TP |
2704 | +\fB-l, --logfile [FILENAME] \fPChange the log file name to the specified FILENAME. Default logging file is cpu_freq_log.txt (single socket) or cpu_freq_log_dual%d.txt (dual socket, %d is either 0, 1). |
2705 | +.TP |
2706 | +\fB--socket0 [SOCKETNUM], --socket1 [SOCKETNUM] \fPThe tool can print information for about 2 sockets at once at the most. The top view will be, by default, of the first socket (controlled by --socket0) and the bottom view will be of the second socket (controlled by --socket1). Supply the appropriate value of 0 or 1 or more for SOCKETNUM (if there are more sockets on the machine) to show in the top and bottom view. |
2707 | +.TP |
2708 | +\fB--nogui \fPDisable the GUI. Useful when the only need is logging. |
2709 | +.SH Example |
2710 | +To print for two sockets and also change the log file (log to /tmp/logfilei7z) |
2711 | + |
2712 | +i7z \-\-socket0 0 \-\-socket1 1 \-logfile /tmp/logfilei7z \-w l |
2713 | + |
2714 | +.SH BUGS |
2715 | +Do report bugs or feature enhancement as an issue at http://code.google.com/p/i7z. |
2716 | + |
2717 | +.SH AUTHORS |
2718 | +Written in 2010, by Abhishek Jaiantilal (abhirana @ gmail.com). i7z is licensed under the terms of the GNU General Public License (GPL) version 2. |
2719 | |
2720 | === removed directory '.pc/install-i7z_rw_registers' |
2721 | === added directory '.pc/install-i7z_rw_registers.patch' |
2722 | === added file '.pc/install-i7z_rw_registers.patch/.timestamp' |
2723 | === added file '.pc/install-i7z_rw_registers.patch/Makefile' |
2724 | --- .pc/install-i7z_rw_registers.patch/Makefile 1970-01-01 00:00:00 +0000 |
2725 | +++ .pc/install-i7z_rw_registers.patch/Makefile 2013-08-15 05:58:18 +0000 |
2726 | @@ -0,0 +1,63 @@ |
2727 | +# |
2728 | +# Makefile for i7z, GPL v2, License in COPYING |
2729 | +# |
2730 | + |
2731 | +#makefile updated from patch by anestling |
2732 | + |
2733 | +#explicitly disable two scheduling flags as they cause segfaults, two more seem to crash the GUI version so putting them |
2734 | +#here |
2735 | +CFLAGS_FOR_AVOIDING_SEG_FAULT = -fno-schedule-insns2 -fno-schedule-insns -fno-inline-small-functions -fno-caller-saves |
2736 | +CFLAGS ?= -O3 |
2737 | +CFLAGS += $(CFLAGS_FOR_AVOIDING_SEG_FAULT) -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DBUILD_MAIN -Wimplicit-function-declaration |
2738 | + |
2739 | +LBITS := $(shell getconf LONG_BIT) |
2740 | +ifeq ($(LBITS),64) |
2741 | + CFLAGS += -Dx64_BIT |
2742 | +else |
2743 | + CFLAGS += -Dx86 |
2744 | +endif |
2745 | + |
2746 | +CC ?= gcc |
2747 | + |
2748 | +LIBS += -lncurses -lpthread -lrt -lm |
2749 | +INCLUDEFLAGS = |
2750 | + |
2751 | +BIN = i7z |
2752 | +# PERFMON-BIN = perfmon-i7z #future version to include performance monitor, either standalone or integrated |
2753 | +SRC = i7z.c helper_functions.c i7z_Single_Socket.c i7z_Dual_Socket.c |
2754 | +OBJ = $(SRC:.c=.o) |
2755 | + |
2756 | +prefix ?= /usr |
2757 | +sbindir = $(prefix)/sbin/ |
2758 | +docdir = $(prefix)/share/doc/$(BIN)/ |
2759 | +mandir ?= $(prefix)/share/man/ |
2760 | + |
2761 | +all: clean test_exist |
2762 | + |
2763 | +message: |
2764 | + @echo "If the compilation complains about not finding ncurses.h, install ncurses (libncurses5-dev on ubuntu/debian)" |
2765 | + |
2766 | +bin: message $(OBJ) |
2767 | + $(CC) $(CFLAGS) $(LDFLAGS) -o $(BIN) $(OBJ) $(LIBS) |
2768 | + |
2769 | +#http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=644728 for -ltinfo on debian |
2770 | +static-bin: message $(OBJ) |
2771 | + $(CC) $(CFLAGS) $(LDFLAGS) -o $(BIN) $(OBJ) -static-libgcc -DNCURSES_STATIC -static -lpthread -lncurses -lrt -lm -ltinfo |
2772 | + |
2773 | +# perfmon-bin: message $(OBJ) |
2774 | +# $(CC) $(CFLAGS) $(LDFLAGS) -o $(PERFMON-BIN) perfmon-i7z.c helper_functions.c $(LIBS) |
2775 | + |
2776 | +test_exist: bin |
2777 | + @test -f i7z && echo 'Succeeded, now run sudo ./i7z' || echo 'Compilation failed' |
2778 | + |
2779 | +clean: |
2780 | + rm -f *.o $(BIN) |
2781 | + |
2782 | +distclean: clean |
2783 | + rm -f *~ \#* |
2784 | + |
2785 | +install: $(BIN) |
2786 | + install -D -m 0644 doc/i7z.man $(DESTDIR)$(mandir)man1/i7z.1 |
2787 | + install -D -m 755 $(BIN) $(DESTDIR)$(sbindir)$(BIN) |
2788 | + install -d $(DESTDIR)$(docdir) |
2789 | + install -m 0644 README.txt put_cores_offline.sh put_cores_online.sh MAKEDEV-cpuid-msr $(DESTDIR)$(docdir) |
2790 | |
2791 | === added file '.pc/install-i7z_rw_registers.patch/i7z_rw_registers.rb' |
2792 | --- .pc/install-i7z_rw_registers.patch/i7z_rw_registers.rb 1970-01-01 00:00:00 +0000 |
2793 | +++ .pc/install-i7z_rw_registers.patch/i7z_rw_registers.rb 2013-08-15 05:58:18 +0000 |
2794 | @@ -0,0 +1,435 @@ |
2795 | +#* ----------------------------------------------------------------------- * |
2796 | +# * |
2797 | +# * Under GPL v3 |
2798 | +# * written by Abhishek Jaiantilal |
2799 | +# * much thanks to Antonio Meireles who suggested this idea & helped with testing |
2800 | +# * run as sudo ruby i7z_rw_registers.rb |
2801 | +# * |
2802 | +# * ----------------------------------------------------------------------- */ |
2803 | + |
2804 | +#!/usr/bin/ruby |
2805 | + |
2806 | +def print_command_list() |
2807 | + print "Do you need help? \n" |
2808 | + print "Possible commands are \n" |
2809 | + print "help : which will print this list again \n" |
2810 | + print "turbo : which examines the turbo status \n" |
2811 | + print "multiplier : examines the multipliers \n" |
2812 | + print "power : which prints current wattage of the system\n" |
2813 | + print "clock : allows for software clock modulation ( a form of throttling )\n" |
2814 | + print "system : allows to print some system info\n" |
2815 | + print "quit : which will quit the program or just do ctrl + c\n" |
2816 | +end |
2817 | + |
2818 | +IA32_PERF_STATUS = 0x198 #read only |
2819 | +IA32_PERF_CTL = 0x199 #read write |
2820 | +IA32_MISC_ENABLE = 0x1a0 |
2821 | + |
2822 | +def num_cores |
2823 | + numcores = `cat /proc/cpuinfo | grep 'cpu cores' |head -n 1|sed 's/cpu cores\\s*:\\s//'` |
2824 | + return numcores.to_i |
2825 | +end |
2826 | + |
2827 | +def nehalem_or_sandybridge |
2828 | + proc_type = `cat /proc/cpuinfo | grep flags |head -n 1| grep avx` |
2829 | + |
2830 | + if proc_type.chomp.length == 0 |
2831 | + return 'Nehalem' |
2832 | + else |
2833 | + return 'Sandy Bridge' |
2834 | + end |
2835 | +end |
2836 | + |
2837 | +def turbo_command_list() |
2838 | + print "turbo : which examines the turbo status \n" |
2839 | + print " probable commands are\n" |
2840 | + print " turbo status : get the current status of turbo\n" |
2841 | + print " turbo enable : enable turbo\n" |
2842 | + print " turbo disable : disable turbo\n" |
2843 | +end |
2844 | + |
2845 | +def multiplier_command_list() |
2846 | + print "multiplier : which allows setting/examining multiplier \n" |
2847 | + print " probable commands are\n" |
2848 | + print " multiplier set <number> : set the multiplier to given number and ONLY in decimals\n" |
2849 | + print " multiplier get : examine the current multiplier\n" |
2850 | +end |
2851 | + |
2852 | +def power_command_list() |
2853 | + print "power : which allows setting/examining TDP / TDC\n" |
2854 | + print " probable commands are\n" |
2855 | + print " power set tdp <number> : set the multiplier to given number and ONLY in decimals\n" |
2856 | + print " power set tdc <number> : set the multiplier to given number and ONLY in decimals\n" |
2857 | + print " power get : examine the current TDP / TDC\n" |
2858 | +end |
2859 | + |
2860 | +def clock_command_list() |
2861 | + print "clock : allows for software clock modulation ( a form of throttling )\n" |
2862 | + print " a good link for understanding this is http://paulsiu.wordpress.com/2007/06/23/does-on-demand-clock-modulation-odcm-conserve-battery/\n" |
2863 | + print " probable commands are\n" |
2864 | + print " clock set <number> : set the number to one of the below or in range between 0-100\n" |
2865 | + print " and i will automatically to the value nearest to\n" |
2866 | + print " 12.5, 25.0, 37.5, 50.0, 63.5, 75, 87.5 (nehalem)\n" |
2867 | + print " sandy bridge supports 6.25% increments\n" |
2868 | + print " but, I (the tool) is not smart yet to distinguish between nehalem and sb\n" |
2869 | + print " so setting to 12.5 increment\n" |
2870 | + print " set <number> to 1 for 12.5%, 2 for 25%, 3 for 37.5%, 4 for 50%, \n" |
2871 | + print" 5 for 63.5%, 6 for 75% and 7 for 87.5%\n" |
2872 | + print " clock status : get clock modulation status\n" |
2873 | + print " clock disable : disable clock modulation\n" |
2874 | +end |
2875 | + |
2876 | +@duty_cycle_array = {0=>"reserved", 1=>'12.5% (default)', 2=>'25%', 3=>'37.5%', 4=>'50%', 5=>'63.5%',6=>'75%',7=>'87.5%'} |
2877 | + |
2878 | +def get_clock_status() |
2879 | + status = `rdmsr 0x19a --bitfield 4:4` |
2880 | + print_command('rdmsr 0x19a --bitfield 4:4') |
2881 | + if status.to_i == 0 |
2882 | + print "Clock modulation is disabled\n" |
2883 | + else |
2884 | + print "Clock modulation is enabled\n" |
2885 | + status = `rdmsr 0x19a --bitfield 3:1` |
2886 | + print_command('rdmsr 0x19a --bitfield 3:1') |
2887 | + print "Duty Cycle is #{@duty_cycle_array[status.to_i]}\n" |
2888 | + end |
2889 | +end |
2890 | + |
2891 | +def set_clock_modulation(mult) |
2892 | + if (mult.to_i<0) | (mult.to_i>8) |
2893 | + print "Error: clock set <number>, where <number> should be between 1-7\n" |
2894 | + print " set <number> to 1 for 12.5%, 2 for 25%, 3 for 37.5%, 4 for 50%, \n" |
2895 | + print" 5 for 63.5%, 6 for 75% and 7 for 87.5%\n" |
2896 | + return |
2897 | + end |
2898 | + get_clock_status() |
2899 | + |
2900 | + mult = mult.to_i << 1 |
2901 | + mult = mult | 0x10 |
2902 | + |
2903 | + for i in (0..12) |
2904 | + status = "wrmsr 0x19a -p#{i} #{mult}" |
2905 | + print_command(status) |
2906 | + system(status) |
2907 | + end |
2908 | + get_clock_status() |
2909 | +end |
2910 | + |
2911 | +def clock_disable() |
2912 | + val = 0x0 |
2913 | + for i in (0..(num_cores()*2-1)) |
2914 | + status = "wrmsr 0x19a -p#{i} #{val}" |
2915 | + print_command(status) |
2916 | + system(status) |
2917 | + end |
2918 | + get_clock_status() |
2919 | +end |
2920 | + |
2921 | +def print_command( str ) |
2922 | + print "Running following command in sudo: #{str} \n" |
2923 | +end |
2924 | + |
2925 | +def print_turbo_status() |
2926 | + status = `rdmsr 0x1a0 --bitfield 38:38` |
2927 | + print_command('rdmsr 0x1a0 --bitfield 38:38') |
2928 | + |
2929 | + if status.to_i == 1 |
2930 | + print "Turbo is Disabled\n" |
2931 | + else |
2932 | + print "Turbo is Enabled\n" |
2933 | + end |
2934 | +end |
2935 | + |
2936 | +def enable_turbo_status() |
2937 | + status = `rdmsr 0x1a0 --decimal` |
2938 | + print "First checking status\n" |
2939 | + print_command('rdmsr 0x1a0 --decimal') |
2940 | + |
2941 | + status = status.to_i & 0xBFFFFFFFFF #1 the 38th bit |
2942 | + |
2943 | + command = "wrmsr 0x1a0 #{status}" |
2944 | + system(command) |
2945 | + print_command(command) |
2946 | + |
2947 | + status = `rdmsr 0x1a0 --bitfield 38:38` |
2948 | + print "Now checking if the update was successful or not\n" |
2949 | + print_command('rdmsr 0x1a0 --bitfield 38:38') |
2950 | + |
2951 | + if status.to_i == 1 |
2952 | + print "Turbo is now Disabled, command failed and i dont know whyq\n" |
2953 | + else |
2954 | + print "Turbo is now Enabled, command succeeded\n" |
2955 | + end |
2956 | +end |
2957 | + |
2958 | +def disable_turbo_status() |
2959 | + status = `rdmsr 0x1a0 --decimal` |
2960 | + status = status.to_i | 0x4000000000 #1 the 38th bit |
2961 | + print "First checking status\n" |
2962 | + print_command('rdmsr 0x1a0 --decimal') |
2963 | + |
2964 | + command = "wrmsr 0x1a0 #{status}" |
2965 | + system(command) |
2966 | + print_command(command) |
2967 | + |
2968 | + status = `rdmsr 0x1a0 --bitfield 38:38` |
2969 | + print "Now checking if the update was successful or not\n" |
2970 | + print_command('rdmsr 0x1a0 --bitfield 38:38') |
2971 | + |
2972 | + if status.to_i == 1 |
2973 | + print "Turbo is now Disabled, command succeeded\n" |
2974 | + else |
2975 | + print "Turbo is now Enabled, command failed and i dont know why\n" |
2976 | + end |
2977 | +end |
2978 | + |
2979 | +def get_multiplier() |
2980 | + if nehalem_or_sandybridge == 'Nehalem' |
2981 | + status = `rdmsr 0x198 --decimal` |
2982 | + print_command('rdmsr 0x198 --decimal') |
2983 | + status = status.to_i & 0xFFFF |
2984 | + else |
2985 | + status = `rdmsr 0x198 --decimal --bitfield 15:8` |
2986 | + print_command('rdmsr 0x198 --decimal --bitfield 15:8') |
2987 | + status = status.to_i & 0xFF |
2988 | + end |
2989 | + print " Current Multiplier is #{status}\n" |
2990 | + |
2991 | + status1 = `rdmsr 0xce --decimal --bitfield 47:40` |
2992 | + print_command('rdmsr 0xce --decimal --bitfield 47:40') |
2993 | + print " Minimum Multiplier possible is #{status1.chomp}\n" |
2994 | + |
2995 | + status1 = `rdmsr 0xce --decimal --bitfield 15:8` |
2996 | + print_command('rdmsr 0xce --decimal --bitfield 15:8') |
2997 | + print " Maximum Multiplier in Non-turbo mode is #{status1.chomp}\n" |
2998 | + |
2999 | + turbo1 = `rdmsr 0x1ad --decimal --bitfield 7:0` |
3000 | + print_command('rdmsr 0x1ad --decimal --bitfield 7:0') |
3001 | + turbo2 = `rdmsr 0x1ad --decimal --bitfield 15:8` |
3002 | + print_command('rdmsr 0x1ad --decimal --bitfield 15:8') |
3003 | + turbo3 = `rdmsr 0x1ad --decimal --bitfield 23:16` |
3004 | + print_command('rdmsr 0x1ad --decimal --bitfield 23:16') |
3005 | + turbo4 = `rdmsr 0x1ad --decimal --bitfield 31:24` |
3006 | + print_command('rdmsr 0x1ad --decimal --bitfield 31:24') |
3007 | + turbo5 = `rdmsr 0x1ad --decimal --bitfield 39:32` |
3008 | + print_command('rdmsr 0x1ad --decimal --bitfield 39:32') |
3009 | + turbo6 = `rdmsr 0x1ad --decimal --bitfield 47:40` |
3010 | + print_command('rdmsr 0x1ad --decimal --bitfield 47:40') |
3011 | + |
3012 | + if num_cores()>=5 |
3013 | + print " Maximum turbo limit with 1/2/3/4/5/6 cores active is #{turbo1.chomp}/#{turbo2.chomp}/#{turbo3.chomp}/#{turbo4.chomp}/#{turbo5.chomp}/#{turbo6.chomp}\n" |
3014 | + elsif (num_cores()<=4 && num_cores()>2) |
3015 | + print " Maximum turbo limit with 1/2/3/4 cores active is #{turbo1.chomp}/#{turbo2.chomp}/#{turbo3.chomp}/#{turbo4.chomp}\n" |
3016 | + else |
3017 | + print " Maximum turbo limit with 1/2 cores active is #{turbo1.chomp}/#{turbo2.chomp}\n" |
3018 | + end |
3019 | +end |
3020 | + |
3021 | +def set_multiplier(mult) |
3022 | + status1 = `rdmsr 0xce --decimal --bitfield 47:40` |
3023 | + minimum_multiplier = status1.chomp.to_i |
3024 | + print_command('rdmsr 0xce --decimal --bitfield 47:40') |
3025 | + |
3026 | + turbo1 = `rdmsr 0x1ad --decimal --bitfield 7:0` |
3027 | + maximum_multiplier = turbo1.chomp.to_i |
3028 | + print_command('rdmsr 0x1ad --decimal --bitfield 7:0') |
3029 | + |
3030 | + if (mult < minimum_multiplier) | (mult > maximum_multiplier) |
3031 | + print "You asked for a multiplier #{mult}\n" |
3032 | + print "The range of input Multiplier is not in range\n" |
3033 | + print "Please put it between #{minimum_multiplier} to #{maximum_multiplier}\n" |
3034 | + |
3035 | + else |
3036 | + print "Don't worry if it prints that some wrmsr error message; i dont know the number of cores on your current machine so trying from 0..12" |
3037 | + for i in (0..(num_cores()*2-1)) |
3038 | + status = "wrmsr 0x199 -p#{i} #{mult}" |
3039 | + print_command(status) |
3040 | + system(status) |
3041 | + end |
3042 | + end |
3043 | + |
3044 | + get_multiplier() |
3045 | + #print "Current Multiplier is #{status}\n" |
3046 | +end |
3047 | + |
3048 | +def get_power |
3049 | + if nehalem_or_sandybridge != 'Nehalem' |
3050 | + print "POWER functions DON'T WORK ON SANDY BRIDGE (intel seems to have removed functionality)\n" |
3051 | + else |
3052 | + status1 = `rdmsr 0x1ac --bitfield 14:0 --decimal` |
3053 | + print_command('rdmsr 0x1ac --bitfield 14:0 --decimal') |
3054 | + |
3055 | + status2 = `rdmsr 0x1ac --bitfield 30:16 --decimal` |
3056 | + print_command('rdmsr 0x1ac --bitfield 30:16 --decimal') |
3057 | + |
3058 | + print "Current TDP limit is #{status1.to_i * 1/8} watts, TDC limit is #{status2.to_i * 1/8} amps\n" |
3059 | + end |
3060 | +end |
3061 | + |
3062 | +def set_tdp(limit) |
3063 | + if nehalem_or_sandybridge != 'Nehalem' |
3064 | + print "POWER functions DON'T WORK ON SANDY BRIDGE (intel seems to have removed functionality)\n" |
3065 | + else |
3066 | + status1 = `rdmsr 0x1ac --decimal` |
3067 | + print_command('rdmsr 0x1ac --decimal') |
3068 | + |
3069 | + tdp = (status1.to_i & 0xFFFFFFFFFFFF8000) | (0x8000) | (limit.to_i/0.125) #set bits 14:0, as resolution is 1/8 of a watt/amp |
3070 | + |
3071 | + status = "wrmsr 0x1ac #{tdp}" |
3072 | + print_command(status) |
3073 | + system(status) |
3074 | + end |
3075 | +end |
3076 | + |
3077 | +def set_tdc(limit) |
3078 | + if nehalem_or_sandybridge != 'Nehalem' |
3079 | + print "POWER functions DON'T WORK ON SANDY BRIDGE (intel seems to have removed functionality)\n" |
3080 | + else |
3081 | + status1 = `rdmsr 0x1ac --decimal` |
3082 | + print_command('rdmsr 0x1ac --decimal') |
3083 | + |
3084 | + tdc = (status1.to_i & 0xFFFFFFFF8000FFFF) | (0x80000000) | ((limit.to_i/0.125).to_i << 16) #set bits 30:16, as resolution is 1/8 of a watt/amp |
3085 | + |
3086 | + status = "wrmsr 0x1ac #{tdc}" |
3087 | + print_command(status) |
3088 | + system(status) |
3089 | + end |
3090 | +end |
3091 | + |
3092 | + |
3093 | +#IGNORE THIS FUNCTION - NOT USING IT AT ALL |
3094 | +def disable_ida() |
3095 | + #status = `rdmsr 0x199` |
3096 | + #status = status.to_i(16) |
3097 | + #p status |
3098 | + |
3099 | + #disable_turbo_string = 0x0100 |
3100 | + #system("wrmsr 0x199 #{disable_turbo_string}") |
3101 | + |
3102 | + #read the current opportunistic performance status and then write it. so first STATUS and then CTL |
3103 | + curr_status = `rdmsr 0x198 --decimal` |
3104 | + print "current performance status 0x#{curr_status}\n" |
3105 | + curr_status = (curr_status.to_i | 0x100).to_s(16) |
3106 | + print "in order to set ida=disable i will set bit 32 to get the following byte value 0x#{curr_status}\n" |
3107 | + curr_command = "wrmsr 0x199 #{curr_status}" |
3108 | + print "now executing #{curr_command}\n" |
3109 | + system(curr_command) |
3110 | +end |
3111 | + |
3112 | +print "\n\nThis script is totally experimental \n" |
3113 | +print "use it in superuser mode to get access to r/w access \n" |
3114 | +print "also i need msr-tools installed so that rdmsr and wrmsr can work in sudo\n" |
3115 | +print "write quit or ctrl+C to exit\n\n" |
3116 | +print "Now for the blurb on why you might find this script useful:\n" |
3117 | +print "Throttling cpu on battery is one place, some machines including W520\n" |
3118 | +print "have a wierd bios which switches off turbo when machine is booted in\n" |
3119 | +print "battery or some bios implement throttling even when the power is within limit\n" |
3120 | +print "and this tool should allow you to manually set the multiplier\n" |
3121 | +print "Whenever you run a command it will print out what goes in the background\n" |
3122 | +print "like what registers were read/written etc, this should allow one to even\n" |
3123 | +print "write different scripts to automatically run specifics multiplier in battery\n" |
3124 | +print "power and other modes.\n" |
3125 | +print "msr-tools are needed. Furthermore \"modprobe msr\" on command line needs to be executed\n" |
3126 | +print_command_list() |
3127 | + |
3128 | +at_exit{print "exiting, thanks for using\n"} |
3129 | + |
3130 | +while(1) |
3131 | + print ">> " |
3132 | + $input = STDIN.gets.chomp |
3133 | + if $input.downcase.eql? "quit" |
3134 | + break; |
3135 | + end |
3136 | + |
3137 | + if $input.length == 0 |
3138 | + print_command_list() |
3139 | + else |
3140 | + commands = $input.split |
3141 | + case commands[0].downcase # some commands have 0 level, eg just `help', others have two level 'turbo' and then status, enable and disable. multiplier get has 3 levels multiplier set 12 will set the multplier to 12 |
3142 | + when "help" |
3143 | + print_command_list() |
3144 | + when "turbo" |
3145 | + if ! commands[1].nil? |
3146 | + case commands[1].downcase |
3147 | + when "status" |
3148 | + print_turbo_status() |
3149 | + when "enable" |
3150 | + enable_turbo_status() |
3151 | + when "disable" |
3152 | + disable_turbo_status() |
3153 | + else |
3154 | + turbo_command_list() |
3155 | + end |
3156 | + else |
3157 | + turbo_command_list() |
3158 | + end |
3159 | + when "multiplier" |
3160 | + if !commands[1].nil? |
3161 | + case commands[1].downcase |
3162 | + when "get" |
3163 | + get_multiplier() |
3164 | + when "set" |
3165 | + if !commands[2].nil? |
3166 | + set_multiplier(commands[2].to_i) |
3167 | + else |
3168 | + multiplier_command_list() |
3169 | + end |
3170 | + else |
3171 | + multiplier_command_list() |
3172 | + end |
3173 | + else |
3174 | + multiplier_command_list() |
3175 | + end |
3176 | + when "power" |
3177 | + if !commands[1].nil? |
3178 | + case commands[1].downcase |
3179 | + when "get" |
3180 | + get_power() |
3181 | + when "set" |
3182 | + if !commands[2].nil? && !commands[3].nil? |
3183 | + case commands[2].downcase |
3184 | + when "tdp" |
3185 | + set_tdp(commands[3]) |
3186 | + when "tdc" |
3187 | + set_tdc(commands[3]) |
3188 | + else |
3189 | + power_command_list() |
3190 | + end |
3191 | + else |
3192 | + power_command_list() |
3193 | + end |
3194 | + else |
3195 | + power_command_list() |
3196 | + end |
3197 | + else |
3198 | + power_command_list() |
3199 | + end |
3200 | + when "clock" |
3201 | + if !commands[1].nil? |
3202 | + case commands[1].downcase |
3203 | + when "status" |
3204 | + get_clock_status() |
3205 | + when "set" |
3206 | + if !commands[2].nil? |
3207 | + set_clock_modulation(commands[2]) |
3208 | + else |
3209 | + clock_command_list() |
3210 | + end |
3211 | + when "disable" |
3212 | + clock_disable() |
3213 | + else |
3214 | + clock_command_list() |
3215 | + end |
3216 | + else |
3217 | + clock_command_list() |
3218 | + end |
3219 | + when "system" |
3220 | + print "number of cores #{num_cores()}\n" |
3221 | + print "trying to distinguish between nehalem/sandy bridge via AVX support... #{nehalem_or_sandybridge}\n" |
3222 | + else |
3223 | + print_command_list() |
3224 | + end |
3225 | + end |
3226 | + |
3227 | + |
3228 | +end |
3229 | + |
3230 | |
3231 | === removed file '.pc/install-i7z_rw_registers/Makefile' |
3232 | --- .pc/install-i7z_rw_registers/Makefile 2013-03-16 21:16:14 +0000 |
3233 | +++ .pc/install-i7z_rw_registers/Makefile 1970-01-01 00:00:00 +0000 |
3234 | @@ -1,63 +0,0 @@ |
3235 | -# |
3236 | -# Makefile for i7z, GPL v2, License in COPYING |
3237 | -# |
3238 | - |
3239 | -#makefile updated from patch by anestling |
3240 | - |
3241 | -#explicitly disable two scheduling flags as they cause segfaults, two more seem to crash the GUI version so putting them |
3242 | -#here |
3243 | -CFLAGS_FOR_AVOIDING_SEG_FAULT = -fno-schedule-insns2 -fno-schedule-insns -fno-inline-small-functions -fno-caller-saves |
3244 | -CFLAGS ?= -O3 |
3245 | -CFLAGS += $(CFLAGS_FOR_AVOIDING_SEG_FAULT) -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DBUILD_MAIN -Wimplicit-function-declaration |
3246 | - |
3247 | -LBITS := $(shell getconf LONG_BIT) |
3248 | -ifeq ($(LBITS),64) |
3249 | - CFLAGS += -Dx64_BIT |
3250 | -else |
3251 | - CFLAGS += -Dx86 |
3252 | -endif |
3253 | - |
3254 | -CC ?= gcc |
3255 | - |
3256 | -LIBS += -lncurses -lpthread -lrt -lm |
3257 | -INCLUDEFLAGS = |
3258 | - |
3259 | -BIN = i7z |
3260 | -# PERFMON-BIN = perfmon-i7z #future version to include performance monitor, either standalone or integrated |
3261 | -SRC = i7z.c helper_functions.c i7z_Single_Socket.c i7z_Dual_Socket.c |
3262 | -OBJ = $(SRC:.c=.o) |
3263 | - |
3264 | -prefix ?= /usr |
3265 | -sbindir = $(prefix)/sbin/ |
3266 | -docdir = $(prefix)/share/doc/$(BIN)/ |
3267 | -mandir ?= $(prefix)/share/man/ |
3268 | - |
3269 | -all: clean test_exist |
3270 | - |
3271 | -message: |
3272 | - @echo "If the compilation complains about not finding ncurses.h, install ncurses (libncurses5-dev on ubuntu/debian)" |
3273 | - |
3274 | -bin: message $(OBJ) |
3275 | - $(CC) $(CFLAGS) $(LDFLAGS) -o $(BIN) $(OBJ) $(LIBS) |
3276 | - |
3277 | -#http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=644728 for -ltinfo on debian |
3278 | -static-bin: message $(OBJ) |
3279 | - $(CC) $(CFLAGS) $(LDFLAGS) -o $(BIN) $(OBJ) -static-libgcc -DNCURSES_STATIC -static -lpthread -lncurses -lrt -lm -ltinfo |
3280 | - |
3281 | -# perfmon-bin: message $(OBJ) |
3282 | -# $(CC) $(CFLAGS) $(LDFLAGS) -o $(PERFMON-BIN) perfmon-i7z.c helper_functions.c $(LIBS) |
3283 | - |
3284 | -test_exist: bin |
3285 | - @test -f i7z && echo 'Succeeded, now run sudo ./i7z' || echo 'Compilation failed' |
3286 | - |
3287 | -clean: |
3288 | - rm -f *.o $(BIN) |
3289 | - |
3290 | -distclean: clean |
3291 | - rm -f *~ \#* |
3292 | - |
3293 | -install: $(BIN) |
3294 | - install -D -m 0644 doc/i7z.man $(DESTDIR)$(mandir)man1/i7z.1 |
3295 | - install -D -m 755 $(BIN) $(DESTDIR)$(sbindir)$(BIN) |
3296 | - install -d $(DESTDIR)$(docdir) |
3297 | - install -m 0644 README.txt put_cores_offline.sh put_cores_online.sh MAKEDEV-cpuid-msr $(DESTDIR)$(docdir) |
3298 | |
3299 | === removed file '.pc/install-i7z_rw_registers/i7z_rw_registers.rb' |
3300 | --- .pc/install-i7z_rw_registers/i7z_rw_registers.rb 2013-03-16 21:16:14 +0000 |
3301 | +++ .pc/install-i7z_rw_registers/i7z_rw_registers.rb 1970-01-01 00:00:00 +0000 |
3302 | @@ -1,435 +0,0 @@ |
3303 | -#* ----------------------------------------------------------------------- * |
3304 | -# * |
3305 | -# * Under GPL v3 |
3306 | -# * written by Abhishek Jaiantilal |
3307 | -# * much thanks to Antonio Meireles who suggested this idea & helped with testing |
3308 | -# * run as sudo ruby i7z_rw_registers.rb |
3309 | -# * |
3310 | -# * ----------------------------------------------------------------------- */ |
3311 | - |
3312 | -#!/usr/bin/ruby |
3313 | - |
3314 | -def print_command_list() |
3315 | - print "Do you need help? \n" |
3316 | - print "Possible commands are \n" |
3317 | - print "help : which will print this list again \n" |
3318 | - print "turbo : which examines the turbo status \n" |
3319 | - print "multiplier : examines the multipliers \n" |
3320 | - print "power : which prints current wattage of the system\n" |
3321 | - print "clock : allows for software clock modulation ( a form of throttling )\n" |
3322 | - print "system : allows to print some system info\n" |
3323 | - print "quit : which will quit the program or just do ctrl + c\n" |
3324 | -end |
3325 | - |
3326 | -IA32_PERF_STATUS = 0x198 #read only |
3327 | -IA32_PERF_CTL = 0x199 #read write |
3328 | -IA32_MISC_ENABLE = 0x1a0 |
3329 | - |
3330 | -def num_cores |
3331 | - numcores = `cat /proc/cpuinfo | grep 'cpu cores' |head -n 1|sed 's/cpu cores\\s*:\\s//'` |
3332 | - return numcores.to_i |
3333 | -end |
3334 | - |
3335 | -def nehalem_or_sandybridge |
3336 | - proc_type = `cat /proc/cpuinfo | grep flags |head -n 1| grep avx` |
3337 | - |
3338 | - if proc_type.chomp.length == 0 |
3339 | - return 'Nehalem' |
3340 | - else |
3341 | - return 'Sandy Bridge' |
3342 | - end |
3343 | -end |
3344 | - |
3345 | -def turbo_command_list() |
3346 | - print "turbo : which examines the turbo status \n" |
3347 | - print " probable commands are\n" |
3348 | - print " turbo status : get the current status of turbo\n" |
3349 | - print " turbo enable : enable turbo\n" |
3350 | - print " turbo disable : disable turbo\n" |
3351 | -end |
3352 | - |
3353 | -def multiplier_command_list() |
3354 | - print "multiplier : which allows setting/examining multiplier \n" |
3355 | - print " probable commands are\n" |
3356 | - print " multiplier set <number> : set the multiplier to given number and ONLY in decimals\n" |
3357 | - print " multiplier get : examine the current multiplier\n" |
3358 | -end |
3359 | - |
3360 | -def power_command_list() |
3361 | - print "power : which allows setting/examining TDP / TDC\n" |
3362 | - print " probable commands are\n" |
3363 | - print " power set tdp <number> : set the multiplier to given number and ONLY in decimals\n" |
3364 | - print " power set tdc <number> : set the multiplier to given number and ONLY in decimals\n" |
3365 | - print " power get : examine the current TDP / TDC\n" |
3366 | -end |
3367 | - |
3368 | -def clock_command_list() |
3369 | - print "clock : allows for software clock modulation ( a form of throttling )\n" |
3370 | - print " a good link for understanding this is http://paulsiu.wordpress.com/2007/06/23/does-on-demand-clock-modulation-odcm-conserve-battery/\n" |
3371 | - print " probable commands are\n" |
3372 | - print " clock set <number> : set the number to one of the below or in range between 0-100\n" |
3373 | - print " and i will automatically to the value nearest to\n" |
3374 | - print " 12.5, 25.0, 37.5, 50.0, 63.5, 75, 87.5 (nehalem)\n" |
3375 | - print " sandy bridge supports 6.25% increments\n" |
3376 | - print " but, I (the tool) is not smart yet to distinguish between nehalem and sb\n" |
3377 | - print " so setting to 12.5 increment\n" |
3378 | - print " set <number> to 1 for 12.5%, 2 for 25%, 3 for 37.5%, 4 for 50%, \n" |
3379 | - print" 5 for 63.5%, 6 for 75% and 7 for 87.5%\n" |
3380 | - print " clock status : get clock modulation status\n" |
3381 | - print " clock disable : disable clock modulation\n" |
3382 | -end |
3383 | - |
3384 | -@duty_cycle_array = {0=>"reserved", 1=>'12.5% (default)', 2=>'25%', 3=>'37.5%', 4=>'50%', 5=>'63.5%',6=>'75%',7=>'87.5%'} |
3385 | - |
3386 | -def get_clock_status() |
3387 | - status = `rdmsr 0x19a --bitfield 4:4` |
3388 | - print_command('rdmsr 0x19a --bitfield 4:4') |
3389 | - if status.to_i == 0 |
3390 | - print "Clock modulation is disabled\n" |
3391 | - else |
3392 | - print "Clock modulation is enabled\n" |
3393 | - status = `rdmsr 0x19a --bitfield 3:1` |
3394 | - print_command('rdmsr 0x19a --bitfield 3:1') |
3395 | - print "Duty Cycle is #{@duty_cycle_array[status.to_i]}\n" |
3396 | - end |
3397 | -end |
3398 | - |
3399 | -def set_clock_modulation(mult) |
3400 | - if (mult.to_i<0) | (mult.to_i>8) |
3401 | - print "Error: clock set <number>, where <number> should be between 1-7\n" |
3402 | - print " set <number> to 1 for 12.5%, 2 for 25%, 3 for 37.5%, 4 for 50%, \n" |
3403 | - print" 5 for 63.5%, 6 for 75% and 7 for 87.5%\n" |
3404 | - return |
3405 | - end |
3406 | - get_clock_status() |
3407 | - |
3408 | - mult = mult.to_i << 1 |
3409 | - mult = mult | 0x10 |
3410 | - |
3411 | - for i in (0..12) |
3412 | - status = "wrmsr 0x19a -p#{i} #{mult}" |
3413 | - print_command(status) |
3414 | - system(status) |
3415 | - end |
3416 | - get_clock_status() |
3417 | -end |
3418 | - |
3419 | -def clock_disable() |
3420 | - val = 0x0 |
3421 | - for i in (0..(num_cores()*2-1)) |
3422 | - status = "wrmsr 0x19a -p#{i} #{val}" |
3423 | - print_command(status) |
3424 | - system(status) |
3425 | - end |
3426 | - get_clock_status() |
3427 | -end |
3428 | - |
3429 | -def print_command( str ) |
3430 | - print "Running following command in sudo: #{str} \n" |
3431 | -end |
3432 | - |
3433 | -def print_turbo_status() |
3434 | - status = `rdmsr 0x1a0 --bitfield 38:38` |
3435 | - print_command('rdmsr 0x1a0 --bitfield 38:38') |
3436 | - |
3437 | - if status.to_i == 1 |
3438 | - print "Turbo is Disabled\n" |
3439 | - else |
3440 | - print "Turbo is Enabled\n" |
3441 | - end |
3442 | -end |
3443 | - |
3444 | -def enable_turbo_status() |
3445 | - status = `rdmsr 0x1a0 --decimal` |
3446 | - print "First checking status\n" |
3447 | - print_command('rdmsr 0x1a0 --decimal') |
3448 | - |
3449 | - status = status.to_i & 0xBFFFFFFFFF #1 the 38th bit |
3450 | - |
3451 | - command = "wrmsr 0x1a0 #{status}" |
3452 | - system(command) |
3453 | - print_command(command) |
3454 | - |
3455 | - status = `rdmsr 0x1a0 --bitfield 38:38` |
3456 | - print "Now checking if the update was successful or not\n" |
3457 | - print_command('rdmsr 0x1a0 --bitfield 38:38') |
3458 | - |
3459 | - if status.to_i == 1 |
3460 | - print "Turbo is now Disabled, command failed and i dont know whyq\n" |
3461 | - else |
3462 | - print "Turbo is now Enabled, command succeeded\n" |
3463 | - end |
3464 | -end |
3465 | - |
3466 | -def disable_turbo_status() |
3467 | - status = `rdmsr 0x1a0 --decimal` |
3468 | - status = status.to_i | 0x4000000000 #1 the 38th bit |
3469 | - print "First checking status\n" |
3470 | - print_command('rdmsr 0x1a0 --decimal') |
3471 | - |
3472 | - command = "wrmsr 0x1a0 #{status}" |
3473 | - system(command) |
3474 | - print_command(command) |
3475 | - |
3476 | - status = `rdmsr 0x1a0 --bitfield 38:38` |
3477 | - print "Now checking if the update was successful or not\n" |
3478 | - print_command('rdmsr 0x1a0 --bitfield 38:38') |
3479 | - |
3480 | - if status.to_i == 1 |
3481 | - print "Turbo is now Disabled, command succeeded\n" |
3482 | - else |
3483 | - print "Turbo is now Enabled, command failed and i dont know why\n" |
3484 | - end |
3485 | -end |
3486 | - |
3487 | -def get_multiplier() |
3488 | - if nehalem_or_sandybridge == 'Nehalem' |
3489 | - status = `rdmsr 0x198 --decimal` |
3490 | - print_command('rdmsr 0x198 --decimal') |
3491 | - status = status.to_i & 0xFFFF |
3492 | - else |
3493 | - status = `rdmsr 0x198 --decimal --bitfield 15:8` |
3494 | - print_command('rdmsr 0x198 --decimal --bitfield 15:8') |
3495 | - status = status.to_i & 0xFF |
3496 | - end |
3497 | - print " Current Multiplier is #{status}\n" |
3498 | - |
3499 | - status1 = `rdmsr 0xce --decimal --bitfield 47:40` |
3500 | - print_command('rdmsr 0xce --decimal --bitfield 47:40') |
3501 | - print " Minimum Multiplier possible is #{status1.chomp}\n" |
3502 | - |
3503 | - status1 = `rdmsr 0xce --decimal --bitfield 15:8` |
3504 | - print_command('rdmsr 0xce --decimal --bitfield 15:8') |
3505 | - print " Maximum Multiplier in Non-turbo mode is #{status1.chomp}\n" |
3506 | - |
3507 | - turbo1 = `rdmsr 0x1ad --decimal --bitfield 7:0` |
3508 | - print_command('rdmsr 0x1ad --decimal --bitfield 7:0') |
3509 | - turbo2 = `rdmsr 0x1ad --decimal --bitfield 15:8` |
3510 | - print_command('rdmsr 0x1ad --decimal --bitfield 15:8') |
3511 | - turbo3 = `rdmsr 0x1ad --decimal --bitfield 23:16` |
3512 | - print_command('rdmsr 0x1ad --decimal --bitfield 23:16') |
3513 | - turbo4 = `rdmsr 0x1ad --decimal --bitfield 31:24` |
3514 | - print_command('rdmsr 0x1ad --decimal --bitfield 31:24') |
3515 | - turbo5 = `rdmsr 0x1ad --decimal --bitfield 39:32` |
3516 | - print_command('rdmsr 0x1ad --decimal --bitfield 39:32') |
3517 | - turbo6 = `rdmsr 0x1ad --decimal --bitfield 47:40` |
3518 | - print_command('rdmsr 0x1ad --decimal --bitfield 47:40') |
3519 | - |
3520 | - if num_cores()>=5 |
3521 | - print " Maximum turbo limit with 1/2/3/4/5/6 cores active is #{turbo1.chomp}/#{turbo2.chomp}/#{turbo3.chomp}/#{turbo4.chomp}/#{turbo5.chomp}/#{turbo6.chomp}\n" |
3522 | - elsif (num_cores()<=4 && num_cores()>2) |
3523 | - print " Maximum turbo limit with 1/2/3/4 cores active is #{turbo1.chomp}/#{turbo2.chomp}/#{turbo3.chomp}/#{turbo4.chomp}\n" |
3524 | - else |
3525 | - print " Maximum turbo limit with 1/2 cores active is #{turbo1.chomp}/#{turbo2.chomp}\n" |
3526 | - end |
3527 | -end |
3528 | - |
3529 | -def set_multiplier(mult) |
3530 | - status1 = `rdmsr 0xce --decimal --bitfield 47:40` |
3531 | - minimum_multiplier = status1.chomp.to_i |
3532 | - print_command('rdmsr 0xce --decimal --bitfield 47:40') |
3533 | - |
3534 | - turbo1 = `rdmsr 0x1ad --decimal --bitfield 7:0` |
3535 | - maximum_multiplier = turbo1.chomp.to_i |
3536 | - print_command('rdmsr 0x1ad --decimal --bitfield 7:0') |
3537 | - |
3538 | - if (mult < minimum_multiplier) | (mult > maximum_multiplier) |
3539 | - print "You asked for a multiplier #{mult}\n" |
3540 | - print "The range of input Multiplier is not in range\n" |
3541 | - print "Please put it between #{minimum_multiplier} to #{maximum_multiplier}\n" |
3542 | - |
3543 | - else |
3544 | - print "Don't worry if it prints that some wrmsr error message; i dont know the number of cores on your current machine so trying from 0..12" |
3545 | - for i in (0..(num_cores()*2-1)) |
3546 | - status = "wrmsr 0x199 -p#{i} #{mult}" |
3547 | - print_command(status) |
3548 | - system(status) |
3549 | - end |
3550 | - end |
3551 | - |
3552 | - get_multiplier() |
3553 | - #print "Current Multiplier is #{status}\n" |
3554 | -end |
3555 | - |
3556 | -def get_power |
3557 | - if nehalem_or_sandybridge != 'Nehalem' |
3558 | - print "POWER functions DON'T WORK ON SANDY BRIDGE (intel seems to have removed functionality)\n" |
3559 | - else |
3560 | - status1 = `rdmsr 0x1ac --bitfield 14:0 --decimal` |
3561 | - print_command('rdmsr 0x1ac --bitfield 14:0 --decimal') |
3562 | - |
3563 | - status2 = `rdmsr 0x1ac --bitfield 30:16 --decimal` |
3564 | - print_command('rdmsr 0x1ac --bitfield 30:16 --decimal') |
3565 | - |
3566 | - print "Current TDP limit is #{status1.to_i * 1/8} watts, TDC limit is #{status2.to_i * 1/8} amps\n" |
3567 | - end |
3568 | -end |
3569 | - |
3570 | -def set_tdp(limit) |
3571 | - if nehalem_or_sandybridge != 'Nehalem' |
3572 | - print "POWER functions DON'T WORK ON SANDY BRIDGE (intel seems to have removed functionality)\n" |
3573 | - else |
3574 | - status1 = `rdmsr 0x1ac --decimal` |
3575 | - print_command('rdmsr 0x1ac --decimal') |
3576 | - |
3577 | - tdp = (status1.to_i & 0xFFFFFFFFFFFF8000) | (0x8000) | (limit.to_i/0.125) #set bits 14:0, as resolution is 1/8 of a watt/amp |
3578 | - |
3579 | - status = "wrmsr 0x1ac #{tdp}" |
3580 | - print_command(status) |
3581 | - system(status) |
3582 | - end |
3583 | -end |
3584 | - |
3585 | -def set_tdc(limit) |
3586 | - if nehalem_or_sandybridge != 'Nehalem' |
3587 | - print "POWER functions DON'T WORK ON SANDY BRIDGE (intel seems to have removed functionality)\n" |
3588 | - else |
3589 | - status1 = `rdmsr 0x1ac --decimal` |
3590 | - print_command('rdmsr 0x1ac --decimal') |
3591 | - |
3592 | - tdc = (status1.to_i & 0xFFFFFFFF8000FFFF) | (0x80000000) | ((limit.to_i/0.125).to_i << 16) #set bits 30:16, as resolution is 1/8 of a watt/amp |
3593 | - |
3594 | - status = "wrmsr 0x1ac #{tdc}" |
3595 | - print_command(status) |
3596 | - system(status) |
3597 | - end |
3598 | -end |
3599 | - |
3600 | - |
3601 | -#IGNORE THIS FUNCTION - NOT USING IT AT ALL |
3602 | -def disable_ida() |
3603 | - #status = `rdmsr 0x199` |
3604 | - #status = status.to_i(16) |
3605 | - #p status |
3606 | - |
3607 | - #disable_turbo_string = 0x0100 |
3608 | - #system("wrmsr 0x199 #{disable_turbo_string}") |
3609 | - |
3610 | - #read the current opportunistic performance status and then write it. so first STATUS and then CTL |
3611 | - curr_status = `rdmsr 0x198 --decimal` |
3612 | - print "current performance status 0x#{curr_status}\n" |
3613 | - curr_status = (curr_status.to_i | 0x100).to_s(16) |
3614 | - print "in order to set ida=disable i will set bit 32 to get the following byte value 0x#{curr_status}\n" |
3615 | - curr_command = "wrmsr 0x199 #{curr_status}" |
3616 | - print "now executing #{curr_command}\n" |
3617 | - system(curr_command) |
3618 | -end |
3619 | - |
3620 | -print "\n\nThis script is totally experimental \n" |
3621 | -print "use it in superuser mode to get access to r/w access \n" |
3622 | -print "also i need msr-tools installed so that rdmsr and wrmsr can work in sudo\n" |
3623 | -print "write quit or ctrl+C to exit\n\n" |
3624 | -print "Now for the blurb on why you might find this script useful:\n" |
3625 | -print "Throttling cpu on battery is one place, some machines including W520\n" |
3626 | -print "have a wierd bios which switches off turbo when machine is booted in\n" |
3627 | -print "battery or some bios implement throttling even when the power is within limit\n" |
3628 | -print "and this tool should allow you to manually set the multiplier\n" |
3629 | -print "Whenever you run a command it will print out what goes in the background\n" |
3630 | -print "like what registers were read/written etc, this should allow one to even\n" |
3631 | -print "write different scripts to automatically run specifics multiplier in battery\n" |
3632 | -print "power and other modes.\n" |
3633 | -print "msr-tools are needed. Furthermore \"modprobe msr\" on command line needs to be executed\n" |
3634 | -print_command_list() |
3635 | - |
3636 | -at_exit{print "exiting, thanks for using\n"} |
3637 | - |
3638 | -while(1) |
3639 | - print ">> " |
3640 | - $input = STDIN.gets.chomp |
3641 | - if $input.downcase.eql? "quit" |
3642 | - break; |
3643 | - end |
3644 | - |
3645 | - if $input.length == 0 |
3646 | - print_command_list() |
3647 | - else |
3648 | - commands = $input.split |
3649 | - case commands[0].downcase # some commands have 0 level, eg just `help', others have two level 'turbo' and then status, enable and disable. multiplier get has 3 levels multiplier set 12 will set the multplier to 12 |
3650 | - when "help" |
3651 | - print_command_list() |
3652 | - when "turbo" |
3653 | - if ! commands[1].nil? |
3654 | - case commands[1].downcase |
3655 | - when "status" |
3656 | - print_turbo_status() |
3657 | - when "enable" |
3658 | - enable_turbo_status() |
3659 | - when "disable" |
3660 | - disable_turbo_status() |
3661 | - else |
3662 | - turbo_command_list() |
3663 | - end |
3664 | - else |
3665 | - turbo_command_list() |
3666 | - end |
3667 | - when "multiplier" |
3668 | - if !commands[1].nil? |
3669 | - case commands[1].downcase |
3670 | - when "get" |
3671 | - get_multiplier() |
3672 | - when "set" |
3673 | - if !commands[2].nil? |
3674 | - set_multiplier(commands[2].to_i) |
3675 | - else |
3676 | - multiplier_command_list() |
3677 | - end |
3678 | - else |
3679 | - multiplier_command_list() |
3680 | - end |
3681 | - else |
3682 | - multiplier_command_list() |
3683 | - end |
3684 | - when "power" |
3685 | - if !commands[1].nil? |
3686 | - case commands[1].downcase |
3687 | - when "get" |
3688 | - get_power() |
3689 | - when "set" |
3690 | - if !commands[2].nil? && !commands[3].nil? |
3691 | - case commands[2].downcase |
3692 | - when "tdp" |
3693 | - set_tdp(commands[3]) |
3694 | - when "tdc" |
3695 | - set_tdc(commands[3]) |
3696 | - else |
3697 | - power_command_list() |
3698 | - end |
3699 | - else |
3700 | - power_command_list() |
3701 | - end |
3702 | - else |
3703 | - power_command_list() |
3704 | - end |
3705 | - else |
3706 | - power_command_list() |
3707 | - end |
3708 | - when "clock" |
3709 | - if !commands[1].nil? |
3710 | - case commands[1].downcase |
3711 | - when "status" |
3712 | - get_clock_status() |
3713 | - when "set" |
3714 | - if !commands[2].nil? |
3715 | - set_clock_modulation(commands[2]) |
3716 | - else |
3717 | - clock_command_list() |
3718 | - end |
3719 | - when "disable" |
3720 | - clock_disable() |
3721 | - else |
3722 | - clock_command_list() |
3723 | - end |
3724 | - else |
3725 | - clock_command_list() |
3726 | - end |
3727 | - when "system" |
3728 | - print "number of cores #{num_cores()}\n" |
3729 | - print "trying to distinguish between nehalem/sandy bridge via AVX support... #{nehalem_or_sandybridge}\n" |
3730 | - else |
3731 | - print_command_list() |
3732 | - end |
3733 | - end |
3734 | - |
3735 | - |
3736 | -end |
3737 | - |
3738 | |
3739 | === modified file 'GUI/i7z_GUI.cpp' |
3740 | --- GUI/i7z_GUI.cpp 2013-03-16 21:16:14 +0000 |
3741 | +++ GUI/i7z_GUI.cpp 2013-08-15 05:58:18 +0000 |
3742 | @@ -171,18 +171,17 @@ |
3743 | //CPUINFO is wrong for i7 but correct for the number of physical and logical cores present |
3744 | //If Hyperthreading is enabled then, multiple logical processors will share a common CORE ID |
3745 | //http://www.redhat.com/magazine/022aug06/departments/tips_tricks/ |
3746 | - system ("cat /proc/cpuinfo |grep MHz|sed 's/cpu\\sMHz\\s*:\\s//'|tail -n 1 > /tmp/cpufreq.txt"); |
3747 | - system ("grep \"core id\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numPhysical.txt"); |
3748 | - system ("grep \"processor\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numLogical.txt"); |
3749 | - |
3750 | - |
3751 | - //Open the parsed cpufreq file and obtain the cpufreq from /proc/cpuinfo |
3752 | + //system ("grep \"core id\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numPhysical.txt"); |
3753 | + //system ("grep \"processor\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numLogical.txt"); |
3754 | + |
3755 | + |
3756 | + // obtain the cpufreq from /proc/cpuinfo |
3757 | FILE *tmp_file; |
3758 | - tmp_file = fopen ("/tmp/cpufreq.txt", "r"); |
3759 | + tmp_file = popen ("sed -n '/MHz/ { s/cpu\\sMHz\\s*:\\s//p; q }' /proc/cpuinfo", "r"); |
3760 | char tmp_str[30]; |
3761 | fgets (tmp_str, 30, tmp_file); |
3762 | + pclose (tmp_file); |
3763 | double cpu_freq_cpuinfo = atof (tmp_str); |
3764 | - fclose (tmp_file); |
3765 | |
3766 | unsigned int numPhysicalCores, numLogicalCores; |
3767 | numPhysicalCores = socket_0.num_physical_cores + socket_1.num_physical_cores; |
3768 | |
3769 | === modified file 'debian/changelog' |
3770 | --- debian/changelog 2013-04-29 09:37:19 +0000 |
3771 | +++ debian/changelog 2013-08-15 05:58:18 +0000 |
3772 | @@ -1,3 +1,19 @@ |
3773 | +i7z (0.27.2-2ubuntu1) saucy; urgency=low |
3774 | + |
3775 | + * Merge from debian unstable. Remaining changes: |
3776 | + - debian/control: Future-proof by adding x32 to the architecture list |
3777 | + |
3778 | + -- Jackson Doak <noskcaj@ubuntu.com> Thu, 15 Aug 2013 07:44:30 +1000 |
3779 | + |
3780 | +i7z (0.27.2-2) unstable; urgency=low |
3781 | + |
3782 | + * Use canonical Vcs-* URLs. |
3783 | + * hyphen-used-as-minus-sign.patch: New. Fix manpage. |
3784 | + * fix-insecure-tempfile.patch: New. Fix insecure usage of /tmp/cpufreq.txt. |
3785 | + Use popen() instead of a temporary file. (Closes: #718418) |
3786 | + |
3787 | + -- Andreas Beckmann <anbe@debian.org> Thu, 01 Aug 2013 03:16:07 +0200 |
3788 | + |
3789 | i7z (0.27.2-1ubuntu1) saucy; urgency=low |
3790 | |
3791 | * Future-proof by adding x32 to the architecture list. |
3792 | |
3793 | === modified file 'debian/control' |
3794 | --- debian/control 2013-04-29 09:37:19 +0000 |
3795 | +++ debian/control 2013-08-15 05:58:18 +0000 |
3796 | @@ -9,8 +9,8 @@ |
3797 | gdb, |
3798 | Standards-Version: 3.9.4 |
3799 | Homepage: http://code.google.com/p/i7z/ |
3800 | -Vcs-Git: git://git.debian.org/collab-maint/i7z.git |
3801 | -Vcs-Browser: http://git.debian.org/?p=collab-maint/i7z.git;a=summary |
3802 | +Vcs-Git: git://anonscm.debian.org/collab-maint/i7z.git |
3803 | +Vcs-Browser: http://anonscm.debian.org/gitweb/?p=collab-maint/i7z.git;a=summary |
3804 | |
3805 | Package: i7z |
3806 | Architecture: amd64 i386 x32 |
3807 | |
3808 | === added file 'debian/patches/fix-insecure-tempfile.patch' |
3809 | --- debian/patches/fix-insecure-tempfile.patch 1970-01-01 00:00:00 +0000 |
3810 | +++ debian/patches/fix-insecure-tempfile.patch 2013-08-15 05:58:18 +0000 |
3811 | @@ -0,0 +1,76 @@ |
3812 | +Author: Andreas Beckmann <anbe@debian.org> |
3813 | +Description: fix insecure temfile usage: /tmp/cpufreq.txt |
3814 | + switch from system() + fopen() to popen() |
3815 | + disable other insecure tempfiles that may be generated but not used |
3816 | +Bug-Debian: http://bugs.debian.org/718418 |
3817 | + |
3818 | +Index: i7z/GUI/i7z_GUI.cpp |
3819 | +=================================================================== |
3820 | +--- i7z.orig/GUI/i7z_GUI.cpp 2013-08-15 07:42:57.277752286 +1000 |
3821 | ++++ i7z/GUI/i7z_GUI.cpp 2013-08-15 07:42:57.273752266 +1000 |
3822 | +@@ -171,18 +171,17 @@ |
3823 | + //CPUINFO is wrong for i7 but correct for the number of physical and logical cores present |
3824 | + //If Hyperthreading is enabled then, multiple logical processors will share a common CORE ID |
3825 | + //http://www.redhat.com/magazine/022aug06/departments/tips_tricks/ |
3826 | +- system ("cat /proc/cpuinfo |grep MHz|sed 's/cpu\\sMHz\\s*:\\s//'|tail -n 1 > /tmp/cpufreq.txt"); |
3827 | +- system ("grep \"core id\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numPhysical.txt"); |
3828 | +- system ("grep \"processor\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numLogical.txt"); |
3829 | ++ //system ("grep \"core id\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numPhysical.txt"); |
3830 | ++ //system ("grep \"processor\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numLogical.txt"); |
3831 | + |
3832 | + |
3833 | +- //Open the parsed cpufreq file and obtain the cpufreq from /proc/cpuinfo |
3834 | ++ // obtain the cpufreq from /proc/cpuinfo |
3835 | + FILE *tmp_file; |
3836 | +- tmp_file = fopen ("/tmp/cpufreq.txt", "r"); |
3837 | ++ tmp_file = popen ("sed -n '/MHz/ { s/cpu\\sMHz\\s*:\\s//p; q }' /proc/cpuinfo", "r"); |
3838 | + char tmp_str[30]; |
3839 | + fgets (tmp_str, 30, tmp_file); |
3840 | ++ pclose (tmp_file); |
3841 | + double cpu_freq_cpuinfo = atof (tmp_str); |
3842 | +- fclose (tmp_file); |
3843 | + |
3844 | + unsigned int numPhysicalCores, numLogicalCores; |
3845 | + numPhysicalCores = socket_0.num_physical_cores + socket_1.num_physical_cores; |
3846 | +Index: i7z/helper_functions.c |
3847 | +=================================================================== |
3848 | +--- i7z.orig/helper_functions.c 2013-08-15 07:42:57.277752286 +1000 |
3849 | ++++ i7z/helper_functions.c 2013-08-15 07:42:57.273752266 +1000 |
3850 | +@@ -531,16 +531,13 @@ |
3851 | + //CPUINFO is wrong for i7 but correct for the number of physical and logical cores present |
3852 | + //If Hyperthreading is enabled then, multiple logical processors will share a common CORE ID |
3853 | + //http://www.redhat.com/magazine/022aug06/departments/tips_tricks/ |
3854 | +- system |
3855 | +- ("cat /proc/cpuinfo |grep MHz|sed 's/cpu\\sMHz\\s*:\\s//'|tail -n 1 > /tmp/cpufreq.txt"); |
3856 | + |
3857 | +- |
3858 | +- //Open the parsed cpufreq file and obtain the cpufreq from /proc/cpuinfo |
3859 | ++ // obtain the cpufreq from /proc/cpuinfo |
3860 | + FILE *tmp_file; |
3861 | +- tmp_file = fopen ("/tmp/cpufreq.txt", "r"); |
3862 | ++ tmp_file = popen ("sed -n '/MHz/ { s/cpu\\sMHz\\s*:\\s//p; q }' /proc/cpuinfo", "r"); |
3863 | + char tmp_str[30]; |
3864 | + fgets (tmp_str, 30, tmp_file); |
3865 | +- fclose (tmp_file); |
3866 | ++ pclose (tmp_file); |
3867 | + return atof(tmp_str); |
3868 | + } |
3869 | + |
3870 | +Index: i7z/i7z_Single_Socket.c |
3871 | +=================================================================== |
3872 | +--- i7z.orig/i7z_Single_Socket.c 2013-08-15 07:42:57.277752286 +1000 |
3873 | ++++ i7z/i7z_Single_Socket.c 2013-08-15 07:42:57.273752266 +1000 |
3874 | +@@ -823,10 +823,13 @@ |
3875 | + //CPUINFO is wrong for i7 but correct for the number of physical and logical cores present |
3876 | + //If Hyperthreading is enabled then, multiple logical processors will share a common CORE ID |
3877 | + //http://www.redhat.com/magazine/022aug06/departments/tips_tricks/ |
3878 | ++ERROR INSECURE TMPFILE |
3879 | + system |
3880 | + ("cat /proc/cpuinfo |grep MHz|sed 's/cpu\\sMHz\\s*:\\s//'|tail -n 1 > /tmp/cpufreq.txt"); |
3881 | ++ERROR INSECURE TMPFILE |
3882 | + system |
3883 | + ("grep \"core id\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numPhysical.txt"); |
3884 | ++ERROR INSECURE TMPFILE |
3885 | + system |
3886 | + ("grep \"processor\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numLogical.txt"); |
3887 | + //At this step, /tmp/numPhysical contains number of physical cores in machine and |
3888 | |
3889 | === added file 'debian/patches/hyphen-used-as-minus-sign.patch' |
3890 | --- debian/patches/hyphen-used-as-minus-sign.patch 1970-01-01 00:00:00 +0000 |
3891 | +++ debian/patches/hyphen-used-as-minus-sign.patch 2013-08-15 05:58:18 +0000 |
3892 | @@ -0,0 +1,28 @@ |
3893 | +Author: Andreas Beckmann <anbe@debian.org> |
3894 | +Description: fix hyphen abuse |
3895 | + |
3896 | +Index: i7z/doc/i7z.man |
3897 | +=================================================================== |
3898 | +--- i7z.orig/doc/i7z.man 2013-08-15 07:42:55.025741119 +1000 |
3899 | ++++ i7z/doc/i7z.man 2013-08-15 07:42:55.025741119 +1000 |
3900 | +@@ -7,15 +7,15 @@ |
3901 | + i7z runs the i7z, ncurses based, program without any options. i7z will print out the C-states and temperature for i3, i5 and i7 based Core processors from Intel (including Nehalems, Sandy Bridge and Ivy Bridge). |
3902 | + .SH OPTIONS |
3903 | + .TP |
3904 | +-\fB-h, --help \fPshow the list of options available with the i7z tool. |
3905 | ++\fB\-h, \-\-help \fPshow the list of options available with the i7z tool. |
3906 | + .TP |
3907 | +-\fB-w [a|l], --write [a,l] \fPLogging of the frequencies can be turned on with this options. Option "-w a" or "--write a" will append to the log file. Option "-w l" or "--write l" will replace the log file. |
3908 | ++\fB\-w [a|l], \-\-write [a,l] \fPLogging of the frequencies can be turned on with this options. Option "\-w a" or "\-\-write a" will append to the log file. Option "\-w l" or "\-\-write l" will replace the log file. |
3909 | + .TP |
3910 | +-\fB-l, --logfile [FILENAME] \fPChange the log file name to the specified FILENAME. Default logging file is cpu_freq_log.txt (single socket) or cpu_freq_log_dual%d.txt (dual socket, %d is either 0, 1). |
3911 | ++\fB\-l, \-\-logfile [FILENAME] \fPChange the log file name to the specified FILENAME. Default logging file is cpu_freq_log.txt (single socket) or cpu_freq_log_dual%d.txt (dual socket, %d is either 0, 1). |
3912 | + .TP |
3913 | +-\fB--socket0 [SOCKETNUM], --socket1 [SOCKETNUM] \fPThe tool can print information for about 2 sockets at once at the most. The top view will be, by default, of the first socket (controlled by --socket0) and the bottom view will be of the second socket (controlled by --socket1). Supply the appropriate value of 0 or 1 or more for SOCKETNUM (if there are more sockets on the machine) to show in the top and bottom view. |
3914 | ++\fB\-\-socket0 [SOCKETNUM], \-\-socket1 [SOCKETNUM] \fPThe tool can print information for about 2 sockets at once at the most. The top view will be, by default, of the first socket (controlled by \-\-socket0) and the bottom view will be of the second socket (controlled by \-\-socket1). Supply the appropriate value of 0 or 1 or more for SOCKETNUM (if there are more sockets on the machine) to show in the top and bottom view. |
3915 | + .TP |
3916 | +-\fB--nogui \fPDisable the GUI. Useful when the only need is logging. |
3917 | ++\fB\-\-nogui \fPDisable the GUI. Useful when the only need is logging. |
3918 | + .SH Example |
3919 | + To print for two sockets and also change the log file (log to /tmp/logfilei7z) |
3920 | + |
3921 | |
3922 | === removed file 'debian/patches/install-i7z_rw_registers' |
3923 | --- debian/patches/install-i7z_rw_registers 2013-03-16 21:16:14 +0000 |
3924 | +++ debian/patches/install-i7z_rw_registers 1970-01-01 00:00:00 +0000 |
3925 | @@ -1,26 +0,0 @@ |
3926 | -Author: Andreas Beckmann <anbe@debian.org> |
3927 | -Description: install the i7z_rw_registers script and fix the hashbang |
3928 | - |
3929 | ---- a/i7z_rw_registers.rb |
3930 | -+++ b/i7z_rw_registers.rb |
3931 | -@@ -1,3 +1,5 @@ |
3932 | -+#!/usr/bin/ruby |
3933 | -+ |
3934 | - #* ----------------------------------------------------------------------- * |
3935 | - # * |
3936 | - # * Under GPL v3 |
3937 | -@@ -7,7 +9,6 @@ |
3938 | - # * |
3939 | - # * ----------------------------------------------------------------------- */ |
3940 | - |
3941 | --#!/usr/bin/ruby |
3942 | - |
3943 | - def print_command_list() |
3944 | - print "Do you need help? \n" |
3945 | ---- a/Makefile |
3946 | -+++ b/Makefile |
3947 | -@@ -61,3 +61,4 @@ |
3948 | - install -D -m 755 $(BIN) $(DESTDIR)$(sbindir)$(BIN) |
3949 | - install -d $(DESTDIR)$(docdir) |
3950 | - install -m 0644 README.txt put_cores_offline.sh put_cores_online.sh MAKEDEV-cpuid-msr $(DESTDIR)$(docdir) |
3951 | -+ install -m 0755 i7z_rw_registers.rb $(DESTDIR)$(sbindir)/i7z_rw_registers |
3952 | |
3953 | === added file 'debian/patches/install-i7z_rw_registers.patch' |
3954 | --- debian/patches/install-i7z_rw_registers.patch 1970-01-01 00:00:00 +0000 |
3955 | +++ debian/patches/install-i7z_rw_registers.patch 2013-08-15 05:58:18 +0000 |
3956 | @@ -0,0 +1,30 @@ |
3957 | +Author: Andreas Beckmann <anbe@debian.org> |
3958 | +Description: install the i7z_rw_registers script and fix the hashbang |
3959 | + |
3960 | +Index: i7z/i7z_rw_registers.rb |
3961 | +=================================================================== |
3962 | +--- i7z.orig/i7z_rw_registers.rb 2013-08-15 07:42:49.797715195 +1000 |
3963 | ++++ i7z/i7z_rw_registers.rb 2013-08-15 07:42:49.793715175 +1000 |
3964 | +@@ -1,3 +1,5 @@ |
3965 | ++#!/usr/bin/ruby |
3966 | ++ |
3967 | + #* ----------------------------------------------------------------------- * |
3968 | + # * |
3969 | + # * Under GPL v3 |
3970 | +@@ -7,7 +9,6 @@ |
3971 | + # * |
3972 | + # * ----------------------------------------------------------------------- */ |
3973 | + |
3974 | +-#!/usr/bin/ruby |
3975 | + |
3976 | + def print_command_list() |
3977 | + print "Do you need help? \n" |
3978 | +Index: i7z/Makefile |
3979 | +=================================================================== |
3980 | +--- i7z.orig/Makefile 2013-08-15 07:42:49.797715195 +1000 |
3981 | ++++ i7z/Makefile 2013-08-15 07:42:49.793715175 +1000 |
3982 | +@@ -61,3 +61,4 @@ |
3983 | + install -D -m 755 $(BIN) $(DESTDIR)$(sbindir)$(BIN) |
3984 | + install -d $(DESTDIR)$(docdir) |
3985 | + install -m 0644 README.txt put_cores_offline.sh put_cores_online.sh MAKEDEV-cpuid-msr $(DESTDIR)$(docdir) |
3986 | ++ install -m 0755 i7z_rw_registers.rb $(DESTDIR)$(sbindir)/i7z_rw_registers |
3987 | |
3988 | === modified file 'debian/patches/series' |
3989 | --- debian/patches/series 2013-03-16 21:16:14 +0000 |
3990 | +++ debian/patches/series 2013-08-15 05:58:18 +0000 |
3991 | @@ -1,1 +1,3 @@ |
3992 | -install-i7z_rw_registers |
3993 | +install-i7z_rw_registers.patch |
3994 | +hyphen-used-as-minus-sign.patch |
3995 | +fix-insecure-tempfile.patch |
3996 | |
3997 | === modified file 'debian/watch' |
3998 | --- debian/watch 2013-03-16 21:16:14 +0000 |
3999 | +++ debian/watch 2013-08-15 05:58:18 +0000 |
4000 | @@ -1,3 +1,2 @@ |
4001 | version=3 |
4002 | - |
4003 | http://code.google.com/p/i7z/downloads/list?can=1 .*/i7z-(\d[\d.]*)\.(?:zip|tgz|tbz2|txz|tar\.gz|tar\.bz2|tar\.xz) |
4004 | |
4005 | === modified file 'doc/i7z.man' |
4006 | --- doc/i7z.man 2013-03-16 21:16:14 +0000 |
4007 | +++ doc/i7z.man 2013-08-15 05:58:18 +0000 |
4008 | @@ -7,15 +7,15 @@ |
4009 | i7z runs the i7z, ncurses based, program without any options. i7z will print out the C-states and temperature for i3, i5 and i7 based Core processors from Intel (including Nehalems, Sandy Bridge and Ivy Bridge). |
4010 | .SH OPTIONS |
4011 | .TP |
4012 | -\fB-h, --help \fPshow the list of options available with the i7z tool. |
4013 | -.TP |
4014 | -\fB-w [a|l], --write [a,l] \fPLogging of the frequencies can be turned on with this options. Option "-w a" or "--write a" will append to the log file. Option "-w l" or "--write l" will replace the log file. |
4015 | -.TP |
4016 | -\fB-l, --logfile [FILENAME] \fPChange the log file name to the specified FILENAME. Default logging file is cpu_freq_log.txt (single socket) or cpu_freq_log_dual%d.txt (dual socket, %d is either 0, 1). |
4017 | -.TP |
4018 | -\fB--socket0 [SOCKETNUM], --socket1 [SOCKETNUM] \fPThe tool can print information for about 2 sockets at once at the most. The top view will be, by default, of the first socket (controlled by --socket0) and the bottom view will be of the second socket (controlled by --socket1). Supply the appropriate value of 0 or 1 or more for SOCKETNUM (if there are more sockets on the machine) to show in the top and bottom view. |
4019 | -.TP |
4020 | -\fB--nogui \fPDisable the GUI. Useful when the only need is logging. |
4021 | +\fB\-h, \-\-help \fPshow the list of options available with the i7z tool. |
4022 | +.TP |
4023 | +\fB\-w [a|l], \-\-write [a,l] \fPLogging of the frequencies can be turned on with this options. Option "\-w a" or "\-\-write a" will append to the log file. Option "\-w l" or "\-\-write l" will replace the log file. |
4024 | +.TP |
4025 | +\fB\-l, \-\-logfile [FILENAME] \fPChange the log file name to the specified FILENAME. Default logging file is cpu_freq_log.txt (single socket) or cpu_freq_log_dual%d.txt (dual socket, %d is either 0, 1). |
4026 | +.TP |
4027 | +\fB\-\-socket0 [SOCKETNUM], \-\-socket1 [SOCKETNUM] \fPThe tool can print information for about 2 sockets at once at the most. The top view will be, by default, of the first socket (controlled by \-\-socket0) and the bottom view will be of the second socket (controlled by \-\-socket1). Supply the appropriate value of 0 or 1 or more for SOCKETNUM (if there are more sockets on the machine) to show in the top and bottom view. |
4028 | +.TP |
4029 | +\fB\-\-nogui \fPDisable the GUI. Useful when the only need is logging. |
4030 | .SH Example |
4031 | To print for two sockets and also change the log file (log to /tmp/logfilei7z) |
4032 | |
4033 | |
4034 | === modified file 'helper_functions.c' |
4035 | --- helper_functions.c 2013-03-16 21:16:14 +0000 |
4036 | +++ helper_functions.c 2013-08-15 05:58:18 +0000 |
4037 | @@ -531,16 +531,13 @@ |
4038 | //CPUINFO is wrong for i7 but correct for the number of physical and logical cores present |
4039 | //If Hyperthreading is enabled then, multiple logical processors will share a common CORE ID |
4040 | //http://www.redhat.com/magazine/022aug06/departments/tips_tricks/ |
4041 | - system |
4042 | - ("cat /proc/cpuinfo |grep MHz|sed 's/cpu\\sMHz\\s*:\\s//'|tail -n 1 > /tmp/cpufreq.txt"); |
4043 | - |
4044 | - |
4045 | - //Open the parsed cpufreq file and obtain the cpufreq from /proc/cpuinfo |
4046 | + |
4047 | + // obtain the cpufreq from /proc/cpuinfo |
4048 | FILE *tmp_file; |
4049 | - tmp_file = fopen ("/tmp/cpufreq.txt", "r"); |
4050 | + tmp_file = popen ("sed -n '/MHz/ { s/cpu\\sMHz\\s*:\\s//p; q }' /proc/cpuinfo", "r"); |
4051 | char tmp_str[30]; |
4052 | fgets (tmp_str, 30, tmp_file); |
4053 | - fclose (tmp_file); |
4054 | + pclose (tmp_file); |
4055 | return atof(tmp_str); |
4056 | } |
4057 | |
4058 | |
4059 | === modified file 'i7z_Single_Socket.c' |
4060 | --- i7z_Single_Socket.c 2013-03-16 21:16:14 +0000 |
4061 | +++ i7z_Single_Socket.c 2013-08-15 05:58:18 +0000 |
4062 | @@ -823,10 +823,13 @@ |
4063 | //CPUINFO is wrong for i7 but correct for the number of physical and logical cores present |
4064 | //If Hyperthreading is enabled then, multiple logical processors will share a common CORE ID |
4065 | //http://www.redhat.com/magazine/022aug06/departments/tips_tricks/ |
4066 | +ERROR INSECURE TMPFILE |
4067 | system |
4068 | ("cat /proc/cpuinfo |grep MHz|sed 's/cpu\\sMHz\\s*:\\s//'|tail -n 1 > /tmp/cpufreq.txt"); |
4069 | +ERROR INSECURE TMPFILE |
4070 | system |
4071 | ("grep \"core id\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numPhysical.txt"); |
4072 | +ERROR INSECURE TMPFILE |
4073 | system |
4074 | ("grep \"processor\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numLogical.txt"); |
4075 | //At this step, /tmp/numPhysical contains number of physical cores in machine and |
Jackson,
You need to include the bug number in the changelog entry (LP: #XXXXXX). Also why did you revert the maintainer changes? What you removed is right for Ubuntu since we have Ubuntu changes. You can manually fix this or I think the update-maintainer script will do it for you (I've never used it)
3800 -Maintainer: Ubuntu Developers <email address hidden> Maintainer: Andreas Beckmann <email address hidden>
3801 -XSBC-Original-
3802 +Maintainer: Andreas Beckmann <email address hidden>