All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] perf report: Add support to print a textual representation of IBS raw sample data
@ 2021-08-17 22:15 Kim Phillips
  2021-08-17 22:15 ` [PATCH 1/3] perf env: Add perf_env__cpuid, perf_env__{nr_}pmu_mappings Kim Phillips
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Kim Phillips @ 2021-08-17 22:15 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, kim.phillips
  Cc: Alexander Shishkin, Arnaldo Carvalho de Melo, Boris Ostrovsky,
	Ian Rogers, Ingo Molnar, Jiri Olsa, Joao Martins,
	Konrad Rzeszutek Wilk, Mark Rutland, Michael Petlan,
	Namhyung Kim, Peter Zijlstra, Robert Richter, Stephane Eranian,
	linux-kernel, linux-perf-users

Hello Linux perf tools users and maintainers,

The first patch in this series prepares the perf tool to support
retrieving cpuid and pmu_mappings data when in report mode,
information that is needed to accurately decode IBS data.

The second patch adds a header file tools/arch/x86/include/asm/amd-ibs.h
from a separate kernel-side submittion [1].

The third patch allows the tool to print a textual representation
of the sample data recorded by IBS.

[1] https://lore.kernel.org/lkml/20210817221048.88063-9-kim.phillips@amd.com

Kim Phillips (3):
  perf env: Add perf_env__cpuid, perf_env__{nr_}pmu_mappings
  perf report: Add tools/arch/x86/include/asm/amd-ibs.h
  perf report: Add support to print a textual representation of IBS raw
    sample data

 tools/arch/x86/include/asm/amd-ibs.h | 132 ++++++++++++
 tools/perf/check-headers.sh          |   1 +
 tools/perf/util/Build                |   1 +
 tools/perf/util/amd-sample-raw.c     | 290 +++++++++++++++++++++++++++
 tools/perf/util/env.c                |  78 +++++++
 tools/perf/util/env.h                |   5 +
 tools/perf/util/sample-raw.c         |   8 +
 tools/perf/util/sample-raw.h         |   6 +-
 8 files changed, 520 insertions(+), 1 deletion(-)
 create mode 100644 tools/arch/x86/include/asm/amd-ibs.h
 create mode 100644 tools/perf/util/amd-sample-raw.c

Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joao Martins <joao.m.martins@oracle.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-perf-users@vger.kernel.org

-- 
2.31.1



^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/3] perf env: Add perf_env__cpuid, perf_env__{nr_}pmu_mappings
  2021-08-17 22:15 [PATCH 0/3] perf report: Add support to print a textual representation of IBS raw sample data Kim Phillips
@ 2021-08-17 22:15 ` Kim Phillips
  2021-08-17 22:15 ` [PATCH 2/3] perf report: Add tools/arch/x86/include/asm/amd-ibs.h Kim Phillips
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 12+ messages in thread
From: Kim Phillips @ 2021-08-17 22:15 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, kim.phillips
  Cc: Alexander Shishkin, Arnaldo Carvalho de Melo, Boris Ostrovsky,
	Ian Rogers, Ingo Molnar, Jiri Olsa, Joao Martins,
	Konrad Rzeszutek Wilk, Mark Rutland, Michael Petlan,
	Namhyung Kim, Peter Zijlstra, Robert Richter, Stephane Eranian,
	linux-kernel, linux-perf-users

To be used by IBS raw data display: It needs the recorder's cpuid in
order to determine which errata workarounds to apply to the data, and
the pmu_mappings are needed in order to figure out which PMU sample
type is IBS Fetch vs. IBS Op.  When not available from perf.data,
we assume local operation, and retrieve cpuid and pmu mappings
directly from the running system.

Signed-off-by: Kim Phillips <kim.phillips@amd.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joao Martins <joao.m.martins@oracle.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-perf-users@vger.kernel.org
---
 tools/perf/util/env.c | 78 +++++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/env.h |  5 +++
 2 files changed, 83 insertions(+)

diff --git a/tools/perf/util/env.c b/tools/perf/util/env.c
index 8f7ff0035c41..cf773f0dec38 100644
--- a/tools/perf/util/env.c
+++ b/tools/perf/util/env.c
@@ -10,6 +10,7 @@
 #include <sys/utsname.h>
 #include <stdlib.h>
 #include <string.h>
+#include "strbuf.h"
 
 struct perf_env perf_env;
 
@@ -306,6 +307,45 @@ int perf_env__read_cpu_topology_map(struct perf_env *env)
 	return 0;
 }
 
+int perf_env__read_pmu_mappings(struct perf_env *env)
+{
+	struct perf_pmu *pmu = NULL;
+	u32 pmu_num = 0;
+	struct strbuf sb;
+
+	while ((pmu = perf_pmu__scan(pmu))) {
+		if (!pmu->name)
+			continue;
+		pmu_num++;
+	}
+	if (!pmu_num) {
+		pr_debug("pmu mappings not available\n");
+		return -ENOENT;
+	}
+	env->nr_pmu_mappings = pmu_num;
+
+	if (strbuf_init(&sb, 128 * pmu_num) < 0)
+		return -ENOMEM;
+
+	while ((pmu = perf_pmu__scan(pmu))) {
+		if (!pmu->name)
+			continue;
+		if (strbuf_addf(&sb, "%u:%s", pmu->type, pmu->name) < 0)
+			goto error;
+		/* include a NULL character at the end */
+		if (strbuf_add(&sb, "", 1) < 0)
+			goto error;
+	}
+
+	env->pmu_mappings = strbuf_detach(&sb, NULL);
+
+	return 0;
+
+error:
+	strbuf_release(&sb);
+	return -1;
+}
+
 int perf_env__read_cpuid(struct perf_env *env)
 {
 	char cpuid[128];
@@ -404,6 +444,44 @@ const char *perf_env__arch(struct perf_env *env)
 	return normalize_arch(arch_name);
 }
 
+const char *perf_env__cpuid(struct perf_env *env)
+{
+	int status;
+
+	if (!env || !env->cpuid) { /* Assume local operation */
+		status = perf_env__read_cpuid(env);
+		if (status)
+			return NULL;
+	}
+
+	return env->cpuid;
+}
+
+int perf_env__nr_pmu_mappings(struct perf_env *env)
+{
+	int status;
+
+	if (!env || !env->nr_pmu_mappings) { /* Assume local operation */
+		status = perf_env__read_pmu_mappings(env);
+		if (status)
+			return 0;
+	}
+
+	return env->nr_pmu_mappings;
+}
+
+const char *perf_env__pmu_mappings(struct perf_env *env)
+{
+	int status;
+
+	if (!env || !env->pmu_mappings) { /* Assume local operation */
+		status = perf_env__read_pmu_mappings(env);
+		if (status)
+			return NULL;
+	}
+
+	return env->pmu_mappings;
+}
 
 int perf_env__numa_node(struct perf_env *env, int cpu)
 {
diff --git a/tools/perf/util/env.h b/tools/perf/util/env.h
index 1f5175820a05..1383876f72b3 100644
--- a/tools/perf/util/env.h
+++ b/tools/perf/util/env.h
@@ -149,11 +149,16 @@ int perf_env__kernel_is_64_bit(struct perf_env *env);
 int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]);
 
 int perf_env__read_cpuid(struct perf_env *env);
+int perf_env__read_pmu_mappings(struct perf_env *env);
+int perf_env__nr_pmu_mappings(struct perf_env *env);
+const char *perf_env__pmu_mappings(struct perf_env *env);
+
 int perf_env__read_cpu_topology_map(struct perf_env *env);
 
 void cpu_cache_level__free(struct cpu_cache_level *cache);
 
 const char *perf_env__arch(struct perf_env *env);
+const char *perf_env__cpuid(struct perf_env *env);
 const char *perf_env__raw_arch(struct perf_env *env);
 int perf_env__nr_cpus_avail(struct perf_env *env);
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/3] perf report: Add tools/arch/x86/include/asm/amd-ibs.h
  2021-08-17 22:15 [PATCH 0/3] perf report: Add support to print a textual representation of IBS raw sample data Kim Phillips
  2021-08-17 22:15 ` [PATCH 1/3] perf env: Add perf_env__cpuid, perf_env__{nr_}pmu_mappings Kim Phillips
