Skip to content

Commit

Permalink
pqos: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksinx authored Apr 20, 2022
1 parent 8542fbc commit 6e1b53f
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 84 deletions.
131 changes: 67 additions & 64 deletions pqos/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <ctype.h> /**< isspace() */
#include <fcntl.h>
#include <getopt.h> /**< getopt_long() */
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -55,6 +56,8 @@

#define FILE_READ_WRITE (0600)

#define DEFAULT_TABLE_SIZE 128

/**
* Default L3 CDP configuration option - don't enforce on or off
*/
Expand Down Expand Up @@ -131,19 +134,11 @@ static int sel_interface_selected = 0;
static int sel_print_version = 0;

#ifdef PQOS_RMID_CUSTOM
/** rmid table max elements */
unsigned rmid_map_rmid_max_elems = 128;
/** core table max elements */
unsigned rmid_map_core_max_elems = 128;

/** rmid table */
static pqos_rmid_t *sel_rmid_map_rmid = NULL;
/** core table */
static unsigned *sel_rmid_map_core = NULL;
static unsigned sel_rmid_size = 0;

/** Custom RMID configuration */
static struct pqos_rmid_config sel_rmid_cfg = {
PQOS_RMID_TYPE_DEFAULT,
{0, sel_rmid_map_rmid, sel_rmid_map_core}};
static struct pqos_rmid_config sel_rmid_cfg = {PQOS_RMID_TYPE_DEFAULT,
{0, NULL, NULL}};
#endif

/**
Expand Down Expand Up @@ -564,12 +559,60 @@ selfn_display_verbose(const char *arg)
sel_display_verbose = 1;
}

#ifdef PQOS_RMID_CUSTOM
/**
* @brief Sets custom RMID mapping for the core
*
* @param [in] lcore logical core
* @param [in] rmid selected RMID
*
* @return Operation status
* @retval 0 OK
* @retval -1 error
*/
static int
monitor_rmid_set(unsigned lcore, pqos_rmid_t rmid)
{
/* allocate more memory */
if (sel_rmid_cfg.map.num >= sel_rmid_size) {
unsigned size = sel_rmid_size;
unsigned *core = sel_rmid_cfg.map.core;
pqos_rmid_t *rmid = sel_rmid_cfg.map.rmid;

if (size == 0)
size = DEFAULT_TABLE_SIZE;
else
size *= 2;

core = realloc(sel_rmid_cfg.map.core, size * sizeof(*core));
if (core == NULL) {
fprintf(stderr, "Error with memory allocation!\n");
return -1;
}
sel_rmid_cfg.map.core = core;

rmid = realloc(sel_rmid_cfg.map.rmid, size * sizeof(*rmid));
if (rmid == NULL) {
fprintf(stderr, "Error with memory allocation!\n");
return -1;
}
sel_rmid_cfg.map.rmid = rmid;

sel_rmid_size = size;
}

sel_rmid_cfg.map.core[sel_rmid_cfg.map.num] = lcore;
sel_rmid_cfg.map.rmid[sel_rmid_cfg.map.num] = rmid;
sel_rmid_cfg.map.num++;

return 0;
}

/**
* @brief Selects custom RMID mapping
*
* @param arg string passed to --rmid command line option
*/
#ifdef PQOS_RMID_CUSTOM
static void
selfn_monitor_rmids(const char *arg)
{
Expand All @@ -592,7 +635,7 @@ selfn_monitor_rmids(const char *arg)
char *p = NULL;
pqos_rmid_t rmid;
unsigned count;
unsigned core_list_size = 128;
unsigned core_list_size = DEFAULT_TABLE_SIZE;
unsigned i;

token = strtok_r(str, ";", &saveptr);
Expand All @@ -615,33 +658,13 @@ selfn_monitor_rmids(const char *arg)
count = strlisttotabrealloc(p + 1, &cores, &core_list_size);

for (i = 0; i < count; i++) {
sel_rmid_cfg.map.core[sel_rmid_cfg.map.num] =
(unsigned)cores[i];
sel_rmid_cfg.map.rmid[sel_rmid_cfg.map.num] = rmid;
sel_rmid_cfg.map.num++;
if (sel_rmid_cfg.map.num >= rmid_map_rmid_max_elems) {
sel_rmid_cfg.map.rmid = realloc_and_init(
sel_rmid_cfg.map.rmid,
&rmid_map_rmid_max_elems,
sizeof(*sel_rmid_cfg.map.rmid));
if (sel_rmid_cfg.map.rmid == NULL) {
printf("Error with memory "
"reallocation!\n");
goto error_exit;
}
}
if (sel_rmid_cfg.map.num >= rmid_map_core_max_elems) {
sel_rmid_cfg.map.core = realloc_and_init(
sel_rmid_cfg.map.core,
&rmid_map_core_max_elems,
sizeof(*sel_rmid_cfg.map.core));
if (sel_rmid_cfg.map.core == NULL) {
printf("Error with memory "
"reallocation!\n");
goto error_exit;
}
}
if (cores[i] > UINT_MAX)
goto error_exit;

if (monitor_rmid_set((unsigned)cores[i], rmid) < 0)
goto error_exit;
}

free(cores);
cores = NULL;
}
Expand Down Expand Up @@ -1075,26 +1098,6 @@ main(int argc, char **argv)
m_cmd_name = argv[0];
print_warning();

