From ee7af0e7107e918d37bd2686fea1db8f88d2242a Mon Sep 17 00:00:00 2001 From: Vladimir Mezentsev Date: Thu, 16 May 2024 21:00:51 -0700 Subject: gprofng: add hardware counters for AMD Zen3 Historically, we have used several APIs (perfctr, libcpc, perf_event_open) for profiling. For each hardware we have several tables of hardware counters. Some information is duplicated in these tables. Some of the information is no longer used. I did not touch the existing hwc tables. I added a new hwc table for an AMD Zen3 machine. ChangeLog 2024-05-16 Vladimir Mezentsev PR gprofng/31123 * common/core_pcbe.c (core_pcbe_get_events): Add new argument. * common/hwc_cpus.h: New constants for AMD hardware. * common/hwcdrv.c: Add new argument to hwcdrv_get_descriptions. Clean up the code. * common/hwcdrv.h: Likewise. * common/hwcfuncs.c (hwcdrv_get_descriptions): Add new argument. * common/hwctable.c: Add the hwc table for AMD Zen3. * src/hwc_amd_zen3.h: New file. * common/opteron_pcbe.c: Add new argument to opt_pcbe_get_events. * src/collctrl.cc: Remove unused variable. * src/collctrl.h: Likewise. --- gprofng/common/hwcdrv.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'gprofng/common/hwcdrv.c') diff --git a/gprofng/common/hwcdrv.c b/gprofng/common/hwcdrv.c index 0ada09d..0b4cfc3 100644 --- a/gprofng/common/hwcdrv.c +++ b/gprofng/common/hwcdrv.c @@ -34,6 +34,7 @@ #include "cpuid.c" /* ftns for identifying a chip */ +static hdrv_pcbe_api_t *pcbe_driver = NULL; static hdrv_pcbe_api_t hdrv_pcbe_core_api; static hdrv_pcbe_api_t hdrv_pcbe_opteron_api; static hdrv_pcbe_api_t *hdrv_pcbe_drivers[] = { @@ -94,8 +95,6 @@ hwcdrv_lookup_cpuver (const char * cpcN_cciname) * For M8, a 4-bit mask of supported PICs is stored in bits [23:20]. */ -IS_GLOBAL hwcdrv_get_eventnum_fn_t *hwcdrv_get_x86_eventnum = 0; - static const attr_info_t perfctr_sparc_attrs[] = { {NTXT ("user"), 0, 0x01, 16}, //usr {NTXT ("system"), 0, 0x01, 17}, //os @@ -132,8 +131,9 @@ myperfctr_get_x86_eventnum (const char *eventname, uint_t pmc, eventsel_t *eventsel, eventsel_t *valid_umask, uint_t *pmc_sel) { - if (hwcdrv_get_x86_eventnum && - !hwcdrv_get_x86_eventnum (eventname, pmc, eventsel, valid_umask, pmc_sel)) + if (pcbe_driver && pcbe_driver->hdrv_pcbe_get_eventnum && + !pcbe_driver->hdrv_pcbe_get_eventnum (eventname, pmc, eventsel, + valid_umask, pmc_sel)) return 0; /* check for numerically-specified counters */ @@ -214,7 +214,7 @@ set_x86_attr_bits (eventsel_t *result_mask, eventsel_t evnt_valid_umask, return 0; } -IS_GLOBAL int +static int hwcfuncs_get_x86_eventsel (unsigned int regno, const char *int_name, eventsel_t *return_event, uint_t *return_pmc_sel) { @@ -287,6 +287,7 @@ perf_event_open (struct perf_event_attr *hw_event_uptr, pid_t pid, rc = syscall (__NR_perf_event_open, hw_event_uptr, pid, cpu, group_fd, flags); if (rc != -1) return rc; + TprintfT (0, "perf_event_open %d: errno=%d %s\n", retry, errno, strerror(errno)); } return rc; } @@ -375,7 +376,6 @@ static struct int internal_open_called; hwcfuncs_tsd_get_fn_t find_vpc_ctx; unsigned hwcdef_cnt; /* number of *active* hardware counters */ - hwcdrv_get_events_fn_t *get_events; } hdrv_pcl_state; static hwcdrv_about_t hdrv_pcl_about = {.cpcN_cpuver = CPUVER_UNDEFINED}; @@ -813,14 +813,13 @@ hdrv_pcl_internal_open () hdrv_pcbe_api_t *ppcbe = hdrv_pcbe_drivers[ii]; if (!ppcbe->hdrv_pcbe_init ()) { + pcbe_driver = ppcbe; hdrv_pcl_about.cpcN_cciname = ppcbe->hdrv_pcbe_impl_name (); hdrv_pcl_about.cpcN_cpuver = hwcdrv_lookup_cpuver (hdrv_pcl_about.cpcN_cciname); if (hdrv_pcl_about.cpcN_cpuver == CPUVER_UNDEFINED) goto internal_open_error; hdrv_pcl_about.cpcN_npics = ppcbe->hdrv_pcbe_ncounters (); hdrv_pcl_about.cpcN_docref = ppcbe->hdrv_pcbe_cpuref (); - hdrv_pcl_state.get_events = ppcbe->hdrv_pcbe_get_events; - hwcdrv_get_x86_eventnum = ppcbe->hdrv_pcbe_get_eventnum; break; } } @@ -894,11 +893,12 @@ hwcdrv_enable_mt (hwcfuncs_tsd_get_fn_t tsd_ftn) } HWCDRV_API int -hwcdrv_get_descriptions (hwcf_hwc_cb_t *hwc_cb, hwcf_attr_cb_t *attr_cb) +hwcdrv_get_descriptions (hwcf_hwc_cb_t *hwc_cb, hwcf_attr_cb_t *attr_cb, + Hwcentry *raw_hwc_tbl) { int count = 0; - if (hwc_cb && hdrv_pcl_state.get_events) - count = hdrv_pcl_state.get_events (hwc_cb); + if (hwc_cb && pcbe_driver && pcbe_driver->hdrv_pcbe_get_events) + count = pcbe_driver->hdrv_pcbe_get_events (hwc_cb, raw_hwc_tbl); if (attr_cb) for (int ii = 0; perfctr_attrs_table && perfctr_attrs_table[ii].attrname; ii++) attr_cb (perfctr_attrs_table[ii].attrname); -- cgit v1.1