@ 2021-08-17 22:15 ` Kim Phillips
  2021-08-17 22:15 ` [PATCH 3/3] perf report: Add support to print a textual representation of IBS raw sample data Kim Phillips
  2021-09-09 21:58 ` [PATCH 0/3] " Kim Phillips
  3 siblings, 0 replies; 12+ messages in thread
From: Kim Phillips @ 2021-08-17 22:15 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, kim.phillips
  Cc: Alexander Shishkin, Arnaldo Carvalho de Melo, Boris Ostrovsky,
	Ian Rogers, Ingo Molnar, Jiri Olsa, Joao Martins,
	Konrad Rzeszutek Wilk, Mark Rutland, Michael Petlan,
	Namhyung Kim, Peter Zijlstra, Robert Richter, Stephane Eranian,
	linux-kernel, linux-perf-users

This is a tools/-side patch for the patch that adds the original copy
of the IBS header file, in arch/x86/include/asm/.

We also add an entry to check-headers.sh, so future changes continue
to be copied.

Signed-off-by: Kim Phillips <kim.phillips@amd.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joao Martins <joao.m.martins@oracle.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-perf-users@vger.kernel.org
---
 tools/arch/x86/include/asm/amd-ibs.h | 132 +++++++++++++++++++++++++++
 tools/perf/check-headers.sh          |   1 +
 2 files changed, 133 insertions(+)
 create mode 100644 tools/arch/x86/include/asm/amd-ibs.h

diff --git a/tools/arch/x86/include/asm/amd-ibs.h b/tools/arch/x86/include/asm/amd-ibs.h
new file mode 100644
index 000000000000..46e1df45efc0
--- /dev/null
+++ b/tools/arch/x86/include/asm/amd-ibs.h
@@ -0,0 +1,132 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * From PPR Vol 1 for AMD Family 19h Model 01h B1
+ * 55898 Rev 0.35 - Feb 5, 2021
+ */
+
+#include <asm/msr-index.h>
+
+/*
+ * IBS Hardware MSRs
+ */
+
+/* MSR 0xc0011030: IBS Fetch Control */
+union ibs_fetch_ctl {
+	__u64 val;
+	struct {
+		__u64	fetch_maxcnt:16,/* 0-15: instruction fetch max. count */
+			fetch_cnt:16,	/* 16-31: instruction fetch count */
+			fetch_lat:16,	/* 32-47: instruction fetch latency */
+			fetch_en:1,	/* 48: instruction fetch enable */
+			fetch_val:1,	/* 49: instruction fetch valid */
+			fetch_comp:1,	/* 50: instruction fetch complete */
+			ic_miss:1,	/* 51: i-cache miss */
+			phy_addr_valid:1,/* 52: physical address valid */
+			l1tlb_pgsz:2,	/* 53-54: i-cache L1TLB page size
+					 *	  (needs IbsPhyAddrValid) */
+			l1tlb_miss:1,	/* 55: i-cache fetch missed in L1TLB */
+			l2tlb_miss:1,	/* 56: i-cache fetch missed in L2TLB */
+			rand_en:1,	/* 57: random tagging enable */
+			fetch_l2_miss:1,/* 58: L2 miss for sampled fetch
+					 *      (needs IbsFetchComp) */
+			reserved:5;	/* 59-63: reserved */
+	};
+};
+
+/* MSR 0xc0011033: IBS Execution Control */
+union ibs_op_ctl {
+	__u64 val;
+	struct {
+		__u64	opmaxcnt:16,	/* 0-15: periodic op max. count */
+			reserved0:1,	/* 16: reserved */
+			op_en:1,	/* 17: op sampling enable */
+			op_val:1,	/* 18: op sample valid */
+			cnt_ctl:1,	/* 19: periodic op counter control */
+			opmaxcnt_ext:7,	/* 20-26: upper 7 bits of periodic op maximum count */
+			reserved1:5,	/* 27-31: reserved */
+			opcurcnt:27,	/* 32-58: periodic op counter current count */
+			reserved2:5;	/* 59-63: reserved */
+	};
+};
+
+/* MSR 0xc0011035: IBS Op Data 2 */
+union ibs_op_data {
+	__u64 val;
+	struct {
+		__u64	comp_to_ret_ctr:16,	/* 0-15: op completion to retire count */
+			tag_to_ret_ctr:16,	/* 15-31: op tag to retire count */
+			reserved1:2,		/* 32-33: reserved */
+			op_return:1,		/* 34: return op */
+			op_brn_taken:1,		/* 35: taken branch op */
+			op_brn_misp:1,		/* 36: mispredicted branch op */
+			op_brn_ret:1,		/* 37: branch op retired */
+			op_rip_invalid:1,	/* 38: RIP is invalid */
+			op_brn_fuse:1,		/* 39: fused branch op */
+			op_microcode:1,		/* 40: microcode op */
+			reserved2:23;		/* 41-63: reserved */
+	};
+};
+
+/* MSR 0xc0011036: IBS Op Data 2 */
+union ibs_op_data2 {
+	__u64 val;
+	struct {
+		__u64	data_src:3,	/* 0-2: data source */
+			reserved0:1,	/* 3: reserved */
+			rmt_node:1,	/* 4: destination node */
+			cache_hit_st:1,	/* 5: cache hit state */
+			reserved1:57;	/* 5-63: reserved */
+	};
+};
+
+/* MSR 0xc0011037: IBS Op Data 3 */
+union ibs_op_data3 {
+	__u64 val;
+	struct {
+		__u64	ld_op:1,			/* 0: load op */
+			st_op:1,			/* 1: store op */
+			dc_l1tlb_miss:1,		/* 2: data cache L1TLB miss */
+			dc_l2tlb_miss:1,		/* 3: data cache L2TLB hit in 2M page */
+			dc_l1tlb_hit_2m:1,		/* 4: data cache L1TLB hit in 2M page */
+			dc_l1tlb_hit_1g:1,		/* 5: data cache L1TLB hit in 1G page */
+			dc_l2tlb_hit_2m:1,		/* 6: data cache L2TLB hit in 2M page */
+			dc_miss:1,			/* 7: data cache miss */
+			dc_mis_acc:1,			/* 8: misaligned access */
+			reserved:4,			/* 9-12: reserved */
+			dc_wc_mem_acc:1,		/* 13: write combining memory access */
+			dc_uc_mem_acc:1,		/* 14: uncacheable memory access */
+			dc_locked_op:1,			/* 15: locked operation */
+			dc_miss_no_mab_alloc:1,		/* 16: DC miss with no MAB allocated */
+			dc_lin_addr_valid:1,		/* 17: data cache linear address valid */
+			dc_phy_addr_valid:1,		/* 18: data cache physical address valid */
+			dc_l2_tlb_hit_1g:1,		/* 19: data cache L2 hit in 1GB page */
+			l2_miss:1,			/* 20: L2 cache miss */
+			sw_pf:1,			/* 21: software prefetch */
+			op_mem_width:4,			/* 22-25: load/store size in bytes */
+			op_dc_miss_open_mem_reqs:6,	/* 26-31: outstanding mem reqs on DC fill */
+			dc_miss_lat:16,			/* 32-47: data cache miss latency */
+			tlb_refill_lat:16;		/* 48-63: L1 TLB refill latency */
+	};
+};
+
+/* MSR 0xc001103c: IBS Fetch Control Extended */
+union ic_ibs_extd_ctl {
+	__u64 val;
+	struct {
+		__u64	itlb_refill_lat:16,	/* 0-15: ITLB Refill latency for sampled fetch */
+			reserved:48;		/* 16-63: reserved */
+	};
+};
+
+/*
+ * IBS driver related
+ */
+
+struct perf_ibs_data {
+	u32		size;
+	union {
+		u32	data[0];	/* data buffer starts here */
+		u32	caps;
+	};
+	u64		regs[MSR_AMD64_IBS_REG_COUNT_MAX];
+};
diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
index c783558332b8..4a6b2b4ec507 100755
--- a/tools/perf/check-headers.sh
+++ b/tools/perf/check-headers.sh
@@ -34,6 +34,7 @@ arch/x86/include/asm/inat_types.h
 arch/x86/include/asm/emulate_prefix.h
 arch/x86/include/asm/irq_vectors.h
 arch/x86/include/asm/msr-index.h
+arch/x86/include/asm/amd-ibs.h
 arch/x86/include/uapi/asm/prctl.h
 arch/x86/lib/x86-opcode-map.txt
 arch/x86/tools/gen-insn-attr-x86.awk
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/3] perf report: Add support to print a textual representation of IBS raw sample data
  2021-08-17 22:15 [PATCH 0/3] perf report: Add support to print a textual representation of IBS raw sample data Kim Phillips
  2021-08-17 22:15 ` [PATCH 1/3] perf env: Add perf_env__cpuid, perf_env__{nr_}pmu_mappings Kim Phillips
  2021-08-17 22:15 ` [PATCH 2/3] perf report: Add tools/arch/x86/include/asm/amd-ibs.h Kim Phillips
@ 2021-08-17 22:15 ` Kim Phillips
  2021-09-09 21:58 ` [PATCH 0/3] " Kim Phillips
  3 siblings, 0 replies; 12+ messages in thread
From: Kim Phillips @ 2021-08-17 22:15 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, kim.phillips
  Cc: Alexander Shishkin, Arnaldo Carvalho de Melo, Boris Ostrovsky,
	Ian Rogers, Ingo Molnar, Jiri Olsa, Joao Martins,
	Konrad Rzeszutek Wilk, Mark Rutland, Michael Petlan,
	Namhyung Kim, Peter Zijlstra, Robert Richter, Stephane Eranian,
	linux-kernel, linux-perf-users

Perf records IBS (Instruction Based Sampling) extra sample data when
'perf record --raw-samples' is used with an IBS-compatible event, on a
machine that supports IBS.  IBS support is indicated in
CPUID_Fn80000001_ECX bit #10.

Up until now, users have been able to see the extra sample data solely
in raw hex format using 'perf report --dump-raw-trace'.  From there,
users could decode the data either manually, or by using an external
script.

Enable the built-in 'perf report --dump-raw-trace' to do the decoding
of the extra sample data bits, so manual or external script decoding
isn't necessary.

Example usage:

sudo perf record -c 10000001 -a --raw-samples -e ibs_fetch/rand_en=1/,ibs_op/cnt_ctl=1/ -C 0,1 taskset -c 0,1 7za b -mmt2 | perf report --dump-raw-trace

Stdout contains IBS Fetch samples, e.g.:

ibs_fetch_ctl:	02170007ffffffff MaxCnt 1048560 Cnt 1048560 Lat     7 En 1 Val 1 Comp 1 IcMiss 0 PhyAddrValid 1 L1TlbPgSz 4KB L1TlbMiss 0 L2TlbMiss 0 RandEn 1 L2Miss 0
IbsFetchLinAd:	000056016b2ead40
IbsFetchPhysAd:	000000115cedfd40
ic_ibs_ext_ctl:	0000000000000000 IbsItlbRefillLat   0

..and IBS Op samples, e.g.:

ibs_op_ctl:	0000009e009e8968 MaxCnt  10000000 En 1 Val 1 CntCtl 1=uOps CurCnt       158
IbsOpRip:	000056016b2ea73d
ibs_op_data:	00000000000b0002 CompToRetCtr     2 TagToRetCtr    11 BrnRet 0  RipInvalid 0 BrnFuse 0 Microcode 0
ibs_op_data2:	0000000000000002 CacheHitSt 0=M-state RmtNode 0 DataSrc 2=Local node cache
ibs_op_data3:	0000000000c60002 LdOp 0 StOp 1 DcL1TlbMiss 0 DcL2TlbMiss 0 DcL1TlbHit2M 0 DcL1TlbHit1G 0 DcL2TlbHit2M 0 DcMiss 0 DcMisAcc 0 DcWcMemAcc 0 DcUcMemAcc 0 DcLockedOp 0 DcMissNoMabAlloc 0 DcLinAddrValid 1 DcPhyAddrValid 1 DcL2TlbHit1G 0 L2Miss 0 SwPf 0 OpMemWidth  4 bytes OpDcMissOpenMemReqs  0 DcMissLat     0 TlbRefillLat     0
IbsDCLinAd:	00007f133c319ce0
IbsDCPhysAd:	0000000270485ce0

Signed-off-by: Kim Phillips <kim.phillips@amd.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Joao Martins <joao.m.martins@oracle.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: linux-kernel@vger.kernel.org
Cc: linux-perf-users@vger.kernel.org
---
 tools/perf/util/Build            |   1 +
 tools/perf/util/amd-sample-raw.c | 290 +++++++++++++++++++++++++++++++
 tools/perf/util/sample-raw.c     |   8 +
 tools/perf/util/sample-raw.h     |   6 +-
 4 files changed, 304 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/util/amd-sample-raw.c

diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 2d4fa1304178..f2914d5bed6e 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -59,6 +59,7 @@ perf-y += pstack.o
 perf-y += session.o
 perf-y += sample-raw.o
 perf-y += s390-sample-raw.o
+perf-y += amd-sample-raw.o
 perf-$(CONFIG_TRACE) += syscalltbl.o
 perf-y += ordered-events.o
 perf-y += namespaces.o
diff --git a/tools/perf/util/amd-sample-raw.c b/tools/perf/util/amd-sample-raw.c
new file mode 100644
index 000000000000..fc1f670e8856
--- /dev/null
+++ b/tools/perf/util/amd-sample-raw.c
@@ -0,0 +1,290 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AMD specific. Provide textual annotation for IBS raw sample data.
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include <linux/string.h>
+#include <asm/amd-ibs.h>
+
+#include "debug.h"
+#include "session.h"
+#include "evlist.h"
+#include "sample-raw.h"
+#include "pmu-events/pmu-events.h"
+
+static u32 cpu_family, cpu_model, ibs_fetch_type, ibs_op_type;
+
+static void pr_ibs_fetch_ctl(union ibs_fetch_ctl reg)
+{
+	const char * const ic_miss_strs[] = {
+		" IcMiss 0",
+		" IcMiss 1",
+	};
+	const char * const l1tlb_pgsz_strs[] = {
+		" L1TlbPgSz 4KB",
+		" L1TlbPgSz 2MB",
+		" L1TlbPgSz 1GB",
+		" L1TlbPgSz RESERVED"
+	};
+	const char * const l1tlb_pgsz_strs_erratum1347[] = {
+		" L1TlbPgSz 4KB",
+		" L1TlbPgSz 16KB",
+		" L1TlbPgSz 2MB",
+		" L1TlbPgSz 1GB"
+	};
+	const char *ic_miss_str = NULL;
+	const char *l1tlb_pgsz_str = NULL;
+
+	if (cpu_family == 0x19 && cpu_model < 0x10) {
+		/*
+		 * Erratum #1238 workaround is to ignore MSRC001_1030[IbsIcMiss]
+		 * Erratum #1347 workaround is to use table provided in erratum
+		 */
+		if (reg.phy_addr_valid)
+			l1tlb_pgsz_str = l1tlb_pgsz_strs_erratum1347[reg.l1tlb_pgsz];
+	} else {
+		if (reg.phy_addr_valid)
+			l1tlb_pgsz_str = l1tlb_pgsz_strs[reg.l1tlb_pgsz];
+		ic_miss_str = ic_miss_strs[reg.ic_miss];
+	}
+
+	printf("ibs_fetch_ctl:\t%016llx MaxCnt %7d Cnt %7d Lat %5d En %d Val %d Comp %d%s "
+	       "PhyAddrValid %d%s L1TlbMiss %d L2TlbMiss %d RandEn %d%s\n",
+		reg.val, reg.fetch_maxcnt << 4, reg.fetch_cnt << 4, reg.fetch_lat,
+		reg.fetch_en, reg.fetch_val, reg.fetch_comp, ic_miss_str ? : "",
+		reg.phy_addr_valid, l1tlb_pgsz_str ? : "", reg.l1tlb_miss, reg.l2tlb_miss,
+		reg.rand_en, reg.fetch_comp ? (reg.fetch_l2_miss ? " L2Miss 1" : " L2Miss 0") : "");
+}
+
+static void pr_ic_ibs_extd_ctl(union ic_ibs_extd_ctl reg)
+{
+	printf("ic_ibs_ext_ctl:\t%016llx IbsItlbRefillLat %3d\n", reg.val, reg.itlb_refill_lat);
+}
+
+static void pr_ibs_op_ctl(union ibs_op_ctl reg)
+{
+	printf("ibs_op_ctl:\t%016llx MaxCnt %9d En %d Val %d CntCtl %d=%s CurCnt %9d\n",
+	       reg.val, ((reg.opmaxcnt_ext << 16) | reg.opmaxcnt) << 4, reg.op_en, reg.op_val,
+	       reg.cnt_ctl, reg.cnt_ctl ? "uOps" : "cycles", reg.opcurcnt);
+}
+
+static void pr_ibs_op_data(union ibs_op_data reg)
+{
+	printf("ibs_op_data:\t%016llx CompToRetCtr %5d TagToRetCtr %5d%s%s%s BrnRet %d "
+		" RipInvalid %d BrnFuse %d Microcode %d\n",
+		reg.val, reg.comp_to_ret_ctr, reg.tag_to_ret_ctr,
+		reg.op_brn_ret ? (reg.op_return ? " OpReturn 1" : " OpReturn 0") : "",
+		reg.op_brn_ret ? (reg.op_brn_taken ? " OpBrnTaken 1" : " OpBrnTaken 0") : "",
+		reg.op_brn_ret ? (reg.op_brn_misp ? " OpBrnMisp 1" : " OpBrnMisp 0") : "",
+		reg.op_brn_ret, reg.op_rip_invalid, reg.op_brn_fuse, reg.op_microcode);
+}
+
+static void pr_ibs_op_data2(union ibs_op_data2 reg)
+{
+	static const char * const data_src_str[] = {
+		"",
+		" DataSrc 1=(reserved)",
+		" DataSrc 2=Local node cache",
+		" DataSrc 3=DRAM",
+		" DataSrc 4=Remote node cache",
+		" DataSrc 5=(reserved)",
+		" DataSrc 6=(reserved)",
+		" DataSrc 7=Other"
+	};
+
+	printf("ibs_op_data2:\t%016llx %sRmtNode %d%s\n", reg.val,
+	       reg.data_src == 2 ? (reg.cache_hit_st ? "CacheHitSt 1=O-State "
+						     : "CacheHitSt 0=M-state ") : "",
+	       reg.rmt_node, data_src_str[reg.data_src]);
+}
+
+static void pr_ibs_op_data3(union ibs_op_data3 reg)
+{
+	char l2_miss_str[sizeof(" L2Miss _")] = "";
+	char op_mem_width_str[sizeof(" OpMemWidth __ bytes")] = "";
+	char op_dc_miss_open_mem_reqs_str[sizeof(" OpDcMissOpenMemReqs __")] = "";
+
+	/*
+	 * Erratum #1293
+	 * Ignore L2Miss and OpDcMissOpenMemReqs (and opdata2) if DcMissNoMabAlloc or SwPf set
+	 */
+	if (!(cpu_family == 0x19 && cpu_model < 0x10 && (reg.dc_miss_no_mab_alloc || reg.sw_pf))) {
+		snprintf(l2_miss_str, sizeof(" L2Miss _"),
+			 " L2Miss %d", reg.l2_miss);
+		snprintf(op_dc_miss_open_mem_reqs_str, sizeof(" OpDcMissOpenMemReqs __"),
+			 " OpDcMissOpenMemReqs %2d", reg.op_dc_miss_open_mem_reqs);
+	}
+
+	if (reg.op_mem_width)
+		snprintf(op_mem_width_str, sizeof(" OpMemWidth __ bytes"),
+			 " OpMemWidth %2d bytes", 1 << (reg.op_mem_width - 1));
+
+	printf("ibs_op_data3:\t%016llx LdOp %d StOp %d DcL1TlbMiss %d DcL2TlbMiss %d "
+		"DcL1TlbHit2M %d DcL1TlbHit1G %d DcL2TlbHit2M %d DcMiss %d DcMisAcc %d "
+		"DcWcMemAcc %d DcUcMemAcc %d DcLockedOp %d DcMissNoMabAlloc %d DcLinAddrValid %d "
+		"DcPhyAddrValid %d DcL2TlbHit1G %d%s SwPf %d%s%s DcMissLat %5d TlbRefillLat %5d\n",
+		reg.val, reg.ld_op, reg.st_op, reg.dc_l1tlb_miss, reg.dc_l2tlb_miss,
+		reg.dc_l1tlb_hit_2m, reg.dc_l1tlb_hit_1g, reg.dc_l2tlb_hit_2m, reg.dc_miss,
+		reg.dc_mis_acc, reg.dc_wc_mem_acc, reg.dc_uc_mem_acc, reg.dc_locked_op,
+		reg.dc_miss_no_mab_alloc, reg.dc_lin_addr_valid, reg.dc_phy_addr_valid,
+		reg.dc_l2_tlb_hit_1g, l2_miss_str, reg.sw_pf, op_mem_width_str,
+		op_dc_miss_open_mem_reqs_str, reg.dc_miss_lat, reg.tlb_refill_lat);
+}
+
+/*
+ * IBS Op/Execution MSRs always saved, in order, are:
+ * IBS_OP_CTL, IBS_OP_RIP, IBS_OP_DATA, IBS_OP_DATA2,
+ * IBS_OP_DATA3, IBS_DC_LINADDR, IBS_DC_PHYSADDR, BP_IBSTGT_RIP
+ */
+static void amd_dump_ibs_op(struct perf_sample *sample)
+{
+	struct perf_ibs_data *data = sample->raw_data;
+	union ibs_op_ctl *op_ctl = (union ibs_op_ctl *)data->data;
+	__u64 *rip = (__u64 *)op_ctl + 1;
+	union ibs_op_data *op_data = (union ibs_op_data *)(rip + 1);
+	union ibs_op_data3 *op_data3 = (union ibs_op_data3 *)(rip + 3);
+
+	pr_ibs_op_ctl(*op_ctl);
+	if (!op_data->op_rip_invalid)
+		printf("IbsOpRip:\t%016llx\n", *rip);
+	pr_ibs_op_data(*op_data);
+	/*
+	 * Erratum #1293: ignore op_data2 if DcMissNoMabAlloc or SwPf are set
+	 */
+	if (!(cpu_family == 0x19 && cpu_model < 0x10 &&
+	      (op_data3->dc_miss_no_mab_alloc || op_data3->sw_pf)))
+		pr_ibs_op_data2(*(union ibs_op_data2 *)(rip + 2));
+	pr_ibs_op_data3(*op_data3);
+	if (op_data3->dc_lin_addr_valid)
+		printf("IbsDCLinAd:\t%016llx\n", *(rip + 4));
+	if (op_data3->dc_phy_addr_valid)
+		printf("IbsDCPhysAd:\t%016llx\n", *(rip + 5));
+	if (op_data->op_brn_ret && *(rip + 6))
+		printf("IbsBrTarget:\t%016llx\n", *(rip + 6));
+}
+
+/*
+ * IBS Fetch MSRs always saved, in order, are:
+ * IBS_FETCH_CTL, IBS_FETCH_LINADDR, IBS_FETCH_PHYSADDR, IC_IBS_EXTD_CTL
+ */
+static void amd_dump_ibs_fetch(struct perf_sample *sample)
+{
+	struct perf_ibs_data *data = sample->raw_data;
+	union ibs_fetch_ctl *fetch_ctl = (union ibs_fetch_ctl *)data->data;
+	__u64 *addr = (__u64 *)fetch_ctl + 1;
+	union ic_ibs_extd_ctl *extd_ctl = (union ic_ibs_extd_ctl *)addr + 2;
+
+	pr_ibs_fetch_ctl(*fetch_ctl);
+	printf("IbsFetchLinAd:\t%016llx\n", *addr++);
+	if (fetch_ctl->phy_addr_valid)
+		printf("IbsFetchPhysAd:\t%016llx\n", *addr);
+	pr_ic_ibs_extd_ctl(*extd_ctl);
+}
+
+/*
+ * Test for enable and valid bits in captured control MSRs.
+ */
+static bool is_valid_ibs_fetch_sample(struct perf_sample *sample)
+{
+	struct perf_ibs_data *data = sample->raw_data;
+	union ibs_fetch_ctl *fetch_ctl = (union ibs_fetch_ctl *)data->data;
+
+	if (fetch_ctl->fetch_en && fetch_ctl->fetch_val)
+		return true;
+
+	return false;
+}
+
+static bool is_valid_ibs_op_sample(struct perf_sample *sample)
+{
+	struct perf_ibs_data *data = sample->raw_data;
+	union ibs_op_ctl *op_ctl = (union ibs_op_ctl *)data->data;
+
+	if (op_ctl->op_en && op_ctl->op_val)
+		return true;
+
+	return false;
+}
+
+/* AMD vendor specific raw sample function. Check for PERF_RECORD_SAMPLE events
+ * and if the event was triggered by IBS, display its raw data with decoded text.
+ * The function is only invoked when the dump flag -D is set.
+ */
+void evlist__amd_sample_raw(struct evlist *evlist, union perf_event *event,
+			    struct perf_sample *sample)
+{
+	struct evsel *evsel;
+
+	if (event->header.type != PERF_RECORD_SAMPLE || !sample->raw_size)
+		return;
+
+	evsel = evlist__event2evsel(evlist, event);
+	if (!evsel)
+		return;
+
+	if (evsel->core.attr.type == ibs_fetch_type) {
+		if (!is_valid_ibs_fetch_sample(sample)) {
+			pr_debug("Invalid raw IBS Fetch MSR data encountered\n");
+			return;
+		}
+		amd_dump_ibs_fetch(sample);
+	} else if (evsel->core.attr.type == ibs_op_type) {
+		if (!is_valid_ibs_op_sample(sample)) {
+			pr_debug("Invalid raw IBS Op MSR data encountered\n");
+			return;
+		}
+		amd_dump_ibs_op(sample);
+	}
+}
+
+static void parse_cpuid(struct perf_env *env)
+{
+	const char *cpuid;
+	int ret;
+
+	cpuid = perf_env__cpuid(env);
+	/*
+	 * cpuid = "AuthenticAMD,family,model,stepping"
+	 */
+	ret = sscanf(cpuid, "%*[^,],%u,%u", &cpu_family, &cpu_model);
+	if (ret != 2)
+		pr_debug("problem parsing cpuid\n");
+}
+
+/*
+ * Find and assign the type number used for ibs_op or ibs_fetch samples.
+ * Device names can be large - we are only interested in the first 9 characters,
+ * to match "ibs_fetch".
+ */
+bool evlist__has_amd_ibs(struct evlist *evlist)
+{
+	struct perf_env *env = evlist->env;
+	int ret, nr_pmu_mappings = perf_env__nr_pmu_mappings(env);
+	const char *pmu_mapping = perf_env__pmu_mappings(env);
+	char name[sizeof("ibs_fetch")];
+	u32 type;
+
+	while (nr_pmu_mappings--) {
+		ret = sscanf(pmu_mapping, "%u:%9s", &type, name);
+		if (ret == 2) {
+			if (strstarts(name, "ibs_op"))
+				ibs_op_type = type;
+			else if (strstarts(name, "ibs_fetch"))
+				ibs_fetch_type = type;
+		}
+		pmu_mapping += strlen(pmu_mapping) + 1 /* '\0' */;
+	}
+
+	if (ibs_fetch_type || ibs_op_type) {
+		if (!cpu_family)
+			parse_cpuid(env);
+		return true;
+	}
+
+	return false;
+}
diff --git a/tools/perf/util/sample-raw.c b/tools/perf/util/sample-raw.c
index cde5cd3ce49b..f3f6bd9d290e 100644
--- a/tools/perf/util/sample-raw.c
+++ b/tools/perf/util/sample-raw.c
@@ -1,8 +1,10 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 
 #include <string.h>
+#include <linux/string.h>
 #include "evlist.h"
 #include "env.h"
+#include "header.h"
 #include "sample-raw.h"
 
 /*
@@ -12,7 +14,13 @@
 void evlist__init_trace_event_sample_raw(struct evlist *evlist)
 {
 	const char *arch_pf = perf_env__arch(evlist->env);
+	const char *cpuid = perf_env__cpuid(evlist->env);
 
 	if (arch_pf && !strcmp("s390", arch_pf))
 		evlist->trace_event_sample_raw = evlist__s390_sample_raw;
+	else if (arch_pf && !strcmp("x86", arch_pf) &&
+		 cpuid && strstarts(cpuid, "AuthenticAMD") &&
+		 evlist__has_amd_ibs(evlist)) {
+		evlist->trace_event_sample_raw = evlist__amd_sample_raw;
+	}
 }
diff --git a/tools/perf/util/sample-raw.h b/tools/perf/util/sample-raw.h
index 4be84a5510cf..ea01c5811503 100644
--- a/tools/perf/util/sample-raw.h
+++ b/tools/perf/util/sample-raw.h
@@ -6,6 +6,10 @@ struct evlist;
 union perf_event;
 struct perf_sample;
 
-void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event, struct perf_sample *sample);
+void evlist__s390_sample_raw(struct evlist *evlist, union perf_event *event,
+			     struct perf_sample *sample);
+bool evlist__has_amd_ibs(struct evlist *evlist);
+void evlist__amd_sample_raw(struct evlist *evlist, union perf_event *event,
+			    struct perf_sample *sample);
 void evlist__init_trace_event_sample_raw(struct evlist *evlist);
 #endif /* __PERF_EVLIST_H */
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/3] perf report: Add support to print a textual representation of IBS raw sample data
  2021-08-17 22:15 [PATCH 0/3] perf report: Add support to print a textual representation of IBS raw sample data Kim Phillips
                   ` (2 preceding siblings ...)
  2021-08-17 22:15 ` [PATCH 3/3] perf report: Add support to print a textual representation of IBS raw sample data Kim Phillips
@ 2021-09-09 21:58 ` Kim Phillips
  2021-09-10 13:47   ` Arnaldo Carvalho de Melo
  3 siblings, 1 reply; 12+ messages in thread
From: Kim Phillips @ 2021-09-09 21:58 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Alexander Shishkin, Arnaldo Carvalho de Melo, Boris Ostrovsky,
	Ian Rogers, Ingo Molnar, Jiri Olsa, Joao Martins,
	Konrad Rzeszutek Wilk, Mark Rutland, Michael Petlan,
	Namhyung Kim, Peter Zijlstra, Robert Richter, Stephane Eranian,
	linux-kernel, linux-perf-users

Hi Arnaldo,

Can you please take a look at applying this series?  Its kernel-side 
dependent series has already been applied and is in Linus' master.

Thanks,

Kim

On 8/17/21 5:15 PM, Kim Phillips wrote:
> Hello Linux perf tools users and maintainers,
> 
> The first patch in this series prepares the perf tool to support
> retrieving cpuid and pmu_mappings data when in report mode,
> information that is needed to accurately decode IBS data.
> 
> The second patch adds a header file tools/arch/x86/include/asm/amd-ibs.h
> from a separate kernel-side submittion [1].
> 
> The third patch allows the tool to print a textual representation
> of the sample data recorded by IBS.
> 
> [1] https://lore.kernel.org/lkml/20210817221048.88063-9-kim.phillips@amd.com
> 
> Kim Phillips (3):
>    perf env: Add perf_env__cpuid, perf_env__{nr_}pmu_mappings
>    perf report: Add tools/arch/x86/include/asm/amd-ibs.h
>    perf report: Add support to print a textual representation of IBS raw
>      sample data
> 
>   tools/arch/x86/include/asm/amd-ibs.h | 132 ++++++++++++
>   tools/perf/check-headers.sh          |   1 +
>   tools/perf/util/Build                |   1 +
>   tools/perf/util/amd-sample-raw.c     | 290 +++++++++++++++++++++++++++
>   tools/perf/util/env.c                |  78 +++++++
>   tools/perf/util/env.h                |   5 +
>   tools/perf/util/sample-raw.c         |   8 +
>   tools/perf/util/sample-raw.h         |   6 +-
>   8 files changed, 520 insertions(+), 1 deletion(-)
>   create mode 100644 tools/arch/x86/include/asm/amd-ibs.h
>   create mode 100644 tools/perf/util/amd-sample-raw.c
> 
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> Cc: Ian Rogers <irogers@google.com>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Jiri Olsa <jolsa@redhat.com>
> Cc: Joao Martins <joao.m.martins@oracle.com>
> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Cc: Michael Petlan <mpetlan@redhat.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Robert Richter <robert.richter@amd.com>
> Cc: Stephane Eranian <eranian@google.com>
> Cc: linux-kernel@vger.kernel.org
> Cc: linux-perf-users@vger.kernel.org
> 

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/3] perf report: Add support to print a textual representation of IBS raw sample data
  2021-09-09 21:58 ` [PATCH 0/3] " Kim Phillips
