Debian Codegraph @

GUI/i7z_GUI.cpp

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /* ----------------------------------------------------------------------- *
2 *
3 * Copyright 2009 Abhishek Jaiantilal
4 *
5 * Under GPL v2
6 *
7 * ----------------------------------------------------------------------- */
8 #include <memory.h>
9 #include <errno.h>
10 #include <stdio.h>
11 #include <fcntl.h>
12 #include <unistd.h>
13 #include <stdlib.h>
14 #include <getopt.h>
15 #include <inttypes.h>
16 #include <sys/types.h>
17 #include <sys/time.h>
18 #include <time.h>
19 #include <math.h>
20
21 #include <QApplication>
22 #include <QPushButton>
23 #include <QProgressBar>
24 #include <QWidget>
25 #include <QVBoxLayout>
26 #include <QGridLayout>
27 #include <QLabel>
28 #include <QThread>
29 #include <QTimer>
30 #include <QTime>
31
32
33 #ifndef UINT32_MAX
34 # define UINT32_MAX (4294967295U)
35 #endif
36 #include "../helper_functions.c"
37
38 #define MAX_PROCESSORS_GUI 12
39
40 bool global_in_i7z_main_thread = false;
41 int socket_list[MAX_PROCESSORS_GUI];
42 int core_list[MAX_PROCESSORS_GUI];
43 struct cpu_heirarchy_info chi;
44 struct cpu_socket_info socket_0, socket_1;
45 unsigned int numCPUs;
46 struct program_options prog_options;
47
48 void Construct_Socket_Information_in_GUI(unsigned int *numCPUs) {
49 int socket_0_num=0, socket_1_num=1;
50 socket_0.max_cpu=0;
51 socket_0.socket_num=0;
52 int i;
53 for(i=0;i < 8; i++)
54 socket_0.processor_num[i]=-1;
55 socket_1.max_cpu=0;
56 socket_1.socket_num=1;
57
58 for(i=0;i < 8; i++)
59 socket_1.processor_num[i]=-1;
60
61 construct_CPU_Heirarchy_info(&chi);
62 construct_sibling_list(&chi);
63 // print_CPU_Heirarchy(chi);
64 construct_socket_information(&chi, &socket_0, &socket_1, socket_0_num, socket_1_num);
65 // print_socket_information(&socket_0);
66 // print_socket_information(&socket_1);
67 *numCPUs = socket_0.num_physical_cores + socket_1.num_physical_cores;
68
69 //// FOR DEBUGGING DUAL SOCKET CODE ON SINGLE SOCKET, UNCOMMENT BELOW 2 lines
70 // memcpy(&socket_1, &socket_0, sizeof(struct cpu_socket_info));
71 // socket_1.socket_num=0;
72
73
74 // print_socket_information(&socket_0);
75 // print_socket_information(&socket_1);
76 *numCPUs = socket_0.num_physical_cores + socket_1.num_physical_cores;
77 // printf("My Widget: Num Processors %d\n",*numCPUs);
78
79 int k, ii;
80 k=0;
81 for (ii = 0; ii < socket_0.num_physical_cores ; ii++) {
82 if ( socket_0.processor_num[ii] != -1) {
83 core_list[k] = socket_0.processor_num[ii];
84 socket_list[k] = 0;
85 k++;
86 }
87 }
88 for (ii = 0; ii < socket_1.num_physical_cores ; ii++) {
89 if ( socket_1.processor_num[ii] != -1) {
90 core_list[k] = socket_1.processor_num[ii];
91 socket_list[k] = 1;
92 k++;
93 }
94 }
95 }
96
97 class MyThread:public QThread
98 {
99 public:
100 MyThread ();
101 void run ();
102 double *FREQ, *MULT;
103 long double *C0_TIME, *C1_TIME, *C3_TIME, *C6_TIME;
104 };
105
106 MyThread::MyThread ()
107 {
108 Construct_Socket_Information_in_GUI(&numCPUs);
109
110 //allocate space for the variables
111 FREQ = (double *) malloc (sizeof (double) * numCPUs);
112 MULT = (double *) malloc (sizeof (double) * numCPUs);
113 C0_TIME = (long double *) malloc (sizeof (long double) * numCPUs);
114 C1_TIME = (long double *) malloc (sizeof (long double) * numCPUs);
115 C3_TIME = (long double *) malloc (sizeof (long double) * numCPUs);
116 C6_TIME = (long double *) malloc (sizeof (long double) * numCPUs);
117
118 int i;
119 for (i = 0; i < (int)numCPUs; i++)
120 {
121 FREQ[i] = 0;
122 MULT[i] = 0;
123 C0_TIME[i] = 0;
124 C1_TIME[i] = 0;
125 C3_TIME[i] = 0;
126 C6_TIME[i] = 0;
127 }
128 }
129
130
131 void
132 MyThread::run ()
133 {
134
135 print_CPU_Heirarchy(chi);
136
137 int i, ii;
138
139 //MSR number and hi:low bit of that MSR
140 //This msr contains a lot of stuff, per socket wise
141 //one can pass any core number and then get in multiplier etc
142 int PLATFORM_INFO_MSR = 206; //CE 15:8
143 int PLATFORM_INFO_MSR_low = 8;
144 int PLATFORM_INFO_MSR_high = 15;
145
146 ////To find out if Turbo is enabled use the below msr and bit 38
147 ////bit for TURBO is 38
148 ////msr reading is now moved into tubo_status
149 //int IA32_MISC_ENABLE = 416;
150 //int TURBO_FLAG_low = 38;
151 //int TURBO_FLAG_high = 38;
152
153
154 //int MSR_TURBO_RATIO_LIMIT = 429;
155
156 int CPU_NUM;
157 int CPU_Multiplier;
158 float BLCK;
159 char TURBO_MODE;
160
161 printf("i7z DEBUG: GUI VERSION DOESN'T SUPPORT CORE OFFLINING\n");
162 sleep (1);
163
164 // 3B defines till Max 4 Core and the rest bit values from 32:63 were reserved.
165 // int MAX_TURBO_1C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 7, 0);
166 // int MAX_TURBO_2C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 15, 8);
167 // int MAX_TURBO_3C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 23, 16);
168 // int MAX_TURBO_4C = get_msr_value (CPU_NUM, MSR_TURBO_RATIO_LIMIT, 31, 24);
169
170
171 //CPUINFO is wrong for i7 but correct for the number of physical and logical cores present
172 //If Hyperthreading is enabled then, multiple logical processors will share a common CORE ID
173 //http://www.redhat.com/magazine/022aug06/departments/tips_tricks/
•174 //system ("grep \"core id\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numPhysical.txt");
175 //system ("grep \"processor\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numLogical.txt");
176
177
•178 // obtain the cpufreq from /proc/cpuinfo
179 FILE *tmp_file;
•180 tmp_file = popen ("sed -n '/MHz/ { s/cpu\\sMHz\\s*:\\s//p; q }' /proc/cpuinfo", "r");
181 char tmp_str[30];
182 fgets (tmp_str, 30, tmp_file);
•183 pclose (tmp_file);
184 double cpu_freq_cpuinfo = atof (tmp_str);
185
186 unsigned int numPhysicalCores, numLogicalCores;
187 numPhysicalCores = socket_0.num_physical_cores + socket_1.num_physical_cores;
188 numLogicalCores = socket_0.num_logical_cores + socket_1.num_logical_cores;
189 // printf("My thread: Num Processors %d\n",numCPUs);
190
191 int error_indx;
192
193 //estimate the freq using the estimate_MHz() code that is almost mhz accurate
194 cpu_freq_cpuinfo = estimate_MHz ();
195
196 //We just need one CPU (we use Core-0) to figure out the multiplier and the bus clock freq.
197 CPU_NUM = 0;
198 CPU_Multiplier =
199 get_msr_value (CPU_NUM, PLATFORM_INFO_MSR, PLATFORM_INFO_MSR_high,
200 PLATFORM_INFO_MSR_low, &error_indx);
201 BLCK = cpu_freq_cpuinfo / CPU_Multiplier;
202 TURBO_MODE = turbo_status (); //get_msr_value(CPU_NUM,IA32_MISC_ENABLE, TURBO_FLAG_high,TURBO_FLAG_low);
203
204 //to find how many cpus are enabled, we could have used sysconf but that will just give the logical numbers
205 //if HT is enabled then the threads of the same core have the same C-state residency number so...
206 //Its imperative to figure out the number of physical and number of logical cores.
207 //sysconf(_SC_NPROCESSORS_ONLN);
208
209
210 bool HT_ON;
211 char HT_ON_str[30];
212 if (numLogicalCores > numPhysicalCores)
213 {
214 strcpy (HT_ON_str, "Hyper Threading ON");
215 HT_ON = true;
216 }
217 else
218 {
219 strcpy (HT_ON_str, "Hyper Threading OFF");
220 HT_ON = false;
221 }
222
223 float TRUE_CPU_FREQ;
224 if (TURBO_MODE == 1)
225 {
226 TRUE_CPU_FREQ = BLCK * ((double)CPU_Multiplier + 1);
227 }
228 else
229 {
230 TRUE_CPU_FREQ = BLCK * ((double)CPU_Multiplier);
231 }
232
233
234 int IA32_PERF_GLOBAL_CTRL = 911; //3BF
235 int IA32_PERF_GLOBAL_CTRL_Value =
236 get_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 63, 0,&error_indx);
237 int IA32_FIXED_CTR_CTL = 909; //38D
238 int IA32_FIXED_CTR_CTL_Value =
239 get_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 63, 0,&error_indx);
240
241 //printf("IA32_PERF_GLOBAL_CTRL %d\n",IA32_PERF_GLOBAL_CTRL_Value);
242 //printf("IA32_FIXED_CTR_CTL %d\n",IA32_FIXED_CTR_CTL_Value);
243
244 unsigned long long int CPU_CLK_UNHALTED_CORE, CPU_CLK_UNHALTED_REF,
245 CPU_CLK_C3, CPU_CLK_C6, CPU_CLK_C1;
246
247 CPU_CLK_UNHALTED_CORE = get_msr_value (CPU_NUM, 778, 63, 0,&error_indx);
248 CPU_CLK_UNHALTED_REF = get_msr_value (CPU_NUM, 779, 63, 0,&error_indx);
249
250 unsigned long long int old_val_CORE[numCPUs], new_val_CORE[numCPUs];
251 unsigned long long int old_val_REF[numCPUs], new_val_REF[numCPUs];
252 unsigned long long int old_val_C3[numCPUs], new_val_C3[numCPUs];
253 unsigned long long int old_val_C6[numCPUs], new_val_C6[numCPUs];
254 // unsigned long int old_val_C1[numCPUs], new_val_C1[numCPUs];
255
256 unsigned long long int old_TSC[numCPUs], new_TSC[numCPUs];
257
258 struct timeval tvstart[numCPUs], tvstop[numCPUs];
259
260 struct timespec one_second_sleep;
261 one_second_sleep.tv_sec = 0;
262 one_second_sleep.tv_nsec = 999999999; // 1000msec
263
264
265 unsigned long int IA32_MPERF = get_msr_value (CPU_NUM, 231, 7, 0,&error_indx);
266 unsigned long int IA32_APERF = get_msr_value (CPU_NUM, 232, 7, 0,&error_indx);
267 // mvprintw(12,0,"Wait...\n"); refresh();
268 nanosleep (&one_second_sleep, NULL);
269 IA32_MPERF = get_msr_value (CPU_NUM, 231, 7, 0, &error_indx) - IA32_MPERF;
270 IA32_APERF = get_msr_value (CPU_NUM, 232, 7, 0, &error_indx) - IA32_APERF;
271
272 //printf("Diff. i n APERF = %u, MPERF = %d\n", IA32_MPERF, IA32_APERF);
273
274 long double C0_time[numCPUs], C1_time[numCPUs], C3_time[numCPUs], C6_time[numCPUs];
275 double _FREQ[numCPUs], _MULT[numCPUs];
276
277 // mvprintw(12,0,"Current Freqs\n");
278
279 int kk=11;
280 double estimated_mhz;
281 for (;;)
282 {
283 Construct_Socket_Information_in_GUI(&numCPUs);
284
285 if (kk>10) {
286 kk=0;
287 for (ii = 0; ii < (int)numCPUs; ii++)
288 {
289 CPU_NUM = core_list[ii];
290 IA32_PERF_GLOBAL_CTRL_Value = get_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 63, 0, &error_indx);
291 set_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 0x700000003LLU);
292
293 IA32_FIXED_CTR_CTL_Value = get_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 63, 0, &error_indx);
294 set_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 819);
295
296 IA32_PERF_GLOBAL_CTRL_Value = get_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 63, 0, &error_indx);
297 IA32_FIXED_CTR_CTL_Value = get_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 63, 0, &error_indx);
298
299 old_val_CORE[ii] = get_msr_value (CPU_NUM, 778, 63, 0,&error_indx);
300 old_val_REF[ii] = get_msr_value (CPU_NUM, 779, 63, 0,&error_indx);
301 old_val_C3[ii] = get_msr_value (CPU_NUM, 1020, 63, 0,&error_indx);
302 old_val_C6[ii] = get_msr_value (CPU_NUM, 1021, 63, 0,&error_indx);
303 old_TSC[ii] = rdtsc ();
304 }
305 }
306 kk++;
307
308 nanosleep (&one_second_sleep, NULL);
309
310 estimated_mhz = estimate_MHz();
311
312 for (i = 0; i < (int)numCPUs; i++)
313 {
314 CPU_NUM = core_list[i];
315 new_val_CORE[i] = get_msr_value (CPU_NUM, 778, 63, 0,&error_indx);
316 new_val_REF[i] = get_msr_value (CPU_NUM, 779, 63, 0,&error_indx);
317 new_val_C3[i] = get_msr_value (CPU_NUM, 1020, 63, 0,&error_indx);
318 new_val_C6[i] = get_msr_value (CPU_NUM, 1021, 63, 0,&error_indx);
319 new_TSC[i] = rdtsc ();
320 if (old_val_CORE[i] > new_val_CORE[i])
321 {
322 CPU_CLK_UNHALTED_CORE =
323 (3.40282366921e38 - old_val_CORE[i]) + new_val_CORE[i];
324 }
325 else
326 {
327 CPU_CLK_UNHALTED_CORE = new_val_CORE[i] - old_val_CORE[i];
328 }
329
330 //number of TSC cycles while its in halted state
331 if ((new_TSC[i] - old_TSC[i]) < CPU_CLK_UNHALTED_CORE)
332 CPU_CLK_C1 = 0;
333 else
334 CPU_CLK_C1 = ((new_TSC[i] - old_TSC[i]) - CPU_CLK_UNHALTED_CORE);
335
336 if (old_val_REF[i] > new_val_REF[i])
337 {
338 CPU_CLK_UNHALTED_REF =
339 (3.40282366921e38 - old_val_REF[i]) + new_val_REF[i];
340 }
341 else
342 {
343 CPU_CLK_UNHALTED_REF = new_val_REF[i] - old_val_REF[i];
344 }
345
346 if (old_val_C3[i] > new_val_C3[i])
347 {
348 CPU_CLK_C3 = (3.40282366921e38 - old_val_C3[i]) + new_val_C3[i];
349 }
350 else
351 {
352 CPU_CLK_C3 = new_val_C3[i] - old_val_C3[i];
353 }
354
355 if (old_val_C6[i] > new_val_C6[i])
356 {
357 CPU_CLK_C6 = (3.40282366921e38 - old_val_C6[i]) + new_val_C6[i];
358 }
359 else
360 {
361 CPU_CLK_C6 = new_val_C6[i] - old_val_C6[i];
362 }
363
364 _FREQ[i] =
365 estimated_mhz * ((long double) CPU_CLK_UNHALTED_CORE /
366 (long double) CPU_CLK_UNHALTED_REF);
367 _MULT[i] = _FREQ[i] / BLCK;
368
369 C0_time[i] =
370 ((long double) CPU_CLK_UNHALTED_REF /
371 (long double) (new_TSC[i] - old_TSC[i]));
372 long double c1_time =
373 ((long double) CPU_CLK_C1 /
374 (long double) (new_TSC[i] - old_TSC[i]));
375 C3_time[i] =
376 ((long double) CPU_CLK_C3 /
377 (long double) (new_TSC[i] - old_TSC[i]));
378 C6_time[i] =
379 ((long double) CPU_CLK_C6 /
380 (long double) (new_TSC[i] - old_TSC[i]));
381
382 //C1_time[i] -= C3_time[i] + C6_time[i];
383 C1_time[i] = c1_time - (C3_time[i] + C6_time[i]) ;
384 if (!isnan(c1_time) && !isinf(c1_time)) {
385 if (C1_time[i] <= 0) {
386 C1_time[i]=0;
387 }
388 }
389
390 if (C0_time[i] < 1e-2) {
391 if (C0_time[i] > 1e-4) C0_time[i] = 0.01;
392 else C0_time[i] = 0;
393 }
394
395 if (C1_time[i] < 1e-2) {
396 if (C1_time[i] > 1e-4) C1_time[i] = 0.01;
397 else C1_time[i] = 0;
398 }
399
400 if (C3_time[i] < 1e-2) {
401 if (C3_time[i] > 1e-4) C3_time[i] = 0.01;
402 else C3_time[i] = 0;
403 }
404
405 if (C6_time[i] < 1e-2) {
406 if (C6_time[i] > 1e-4) C6_time[i] = 0.01;
407 else C6_time[i] = 0;
408 }
409 }
410 // printf("Hello");
411 // for(i=0;i<numCPUs;i++){
412 // 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]));
413 // 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]));
414 // printf("%llu %llu %lld\n",new_TSC[i], old_TSC[i],new_TSC[i]- old_TSC[i]);
415 // }
416 TRUE_CPU_FREQ = 0;
417 for (i = 0; i < (int)numCPUs; i++)
418 if (_FREQ[i] > TRUE_CPU_FREQ)
419 TRUE_CPU_FREQ = _FREQ[i];
420
421 memcpy (old_val_CORE, new_val_CORE, sizeof (unsigned long int) * numCPUs);
422 memcpy (old_val_REF, new_val_REF, sizeof (unsigned long int) * numCPUs);
423 memcpy (old_val_C3, new_val_C3, sizeof (unsigned long int) * numCPUs);
424 memcpy (old_val_C6, new_val_C6, sizeof (unsigned long int) * numCPUs);
425 memcpy (tvstart, tvstop, sizeof (struct timeval) * numCPUs);
426 memcpy (old_TSC, new_TSC, sizeof (unsigned long long int) * numCPUs);
427
428 memcpy (FREQ, _FREQ, sizeof (double) * numCPUs);
429 memcpy (MULT, _MULT, sizeof (double) * numCPUs);
430 memcpy (C0_TIME, C0_time, sizeof (long double) * numCPUs);
431 memcpy (C1_TIME, C1_time, sizeof (long double) * numCPUs);
432 memcpy (C3_TIME, C3_time, sizeof (long double) * numCPUs);
433 memcpy (C6_TIME, C6_time, sizeof (long double) * numCPUs);
434 global_in_i7z_main_thread = true;
435 }
436
437 }
438
439 class MyWidget:public QWidget
440 {
441 Q_OBJECT public:
442 QProgressBar * C0_l[MAX_PROCESSORS_GUI], *C1_l[MAX_PROCESSORS_GUI], *C3_l[MAX_PROCESSORS_GUI], *C6_l[MAX_PROCESSORS_GUI];
443 QLabel *C0, *C1, *C3, *C6;
444 QLabel *Freq_[MAX_PROCESSORS_GUI];
445 QLabel *StatusMessage0, *StatusMessage1, *Curr_Freq0, *Curr_Freq1;
446 QLabel *ProcNames[MAX_PROCESSORS_GUI];
447 MyWidget (QWidget * parent = 0);
448 MyThread *mythread;
449 int curr_numCPUs;
450
451 private slots:
452 void UpdateWidget ();
453 };
454
455 MyWidget::MyWidget (QWidget * parent):QWidget (parent)
456 {
457
458 Print_Version_Information();
459
460 //
461 //Print_Information_Processor ();
462 bool cpuNehalem, cpuSandybridge, cpuIvybridge, cpuHaswell;
463 Print_Information_Processor (&cpuNehalem, &cpuSandybridge, &cpuIvybridge, &cpuHaswell);
464
465 Test_Or_Make_MSR_DEVICE_FILES ();
466
467 Construct_Socket_Information_in_GUI(&numCPUs);
468
469 char processor_str[100];
470 // printf("MyWidget: Num Processors %d\n",numCPUs);
471 int i;
472
473 for (i = 0; i < (int)numCPUs; i++)
474 {
475 C0_l[i] = new QProgressBar;
476 C0_l[i]->setMaximum (99);
477 C0_l[i]->setMinimum (0);
478 C1_l[i] = new QProgressBar;
479 C1_l[i]->setMaximum (99);
480 C1_l[i]->setMinimum (0);
481 C3_l[i] = new QProgressBar;
482 C3_l[i]->setMaximum (99);
483 C3_l[i]->setMinimum (0);
484 C6_l[i] = new QProgressBar;
485 C6_l[i]->setMaximum (99);
486 C6_l[i]->setMinimum (0);
487 Freq_[i] = new QLabel (tr (""));
488 }
489
490 QGridLayout * layout1 = new QGridLayout;
491
492 curr_numCPUs = numCPUs;
493 for (i = 0; i < (int)numCPUs; i++)
494 {
495 layout1->addWidget (C0_l[i], i + 1, 1);
496 layout1->addWidget (C1_l[i], i + 1, 2);
497 layout1->addWidget (C3_l[i], i + 1, 3);
498 layout1->addWidget (C6_l[i], i + 1, 4);
499 }
500
501 C0 = new QLabel (tr ("C0"));
502 C0->setAlignment (Qt::AlignCenter);
503 C1 = new QLabel (tr ("C1"));
504 C1->setAlignment (Qt::AlignCenter);
505 C3 = new QLabel (tr ("C3"));
506 C3->setAlignment (Qt::AlignCenter);
507 C6 = new QLabel (tr ("C6"));
508 C6->setAlignment (Qt::AlignCenter);
509
510 snprintf(processor_str, 100, "Core-1 [id:%d,socket:%d]",core_list[0],socket_list[0]);
511 ProcNames[0] = new QLabel (tr (processor_str));
512
513 snprintf(processor_str, 100, "Core-2 [id:%d,socket:%d]",core_list[1],socket_list[1]);
514 ProcNames[1] = new QLabel (tr (processor_str));
515
516 snprintf(processor_str, 100, "Core-3 [id:%d,socket:%d]",core_list[2],socket_list[2]);
517 ProcNames[2] = new QLabel (tr (processor_str));
518
519 snprintf(processor_str, 100, "Core-4 [id:%d,socket:%d]",core_list[3],socket_list[3]);
520 ProcNames[3] = new QLabel (tr (processor_str));
521
522 snprintf(processor_str, 100, "Core-5 [id:%d,socket:%d]",core_list[4],socket_list[4]);
523 ProcNames[4] = new QLabel (tr (processor_str));
524
525 snprintf(processor_str, 100, "Core-6 [id:%d,socket:%d]",core_list[5],socket_list[5]);
526 ProcNames[5] = new QLabel (tr (processor_str));
527
528 snprintf(processor_str, 100, "Core-7 [id:%d,socket:%d]",core_list[6],socket_list[6]);
529 ProcNames[6] = new QLabel (tr (processor_str));
530
531 snprintf(processor_str, 100, "Core-8 [id:%d,socket:%d]",core_list[7],socket_list[7]);
532 ProcNames[7] = new QLabel (tr (processor_str));
533
534 snprintf(processor_str, 100, "Core-9 [id:%d,socket:%d]",core_list[8],socket_list[8]);
535 ProcNames[8] = new QLabel (tr (processor_str));
536
537 snprintf(processor_str, 100, "Core-10 [id:%d,socket:%d]",core_list[9],socket_list[9]);
538 ProcNames[9] = new QLabel (tr (processor_str));
539
540 snprintf(processor_str, 100, "Core-11 [id:%d,socket:%d]",core_list[10],socket_list[10]);
541 ProcNames[10] = new QLabel (tr (processor_str));
542
543 snprintf(processor_str, 100, "Core-12 [id:%d,socket:%d]",core_list[11],socket_list[11]);
544 ProcNames[11] = new QLabel (tr (processor_str));
545
546 StatusMessage0 = new QLabel (tr ("Wait"));
547 Curr_Freq0 = new QLabel (tr ("Wait"));
548
549 if ( (socket_0.num_physical_cores > 0) && (socket_1.num_physical_cores > 0)) {
550 StatusMessage1 = new QLabel (tr ("Wait"));
551 Curr_Freq1 = new QLabel (tr ("Wait"));
552 }
553
554 for (i = 0; i < (int)numCPUs; i++) {
555 layout1->addWidget (ProcNames[i], i + 1, 0);
556 }
557
558 layout1->addWidget (C0, 0, 1);
559 layout1->addWidget (C1, 0, 2);
560 layout1->addWidget (C3, 0, 3);
561 layout1->addWidget (C6, 0, 4);
562
563 for (i = 0; i < (int)numCPUs; i++)
564 layout1->addWidget (Freq_[i], i + 1, 5);
565
566 layout1->addWidget (StatusMessage0, numCPUs + 1, 4);
567 layout1->addWidget (Curr_Freq0, numCPUs + 1, 5);
568 if ( (socket_0.num_physical_cores > 0) && (socket_1.num_physical_cores > 0)) {
569 layout1->addWidget (StatusMessage1, numCPUs + 2, 4);
570 layout1->addWidget (Curr_Freq1, numCPUs + 2, 5);
571 }
572 QTimer *timer = new QTimer (this);
573 connect (timer, SIGNAL (timeout ()), this, SLOT (UpdateWidget ()));
574 timer->start (1000);
575
576 mythread = new MyThread ();
577 mythread->start ();
578
579 setLayout (layout1);
580 }
581
582 void
583 MyWidget::UpdateWidget ()
584 {
585 char processor_str[100];
586 snprintf(processor_str, 100, "Core-1 [id:%d,socket:%d]",core_list[0],socket_list[0]);
587 ProcNames[0]->setText(tr (processor_str));
588 snprintf(processor_str, 100, "Core-2 [id:%d,socket:%d]",core_list[1],socket_list[1]);
589 ProcNames[1]->setText(tr (processor_str));
590 snprintf(processor_str, 100, "Core-3 [id:%d,socket:%d]",core_list[2],socket_list[2]);
591 ProcNames[2]->setText(tr (processor_str));
592 snprintf(processor_str, 100, "Core-4 [id:%d,socket:%d]",core_list[3],socket_list[3]);
593 ProcNames[3]->setText(tr (processor_str));
594 snprintf(processor_str, 100, "Core-5 [id:%d,socket:%d]",core_list[4],socket_list[4]);
595 ProcNames[4]->setText(tr (processor_str));
596 snprintf(processor_str, 100, "Core-6 [id:%d,socket:%d]",core_list[5],socket_list[5]);
597 ProcNames[5]->setText(tr (processor_str));
598 snprintf(processor_str, 100, "Core-7 [id:%d,socket:%d]",core_list[6],socket_list[6]);
599 ProcNames[6]->setText(tr (processor_str));
600 snprintf(processor_str, 100, "Core-8 [id:%d,socket:%d]",core_list[7],socket_list[7]);
601 ProcNames[7]->setText(tr (processor_str));
602 snprintf(processor_str, 100, "Core-9 [id:%d,socket:%d]",core_list[8],socket_list[8]);
603 ProcNames[8]->setText(tr (processor_str));
604 snprintf(processor_str, 100, "Core-10 [id:%d,socket:%d]",core_list[9],socket_list[9]);
605 ProcNames[9]->setText(tr (processor_str));
606 snprintf(processor_str, 100, "Core-11 [id:%d,socket:%d]",core_list[10],socket_list[10]);
607 ProcNames[10]->setText(tr (processor_str));
608 snprintf(processor_str, 100, "Core-12 [id:%d,socket:%d]",core_list[11],socket_list[11]);
609 ProcNames[11]->setText(tr (processor_str));
610
611 //Have to make sure that the constructor is being called correct.
612 //the below code logic is that if a core goes offline, call the constructor
613 //so as to replot all the widgets.
614 /* printf("Number of Cores %d\n",numCPUs);
615 if(numCPUs != curr_numCPUs){
616 curr_numCPUs = numCPUs;
617 printf("Number of Cores changed\n");
618 MyWidget (0);
619 }*/
620
621 // printf("UpdateWidget: Num Processors %d\n",numCPUs);
622 int i;
623 char val2set[100];
624 for (i = 0; i < (int)numCPUs; i++)
625 {
626 snprintf (val2set, 100, "%0.2f Mhz", mythread->FREQ[i]);
627 Freq_[i]->setText (val2set);
628 }
629
630 for (i = 0; i < (int)numCPUs; i++)
631 {
632 C0_l[i]->setValue (mythread->C0_TIME[i] * 100);
633 C1_l[i]->setValue (mythread->C1_TIME[i] * 100);
634 C3_l[i]->setValue (mythread->C3_TIME[i] * 100);
635 C6_l[i]->setValue (mythread->C6_TIME[i] * 100);
636 }
637
638 float Max_Freq_socket0 = 0;
639 float Max_Freq_socket1 = 0;
640 int num_socket0_cpus, num_socket1_cpus;
641
642 for (i = 0; i < (int)numCPUs; i++)
643 {
644 if ( (mythread->FREQ[i] > Max_Freq_socket0) && (!isnan(mythread->FREQ[i])) &&
645 (!isinf(mythread->FREQ[i])) && (socket_list[i] == socket_0.socket_num) ) {
646 Max_Freq_socket0 = mythread->FREQ[i];
647 num_socket0_cpus++;
648 }
649 if ( (mythread->FREQ[i] > Max_Freq_socket1) && (!isnan(mythread->FREQ[i])) &&
650 (!isinf(mythread->FREQ[i])) && (socket_list[i] == socket_1.socket_num) ) {
651 Max_Freq_socket1 = mythread->FREQ[i];
652 num_socket1_cpus++;
653 }
654 }
655 if (socket_0.num_physical_cores > 0) {
656 StatusMessage0->setText ("Socket[0] Freq:");
657 snprintf (val2set, 100, "%0.2f Mhz", Max_Freq_socket0);
658 Curr_Freq0->setText (val2set);
659 }
660 if (socket_1.num_physical_cores > 0) {
661 StatusMessage1->setText ("Socket[1] Freq:");
662 snprintf (val2set, 100, "%0.2f Mhz", Max_Freq_socket1);
663 Curr_Freq1->setText (val2set);
664 }
665 }
666
667
668
669 int
670 main (int argc, char *argv[])
671 {
672 char hostname[1024];
673 hostname[1023] = '\0';
674 gethostname(hostname, 1023);
675
676 QApplication app (argc, argv);
677
678 char str_display[1050];
679 snprintf(str_display, 1050, "i7z @ %s", hostname);
680 MyWidget i7z_widget;
681 i7z_widget.setWindowTitle(str_display);
682 i7z_widget.show ();
683 return app.exec ();
684 }
685
686 #include "i7z_GUI.moc"