perf report: Add support to print a textual representation of IBS raw sample data
cover perf report: Add support to print a textual representation of IBS raw sample data
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/[email protected]
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
Signature · 1 line
2.31.1
PATCH 1/3 perf env: Add perf_env__cpuid, perf_env__{nr_}pmu_mappings
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.
--- tools/perf/util/env.c | 78 +++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/env.h | 5 +++ 2 files changed, 83 insertions(+)
tools/perf/util/env.c +78 -0
@@ -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) {
tools/perf/util/env.h +5 -0
@@ -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);
Signature · 1 line
2.31.1
PATCH 2/3 perf report: Add tools/arch/x86/include/asm/amd-ibs.h
In reply to Kim PhillipsThis 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.
--- 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
tools/arch/x86/include/asm/amd-ibs.h new file +132 -0
@@ -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 ]; +};
tools/perf/check-headers.sh +1 -0
@@ -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
Signature · 1 line
2.31.1
PATCH 3/3 perf report: Add support to print a textual representation of IBS raw sample data
In reply to Kim PhillipsPerf 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: 000000115cedfd40ic_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: 000056016b2ea73dibs_op_data: 00000000000b0002 CompToRetCtr 2 TagToRetCtr 11 BrnRet 0 RipInvalid 0 BrnFuse 0 Microcode 0ibs_op_data2: 0000000000000002 CacheHitSt 0=M-state RmtNode 0 DataSrc 2=Local node cacheibs_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
--- 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
tools/perf/util/Build +1 -0
@@ -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
tools/perf/util/amd-sample-raw.c new file +290 -0
290 lines not on this page · raw message
tools/perf/util/sample-raw.c +8 -0
@@ -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; + } }
tools/perf/util/sample-raw.h +5 -1
@@ -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 */
Signature · 1 line
2.31.1
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
Quoted 49 lines · Kim Phillips
Hello Linux perf tools users and maintainers,
The first patch in this series prepares the perf tool to support retrieving cpuid and
pmu_mappingsdata 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.hfrom 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/[email protected]
Kim Phillips (3):
perf env: Addperf_env__cpuid, perf_env__{nr_}pmu_mappings perf report: Addtools/arch/x86/include/asm/amd-ibs.hperf report: Add support to print a textual representation of IBS raw
sample datatools/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.hcreate mode 100644tools/perf/util/amd-sample-raw.cCc Alexander Shishkin <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Cc Boris Ostrovsky <[email protected]>Cc Ian Rogers <[email protected]>Cc Ingo Molnar <[email protected]>Cc Jiri Olsa <[email protected]>Cc Joao Martins <[email protected]>Cc Konrad Rzeszutek Wilk <[email protected]>Cc Mark Rutland <[email protected]>Cc Michael Petlan <[email protected]>Cc Namhyung Kim <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Robert Richter <[email protected]>Cc Stephane Eranian <[email protected]>
Arnaldo Carvalho de Melo
maintainerEm Thu, Sep 09, 2021 at 04:58:12PM -0500, Kim Phillips escreveu:
Quoted 4 lines
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.outil/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
Quoted 54 lines
Thanks,
Kim
Quoted 49 lines · Kim Phillips
Hello Linux perf tools users and maintainers,
The first patch in this series prepares the perf tool to support retrieving cpuid and
pmu_mappingsdata 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.hfrom 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/[email protected]
Kim Phillips (3):
perf env: Addperf_env__cpuid, perf_env__{nr_}pmu_mappings perf report: Addtools/arch/x86/include/asm/amd-ibs.hperf report: Add support to print a textual representation of IBS raw
sample datatools/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.hcreate mode 100644tools/perf/util/amd-sample-raw.cCc Alexander Shishkin <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Cc Boris Ostrovsky <[email protected]>Cc Ian Rogers <[email protected]>Cc Ingo Molnar <[email protected]>Cc Jiri Olsa <[email protected]>Cc Joao Martins <[email protected]>Cc Konrad Rzeszutek Wilk <[email protected]>Cc Mark Rutland <[email protected]>Cc Michael Petlan <[email protected]>Cc Namhyung Kim <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Robert Richter <[email protected]>Cc Stephane Eranian <[email protected]>
Signature · 1 line
- Arnaldo
Arnaldo Carvalho de Melo
maintainerEm Fri, Sep 10, 2021 at 10:47:16AM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 16 lines
Em Thu, Sep 09, 2021 at 04:58:12PM -0500, Kim Phillips escreveu:
Quoted 4 lines
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.outil/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,
fromutil/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
Quoted 8 lines
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
Arnaldo Carvalho de Melo
maintainerEm Fri, Sep 10, 2021 at 11:08:02AM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 43 lines
Em Fri, Sep 10, 2021 at 10:47:16AM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 16 lines
Em Thu, Sep 09, 2021 at 04:58:12PM -0500, Kim Phillips escreveu:
Quoted 4 lines
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.outil/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,
fromutil/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 21Quoted 8 lines
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 1So, 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; }
Quoted 5 lines
[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
tools/perf/util/amd-sample-raw.c +2 -2
@@ -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 "
Arnaldo Carvalho de Melo
maintainerEm Fri, Sep 10, 2021 at 11:11:48AM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 48 lines
Em Fri, Sep 10, 2021 at 11:08:02AM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 47 lines
Em Fri, Sep 10, 2021 at 10:47:16AM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 16 lines
Em Thu, Sep 09, 2021 at 04:58:12PM -0500, Kim Phillips escreveu:
Quoted 4 lines
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.outil/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,
fromutil/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 21Quoted 8 lines
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 1So, 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]$
Quoted 5 lines
Quoted 1 line
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:
tools/perf/util/amd-sample-raw.c +4 -5
@@ -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 "
Arnaldo Carvalho de Melo
maintainerAnother bug: Re: [PATCH 0/3] perf report: Add support to print a textual representation of IBS raw sample data
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>
^~~~~~~~~~~~~~~Arnaldo Carvalho de Melo
maintainerRe: Another bug: Re: [PATCH 0/3] perf report: Add support to print a textual representation of IBS raw sample data
Em Fri, Sep 10, 2021 at 04:48:42PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 8 lines
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:
tools/perf/util/amd-sample-raw.c +1 -1
@@ -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"
Arnaldo Carvalho de Melo
maintainerRe: Another bug: Re: [PATCH 0/3] perf report: Add support to print a textual representation of IBS raw sample data
Em Fri, Sep 10, 2021 at 05:58:14PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 17 lines
Em Fri, Sep 10, 2021 at 04:48:42PM -0300, Arnaldo Carvalho de Melo escreveu:
Quoted 8 lines
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:
tools/perf/util/amd-sample-raw.c +0
-0
tools/perf/util/amd-sample-raw.c line 15
Quoted 8 lines
tools/perf/util/amd-sample-raw.c +1
-1@@ -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
tools/arch/x86/include/asm/amd-ibs.h +1 -1
@@ -4,7 +4,7 @@* 55898 Rev 0.35 - Feb 5, 2021 */ -#include <asm/msr-index.h> +#include "msr-index.h" /* * IBS Hardware MSRs
tools/perf/check-headers.sh +1 -1
@@ -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$"'