@ 2021-09-10 13:47   ` Arnaldo Carvalho de Melo
  2021-09-10 14:08     ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-09-10 13:47 UTC (permalink / raw)
  To: Kim Phillips
  Cc: Arnaldo Carvalho de Melo, Alexander Shishkin, Boris Ostrovsky,
	Ian Rogers, Ingo Molnar, Jiri Olsa, Joao Martins,
	Konrad Rzeszutek Wilk, Mark Rutland, Michael Petlan,
	Namhyung Kim, Peter Zijlstra, Robert Richter, Stephane Eranian,
	linux-kernel, linux-perf-users

Em Thu, Sep 09, 2021 at 04:58:12PM -0500, Kim Phillips escreveu:
> Hi Arnaldo,
> 
> Can you please take a look at applying this series?  Its kernel-side
> dependent series has already been applied and is in Linus' master.

Sure, I'm now trying to fix this:

  CC      /tmp/build/perf/util/amd-sample-raw.o
util/amd-sample-raw.c: In function ‘evlist__amd_sample_raw’:
util/amd-sample-raw.c:125:42: error: ‘ bytes’ directive output may be truncated writing 6 bytes into a region of size between 4 and 7 [-Werror=format-truncation=]
  125 |                          " OpMemWidth %2d bytes", 1 << (reg.op_mem_width - 1));
      |                                          ^~~~~~
In file included from /usr/include/stdio.h:866,
                 from util/amd-sample-raw.c:7:
/usr/include/bits/stdio2.h:71:10: note: ‘__builtin___snprintf_chk’ output between 21 and 24 bytes into a destination of size 21
   71 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   72 |                                    __glibc_objsize (__s), __fmt,
      |                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   73 |                                    __va_arg_pack ());
      |                                    ~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[4]: *** [/var/home/acme/git/perf/tools/build/Makefile.build:96: /tmp/build/perf/util/amd-sample-raw.o] Error 1
 
> Thanks,
> 
> Kim
> 
> On 8/17/21 5:15 PM, Kim Phillips wrote:
> > Hello Linux perf tools users and maintainers,
> > 
> > The first patch in this series prepares the perf tool to support
> > retrieving cpuid and pmu_mappings data when in report mode,
> > information that is needed to accurately decode IBS data.
> > 
> > The second patch adds a header file tools/arch/x86/include/asm/amd-ibs.h
> > from a separate kernel-side submittion [1].
> > 
> > The third patch allows the tool to print a textual representation
> > of the sample data recorded by IBS.
> > 
> > [1] https://lore.kernel.org/lkml/20210817221048.88063-9-kim.phillips@amd.com
> > 
> > Kim Phillips (3):
> >    perf env: Add perf_env__cpuid, perf_env__{nr_}pmu_mappings
> >    perf report: Add tools/arch/x86/include/asm/amd-ibs.h
> >    perf report: Add support to print a textual representation of IBS raw
> >      sample data
> > 
> >   tools/arch/x86/include/asm/amd-ibs.h | 132 ++++++++++++
> >   tools/perf/check-headers.sh          |   1 +
> >   tools/perf/util/Build                |   1 +
> >   tools/perf/util/amd-sample-raw.c     | 290 +++++++++++++++++++++++++++
> >   tools/perf/util/env.c                |  78 +++++++
> >   tools/perf/util/env.h                |   5 +
> >   tools/perf/util/sample-raw.c         |   8 +
> >   tools/perf/util/sample-raw.h         |   6 +-
> >   8 files changed, 520 insertions(+), 1 deletion(-)
> >   create mode 100644 tools/arch/x86/include/asm/amd-ibs.h
> >   create mode 100644 tools/perf/util/amd-sample-raw.c
> > 
> > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> > Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
> > Cc: Ian Rogers <irogers@google.com>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: Jiri Olsa <jolsa@redhat.com>
> > Cc: Joao Martins <joao.m.martins@oracle.com>
> > Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
> > Cc: Mark Rutland <mark.rutland@arm.com>
> > Cc: Michael Petlan <mpetlan@redhat.com>
> > Cc: Namhyung Kim <namhyung@kernel.org>
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Cc: Robert Richter <robert.richter@amd.com>
> > Cc: Stephane Eranian <eranian@google.com>
> > Cc: linux-kernel@vger.kernel.org
> > Cc: linux-perf-users@vger.kernel.org
> > 

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/3] perf report: Add support to print a textual representation of IBS raw sample data
  2021-09-10 13:47   ` Arnaldo Carvalho de Melo
