Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support event aliases in pmcstat #1514

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions lib/libpmc/libpmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1103,22 +1103,29 @@ pmc_allocate(const char *ctrspec, enum pmc_mode mode,
pmc_config.pm_caps = 0;
pmc_config.pm_class = 0;
}
free(spec_copy);
spec_copy = NULL;

/* replace an event alias with the canonical event specifier */
if (pmc_mdep_event_aliases)
for (alias = pmc_mdep_event_aliases; alias->pm_alias; alias++)
if (!strcasecmp(ctrspec, alias->pm_alias)) {
spec_copy = strdup(alias->pm_spec);
if (!strcasecmp(ctrname, alias->pm_alias)) {
/* Aliases must not contain a comma. */
if (strchr(alias->pm_alias, ',')) {
errno = EDOOFUS;
goto out;
}
ctrname = alias->pm_spec;
break;
}

if (spec_copy == NULL)
spec_copy = strdup(ctrspec);

r = spec_copy;
ctrname = strsep(&r, ",");
/* Try pmu_alias_get as another generic fallback. */
const char* alias_name = _pmu_alias_get(ctrname);
if (alias_name != ctrname) {
/* Aliases must not contain a comma. */
if (strchr(alias_name, ',')) {
errno = EDOOFUS;
goto out;
}
ctrname = alias_name;
}

/*
* If a explicit class prefix was given by the user, restrict the
Expand Down Expand Up @@ -1167,8 +1174,7 @@ pmc_allocate(const char *ctrspec, enum pmc_mode mode,
retval = 0;
}
out:
if (spec_copy)
free(spec_copy);
free(spec_copy);

return (retval);
}
Expand Down
28 changes: 15 additions & 13 deletions lib/libpmc/libpmc_pmu_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <pmclog.h>
#include <assert.h>
#include <libpmcstat.h>
#include "libpmcinternal.h"
#include "pmu-events/pmu-events.h"

struct pmu_alias {
Expand Down Expand Up @@ -132,8 +133,8 @@ pmu_events_mfr(void)
*
*/

static const char *
pmu_alias_get(const char *name)
const char *
_pmu_alias_get(const char *name)
{
pmu_mfr_t mfr;
struct pmu_alias *pa;
Expand All @@ -156,8 +157,8 @@ pmu_alias_get(const char *name)
}
#elif defined(__powerpc64__)

static const char *
pmu_alias_get(const char *name)
const char *
_pmu_alias_get(const char *name)
{
return (name);
}
Expand All @@ -175,6 +176,7 @@ static struct pmu_alias pmu_armv8_alias_table[] = {
{"BRANCH-INSTRUCTION-RETIRED", "BR_RETIRED"},
{"BRANCH_MISSES_RETIRED", "BR_MIS_PRED_RETIRED"},
{"BRANCH-MISSES-RETIRED", "BR_MIS_PRED_RETIRED"},
{"cycles", "CPU_CYCLES"},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The x86 tables in here don't have this either

{"unhalted-cycles", "CPU_CYCLES"},
{"instructions", "INST_RETIRED",},
{"branch-mispredicts", "BR_MIS_PRED_RETIRED"},
Expand All @@ -183,8 +185,8 @@ static struct pmu_alias pmu_armv8_alias_table[] = {
{NULL, NULL},
};

static const char *
pmu_alias_get(const char *name)
const char *
_pmu_alias_get(const char *name)
{
struct pmu_alias *pa;

Expand All @@ -197,8 +199,8 @@ pmu_alias_get(const char *name)

#else

static const char *
pmu_alias_get(const char *name)
const char *
_pmu_alias_get(const char *name)
{

return (name);
Expand Down Expand Up @@ -284,7 +286,7 @@ pmc_pmu_idx_get_by_event(const char *cpuid, const char *event)
int idx;
const char *realname;

realname = pmu_alias_get(event);
realname = _pmu_alias_get(event);
if (pmu_event_get(cpuid, realname, &idx) == NULL)
return (-1);
return (idx);
Expand Down Expand Up @@ -365,7 +367,7 @@ pmc_pmu_sample_rate_get(const char *event_name)
const struct pmu_event *pe;
struct pmu_event_desc ped;

event_name = pmu_alias_get(event_name);
event_name = _pmu_alias_get(event_name);
if ((pe = pmu_event_get(NULL, event_name, NULL)) == NULL)
return (DEFAULT_SAMPLE_COUNT);
if (pe->event == NULL)
Expand Down Expand Up @@ -587,7 +589,7 @@ pmc_pmu_pmcallocate(const char *event_name, struct pmc_op_pmcallocate *pm)

bzero(&pm->pm_md, sizeof(pm->pm_md));
pm->pm_caps |= (PMC_CAP_READ | PMC_CAP_WRITE);
event_name = pmu_alias_get(event_name);
event_name = _pmu_alias_get(event_name);
if ((pe = pmu_event_get(NULL, event_name, &idx)) == NULL)
return (ENOENT);
assert(idx >= 0);
Expand Down Expand Up @@ -615,7 +617,7 @@ pmc_pmu_pmcallocate(const char *event_name, struct pmc_op_pmcallocate *pm)

bzero(&pm->pm_md, sizeof(pm->pm_md));
pm->pm_caps |= (PMC_CAP_READ | PMC_CAP_WRITE);
event_name = pmu_alias_get(event_name);
event_name = _pmu_alias_get(event_name);

if ((pe = pmu_event_get(NULL, event_name, &idx)) == NULL)
return (ENOENT);
Expand All @@ -640,7 +642,7 @@ pmc_pmu_pmcallocate(const char *event_name, struct pmc_op_pmcallocate *pm)
struct pmu_event_desc ped;
int idx = -1;

event_name = pmu_alias_get(event_name);
event_name = _pmu_alias_get(event_name);
if ((pe = pmu_event_get(NULL, event_name, &idx)) == NULL)
return (ENOENT);
if (pe->event == NULL)
Expand Down
1 change: 1 addition & 0 deletions lib/libpmc/libpmcinternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@
* Prototypes.
*/
const char *_pmc_name_of_event(enum pmc_event _ev, enum pmc_cputype _cpu);
const char *_pmu_alias_get(const char *name);

#endif /* LIBPMC_INTERNAL_H */
Loading