Skip to contentSkip to conversation

perf/amd/ibs: provide weights for all IBS op samples

PATCH In review Stephane Eranian 2 participants 2 messages Mar 13, 2024 – Mar 18, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf/amd/ibs: provide weights for all IBS op samples

IBS Op provides instructions latencies for each uop sampled. The current code was only providing the weights only for loads. This is useful information for performance analysis. This patch modifies the logic to provide the weights for all uops.

$ perf record -a -W -c 100003 -e ibs_op/cnt_ctl=1/GH ....
---
 arch/x86/events/amd/ibs.c | 46 +++++++++++++++++++++++++++++----------
 1 file changed, 35 insertions(+), 11 deletions(-)
arch/x86/events/amd/ibs.c +35 -11
index e91970b01d62..d2f4d3b19cf9 100644
@@ -957,6 +957,28 @@ static __u64 perf_ibs_get_op_data2(struct perf_ibs_data *ibs_data,
 	return val;
 }
 
+static void perf_ibs_parse_uop_latencies(__u64 sample_type,
+					 struct perf_ibs_data *ibs_data,
+					 struct perf_sample_data *data)
+{
+	union ibs_op_data op_data;
+
+	/* latencies not requested by user */
+	if (!(sample_type & PERF_SAMPLE_WEIGHT_TYPE))
+		return;
+
+	op_data.val = ibs_data->regs[ibs_op_msr_idx(MSR_AMD64_IBSOPDATA)];
+
+	if (sample_type & PERF_SAMPLE_WEIGHT_STRUCT) {
+		data->weight.var1_dw = 0;
+		data->weight.var2_w = op_data.tag_to_ret_ctr;
+		data->weight.var3_w = op_data.comp_to_ret_ctr;
+	} else {
+		data->weight.full = op_data.tag_to_ret_ctr;
+	}
+	data->sample_flags |= PERF_SAMPLE_WEIGHT_TYPE;
+}
+
 static void perf_ibs_parse_ld_st_data(__u64 sample_type,
 				      struct perf_ibs_data *ibs_data,
 				      struct perf_sample_data *data)
@@ -980,17 +1002,15 @@ static void perf_ibs_parse_ld_st_data(__u64 sample_type,
 		data->sample_flags |= PERF_SAMPLE_DATA_SRC;
 	}
 
-	if (sample_type & PERF_SAMPLE_WEIGHT_TYPE && op_data3.dc_miss &&
-	    data->data_src.mem_op == PERF_MEM_OP_LOAD) {
+	if (sample_type & PERF_SAMPLE_WEIGHT_TYPE) {
 		op_data.val = ibs_data->regs[ibs_op_msr_idx(MSR_AMD64_IBSOPDATA)];
-
-		if (sample_type & PERF_SAMPLE_WEIGHT_STRUCT) {
-			data->weight.var1_dw = op_data3.dc_miss_lat;
-			data->weight.var2_w = op_data.tag_to_ret_ctr;
-		} else if (sample_type & PERF_SAMPLE_WEIGHT) {
-			data->weight.full = op_data3.dc_miss_lat;
+		if (op_data3.dc_miss && data->data_src.mem_op == PERF_MEM_OP_LOAD) {
+			if (sample_type & PERF_SAMPLE_WEIGHT_STRUCT) {
+				data->weight.var1_dw = op_data3.dc_miss_lat;
+			} else if (sample_type & PERF_SAMPLE_WEIGHT) {
+				data->weight.full = op_data3.dc_miss_lat;
+			}
 		}
-		data->sample_flags |= PERF_SAMPLE_WEIGHT_TYPE;
 	}
 
 	if (sample_type & PERF_SAMPLE_ADDR && op_data3.dc_lin_addr_valid) {
@@ -1121,8 +1141,12 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs)
 		perf_sample_save_raw_data(&data, &raw);
 	}
 
-	if (perf_ibs == &perf_ibs_op)
-		perf_ibs_parse_ld_st_data(event->attr.sample_type, &ibs_data, &data);
+	if (perf_ibs == &perf_ibs_op) {
+		__u32 type = event->attr.sample_type;
+
+		perf_ibs_parse_uop_latencies(type, &ibs_data, &data);
+		perf_ibs_parse_ld_st_data(type, &ibs_data, &data);
+	}
 
 	/*
 	 * rip recorded by IbsOpRip will not be consistent with rsp and rbp
Signature · 1 line
2.44.0.278.ge034bb2e1d-goog
Reviewed-by on v1 1/1
#1 lore raw
cc +Ingo
Quoted 8 lines · Stephane Eranian

IBS Op provides instructions latencies for each uop sampled. The current code was only providing the weights only for loads. This is useful information for performance analysis. This patch modifies the logic to provide the weights for all uops.

$ perf record -a -W -c 100003 -e ibs_op/cnt_ctl=1/GH ....