@ 2021-09-10 14:08     ` Arnaldo Carvalho de Melo
  2021-09-10 14:11       ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-09-10 14:08 UTC (permalink / raw)
  To: Kim Phillips
  Cc: Arnaldo Carvalho de Melo, Alexander Shishkin, Boris Ostrovsky,
	Ian Rogers, Ingo Molnar, Jiri Olsa, Joao Martins,
	Konrad Rzeszutek Wilk, Mark Rutland, Michael Petlan,
	Namhyung Kim, Peter Zijlstra, Robert Richter, Stephane Eranian,
	linux-kernel, linux-perf-users

Em Fri, Sep 10, 2021 at 10:47:16AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Thu, Sep 09, 2021 at 04:58:12PM -0500, Kim Phillips escreveu:
> > Hi Arnaldo,
> > 
> > Can you please take a look at applying this series?  Its kernel-side
> > dependent series has already been applied and is in Linus' master.
> 
> Sure, I'm now trying to fix this:
> 
>   CC      /tmp/build/perf/util/amd-sample-raw.o
> util/amd-sample-raw.c: In function ‘evlist__amd_sample_raw’:
> util/amd-sample-raw.c:125:42: error: ‘ bytes’ directive output may be truncated writing 6 bytes into a region of size between 4 and 7 [-Werror=format-truncation=]
>   125 |                          " OpMemWidth %2d bytes", 1 << (reg.op_mem_width - 1));
>       |                                          ^~~~~~
> In file included from /usr/include/stdio.h:866,
>                  from util/amd-sample-raw.c:7:
> /usr/include/bits/stdio2.h:71:10: note: ‘__builtin___snprintf_chk’ output between 21 and 24 bytes into a destination of size 21
>    71 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
>       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    72 |                                    __glibc_objsize (__s), __fmt,
>       |                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>    73 |                                    __va_arg_pack ());
>       |                                    ~~~~~~~~~~~~~~~~~
> cc1: all warnings being treated as errors
> make[4]: *** [/var/home/acme/git/perf/tools/build/Makefile.build:96: /tmp/build/perf/util/amd-sample-raw.o] Error 1

So, that trick with using sizeof and that string 3 times is cumbersome
and prone to truncation, at least the compiler can't say that the number
you're passing to %2d will have just 2 digits:

[acme@quaco c]$ cat printf.c
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
	char bf[64];
	int len = snprintf(bf, sizeof(bf), "%2d", atoi(argv[1]));

	printf("strlen(%s): %u\n", bf, len);

	return 0;
}
[acme@quaco c]$ ./printf 1234567
strlen(1234567): 7
[acme@quaco c]$

I'm trying to rework this.

- Arnaldo

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/3] perf report: Add support to print a textual representation of IBS raw sample data
  2021-09-10 14:08     ` Arnaldo Carvalho de Melo
