diff options
author | Jessica Clarke <jrtc27@FreeBSD.org> | 2023-06-07 14:21:18 +0000 |
---|---|---|
committer | Jessica Clarke <jrtc27@FreeBSD.org> | 2023-06-07 14:24:29 +0000 |
commit | 21f7397a61f7bff61a1221cc6340cd980a922540 (patch) | |
tree | 1b2960e78f22a93c849fe84ff6449dde4e355ec4 /lib/libpmc/pmclog.c | |
parent | 296a0987be590e73784e4c313d28a61ff310f1a3 (diff) | |
download | src-21f7397a61f7bff61a1221cc6340cd980a922540.tar.gz src-21f7397a61f7bff61a1221cc6340cd980a922540.zip |
Diffstat (limited to 'lib/libpmc/pmclog.c')
-rw-r--r-- | lib/libpmc/pmclog.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/lib/libpmc/pmclog.c b/lib/libpmc/pmclog.c index 0db91cf51bc2..92bcb1c2b161 100644 --- a/lib/libpmc/pmclog.c +++ b/lib/libpmc/pmclog.c @@ -356,12 +356,27 @@ pmclog_get_event(void *cookie, char **data, ssize_t *len, PMCLOG_READ32(le,ev->pl_u.pl_a.pl_flags); PMCLOG_READ32(le,noop); PMCLOG_READ64(le,ev->pl_u.pl_a.pl_rate); - ev->pl_u.pl_a.pl_evname = pmc_pmu_event_get_by_idx(ps->ps_cpuid, ev->pl_u.pl_a.pl_event); - if (ev->pl_u.pl_a.pl_evname != NULL) - break; - else if ((ev->pl_u.pl_a.pl_evname = - _pmc_name_of_event(ev->pl_u.pl_a.pl_event, ps->ps_arch)) - == NULL) { + + /* + * Could be either a PMC event code or a PMU event index; + * assume that their encodings don't overlap (i.e. no PMU event + * table is more than 0x1000 entries) to distinguish them here. + * Otherwise pmc_pmu_event_get_by_idx will go out of bounds if + * given a PMC event code when it knows about that CPU. + * + * XXX: Ideally we'd have user flags to give us that context. + */ + if (ev->pl_u.pl_a.pl_event < PMC_EVENT_FIRST) + ev->pl_u.pl_a.pl_evname = + pmc_pmu_event_get_by_idx(ps->ps_cpuid, + ev->pl_u.pl_a.pl_event); + else if (ev->pl_u.pl_a.pl_event <= PMC_EVENT_LAST) + ev->pl_u.pl_a.pl_evname = + _pmc_name_of_event(ev->pl_u.pl_a.pl_event, + ps->ps_arch); + else + ev->pl_u.pl_a.pl_evname = NULL; + if (ev->pl_u.pl_a.pl_evname == NULL) { printf("unknown event\n"); goto error; } |