From 64d4e02b4ff1b0a9cc50e09ae9ffe5ed21feee24 Mon Sep 17 00:00:00 2001 From: Thomas Richter Date: Wed, 10 Jan 2024 15:24:09 +0100 Subject: [PATCH] cpumf/pai: Handle perf records type PERF_RECORD_SWITCH MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Running command pai -r might encounter entries of type PERF_RECORD_SWITCH. Entries of that type are currently not handled and cause an error message: # pai -r ~/paicrypto.000 unknown header-type 14 unknown header-type 14 \ unknown header-type 14 ... The error message is not terminated by a newline. Handle entries of this type PERF_RECORD_SWITCH. These records do not carry any payload at all, just a bit is set in the header::misc member. This bit set determines context switch out. Output after: # ./pai -r ~/paicrypto.000 0x4b814018f4f3 6 cs-out 0x4b817bc3c936 6 cs-in 0x4b817bc5246c 6 cs-out 0x4b817bd90e9a 6 cs-in .... # Signed-off-by: Thomas Richter Acked-by: Sumanth Korikkar Signed-off-by: Jan Höppner --- cpumf/pai.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cpumf/pai.c b/cpumf/pai.c index 68bdebfa..4c60e54c 100644 --- a/cpumf/pai.c +++ b/cpumf/pai.c @@ -449,6 +449,11 @@ static void evt_show(__u64 evtnum, const char *evtsel, struct pai_event_out *ev) ev->u.s_comm.tid); break; + case PERF_RECORD_SWITCH: + printf("cs-%s", + (ev->misc & PERF_RECORD_MISC_SWITCH_OUT) ? "out" : "in"); + break; + case PERF_RECORD_SWITCH_CPU_WIDE: if (ev->misc & PERF_RECORD_MISC_SWITCH_OUT) { short p = PERF_RECORD_MISC_SWITCH_OUT_PREEMPT; @@ -549,6 +554,9 @@ static int evt_scan(char *fn, unsigned char *buf, size_t len, offset -= sizeof(__u64); break; + case PERF_RECORD_SWITCH: + break; + case PERF_RECORD_SWITCH_CPU_WIDE: memcpy(&ev.u, buf + offset, sizeof(ev.u.s_cs)); offset += sizeof(ev.u.s_cs); @@ -583,7 +591,7 @@ static int evt_scan(char *fn, unsigned char *buf, size_t len, break; default: - printf("unknown header-type %d ", hdr->type); + printf("unknown header-type %d\n", hdr->type); offset += hdr->size - sizeof(*hdr); goto bypass; }