Debian Codegraph @

perfmon-i7z/perfmon-i7z.cpp

raw
1 //i7z.c
2 /* ----------------------------------------------------------------------- *
3 *
4 * Copyright 2009 Abhishek Jaiantilal
5 *
6 * Under GPL v2
7 *
8 * ----------------------------------------------------------------------- */
9
10 #include <memory.h>
11 #include <errno.h>
12 #include <stdio.h>
13 #include <fcntl.h>
14 #include <unistd.h>
15 #include <stdlib.h>
16 #include <getopt.h>
17 #include <inttypes.h>
18 #include <sys/types.h>
19 #include <sys/time.h>
20 #include <time.h>
21 #include <ncurses.h>
22 #include <math.h>
23 #include <ctype.h>
24 #include <pthread.h>
25
26 #include "perfmon-i7z.h"
27 //#include "CPUHeirarchy.h"
28
29 #define CPU_FREQUENCY 3291 //this is in mhz
30
31 int Single_Socket();
32 int Dual_Socket();
33
34 int numPhysicalCores, numLogicalCores;
35 double TRUE_CPU_FREQ;
36
37 #define IA32_THERM_STATUS 0x19C
38 #define IA32_TEMPERATURE_TARGET 0x1a2
39
40 //Info: I start from index 1 when i talk about cores on CPU
41
42 //Monitoring Version - 1
43 //4 events at most can be monitored
44 //put in the value in PERFEVTSEL and the counts are in PMC
45 #define IA32_PERFEVTSEL0 0x186
46 #define IA32_PERFEVTSEL1 0x187
47 #define IA32_PERFEVTSEL2 0x188
48 #define IA32_PERFEVTSEL3 0x189
49 #define IA32_PMC0 0x0C1
50 #define IA32_PMC1 0x0C2
51 #define IA32_PMC2 0x0C3
52 #define IA32_PMC3 0x0C4
53
54 //Monitoring Version - 2
55 //Another 3 events can be then monitored in IA32_FIXED_CTR0 to CTR2
56 #define IA32_FIXED_CTR_CTL 0x38D
57 #define IA32_PERF_GLOBAL_CTRL 0x38F
58 #define IA32_FIXED_CTR0 0x309 //Instruction_Retired.Any
59 #define IA32_FIXED_CTR1 0x30A //CPU_CLK_Unhalted.Core
60 #define IA32_FIXED_CTR2 0x30B //CPU_CLK_Unhalted.Ref
61
62 //Performance event number and umask value
63 #define MEM_INST_RETIRED_LOADS_EVENT 0x0B
64 #define MEM_INST_RETIRED_LOADS_UMASK 0x01
65 #define MEM_INST_RETIRED_LOADS 0x010B
66
67 #define MEM_INST_RETIRED_STORES_EVENT 0x0B
68 #define MEM_INST_RETIRED_STORES_UMASK 0x02
69 #define MEM_INST_RETIRED_STORES 0x020B
70
71 #define FP_COMP_OPS_EXE_X87_EVENT 0x10
72 #define FP_COMP_OPS_EXE_X87_UMASK 0x01
73 #define FP_COMP_OPS_EXE_X87 0x0110
74
75 #define FP_COMP_OPS_EXE_SSE_FP_EVENT 0x10
76 #define FP_COMP_OPS_EXE_SSE_FP_UMASK 0x04
77 #define FP_COMP_OPS_EXE_SSE_FP 0x0410
78
79 #define MAX_PROCESSORS_SYSTEM 4
80
81 int error_indx;
82
83 struct therm_status_struct {
84 int reading_valid;
85 int resolution_deg_celcius;
86 int digital_readout;
87 int power_limit_notification_status;
88 int power_limit_notification_log;
89 int thermal_threshold_2_log;
90 int thermal_threshold_2_status;
91 int thermal_threshold_1_log;
92 int thermal_threshold_1_status;
93 int critical_temperature_log;
94 int critical_temperature_status;
95 int PROCHOT_log;
96 int PROCHOT_event;
97 int thermal_status_log;
98 int thermal_status;
99
100 int PROCHOT_temp; //Tj
101 int current_core_temp; //PROCHOT_temp - digital_readout
102 };
103
104 int Get_Bits_Value(unsigned long val, int highbit, int lowbit)
105 {
106 unsigned long data = val;
107 int bits = highbit - lowbit + 1;
108 if (bits < 64) {
109 data >>= lowbit;
110 data &= (1ULL << bits) - 1;
111 }
112 return (data);
113 }
114
115 void Print_Thermal_Status(struct therm_status_struct therm_status)
116 {
117 printf("Reading Valid: %d\n", therm_status.reading_valid);
118 printf("Deg Celcius: %d\n", therm_status.resolution_deg_celcius);
119 printf("Digital Readout: %d\n", therm_status.digital_readout);
120 printf("Tj: %d\n", therm_status.PROCHOT_temp);
121 printf("Current Temp: %d\n", therm_status.current_core_temp);
122 }
123
124 void Read_Thermal_Status(struct therm_status_struct *therm_status)
125 {
126 unsigned long val =
127 get_msr_value(0, IA32_THERM_STATUS, 63, 0, &error_indx);
128 therm_status->reading_valid = Get_Bits_Value(val, 32, 31);
129 therm_status->resolution_deg_celcius = Get_Bits_Value(val, 31, 27);
130 therm_status->digital_readout = Get_Bits_Value(val, 23, 16);
131
132 val = get_msr_value(0, IA32_TEMPERATURE_TARGET, 63, 0, &error_indx);
133 therm_status->PROCHOT_temp = Get_Bits_Value(val, 24, 16);
134
135 therm_status->current_core_temp =
136 therm_status->PROCHOT_temp - therm_status->digital_readout;
137 }
138
139 unsigned long Read_instruction_retired_any(int cpu)
140 {
141 return (get_msr_value(cpu, IA32_FIXED_CTR0, 63, 0, &error_indx));
142 }
143
144 unsigned long Read_cpu_clk_unhalted_core(int cpu)
145 {
146 return (get_msr_value(cpu, IA32_FIXED_CTR1, 63, 0, &error_indx));
147 }
148
149 unsigned long Read_cpu_clk_unhalted_ref(int cpu)
150 {
151 return (get_msr_value(cpu, IA32_FIXED_CTR2, 63, 0, &error_indx));
152 }
153
154 //////////////PERFORMANCE COUNTER VERSION-1/////////////////////////////////////////////////////
155 void Set_MV1_Counters(int cpu, int pmc1, int pmc2, int pmc3, int pmc4)
156 {
157 int error_indx;
158 //pmc consists of 1byte of umask and 1byte of event select
159 //63 = 0110 0011 = enable counter,anythread,os mode and user mode
160 set_msr_value(cpu, IA32_PERFEVTSEL0, 0x430000 + pmc1, &error_indx);
161 set_msr_value(cpu, IA32_PERFEVTSEL1, 0x430000 + pmc2, &error_indx);
162 set_msr_value(cpu, IA32_PERFEVTSEL2, 0x430000 + pmc3, &error_indx);
163 set_msr_value(cpu, IA32_PERFEVTSEL3, 0x430000 + pmc4, &error_indx);
164 }
165
166 unsigned long Get_MV1_Counter0(int cpu)
167 {
168 return (get_msr_value(cpu, IA32_PMC0, 63, 0, &error_indx));
169 }
170
171 unsigned long Get_MV1_Counter1(int cpu)
172 {
173 return (get_msr_value(cpu, IA32_PMC1, 63, 0, &error_indx));
174 }
175
176 unsigned long Get_MV1_Counter2(int cpu)
177 {
178 return (get_msr_value(cpu, IA32_PMC2, 63, 0, &error_indx));
179 }
180
181 unsigned long Get_MV1_Counter3(int cpu)
182 {
183 return (get_msr_value(cpu, IA32_PMC3, 63, 0, &error_indx));
184 }
185
186 void sleep_ms(long long int msecs)
187 {
188 struct timespec t_req, t_rem;
189 int secs_to_sleep = floor((double)msecs / 1000);
190 int ms_to_sleep = msecs - secs_to_sleep * 1000;
191 t_req.tv_sec = secs_to_sleep;
192 t_req.tv_nsec = ms_to_sleep * 1000000;
193 nanosleep(&t_req, NULL);
194 }
195
196 long double ctime_long_double()
197 {
198 struct timeval current_time;
199 long double current_time_f;
200 gettimeofday(&current_time, NULL);
201 current_time_f =
202 (long double)current_time.tv_sec +
203 (long double)current_time.tv_usec / 1000000;
204 return (current_time_f);
205 }
206
207 ///////////////////////////////////////////////////////////////////////////////////////////////
208
209 struct cycle_information {
210 unsigned long instruction_retired_any;
211 unsigned long cpu_clk_unhalted_core;
212 unsigned long cpu_clk_unhalted_ref;
213 unsigned long mem_inst_retired_stores;
214 unsigned long mem_inst_retired_loads;
215 unsigned long fp_comp_ops_exe_sse_fp;
216 unsigned long fp_comp_ops_exe_x87;
217 };
218
219 char *lvalue = NULL;
220 bool logging = false;
221
222
223 void *main_thread(void *filename)
224 {
225 int i;
226 struct cpu_heirarchy_info chi;
227 struct cpu_socket_info socket_0;
228 socket_0.max_cpu = 0, socket_0.socket_num = 0;
229 for(i=0; i<8; i++)
230 socket_0.processor_num[i] = -1;
231
232 struct cpu_socket_info socket_1;
233 socket_1.max_cpu = 0, socket_1.socket_num = 0;
234 for(i=0; i<8; i++)
235 socket_1.processor_num[i] = -1;
236
237
238 int c;
239 opterr = 0;
240
241
242 FILE *fp;
243 printf("Logging enabled to %s\n", lvalue);
244
245 construct_CPU_Heirarchy_info(&chi);
246 construct_sibling_list(&chi);
247 construct_socket_information(&chi, &socket_0, &socket_1);
248 //print_CPU_Heirarchy(chi);
249 //print_socket_information(&socket_0);
250
251
252 /******************************************
253 for(i=0; i<8 ;i++){
254 printf("%d %d\n",chi.coreid_num[i],chi.sibling_num[i]);
255 }
256
257 struct therm_status_struct therm_status;
258 printf("Number of MSR %d\n", num_msr());
259 printf("PMCx width %d\n", bit_width_PMCx());
260
261 printf("Sizeof long %d\n", sizeof(long));
262 printf("value of long %ld\n", 0x7fffffffffffffff);
263 ******************************************/
264
265 unsigned long new_value_array[MAX_PROCESSORS_SYSTEM * 4],
266 old_value_array[MAX_PROCESSORS_SYSTEM * 4];
267
268 unsigned long instruction_retired_any_old[MAX_PROCESSORS_SYSTEM],
269 instruction_retired_any_new[MAX_PROCESSORS_SYSTEM];
270 unsigned long cpu_clk_unhalted_core_old[MAX_PROCESSORS_SYSTEM],
271 cpu_clk_unhalted_core_new[MAX_PROCESSORS_SYSTEM];
272 unsigned long cpu_clk_unhalted_ref_old[MAX_PROCESSORS_SYSTEM],
273 cpu_clk_unhalted_ref_new[MAX_PROCESSORS_SYSTEM];
274 unsigned long new_tsc[MAX_PROCESSORS_SYSTEM],
275 old_tsc[MAX_PROCESSORS_SYSTEM];
276
277 memset(new_value_array, 0,
278 MAX_PROCESSORS_SYSTEM * 4 * sizeof(unsigned long));
279 memset(old_value_array, 0,
280 MAX_PROCESSORS_SYSTEM * 4 * sizeof(unsigned long));
281 memset(instruction_retired_any_old, 0,
282 MAX_PROCESSORS_SYSTEM * sizeof(unsigned long));
283 memset(instruction_retired_any_new, 0,
284 MAX_PROCESSORS_SYSTEM * sizeof(unsigned long));
285 memset(cpu_clk_unhalted_core_old, 0,
286 MAX_PROCESSORS_SYSTEM * 4 * sizeof(unsigned long));
287 memset(cpu_clk_unhalted_core_new, 0,
288 MAX_PROCESSORS_SYSTEM * 4 * sizeof(unsigned long));
289 memset(cpu_clk_unhalted_ref_old, 0,
290 MAX_PROCESSORS_SYSTEM * 4 * sizeof(unsigned long));
291 memset(cpu_clk_unhalted_ref_new, 0,
292 MAX_PROCESSORS_SYSTEM * 4 * sizeof(unsigned long));
293 memset(new_tsc, 0, MAX_PROCESSORS_SYSTEM * 4 * sizeof(unsigned long));
294 memset(old_tsc, 0, MAX_PROCESSORS_SYSTEM * 4 * sizeof(unsigned long));
295
296 unsigned long long tsc_overall, instruction_retired_any_overall,
297 cpu_clk_unhalted_core_overall, cpu_clk_unhalted_ref_overall,
298 value_array_overall[4];
299
300 /* new_value = get_msr_value(0,0x186,63,0,&error_indx);
301 printf("value %ld\n",new_value);
302 new_value = get_msr_value(0,0x187,63,0,&error_indx);
303 printf("value %ld\n",new_value);
304 new_value = get_msr_value(0,0x188,63,0,&error_indx);
305 printf("value %ld\n",new_value);*/
306
307 int error_indx;
308 for (i = 0; i < MAX_PROCESSORS_SYSTEM; i++) {
309 //below is example of MV-1 for instruction_retired.any
310 //set_msr_value(0,IA32_PERFEVTSEL0,0x63003c);
311 Set_MV1_Counters(i, FP_COMP_OPS_EXE_SSE_FP, FP_COMP_OPS_EXE_X87,
312 MEM_INST_RETIRED_LOADS,
313 MEM_INST_RETIRED_STORES);
314 //Needs to set this to enable Monitoring Version - 2
315 set_msr_value(i, IA32_FIXED_CTR_CTL, 0xFFF, &error_indx); //can be used to stop/start counter
316 set_msr_value(i, IA32_PERF_GLOBAL_CTRL, 0x70000000FLLU, &error_indx); //this controls both the MV-2 and MV-1 events
317 //Thus need to enable it always!
318 }
319
320 bool init_thread = 0;
321
322 printf
323 ("Core id\t\tCurr Time\tTSC diff \tCurrFREQ (Core/Ref)*CPU_Freq\tInst.Retired\tUnhalted(Core)\tUnhalted(Ref)\tMem.Loads\tMem.Stores\t\tSSE_FP\t\tX87\n");
324
325 long long int iteration = 0;
326 int num_online_physical_cores = 0;
327 long double time_1, time_2, elapsed_time=0;
328 long double time_3, time_4, time_in_sleep=0;
329 //struct timeval current_time;
330 //long double current_time_f;
331
332 while (1) {
333 time_1 = ctime_long_double();
334 if (logging) {
335 //printf("logging noow");
336 fp = fopen(lvalue, "a+");
337 //printf("fp=%d", fp);
338 }
339 //gettimeofday(&current_time, NULL);
340 //current_time_f = (long double)current_time.tv_sec + (long double)current_time.tv_usec/1000000;
341 //printf("sec %Lf\n", ctime_long_double());
342
343 tsc_overall = 0, instruction_retired_any_overall = 0,
344 cpu_clk_unhalted_core_overall = 0, cpu_clk_unhalted_ref_overall = 0;
345 memset(value_array_overall, 0, sizeof(unsigned long) * 4);
346 num_online_physical_cores = 0;
347
348 for (i = 0; i < MAX_PROCESSORS_SYSTEM; i++) {
349 construct_CPU_Heirarchy_info(&chi);
350 construct_sibling_list(&chi);
351 construct_socket_information(&chi, &socket_0, &socket_1);
352
353 old_value_array[i * 4 + 0] = new_value_array[i * 4 + 0];
354 old_value_array[i * 4 + 1] = new_value_array[i * 4 + 1];
355 old_value_array[i * 4 + 2] = new_value_array[i * 4 + 2];
356 old_value_array[i * 4 + 3] = new_value_array[i * 4 + 3];
357
358 old_tsc[i] = new_tsc[i];
359 instruction_retired_any_old[i] = instruction_retired_any_new[i];
360 cpu_clk_unhalted_core_old[i] = cpu_clk_unhalted_core_new[i];
361 cpu_clk_unhalted_ref_old[i] = cpu_clk_unhalted_ref_new[i];
362
363 new_tsc[i] = rdtsc();
364 //new_value = get_msr_value(0,IA32_PMC0,63,0,&error_indx);
365 new_value_array[i * 4 + 0] = Get_MV1_Counter0(i);
366 new_value_array[i * 4 + 1] = Get_MV1_Counter1(i);
367 new_value_array[i * 4 + 2] = Get_MV1_Counter2(i);
368 new_value_array[i * 4 + 3] = Get_MV1_Counter3(i);
369
370 instruction_retired_any_new[i] = Read_instruction_retired_any(i);
371 cpu_clk_unhalted_core_new[i] = Read_cpu_clk_unhalted_core(i);
372 cpu_clk_unhalted_ref_new[i] = Read_cpu_clk_unhalted_ref(i);
373
374 if ((iteration > 0)
375 && (socket_0.processor_num[i] != -1)) {
376 num_online_physical_cores++;
377 if (iteration % 10 == 0) {printf("%10d\t%12.2Lf\t", socket_0.processor_num[i], ctime_long_double());}
378 if (logging) {fprintf(fp, "%10d\t%12.2Lf\t", socket_0.processor_num[i], ctime_long_double());}
379
380 if (iteration % 10 == 0)
381 printf("%10llu\t%10f\t\t", (new_tsc[i] - old_tsc[i]),
382 CPU_FREQUENCY * ((double) (cpu_clk_unhalted_core_new[i] - cpu_clk_unhalted_core_old[i])) / ((double) (cpu_clk_unhalted_ref_new[i] - cpu_clk_unhalted_ref_old[i])));
383 if (logging) {
384 fprintf(fp, "%10llu\t%10f\t\t", (new_tsc[i] - old_tsc[i]),
385 CPU_FREQUENCY * ((double) (cpu_clk_unhalted_core_new[i] - cpu_clk_unhalted_core_old[i])) / ((double)(cpu_clk_unhalted_ref_new[i] - cpu_clk_unhalted_ref_old[i])));
386 }
387 tsc_overall += (new_tsc[i] - old_tsc[i]);
388
389 if (iteration % 10 == 0) {printf("%10lu\t", instruction_retired_any_new[i] - instruction_retired_any_old[i]);}
390 if (logging) {fprintf(fp, "%10lu\t", instruction_retired_any_new[i] - instruction_retired_any_old[i]);}
391 instruction_retired_any_overall += (instruction_retired_any_new[i] - instruction_retired_any_old[i]);
392
393 if (iteration % 10 == 0) {printf("%10lu\t", cpu_clk_unhalted_core_new[i] - cpu_clk_unhalted_core_old[i]);}
394 if (logging) {fprintf(fp, "%10lu\t", cpu_clk_unhalted_core_new[i] - cpu_clk_unhalted_core_old[i]);}
395 cpu_clk_unhalted_core_overall += (cpu_clk_unhalted_core_new[i] - cpu_clk_unhalted_core_old[i]);
396
397 if (iteration % 10 == 0) {printf("%10lu\t", cpu_clk_unhalted_ref_new[i] - cpu_clk_unhalted_ref_old[i]);}
398 if (logging) {fprintf(fp, "%10lu\t", cpu_clk_unhalted_ref_new[i] - cpu_clk_unhalted_ref_old[i]);}
399 cpu_clk_unhalted_ref_overall += (cpu_clk_unhalted_ref_new[i] - cpu_clk_unhalted_ref_old[i]);
400
401 if (iteration % 10 == 0) {printf("%10lu\t", new_value_array[i * 4 + 0] - old_value_array[i * 4 + 0]);}
402 if (logging) {fprintf(fp, "%10lu\t", new_value_array[i * 4 + 0] - old_value_array[i * 4 + 0]);}
403 value_array_overall[0] += (new_value_array[i * 4 + 0] - old_value_array[i * 4 + 0]);
404
405 if (iteration % 10 == 0) {printf("%10lu\t", new_value_array[i * 4 + 1] - old_value_array[i * 4 + 1]);}
406 if (logging) {fprintf(fp, "%10lu\t", new_value_array[i * 4 + 1] - old_value_array[i * 4 + 1]);}
407 value_array_overall[1] += (new_value_array[i * 4 + 1] - old_value_array[i * 4 + 1]);
408
409 if (iteration % 10 == 0) {printf("%10lu\t", new_value_array[i * 4 + 2] - old_value_array[i * 4 + 2]);}
410 if (logging) {fprintf(fp, "%10lu\t", new_value_array[i * 4 + 2] - old_value_array[i * 4 + 2]);}
411 value_array_overall[2] += (new_value_array[i * 4 + 2] - old_value_array[i * 4 + 2]);
412
413 if (iteration % 10 == 0) {printf("%10lu\n", new_value_array[i * 4 + 3] - old_value_array[i * 4 + 3]);}
414 if (logging) {fprintf(fp, "%10lu\n", new_value_array[i * 4 + 3] - old_value_array[i * 4 + 3]);}
415 value_array_overall[3] += (new_value_array[i * 4 + 3] - old_value_array[i * 4 + 3]);
416 }
417 //Read_Thermal_Status(&therm_status);
418 //Print_Thermal_Status(therm_status);
419 }
420
421 if ((iteration > 0) && (iteration % 10 == 0)) {
422 printf("Overall (%d/%d)\t%12.2Lf\t",
423 num_online_physical_cores, 4,
424 ctime_long_double());
425 printf("%10llu\t%10f\t\t", tsc_overall,
426 CPU_FREQUENCY * ((double)cpu_clk_unhalted_core_overall /
427 (double)cpu_clk_unhalted_ref_overall));
428 printf("%10llu\t", instruction_retired_any_overall);
429 printf("%10llu\t", cpu_clk_unhalted_core_overall);
430 printf("%10llu\t", cpu_clk_unhalted_ref_overall);
431 printf("%10llu\t", value_array_overall[0]);
432 printf("%10llu\t", value_array_overall[1]);
433 printf("%10llu\t", value_array_overall[2]);
434 printf("%10llu\t", value_array_overall[3]);
435 printf("\n");
436
437 printf
438 ("--------------------------------------------------------------------------------------------");
439 printf
440 ("--------------------------------------------------------------------------------------------\n");
441 }
442 if ((logging) && (iteration > 0)) {
443 fprintf(fp, "Overall (%d/%d)\t%12.2Lf\t",
444 num_online_physical_cores, 4,
445 ctime_long_double());
446 fprintf(fp, "%10llu\t%10f\t", tsc_overall,
447 CPU_FREQUENCY * ((double)cpu_clk_unhalted_core_overall /
448 (double)cpu_clk_unhalted_ref_overall));
449 fprintf(fp, "%10llu\t",
450 instruction_retired_any_overall);
451 fprintf(fp, "%10llu\t", cpu_clk_unhalted_core_overall);
452 fprintf(fp, "%10llu\t", cpu_clk_unhalted_ref_overall);
453 fprintf(fp, "%10llu\t", value_array_overall[0]);
454 fprintf(fp, "%10llu\t", value_array_overall[1]);
455 fprintf(fp, "%10llu\t", value_array_overall[2]);
456 fprintf(fp, "%10llu\t", value_array_overall[3]);
457 fprintf(fp, "\n");
458 }
459 //fflush(fp);
460 fflush(stdout);
461
462 iteration++;
463 if (logging) {
464 fclose(fp);
465 }
466 time_2 = ctime_long_double();
467
468 elapsed_time += (time_2 - time_1);
469 if (iteration % 10 == 0) {
470 printf("Avg elapsed time %Lf\n", elapsed_time/iteration);
471 }
472
473 time_3 = ctime_long_double();
474 //sleep(1);
475 sleep_ms(800);
476 time_4 = ctime_long_double();
477 time_in_sleep += (time_4 - time_3);
478 if (iteration % 10 == 0) {
479 printf("Avg Sleep time %Lf\n", time_in_sleep/iteration);
480 }
481 //
482 }
483
484 }
485
486 void print_scheduler(void)
487 {
488 int schedType;
489
490 schedType = sched_getscheduler(getpid());
491
492 switch(schedType)
493 {
494 case SCHED_FIFO:
495 printf("Pthread Policy is SCHED_FIFO\n");
496 break;
497 case SCHED_OTHER:
498 printf("Pthread Policy is SCHED_OTHER\n");
499 break;
500 case SCHED_RR:
501 printf("Pthread Policy is SCHED_OTHER\n");
502 break;
503 default:
504 printf("Pthread Policy is UNKNOWN\n");
505 }
506 }
507
508
509 int main(int argc, char **argv)
510 {
511 //sam siewert rocks! http://avatar.colorado.edu/resource/linux_examples/pthread.c
512 pthread_attr_t rt_sched_attr;
513 int rt_max_prio, rt_min_prio, rc;
514 struct sched_param rt_param, nrt_param;
515
516 print_scheduler();
517
518 pthread_attr_init(&rt_sched_attr);
519 pthread_attr_setinheritsched(&rt_sched_attr, PTHREAD_EXPLICIT_SCHED);
520 pthread_attr_setschedpolicy(&rt_sched_attr, SCHED_RR);
521
522 rt_max_prio = sched_get_priority_max(SCHED_FIFO);
523 rt_min_prio = sched_get_priority_min(SCHED_FIFO);
524
525 rc=sched_getparam(getpid(), &nrt_param);
526 rt_param.sched_priority = rt_max_prio;
527 rc=sched_setscheduler(getpid(), SCHED_FIFO, &rt_param);
528
529 if (rc) {printf("ERROR; sched_setscheduler rc is %d\n", rc); perror(NULL); exit(-1);}
530 print_scheduler();
531
532 int c;
533 while ((c = getopt(argc, argv, "l:")) != -1) {
534 switch (c) {
535 case 'l':
536 logging = true;
537 lvalue = optarg;
538 break;
539 case '?':
540 if (optopt == 'l')
541 fprintf(stderr,
542 "Option -%c requires an argument\n",
543 optopt);
544 default:
545 abort();
546 }
547 }
548
549 pthread_t mainthread;
550 int iret;
551
552 iret = pthread_create(&mainthread, NULL, main_thread, NULL);
553
554 pthread_join(mainthread, NULL);
555 return (1);
556 }