forked from intel/intel-cmt-cat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpqos.h
1329 lines (1225 loc) · 43.2 KB
/
pqos.h
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
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* BSD LICENSE
*
* Copyright(c) 2014-2020 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 API and data structure definition
*
* API from this file is implemented by the following:
* cap.c, allocation.c, monitoring.c and utils.c
*/
#ifndef __PQOS_H__
#define __PQOS_H__
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* =======================================
* Various defines
* =======================================
*/
#define PQOS_VERSION 30200 /**< version 3.2.0 */
#define PQOS_MAX_COS 16 /** 16 x COS */
#define PQOS_MAX_L3CA_COS PQOS_MAX_COS
#define PQOS_MAX_L2CA_COS PQOS_MAX_COS
/*
* =======================================
* Return values
* =======================================
*/
#define PQOS_RETVAL_OK 0 /**< everything OK */
#define PQOS_RETVAL_ERROR 1 /**< generic error */
#define PQOS_RETVAL_PARAM 2 /**< parameter error */
#define PQOS_RETVAL_RESOURCE 3 /**< resource error */
#define PQOS_RETVAL_INIT 4 /**< initialization error */
#define PQOS_RETVAL_TRANSPORT 5 /**< transport error */
#define PQOS_RETVAL_PERF_CTR 6 /**< performance counter error */
#define PQOS_RETVAL_BUSY 7 /**< resource busy error */
#define PQOS_RETVAL_INTER 8 /**< Interface not supported */
/*
* =======================================
* Interface values
* =======================================
*/
enum pqos_interface {
PQOS_INTER_MSR = 0, /**< MSR */
PQOS_INTER_OS = 1, /**< OS */
PQOS_INTER_OS_RESCTRL_MON = 2 /**< OS with resctrl monitoring */
};
/*
* =======================================
* Init and fini
* =======================================
*/
enum pqos_cdp_config {
PQOS_REQUIRE_CDP_OFF = 0, /**< app not compatible with CDP */
PQOS_REQUIRE_CDP_ON, /**< app requires CDP */
PQOS_REQUIRE_CDP_ANY /**< app will work with any CDP
setting */
};
/**
* Resource Monitoring ID (RMID) definition
*/
typedef uint32_t pqos_rmid_t;
#ifdef PQOS_RMID_CUSTOM
/**
* RMID initialization types
*/
enum pqos_rmid_type {
PQOS_RMID_TYPE_DEFAULT = 0, /**< Default sequential init */
PQOS_RMID_TYPE_MAP /**< Custom Core to RMID mapping */
};
/**
* RMID configuration
*/
struct pqos_rmid_config {
enum pqos_rmid_type type; /**< rmid initialization type */
struct {
unsigned num; /**< number of rmid to core mappings */
pqos_rmid_t *rmid; /**< rmid table */
unsigned *core; /**< core table */
} map;
};
#endif
/**
* PQoS library configuration structure
*
* @param fd_log file descriptor to be used as library log
* @param callback_log pointer to an application callback function
* void * - An application context - it can point to a structure
* or an object that an application may find useful
* when receiving the callback
* const size_t - the size of the log message
* const char * - the log message
* @param context_log application specific data that is provided
* to the callback function. It can be NULL if application
* doesn't require it.
* @param verbose logging options
* LOG_VER_SILENT - no messages
* LOG_VER_DEFAULT - warning and error messages
* LOG_VER_VERBOSE - warning, error and info messages
* LOG_VER_SUPER_VERBOSE - warning, error, info and debug messages
*
* @param interface preference
* PQOS_INTER_MSR - MSR interface or nothing
* PQOS_INTER_OS - OS interface or nothing
* PQOS_INTER_OS_RESCTRL_MON - OS interface with resctrl monitoring
* or nothing
*/
struct pqos_config {
int fd_log;
void (*callback_log)(void *context,
const size_t size,
const char *message);
void *context_log;
int verbose;
enum pqos_interface interface;
#ifdef PQOS_RMID_CUSTOM
struct pqos_rmid_config rmid_cfg;
#endif
};
/**
* @brief Initializes PQoS module
*
* @param [in] config initialization parameters structure
* Note that fd_log in \a config needs to be a valid
* file descriptor.
*
* @return Operation status
* @retval PQOS_RETVAL_OK on success
* @note If you require system wide interface enforcement you can do so by
* setting the "RDT_IFACE" environment variable.
*/
int pqos_init(const struct pqos_config *config);
/**
* @brief Shuts down PQoS module
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_fini(void);
/*
* =======================================
* Query capabilities
* =======================================
*/
/**
* Types of possible PQoS capabilities
*
* For now there are:
* - monitoring capability
* - L3 cache allocation capability
* - L2 cache allocation capability
* - Memory Bandwidth Allocation
*/
enum pqos_cap_type {
PQOS_CAP_TYPE_MON = 0, /**< QoS monitoring */
PQOS_CAP_TYPE_L3CA, /**< L3/LLC cache allocation */
PQOS_CAP_TYPE_L2CA, /**< L2 cache allocation */
PQOS_CAP_TYPE_MBA, /**< Memory Bandwidth Allocation */
PQOS_CAP_TYPE_NUMOF
};
/**
* L3 Cache Allocation (CA) capability structure
*/
struct pqos_cap_l3ca {
unsigned mem_size; /**< byte size of the structure */
unsigned num_classes; /**< number of classes of service */
unsigned num_ways; /**< number of cache ways */
unsigned way_size; /**< way size in bytes */
uint64_t way_contention; /**< ways contention bit mask */
int cdp; /**< code data prioritization feature
support */
int cdp_on; /**< code data prioritization on or
off */
};
/**
* L2 Cache Allocation (CA) capability structure
*/
struct pqos_cap_l2ca {
unsigned mem_size; /**< byte size of the structure */
unsigned num_classes; /**< number of classes of service */
unsigned num_ways; /**< number of cache ways */
unsigned way_size; /**< way size in bytes */
uint64_t way_contention; /**< ways contention bit mask */
int cdp; /**< code data prioritization feature
support */
int cdp_on; /**< code data prioritization on or off */
};
/**
* Memory Bandwidth Allocation configuration enumeration
*/
enum pqos_mba_config {
PQOS_MBA_ANY, /**< currently enabled configuration */
PQOS_MBA_DEFAULT, /**< direct MBA hardware configuration
(percentage) */
PQOS_MBA_CTRL /**< MBA controller configuration (MBps) */
};
/**
* Memory Bandwidth Allocation capability structure
*/
struct pqos_cap_mba {
unsigned mem_size; /**< byte size of the structure */
unsigned num_classes; /**< number of classes of service */
unsigned throttle_max; /**< the max MBA can be throttled */
unsigned throttle_step; /**< MBA granularity */
int is_linear; /**< the type of MBA linear/nonlinear */
int ctrl; /**< MBA controller support */
int ctrl_on; /**< MBA controller enabled */
};
/**
* Available types of monitored events
* (matches CPUID enumeration)
*/
enum pqos_mon_event {
PQOS_MON_EVENT_L3_OCCUP = 1, /**< LLC occupancy event */
PQOS_MON_EVENT_LMEM_BW = 2, /**< Local memory bandwidth */
PQOS_MON_EVENT_TMEM_BW = 4, /**< Total memory bandwidth */
PQOS_MON_EVENT_RMEM_BW = 8, /**< Remote memory bandwidth
(virtual event) */
RESERVED1 = 0x1000,
RESERVED2 = 0x2000,
PQOS_PERF_EVENT_LLC_MISS = 0x4000, /**< LLC misses */
PQOS_PERF_EVENT_IPC = 0x8000, /**< instructions per clock */
};
/**
* Monitoring capabilities structure
*
* Few assumptions here:
* - Data associated with each type of event won't exceed 64bits
* This results from MSR register size.
* - Interpretation of the data is up to application based
* on available documentation.
* - Meaning of the event is well understood by an application
* based on available documentation
*/
struct pqos_monitor {
enum pqos_mon_event type; /**< event type */
unsigned max_rmid; /**< max RMID supported for this event */
uint32_t scale_factor; /**< factor to scale RMID value to bytes */
unsigned counter_length; /**< counter bit length */
};
struct pqos_cap_mon {
unsigned mem_size; /**< byte size of the structure */
unsigned max_rmid; /**< max RMID supported by socket */
unsigned l3_size; /**< L3 cache size in bytes */
unsigned num_events; /**< number of supported events */
struct pqos_monitor events[0];
};
/**
* Single PQoS capabilities entry structure.
* Effectively a union of all possible PQoS structures plus type.
*/
struct pqos_capability {
enum pqos_cap_type type;
union {
struct pqos_cap_mon *mon;
struct pqos_cap_l3ca *l3ca;
struct pqos_cap_l2ca *l2ca;
struct pqos_cap_mba *mba;
void *generic_ptr;
} u;
};
/**
* Structure describing all Platform QoS capabilities
*/
struct pqos_cap {
unsigned mem_size; /**< byte size of the structure */
unsigned version; /**< version of PQoS library */
unsigned num_cap; /**< number of capabilities */
struct pqos_capability capabilities[0];
};
/**
* Core information structure
*/
struct pqos_coreinfo {
unsigned lcore; /**< logical core id */
unsigned socket; /**< socket id in the system */
unsigned l3_id; /**< L3/LLC cluster id */
unsigned l2_id; /**< L2 cluster id */
unsigned l3cat_id; /**< L3 CAT classes id */
unsigned mba_id; /**< MBA id */
};
/**
* CPU cache information structure
*/
struct pqos_cacheinfo {
int detected; /**< Indicates cache detected & valid */
unsigned num_ways; /**< Number of cache ways */
unsigned num_sets; /**< Number of sets */
unsigned num_partitions; /**< Number of partitions */
unsigned line_size; /**< Cache line size in bytes */
unsigned total_size; /**< Total cache size in bytes */
unsigned way_size; /**< Cache way size in bytes */
};
/**
* =======================================
* Vendor values
* =======================================
*/
enum pqos_vendor {
PQOS_VENDOR_UNKNOWN = 0, /**< UNKNOWN */
PQOS_VENDOR_INTEL = 1, /**< INTEL */
PQOS_VENDOR_AMD = 2 /**< AMD */
};
/**
* CPU topology structure
*/
struct pqos_cpuinfo {
unsigned mem_size; /**< byte size of the structure */
struct pqos_cacheinfo l2; /**< L2 cache information */
struct pqos_cacheinfo l3; /**< L3 cache information */
enum pqos_vendor vendor; /**< vendor Intel/AMD */
unsigned num_cores; /**< number of cores in the system */
struct pqos_coreinfo cores[0];
};
/**
* @brief Retrieves PQoS capabilities data
*
* @param [out] cap location to store PQoS capabilities information at
* @param [out] cpu location to store CPU information at
* This parameter is optional and when NULL is passed then
* no cpu information is returned.
* CPU information includes data about number of sockets,
* logical cores and their assignment.
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_cap_get(const struct pqos_cap **cap, const struct pqos_cpuinfo **cpu);
/*
* =======================================
* Monitoring
* =======================================
*/
/**
* The structure to store monitoring data for all of the events
*/
struct pqos_event_values {
uint64_t llc; /**< cache occupancy */
uint64_t mbm_local; /**< bandwidth local - reading */
uint64_t mbm_total; /**< bandwidth total - reading */
uint64_t mbm_remote; /**< bandwidth remote - reading */
uint64_t mbm_local_delta; /**< bandwidth local - delta */
uint64_t mbm_total_delta; /**< bandwidth total - delta */
uint64_t mbm_remote_delta; /**< bandwidth remote - delta */
uint64_t ipc_retired; /**< instructions retired - reading */
uint64_t ipc_retired_delta; /**< instructions retired - delta */
uint64_t ipc_unhalted; /**< unhalted cycles - reading */
uint64_t ipc_unhalted_delta; /**< unhalted cycles - delta */
double ipc; /**< retired instructions / cycles */
uint64_t llc_misses; /**< LLC misses - reading */
uint64_t llc_misses_delta; /**< LLC misses - delta */
};
/**
* Core monitoring poll context
*/
struct pqos_mon_poll_ctx {
unsigned lcore;
unsigned cluster;
pqos_rmid_t rmid;
};
/**
* Perf monitoring poll context
*/
struct pqos_mon_perf_ctx {
int fd_llc;
int fd_mbl;
int fd_mbt;
int fd_inst;
int fd_cyc;
int fd_llc_misses;
};
/**
* Monitoring group data structure
*/
struct pqos_mon_data {
/**
* Common section
*/
int valid; /**< structure validity marker */
enum pqos_mon_event event; /**< monitored event */
void *context; /**< application specific context
pointer */
struct pqos_event_values values; /**< RMID events value */
/**
* Task specific section
*/
unsigned num_pids; /**< number of pids in the group */
pid_t *pids; /**< list of pids in the group */
unsigned tid_nr;
pid_t *tid_map;
/**
* Perf specific section
*/
struct pqos_mon_perf_ctx *perf; /**< Perf poll context for each
core/tid */
enum pqos_mon_event perf_event; /**< Started perf events */
/**
* Resctrl specific section
*/
enum pqos_mon_event resctrl_event;
char *resctrl_mon_group;
struct pqos_event_values resctrl_values_storage; /**< stores values
of monitoring group
that was moved to
another COS */
/**
* Core specific section
*/
struct pqos_mon_poll_ctx *poll_ctx; /**< core, cluster & RMID */
unsigned num_poll_ctx; /**< number of poll contexts */
unsigned *cores; /**< list of cores in the group */
unsigned num_cores; /**< number of cores in the group */
int valid_mbm_read; /**< flag to discard 1st invalid
read */
};
/**
* @brief Resets monitoring by binding all cores with RMID0
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_mon_reset(void);
/**
* @brief Reads RMID association of the \a lcore
*
* @param [in] lcore CPU logical core id
* @param [out] rmid place to store resource monitoring id
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_mon_assoc_get(const unsigned lcore, pqos_rmid_t *rmid);
/**
* @brief Starts resource monitoring on selected group of cores
*
* The function sets up content of the \a group structure.
*
* Note that \a event cannot select PQOS_PERF_EVENT_IPC or
* PQOS_PERF_EVENT_L3_MISS events without any PQoS event
* selected at the same time.
*
* @param [in] num_cores number of cores in \a cores array
* @param [in] cores array of logical core id's
* @param [in] event combination of monitoring events
* @param [in] context a pointer for application's convenience
* (unused by the library)
* @param [in,out] group a pointer to monitoring structure
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*
* @note As of Kernel 4.10, Intel(R) RDT perf results per core are found to
* be incorrect.
*/
int pqos_mon_start(const unsigned num_cores,
const unsigned *cores,
const enum pqos_mon_event event,
void *context,
struct pqos_mon_data *group);
/**
* @brief Starts resource monitoring of selected \a pid (process)
*
* @param [in] pid process ID
* @param [in] event monitoring event id
* @param [in] context a pointer for application's convenience
* (unused by the library)
* @param [in,out] group a pointer to monitoring structure
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_mon_start_pid(const pid_t pid,
const enum pqos_mon_event event,
void *context,
struct pqos_mon_data *group);
/**
* @brief Starts resource monitoring of selected \a pids (processes)
*
* @param [in] num_pids number of pids in \a pids array
* @param [in] pids array of process ID
* @param [in] event monitoring event id
* @param [in] context a pointer for application's convenience
* (unused by the library)
* @param [in,out] group a pointer to monitoring structure
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_mon_start_pids(const unsigned num_pids,
const pid_t *pids,
const enum pqos_mon_event event,
void *context,
struct pqos_mon_data *group);
/**
* @brief Adds pids to the resource monitoring grpup
*
* @param [in] num_pids number of pids in \a pids array
* @param [in] pids array of process ID
* @param [in,out] group a pointer to monitoring structure
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_mon_add_pids(const unsigned num_pids,
const pid_t *pids,
struct pqos_mon_data *group);
/**
* @brief Remove pids from the resource monitoring grpup
*
* @param [in] num_pids number of pids in \a pids array
* @param [in] pids array of process ID
* @param [in,out] group a pointer to monitoring structure
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_mon_remove_pids(const unsigned num_pids,
const pid_t *pids,
struct pqos_mon_data *group);
/**
* @brief Stops resource monitoring data for selected monitoring group
*
* @param [in] group monitoring context for selected number of cores
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_mon_stop(struct pqos_mon_data *group);
/**
* @brief Polls monitoring data from requested cores
*
* @param [in] groups table of monitoring group pointers to be be updated
* @param [in] num_groups number of monitoring groups in the table
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_mon_poll(struct pqos_mon_data **groups, const unsigned num_groups);
/*
* =======================================
* Allocation Technology
* =======================================
*/
/**
* @brief Associates \a lcore with given class of service
*
* @param [in] lcore CPU logical core id
* @param [in] class_id class of service
*
* @return Operations status
*/
int pqos_alloc_assoc_set(const unsigned lcore, const unsigned class_id);
/**
* @brief Reads association of \a lcore with class of service
*
* @param [in] lcore CPU logical core id
* @param [out] class_id class of service
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_alloc_assoc_get(const unsigned lcore, unsigned *class_id);
/**
* @brief OS interface to associate \a task
* with given class of service
*
* @param [in] task task ID to be associated
* @param [in] class_id class of service
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_alloc_assoc_set_pid(const pid_t task, const unsigned class_id);
/**
* @brief OS interface to read association
* of \a task with class of service
*
* @param [in] task ID to find association
* @param [out] class_id class of service
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_alloc_assoc_get_pid(const pid_t task, unsigned *class_id);
/**
* @brief Assign first available COS to cores in \a core_array
*
* While searching for available COS take technologies it is intended to use
* with into account.
* Note on \a technology and \a core_array selection:
* - if L2 CAT technology is requested then cores need to belong to
* one L2 cluster (same L2ID)
* - if only L3 CAT is requested then cores need to belong to one socket
* - if only MBA is selected then cores need to belong to one socket
*
* @param [in] technology bit mask selecting technologies
* (1 << enum pqos_cap_type)
* @param [in] core_array list of core ids
* @param [in] core_num number of core ids in the \a core_array
* @param [out] class_id place to store reserved COS id
*
* @return Operations status
*/
int pqos_alloc_assign(const unsigned technology,
const unsigned *core_array,
const unsigned core_num,
unsigned *class_id);
/**
* @brief Reassign cores in \a core_array to default COS#0
*
* @param [in] core_array list of core ids
* @param [in] core_num number of core ids in the \a core_array
*
* @return Operations status
*/
int pqos_alloc_release(const unsigned *core_array, const unsigned core_num);
/**
* @brief Assign first available COS to tasks in \a task_array
* Searches all COS directories from highest to lowest
*
* While searching for available COS take technologies it is intended to use
* with into account.
* Note on \a technology parameter:
* - this parameter is currently reserved for future use
* - resctrl (Linux interface) will only provide the highest class id common
* to all supported technologies
*
* @param [in] technology bit mask selecting technologies
* (1 << enum pqos_cap_type)
* @param [in] task_array list of task ids
* @param [in] task_num number of task ids in the \a task_array
* @param [out] class_id place to store reserved COS id
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_alloc_assign_pid(const unsigned technology,
const pid_t *task_array,
const unsigned task_num,
unsigned *class_id);
/**
* @brief Reassign tasks in \a task_array to default COS#0
*
* @param [in] task_array list of task ids
* @param [in] task_num number of task ids in the \a task_array
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_alloc_release_pid(const pid_t *task_array, const unsigned task_num);
/**
* @brief Resets configuration of allocation technologies
*
* Reverts CAT/MBA state to the one after reset:
* - all cores associated with COS0
* - all COS are set to give access to entire resource
*
* As part of allocation reset CDP reconfiguration can be performed.
* This can be requested via \a l3_cdp_cfg, \a l2_cdp_cfg and \a mba_cfg.
*
* @param [in] l3_cdp_cfg requested L3 CAT CDP config
* @param [in] l2_cdp_cfg requested L2 CAT CDP config
* @param [in] mba_cfg requested MBA config
*
* @return Operation status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_alloc_reset(const enum pqos_cdp_config l3_cdp_cfg,
const enum pqos_cdp_config l2_cdp_cfg,
const enum pqos_mba_config mba_cfg);
/*
* =======================================
* L3 cache allocation
* =======================================
*/
/**
* L3 cache allocation class of service data structure
*/
struct pqos_l3ca {
unsigned class_id; /**< class of service */
int cdp; /**< data & code masks used if true */
union {
uint64_t ways_mask; /**< bit mask for L3 cache ways */
struct {
uint64_t data_mask;
uint64_t code_mask;
} s;
} u;
};
/**
* @brief Sets classes of service defined by \a ca on \a l3cat_id
*
* @param [in] l3cat_id L3 CAT resource id
* @param [in] num_cos number of classes of service at \a ca
* @param [in] ca table with class of service definitions
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_l3ca_set(const unsigned l3cat_id,
const unsigned num_cos,
const struct pqos_l3ca *ca);
/**
* @brief Reads classes of service from \a socket
*
* @param [in] l3cat_id L3 CAT resource id
* @param [in] max_num_ca maximum number of classes of service
* that can be accommodated at \a ca
* @param [out] num_ca number of classes of service read into \a ca
* @param [out] ca table with read classes of service
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_l3ca_get(const unsigned l3cat_id,
const unsigned max_num_ca,
unsigned *num_ca,
struct pqos_l3ca *ca);
/**
* @brief Get minimum number of bits which must be set in L3 way mask when
* updating a class of service
*
* @param [out] min_cbm_bits minimum number of bits that must be set
*
* @return Operational status
* @retval PQOS_RETVAL_OK on success
* @retval PQOS_RETVAL_RESOURCE if unable to determine
*/
int pqos_l3ca_get_min_cbm_bits(unsigned *min_cbm_bits);
/*
* =======================================
* L2 cache allocation
* =======================================
*/
/**
* L2 cache allocation class of service data structure
*/
struct pqos_l2ca {
unsigned class_id; /**< class of service */
int cdp; /**< data & code masks used if true */
union {
uint64_t ways_mask; /**< bit mask for L2 cache ways */
struct {
uint64_t data_mask;
uint64_t code_mask;
} s;
} u;
};
/**
* @brief Sets classes of service defined by \a ca on \a l2id
*
* @param [in] l2id unique L2 cache identifier
* @param [in] num_cos number of classes of service at \a ca
* @param [in] ca table with class of service definitions
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_l2ca_set(const unsigned l2id,
const unsigned num_cos,
const struct pqos_l2ca *ca);
/**
* @brief Reads classes of service from \a l2id
*
* @param [in] l2id unique L2 cache identifier
* @param [in] max_num_ca maximum number of classes of service
* that can be accommodated at \a ca
* @param [out] num_ca number of classes of service read into \a ca
* @param [out] ca table with read classes of service
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_l2ca_get(const unsigned l2id,
const unsigned max_num_ca,
unsigned *num_ca,
struct pqos_l2ca *ca);
/**
* @brief Get minimum number of bits which must be set in L2 way mask when
* updating a class of service
*
* @param [out] min_cbm_bits minimum number of bits that must be set
*
* @return Operational status
* @retval PQOS_RETVAL_OK on success
* @retval PQOS_RETVAL_RESOURCE if unable to determine
*/
int pqos_l2ca_get_min_cbm_bits(unsigned *min_cbm_bits);
/*
* =======================================
* Memory Bandwidth Allocation
* =======================================
*/
/**
* MBA class of service data structure
*/
struct pqos_mba {
unsigned class_id; /**< class of service */
unsigned mb_max; /**< maximum available bandwidth in percentage
(without MBA controller) or in MBps
(with MBA controller), depending on ctrl
flag */
int ctrl; /**< MBA controller flag */
};
/**
* @brief Sets classes of service defined by \a mba on \a mba id
*
* @param [in] mba_id MBA resource id
* @param [in] num_cos number of classes of service at \a ca
* @param [in] requested table with class of service definitions
* @param [out] actual table with class of service definitions
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_mba_set(const unsigned mba_id,
const unsigned num_cos,
const struct pqos_mba *requested,
struct pqos_mba *actual);
/**
* @brief Reads MBA from \a mba_id
*
* @param [in] mba_id MBA resource id
* @param [in] max_num_cos maximum number of classes of service
* that can be accommodated at \a mba_tab
* @param [out] num_cos number of classes of service read into \a mba_tab
* @param [out] mba_tab table with read classes of service
*
* @return Operations status
* @retval PQOS_RETVAL_OK on success
*/
int pqos_mba_get(const unsigned mba_id,
const unsigned max_num_cos,
unsigned *num_cos,
struct pqos_mba *mba_tab);
/*
* =======================================
* Utility API
* =======================================
*/
/**
* @brief Retrieves mba id's from cpu info structure
*
* @param [in] cpu CPU information structure from \a pqos_cap_get
* @param [out] count place to store actual number of mba ids returned
*
* @return Allocated array of size \a count populated with mba id's
* @retval NULL on error
*/
unsigned *pqos_cpu_get_mba_ids(const struct pqos_cpuinfo *cpu, unsigned *count);
/**
* @brief Retrieves l3cat id's from cpu info structure
*
* @param [in] cpu CPU information structure from \a pqos_cap_get
* @param [out] count place to store actual number of l3cat ids returned
*
* @return Allocated array of size \a count populated with l3cat id's
* @retval NULL on error
*/
unsigned *pqos_cpu_get_l3cat_ids(const struct pqos_cpuinfo *cpu,
unsigned *count);
/**
* @brief Retrieves socket id's from cpu info structure
*
* @param [in] cpu CPU information structure from \a pqos_cap_get
* @param [out] count place to store actual number of sockets returned
*
* @return Allocated array of size \a count populated with socket id's
* @retval NULL on error
*/
unsigned *pqos_cpu_get_sockets(const struct pqos_cpuinfo *cpu, unsigned *count);
/**
* @brief Retrieves L2 id's from cpu info structure
*
* @param [in] cpu CPU information structure from \a pqos_cap_get
* @param [out] count place to store actual number of L2 id's returned
*
* @return Allocated array of size \a count populated with L2 id's
* @retval NULL on error
*/
unsigned *pqos_cpu_get_l2ids(const struct pqos_cpuinfo *cpu, unsigned *count);
/**
* @brief Creates list of cores belonging to given L3 cluster
*
* Function allocates memory for the core list that needs to be freed by
* the caller.