Skip to content

Commit

Permalink
selftests/resctrl: Consolidate naming of perf event related things
Browse files Browse the repository at this point in the history
Naming for perf event related functions, types, and variables is
inconsistent.

Make struct read_format and all functions related to perf events start
with "perf_". Adjust variable names towards the same direction but use
shorter names for variables where appropriate (pe prefix).

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
  • Loading branch information
Ilpo Järvinen authored and Shuah Khan committed Feb 13, 2024
1 parent 3c6bfc9 commit b6e6a58
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions tools/testing/selftests/resctrl/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
#include <stdint.h>
#include "resctrl.h"

struct read_format {
struct perf_event_read {
__u64 nr; /* The number of events */
struct {
__u64 value; /* The value of the event */
} values[2];
};

static struct perf_event_attr pea_llc_miss;
static struct read_format rf_cqm;
static int fd_lm;
static struct perf_event_read pe_read;
static int pe_fd;
char llc_occup_path[1024];

static void initialize_perf_event_attr(void)
static void perf_event_attr_initialize(void)
{
pea_llc_miss.type = PERF_TYPE_HARDWARE;
pea_llc_miss.size = sizeof(struct perf_event_attr);
Expand All @@ -30,34 +30,34 @@ static void initialize_perf_event_attr(void)
}

/* Start counters to log values */
static void ioctl_perf_event_ioc_reset_enable(void)
static void perf_event_reset_enable(void)
{
ioctl(fd_lm, PERF_EVENT_IOC_RESET, 0);
ioctl(fd_lm, PERF_EVENT_IOC_ENABLE, 0);
ioctl(pe_fd, PERF_EVENT_IOC_RESET, 0);
ioctl(pe_fd, PERF_EVENT_IOC_ENABLE, 0);
}

static void initialize_llc_perf(void)
static void perf_event_initialize(void)
{
memset(&pea_llc_miss, 0, sizeof(struct perf_event_attr));
memset(&rf_cqm, 0, sizeof(struct read_format));
memset(&pe_read, 0, sizeof(struct perf_event_read));

/* Initialize perf_event_attr structures for HW_CACHE_MISSES */
initialize_perf_event_attr();
perf_event_attr_initialize();

pea_llc_miss.config = PERF_COUNT_HW_CACHE_MISSES;

rf_cqm.nr = 1;
pe_read.nr = 1;
}

static int reset_enable_llc_perf(pid_t pid, int cpu_no)
static int perf_open(pid_t pid, int cpu_no)
{
fd_lm = perf_event_open(&pea_llc_miss, pid, cpu_no, -1, PERF_FLAG_FD_CLOEXEC);
if (fd_lm == -1) {
pe_fd = perf_event_open(&pea_llc_miss, pid, cpu_no, -1, PERF_FLAG_FD_CLOEXEC);
if (pe_fd == -1) {
ksft_perror("Error opening leader");
return -1;
}

ioctl_perf_event_ioc_reset_enable();
perf_event_reset_enable();

return 0;
}
Expand Down Expand Up @@ -141,15 +141,15 @@ static int perf_event_measure(const char *filename, int bm_pid)
int ret;

/* Stop counters after one span to get miss rate */
ioctl(fd_lm, PERF_EVENT_IOC_DISABLE, 0);
ioctl(pe_fd, PERF_EVENT_IOC_DISABLE, 0);

ret = read(fd_lm, &rf_cqm, sizeof(struct read_format));
ret = read(pe_fd, &pe_read, sizeof(struct perf_event_read));
if (ret == -1) {
ksft_perror("Could not get perf value");
return -1;
}

return print_results_cache(filename, bm_pid, rf_cqm.values[0].value);
return print_results_cache(filename, bm_pid, pe_read.values[0].value);
}

/*
Expand Down Expand Up @@ -204,7 +204,7 @@ int cat_val(struct resctrl_val_param *param, size_t span)
if (ret)
return ret;

initialize_llc_perf();
perf_event_initialize();

/* Test runs until the callback setup() tells the test to stop. */
while (1) {
Expand All @@ -215,7 +215,7 @@ int cat_val(struct resctrl_val_param *param, size_t span)
}
if (ret < 0)
break;
ret = reset_enable_llc_perf(bm_pid, param->cpu_no);
ret = perf_open(bm_pid, param->cpu_no);
if (ret)
break;

Expand All @@ -234,7 +234,7 @@ int cat_val(struct resctrl_val_param *param, size_t span)
return ret;

pe_close:
close(fd_lm);
close(pe_fd);
return ret;
}

Expand Down

0 comments on commit b6e6a58

Please sign in to comment.