[PATCH 13/14] tools/perf: Enable perf script to present the DTL entries
Adrian Hunter
adrian.hunter at intel.com
Thu Aug 28 03:30:38 AEST 2025
On 15/08/2025 11:34, Athira Rajeev wrote:
> Enable perf script to present the DTL entries. Process the
> dispatch trace log details in arch_perf_sample__fprintf_synth_evt()
> defined in buiultin-script.c file for config value:
> PERF_SYNTH_POWERPC_VPA_DTL.
>
> Sample output:
>
> ./perf record -a -e sched:*,vpa_dtl/dtl_all/ -c 1000000000 sleep 1
> [ perf record: Woken up 1 times to write data ]
> [ perf record: Captured and wrote 0.300 MB perf.data ]
>
> ./perf script
> perf 13322 [002] 233.835807: sched:sched_switch: perf:13322 [120] R ==> migration/2:27 [0]
> migration/2 27 [002] 233.835811: sched:sched_migrate_task: comm=perf pid=13322 prio=120 orig_cpu=2 dest_cpu=3
> migration/2 27 [002] 233.835818: sched:sched_stat_runtime: comm=migration/2 pid=27 runtime=9214 [ns]
> migration/2 27 [002] 233.835819: sched:sched_switch: migration/2:27 [0] S ==> swapper/2:0 [120]
> swapper 0 [002] 233.835822: vpa-dtl: timebase: 338954486062657 dispatch_reason:decrementer_interrupt, preempt_reason:H_CEDE, enqueue_to_dispatch_time:435, ready_to_enqueue_time:0, waiting_to_ready_time:34775058, processor_id: 202 c0000000000f8094 plpar_hcall_norets_notrace+0x18 ([kernel.kallsyms])
> swapper 0 [001] 233.835886: vpa-dtl: timebase: 338954486095398 dispatch_reason:priv_doorbell, preempt_reason:H_CEDE, enqueue_to_dispatch_time:542, ready_to_enqueue_time:0, waiting_to_ready_time:1245360, processor_id: 201 c0000000000f8094 plpar_hcall_norets_notrace+0x18 ([kernel.kallsyms])
>
> Signed-off-by: Athira Rajeev <atrajeev at linux.ibm.com>
> ---
> tools/perf/builtin-script.c | 23 +++++++++++++++++++++--
> tools/perf/util/powerpc-vpadtl.c | 16 ----------------
> tools/perf/util/powerpc-vpadtl.h | 19 +++++++++++++++++++
> 3 files changed, 40 insertions(+), 18 deletions(-)
>
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index eff584735980..a0faadaadc4d 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -66,6 +66,7 @@
> #include "util/cgroup.h"
> #include "util/annotate.h"
> #include "perf.h"
> +#include "util/powerpc-vpadtl.h"
>
> #include <linux/ctype.h>
> #ifdef HAVE_LIBTRACEEVENT
> @@ -2004,8 +2005,26 @@ static int perf_sample__fprintf_synth_iflag_chg(struct perf_sample *sample, FILE
> }
>
> static void arch_perf_sample__fprintf_synth_evt(struct perf_sample *data __maybe_unused,
> - FILE *fp __maybe_unused, u64 config __maybe_unused)
> + FILE *fp __maybe_unused, u64 config __maybe_unused, struct perf_env *env)
> {
> + const char *arch = perf_env__arch(env);
> +
> + if (!strcmp("powerpc", arch)) {
Not needed. PERF_SYNTH_POWERPC_VPA_DTL is unique.
> + struct dtl_entry *dtl = (struct dtl_entry *)data->raw_data;
> +
> + if (config != PERF_SYNTH_POWERPC_VPA_DTL)
> + return;
> + fprintf(fp, "timebase: %" PRIu64 "dispatch_reason:%s, preempt_reason:%s, enqueue_to_dispatch_time:%d,\
> + ready_to_enqueue_time:%d, waiting_to_ready_time:%d, processor_id: %d",\
> + be64_to_cpu(dtl->timebase),
If the output were ever to be injected into another
perf.data file (by adding support in perf inject) then it
would be aligned to 4 bytes not 8, so for 64-bit access it
would be safer to use get_unaligned_be64()
> + dispatch_reasons[dtl->dispatch_reason],
> + preempt_reasons[dtl->preempt_reason],
> + be32_to_cpu(dtl->enqueue_to_dispatch_time),
> + be32_to_cpu(dtl->ready_to_enqueue_time),
> + be32_to_cpu(dtl->waiting_to_ready_time),
> + be16_to_cpu(dtl->processor_id));
> + }
> +
> return;
> }
>
> @@ -2032,7 +2051,7 @@ static int perf_sample__fprintf_synth(struct perf_sample *sample,
> case PERF_SYNTH_INTEL_IFLAG_CHG:
> return perf_sample__fprintf_synth_iflag_chg(sample, fp);
> default:
> - arch_perf_sample__fprintf_synth_evt(sample, fp, evsel->core.attr.config);
> + arch_perf_sample__fprintf_synth_evt(sample, fp, evsel->core.attr.config, evsel__env(evsel));
> break;
> }
>
> diff --git a/tools/perf/util/powerpc-vpadtl.c b/tools/perf/util/powerpc-vpadtl.c
> index 370c566f9ac2..482ddf1a2d51 100644
> --- a/tools/perf/util/powerpc-vpadtl.c
> +++ b/tools/perf/util/powerpc-vpadtl.c
> @@ -30,22 +30,6 @@
> #include "symbol.h"
> #include "tool.h"
>
> -/*
> - * The DTL entries are of below format
> - */
> -struct dtl_entry {
> - u8 dispatch_reason;
> - u8 preempt_reason;
> - u16 processor_id;
> - u32 enqueue_to_dispatch_time;
> - u32 ready_to_enqueue_time;
> - u32 waiting_to_ready_time;
> - u64 timebase;
> - u64 fault_addr;
> - u64 srr0;
> - u64 srr1;
> -};
> -
> /*
> * Structure to save the auxtrace queue
> */
> diff --git a/tools/perf/util/powerpc-vpadtl.h b/tools/perf/util/powerpc-vpadtl.h
> index 625172adaba5..497f704787a5 100644
> --- a/tools/perf/util/powerpc-vpadtl.h
> +++ b/tools/perf/util/powerpc-vpadtl.h
> @@ -20,6 +20,25 @@ union perf_event;
> struct perf_session;
> struct perf_pmu;
>
> +/*
> + * The DTL entries are of below format
> + */
> +struct dtl_entry {
> + u8 dispatch_reason;
> + u8 preempt_reason;
> + u16 processor_id;
> + u32 enqueue_to_dispatch_time;
> + u32 ready_to_enqueue_time;
> + u32 waiting_to_ready_time;
> + u64 timebase;
> + u64 fault_addr;
> + u64 srr0;
> + u64 srr1;
> +};
As mentioned for patch 8, maybe call it vpadtl_entry or powerpc_vpadtl_entry and
put it in perf/util/event.h
> +
> +extern const char *dispatch_reasons[11];
> +extern const char *preempt_reasons[10];
These are in perf/util/powerpc-vpadtl.c which is conditionally compiled
depending on CONFIG_AUXTRACE. So this happens when building with
NO_AUXTRACE=1 :
usr/bin/ld: perf-in.o: in function `process_sample_event':
builtin-script.c:(.text+0x379a6): undefined reference to `preempt_reasons'
/usr/bin/ld: builtin-script.c:(.text+0x379d5): undefined reference to `dispatch_reasons
> +
> int powerpc_vpadtl_process_auxtrace_info(union perf_event *event,
> struct perf_session *session);
>
More information about the Linuxppc-dev
mailing list