Re: [PATCH v1] arch/x86: port I/O tracing on x86

From: Dan Raymond
Date: Tue Sep 19 2023 - 15:30:15 EST


This feature was developed because there is currently no way to trace UART traffic when using an I/O port based serial port. It can only be done with memory-mapped serial ports using CONFIG_MMIOTRACE or CONFIG_TRACE_MMIO_ACCESS. Port I/O tracing can now be done as follows:

# cat /proc/tty/driver/serial
serinfo:1.0 driver revision:
0: uart:16550A port:000003F8 irq:4 tx:0 rx:0
1: uart:16550A port:000002F8 irq:3 tx:60 rx:184 RTS|DTR
2: uart:unknown port:000003E8 irq:4
3: uart:unknown port:000002E8 irq:3

# mount -t tracefs tracefs /sys/kernel/tracing
# cd /sys/kernel/tracing
# echo 'port >= 0x2f8 && port <= 0x2ff' > events/portio/filter
# echo 1 > events/portio/enable

(perform UART transaction on /dev/ttyS1)

# cat trace
# tracer: nop
#
# entries-in-buffer/entries-written: 17/17 #P:1
#
# _-----=> irqs-off/BH-disabled
# / _----=> need-resched
# | / _---=> hardirq/softirq
# || / _--=> preempt-depth
# ||| / _-=> migrate-disable
# |||| / delay
# TASK-PID CPU# ||||| TIMESTAMP FUNCTION
# | | | ||||| | |
my_app-90 [000] d..1. 130.595559: portio_write: port=0x02f9 value=0x07 io_serial_out+0x0/0x40
my_app-90 [000] d.h2. 130.595574: portio_read: port=0x02fa value=0xc2 io_serial_in+0x0/0x80
my_app-90 [000] d.h3. 130.595577: portio_read: port=0x02fd value=0x60 io_serial_in+0x0/0x80
my_app-90 [000] d.h3. 130.595580: portio_read: port=0x02fe value=0x00 io_serial_in+0x0/0x80
my_app-90 [000] d.h3. 130.595582: portio_write: port=0x02f8 value=0xc9 io_serial_out+0x0/0x40
my_app-90 [000] d.h3. 130.595587: portio_write: port=0x02f9 value=0x05 io_serial_out+0x0/0x40
my_app-90 [000] d.h2. 130.595590: portio_read: port=0x02fa value=0xc1 io_serial_in+0x0/0x80
<idle>-0 [000] d.h2. 130.745727: portio_read: port=0x02fa value=0xcc io_serial_in+0x0/0x80
<idle>-0 [000] d.h3. 130.745733: portio_read: port=0x02fd value=0x61 io_serial_in+0x0/0x80
<idle>-0 [000] d.h3. 130.745736: portio_read: port=0x02f8 value=0xc9 io_serial_in+0x0/0x80
<idle>-0 [000] d.h3. 130.745740: portio_read: port=0x02fd value=0x61 io_serial_in+0x0/0x80
<idle>-0 [000] d.h3. 130.745742: portio_read: port=0x02f8 value=0xe8 io_serial_in+0x0/0x80
<idle>-0 [000] d.h3. 130.745744: portio_read: port=0x02fd value=0x61 io_serial_in+0x0/0x80
<idle>-0 [000] d.h3. 130.745746: portio_read: port=0x02f8 value=0x00 io_serial_in+0x0/0x80
<idle>-0 [000] d.h3. 130.745748: portio_read: port=0x02fd value=0x60 io_serial_in+0x0/0x80
<idle>-0 [000] dNh3. 130.745762: portio_read: port=0x02fe value=0x00 io_serial_in+0x0/0x80
<idle>-0 [000] dNh2. 130.745765: portio_read: port=0x02fa value=0xc1 io_serial_in+0x0/0x80