1108fc825SYoshihiro YUNOMAETrace Agent for virtio-trace 2108fc825SYoshihiro YUNOMAE============================ 3108fc825SYoshihiro YUNOMAE 4108fc825SYoshihiro YUNOMAETrace agent is a user tool for sending trace data of a guest to a Host in low 5108fc825SYoshihiro YUNOMAEoverhead. Trace agent has the following functions: 6108fc825SYoshihiro YUNOMAE - splice a page of ring-buffer to read_pipe without memory copying 7108fc825SYoshihiro YUNOMAE - splice the page from write_pipe to virtio-console without memory copying 8108fc825SYoshihiro YUNOMAE - write trace data to stdout by using -o option 9108fc825SYoshihiro YUNOMAE - controlled by start/stop orders from a Host 10108fc825SYoshihiro YUNOMAE 11108fc825SYoshihiro YUNOMAEThe trace agent operates as follows: 12108fc825SYoshihiro YUNOMAE 1) Initialize all structures. 13108fc825SYoshihiro YUNOMAE 2) Create a read/write thread per CPU. Each thread is bound to a CPU. 14108fc825SYoshihiro YUNOMAE The read/write threads hold it. 15108fc825SYoshihiro YUNOMAE 3) A controller thread does poll() for a start order of a host. 16108fc825SYoshihiro YUNOMAE 4) After the controller of the trace agent receives a start order from a host, 17108fc825SYoshihiro YUNOMAE the controller wake read/write threads. 18108fc825SYoshihiro YUNOMAE 5) The read/write threads start to read trace data from ring-buffers and 19108fc825SYoshihiro YUNOMAE write the data to virtio-serial. 20108fc825SYoshihiro YUNOMAE 6) If the controller receives a stop order from a host, the read/write threads 21108fc825SYoshihiro YUNOMAE stop to read trace data. 22108fc825SYoshihiro YUNOMAE 23108fc825SYoshihiro YUNOMAE 24108fc825SYoshihiro YUNOMAEFiles 25108fc825SYoshihiro YUNOMAE===== 26108fc825SYoshihiro YUNOMAE 27108fc825SYoshihiro YUNOMAEREADME: this file 28108fc825SYoshihiro YUNOMAEMakefile: Makefile of trace agent for virtio-trace 29108fc825SYoshihiro YUNOMAEtrace-agent.c: includes main function, sets up for operating trace agent 30108fc825SYoshihiro YUNOMAEtrace-agent.h: includes all structures and some macros 31108fc825SYoshihiro YUNOMAEtrace-agent-ctl.c: includes controller function for read/write threads 32108fc825SYoshihiro YUNOMAEtrace-agent-rw.c: includes read/write threads function 33108fc825SYoshihiro YUNOMAE 34108fc825SYoshihiro YUNOMAE 35108fc825SYoshihiro YUNOMAESetup 36108fc825SYoshihiro YUNOMAE===== 37108fc825SYoshihiro YUNOMAE 38108fc825SYoshihiro YUNOMAETo use this trace agent for virtio-trace, we need to prepare some virtio-serial 39108fc825SYoshihiro YUNOMAEI/Fs. 40108fc825SYoshihiro YUNOMAE 41108fc825SYoshihiro YUNOMAE1) Make FIFO in a host 42108fc825SYoshihiro YUNOMAE virtio-trace uses virtio-serial pipe as trace data paths as to the number 43108fc825SYoshihiro YUNOMAEof CPUs and a control path, so FIFO (named pipe) should be created as follows: 44108fc825SYoshihiro YUNOMAE # mkdir /tmp/virtio-trace/ 45108fc825SYoshihiro YUNOMAE # mkfifo /tmp/virtio-trace/trace-path-cpu{0,1,2,...,X}.{in,out} 46108fc825SYoshihiro YUNOMAE # mkfifo /tmp/virtio-trace/agent-ctl-path.{in,out} 47108fc825SYoshihiro YUNOMAE 48108fc825SYoshihiro YUNOMAEFor example, if a guest use three CPUs, the names are 49108fc825SYoshihiro YUNOMAE trace-path-cpu{0,1,2}.{in.out} 50108fc825SYoshihiro YUNOMAEand 51108fc825SYoshihiro YUNOMAE agent-ctl-path.{in,out}. 52108fc825SYoshihiro YUNOMAE 53108fc825SYoshihiro YUNOMAE2) Set up of virtio-serial pipe in a host 54108fc825SYoshihiro YUNOMAE Add qemu option to use virtio-serial pipe. 55108fc825SYoshihiro YUNOMAE 56108fc825SYoshihiro YUNOMAE ##virtio-serial device## 57108fc825SYoshihiro YUNOMAE -device virtio-serial-pci,id=virtio-serial0\ 58108fc825SYoshihiro YUNOMAE ##control path## 59108fc825SYoshihiro YUNOMAE -chardev pipe,id=charchannel0,path=/tmp/virtio-trace/agent-ctl-path\ 60108fc825SYoshihiro YUNOMAE -device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel0,\ 61108fc825SYoshihiro YUNOMAE id=channel0,name=agent-ctl-path\ 62108fc825SYoshihiro YUNOMAE ##data path## 63108fc825SYoshihiro YUNOMAE -chardev pipe,id=charchannel1,path=/tmp/virtio-trace/trace-path-cpu0\ 649513c55cSRoss Zwisler -device virtserialport,bus=virtio-serial0.0,nr=2,chardev=charchannel1,\ 65108fc825SYoshihiro YUNOMAE id=channel1,name=trace-path-cpu0\ 66108fc825SYoshihiro YUNOMAE ... 67108fc825SYoshihiro YUNOMAE 68108fc825SYoshihiro YUNOMAEIf you manage guests with libvirt, add the following tags to domain XML files. 69108fc825SYoshihiro YUNOMAEThen, libvirt passes the same command option to qemu. 70108fc825SYoshihiro YUNOMAE 71108fc825SYoshihiro YUNOMAE <channel type='pipe'> 72108fc825SYoshihiro YUNOMAE <source path='/tmp/virtio-trace/agent-ctl-path'/> 73108fc825SYoshihiro YUNOMAE <target type='virtio' name='agent-ctl-path'/> 74108fc825SYoshihiro YUNOMAE <address type='virtio-serial' controller='0' bus='0' port='0'/> 75108fc825SYoshihiro YUNOMAE </channel> 76108fc825SYoshihiro YUNOMAE <channel type='pipe'> 77108fc825SYoshihiro YUNOMAE <source path='/tmp/virtio-trace/trace-path-cpu0'/> 78108fc825SYoshihiro YUNOMAE <target type='virtio' name='trace-path-cpu0'/> 79108fc825SYoshihiro YUNOMAE <address type='virtio-serial' controller='0' bus='0' port='1'/> 80108fc825SYoshihiro YUNOMAE </channel> 81108fc825SYoshihiro YUNOMAE ... 82108fc825SYoshihiro YUNOMAEHere, chardev names are restricted to trace-path-cpuX and agent-ctl-path. For 83108fc825SYoshihiro YUNOMAEexample, if a guest use three CPUs, chardev names should be trace-path-cpu0, 84108fc825SYoshihiro YUNOMAEtrace-path-cpu1, trace-path-cpu2, and agent-ctl-path. 85108fc825SYoshihiro YUNOMAE 86108fc825SYoshihiro YUNOMAE3) Boot the guest 87108fc825SYoshihiro YUNOMAE You can find some chardev in /dev/virtio-ports/ in the guest. 88108fc825SYoshihiro YUNOMAE 89108fc825SYoshihiro YUNOMAE 90108fc825SYoshihiro YUNOMAERun 91108fc825SYoshihiro YUNOMAE=== 92108fc825SYoshihiro YUNOMAE 93108fc825SYoshihiro YUNOMAE0) Build trace agent in a guest 94108fc825SYoshihiro YUNOMAE $ make 95108fc825SYoshihiro YUNOMAE 96108fc825SYoshihiro YUNOMAE1) Enable ftrace in the guest 97108fc825SYoshihiro YUNOMAE <Example> 98*07496eeaSRoss Zwisler # echo 1 > /sys/kernel/tracing/events/sched/enable 99108fc825SYoshihiro YUNOMAE 100108fc825SYoshihiro YUNOMAE2) Run trace agent in the guest 101108fc825SYoshihiro YUNOMAE This agent must be operated as root. 102108fc825SYoshihiro YUNOMAE # ./trace-agent 103108fc825SYoshihiro YUNOMAEread/write threads in the agent wait for start order from host. If you add -o 104108fc825SYoshihiro YUNOMAEoption, trace data are output via stdout in the guest. 105108fc825SYoshihiro YUNOMAE 106108fc825SYoshihiro YUNOMAE3) Open FIFO in a host 107108fc825SYoshihiro YUNOMAE # cat /tmp/virtio-trace/trace-path-cpu0.out 108108fc825SYoshihiro YUNOMAEIf a host does not open these, trace data get stuck in buffers of virtio. Then, 109108fc825SYoshihiro YUNOMAEthe guest will stop by specification of chardev in QEMU. This blocking mode may 110108fc825SYoshihiro YUNOMAEbe solved in the future. 111108fc825SYoshihiro YUNOMAE 112108fc825SYoshihiro YUNOMAE4) Start to read trace data by ordering from a host 113108fc825SYoshihiro YUNOMAE A host injects read start order to the guest via virtio-serial. 114108fc825SYoshihiro YUNOMAE # echo 1 > /tmp/virtio-trace/agent-ctl-path.in 115108fc825SYoshihiro YUNOMAE 116108fc825SYoshihiro YUNOMAE5) Stop to read trace data by ordering from a host 117108fc825SYoshihiro YUNOMAE A host injects read stop order to the guest via virtio-serial. 118108fc825SYoshihiro YUNOMAE # echo 0 > /tmp/virtio-trace/agent-ctl-path.in 119