Skip to contentSkip to conversation

Add VM kernel tracing using VSOCK socket for transport

PATCH Superseded [email protected] 2 participants 3 messages Nov 7, 2018 – Nov 8, 2018

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add VM kernel tracing using VSOCK socket for transport

From: Slavomir Kaslev <[email protected]>

To test, start a VM and assign it a valid (> 2) unused CID:

    you@host # qemu-system-x86_64 \
        -name guest2 --uuid 7edfdf4a-cb9e-11e8-b38a-173b58342476 \
        -m 4096 -boot d -enable-kvm -smp 3 -net nic -net user -hda $HOME/vm/guest2.img \
        -fsdev local,id=host,path=$HOME,security_model=mapped \
        -device virtio-9p-pci,fsdev=host,mount_tag=host \
        -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x6 \
        -chardev pipe,id=charchannel1,path=/var/lib/test/fifo0 \
        -device virtserialport,bus=virtio-serial0.0,nr=3,chardev=charchannel1,id=channel1,name=fifo0 \
        -device vhost-vsock-pci,id=vhost-vsock-pci0,guest-cid=3

and start trace-cmd agent on the guest as root:

you@guest2 # trace-cmd agent

Finally, start trace-cmd record on the host (running as root is only necessary if the host will be traced too):

you@host $ trace-cmd record -A guest2 -e irq -e sched

---
 include/trace-cmd/trace-cmd.h  |  14 +
 lib/trace-cmd/trace-input.c    |   2 +-
 lib/trace-cmd/trace-recorder.c |  53 ++-
 tracecmd/Makefile              |   1 +
 tracecmd/include/trace-local.h |  19 +
 tracecmd/trace-agent.c         | 229 ++++++++++++
 tracecmd/trace-cmd.c           |   1 +
 tracecmd/trace-msg.c           | 219 ++++++++++-
 tracecmd/trace-record.c        | 666 ++++++++++++++++++++++++++++++---
 tracecmd/trace-usage.c         |  11 +-
 10 files changed, 1140 insertions(+), 75 deletions(-)
 create mode 100644 tracecmd/trace-agent.c
include/trace-cmd/trace-cmd.h +14 -0
index 684ddb7..896fa4f 100644
@@ -271,6 +271,7 @@ enum {
 void tracecmd_free_recorder(struct tracecmd_recorder *recorder);
 struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu, unsigned flags);
 struct tracecmd_recorder *tracecmd_create_recorder_fd(int fd, int cpu, unsigned flags);
+struct tracecmd_recorder *tracecmd_create_recorder_virt(const char *file, int cpu, int trace_fd);
 struct tracecmd_recorder *tracecmd_create_recorder_maxkb(const char *file, int cpu, unsigned flags, int maxkb);
 struct tracecmd_recorder *tracecmd_create_buffer_recorder_fd(int fd, int cpu, unsigned flags, const char *buffer);
 struct tracecmd_recorder *tracecmd_create_buffer_recorder(const char *file, int cpu, unsigned flags, const char *buffer);
@@ -325,10 +326,23 @@ void tracecmd_msg_send_close_msg(struct tracecmd_msg_handle *msg_handle);
 int tracecmd_msg_initial_setting(struct tracecmd_msg_handle *msg_handle);
 int tracecmd_msg_send_port_array(struct tracecmd_msg_handle *msg_handle,
 				 int *ports);
+int tracecmd_msg_read_metadata(struct tracecmd_msg_handle *msg_handle, int ofd);
 int tracecmd_msg_collect_metadata(struct tracecmd_msg_handle *msg_handle, int ofd);
 bool tracecmd_msg_done(struct tracecmd_msg_handle *msg_handle);
 void tracecmd_msg_set_done(struct tracecmd_msg_handle *msg_handle);
 
