Skip to content

Commit 2013acb

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 c809fff commit 2013acb

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

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) scripts for kernel tracing
3739

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

tools/eBPF/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Enhanced Berkeley Packet Filter (eBPF) scripts
2+
3+
bpftrace must be installed to be able to use eBPF scripts:
4+
5+
```
6+
sudo apt install bpftrace
7+
sudo dnf install bpftrace
8+
sudo pacman -S bpftrace
9+
sudo emerge -a bpftrace
10+
...
11+
```
12+
13+
**Note**: the distro provided bpftrace might be old, in that case the tool can be downloaded from [https://github.com/bpftrace/bpftrace/releases](URL)
14+
15+
## ipc4-msg-trace.bt
16+
17+
The script will tap onto the entry of sof_ipc4_log_header() to log IPC messages.
18+
It will start logging the sent messages (including payloads) and received notification with exception of 0x1b060000 - trace update.
19+
20+
### To use the script:
21+
22+
```
23+
sudo ./tools/sof-ipc4-msg-trace.bt
24+
or
25+
sudo bpftrace tools/sof-ipc4-msg-trace.bt
26+
```
27+
28+
To stop the logging, just terminate the script with CTRL+C

tools/eBPF/ipc4-msg-trace.bt

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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 32bit words, arranged by 4 words/line.
25+
* In case the payload lenght is not aligned to 32bit words, the remaining 1-3
26+
* bytes are printed as bytes (unlikely, just for safety)
27+
*/
28+
kprobe:sof_ipc4_log_header {
29+
$msg = (struct sof_ipc4_msg *)arg2;
30+
31+
if ($msg->primary != 0x1b060000 && arg3 == 1 && $msg->data_size != 0) {
32+
printf("%s : 0x%x|0x%x [data size:: %llu]\n", str(arg1),
33+
$msg->primary, $msg->extension, $msg->data_size);
34+
35+
if (!strcontains(str(arg1), "done")) {
36+
$count = (int64) $msg->data_size;
37+
$ptr = (uint32*) $msg->data_ptr;
38+
39+
printf("Message payload:\n");
40+
41+
$line = 0;
42+
while ($line < 500) {
43+
printf("%08x:", $line * 16);
44+
45+
$word = 0;
46+
while ($word < 4) {
47+
if ($count >= 4) {
48+
printf(" %08x", *$ptr);
49+
$count -= 4;
50+
} else {
51+
printf("%rh", buf($ptr, $count));
52+
$count = 0;
53+
}
54+
55+
if ($count == 0) {
56+
break;
57+
}
58+
59+
$ptr++;
60+
$word++;
61+
}
62+
63+
printf("\n");
64+
65+
if ($count == 0) {
66+
break;
67+
}
68+
69+
$line++;
70+
}
71+
} else {
72+
printf("\n");
73+
}
74+
} else if ($msg->primary != 0x1b060000) {
75+
printf("%s : 0x%x|0x%x\n", str(arg1), $msg->primary, $msg->extension);
76+
77+
if (strcontains(str(arg1), "done")) {
78+
printf("\n");
79+
}
80+
}
81+
}
82+

0 commit comments

Comments
 (0)