Revert r334242 "pmc(3)/hwpmc(4): update supported Intel processors to rely fully on the"
because of squash commit messages
This commit is contained in:
parent
2e56e89840
commit
274069bbf6
@ -2031,7 +2031,7 @@ _libmagic=lib/libmagic
|
||||
.endif
|
||||
|
||||
.if ${MACHINE_CPUARCH} == "amd64"
|
||||
_jevents=lib/libpmc/pmu-events
|
||||
_jevents=lib/libpmcstat/pmu-events
|
||||
.endif
|
||||
|
||||
# kernel-toolchain skips _cleanobj, so handle cleaning up previous
|
||||
|
@ -3,31 +3,9 @@
|
||||
PACKAGE=lib${LIB}
|
||||
LIB= pmc
|
||||
|
||||
SRCS= libpmc.c pmclog.c libpmc_pmu_util.c
|
||||
SRCS= libpmc.c pmclog.c
|
||||
INCS= pmc.h pmclog.h
|
||||
|
||||
CFLAGS+= -I${.CURDIR}
|
||||
|
||||
.if ${MACHINE_CPUARCH} == "amd64"
|
||||
|
||||
.if ${MACHINE_CPUARCH} == "aarch64"
|
||||
EVENT_ARCH="arm64"
|
||||
.elif ${MACHINE_CPUARCH} == "amd64"
|
||||
EVENT_ARCH="x86"
|
||||
.elif ${MACHINE_CPUARCH} == "powerpc"
|
||||
EVENT_ARCH="powerpc"
|
||||
.endif
|
||||
|
||||
JEVENTS= ${BTOOLSPATH:U.}/pmu-events/jevents
|
||||
# This file is built in a subdirectory so never try to rebuild
|
||||
# it here due to missing meta file.
|
||||
${JEVENTS}: .NOMETA
|
||||
|
||||
libpmc_events.c: ${JEVENTS}
|
||||
${JEVENTS} ${EVENT_ARCH} ${.CURDIR}/pmu-events/arch libpmc_events.c
|
||||
SRCS+= libpmc_events.c
|
||||
.endif
|
||||
|
||||
MAN= pmc.3
|
||||
MAN+= pmc_allocate.3
|
||||
MAN+= pmc_attach.3
|
||||
|
@ -2781,27 +2781,8 @@ pmc_allocate(const char *ctrspec, enum pmc_mode mode,
|
||||
|
||||
if (mode != PMC_MODE_SS && mode != PMC_MODE_TS &&
|
||||
mode != PMC_MODE_SC && mode != PMC_MODE_TC) {
|
||||
return (EINVAL);
|
||||
}
|
||||
bzero(&pmc_config, sizeof(pmc_config));
|
||||
pmc_config.pm_cpu = cpu;
|
||||
pmc_config.pm_mode = mode;
|
||||
pmc_config.pm_flags = flags;
|
||||
if (PMC_IS_SAMPLING_MODE(mode))
|
||||
pmc_config.pm_caps |= PMC_CAP_INTERRUPT;
|
||||
/*
|
||||
* Can we pull this straight from the pmu table?
|
||||
*/
|
||||
r = spec_copy = strdup(ctrspec);
|
||||
ctrname = strsep(&r, ",");
|
||||
if (pmc_pmu_pmcallocate(ctrname, &pmc_config) == 0) {
|
||||
if (PMC_CALL(PMCALLOCATE, &pmc_config) < 0)
|
||||
return (errno);
|
||||
*pmcid = pmc_config.pm_pmcid;
|
||||
return (0);
|
||||
} else {
|
||||
free(spec_copy);
|
||||
spec_copy = NULL;
|
||||
errno = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* replace an event alias with the canonical event specifier */
|
||||
@ -2852,8 +2833,15 @@ pmc_allocate(const char *ctrspec, enum pmc_mode mode,
|
||||
goto out;
|
||||
}
|
||||
|
||||
bzero(&pmc_config, sizeof(pmc_config));
|
||||
pmc_config.pm_ev = ev->pm_ev_code;
|
||||
pmc_config.pm_class = pcd->pm_evc_class;
|
||||
pmc_config.pm_cpu = cpu;
|
||||
pmc_config.pm_mode = mode;
|
||||
pmc_config.pm_flags = flags;
|
||||
|
||||
if (PMC_IS_SAMPLING_MODE(mode))
|
||||
pmc_config.pm_caps |= PMC_CAP_INTERRUPT;
|
||||
|
||||
if (pcd->pm_evc_allocate_pmc(ev->pm_ev_code, r, &pmc_config) < 0) {
|
||||
errno = EINVAL;
|
||||
|
@ -1,333 +0,0 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
||||
*
|
||||
* Copyright (c) 2018, Matthew Macy
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <pmc.h>
|
||||
#include <pmclog.h>
|
||||
#include <libpmcstat.h>
|
||||
#include "pmu-events/pmu-events.h"
|
||||
|
||||
#if defined(__amd64__)
|
||||
struct pmu_alias {
|
||||
const char *pa_alias;
|
||||
const char *pa_name;
|
||||
};
|
||||
static struct pmu_alias pmu_alias_table[] = {
|
||||
{ "UNHALTED_CORE_CYCLES", "CPU_CLK_UNHALTED.THREAD_P_ANY"},
|
||||
{ "UNHALTED-CORE-CYCLES", "CPU_CLK_UNHALTED.THREAD_P_ANY"},
|
||||
{ "LLC_MISSES", "LONGEST_LAT_CACHE.MISS"},
|
||||
{ "LLC-MISSES", "LONGEST_LAT_CACHE.MISS"},
|
||||
{ "LLC_REFERENCE", "LONGEST_LAT_CACHE.REFERENCE"},
|
||||
{ "LLC-REFERENCE", "LONGEST_LAT_CACHE.REFERENCE"},
|
||||
{ "LLC_MISS_RHITM", "mem_load_l3_miss_retired.remote_hitm"},
|
||||
{ "LLC-MISS-RHITM", "mem_load_l3_miss_retired.remote_hitm"},
|
||||
{ "RESOURCE_STALL", "RESOURCE_STALLS.ANY"},
|
||||
{ "RESOURCE_STALLS_ANY", "RESOURCE_STALLS.ANY"},
|
||||
{ "BRANCH_INSTRUCTION_RETIRED", "BR_INST_RETIRED.ALL_BRANCHES"},
|
||||
{ "BRANCH-INSTRUCTION-RETIRED", "BR_INST_RETIRED.ALL_BRANCHES"},
|
||||
{ "BRANCH_MISSES_RETIRED", "BR_MISP_RETIRED.ALL_BRANCHES"},
|
||||
{ "BRANCH-MISSES-RETIRED", "BR_MISP_RETIRED.ALL_BRANCHES"},
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
static const char *
|
||||
pmu_alias_get(const char *name)
|
||||
{
|
||||
struct pmu_alias *pa;
|
||||
|
||||
for (pa = pmu_alias_table; pa->pa_alias != NULL; pa++)
|
||||
if (strcasecmp(name, pa->pa_alias) == 0)
|
||||
return (pa->pa_name);
|
||||
return (name);
|
||||
}
|
||||
|
||||
struct pmu_event_desc {
|
||||
uint64_t ped_period;
|
||||
uint64_t ped_offcore_rsp;
|
||||
uint32_t ped_event;
|
||||
uint32_t ped_frontend;
|
||||
uint32_t ped_ldlat;
|
||||
uint32_t ped_config1;
|
||||
uint8_t ped_umask;
|
||||
uint8_t ped_cmask;
|
||||
uint8_t ped_any;
|
||||
uint8_t ped_inv;
|
||||
uint8_t ped_edge;
|
||||
uint8_t ped_fc_mask;
|
||||
uint8_t ped_ch_mask;
|
||||
};
|
||||
|
||||
static const struct pmu_events_map *
|
||||
pmu_events_map_get(void)
|
||||
{
|
||||
size_t s;
|
||||
char buf[64];
|
||||
const struct pmu_events_map *pme;
|
||||
|
||||
if (sysctlbyname("kern.hwpmc.cpuid", (void *)NULL, &s,
|
||||
(void *)NULL, 0) == -1)
|
||||
return (NULL);
|
||||
if (sysctlbyname("kern.hwpmc.cpuid", buf, &s,
|
||||
(void *)NULL, 0) == -1)
|
||||
return (NULL);
|
||||
for (pme = pmu_events_map; pme->cpuid != NULL; pme++)
|
||||
if (strcmp(buf, pme->cpuid) == 0)
|
||||
return (pme);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static const struct pmu_event *
|
||||
pmu_event_get(const char *event_name, int *idx)
|
||||
{
|
||||
const struct pmu_events_map *pme;
|
||||
const struct pmu_event *pe;
|
||||
int i;
|
||||
|
||||
if ((pme = pmu_events_map_get()) == NULL)
|
||||
return (NULL);
|
||||
for (i = 0, pe = pme->table; pe->name || pe->desc || pe->event; pe++, i++) {
|
||||
if (pe->name == NULL)
|
||||
continue;
|
||||
if (strcasecmp(pe->name, event_name) == 0) {
|
||||
if (idx)
|
||||
*idx = i;
|
||||
return (pe);
|
||||
}
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
const char *
|
||||
pmu_event_get_by_idx(int idx)
|
||||
{
|
||||
const struct pmu_events_map *pme;
|
||||
const struct pmu_event *pe;
|
||||
int i;
|
||||
|
||||
if ((pme = pmu_events_map_get()) == NULL)
|
||||
return (NULL);
|
||||
for (i = 0, pe = pme->table; (pe->name || pe->desc || pe->event) && i < idx; pe++, i++)
|
||||
;
|
||||
return (pe->name);
|
||||
}
|
||||
|
||||
static int
|
||||
pmu_parse_event(struct pmu_event_desc *ped, const char *eventin)
|
||||
{
|
||||
char *event;
|
||||
char *kvp, *key, *value;
|
||||
char *debug;
|
||||
|
||||
if ((event = strdup(eventin)) == NULL)
|
||||
return (ENOMEM);
|
||||
bzero(ped, sizeof(*ped));
|
||||
while ((kvp = strsep(&event, ",")) != NULL) {
|
||||
key = strsep(&kvp, "=");
|
||||
if (key == NULL)
|
||||
abort();
|
||||
value = kvp;
|
||||
if (strcmp(key, "umask") == 0)
|
||||
ped->ped_umask = strtol(value, NULL, 16);
|
||||
else if (strcmp(key, "event") == 0)
|
||||
ped->ped_event = strtol(value, NULL, 16);
|
||||
else if (strcmp(key, "period") == 0)
|
||||
ped->ped_period = strtol(value, NULL, 10);
|
||||
else if (strcmp(key, "offcore_rsp") == 0)
|
||||
ped->ped_offcore_rsp = strtol(value, NULL, 16);
|
||||
else if (strcmp(key, "any") == 0)
|
||||
ped->ped_any = strtol(value, NULL, 10);
|
||||
else if (strcmp(key, "cmask") == 0)
|
||||
ped->ped_cmask = strtol(value, NULL, 10);
|
||||
else if (strcmp(key, "inv") == 0)
|
||||
ped->ped_inv = strtol(value, NULL, 10);
|
||||
else if (strcmp(key, "edge") == 0)
|
||||
ped->ped_edge = strtol(value, NULL, 10);
|
||||
else if (strcmp(key, "frontend") == 0)
|
||||
ped->ped_frontend = strtol(value, NULL, 16);
|
||||
else if (strcmp(key, "ldlat") == 0)
|
||||
ped->ped_ldlat = strtol(value, NULL, 16);
|
||||
else if (strcmp(key, "fc_mask") == 0)
|
||||
ped->ped_fc_mask = strtol(value, NULL, 16);
|
||||
else if (strcmp(key, "ch_mask") == 0)
|
||||
ped->ped_ch_mask = strtol(value, NULL, 16);
|
||||
else if (strcmp(key, "config1") == 0)
|
||||
ped->ped_config1 = strtol(value, NULL, 16);
|
||||
else {
|
||||
debug = getenv("PMUDEBUG");
|
||||
if (debug != NULL && strcmp(debug, "true") == 0 && value != NULL)
|
||||
printf("unrecognized kvpair: %s:%s\n", key, value);
|
||||
}
|
||||
}
|
||||
free(event);
|
||||
return (0);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
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);
|
||||
if ((pe = pmu_event_get(event_name, NULL)) == NULL)
|
||||
return (DEFAULT_SAMPLE_COUNT);
|
||||
if (pe->alias && (pe = pmu_event_get(pe->alias, NULL)) == NULL)
|
||||
return (DEFAULT_SAMPLE_COUNT);
|
||||
if (pe->event == NULL)
|
||||
return (DEFAULT_SAMPLE_COUNT);
|
||||
if (pmu_parse_event(&ped, pe->event))
|
||||
return (DEFAULT_SAMPLE_COUNT);
|
||||
return (ped.ped_period);
|
||||
}
|
||||
|
||||
int
|
||||
pmc_pmu_enabled(void)
|
||||
{
|
||||
|
||||
return (pmu_events_map_get() != NULL);
|
||||
}
|
||||
|
||||
void
|
||||
pmc_pmu_print_counters(void)
|
||||
{
|
||||
const struct pmu_events_map *pme;
|
||||
const struct pmu_event *pe;
|
||||
struct pmu_event_desc ped;
|
||||
char *debug;
|
||||
int do_debug;
|
||||
|
||||
debug = getenv("PMUDEBUG");
|
||||
do_debug = 0;
|
||||
|
||||
if (debug != NULL && strcmp(debug, "true") == 0)
|
||||
do_debug = 1;
|
||||
if ((pme = pmu_events_map_get()) == NULL)
|
||||
return;
|
||||
for (pe = pme->table; pe->name || pe->desc || pe->event; pe++) {
|
||||
if (pe->name == NULL)
|
||||
continue;
|
||||
printf("\t%s\n", pe->name);
|
||||
if (do_debug)
|
||||
pmu_parse_event(&ped, pe->event);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pmc_pmu_print_counter_desc(const char *ev)
|
||||
{
|
||||
const struct pmu_events_map *pme;
|
||||
const struct pmu_event *pe;
|
||||
|
||||
if ((pme = pmu_events_map_get()) == NULL)
|
||||
return;
|
||||
for (pe = pme->table; pe->name || pe->desc || pe->event; pe++) {
|
||||
if (pe->name == NULL)
|
||||
continue;
|
||||
if (strcasestr(pe->name, ev) != NULL &&
|
||||
pe->desc != NULL)
|
||||
printf("%s:\t%s\n", pe->name, pe->desc);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
pmc_pmu_print_counter_desc_long(const char *ev)
|
||||
{
|
||||
const struct pmu_events_map *pme;
|
||||
const struct pmu_event *pe;
|
||||
|
||||
if ((pme = pmu_events_map_get()) == NULL)
|
||||
return;
|
||||
for (pe = pme->table; pe->name || pe->desc || pe->event; pe++) {
|
||||
if (pe->name == NULL)
|
||||
continue;
|
||||
if (strcasestr(pe->name, ev) != NULL) {
|
||||
if (pe->long_desc != NULL)
|
||||
printf("%s:\n%s\n", pe->name, pe->long_desc);
|
||||
else if (pe->desc != NULL)
|
||||
printf("%s:\t%s\n", pe->name, pe->desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
pmc_pmu_pmcallocate(const char *event_name, struct pmc_op_pmcallocate *pm)
|
||||
{
|
||||
const struct pmu_event *pe;
|
||||
struct pmu_event_desc ped;
|
||||
struct pmc_md_iap_op_pmcallocate *iap;
|
||||
int idx;
|
||||
|
||||
iap = &pm->pm_md.pm_iap;
|
||||
bzero(iap, sizeof(*iap));
|
||||
event_name = pmu_alias_get(event_name);
|
||||
if ((pe = pmu_event_get(event_name, &idx)) == NULL)
|
||||
return (ENOENT);
|
||||
if (pe->alias && (pe = pmu_event_get(pe->alias, &idx)) == NULL)
|
||||
return (ENOENT);
|
||||
if (pe->event == NULL)
|
||||
return (ENOENT);
|
||||
if (pmu_parse_event(&ped, pe->event))
|
||||
return (ENOENT);
|
||||
|
||||
pm->pm_class = PMC_CLASS_IAP;
|
||||
pm->pm_ev = idx;
|
||||
iap->pm_iap_config |= IAP_EVSEL(ped.ped_event);
|
||||
iap->pm_iap_config |= IAP_UMASK(ped.ped_umask);
|
||||
iap->pm_iap_config |= IAP_CMASK(ped.ped_cmask);
|
||||
iap->pm_iap_rsp = ped.ped_offcore_rsp;
|
||||
|
||||
iap->pm_iap_config |= (IAP_USR | IAP_OS);
|
||||
if (ped.ped_edge)
|
||||
iap->pm_iap_config |= IAP_EDGE;
|
||||
if (ped.ped_any)
|
||||
iap->pm_iap_config |= IAP_ANY;
|
||||
if (ped.ped_inv)
|
||||
iap->pm_iap_config |= IAP_EDGE;
|
||||
if (pm->pm_caps & PMC_CAP_INTERRUPT)
|
||||
iap->pm_iap_config |= IAP_INT;
|
||||
return (0);
|
||||
}
|
||||
|
||||
#else
|
||||
uint64_t pmc_pmu_sample_rate_get(const char *event_name __unused) { return (DEFAULT_SAMPLE_COUNT); }
|
||||
void pmc_pmu_print_counters(void) {}
|
||||
void pmc_pmu_print_counter_desc(const char *e __unused) {}
|
||||
void pmc_pmu_print_counter_desc_long(const char *e __unused) {}
|
||||
int pmc_pmu_enabled(void) { return (0); }
|
||||
int pmc_pmu_pmcallocate(const char *e __unused, struct pmc_op_pmcallocate *p __unused) { return (EOPNOTSUPP); }
|
||||
const char *pmu_event_get_by_idx(int idx __unused) { return (NULL); }
|
||||
|
||||
#endif
|
@ -112,14 +112,6 @@ const char *pmc_name_of_state(enum pmc_state _ps);
|
||||
|
||||
int pmc_event_names_of_class(enum pmc_class _cl, const char ***_eventnames,
|
||||
int *_nevents);
|
||||
|
||||
int pmc_pmu_enabled(void);
|
||||
void pmc_pmu_print_counters(void);
|
||||
void pmc_pmu_print_counter_desc(const char *);
|
||||
void pmc_pmu_print_counter_desc_long(const char *);
|
||||
uint64_t pmc_pmu_sample_rate_get(const char *);
|
||||
int pmc_pmu_pmcallocate(const char *, struct pmc_op_pmcallocate *);
|
||||
const char *pmu_event_get_by_idx(int idx);
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
|
@ -82,14 +82,13 @@ struct pmclog_ev {
|
||||
struct timespec pl_ts; /* log entry timestamp */
|
||||
enum pmclog_type pl_type; /* log entry kind */
|
||||
union { /* log entry data */
|
||||
struct pmclog_ev_callchain pl_cc;
|
||||
struct pmclog_ev_closelog pl_cl;
|
||||
struct pmclog_ev_dropnotify pl_d;
|
||||
struct pmclog_ev_initialize pl_i;
|
||||
struct pmclog_ev_map_in pl_mi;
|
||||
struct pmclog_ev_map_out pl_mo;
|
||||
struct pmclog_ev_pcsample pl_s;
|
||||
struct pmclog_ev_pmcallocate pl_a;
|
||||
struct pmclog_ev_pmcallocatedyn pl_ad;
|
||||
struct pmclog_ev_pmcattach pl_t;
|
||||
struct pmclog_ev_pmcdetach pl_d;
|
||||
struct pmclog_ev_proccsw pl_c;
|
||||
@ -271,8 +270,8 @@ while (pmclog_read(parser, &ev) == 0) {
|
||||
case PMCLOG_TYPE_PROCCSW:
|
||||
--process a thread context switch record--
|
||||
break;
|
||||
case PMCLOG_TYPE_CALLCHAIN:
|
||||
--process a callchain sample--
|
||||
case PMCLOG_TYPE_PCSAMPLE:
|
||||
--process a PC sample--
|
||||
break;
|
||||
--and so on--
|
||||
}
|
||||
|
@ -46,7 +46,6 @@ __FBSDID("$FreeBSD$");
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <machine/pmc_mdep.h>
|
||||
|
||||
@ -279,7 +278,7 @@ pmclog_get_event(void *cookie, char **data, ssize_t *len,
|
||||
struct pmclog_ev *ev)
|
||||
{
|
||||
int evlen, pathlen;
|
||||
uint32_t h, *le, npc, noop;
|
||||
uint32_t h, *le, npc;
|
||||
enum pmclog_parser_state e;
|
||||
struct pmclog_parse_state *ps;
|
||||
|
||||
@ -289,7 +288,6 @@ pmclog_get_event(void *cookie, char **data, ssize_t *len,
|
||||
|
||||
if ((e = pmclog_get_record(ps,data,len)) == PL_STATE_ERROR) {
|
||||
ev->pl_state = PMCLOG_ERROR;
|
||||
printf("state error\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -303,7 +301,6 @@ pmclog_get_event(void *cookie, char **data, ssize_t *len,
|
||||
PMCLOG_READ32(le,h);
|
||||
|
||||
if (!PMCLOG_HEADER_CHECK_MAGIC(h)) {
|
||||
printf("bad magic\n");
|
||||
ps->ps_state = PL_STATE_ERROR;
|
||||
ev->pl_state = PMCLOG_ERROR;
|
||||
return -1;
|
||||
@ -363,20 +360,21 @@ pmclog_get_event(void *cookie, char **data, ssize_t *len,
|
||||
PMCLOG_READADDR(le,ev->pl_u.pl_mo.pl_start);
|
||||
PMCLOG_READADDR(le,ev->pl_u.pl_mo.pl_end);
|
||||
break;
|
||||
case PMCLOG_TYPE_PCSAMPLE:
|
||||
PMCLOG_READ32(le,ev->pl_u.pl_s.pl_pid);
|
||||
PMCLOG_READADDR(le,ev->pl_u.pl_s.pl_pc);
|
||||
PMCLOG_READ32(le,ev->pl_u.pl_s.pl_pmcid);
|
||||
PMCLOG_READ32(le,ev->pl_u.pl_s.pl_usermode);
|
||||
PMCLOG_READ32(le,ev->pl_u.pl_s.pl_tid);
|
||||
break;
|
||||
case PMCLOG_TYPE_PMCALLOCATE:
|
||||
PMCLOG_READ32(le,ev->pl_u.pl_a.pl_pmcid);
|
||||
PMCLOG_READ32(le,ev->pl_u.pl_a.pl_event);
|
||||
PMCLOG_READ32(le,ev->pl_u.pl_a.pl_flags);
|
||||
PMCLOG_READ32(le,noop);
|
||||
ev->pl_u.pl_a.pl_evname = pmu_event_get_by_idx(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 =
|
||||
if ((ev->pl_u.pl_a.pl_evname =
|
||||
_pmc_name_of_event(ev->pl_u.pl_a.pl_event, ps->ps_arch))
|
||||
== NULL) {
|
||||
printf("unknown event\n");
|
||||
== NULL)
|
||||
goto error;
|
||||
}
|
||||
break;
|
||||
case PMCLOG_TYPE_PMCALLOCATEDYN:
|
||||
PMCLOG_READ32(le,ev->pl_u.pl_ad.pl_pmcid);
|
||||
@ -403,16 +401,14 @@ pmclog_get_event(void *cookie, char **data, ssize_t *len,
|
||||
case PMCLOG_TYPE_PROCEXEC:
|
||||
PMCLOG_GET_PATHLEN(pathlen,evlen,pmclog_procexec);
|
||||
PMCLOG_READ32(le,ev->pl_u.pl_x.pl_pid);
|
||||
PMCLOG_READ32(le,ev->pl_u.pl_x.pl_pmcid);
|
||||
PMCLOG_READ32(le,noop);
|
||||
PMCLOG_READADDR(le,ev->pl_u.pl_x.pl_entryaddr);
|
||||
PMCLOG_READ32(le,ev->pl_u.pl_x.pl_pmcid);
|
||||
PMCLOG_READSTRING(le,ev->pl_u.pl_x.pl_pathname,pathlen);
|
||||
break;
|
||||
case PMCLOG_TYPE_PROCEXIT:
|
||||
PMCLOG_READ32(le,ev->pl_u.pl_e.pl_pmcid);
|
||||
PMCLOG_READ32(le,ev->pl_u.pl_e.pl_pid);
|
||||
PMCLOG_READ32(le,noop);
|
||||
PMCLOG_READ64(le,ev->pl_u.pl_e.pl_value);
|
||||
PMCLOG_READ32(le,ev->pl_u.pl_e.pl_pid);
|
||||
break;
|
||||
case PMCLOG_TYPE_PROCFORK:
|
||||
PMCLOG_READ32(le,ev->pl_u.pl_f.pl_oldpid);
|
||||
@ -493,9 +489,8 @@ pmclog_read(void *cookie, struct pmclog_ev *ev)
|
||||
|
||||
ps->ps_len = nread;
|
||||
ps->ps_data = ps->ps_buffer;
|
||||
} else {
|
||||
} else
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
assert(ps->ps_len > 0);
|
||||
@ -503,6 +498,7 @@ pmclog_read(void *cookie, struct pmclog_ev *ev)
|
||||
|
||||
/* Retrieve one event from the byte stream. */
|
||||
retval = pmclog_get_event(ps, &ps->ps_data, &ps->ps_len, ev);
|
||||
|
||||
/*
|
||||
* If we need more data and we have a configured fd, try read
|
||||
* from it.
|
||||
|
@ -158,6 +158,7 @@ struct pmclog_ev {
|
||||
struct pmclog_ev_initialize pl_i;
|
||||
struct pmclog_ev_map_in pl_mi;
|
||||
struct pmclog_ev_map_out pl_mo;
|
||||
struct pmclog_ev_pcsample pl_s;
|
||||
struct pmclog_ev_pmcallocate pl_a;
|
||||
struct pmclog_ev_pmcallocatedyn pl_ad;
|
||||
struct pmclog_ev_pmcattach pl_t;
|
||||
|
@ -9,7 +9,30 @@ SRCS= \
|
||||
libpmcstat_logging.c \
|
||||
libpmcstat_process.c \
|
||||
libpmcstat_string.c \
|
||||
libpmcstat_symbol.c
|
||||
libpmcstat_symbol.c \
|
||||
libpmcstat_pmu_util.c
|
||||
INCS= libpmcstat.h
|
||||
|
||||
CFLAGS+= -I${.CURDIR}
|
||||
|
||||
.if ${MACHINE_CPUARCH} == "amd64"
|
||||
|
||||
.if ${MACHINE_CPUARCH} == "aarch64"
|
||||
EVENT_ARCH="arm64"
|
||||
.elif ${MACHINE_CPUARCH} == "amd64"
|
||||
EVENT_ARCH="x86"
|
||||
.elif ${MACHINE_CPUARCH} == "powerpc"
|
||||
EVENT_ARCH="powerpc"
|
||||
.endif
|
||||
|
||||
JEVENTS= ${BTOOLSPATH:U.}/pmu-events/jevents
|
||||
# This file is built in a subdirectory so never try to rebuild
|
||||
# it here due to missing meta file.
|
||||
${JEVENTS}: .NOMETA
|
||||
|
||||
libpmcstat_events.c: ${JEVENTS}
|
||||
${JEVENTS} ${EVENT_ARCH} ${.CURDIR}/pmu-events/arch libpmcstat_events.c
|
||||
SRCS+= libpmcstat_events.c
|
||||
.endif
|
||||
|
||||
.include <bsd.lib.mk>
|
||||
|
@ -382,6 +382,8 @@ int pmcstat_analyze_log(struct pmcstat_args *args,
|
||||
int pmcstat_open_log(const char *_p, int _mode);
|
||||
int pmcstat_close_log(struct pmcstat_args *args);
|
||||
|
||||
uint64_t pmcstat_pmu_sample_rate_get(const char *);
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif /* !_LIBPMCSTAT_H_ */
|
||||
|
@ -195,6 +195,7 @@ pmcstat_analyze_log(struct pmcstat_args *args,
|
||||
int *ps_samples_period)
|
||||
{
|
||||
uint32_t cpu, cpuflags;
|
||||
uintfptr_t pc;
|
||||
pid_t pid;
|
||||
struct pmcstat_image *image;
|
||||
struct pmcstat_process *pp, *ppnew;
|
||||
@ -267,6 +268,44 @@ pmcstat_analyze_log(struct pmcstat_args *args,
|
||||
ev.pl_u.pl_mo.pl_end);
|
||||
break;
|
||||
|
||||
case PMCLOG_TYPE_PCSAMPLE:
|
||||
/*
|
||||
* Note: the `PCSAMPLE' log entry is not
|
||||
* generated by hpwmc(4) after version 2.
|
||||
*/
|
||||
|
||||
/*
|
||||
* We bring in the gmon file for the image
|
||||
* currently associated with the PMC & pid
|
||||
* pair and increment the appropriate entry
|
||||
* bin inside this.
|
||||
*/
|
||||
pmcstat_stats->ps_samples_total++;
|
||||
*ps_samples_period += 1;
|
||||
|
||||
pc = ev.pl_u.pl_s.pl_pc;
|
||||
pp = pmcstat_process_lookup(ev.pl_u.pl_s.pl_pid,
|
||||
PMCSTAT_ALLOCATE);
|
||||
|
||||
/* Get PMC record. */
|
||||
pmcr = pmcstat_lookup_pmcid(ev.pl_u.pl_s.pl_pmcid, pmcstat_mergepmc);
|
||||
assert(pmcr != NULL);
|
||||
pmcr->pr_samples++;
|
||||
|
||||
/*
|
||||
* Call the plugins processing
|
||||
* TODO: move pmcstat_process_find_map inside plugins
|
||||
*/
|
||||
|
||||
if (plugins[args->pa_pplugin].pl_process != NULL)
|
||||
plugins[args->pa_pplugin].pl_process(
|
||||
pp, pmcr, 1, &pc,
|
||||
pmcstat_process_find_map(pp, pc) != NULL, 0);
|
||||
plugins[args->pa_plugin].pl_process(
|
||||
pp, pmcr, 1, &pc,
|
||||
pmcstat_process_find_map(pp, pc) != NULL, 0);
|
||||
break;
|
||||
|
||||
case PMCLOG_TYPE_CALLCHAIN:
|
||||
pmcstat_stats->ps_samples_total++;
|
||||
*ps_samples_period += 1;
|
||||
@ -414,8 +453,8 @@ pmcstat_analyze_log(struct pmcstat_args *args,
|
||||
return (PMCSTAT_RUNNING);
|
||||
|
||||
err(EX_DATAERR,
|
||||
"ERROR: event parsing failed state: %d type: %d (record %jd, offset 0x%jx)",
|
||||
ev.pl_state, ev.pl_type, (uintmax_t) ev.pl_count + 1, ev.pl_offset);
|
||||
"ERROR: event parsing failed (record %jd, offset 0x%jx)",
|
||||
(uintmax_t) ev.pl_count + 1, ev.pl_offset);
|
||||
}
|
||||
|
||||
/*
|
||||
|
164
lib/libpmcstat/libpmcstat_pmu_util.c
Normal file
164
lib/libpmcstat/libpmcstat_pmu_util.c
Normal file
@ -0,0 +1,164 @@
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
||||
*
|
||||
* Copyright (c) 2018, Matthew Macy
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/errno.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <pmc.h>
|
||||
#include <pmclog.h>
|
||||
#include <libpmcstat.h>
|
||||
#include "pmu-events/pmu-events.h"
|
||||
|
||||
#if defined(__amd64__)
|
||||
struct pmu_alias {
|
||||
const char *pa_alias;
|
||||
const char *pa_name;
|
||||
};
|
||||
static struct pmu_alias pmu_alias_table[] = {
|
||||
{ "UNHALTED_CORE_CYCLES", "CPU_CLK_UNHALTED.THREAD_P_ANY"},
|
||||
{ "UNHALTED-CORE-CYCLES", "CPU_CLK_UNHALTED.THREAD_P_ANY"},
|
||||
{ "LLC_MISSES", "LONGEST_LAT_CACHE.MISS"},
|
||||
{ "LLC-MISSES", "LONGEST_LAT_CACHE.MISS"},
|
||||
{ "LLC_REFERENCE", "LONGEST_LAT_CACHE.REFERENCE"},
|
||||
{ "LLC-REFERENCE", "LONGEST_LAT_CACHE.REFERENCE"},
|
||||
{ "LLC_MISS_RHITM", "mem_load_l3_miss_retired.remote_hitm"},
|
||||
{ "LLC-MISS-RHITM", "mem_load_l3_miss_retired.remote_hitm"},
|
||||
{ "RESOURCE_STALL", "RESOURCE_STALLS.ANY"},
|
||||
{ "RESOURCE_STALLS_ANY", "RESOURCE_STALLS.ANY"},
|
||||
{ "BRANCH_INSTRUCTION_RETIRED", "BR_INST_RETIRED.ALL_BRANCHES"},
|
||||
{ "BRANCH-INSTRUCTION-RETIRED", "BR_INST_RETIRED.ALL_BRANCHES"},
|
||||
{ "BRANCH_MISSES_RETIRED", "BR_MISP_RETIRED.ALL_BRANCHES"},
|
||||
{ "BRANCH-MISSES-RETIRED", "BR_MISP_RETIRED.ALL_BRANCHES"},
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
static const char *
|
||||
pmu_alias_get(const char *name)
|
||||
{
|
||||
struct pmu_alias *pa;
|
||||
|
||||
for (pa = pmu_alias_table; pa->pa_alias != NULL; pa++)
|
||||
if (strcasecmp(name, pa->pa_alias) == 0)
|
||||
return (pa->pa_name);
|
||||
return (name);
|
||||
}
|
||||
|
||||
struct pmu_event_desc {
|
||||
uint32_t ped_umask;
|
||||
uint32_t ped_event;
|
||||
uint64_t ped_period;
|
||||
};
|
||||
|
||||
static const struct pmu_events_map *
|
||||
pmu_events_map_get(void)
|
||||
{
|
||||
size_t s;
|
||||
char buf[64];
|
||||
const struct pmu_events_map *pme;
|
||||
|
||||
if (sysctlbyname("kern.hwpmc.cpuid", (void *)NULL, &s,
|
||||
(void *)NULL, 0) == -1)
|
||||
return (NULL);
|
||||
if (sysctlbyname("kern.hwpmc.cpuid", buf, &s,
|
||||
(void *)NULL, 0) == -1)
|
||||
return (NULL);
|
||||
for (pme = pmu_events_map; pme->cpuid != NULL; pme++)
|
||||
if (strcmp(buf, pme->cpuid) == 0)
|
||||
return (pme);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static const struct pmu_event *
|
||||
pmu_event_get(const char *event_name)
|
||||
{
|
||||
const struct pmu_events_map *pme;
|
||||
const struct pmu_event *pe;
|
||||
|
||||
if ((pme = pmu_events_map_get()) == NULL)
|
||||
return (NULL);
|
||||
for (pe = pme->table; pe->name || pe->desc || pe->event; pe++) {
|
||||
if (pe->name == NULL)
|
||||
continue;
|
||||
if (strcasecmp(pe->name, event_name) == 0)
|
||||
return (pe);
|
||||
}
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
static int
|
||||
pmu_parse_event(struct pmu_event_desc *ped, const char *eventin)
|
||||
{
|
||||
char *event;
|
||||
char *kvp, *key, *value;
|
||||
|
||||
if ((event = strdup(eventin)) == NULL)
|
||||
return (ENOMEM);
|
||||
bzero(ped, sizeof(*ped));
|
||||
while ((kvp = strsep(&event, ",")) != NULL) {
|
||||
key = strsep(&kvp, "=");
|
||||
if (key == NULL)
|
||||
abort();
|
||||
value = kvp;
|
||||
if (strcmp(key, "umask") == 0)
|
||||
ped->ped_umask = strtol(value, NULL, 16);
|
||||
if (strcmp(key, "event") == 0)
|
||||
ped->ped_event = strtol(value, NULL, 16);
|
||||
if (strcmp(key, "period") == 0)
|
||||
ped->ped_period = strtol(value, NULL, 10);
|
||||
}
|
||||
free(event);
|
||||
return (0);
|
||||
}
|
||||
|
||||
uint64_t
|
||||
pmcstat_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);
|
||||
if ((pe = pmu_event_get(event_name)) == NULL)
|
||||
return (DEFAULT_SAMPLE_COUNT);
|
||||
if (pe->alias && (pe = pmu_event_get(pe->alias)) == NULL)
|
||||
return (DEFAULT_SAMPLE_COUNT);
|
||||
if (pe->event == NULL)
|
||||
return (DEFAULT_SAMPLE_COUNT);
|
||||
if (pmu_parse_event(&ped, pe->event))
|
||||
return (DEFAULT_SAMPLE_COUNT);
|
||||
return (ped.ped_period);
|
||||
}
|
||||
|
||||
#else
|
||||
uint64_t pmcstat_pmu_sample_rate_get(const char *event_name __unused) { return (DEFAULT_SAMPLE_COUNT); }
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user