/** * @brief Initializes PQoS library * * To satisfy dlock_init() requirements CAT is reset here. * More sophisticated solution would be to look for unused CLOS here and * pass it on to dlock_init(). * * @return Operation status * @retval 0 OK * @retval <0 error */ static int init_pqos(void) { const struct pqos_cpuinfo *p_cpu = NULL; const struct pqos_cap *p_cap = NULL; struct pqos_config cfg; int ret; memset(&cfg, 0, sizeof(cfg)); cfg.fd_log = STDOUT_FILENO; cfg.verbose = 0; ret = pqos_init(&cfg); if (ret != PQOS_RETVAL_OK) { printf("Error initializing PQoS library!\n"); return -1; } /* Get CMT capability and CPU info pointer */ ret = pqos_cap_get(&p_cap, &p_cpu); if (ret != PQOS_RETVAL_OK) { pqos_fini(); printf("Error retrieving PQoS capabilities!\n"); return -1; } /* Reset CAT */ ret = pqos_alloc_reset(PQOS_REQUIRE_CDP_ANY); if (ret != PQOS_RETVAL_OK) { pqos_fini(); printf("Error resetting CAT!\n"); return -1; } return 0; }
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_l3ca = NULL; unsigned sock_count, *sockets = NULL; int ret, exit_val = EXIT_SUCCESS; memset(&cfg, 0, sizeof(cfg)); cfg.fd_log = STDOUT_FILENO; cfg.verbose = 0; /* PQoS Initialization - Check and initialize CAT and CMT capability */ ret = pqos_init(&cfg); if (ret != PQOS_RETVAL_OK) { printf("Error initializing PQoS library!\n"); exit_val = EXIT_FAILURE; goto error_exit; } /* Get CMT capability and CPU info pointer */ 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; } if (argc == 2 && (!strcmp(argv[1], "-h") || !strcmp(argv[1], "-H"))) { printf("Usage: %s\n\n", argv[0]); goto error_exit; } /* Reset Api */ ret = pqos_alloc_reset(PQOS_REQUIRE_CDP_ANY, PQOS_REQUIRE_CDP_ANY, PQOS_MBA_ANY); if (ret != PQOS_RETVAL_OK) printf("CAT reset failed!\n"); else printf("CAT reset successful\n"); /* Get CPU socket information to set COS */ sockets = pqos_cpu_get_sockets(p_cpu, &sock_count); if (sockets == NULL) { printf("Error retrieving CPU socket information!\n"); exit_val = EXIT_FAILURE; goto error_exit; } (void) pqos_cap_get_type(p_cap, PQOS_CAP_TYPE_L3CA, &cap_l3ca); /* Print COS and associated cores */ print_allocation_config(cap_l3ca, sock_count, sockets, p_cpu); error_exit: /* reset and deallocate all the resources */ ret = pqos_fini(); if (ret != PQOS_RETVAL_OK) printf("Error shutting down PQoS library!\n"); if (sockets != NULL) free(sockets); return exit_val; }