@ 2021-09-10 14:11       ` Arnaldo Carvalho de Melo
  2021-09-10 14:17         ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-09-10 14:11 UTC (permalink / raw)
  To: Kim Phillips
  Cc: Arnaldo Carvalho de Melo, Alexander Shishkin, Boris Ostrovsky,
	Ian Rogers, Ingo Molnar, Jiri Olsa, Joao Martins,
	Konrad Rzeszutek Wilk, Mark Rutland, Michael Petlan,
	Namhyung Kim, Peter Zijlstra, Robert Richter, Stephane Eranian,
	linux-kernel, linux-perf-users

Em Fri, Sep 10, 2021 at 11:08:02AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Sep 10, 2021 at 10:47:16AM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Thu, Sep 09, 2021 at 04:58:12PM -0500, Kim Phillips escreveu:
> > > Hi Arnaldo,
> > > 
> > > Can you please take a look at applying this series?  Its kernel-side
> > > dependent series has already been applied and is in Linus' master.
> > 
> > Sure, I'm now trying to fix this:
> > 
> >   CC      /tmp/build/perf/util/amd-sample-raw.o
> > util/amd-sample-raw.c: In function ‘evlist__amd_sample_raw’:
> > util/amd-sample-raw.c:125:42: error: ‘ bytes’ directive output may be truncated writing 6 bytes into a region of size between 4 and 7 [-Werror=format-truncation=]
> >   125 |                          " OpMemWidth %2d bytes", 1 << (reg.op_mem_width - 1));
> >       |                                          ^~~~~~
> > In file included from /usr/include/stdio.h:866,
> >                  from util/amd-sample-raw.c:7:
> > /usr/include/bits/stdio2.h:71:10: note: ‘__builtin___snprintf_chk’ output between 21 and 24 bytes into a destination of size 21
> >    71 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
> >       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >    72 |                                    __glibc_objsize (__s), __fmt,
> >       |                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >    73 |                                    __va_arg_pack ());
> >       |                                    ~~~~~~~~~~~~~~~~~
> > cc1: all warnings being treated as errors
> > make[4]: *** [/var/home/acme/git/perf/tools/build/Makefile.build:96: /tmp/build/perf/util/amd-sample-raw.o] Error 1
> 
> So, that trick with using sizeof and that string 3 times is cumbersome
> and prone to truncation, at least the compiler can't say that the number
> you're passing to %2d will have just 2 digits:
> 
> [acme@quaco c]$ cat printf.c
> #include <stdio.h>
> #include <stdlib.h>
> 
> int main(int argc, char *argv[])
> {
> 	char bf[64];
> 	int len = snprintf(bf, sizeof(bf), "%2d", atoi(argv[1]));
> 
> 	printf("strlen(%s): %u\n", bf, len);
> 
> 	return 0;
> }
> [acme@quaco c]$ ./printf 1234567
> strlen(1234567): 7
> [acme@quaco c]$
> 
> I'm trying to rework this.

So below is the minimal fix, the other cases the compiler somehow thinks
its ok, so I'll keep as is, will just remove the sizeof(string) to
sizeof(var), as I did below for the offending case.

- Arnaldo

diff --git a/tools/perf/util/amd-sample-raw.c b/tools/perf/util/amd-sample-raw.c
index fc1f670e88562b2e..e24025022735acdc 100644
--- a/tools/perf/util/amd-sample-raw.c
+++ b/tools/perf/util/amd-sample-raw.c
@@ -106,7 +106,7 @@ static void pr_ibs_op_data2(union ibs_op_data2 reg)
 static void pr_ibs_op_data3(union ibs_op_data3 reg)
 {
 	char l2_miss_str[sizeof(" L2Miss _")] = "";
-	char op_mem_width_str[sizeof(" OpMemWidth __ bytes")] = "";
+	char op_mem_width_str[sizeof(" OpMemWidth _____ bytes")] = "";
 	char op_dc_miss_open_mem_reqs_str[sizeof(" OpDcMissOpenMemReqs __")] = "";
 
 	/*
@@ -121,7 +121,7 @@ static void pr_ibs_op_data3(union ibs_op_data3 reg)
 	}
 
 	if (reg.op_mem_width)
-		snprintf(op_mem_width_str, sizeof(" OpMemWidth __ bytes"),
+		snprintf(op_mem_width_str, sizeof(op_mem_width_str),
 			 " OpMemWidth %2d bytes", 1 << (reg.op_mem_width - 1));
 
 	printf("ibs_op_data3:\t%016llx LdOp %d StOp %d DcL1TlbMiss %d DcL2TlbMiss %d "

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/3] perf report: Add support to print a textual representation of IBS raw sample data
  2021-09-10 14:11       ` Arnaldo Carvalho de Melo
