/* * These attributes specify the bits in the config word that the perf * syscall uses to pass the event ids and categories to perfmon.
*/
DEFINE_PERFMON_FORMAT_ATTR(event_category, "config:0-3");
DEFINE_PERFMON_FORMAT_ATTR(event, "config:4-31");
/* * These attributes specify the bits in the config1 word that the perf * syscall uses to pass filter data to perfmon.
*/
DEFINE_PERFMON_FORMAT_ATTR(filter_wq, "config1:0-31");
DEFINE_PERFMON_FORMAT_ATTR(filter_tc, "config1:32-39");
DEFINE_PERFMON_FORMAT_ATTR(filter_pgsz, "config1:40-43");
DEFINE_PERFMON_FORMAT_ATTR(filter_sz, "config1:44-51");
DEFINE_PERFMON_FORMAT_ATTR(filter_eng, "config1:52-59");
staticint perfmon_assign_event(struct idxd_pmu *idxd_pmu, struct perf_event *event)
{ int i;
for (i = 0; i < IDXD_PMU_EVENT_MAX; i++) if (!test_and_set_bit(i, idxd_pmu->used_mask)) return i;
return -EINVAL;
}
/* * Check whether there are enough counters to satisfy that all the * events in the group can actually be scheduled at the same time. * * To do this, create a fake idxd_pmu object so the event collection * and assignment functions can be used without affecting the internal * state of the real idxd_pmu object.
*/ staticint perfmon_validate_group(struct idxd_pmu *pmu, struct perf_event *event)
{ struct perf_event *leader = event->group_leader; struct idxd_pmu *fake_pmu; int i, ret = 0, n, idx;
fake_pmu = kzalloc(sizeof(*fake_pmu), GFP_KERNEL); if (!fake_pmu) return -ENOMEM;
/* * While updating overflowed counters, other counters behind * them could overflow and be missed in a given pass. * Normally this could happen at most n_counters times, but in * theory a tiny counter width could result in continual * overflows and endless looping. max_loop provides a * failsafe in that highly unlikely case.
*/ while (ovfstatus && max_loop--) { /* Figure out which counter(s) overflowed */
for_each_set_bit(i, &ovfstatus, n_counters) { unsignedlong ovfstatus_clear = 0;
/* Update event->count for overflowed counter */
event = idxd->idxd_pmu->event_list[i];
perfmon_pmu_event_update(event); /* Writing 1 to OVFSTATUS bit clears it */
set_bit(i, &ovfstatus_clear);
iowrite32(ovfstatus_clear, OVFSTATUS_REG(idxd));
}
ovfstatus = ioread32(OVFSTATUS_REG(idxd));
}
/* * Should never happen. If so, it means a counter(s) looped * around twice while this handler was running.
*/
WARN_ON_ONCE(ovfstatus);
}
staticvoid perfmon_pmu_event_start(struct perf_event *event, int mode)
{
u32 flt_wq, flt_tc, flt_pg_sz, flt_xfer_sz, flt_eng = 0;
u64 cntr_cfg, cntrdata, event_enc, event_cat = 0; struct hw_perf_event *hwc = &event->hw; union filter_cfg flt_cfg; union event_cfg event_cfg; struct idxd_device *idxd; int cntr;
idxd = event_to_idxd(event);
event->hw.idx = hwc->idx;
cntr = hwc->idx;
/* Obtain event category and event value from user space */
event_cfg.val = event->attr.config;
flt_cfg.val = event->attr.config1;
event_cat = event_cfg.event_cat;
event_enc = event_cfg.event_enc;
/* Obtain filter configuration from user space */
flt_wq = flt_cfg.wq;
flt_tc = flt_cfg.tc;
flt_pg_sz = flt_cfg.pg_sz;
flt_xfer_sz = flt_cfg.xfer_sz;
flt_eng = flt_cfg.eng;
if (flt_wq && test_bit(FLT_WQ, &idxd->idxd_pmu->supported_filters))
iowrite32(flt_wq, FLTCFG_REG(idxd, cntr, FLT_WQ)); if (flt_tc && test_bit(FLT_TC, &idxd->idxd_pmu->supported_filters))
iowrite32(flt_tc, FLTCFG_REG(idxd, cntr, FLT_TC)); if (flt_pg_sz && test_bit(FLT_PG_SZ, &idxd->idxd_pmu->supported_filters))
iowrite32(flt_pg_sz, FLTCFG_REG(idxd, cntr, FLT_PG_SZ)); if (flt_xfer_sz && test_bit(FLT_XFER_SZ, &idxd->idxd_pmu->supported_filters))
iowrite32(flt_xfer_sz, FLTCFG_REG(idxd, cntr, FLT_XFER_SZ)); if (flt_eng && test_bit(FLT_ENG, &idxd->idxd_pmu->supported_filters))
iowrite32(flt_eng, FLTCFG_REG(idxd, cntr, FLT_ENG));
/* Read the start value */
cntrdata = ioread64(CNTRDATA_REG(idxd, cntr));
local64_set(&event->hw.prev_count, cntrdata);
/* Set counter to event/category */
cntr_cfg = event_cat << CNTRCFG_CATEGORY_SHIFT;
cntr_cfg |= event_enc << CNTRCFG_EVENT_SHIFT; /* Set interrupt on overflow and counter enable bits */
cntr_cfg |= (CNTRCFG_IRQ_OVERFLOW | CNTRCFG_ENABLE);
iowrite64(cntr_cfg, CNTRCFG_REG(idxd, cntr));
}
staticvoid perfmon_pmu_event_stop(struct perf_event *event, int mode)
{ struct hw_perf_event *hwc = &event->hw; struct idxd_device *idxd; int i, cntr = hwc->idx;
u64 cntr_cfg;
idxd = event_to_idxd(event);
/* remove this event from event list */ for (i = 0; i < idxd->idxd_pmu->n_events; i++) { if (event != idxd->idxd_pmu->event_list[i]) continue;
for (++i; i < idxd->idxd_pmu->n_events; i++)
idxd->idxd_pmu->event_list[i - 1] = idxd->idxd_pmu->event_list[i];
--idxd->idxd_pmu->n_events; break;
}
/* * If total perf counter is 0, stop further registration. * This is necessary in order to support driver running on * guest which does not have pmon support.
*/ if (perfcap.num_perf_counter == 0) goto free;
/* A counter width of 0 means it can't count */ if (perfcap.counter_width == 0) goto free;
/* Overflow interrupt and counter freeze support must be available */ if (!perfcap.overflow_interrupt || !perfcap.counter_freeze) goto free;
/* Number of event categories cannot be 0 */ if (perfcap.num_event_category == 0) goto free;
/* * We don't support per-counter capabilities for now.
*/ if (perfcap.cap_per_counter) goto free;
/* check filter capability. If 0, then filters are not supported */
idxd_pmu->supported_filters = perfcap.filter; if (perfcap.filter)
idxd_pmu->n_filters = hweight8(perfcap.filter);
/* Store the total number of counters categories, and counter width */
idxd_pmu->n_counters = perfcap.num_perf_counter;
idxd_pmu->counter_width = perfcap.counter_width;
idxd_pmu_init(idxd_pmu);
rc = perf_pmu_register(&idxd_pmu->pmu, idxd_pmu->name, -1); if (rc) goto free;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.