Skip to content

Commit

Permalink
tools: Initial version of IPC4 tx message logger using eBPF
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ujfalusi committed Jun 10, 2024
1 parent 6571dcf commit 6a574da
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
* sof-process-state.sh
<br> Shows the current state of a given process

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

Topologies
----------
Expand Down
15 changes: 15 additions & 0 deletions tools/eBPF/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# ipc4-msg-trace.bt

script will tap into the entry of sof_ipc4_log_header() to log IPC messages.

## 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
63 changes: 63 additions & 0 deletions tools/eBPF/ipc4-msg-trace.bt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/bpftrace

struct sof_ipc4_msg {
union {
unsigned long header_u64;
struct {
unsigned int primary;
unsigned int extension;
};
};

unsigned long data_size;
void *data_ptr;
};

BEGIN
{
printf("SOF IPC4 tx message logging. Ctrl-C to end.\n\n");
}

/*
* Log the sent IPC4 messages, ignoring the 0x1b060000 notification
* from firmware (trace update)
* The message payload is printed as bytes, arranged by 16 bytes/line
*/
kprobe:sof_ipc4_log_header {
$msg = (struct sof_ipc4_msg *)arg2;

if ($msg->primary != 0x1b060000 && arg3 == 1 && $msg->data_size != 0) {
printf("%s : 0x%x|0x%x [data size:: %llu]\n", str(arg1),
$msg->primary, $msg->extension, $msg->data_size);
if (!strcontains(str(arg1), "done")) {
$count = (int64) $msg->data_size;
$ptr = (uint8*) $msg->data_ptr;
$line = 0;

printf("Message payload:\n");
while ($line < 500) {
if ($count <= 16) {
printf("%rh\n", buf($ptr, $count));
break;
}

printf("%rh\n", buf($ptr, 16));
$count -= 16;
if ($count == 0) {
break;
}
$ptr += 16;
$line++;
}
} else {
printf("\n");
}
} else if ($msg->primary != 0x1b060000) {
printf("%s : 0x%x|0x%x\n", str(arg1), $msg->primary,
$msg->extension);
if (strcontains(str(arg1), "done")) {
printf("\n");
}
}
}

0 comments on commit 6a574da

Please sign in to comment.