@ 2021-09-10 14:17         ` Arnaldo Carvalho de Melo
  2021-09-10 19:48           ` Another bug: " Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-09-10 14:17 UTC (permalink / raw)
  To: Kim Phillips
  Cc: Arnaldo Carvalho de Melo, Alexander Shishkin, Boris Ostrovsky,
	Ian Rogers, Ingo Molnar, Jiri Olsa, Joao Martins,
	Konrad Rzeszutek Wilk, Mark Rutland, Michael Petlan,
	Namhyung Kim, Peter Zijlstra, Robert Richter, Stephane Eranian,
	linux-kernel, linux-perf-users

Em Fri, Sep 10, 2021 at 11:11:48AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Sep 10, 2021 at 11:08:02AM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Fri, Sep 10, 2021 at 10:47:16AM -0300, Arnaldo Carvalho de Melo escreveu:
> > > Em Thu, Sep 09, 2021 at 04:58:12PM -0500, Kim Phillips escreveu:
> > > > Hi Arnaldo,
> > > > 
> > > > Can you please take a look at applying this series?  Its kernel-side
> > > > dependent series has already been applied and is in Linus' master.
> > > 
> > > Sure, I'm now trying to fix this:
> > > 
> > >   CC      /tmp/build/perf/util/amd-sample-raw.o
> > > util/amd-sample-raw.c: In function ‘evlist__amd_sample_raw’:
> > > util/amd-sample-raw.c:125:42: error: ‘ bytes’ directive output may be truncated writing 6 bytes into a region of size between 4 and 7 [-Werror=format-truncation=]
> > >   125 |                          " OpMemWidth %2d bytes", 1 << (reg.op_mem_width - 1));
> > >       |                                          ^~~~~~
> > > In file included from /usr/include/stdio.h:866,
> > >                  from util/amd-sample-raw.c:7:
> > > /usr/include/bits/stdio2.h:71:10: note: ‘__builtin___snprintf_chk’ output between 21 and 24 bytes into a destination of size 21
> > >    71 |   return __builtin___snprintf_chk (__s, __n, __USE_FORTIFY_LEVEL - 1,
> > >       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > >    72 |                                    __glibc_objsize (__s), __fmt,
> > >       |                                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > >    73 |                                    __va_arg_pack ());
> > >       |                                    ~~~~~~~~~~~~~~~~~
> > > cc1: all warnings being treated as errors
> > > make[4]: *** [/var/home/acme/git/perf/tools/build/Makefile.build:96: /tmp/build/perf/util/amd-sample-raw.o] Error 1
> > 
> > So, that trick with using sizeof and that string 3 times is cumbersome
> > and prone to truncation, at least the compiler can't say that the number
> > you're passing to %2d will have just 2 digits:
> > 
> > [acme@quaco c]$ cat printf.c
> > #include <stdio.h>
> > #include <stdlib.h>
> > 
> > int main(int argc, char *argv[])
> > {
> > 	char bf[64];
> > 	int len = snprintf(bf, sizeof(bf), "%2d", atoi(argv[1]));
> > 
> > 	printf("strlen(%s): %u\n", bf, len);
> > 
> > 	return 0;
> > }
> > [acme@quaco c]$ ./printf 1234567
> > strlen(1234567): 7
> > [acme@quaco c]$
> > 
> > I'm trying to rework this.
> 
> So below is the minimal fix, the other cases the compiler somehow thinks
> its ok, so I'll keep as is, will just remove the sizeof(string) to
> sizeof(var), as I did below for the offending case.

