Skip to content

Commit 6a574da

Browse files
committed
tools: Initial version of IPC4 tx message logger using eBPF
The ipc4-msg-trace.bt script will tap into the entry of sof_ipc4_log_header() which is always called but only prints if dynamic debugging is enabled. It's parameter list is not expected to be changed. The bpftrace must be installed to be able to use the script sudo pacman -S bpftrace sudo emerge -a bpftrace sudo apt install bpftrace sudo dnf install bpftrace To use the script: sudo ./tools/sof-ipc4-msg-trace.bt or sudo bpftrace tools/sof-ipc4-msg-trace.bt It will start logging the sent messages (including payloads) and received notification with exception of 0x1b060000 - trace update. To stop the logging, just terminate the script with CTRL+C Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
1 parent 6571dcf commit 6a574da

3 files changed

Lines changed: 80 additions & 0 deletions

File tree

tools/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
* sof-process-state.sh
3535
<br> Shows the current state of a given process
3636

37+
* eBPF (directory)
38+
<br> Enhanced Berkeley Packet Filter (eBPF) dcripts for kernel tracing
3739

3840
Topologies
3941
----------

tools/eBPF/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# ipc4-msg-trace.bt
2+
3+
script will tap into the entry of sof_ipc4_log_header() to log IPC messages.
4+
5+
## To use the script:
6+
7+
```
8+
sudo ./tools/sof-ipc4-msg-trace.bt
9+
or
10+
sudo bpftrace tools/sof-ipc4-msg-trace.bt
11+
```
12+
13+
It will start logging the sent messages (including payloads) and received notification with exception of 0x1b060000 - trace update.
14+
15+
To stop the logging, just terminate the script with CTRL+C

tools/eBPF/ipc4-msg-trace.bt

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/bpftrace
2+
3+
struct sof_ipc4_msg {
4+
union {
5+
unsigned long header_u64;
6+
struct {
7+
unsigned int primary;
8+
unsigned int extension;
9+
};
10+
};
11+
12+
unsigned long data_size;
13+
void *data_ptr;
14+
};
15+
16+
BEGIN
17+
{
18+
printf("SOF IPC4 tx message logging. Ctrl-C to end.\n\n");
19+
}
20+
21+
/*
22+
* Log the sent IPC4 messages, ignoring the 0x1b060000 notification
23+
* from firmware (trace update)
24+
* The message payload is printed as bytes, arranged by 16 bytes/line
25+
*/
26+
kprobe:sof_ipc4_log_header {
27+
$msg = (struct sof_ipc4_msg *)arg2;
28+
29+
if ($msg->primary != 0x1b060000 && arg3 == 1 && $msg->data_size != 0) {
30+
printf("%s : 0x%x|0x%x [data size:: %llu]\n", str(arg1),
31+
$msg->primary, $msg->extension, $msg->data_size);
32+
if (!strcontains(str(arg1), "done")) {
33+
$count = (int64) $msg->data_size;
34+
$ptr = (uint8*) $msg->data_ptr;
35+
$line = 0;
36+
37+
printf("Message payload:\n");
38+
while ($line < 500) {
39+
if ($count <= 16) {
40+
printf("%rh\n", buf($ptr, $count));
41+
break;
42+
}
43+
44+
printf("%rh\n", buf($ptr, 16));
45+
$count -= 16;
46+
if ($count == 0) {
47+
break;
48+
}
49+
$ptr += 16;
50+
$line++;
51+
}
52+
} else {
53+
printf("\n");
54+
}
55+
} else if ($msg->primary != 0x1b060000) {
56+
printf("%s : 0x%x|0x%x\n", str(arg1), $msg->primary,
57+
$msg->extension);
58+
if (strcontains(str(arg1), "done")) {
59+
printf("\n");
60+
}
61+
}
62+
}
63+

0 commit comments

Comments
 (0)