Debian Codegraph @

GUI/i7z_GUI.cpp

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
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 ("cat /proc/cpuinfo |grep MHz|sed 's/cpu\\sMHz\\s*:\\s//'|tail -n 1 > /tmp/cpufreq.txt");
175 system ("grep \"core id\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numPhysical.txt");
176 system ("grep \"processor\" /proc/cpuinfo |sort -|uniq -|wc -l > /tmp/numLogical.txt");
177
178
179 //Open the parsed cpufreq file and obtain the cpufreq from /proc/cpuinfo
180 FILE *tmp_file;
181 tmp_file = fopen ("/tmp/cpufreq.txt", "r");
182 char tmp_str[30];
183 fgets (tmp_str, 30, tmp_file);
184 double cpu_freq_cpuinfo = atof (tmp_str);
185 fclose (tmp_file);
186
187 unsigned int numPhysicalCores, numLogicalCores;
188 numPhysicalCores = socket_0.num_physical_cores + socket_1.num_physical_cores;
189 numLogicalCores = socket_0.num_logical_cores + socket_1.num_logical_cores;
190 // printf("My thread: Num Processors %d\n",numCPUs);
191
192 int error_indx;
193
194 //estimate the freq using the estimate_MHz() code that is almost mhz accurate
195 cpu_freq_cpuinfo = estimate_MHz ();
196
197 //We just need one CPU (we use Core-0) to figure out the multiplier and the bus clock freq.
198 CPU_NUM = 0;
199 CPU_Multiplier =
200 get_msr_value (CPU_NUM, PLATFORM_INFO_MSR, PLATFORM_INFO_MSR_high,
201 PLATFORM_INFO_MSR_low, &error_indx);
202 BLCK = cpu_freq_cpuinfo / CPU_Multiplier;
203 TURBO_MODE = turbo_status (); //get_msr_value(CPU_NUM,IA32_MISC_ENABLE, TURBO_FLAG_high,TURBO_FLAG_low);
204
205 //to find how many cpus are enabled, we could have used sysconf but that will just give the logical numbers
206 //if HT is enabled then the threads of the same core have the same C-state residency number so...
207 //Its imperative to figure out the number of physical and number of logical cores.
208 //sysconf(_SC_NPROCESSORS_ONLN);
209
210
211 bool HT_ON;
212 char HT_ON_str[30];
213 if (numLogicalCores > numPhysicalCores)
214 {
215 strcpy (HT_ON_str, "Hyper Threading ON");
216 HT_ON = true;
217 }
218 else
219 {
220 strcpy (HT_ON_str, "Hyper Threading OFF");
221 HT_ON = false;
222 }
223
224 float TRUE_CPU_FREQ;
225 if (TURBO_MODE == 1)
226 {
227 TRUE_CPU_FREQ = BLCK * ((double)CPU_Multiplier + 1);
228 }
229 else
230 {
231 TRUE_CPU_FREQ = BLCK * ((double)CPU_Multiplier);
232 }
233
234
235 int IA32_PERF_GLOBAL_CTRL = 911; //3BF
236 int IA32_PERF_GLOBAL_CTRL_Value =
237 get_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 63, 0,&error_indx);
238 int IA32_FIXED_CTR_CTL = 909; //38D
239 int IA32_FIXED_CTR_CTL_Value =
240 get_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 63, 0,&error_indx);
241
242 //printf("IA32_PERF_GLOBAL_CTRL %d\n",IA32_PERF_GLOBAL_CTRL_Value);
243 //printf("IA32_FIXED_CTR_CTL %d\n",IA32_FIXED_CTR_CTL_Value);
244
245 unsigned long long int CPU_CLK_UNHALTED_CORE, CPU_CLK_UNHALTED_REF,
246 CPU_CLK_C3, CPU_CLK_C6, CPU_CLK_C1;
247
248 CPU_CLK_UNHALTED_CORE = get_msr_value (CPU_NUM, 778, 63, 0,&error_indx);
249 CPU_CLK_UNHALTED_REF = get_msr_value (CPU_NUM, 779, 63, 0,&error_indx);
250
251 unsigned long long int old_val_CORE[numCPUs], new_val_CORE[numCPUs];
252 unsigned long long int old_val_REF[numCPUs], new_val_REF[numCPUs];
253 unsigned long long int old_val_C3[numCPUs], new_val_C3[numCPUs];
254 unsigned long long int old_val_C6[numCPUs], new_val_C6[numCPUs];
255 // unsigned long int old_val_C1[numCPUs], new_val_C1[numCPUs];
256
257 unsigned long long int old_TSC[numCPUs], new_TSC[numCPUs];
258
259 struct timeval tvstart[numCPUs], tvstop[numCPUs];
260
261 struct timespec one_second_sleep;
262 one_second_sleep.tv_sec = 0;
263 one_second_sleep.tv_nsec = 999999999; // 1000msec
264
265
266 unsigned long int IA32_MPERF = get_msr_value (CPU_NUM, 231, 7, 0,&error_indx);
267 unsigned long int IA32_APERF = get_msr_value (CPU_NUM, 232, 7, 0,&error_indx);
268 // mvprintw(12,0,"Wait...\n"); refresh();
269 nanosleep (&one_second_sleep, NULL);
270 IA32_MPERF = get_msr_value (CPU_NUM, 231, 7, 0, &error_indx) - IA32_MPERF;
271 IA32_APERF = get_msr_value (CPU_NUM, 232, 7, 0, &error_indx) - IA32_APERF;
272
273 //printf("Diff. i n APERF = %u, MPERF = %d\n", IA32_MPERF, IA32_APERF);
274
275 long double C0_time[numCPUs], C1_time[numCPUs], C3_time[numCPUs], C6_time[numCPUs];
276 double _FREQ[numCPUs], _MULT[numCPUs];
277
278 // mvprintw(12,0,"Current Freqs\n");
279
280 int kk=11;
281 double estimated_mhz;
282 for (;;)
283 {
284 Construct_Socket_Information_in_GUI(&numCPUs);
285
286 if (kk>10) {
287 kk=0;
288 for (ii = 0; ii < (int)numCPUs; ii++)
289 {
290 CPU_NUM = core_list[ii];
291 IA32_PERF_GLOBAL_CTRL_Value = get_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 63, 0, &error_indx);
292 set_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 0x700000003LLU);
293
294 IA32_FIXED_CTR_CTL_Value = get_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 63, 0, &error_indx);
295 set_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 819);
296
297 IA32_PERF_GLOBAL_CTRL_Value = get_msr_value (CPU_NUM, IA32_PERF_GLOBAL_CTRL, 63, 0, &error_indx);
298 IA32_FIXED_CTR_CTL_Value = get_msr_value (CPU_NUM, IA32_FIXED_CTR_CTL, 63, 0, &error_indx);
299
300 old_val_CORE[ii] = get_msr_value (CPU_NUM, 778, 63, 0,&error_indx);
301 old_val_REF[ii] = get_msr_value (CPU_NUM, 779, 63, 0,&error_indx);
302 old_val_C3[ii] = get_msr_value (CPU_NUM, 1020, 63, 0,&error_indx);
303 old_val_C6[ii] = get_msr_value (CPU_NUM, 1021, 63, 0,&error_indx);
304 old_TSC[ii] = rdtsc ();
305 }
306 }
307 kk++;
308
309 nanosleep (&one_second_sleep, NULL);
310
311 estimated_mhz = estimate_MHz();
312
313 for (i = 0; i < (int)numCPUs; i++)
314 {
315 CPU_NUM = core_list[i];
316 new_val_CORE[i] = get_msr_value (CPU_NUM, 778, 63, 0,&error_indx);
317 new_val_REF[i] = get_msr_value (CPU_NUM, 779, 63, 0,&error_indx);
318 new_val_C3[i] = get_msr_value (CPU_NUM, 1020, 63, 0,&error_indx);
319 new_val_C6[i] = get_msr_value (CPU_NUM, 1021, 63, 0,&error_indx);
320 new_TSC[i] = rdtsc ();
321 if (old_val_CORE[i] > new_val_CORE[i])
322 {
323 CPU_CLK_UNHALTED_CORE =
324 (3.40282366921e38 - old_val_CORE[i]) + new_val_CORE[i];
325 }
326 else
327 {
328 CPU_CLK_UNHALTED_CORE = new_val_CORE[i] - old_val_CORE[i];
329 }
330
331 //number of TSC cycles while its in halted state
332 if ((new_TSC[i] - old_TSC[i]) < CPU_CLK_UNHALTED_CORE)
333 CPU_CLK_C1 = 0;
334 else
335 CPU_CLK_C1 = ((new_TSC[i] - old_TSC[i]) - CPU_CLK_UNHALTED_CORE);
336
337 if (old_val_REF[i] > new_val_REF[i])
338 {
339 CPU_CLK_UNHALTED_REF =
340 (3.40282366921e38 - old_val_REF[i]) + new_val_REF[i];
341 }
342 else
343 {
344 CPU_CLK_UNHALTED_REF = new_val_REF[i] - old_val_REF[i];
345 }
346
347 if (old_val_C3[i] > new_val_C3[i])
348 {
349 CPU_CLK_C3 = (3.40282366921e38 - old_val_C3[i]) + new_val_C3[i];
350 }
351 else
352 {
353 CPU_CLK_C3 = new_val_C3[i] - old_val_C3[i];
354 }
355
356 if (old_val_C6[i] > new_val_C6[i])
357 {
358 CPU_CLK_C6 = (3.40282366921e38 - old_val_C6[i]) + new_val_C6[i];
359 }
360 else
361 {
362 CPU_CLK_C6 = new_val_C6[i] - old_val_C6[i];
363 }
364
365 _FREQ[i] =
366 estimated_mhz * ((long double) CPU_CLK_UNHALTED_CORE /
367 (long double) CPU_CLK_UNHALTED_REF);
368 _MULT[i] = _FREQ[i] / BLCK;
369
370 C0_time[i] =
371 ((long double) CPU_CLK_UNHALTED_REF /
372 (long double) (new_TSC[i] - old_TSC[i]));
373 long double c1_time =
374 ((long double) CPU_CLK_C1 /
375 (long double) (new_TSC[i] - old_TSC[i]));
376 C3_time[i] =
377 ((long double) CPU_CLK_C3 /
378 (long double) (new_TSC[i] - old_TSC[i]));
379 C6_time[i] =
380 ((long double) CPU_CLK_C6 /
381 (long double) (new_TSC[i] - old_TSC[i]));
382
383 //C1_time[i] -= C3_time[i] + C6_time[i];
384 C1_time[i] = c1_time - (C3_time[i] + C6_time[i]) ;
385 if (!isnan(c1_time) && !isinf(c1_time)) {
386 if (C1_time[i] <= 0) {
387 C1_time[i]=0;
388 }
389 }
390
391 if (C0_time[i] < 1e-2) {
392 if (C0_time[i] > 1e-4) C0_time[i] = 0.01;
393 else C0_time[i] = 0;
394 }
395
396 if (C1_time[i] < 1e-2) {
397 if (C1_time[i] > 1e-4) C1_time[i] = 0.01;
398 else C1_time[i] = 0;
399 }
400
401 if (C3_time[i] < 1e-2) {
402 if (C3_time[i] > 1e-4) C3_time[i] = 0.01;
403 else C3_time[i] = 0;
404 }
405
406 if (C6_time[i] < 1e-2) {
407 if (C6_time[i] > 1e-4) C6_time[i] = 0.01;
408 else C6_time[i] = 0;
409 }
410 }
411 // printf("Hello");
412 // for(i=0;i<numCPUs;i++){
413 // 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]));
414 // 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]));
415 // printf("%llu %llu %lld\n",new_TSC[i], old_TSC[i],new_TSC[i]- old_TSC[i]);
416 // }
417 TRUE_CPU_FREQ = 0;
418 for (i = 0; i < (int)numCPUs; i++)
419 if (_FREQ[i] > TRUE_CPU_FREQ)
420 TRUE_CPU_FREQ = _FREQ[i];
421
422 memcpy (old_val_CORE, new_val_CORE, sizeof (unsigned long int) * numCPUs);
423 memcpy (old_val_REF, new_val_REF, sizeof (unsigned long int) * numCPUs);
424 memcpy (old_val_C3, new_val_C3, sizeof (unsigned long int) * numCPUs);
425 memcpy (old_val_C6, new_val_C6, sizeof (unsigned long int) * numCPUs);
426 memcpy (tvstart, tvstop, sizeof (struct timeval) * numCPUs);
427 memcpy (old_TSC, new_TSC, sizeof (unsigned long long int) * numCPUs);
428
429 memcpy (FREQ, _FREQ, sizeof (double) * numCPUs);
430 memcpy (MULT, _MULT, sizeof (double) * numCPUs);
431 memcpy (C0_TIME, C0_time, sizeof (long double) * numCPUs);
432 memcpy (C1_TIME, C1_time, sizeof (long double) * numCPUs);
433 memcpy (C3_TIME, C3_time, sizeof (long double) * numCPUs);
434 memcpy (C6_TIME, C6_time, sizeof (long double) * numCPUs);
435 global_in_i7z_main_thread = true;
436 }
437
438 }
439
440 class MyWidget:public QWidget
441 {
442 Q_OBJECT public:
443 QProgressBar * C0_l[MAX_PROCESSORS_GUI], *C1_l[MAX_PROCESSORS_GUI], *C3_l[MAX_PROCESSORS_GUI], *C6_l[MAX_PROCESSORS_GUI];
444 QLabel *C0, *C1, *C3, *C6;
445 QLabel *Freq_[MAX_PROCESSORS_GUI];
446 QLabel *StatusMessage0, *StatusMessage1, *Curr_Freq0, *Curr_Freq1;
447 QLabel *ProcNames[MAX_PROCESSORS_GUI];
448 MyWidget (QWidget * parent = 0);
449 MyThread *mythread;
450 int curr_numCPUs;
451
452 private slots:
453 void UpdateWidget ();
454 };
455
456 MyWidget::MyWidget (QWidget * parent):QWidget (parent)
457 {
458
459 Print_Version_Information();
460
461 //
462 //Print_Information_Processor ();
463 bool cpuNehalem, cpuSandybridge, cpuIvybridge, cpuHaswell;
464 Print_Information_Processor (&cpuNehalem, &cpuSandybridge, &cpuIvybridge, &cpuHaswell);
465
466 Test_Or_Make_MSR_DEVICE_FILES ();
467
468 Construct_Socket_Information_in_GUI(&numCPUs);
469
470 char processor_str[100];
471 // printf("MyWidget: Num Processors %d\n",numCPUs);
472 int i;
473
474 for (i = 0; i < (int)numCPUs; i++)
475 {
476 C0_l[i] = new QProgressBar;
477 C0_l[i]->setMaximum (99);
478 C0_l[i]->setMinimum (0);
479 C1_l[i] = new QProgressBar;
480 C1_l[i]->setMaximum (99);
481 C1_l[i]->setMinimum (0);
482 C3_l[i] = new QProgressBar;
483 C3_l[i]->setMaximum (99);
484 C3_l[i]->setMinimum (0);
485 C6_l[i] = new QProgressBar;
486 C6_l[i]->setMaximum (99);
487 C6_l[i]->setMinimum (0);
488 Freq_[i] = new QLabel (tr (""));
489 }
490
491 QGridLayout * layout1 = new QGridLayout;
492
493 curr_numCPUs = numCPUs;
494 for (i = 0; i < (int)numCPUs; i++)
495 {
496 layout1->addWidget (C0_l[i], i + 1, 1);
497 layout1->addWidget (C1_l[i], i + 1, 2);
498 layout1->addWidget (C3_l[i], i + 1, 3);
499 layout1->addWidget (C6_l[i], i + 1, 4);
500 }
501
502 C0 = new QLabel (tr ("C0"));
503 C0->setAlignment (Qt::AlignCenter);
504 C1 = new QLabel (tr ("C1"));
505 C1->setAlignment (Qt::AlignCenter);
506 C3 = new QLabel (tr ("C3"));
507 C3->setAlignment (Qt::AlignCenter);
508 C6 = new QLabel (tr ("C6"));
509 C6->setAlignment (Qt::AlignCenter);
510
511 snprintf(processor_str, 100, "Core-1 [id:%d,socket:%d]",core_list[0],socket_list[0]);
512 ProcNames[0] = new QLabel (tr (processor_str));
513
514 snprintf(processor_str, 100, "Core-2 [id:%d,socket:%d]",core_list[1],socket_list[1]);
515 ProcNames[1] = new QLabel (tr (processor_str));
516
517 snprintf(processor_str, 100, "Core-3 [id:%d,socket:%d]",core_list[2],socket_list[2]);
518 ProcNames[2] = new QLabel (tr (processor_str));
519
520 snprintf(processor_str, 100, "Core-4 [id:%d,socket:%d]",core_list[3],socket_list[3]);
521 ProcNames[3] = new QLabel (tr (processor_str));
522
523 snprintf(processor_str, 100, "Core-5 [id:%d,socket:%d]",core_list[4],socket_list[4]);
524 ProcNames[4] = new QLabel (tr (processor_str));
525
526 snprintf(processor_str, 100, "Core-6 [id:%d,socket:%d]",core_list[5],socket_list[5]);
527 ProcNames[5] = new QLabel (tr (processor_str));
528
529 snprintf(processor_str, 100, "Core-7 [id:%d,socket:%d]",core_list[6],socket_list[6]);
530 ProcNames[6] = new QLabel (tr (processor_str));
531
532 snprintf(processor_str, 100, "Core-8 [id:%d,socket:%d]",core_list[7],socket_list[7]);
533 ProcNames[7] = new QLabel (tr (processor_str));
534
535 snprintf(processor_str, 100, "Core-9 [id:%d,socket:%d]",core_list[8],socket_list[8]);
536 ProcNames[8] = new QLabel (tr (processor_str));
537
538 snprintf(processor_str, 100, "Core-10 [id:%d,socket:%d]",core_list[9],socket_list[9]);
539 ProcNames[9] = new QLabel (tr (processor_str));
540
541 snprintf(processor_str, 100, "Core-11 [id:%d,socket:%d]",core_list[10],socket_list[10]);
542 ProcNames[10] = new QLabel (tr (processor_str));
543
544 snprintf(processor_str, 100, "Core-12 [id:%d,socket:%d]",core_list[11],socket_list[11]);
545 ProcNames[11] = new QLabel (tr (processor_str));
546
547 StatusMessage0 = new QLabel (tr ("Wait"));
548 Curr_Freq0 = new QLabel (tr ("Wait"));
549
550 if ( (socket_0.num_physical_cores > 0) && (socket_1.num_physical_cores > 0)) {
551 StatusMessage1 = new QLabel (tr ("Wait"));
552 Curr_Freq1 = new QLabel (tr ("Wait"));
553 }
554
555 for (i = 0; i < (int)numCPUs; i++) {
556 layout1->addWidget (ProcNames[i], i + 1, 0);
557 }
558
559 layout1->addWidget (C0, 0, 1);
560 layout1->addWidget (C1, 0, 2);
561 layout1->addWidget (C3, 0, 3);
562 layout1->addWidget (C6, 0, 4);
563
564 for (i = 0; i < (int)numCPUs; i++)
565 layout1->addWidget (Freq_[i], i + 1, 5);
566
567 layout1->addWidget (StatusMessage0, numCPUs + 1, 4);
568 layout1->addWidget (Curr_Freq0, numCPUs + 1, 5);
569 if ( (socket_0.num_physical_cores > 0) && (socket_1.num_physical_cores > 0)) {
570 layout1->addWidget (StatusMessage1, numCPUs + 2, 4);
571 layout1->addWidget (Curr_Freq1, numCPUs + 2, 5);
572 }
573 QTimer *timer = new QTimer (this);
574 connect (timer, SIGNAL (timeout ()), this, SLOT (UpdateWidget ()));
575 timer->start (1000);
576
577 mythread = new MyThread ();
578 mythread->start ();
579
580 setLayout (layout1);
581 }
582
583 void
584 MyWidget::UpdateWidget ()
585 {
586 char processor_str[100];
587 snprintf(processor_str, 100, "Core-1 [id:%d,socket:%d]",core_list[0],socket_list[0]);
588 ProcNames[0]->setText(tr (processor_str));
589 snprintf(processor_str, 100, "Core-2 [id:%d,socket:%d]",core_list[1],socket_list[1]);
590 ProcNames[1]->setText(tr (processor_str));
591 snprintf(processor_str, 100, "Core-3 [id:%d,socket:%d]",core_list[2],socket_list[2]);
592 ProcNames[2]->setText(tr (processor_str));
593 snprintf(processor_str, 100, "Core-4 [id:%d,socket:%d]",core_list[3],socket_list[3]);
594 ProcNames[3]->setText(tr (processor_str));
595 snprintf(processor_str, 100, "Core-5 [id:%d,socket:%d]",core_list[4],socket_list[4]);
596 ProcNames[4]->setText(tr (processor_str));
597 snprintf(processor_str, 100, "Core-6 [id:%d,socket:%d]",core_list[5],socket_list[5]);
598 ProcNames[5]->setText(tr (processor_str));
599 snprintf(processor_str, 100, "Core-7 [id:%d,socket:%d]",core_list[6],socket_list[6]);
600 ProcNames[6]->setText(tr (processor_str));
601 snprintf(processor_str, 100, "Core-8 [id:%d,socket:%d]",core_list[7],socket_list[7]);
602 ProcNames[7]->setText(tr (processor_str));
603 snprintf(processor_str, 100, "Core-9 [id:%d,socket:%d]",core_list[8],socket_list[8]);
604 ProcNames[8]->setText(tr (processor_str));
605 snprintf(processor_str, 100, "Core-10 [id:%d,socket:%d]",core_list[9],socket_list[9]);
606 ProcNames[9]->setText(tr (processor_str));
607 snprintf(processor_str, 100, "Core-11 [id:%d,socket:%d]",core_list[10],socket_list[10]);
608 ProcNames[10]->setText(tr (processor_str));
609 snprintf(processor_str, 100, "Core-12 [id:%d,socket:%d]",core_list[11],socket_list[11]);
610 ProcNames[11]->setText(tr (processor_str));
611
612 //Have to make sure that the constructor is being called correct.
613 //the below code logic is that if a core goes offline, call the constructor
614 //so as to replot all the widgets.
615 /* printf("Number of Cores %d\n",numCPUs);
616 if(numCPUs != curr_numCPUs){
617 curr_numCPUs = numCPUs;
618 printf("Number of Cores changed\n");
619 MyWidget (0);
620 }*/
621
622 // printf("UpdateWidget: Num Processors %d\n",numCPUs);
623 int i;
624 char val2set[100];
625 for (i = 0; i < (int)numCPUs; i++)
626 {
627 snprintf (val2set, 100, "%0.2f Mhz", mythread->FREQ[i]);
628 Freq_[i]->setText (val2set);
629 }
630
631 for (i = 0; i < (int)numCPUs; i++)
632 {
633 C0_l[i]->setValue (mythread->C0_TIME[i] * 100);
634 C1_l[i]->setValue (mythread->C1_TIME[i] * 100);
635 C3_l[i]->setValue (mythread->C3_TIME[i] * 100);
636 C6_l[i]->setValue (mythread->C6_TIME[i] * 100);
637 }
638
639 float Max_Freq_socket0 = 0;
640 float Max_Freq_socket1 = 0;
641 int num_socket0_cpus, num_socket1_cpus;
642
643 for (i = 0; i < (int)numCPUs; i++)
644 {
645 if ( (mythread->FREQ[i] > Max_Freq_socket0) && (!isnan(mythread->FREQ[i])) &&
646 (!isinf(mythread->FREQ[i])) && (socket_list[i] == socket_0.socket_num) ) {
647 Max_Freq_socket0 = mythread->FREQ[i];
648 num_socket0_cpus++;
649 }
650 if ( (mythread->FREQ[i] > Max_Freq_socket1) && (!isnan(mythread->FREQ[i])) &&
651 (!isinf(mythread->FREQ[i])) && (socket_list[i] == socket_1.socket_num) ) {
652 Max_Freq_socket1 = mythread->FREQ[i];
653 num_socket1_cpus++;
654 }
655 }
656 if (socket_0.num_physical_cores > 0) {
657 StatusMessage0->setText ("Socket[0] Freq:");
658 snprintf (val2set, 100, "%0.2f Mhz", Max_Freq_socket0);
659 Curr_Freq0->setText (val2set);
660 }
661 if (socket_1.num_physical_cores > 0) {
662 StatusMessage1->setText ("Socket[1] Freq:");
663 snprintf (val2set, 100, "%0.2f Mhz", Max_Freq_socket1);
664 Curr_Freq1->setText (val2set);
665 }
666 }
667
668
669
670 int
671 main (int argc, char *argv[])
672 {
673 char hostname[1024];
674 hostname[1023] = '\0';
675 gethostname(hostname, 1023);
676
677 QApplication app (argc, argv);
678
679 char str_display[1050];
680 snprintf(str_display, 1050, "i7z @ %s", hostname);
681 MyWidget i7z_widget;
682 i7z_widget.setWindowTitle(str_display);
683 i7z_widget.show ();
684 return app.exec ();
685 }
686
687 #include "i7z_GUI.moc"