End result:

diff --git a/tools/perf/util/amd-sample-raw.c b/tools/perf/util/amd-sample-raw.c
index fc1f670e88562b2e..fbb7d61c50489374 100644
--- a/tools/perf/util/amd-sample-raw.c
+++ b/tools/perf/util/amd-sample-raw.c
@@ -106,7 +106,7 @@ static void pr_ibs_op_data2(union ibs_op_data2 reg)
 static void pr_ibs_op_data3(union ibs_op_data3 reg)
 {
 	char l2_miss_str[sizeof(" L2Miss _")] = "";
-	char op_mem_width_str[sizeof(" OpMemWidth __ bytes")] = "";
+	char op_mem_width_str[sizeof(" OpMemWidth _____ bytes")] = "";
 	char op_dc_miss_open_mem_reqs_str[sizeof(" OpDcMissOpenMemReqs __")] = "";
 
 	/*
@@ -114,14 +114,13 @@ static void pr_ibs_op_data3(union ibs_op_data3 reg)
 	 * Ignore L2Miss and OpDcMissOpenMemReqs (and opdata2) if DcMissNoMabAlloc or SwPf set
 	 */
 	if (!(cpu_family == 0x19 && cpu_model < 0x10 && (reg.dc_miss_no_mab_alloc || reg.sw_pf))) {
-		snprintf(l2_miss_str, sizeof(" L2Miss _"),
-			 " L2Miss %d", reg.l2_miss);
-		snprintf(op_dc_miss_open_mem_reqs_str, sizeof(" OpDcMissOpenMemReqs __"),
+		snprintf(l2_miss_str, sizeof(l2_miss_str), " L2Miss %d", reg.l2_miss);
+		snprintf(op_dc_miss_open_mem_reqs_str, sizeof(op_dc_miss_open_mem_reqs_str),
 			 " OpDcMissOpenMemReqs %2d", reg.op_dc_miss_open_mem_reqs);
 	}
 
 	if (reg.op_mem_width)
-		snprintf(op_mem_width_str, sizeof(" OpMemWidth __ bytes"),
+		snprintf(op_mem_width_str, sizeof(op_mem_width_str),
 			 " OpMemWidth %2d bytes", 1 << (reg.op_mem_width - 1));
 
 	printf("ibs_op_data3:\t%016llx LdOp %d StOp %d DcL1TlbMiss %d DcL2TlbMiss %d "

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Another bug: Re: [PATCH 0/3] perf report: Add support to print a textual representation of IBS raw sample data
  2021-09-10 14:17         ` Arnaldo Carvalho de Melo
@ 2021-09-10 19:48           ` Arnaldo Carvalho de Melo
  2021-09-10 20:58             ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-09-10 19:48 UTC (permalink / raw)
  To: Kim Phillips
  Cc: Arnaldo Carvalho de Melo, Alexander Shishkin, Boris Ostrovsky,
	Ian Rogers, Ingo Molnar, Jiri Olsa, Joao Martins,
	Konrad Rzeszutek Wilk, Mark Rutland, Michael Petlan,
	Namhyung Kim, Peter Zijlstra, Robert Richter, Stephane Eranian,
	linux-kernel, linux-perf-users


All the cross builds are failing:

  28     9.20 debian:experimental-x-arm64   : FAIL gcc version 10.2.1 20210110 (Debian 10.2.1-6)
    util/amd-sample-raw.c:12:10: fatal error: asm/amd-ibs.h: No such file or directory
       12 | #include <asm/amd-ibs.h>
          |          ^~~~~~~~~~~~~~~
    compilation terminated.
  29     7.29 debian:experimental-x-mips    : FAIL gcc version 10.2.1 20210110 (Debian 10.2.1-6)
    util/amd-sample-raw.c:12:10: fatal error: asm/amd-ibs.h: No such file or directory
       12 | #include <asm/amd-ibs.h>
          |          ^~~~~~~~~~~~~~~
    compilation terminated.
  30     8.50 debian:experimental-x-mips64  : FAIL gcc version 10.2.1 20210110 (Debian 10.2.1-6)
    util/amd-sample-raw.c:12:10: fatal error: asm/amd-ibs.h: No such file or directory
       12 | #include <asm/amd-ibs.h>
          |          ^~~~~~~~~~~~~~~
    compilation terminated.
  31     8.50 debian:experimental-x-mipsel  : FAIL gcc version 10.2.1 20210110 (Debian 10.2.1-6)
    util/amd-sample-raw.c:12:10: fatal error: asm/amd-ibs.h: No such file or directory
       12 | #include <asm/amd-ibs.h>
          |          ^~~~~~~~~~~~~~~
    compilation terminated.
  32    26.37 fedora:22                     : Ok   gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6) , clang version 3.5.0 (tags/RELEASE_350/final)
  33    66.13 fedora:23                     : Ok   gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6) , clang version 3.7.0 (tags/RELEASE_370/final)
  34    79.47 fedora:24                     : Ok   gcc (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1) , clang version 3.8.1 (tags/RELEASE_381/final)
  35     6.89 fedora:24-x-ARC-uClibc        : FAIL gcc version 7.1.1 20170710 (ARCompact ISA Linux uClibc toolchain 2017.09-rc2)
    util/amd-sample-raw.c:12:10: fatal error: asm/amd-ibs.h: No such file or directory
     #include <asm/amd-ibs.h>
              ^~~~~~~~~~~~~~~


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Another bug: Re: [PATCH 0/3] perf report: Add support to print a textual representation of IBS raw sample data
  2021-09-10 19:48           ` Another bug: " Arnaldo Carvalho de Melo
@ 2021-09-10 20:58             ` Arnaldo Carvalho de Melo
  2021-09-10 21:40               ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-09-10 20:58 UTC (permalink / raw)
  To: Kim Phillips
  Cc: Arnaldo Carvalho de Melo, Alexander Shishkin, Boris Ostrovsky,
	Ian Rogers, Ingo Molnar, Jiri Olsa, Joao Martins,
	Konrad Rzeszutek Wilk, Mark Rutland, Michael Petlan,
	Namhyung Kim, Peter Zijlstra, Robert Richter, Stephane Eranian,
	linux-kernel, linux-perf-users

Em Fri, Sep 10, 2021 at 04:48:42PM -0300, Arnaldo Carvalho de Melo escreveu:
> 
> All the cross builds are failing:
> 
>   28     9.20 debian:experimental-x-arm64   : FAIL gcc version 10.2.1 20210110 (Debian 10.2.1-6)
>     util/amd-sample-raw.c:12:10: fatal error: asm/amd-ibs.h: No such file or directory
>        12 | #include <asm/amd-ibs.h>
>           |          ^~~~~~~~~~~~~~~
>     compilation terminated.

Trying with the same trick used by intel-pt to build on all arches:

diff --git a/tools/perf/util/amd-sample-raw.c b/tools/perf/util/amd-sample-raw.c
index fbb7d61c50489374..d19d765195c54b79 100644
--- a/tools/perf/util/amd-sample-raw.c
+++ b/tools/perf/util/amd-sample-raw.c
@@ -9,7 +9,7 @@
 #include <inttypes.h>
 
 #include <linux/string.h>
-#include <asm/amd-ibs.h>
+#include "../../arch/x86/include/asm/amd-ibs.h"
 
 #include "debug.h"
 #include "session.h"

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: Another bug: Re: [PATCH 0/3] perf report: Add support to print a textual representation of IBS raw sample data
  2021-09-10 20:58             ` Arnaldo Carvalho de Melo
@ 2021-09-10 21:40               ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 12+ messages in thread
From: Arnaldo Carvalho de Melo @ 2021-09-10 21:40 UTC (permalink / raw)
  To: Kim Phillips
  Cc: Arnaldo Carvalho de Melo, Alexander Shishkin, Boris Ostrovsky,
	Ian Rogers, Ingo Molnar, Jiri Olsa, Joao Martins,
	Konrad Rzeszutek Wilk, Mark Rutland, Michael Petlan,
	Namhyung Kim, Peter Zijlstra, Robert Richter, Stephane Eranian,
	linux-kernel, linux-perf-users

Em Fri, Sep 10, 2021 at 05:58:14PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Sep 10, 2021 at 04:48:42PM -0300, Arnaldo Carvalho de Melo escreveu:
> > 
> > All the cross builds are failing:
> > 
> >   28     9.20 debian:experimental-x-arm64   : FAIL gcc version 10.2.1 20210110 (Debian 10.2.1-6)
> >     util/amd-sample-raw.c:12:10: fatal error: asm/amd-ibs.h: No such file or directory
> >        12 | #include <asm/amd-ibs.h>
> >           |          ^~~~~~~~~~~~~~~
> >     compilation terminated.
> 
> Trying with the same trick used by intel-pt to build on all arches:
> 
> diff --git a/tools/perf/util/amd-sample-raw.c b/tools/perf/util/amd-sample-raw.c
> index fbb7d61c50489374..d19d765195c54b79 100644
> --- a/tools/perf/util/amd-sample-raw.c
> +++ b/tools/perf/util/amd-sample-raw.c
> @@ -9,7 +9,7 @@
>  #include <inttypes.h>
>  
>  #include <linux/string.h>
> -#include <asm/amd-ibs.h>
> +#include "../../arch/x86/include/asm/amd-ibs.h"
>  
>  #include "debug.h"
>  #include "session.h"

Not enough, this one is needed for msr-index.h, same reason, a bit more
involved, but check-patch.h has a few entries like that, see below.

Now it seems to be ok:

# export BUILD_TARBALL=http://192.168.100.2/perf/perf-5.14.0.tar.xz
# dm  android-ndk:r12b-arm android-ndk:r15c-arm debian:experimental-x-arm64 debian:experimental-x-mips debian:experimental-x-mips64 debian:experimental-x-mipsel fedora:24-x-ARC-uClibc fedora:34-x-ARC-glibc fedora:34-x-ARC-uClibc mageia:7 openmandriva:cooker ubuntu:16.04-x-arm ubuntu:16.04-x-arm64 ubuntu:16.04-x-powerpc ubuntu:16.04-x-powerpc64 ubuntu:16.04-x-powerpc64el ubuntu:16.04-x-s390 ubuntu:18.04-x-arm ubuntu:18.04-x-arm64 ubuntu:18.04-x-m68k ubuntu:18.04-x-powerpc ubuntu:18.04-x-powerpc64 ubuntu:18.04-x-powerpc64el ubuntu:18.04-x-riscv64 ubuntu:18.04-x-s390 ubuntu:18.04-x-sh4 ubuntu:18.04-x-sparc64 ubuntu:20.04-x-powerpc64el ubuntu:20.04-x-s390 ubuntu:21.04-x-mips ubuntu:21.04-x-mips64
   1    29.83 android-ndk:r12b-arm          : Ok   arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease)
   2    40.15 android-ndk:r15c-arm          : Ok   arm-linux-androideabi-gcc (GCC) 4.9.x 20150123 (prerelease)
   3    49.76 debian:experimental-x-arm64   : Ok   aarch64-linux-gnu-gcc (Debian 10.2.1-6) 10.2.1 20210110
   4    38.37 debian:experimental-x-mips    : Ok   mips-linux-gnu-gcc (Debian 10.2.1-6) 10.2.1 20210110
   5    45.28 debian:experimental-x-mips64  : Ok   mips64-linux-gnuabi64-gcc (Debian 10.2.1-6) 10.2.1 20210110
   6    45.15 debian:experimental-x-mipsel  : Ok   mipsel-linux-gnu-gcc (Debian 10.2.1-6) 10.2.1 20210110
   7: fedora:24-x-ARC-uClibc

Some more to go, but should be ok by now.

- Arnaldo

diff --git a/tools/arch/x86/include/asm/amd-ibs.h b/tools/arch/x86/include/asm/amd-ibs.h
index 46e1df45efc04627..174e7d83fcbdb22f 100644
--- a/tools/arch/x86/include/asm/amd-ibs.h
+++ b/tools/arch/x86/include/asm/amd-ibs.h
@@ -4,7 +4,7 @@
  * 55898 Rev 0.35 - Feb 5, 2021
  */
 
-#include <asm/msr-index.h>
+#include "msr-index.h"
 
 /*
  * IBS Hardware MSRs
diff --git a/tools/perf/check-headers.sh b/tools/perf/check-headers.sh
index 4a6b2b4ec5074a49..f1e46277e8226b5a 100755
--- a/tools/perf/check-headers.sh
+++ b/tools/perf/check-headers.sh
@@ -34,7 +34,6 @@ arch/x86/include/asm/inat_types.h
 arch/x86/include/asm/emulate_prefix.h
 arch/x86/include/asm/irq_vectors.h
 arch/x86/include/asm/msr-index.h
-arch/x86/include/asm/amd-ibs.h
 arch/x86/include/uapi/asm/prctl.h
 arch/x86/lib/x86-opcode-map.txt
 arch/x86/tools/gen-insn-attr-x86.awk
@@ -145,6 +144,7 @@ done
 # diff with extra ignore lines
 check arch/x86/lib/memcpy_64.S        '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>" -I"^SYM_FUNC_START\(_LOCAL\)*(memcpy_\(erms\|orig\))"'
 check arch/x86/lib/memset_64.S        '-I "^EXPORT_SYMBOL" -I "^#include <asm/export.h>" -I"^SYM_FUNC_START\(_LOCAL\)*(memset_\(erms\|orig\))"'
+check arch/x86/include/asm/amd-ibs.h  '-I "^#include [<\"]\(asm/\)*msr-index.h"'
 check include/uapi/asm-generic/mman.h '-I "^#include <\(uapi/\)*asm-generic/mman-common\(-tools\)*.h>"'
 check include/uapi/linux/mman.h       '-I "^#include <\(uapi/\)*asm/mman.h>"'
 check include/linux/build_bug.h       '-I "^#\(ifndef\|endif\)\( \/\/\)* static_assert$"'

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2021-09-10 21:40 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-17 22:15 [PATCH 0/3] perf report: Add support to print a textual representation of IBS raw sample data Kim Phillips
2021-08-17 22:15 ` [PATCH 1/3] perf env: Add perf_env__cpuid, perf_env__{nr_}pmu_mappings Kim Phillips
2021-08-17 22:15 ` [PATCH 2/3] perf report: Add tools/arch/x86/include/asm/amd-ibs.h Kim Phillips
2021-08-17 22:15 ` [PATCH 3/3] perf report: Add support to print a textual representation of IBS raw sample data Kim Phillips
2021-09-09 21:58 ` [PATCH 0/3] " Kim Phillips
2021-09-10 13:47   ` Arnaldo Carvalho de Melo
2021-09-10 14:08     ` Arnaldo Carvalho de Melo
2021-09-10 14:11       ` Arnaldo Carvalho de Melo
2021-09-10 14:17         ` Arnaldo Carvalho de Melo
2021-09-10 19:48           ` Another bug: " Arnaldo Carvalho de Melo
2021-09-10 20:58             ` Arnaldo Carvalho de Melo
2021-09-10 21:40               ` Arnaldo Carvalho de Melo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.