/usr/include/pqos.h is in intel-cmt-cat 0.1.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /*
* 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 API and data structure definition
*
* API from this file is implemented by the following:
* host_cap.c, host_allocation.c, host_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 103 /**< version 1.03 */
#define PQOS_MAX_L3CA_COS 16 /**< 16xCOS */
/*
* =======================================
* 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 */
/*
* =======================================
* 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 */
};
/**
* PQoS library configuration structure
*/
struct pqos_config {
int fd_log; /**< file descriptor to be used for
library to log messages */
int verbose; /**< if true increases library
verbosity level */
const struct pqos_cpuinfo *topology; /**< application may choose to
pass CPU topology to the library.
In such case, library will not
run its own CPU discovery. */
int free_in_use_rmid; /**< forces the library to take all
cores and RMIDs in the system even
if cores may seem to be subject of
monitoring activity */
enum pqos_cdp_config cdp_cfg; /**< requires CDP as described above */
};
/**
* @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
*/
int pqos_init(const struct pqos_config *config);
/**
* @brief Shuts down PQoS module
*
* @return Operations status
*/
int pqos_fini(void);
/*
* =======================================
* Query capabilities
* =======================================
*/
/**
* Types of possible PQoS capabilities
*
* For now there are:
* - monitoring capability
* - L3 cache allocation capability
*/
enum pqos_cap_type {
PQOS_CAP_TYPE_MON = 0, /**< QoS monitoring */
PQOS_CAP_TYPE_L3CA, /**< LLC cache 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 prioratization feature presence */
int cdp_on; /**< code data prioratization on or off*/
};
/**
* 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) */
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;
unsigned max_rmid; /**< max RMID supported for
this event */
uint32_t scale_factor; /**< factor to scale RMID value
to bytes */
unsigned pid_support; /**< flag to show if PID monitoring
is supported */
};
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;
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 cluster; /**< cluster id in the socket */
};
/**
* CPU topology structure
*/
struct pqos_cpuinfo {
unsigned mem_size; /**< byte size of the structure */
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
*/
int pqos_cap_get(const struct pqos_cap **cap,
const struct pqos_cpuinfo **cpu);
/*
* =======================================
* Monitoring
* =======================================
*/
/**
* Resource Monitoring ID (RMID) definition
*/
typedef uint32_t pqos_rmid_t;
/**
* 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;
};
/**
* 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 */
pid_t pid; /**< if not zero then this group tracks a process */
/**
* Task specific section
*/
int tid_nr;
pid_t *tid_map;
int *fds_llc;
int *fds_mbl;
int *fds_mbt;
int **fds_ipc;
int **fds_misses;
/**
* 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 */
};
/**
* @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
*/
int pqos_mon_assoc_get(const unsigned lcore,
pqos_rmid_t *rmid);
/**
* @brief Starts resource monitoring data logging on \a lcore
*
* 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] lcore CPU logical core id
* @param [in] event monitoring event id
* @param [in] context application dependent context pointer
*
* @return Operations status
*/
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 \a pid process
*
* @param [in] pid process ID
* @param [in] event monitoring event id
* @param [in] context application dependent context pointer
*
* @return Operations status
*/
int pqos_mon_start_pid(const pid_t pid,
const enum pqos_mon_event event,
void *context,
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
*/
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
*/
int pqos_mon_poll(struct pqos_mon_data **groups,
const unsigned num_groups);
/*
* =======================================
* 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;
};
};
};
/**
* @brief Sets classes of service defined by \a ca on \a socket
*
* @param [in] socket CPU socket 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
*/
int pqos_l3ca_set(const unsigned socket,
const unsigned num_cos,
const struct pqos_l3ca *ca);
/**
* @brief Reads classes of service from \a socket
*
* @param [in] socket CPU socket id
* @param [in] max_num_cos maximum number of classes of service
* that can be accommodated at \a ca
* @param [out] num_cos number of classes of service read into \a ca
* @param [out] ca table with read classes of service
*
* @return Operations status
*/
int pqos_l3ca_get(const unsigned socket,
const unsigned max_num_ca,
unsigned *num_ca,
struct pqos_l3ca *ca);
/**
* @brief Associates \a lcore with given L3CA class of service
*
* @param [in] lcore CPU logical core id
* @param [in] class_id L3CA class of service
*
* @return Operations status
*/
int pqos_l3ca_assoc_set(const unsigned lcore,
const unsigned class_id);
/**
* @brief Reads association of \a lcore with L3CA class of service
*
* @param [in] lcore CPU logical core id
* @param [out] class_id L3CA class of service
*
* @return Operations status
*/
int pqos_l3ca_assoc_get(const unsigned lcore,
unsigned *class_id);
/*
* =======================================
* PQoS utility API
* =======================================
*/
/**
* @brief Retrieves socket id's from cpu info structure
*
* @param [in] cpu CPU information structure from \a pqos_cap_get
* @param [in] max_count maximum number of sockets that \a sockets can accommodate
* @param [out] count place to store actual number of sockets returned
* @param [out] sockets array to store socket id's in
*
* @return Operation status
* @retval PQOS_RETVAL_OK on success
*/
int
pqos_cpu_get_sockets(const struct pqos_cpuinfo *cpu,
const unsigned max_count,
unsigned *count,
unsigned *sockets);
/**
* @brief Retrieves number of sockets in CPU topology
*
* @param [in] cpu CPU information structure from \a pqos_cap_get
* @param [out] count place to store actual number of sockets returned
*
* @return Operation status
* @retval PQOS_RETVAL_OK on success
*/
int
pqos_cpu_get_num_sockets(const struct pqos_cpuinfo *cpu,
unsigned *count);
/**
* @brief Retrieves core id's from cpu info structure for \a socket
*
* @param [in] cpu CPU information structure from cpu info module
* @param [in] socket CPU socket id to enumerate
* @param [in] max_count maximum number of core id's that
* \a cores array can accommodate
* @param [out] count place to store actual number of core id's returned
* @param [out] cores array to store core id's in
*
* @return Operation status
* @retval PQOS_RETVAL_OK on success
*/
int
pqos_cpu_get_cores(const struct pqos_cpuinfo *cpu,
const unsigned socket,
const unsigned max_count,
unsigned *count,
unsigned *cores);
/**
* @brief Verifies if \a core is a valid logical core id
*
* @param [in] cpu CPU information structure from cpu info module
* @param [in] lcore logical core id
*
* @return Operation status
* @retval PQOS_RETVAL_OK on success
*/
int
pqos_cpu_check_core(const struct pqos_cpuinfo *cpu,
const unsigned lcore);
/**
* @brief Retrieves socket id for given \logical core id
*
* @param [in] cpu CPU information structure from cpu info module
* @param [in] lcore logical core id
* @param [out] socket location to store socket id at
*
* @return Operation status
* @retval PQOS_RETVAL_OK on success
*/
int
pqos_cpu_get_socketid(const struct pqos_cpuinfo *cpu,
const unsigned lcore,
unsigned *socket);
/**
* @brief Retrieves monitoring cluster id for given logical core id
*
* @param [in] cpu CPU information structure from cpu info module
* @param [in] lcore logical core id
* @param [out] cluster location to store cluster id at
*
* @return Operation status
* @retval PQOS_RETVAL_OK on success
*/
int
pqos_cpu_get_clusterid(const struct pqos_cpuinfo *cpu,
const unsigned lcore,
unsigned *cluster);
/**
* @brief Retrieves \a type of capability from \a cap structure
*
* @param [in] cap platform QoS capabilities structure
* returned by \a pqos_cap_get
* @param [in] type capability type to look for
* @param [out] cap_item place to store pointer to selected capability
*
* @return Operation status
* @retval PQOS_RETVAL_OK on success
*/
int
pqos_cap_get_type(const struct pqos_cap *cap,
const enum pqos_cap_type type,
const struct pqos_capability **cap_item);
/**
* @brief Retrieves \a monitoring event data from \a cap structure
*
* @param [in] cap platform QoS capabilities structure
* returned by \a pqos_cap_get
* @param [in] event monitoring event type to look for
* @param [out] p_mon place to store pointer to selected event capabilities
*
* @return Operation status
* @retval PQOS_RETVAL_OK on success
*/
int
pqos_cap_get_event(const struct pqos_cap *cap,
const enum pqos_mon_event event,
const struct pqos_monitor **p_mon);
/**
* @brief Retrieves number of allocation classes of service from \a cap structure.
*
* @param [in] cap platform QoS capabilities structure
* returned by \a pqos_cap_get
* @param [out] cos_num place to store number of classes of service
*
* @return Operation status
* @retval PQOS_RETVAL_OK on success
*/
int
pqos_l3ca_get_cos_num(const struct pqos_cap *cap,
unsigned *cos_num);
/**
* @brief Retrieves CDP status
*
* @param [in] cap platform QoS capabilities structure
* returned by \a pqos_cap_get
* @param [out] cdp_supported place to store CDP support status
* @param [out] cdp_enabled place to store CDP enable status
*
* @return Operation status
* @retval PQOS_RETVAL_OK on success
*/
int
pqos_l3ca_cdp_enabled(const struct pqos_cap *cap,
int *cdp_supported,
int *cdp_enabled);
/**
* @brief Resets configuration of cache allocation technology
*
* Reverts CAT state to the one after reset:
* - all cores associated with COS0
* - all COS are set to give access to all cache ways
*
* @param [in] cap platform QoS capabilities structure
* returned by \a pqos_cap_get
* @param [in] cpu CPU information structure from cpu info module
*
* @return Operation status
* @retval PQOS_RETVAL_OK on success
*/
int
pqos_l3ca_reset(const struct pqos_cap *cap,
const struct pqos_cpuinfo *cpu);
/**
* @brief Retrieves a monitoring value from a group for a specific event.
* @param [out] value monitoring value
* @param [in] event_id event being monitored
* @param [in] group monitoring group
*
* @return Operation status
* @retval PQOS_RETVAL_OK on success
*/
static inline int
pqos_mon_get_event_value(void * const value,
const enum pqos_mon_event event_id,
const struct pqos_mon_data * const group)
{
uint64_t * const p_64 = value;
double * const p_dbl = value;
if (group == NULL || value == NULL)
return PQOS_RETVAL_PARAM;
switch (event_id) {
case PQOS_MON_EVENT_L3_OCCUP:
*p_64 = group->values.llc;
break;
case PQOS_MON_EVENT_LMEM_BW:
*p_64 = group->values.mbm_local_delta;
break;
case PQOS_MON_EVENT_TMEM_BW:
*p_64 = group->values.mbm_total_delta;
break;
case PQOS_MON_EVENT_RMEM_BW:
*p_64 = group->values.mbm_remote_delta;
break;
case PQOS_PERF_EVENT_IPC:
*p_dbl = group->values.ipc;
break;
case PQOS_PERF_EVENT_LLC_MISS:
*p_64 = group->values.llc_misses_delta;
break;
default:
return PQOS_RETVAL_PARAM;
}
return PQOS_RETVAL_OK;
}
#ifdef __cplusplus
}
#endif
#endif /* __PQOS_H__ */
|