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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/libpmc/libpmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,12 @@ pmc_allocate(const char *ctrspec, enum pmc_mode mode,
break;
}

/* Try pmu_alias_get as another generic fallback/ */
if (spec_copy == NULL) {
const char* alias_name = _pmu_alias_get(ctrspec);
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/const char* /const char */

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

Expand Down
27 changes: 14 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 @@ -183,8 +184,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 +198,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 +285,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 +366,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 +588,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 +616,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 +641,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 */