+int tracecmd_msg_send_trace_req(struct tracecmd_msg_handle *msg_handle,
+				int argc, char **argv);
+int tracecmd_msg_recv_trace_req(struct tracecmd_msg_handle *msg_handle,
+				int *argc, char ***argv);
+
+int tracecmd_msg_send_trace_resp(struct tracecmd_msg_handle *msg_handle,
+				 int nr_cpus, int page_size, int *ports);
+int tracecmd_msg_recv_trace_resp(struct tracecmd_msg_handle *msg_handle,
+				 int *nr_cpus, int *page_size, int **ports);
+
+int tracecmd_msg_wait_close(struct tracecmd_msg_handle *msg_handle);
+
 /* --- Plugin handling --- */
 extern struct tep_plugin_option trace_ftrace_options[];
 
lib/trace-cmd/trace-input.c +1 -1
index d70c110..7a8cbde 100644
@@ -2603,7 +2603,7 @@ struct tracecmd_input *tracecmd_alloc_fd(int fd)
 {
 	struct tracecmd_input *handle;
 	char test[] = { 23, 8, 68 };
-    unsigned int page_size;
+	unsigned int page_size;
 	char *version;
 	char buf[BUFSIZ];
 
lib/trace-cmd/trace-recorder.c +38 -15

81 lines not on this page · raw message

tracecmd/Makefile +1 -0
index 3a11024..6f2e405 100644
@@ -17,6 +17,7 @@ TRACE_CMD_OBJS += trace-record.o
 TRACE_CMD_OBJS += trace-read.o
 TRACE_CMD_OBJS += trace-split.o
 TRACE_CMD_OBJS += trace-listen.o
+TRACE_CMD_OBJS += trace-agent.o
 TRACE_CMD_OBJS += trace-stack.o
 TRACE_CMD_OBJS += trace-hist.o
 TRACE_CMD_OBJS += trace-mem.o
tracecmd/include/trace-local.h +19 -0
index a1a06e9..5072d8e 100644
@@ -12,6 +12,8 @@
 #include "trace-cmd.h"
 #include "event-utils.h"
 
+#define TRACE_AGENT_DEFAULT_PORT	823
+
 extern int debug;
 extern int quiet;
 
@@ -64,6 +66,8 @@ void trace_split(int argc, char **argv);
 
 void trace_listen(int argc, char **argv);
 
+void trace_agent(int argc, char **argv);
+
 void trace_restore(int argc, char **argv);
 
 void trace_clear(int argc, char **argv);
@@ -88,6 +92,10 @@ void trace_list(int argc, char **argv);
 
 void trace_usage(int argc, char **argv);
 
+int trace_record_agent(struct tracecmd_msg_handle *msg_handle,
+		       int cpus, int *fds,
+		       int argc, char **argv);
+
 struct hook_list;
 
 void trace_init_profile(struct tracecmd_input *handle, struct hook_list *hooks,
@@ -149,6 +157,8 @@ char *strstrip(char *str);
 enum buffer_instance_flags {
 	BUFFER_FL_KEEP		= 1 << 0,
 	BUFFER_FL_PROFILE	= 1 << 1,
+	BUFFER_FL_GUEST		= 1 << 2,
+	BUFFER_FL_AGENT		= 1 << 3,
 };
 
 struct func_list {
@@ -174,6 +184,7 @@ struct buffer_instance {
 	struct func_list	*notrace_funcs;
 
 	const char		*clock;
+	int			*client_ports;
 
 	struct trace_seq	*s_save;
 	struct trace_seq	*s_print;
@@ -188,6 +199,14 @@ struct buffer_instance {
 	int			tracing_on_fd;
 	int			buffer_size;
 	int			cpu_count;
+
+	int			argc;
+	char			**argv;
+	int			argv_cap;
+
+	int			cid;
+	int			port;
+	int			*fds;
 };
 
 extern struct buffer_instance top_instance;
tracecmd/trace-agent.c new file +229 -0

229 lines not on this page · raw message

tracecmd/trace-cmd.c +1 -0
index 797b303..2d4fc1b 100644
@@ -83,6 +83,7 @@ struct command commands[] = {
 	{"hist", trace_hist},
 	{"mem", trace_mem},
 	{"listen", trace_listen},
+	{"agent", trace_agent},
 	{"split", trace_split},
 	{"restore", trace_restore},
 	{"stack", trace_stack},
tracecmd/trace-msg.c +216 -3

274 lines not on this page · raw message

tracecmd/trace-record.c +611 -55

1,033 lines not on this page · raw message

tracecmd/trace-usage.c +10 -1
index 10f737b..731d462 100644
@@ -231,11 +231,20 @@ static struct usage_help usage_help[] = {
 		"listen on a network socket for trace clients",
 		" %s listen -p port[-D][-o file][-d dir][-l logfile]\n"
 		"          Creates a socket to listen for clients.\n"
-		"          -D create it in daemon mode.\n"
+		"          -p port number to listen on.\n"
+		"          -D run in daemon mode.\n"
 		"          -o file name to use for clients.\n"
 		"          -d diretory to store client files.\n"
 		"          -l logfile to write messages to.\n"
 	},
+	{
+		"agent",
+		"listen on a VSOCK socket for trace clients",
+		" %s agent -p port[-D]\n"
+		"          Creates a VSOCK socket to listen for clients.\n"
+		"          -p port number to listen on.\n"
+		"          -D run in daemon mode.\n"
+	},
 	{
 		"list",
 		"list the available events, plugins or options",
Signature · 1 line
2.17.1
#1 lore raw
Quoted 4 lines · On Tue, 6 Nov 2018 16:59:02 +0200 [email protected] wrote:

From: Slavomir Kaslev <[email protected]>

To test, start a VM and assign it a valid (> 2) unused CID:

Quoted 9 lines
    you@host # qemu-system-x86_64 \
        -name guest2 --uuid 7edfdf4a-cb9e-11e8-b38a-173b58342476 \
        -m 4096 -boot d -enable-kvm -smp 3 -net nic -net user -hda $HOME/vm/guest2.img \
        -fsdev local,id=host,path=$HOME,security_model=mapped \
        -device virtio-9p-pci,fsdev=host,mount_tag=host \
        -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x6 \
        -chardev pipe,id=charchannel1,path=/var/lib/test/fifo0 \
        -device virtserialport,bus=virtio-serial0.0,nr=3,chardev=charchannel1,id=channel1,name=fifo0 \
        -device vhost-vsock-pci,id=vhost-vsock-pci0,guest-cid=3

It would be more helpful to specify what parameters are needed and why. The above isn't useful for me, as I run my guests with libvirt, and can hard code in extra parameters. But if I don't know what I need to hard code in, I can't simulate it.

-- Steve

Quoted 12 lines

and start trace-cmd agent on the guest as root:

you@guest2 # trace-cmd agent

Finally, start trace-cmd record on the host (running as root is only necessary if the host will be traced too):

you@host $ trace-cmd record -A guest2 -e irq -e sched

#2 lore raw
Quoted 18 lines · Steven Rostedt
Quoted 4 lines · On Tue, 6 Nov 2018 16:59:02 +0200 [email protected] wrote:

From: Slavomir Kaslev <[email protected]>

To test, start a VM and assign it a valid (> 2) unused CID:

Quoted 9 lines
    you@host # qemu-system-x86_64 \
        -name guest2 --uuid 7edfdf4a-cb9e-11e8-b38a-173b58342476 \
        -m 4096 -boot d -enable-kvm -smp 3 -net nic -net user -hda $HOME/vm/guest2.img \
        -fsdev local,id=host,path=$HOME,security_model=mapped \
        -device virtio-9p-pci,fsdev=host,mount_tag=host \
        -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x6 \
        -chardev pipe,id=charchannel1,path=/var/lib/test/fifo0 \
        -device virtserialport,bus=virtio-serial0.0,nr=3,chardev=charchannel1,id=channel1,name=fifo0 \
        -device vhost-vsock-pci,id=vhost-vsock-pci0,guest-cid=3
Quoted 4 lines

It would be more helpful to specify what parameters are needed and why. The above isn't useful for me, as I run my guests with libvirt, and can hard code in extra parameters. But if I don't know what I need to hard code in, I can't simulate it.

Only the last line is necessary for testing:

-device vhost-vsock-pci,id=vhost-vsock-pci0,guest-cid=3

where 'guest-cid=3' can be any number > 2 and is unique across VMs. Sorry about the noisy command in the commit message, I already fixed it for V2 of this patch which I'll send after all feedback is addressed.