Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) Trace Agent for virtio-trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) ============================
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) Trace agent is a user tool for sending trace data of a guest to a Host in low
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) overhead. Trace agent has the following functions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  - splice a page of ring-buffer to read_pipe without memory copying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  - splice the page from write_pipe to virtio-console without memory copying
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  - write trace data to stdout by using -o option
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  - controlled by start/stop orders from a Host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) The trace agent operates as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  1) Initialize all structures.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  2) Create a read/write thread per CPU. Each thread is bound to a CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)     The read/write threads hold it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  3) A controller thread does poll() for a start order of a host.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  4) After the controller of the trace agent receives a start order from a host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)     the controller wake read/write threads.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  5) The read/write threads start to read trace data from ring-buffers and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)     write the data to virtio-serial.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  6) If the controller receives a stop order from a host, the read/write threads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)     stop to read trace data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) Files
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) =====
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) README: this file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) Makefile: Makefile of trace agent for virtio-trace
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) trace-agent.c: includes main function, sets up for operating trace agent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) trace-agent.h: includes all structures and some macros
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) trace-agent-ctl.c: includes controller function for read/write threads
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) trace-agent-rw.c: includes read/write threads function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) Setup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) =====
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) To use this trace agent for virtio-trace, we need to prepare some virtio-serial
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) I/Fs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 1) Make FIFO in a host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42)  virtio-trace uses virtio-serial pipe as trace data paths as to the number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) of CPUs and a control path, so FIFO (named pipe) should be created as follows:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	# mkdir /tmp/virtio-trace/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	# mkfifo /tmp/virtio-trace/trace-path-cpu{0,1,2,...,X}.{in,out}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	# mkfifo /tmp/virtio-trace/agent-ctl-path.{in,out}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) For example, if a guest use three CPUs, the names are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	trace-path-cpu{0,1,2}.{in.out}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	agent-ctl-path.{in,out}.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 2) Set up of virtio-serial pipe in a host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  Add qemu option to use virtio-serial pipe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  ##virtio-serial device##
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)      -device virtio-serial-pci,id=virtio-serial0\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  ##control path##
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)      -chardev pipe,id=charchannel0,path=/tmp/virtio-trace/agent-ctl-path\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60)      -device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61)       id=channel0,name=agent-ctl-path\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62)  ##data path##
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)      -chardev pipe,id=charchannel1,path=/tmp/virtio-trace/trace-path-cpu0\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64)      -device virtserialport,bus=virtio-serial0.0,nr=2,chardev=charchannel0,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65)       id=channel1,name=trace-path-cpu0\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66)       ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) If you manage guests with libvirt, add the following tags to domain XML files.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) Then, libvirt passes the same command option to qemu.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	<channel type='pipe'>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	   <source path='/tmp/virtio-trace/agent-ctl-path'/>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	   <target type='virtio' name='agent-ctl-path'/>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	   <address type='virtio-serial' controller='0' bus='0' port='0'/>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	</channel>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	<channel type='pipe'>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	   <source path='/tmp/virtio-trace/trace-path-cpu0'/>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	   <target type='virtio' name='trace-path-cpu0'/>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	   <address type='virtio-serial' controller='0' bus='0' port='1'/>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	</channel>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) Here, chardev names are restricted to trace-path-cpuX and agent-ctl-path. For
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) example, if a guest use three CPUs, chardev names should be trace-path-cpu0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) trace-path-cpu1, trace-path-cpu2, and agent-ctl-path.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 3) Boot the guest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87)  You can find some chardev in /dev/virtio-ports/ in the guest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) Run
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) ===
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 0) Build trace agent in a guest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	$ make
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 1) Enable ftrace in the guest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  <Example>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	# echo 1 > /sys/kernel/debug/tracing/events/sched/enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 2) Run trace agent in the guest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  This agent must be operated as root.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	# ./trace-agent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) read/write threads in the agent wait for start order from host. If you add -o
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) option, trace data are output via stdout in the guest.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 3) Open FIFO in a host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	# cat /tmp/virtio-trace/trace-path-cpu0.out
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) If a host does not open these, trace data get stuck in buffers of virtio. Then,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) the guest will stop by specification of chardev in QEMU. This blocking mode may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) be solved in the future.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 4) Start to read trace data by ordering from a host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  A host injects read start order to the guest via virtio-serial.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	# echo 1 > /tmp/virtio-trace/agent-ctl-path.in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 5) Stop to read trace data by ordering from a host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)  A host injects read stop order to the guest via virtio-serial.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	# echo 0 > /tmp/virtio-trace/agent-ctl-path.in