From 3fd0ce4f0d022f2babc0d6d17be8b02039381047 Mon Sep 17 00:00:00 2001 From: Thomas Roehl Date: Fri, 18 Jun 2021 18:13:47 +0200 Subject: [PATCH] Fix for NEST counters on IBM POWER9 due to renaming in perf_event --- src/includes/perfmon_perfevent.h | 57 +++++++++++++++++++++++--------- src/includes/perfmon_types.h | 1 + 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/src/includes/perfmon_perfevent.h b/src/includes/perfmon_perfevent.h index 7a5fbbe8e..3a9bcc00d 100644 --- a/src/includes/perfmon_perfevent.h +++ b/src/includes/perfmon_perfevent.h @@ -163,6 +163,7 @@ static char* perfEventOptionNames[] = { #ifdef _ARCH_PPC [EVENT_OPTION_PMC] = "pmc", [EVENT_OPTION_PMCXSEL] = "pmcxsel", + [EVENT_OPTION_UNCORE_CONFIG] = "event", #endif }; @@ -490,6 +491,7 @@ int perf_uncore_setup(struct perf_event_attr *attr, RegisterType type, PerfmonEv int perf_type = 0; PERF_EVENT_PMC_OPT_REGS reg = PERF_EVENT_INVAL_REG; int start = 0, end = -1; + uint64_t eventConfig = 0x0; if (perf_event_paranoid > 0 && getuid() != 0) { return EPERM; @@ -525,32 +527,57 @@ int perf_uncore_setup(struct perf_event_attr *attr, RegisterType type, PerfmonEv attr->type = perf_type; attr->disabled = 1; attr->inherit = 1; - //attr->config = (event->umask<<8) + event->eventId; +#ifdef _ARCH_PPC + eventConfig = (event->umask<<8)|event->eventId; +#else + eventConfig = event->eventId; +#endif getEventOptionConfig(translate_types[type], EVENT_OPTION_GENERIC_CONFIG, ®, &start, &end); switch(reg) { case PERF_EVENT_CONFIG_REG: - attr->config |= create_mask(event->eventId, start, end); + attr->config |= create_mask(eventConfig, start, end); break; case PERF_EVENT_CONFIG1_REG: - attr->config1 |= create_mask(event->eventId, start, end); + attr->config1 |= create_mask(eventConfig, start, end); break; case PERF_EVENT_CONFIG2_REG: - attr->config2 |= create_mask(event->eventId, start, end); + attr->config2 |= create_mask(eventConfig, start, end); break; } - getEventOptionConfig(translate_types[type], EVENT_OPTION_GENERIC_UMASK, ®, &start, &end); - switch(reg) +#ifdef _ARCH_PPC + if (reg == PERF_EVENT_INVAL_REG) { - case PERF_EVENT_CONFIG_REG: - attr->config |= create_mask(event->umask, start, end); - break; - case PERF_EVENT_CONFIG1_REG: - attr->config1 |= create_mask(event->umask, start, end); - break; - case PERF_EVENT_CONFIG2_REG: - attr->config2 |= create_mask(event->umask, start, end); - break; + getEventOptionConfig(translate_types[type], EVENT_OPTION_UNCORE_CONFIG, ®, &start, &end); + switch(reg) + { + case PERF_EVENT_CONFIG_REG: + attr->config |= create_mask(eventConfig, start, end); + break; + case PERF_EVENT_CONFIG1_REG: + attr->config1 |= create_mask(eventConfig, start, end); + break; + case PERF_EVENT_CONFIG2_REG: + attr->config2 |= create_mask(eventConfig, start, end); + break; + } + } +#endif + if (event->umask != 0x0) + { + getEventOptionConfig(translate_types[type], EVENT_OPTION_GENERIC_UMASK, ®, &start, &end); + switch(reg) + { + case PERF_EVENT_CONFIG_REG: + attr->config |= create_mask(event->umask, start, end); + break; + case PERF_EVENT_CONFIG1_REG: + attr->config1 |= create_mask(event->umask, start, end); + break; + case PERF_EVENT_CONFIG2_REG: + attr->config2 |= create_mask(event->umask, start, end); + break; + } } diff --git a/src/includes/perfmon_types.h b/src/includes/perfmon_types.h index 208e1fdbf..a4002c444 100644 --- a/src/includes/perfmon_types.h +++ b/src/includes/perfmon_types.h @@ -90,6 +90,7 @@ typedef enum { #ifdef _ARCH_PPC EVENT_OPTION_PMC, EVENT_OPTION_PMCXSEL, + EVENT_OPTION_UNCORE_CONFIG, /*!< \brief Configuration bitmask for NEST (uncore) counters */ #endif NUM_EVENT_OPTIONS /*!< \brief Amount of defined options */ } EventOptionType;