Skip to content

Commit

Permalink
libpmc: enable pmu_utils on arm64
Browse files Browse the repository at this point in the history
This allows supported libpmc to query/select from the pmu-events table,
which may have a more complete set of events than what we define
manually. A future update to these definitions should greatly improve
this support. The alias table is empty for now, until this future import
is complete.

Add the Foundation's copyright for recent work on this file.

Reviewed by:	ray (slightly earlier version)
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D30603
  • Loading branch information
mhorne committed Jun 30, 2021
1 parent 8cc3815 commit 28dd673
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions lib/libpmc/libpmc_pmu_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2018, Matthew Macy
* Copyright (c) 2021, The FreeBSD Foundation
*
* Portions of this software were developed by Mitchell Horne
* under sponsorship from the FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -139,6 +143,24 @@ pmu_alias_get(const char *name)
return (name);
}

#elif defined(__aarch64__)

static struct pmu_alias pmu_armv8_alias_table[] = {
{NULL, NULL},
};

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

for (pa = pmu_armv8_alias_table; pa->pa_alias != NULL; pa++)
if (strcasecmp(name, pa->pa_alias) == 0)
return (pa->pa_name);

return (name);
}

#else

static const char *
Expand Down Expand Up @@ -549,6 +571,28 @@ pmc_pmu_pmcallocate(const char *event_name, struct pmc_op_pmcallocate *pm)
return (pmc_pmu_amd_pmcallocate(event_name, pm, &ped));
}

#elif defined(__aarch64__)

int
pmc_pmu_pmcallocate(const char *event_name, struct pmc_op_pmcallocate *pm)
{
const struct pmu_event *pe;
int idx = -1;

event_name = pmu_alias_get(event_name);
if ((pe = pmu_event_get(NULL, event_name, &idx)) == NULL)
return (ENOENT);
if (pe->event == NULL)
return (ENOENT);

assert(idx >= 0);
pm->pm_md.pm_md_flags |= PM_MD_RAW_EVENT;
pm->pm_class = PMC_CLASS_ARMV8;
pm->pm_caps |= (PMC_CAP_READ | PMC_CAP_WRITE);

return (0);
}

#else

int
Expand Down

0 comments on commit 28dd673

Please sign in to comment.