#ifdef PQOS_RMID_CUSTOM
sel_rmid_map_rmid =
calloc(rmid_map_rmid_max_elems, sizeof(*sel_rmid_map_rmid));
if (sel_rmid_map_rmid == NULL) {
printf("Error with memory allocation!\n");
exit_val = EXIT_FAILURE;
goto error_exit_1;
}
sel_rmid_map_core =
calloc(rmid_map_core_max_elems, sizeof(*sel_rmid_map_core));
if (sel_rmid_map_core == NULL) {
printf("Error with memory allocation!\n");
exit_val = EXIT_FAILURE;
goto error_exit_1;
}
sel_rmid_cfg.type = PQOS_RMID_TYPE_DEFAULT;
sel_rmid_cfg.map.num = 0;
sel_rmid_cfg.map.rmid = sel_rmid_map_rmid;
sel_rmid_cfg.map.core = sel_rmid_map_core;
#endif
memset(&cfg, 0, sizeof(cfg));

while ((cmd = getopt_long(argc, argv,
Expand Down Expand Up @@ -1486,10 +1489,10 @@ main(int argc, char **argv)
if (l3cat_ids != NULL)
free(l3cat_ids);
#ifdef PQOS_RMID_CUSTOM
if (sel_rmid_map_rmid != NULL)
free(sel_rmid_map_rmid);
if (sel_rmid_map_core != NULL)
free(sel_rmid_map_core);
if (sel_rmid_cfg.map.core != NULL)
free(sel_rmid_cfg.map.core);
if (sel_rmid_cfg.map.rmid != NULL)
free(sel_rmid_cfg.map.rmid);
#endif
return exit_val;
}
10 changes: 2 additions & 8 deletions pqos/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,20 @@ void selfn_monitor_disable_llc_miss(const char *arg);
* @brief Check to determine if processes are monitored
*
* @return Process monitoring mode status
* @retval 0 monitoring cores
* @retval 1 monitoring processes
*/
int monitor_process_mode(void);

/**
* @brief Check to determine if cores are monitored
*
* @return Process monitoring mode status
* @retval 0 monitoring cores
* @retval 1 monitoring processes
* @return Core monitoring mode status
*/
int monitor_core_mode(void);

/**
* @brief Check to determine if uncore monitoring is started
*
* @return Process monitoring mode status
* @retval 0 monitoring cores
* @retval 1 monitoring processes
* @return Uncore monitoring mode status
*/
int monitor_uncore_mode(void);

Expand Down
8 changes: 4 additions & 4 deletions pqos/monitor_csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ monitor_csv_begin(FILE *fp)
#ifdef PQOS_RMID_CUSTOM
enum pqos_interface iface;

pqos_get_inter(&iface);
pqos_inter_get(&iface);
if (iface == PQOS_INTER_MSR)
fprintf(hdr, ",RMID");
fprintf(fp, ",RMID");
#endif
} else if (monitor_process_mode())
fprintf(fp, "Time,PID,Core");
Expand Down Expand Up @@ -158,14 +158,14 @@ monitor_csv_row(FILE *fp,
#ifdef PQOS_RMID_CUSTOM
enum pqos_interface iface;

pqos_get_inter(&iface);
pqos_inter_get(&iface);
if (iface == PQOS_INTER_MSR) {
pqos_rmid_t rmid;
int ret = pqos_mon_assoc_get(mon_data->cores[0], &rmid);

offset += fillin_csv_column(
",%.0f", rmid, data + offset, sz_data - offset,
ret == PQOS_RETVAL_OK, sel_interface == PQOS_INTER_MSR);
ret == PQOS_RETVAL_OK, iface == PQOS_INTER_MSR);
}
#endif

Expand Down
6 changes: 3 additions & 3 deletions pqos/monitor_text.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ monitor_text_header(FILE *fp, const char *timestamp)
#ifdef PQOS_RMID_CUSTOM
enum pqos_interface iface;

pqos_get_inter(&iface);
pqos_inter_get(&iface);
if (iface == PQOS_INTER_MSR)
fprintf(fp, " RMID");
#endif
Expand Down Expand Up @@ -167,14 +167,14 @@ monitor_text_row(FILE *fp,
#ifdef PQOS_RMID_CUSTOM
enum pqos_interface iface;

pqos_get_inter(&iface);
pqos_inter_get(&iface);
if (iface == PQOS_INTER_MSR) {
pqos_rmid_t rmid;
int ret = pqos_mon_assoc_get(mon_data->cores[0], &rmid);

offset += fillin_text_column(
" %4.0f", (double)rmid, data + offset, sz_data - offset,
ret == PQOS_RETVAL_OK, sel_interface == PQOS_INTER_MSR);
ret == PQOS_RETVAL_OK, iface == PQOS_INTER_MSR);
}
#endif
struct {
Expand Down
9 changes: 4 additions & 5 deletions pqos/monitor_xml.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,14 @@ monitor_xml_row(FILE *fp,
#ifdef PQOS_RMID_CUSTOM
enum pqos_interface iface;

pqos_get_inter(&iface);
pqos_inter_get(&iface);
if (iface == PQOS_INTER_MSR) {
pqos_rmid_t rmid;
int ret = pqos_mon_assoc_get(mon_data->cores[0], &rmid);

offset +=
fillin_xml_column("%.0f", rmid, data + offset,
sz_data - offset, ret == PQOS_RETVAL_OK,
sel_interface == PQOS_INTER_MSR, "rmid");
offset += fillin_xml_column(
"%.0f", rmid, data + offset, sz_data - offset,
ret == PQOS_RETVAL_OK, iface == PQOS_INTER_MSR, "rmid");
}
#endif

Expand Down

0 comments on commit 6e1b53f

Please sign in to comment.