forked from intel/intel-cmt-cat
/
main.c
769 lines (689 loc) · 25.6 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
/*
* BSD LICENSE
*
* Copyright(c) 2014-2016 Intel Corporation. All rights reserved.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Intel Corporation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @brief Platform QoS utility - main module
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h> /**< isspace() */
#include <sys/types.h> /**< open() */
#include <sys/stat.h>
#include <fcntl.h>
#include <getopt.h> /**< getopt_long() */
#include "pqos.h"
#include "main.h"
#include "profiles.h"
#include "monitor.h"
#include "alloc.h"
/**
* Default CDP configuration option - don't enforce on or off
*/
static enum pqos_cdp_config selfn_cdp_config = PQOS_REQUIRE_CDP_ANY;
/**
* Free RMID's being in use
*/
static int sel_free_in_use_rmid = 0;
/**
* Maintains pointer to selected log file name
*/
static char *sel_log_file = NULL;
/**
* Maintains pointer to selected config file
*/
static char *sel_config_file = NULL;
/**
* Maintains pointer to allocation profile from internal DB
*/
static char *sel_allocation_profile = NULL;
/**
* Maintains verbose mode choice selected in config string
*/
static int sel_verbose_mode = 0;
/**
* Reset CAT configuration
*/
static int sel_reset_CAT = 0;
/**
* Enable showing cache allocation settings
*/
static int sel_show_allocation_config = 0;
/**
* @brief Function to check if a value is already contained in a table
*
* @param tab table of values to check
* @param size size of the table
* @param val value to search for
*
* @return If the value is already in the table
* @retval 1 if value if found
* @retval 0 if value is not found
*/
static int
isdup(const uint64_t *tab, const unsigned size, const uint64_t val)
{
unsigned i;
for (i = 0; i < size; i++)
if (tab[i] == val)
return 1;
return 0;
}
uint64_t strtouint64(const char *s)
{
const char *str = s;
int base = 10;
uint64_t n = 0;
char *endptr = NULL;
ASSERT(s != NULL);
if (strncasecmp(s, "0x", 2) == 0) {
base = 16;
s += 2;
}
n = strtoull(s, &endptr, base);
if (!(*s != '\0' && *endptr == '\0')) {
printf("Error converting '%s' to unsigned number!\n", str);
exit(EXIT_FAILURE);
}
return n;
}
unsigned strlisttotab(char *s, uint64_t *tab, const unsigned max)
{
unsigned index = 0;
char *saveptr = NULL;
if (s == NULL || tab == NULL || max == 0)
return index;
for (;;) {
char *p = NULL;
char *token = NULL;
token = strtok_r(s, ",", &saveptr);
if (token == NULL)
break;
s = NULL;
/* get rid of leading spaces & skip empty tokens */
while (isspace(*token))
token++;
if (*token == '\0')
continue;
p = strchr(token, '-');
if (p != NULL) {
/**
* range of numbers provided
* example: 1-5 or 12-9
*/
uint64_t n, start, end;
*p = '\0';
start = strtouint64(token);
end = strtouint64(p+1);
if (start > end) {
/**
* no big deal just swap start with end
*/
n = start;
start = end;
end = n;
}
for (n = start; n <= end; n++) {
if (!(isdup(tab, index, n))) {
tab[index] = n;
index++;
}
if (index >= max)
return index;
}
} else {
/**
* single number provided here
* remove duplicates if necessary
*/
uint64_t val = strtouint64(token);
if (!(isdup(tab, index, val))) {
tab[index] = val;
index++;
}
if (index >= max)
return index;
}
}
return index;
}
__attribute__ ((noreturn)) void
parse_error(const char *arg, const char *note)
{
printf("Error parsing \"%s\" command line argument. %s\n",
arg ? arg : "<null>",
note ? note : "");
exit(EXIT_FAILURE);
}
void selfn_strdup(char **sel, const char *arg)
{
ASSERT(sel != NULL && arg != NULL);
if (*sel != NULL) {
free(*sel);
*sel = NULL;
}
*sel = strdup(arg);
ASSERT(*sel != NULL);
if (*sel == NULL) {
printf("String duplicate error!\n");
exit(EXIT_FAILURE);
}
}
/**
* @brief Function to print warning to users as utility begins
*/
static void
print_warning(void)
{
printf("NOTE: Mixed use of MSR and kernel interfaces "
"to manage\n CAT or CMT & MBM may lead to "
"unexpected behavior.\n");
}
/**
* @brief Selects log file
*
* @param arg string passed to -l command line option
*/
static void
selfn_log_file(const char *arg)
{
selfn_strdup(&sel_log_file, arg);
}
/**
* @brief Selects verbose mode on
*
* @param arg not used
*/
static void
selfn_verbose_mode(const char *arg)
{
UNUSED_ARG(arg);
sel_verbose_mode = 1;
}
/**
* @brief Selects super verbose mode on
*
* @param arg not used
*/
static void
selfn_super_verbose_mode(const char *arg)
{
UNUSED_ARG(arg);
sel_verbose_mode = 2;
}
/**
* @brief Processes configuration setting
*
* For now CDP config settings are only accepted.
*
* @param arg string detailing configuration setting
*/
static void
selfn_set_config(const char *arg)
{
if (strcasecmp(arg, "cdp-on") == 0)
selfn_cdp_config = PQOS_REQUIRE_CDP_ON;
else if (strcasecmp(arg, "cdp-off") == 0)
selfn_cdp_config = PQOS_REQUIRE_CDP_OFF;
else if (strcasecmp(arg, "cdp-any") == 0)
selfn_cdp_config = PQOS_REQUIRE_CDP_ANY;
else {
printf("Unrecognized '%s' setting!\n", arg);
exit(EXIT_FAILURE);
}
}
/**
* @brief Sets CAT reset flag
*
* @param arg not used
*/
static void selfn_reset_cat(const char *arg)
{
UNUSED_ARG(arg);
sel_reset_CAT = 1;
}
/**
* @brief Selects showing allocation settings
*
* @param arg not used
*/
static void selfn_show_allocation(const char *arg)
{
UNUSED_ARG(arg);
sel_show_allocation_config = 1;
}
/**
* @brief Selects allocation profile from internal DB
*
* @param arg string passed to -c command line option
*/
static void
selfn_allocation_select(const char *arg)
{
selfn_strdup(&sel_allocation_profile, arg);
}
/**
* @brief Opens configuration file and parses its contents
*
* @param fname Name of the file with configuration parameters
*/
static void
parse_config_file(const char *fname)
{
static const struct {
const char *option;
void (*fn)(const char *);
} optab[] = {
{"show-alloc:", selfn_show_allocation }, /**< -s */
{"log-file:", selfn_log_file }, /**< -l */
{"verbose-mode:", selfn_verbose_mode }, /**< -v */
{"super-verbose-mode:", selfn_super_verbose_mode },/**< -V */
{"alloc-class-set:", selfn_allocation_class }, /**< -e */
{"alloc-assoc-set:", selfn_allocation_assoc }, /**< -a */
{"alloc-class-select:", selfn_allocation_select }, /**< -c */
{"monitor-pids:", selfn_monitor_pids }, /**< -p */
{"monitor-cores:", selfn_monitor_cores }, /**< -m */
{"monitor-time:", selfn_monitor_time }, /**< -t */
{"monitor-interval:", selfn_monitor_interval }, /**< -i */
{"monitor-file:", selfn_monitor_file }, /**< -o */
{"monitor-file-type:", selfn_monitor_file_type }, /**< -u */
{"monitor-top-like:", selfn_monitor_top_like }, /**< -T */
{"set-config:", selfn_set_config }, /**< -S */
{"reset-cat:", selfn_reset_cat }, /**< -R */
};
FILE *fp = NULL;
char cb[256];
fp = fopen(fname, "r");
if (fp == NULL)
parse_error(fname, "cannot open configuration file!");
memset(cb, 0, sizeof(cb));
while (fgets(cb, sizeof(cb)-1, fp) != NULL) {
int i, j, remain;
char *cp = NULL;
for (j = 0; j < (int)sizeof(cb)-1; j++)
if (!isspace(cb[j]))
break;
if (j >= (int)(sizeof(cb)-1))
continue; /**< blank line */
if (strlen(cb+j) == 0)
continue; /**< blank line */
if (cb[j] == '#')
continue; /**< comment */
cp = cb+j;
remain = (int)strlen(cp);
/**
* remove trailing white spaces
*/
for (i = (int)strlen(cp)-1; i > 0; i--)
if (!isspace(cp[i])) {
cp[i+1] = '\0';
break;
}
for (i = 0; i < (int)DIM(optab); i++) {
int len = (int)strlen(optab[i].option);
if (len > remain)
continue;
if (strncasecmp(cp, optab[i].option, (size_t)len) != 0)
continue;
while (isspace(cp[len]))
len++; /**< skip space characters */
optab[i].fn(cp+len);
break;
}
if (i >= (int)DIM(optab))
parse_error(cp,
"Unrecognized configuration file command");
}
fclose(fp);
}
static const char *m_cmd_name = "pqos"; /**< command name */
static const char help_printf_short[] =
"Usage: %s [-h] [--help] [-v] [--verbose] [-V] [--super-verbose]\n"
" [-l FILE] [--log-file=FILE] [-S CONFIG] [--set CONFIG]\n"
" %s [-s] [--show]\n"
" %s [-m EVTCORES] [--mon-core=EVTCORES] | [-p EVTPIDS] "
"[--mon-pid=EVTPIDS]\n"
" [-t SECONDS] [--mon-time=SECONDS]\n"
" [-i N] [--mon-interval=N]\n"
" [-T] [--mon-top]\n"
" [-o FILE] [--mon-file=FILE]\n"
" [-u TYPE] [--mon-file-type=TYPE]\n"
" [-r] [--mon-reset]\n"
" %s [-e CLASSDEF] [--alloc-class=CLASSDEF]\n"
" [-a CLASS2CORE] [--alloc-assoc=CLASS2CORE]\n"
" %s [-R] [--alloc-reset]\n"
" %s [-H] [--profile-list] | [-c PROFILE] "
"[--profile-set=PROFILE]\n"
" %s [-f FILE] [--config-file=FILE]\n";
static const char help_printf_long[] =
"Description:\n"
" -h, --help help page\n"
" -v, --verbose verbose mode\n"
" -V, --super-verbose super-verbose mode\n"
" -s, --show show current PQoS configuration\n"
" -f FILE, --config-file=FILE load commands from selected file\n"
" -l FILE, --log-file=FILE log messages into selected file\n"
" -S CONFIG, --set=CONFIG set configuration parameter.\n"
" CONFIG can be: cdp-on, cdp-off or cdp-any (default).\n"
" NOTE: change of CDP from ON to OFF, or from OFF to ON\n"
" results in allocation (CAT) reset.\n"
" -e CLASSDEF, --alloc-class=CLASSDEF\n"
" define allocation classes.\n"
" CLASSDEF format is 'TYPE:ID=DEFINITION;'.\n"
" Example 'llc:0=0xffff;llc:1=0x00ff;'.\n"
" -a CLASS2CORE, --alloc-assoc=CLASS2CORE\n"
" associate cores with an allocation class.\n"
" CLASS2CORE format is 'TYPE:ID=CORE_LIST'.\n"
" Example 'llc:0=0,2,4,6-10;llc:1=1'.\n"
" -R, --alloc-reset reset allocation (CAT) configuration\n"
" -m EVTCORES, --mon-core=EVTCORES\n"
" select cores and events for monitoring.\n"
" EVTCORES format is 'EVENT:CORE_LIST'.\n"
" Example: \"all:0,2,4-10;llc:1,3;mbr:11-12\".\n"
" Cores can be grouped by enclosing them in square brackets,\n"
" example: \"llc:[0-3];all:[4,5,6];mbr:[0-3],7,8\".\n"
" -p EVTPIDS, --mon-pid=EVTPIDS\n"
" select process ids and events to monitor.\n"
" EVTPIDS format is 'EVENT:PID_LIST'.\n"
" Example 'llc:22,25673' or 'all:892,4588-4592'.\n"
" Note: processes and cores cannot be monitored together.\n"
" -o FILE, --mon-file=FILE output monitored data in a FILE\n"
" -u TYPE, --mon-file-type=TYPE\n"
" select output file format type for monitored data.\n"
" TYPE is one of: text (default), xml or csv.\n"
" -i N, --mon-interval=N set sampling interval to Nx100ms,\n"
" default 10 = 10 x 100ms = 1s.\n"
" -T, --mon-top top like monitoring output\n"
" -t SECONDS, --mon-time=SECONDS\n"
" set monitoring time in seconds. Use 'inf' or 'infinite'\n"
" for infinite monitoring. CTRL+C stops monitoring.\n"
" -r, --mon-reset monitoring reset, claim all RMID's\n"
" -H, --profile-list list supported allocation profiles\n"
" -c PROFILE, --profile-set=PROFILE\n"
" select a PROFILE of predefined allocation classes.\n"
" Use -H to list available profiles.\n";
/**
* @brief Displays help information
*
* @param is_long print long help version or a short one
*
*/
static void print_help(const int is_long)
{
printf(help_printf_short,
m_cmd_name, m_cmd_name, m_cmd_name, m_cmd_name,
m_cmd_name, m_cmd_name, m_cmd_name);
if (is_long)
printf(help_printf_long);
}
static struct option long_cmd_opts[] = {
{"help", no_argument, 0, 'h'},
{"log-file", required_argument, 0, 'l'},
{"set", required_argument, 0, 'S'},
{"config-file", required_argument, 0, 'f'},
{"show", no_argument, 0, 's'},
{"profile-list", no_argument, 0, 'H'},
{"profile-set", required_argument, 0, 'c'},
{"mon-interval", required_argument, 0, 'i'},
{"mon-pid", required_argument, 0, 'p'},
{"mon-core", required_argument, 0, 'm'},
{"mon-time", required_argument, 0, 't'},
{"mon-top", no_argument, 0, 'T'},
{"mon-file", required_argument, 0, 'o'},
{"mon-file-type", required_argument, 0, 'u'},
{"mon-reset", no_argument, 0, 'r'},
{"alloc-class", required_argument, 0, 'e'},
{"alloc-reset", no_argument, 0, 'R'},
{"alloc-assoc", required_argument, 0, 'a'},
{"verbose", no_argument, 0, 'v'},
{"super-verbose", no_argument, 0, 'V'},
{0, 0, 0, 0} /* end */
};
int main(int argc, char **argv)
{
struct pqos_config cfg;
const struct pqos_cpuinfo *p_cpu = NULL;
const struct pqos_cap *p_cap = NULL;
const struct pqos_capability *cap_mon = NULL, *cap_l3ca = NULL;
unsigned sock_count, sockets[PQOS_MAX_SOCKETS];
int cmd, ret, exit_val = EXIT_SUCCESS;
int opt_index = 0;
m_cmd_name = argv[0];
print_warning();
while ((cmd = getopt_long(argc, argv,
"Hhf:i:m:Tt:l:o:u:e:c:a:p:S:srvVR",
long_cmd_opts, &opt_index)) != -1) {
switch (cmd) {
case 'h':
print_help(1);
return EXIT_SUCCESS;
case 'H':
profile_l3ca_list(stdout);
return EXIT_SUCCESS;
case 'S':
selfn_set_config(optarg);
break;
case 'f':
if (sel_config_file != NULL) {
printf("Only one config file argument is "
"accepted!\n");
return EXIT_FAILURE;
}
selfn_strdup(&sel_config_file, optarg);
parse_config_file(sel_config_file);
break;
case 'i':
selfn_monitor_interval(optarg);
break;
case 'p':
selfn_monitor_pids(optarg);
break;
case 'm':
selfn_monitor_cores(optarg);
break;
case 't':
selfn_monitor_time(optarg);
break;
case 'T':
selfn_monitor_top_like(NULL);
break;
case 'l':
selfn_log_file(optarg);
break;
case 'o':
selfn_monitor_file(optarg);
break;
case 'u':
selfn_monitor_file_type(optarg);
break;
case 'e':
selfn_allocation_class(optarg);
break;
case 'r':
sel_free_in_use_rmid = 1;
break;
case 'R':
selfn_reset_cat(NULL);
break;
case 'a':
selfn_allocation_assoc(optarg);
break;
case 'c':
selfn_allocation_select(optarg);
break;
case 's':
selfn_show_allocation(NULL);
break;
case 'v':
selfn_verbose_mode(NULL);
break;
case 'V':
selfn_super_verbose_mode(NULL);
break;
default:
printf("Unsupported option: -%c. "
"See option -h for help.\n", optopt);
return EXIT_FAILURE;
break;
case '?':
print_help(0);
return EXIT_SUCCESS;
break;
}
}
memset(&cfg, 0, sizeof(cfg));
cfg.verbose = sel_verbose_mode;
cfg.free_in_use_rmid = sel_free_in_use_rmid;
cfg.cdp_cfg = selfn_cdp_config;
/**
* Set up file descriptor for message log
*/
if (sel_log_file == NULL) {
cfg.fd_log = STDOUT_FILENO;
} else {
cfg.fd_log = open(sel_log_file, O_WRONLY|O_CREAT,
S_IRUSR|S_IWUSR);
if (cfg.fd_log == -1) {
printf("Error opening %s log file!\n", sel_log_file);
exit_val = EXIT_FAILURE;
goto error_exit_2;
}
}
ret = pqos_init(&cfg);
if (ret != PQOS_RETVAL_OK) {
printf("Error initializing PQoS library!\n");
exit_val = EXIT_FAILURE;
goto error_exit_1;
}
ret = pqos_cap_get(&p_cap, &p_cpu);
if (ret != PQOS_RETVAL_OK) {
printf("Error retrieving PQoS capabilities!\n");
exit_val = EXIT_FAILURE;
goto error_exit_2;
}
ret = pqos_cpu_get_sockets(p_cpu, PQOS_MAX_SOCKETS,
&sock_count,
sockets);
if (ret != PQOS_RETVAL_OK) {
printf("Error retrieving CPU socket information!\n");
exit_val = EXIT_FAILURE;
goto error_exit_2;
}
ret = pqos_cap_get_type(p_cap, PQOS_CAP_TYPE_MON, &cap_mon);
if (ret == PQOS_RETVAL_PARAM) {
printf("Error retrieving monitoring capabilities!\n");
exit_val = EXIT_FAILURE;
goto error_exit_2;
}
ret = pqos_cap_get_type(p_cap, PQOS_CAP_TYPE_L3CA, &cap_l3ca);
if (ret == PQOS_RETVAL_PARAM) {
printf("Error retrieving allocation capabilities!\n");
exit_val = EXIT_FAILURE;
goto error_exit_2;
}
if (sel_reset_CAT) {
/**
* Reset CAT configuration to after-reset state and exit
*/
if (pqos_l3ca_reset(p_cap, p_cpu) != PQOS_RETVAL_OK) {
exit_val = EXIT_FAILURE;
printf("CAT reset failed!\n");
} else
printf("CAT reset successful\n");
goto allocation_exit;
}
if (sel_show_allocation_config) {
/**
* Show info about allocation config and exit
*/
alloc_print_config(cap_mon, cap_l3ca, sock_count,
sockets, p_cpu);
goto allocation_exit;
}
if (sel_allocation_profile != NULL) {
if (profile_l3ca_apply(sel_allocation_profile, cap_l3ca) != 0) {
exit_val = EXIT_FAILURE;
goto error_exit_2;
}
}
switch (alloc_apply(cap_l3ca, sock_count, sockets)) {
case 0: /* nothing to apply */
break;
case 1: /* new allocation config applied and all is good */
goto allocation_exit;
break;
case -1: /* something went wrong */
default:
exit_val = EXIT_FAILURE;
goto error_exit_2;
break;
}
/**
* Just monitoring option left on the table now
*/
if (cap_mon == NULL) {
printf("Monitoring capability not detected!\n");
exit_val = EXIT_FAILURE;
goto error_exit_2;
}
if (monitor_setup(p_cpu, cap_mon) != 0) {
exit_val = EXIT_FAILURE;
goto error_exit_2;
}
monitor_loop(p_cap);
monitor_stop();
allocation_exit:
error_exit_2:
ret = pqos_fini();
ASSERT(ret == PQOS_RETVAL_OK);
if (ret != PQOS_RETVAL_OK)
printf("Error shutting down PQoS library!\n");
error_exit_1:
monitor_cleanup();
/**
* Close file descriptor for message log
*/
if (cfg.fd_log > 0 && cfg.fd_log != STDOUT_FILENO)
close(cfg.fd_log);
/**
* Free allocated memory
*/
if (sel_allocation_profile != NULL)
free(sel_allocation_profile);
if (sel_log_file != NULL)
free(sel_log_file);
if (sel_config_file != NULL)
free(sel_config_file);
return exit_val;
}