@@ -3147,17 +3147,26 @@ intel_bts_constraints(struct perf_event *event)
return NULL;
}
+static struct event_constraint *intel_virt_event_constraints[] __read_mostly = {
+ &vlbr_constraint,
+ &vmetrics_constraint,
+};
+
/*
- * Note: matches a fake event, like Fixed2.
+ * Note: matches a virtual event, like vmetrics.
*/
static struct event_constraint *
-intel_vlbr_constraints(struct perf_event *event)
+intel_virt_constraints(struct perf_event *event)
{
- struct event_constraint *c = &vlbr_constraint;
+ int i;
+ struct event_constraint *c;
- if (unlikely(constraint_match(c, event->hw.config))) {
- event->hw.flags |= c->flags;
- return c;
+ for (i = 0; i < ARRAY_SIZE(intel_virt_event_constraints); i++) {
+ c = intel_virt_event_constraints[i];
+ if (unlikely(constraint_match(c, event->hw.config))) {
+ event->hw.flags |= c->flags;
+ return c;
+ }
}
return NULL;
@@ -3357,7 +3366,7 @@ __intel_get_event_constraints(struct cpu_hw_events *cpuc, int idx,
{
struct event_constraint *c;
- c = intel_vlbr_constraints(event);
+ c = intel_virt_constraints(event);
if (c)
return c;
@@ -5349,6 +5358,11 @@ static struct attribute *spr_tsx_events_attrs[] = {
NULL,
};
+struct event_constraint vmetrics_constraint =
+ __EVENT_CONSTRAINT(INTEL_FIXED_VMETRICS_EVENT,
+ (1ULL << INTEL_PMC_IDX_FIXED_VMETRICS),
+ FIXED_EVENT_FLAGS, 1, 0, 0);
+
static ssize_t freeze_on_smi_show(struct device *cdev,
struct device_attribute *attr,
char *buf)
@@ -1482,6 +1482,7 @@ void reserve_lbr_buffers(void);
extern struct event_constraint bts_constraint;
extern struct event_constraint vlbr_constraint;
+extern struct event_constraint vmetrics_constraint;
void intel_pmu_enable_bts(u64 config);
@@ -390,6 +390,21 @@ static inline bool is_topdown_idx(int idx)
*/
#define INTEL_PMC_IDX_FIXED_VLBR (GLOBAL_STATUS_LBRS_FROZEN_BIT)
+/*
+ * We model guest TopDown metrics event tracing similarly.
+ *
+ * Guest metric events are recognized as vCPU process's events on host, they
+ * would be time-sharing multiplexed with other host metric events, so that
+ * we choose bit 48 (INTEL_PMC_IDX_METRIC_BASE) as the index of virtual
+ * metrics event.
+ */
+#define INTEL_PMC_IDX_FIXED_VMETRICS (INTEL_PMC_IDX_METRIC_BASE)
+
+/*
+ * Pseudo-encoding the guest metrics event as event=0x00,umask=0x11,
+ * since it would claim bit 48 which is effectively Fixed16.
+ */
+#define INTEL_FIXED_VMETRICS_EVENT 0x1100
/*
* Pseudo-encoding the guest LBR event as event=0x00,umask=0x1b,
* since it would claim bit 58 which is effectively Fixed26.