From be725b353dce7add5dbd92d7a2fc0039018fd2a9 Mon Sep 17 00:00:00 2001 Message-Id: In-Reply-To: References: From: Blue Swirl Date: Tue, 23 Aug 2011 17:31:53 +0000 Subject: [PATCH 2/2] trace: implement guest tracepoint passthrough Let guests inject tracepoint data via fw_cfg device. Signed-off-by: Blue Swirl --- Makefile.objs | 14 ++++++++++- configure | 6 +++++ hw/fw_cfg.c | 27 +++++++++++++++++++++++ hw/fw_cfg.h | 2 + scripts/tracetool | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 105 insertions(+), 4 deletions(-) diff --git a/Makefile.objs b/Makefile.objs index df11aec..ba59665 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -340,12 +340,12 @@ else trace.h: trace.h-timestamp endif trace.h-timestamp: $(SRC_PATH)/trace-events config-host.mak - $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -h < $< > $@," GEN trace.h") + $(call quiet-command,cat $< $(CONFIG_GUEST_TRACE_FILE) | sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -h > $@," GEN trace.h") @cmp -s $@ trace.h || cp $@ trace.h trace.c: trace.c-timestamp trace.c-timestamp: $(SRC_PATH)/trace-events config-host.mak - $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -c < $< > $@," GEN trace.c") + $(call quiet-command,cat $< $(CONFIG_GUEST_TRACE_FILE) | sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -c > $@," GEN trace.c") @cmp -s $@ trace.c || cp $@ trace.c trace.o: trace.c $(GENERATED_HEADERS) @@ -384,6 +384,16 @@ user-obj-y += qemu-timer-common.o endif endif +ifneq ($(CONFIG_GUEST_TRACE_FILE),) +guest-trace.c: guest-trace.c-timestamp +guest-trace.c-timestamp: $(CONFIG_GUEST_TRACE_FILE) config-host.mak + $(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -g < $< > $@," GEN guest-trace.c") + @cmp -s $@ guest-trace.c || cp $@ guest-trace.c + +guest-trace.o: guest-trace.c $(GENERATED_HEADERS) +trace-obj-y += guest-trace.o +endif + ###################################################################### # smartcard diff --git a/configure b/configure index 1340c33..fd13e73 100755 --- a/configure +++ b/configure @@ -175,6 +175,7 @@ user_pie="no" zero_malloc="" trace_backend="nop" trace_file="trace" +guest_trace_file="" spice="" rbd="" smartcard="" @@ -537,6 +538,8 @@ for opt do ;; --with-trace-file=*) trace_file="$optarg" ;; + --with-guest-trace-file=*) guest_trace_file="$optarg" + ;; --enable-gprof) gprof="yes" ;; --static) @@ -1033,6 +1036,7 @@ echo " --enable-trace-backend=B Set trace backend" echo " Available backends:" $("$source_path"/scripts/tracetool --list-backends) echo " --with-trace-file=NAME Full PATH,NAME of file to store traces" echo " Default:trace-" +echo " --with-guest-trace-file=NAME Full PATH,NAME for guest trace events" echo " --disable-spice disable spice" echo " --enable-spice enable spice" echo " --enable-rbd enable building the rados block device (rbd)" @@ -2724,6 +2728,7 @@ echo "uuid support $uuid" echo "vhost-net support $vhost_net" echo "Trace backend $trace_backend" echo "Trace output file $trace_file-" +echo "Guest trace file $guest_trace_file" echo "spice support $spice" echo "rbd support $rbd" echo "xfsctl support $xfs" @@ -3076,6 +3081,7 @@ if test "$trace_backend" = "dtrace" -a "$trace_backend_stap" = "yes" ; then echo "CONFIG_SYSTEMTAP_TRACE=y" >> $config_host_mak fi echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak +echo "CONFIG_GUEST_TRACE_FILE=$guest_trace_file" >> $config_host_mak echo "TOOLS=$tools" >> $config_host_mak echo "ROMS=$roms" >> $config_host_mak diff --git a/hw/fw_cfg.c b/hw/fw_cfg.c index 663ad80..e96a68e 100644 --- a/hw/fw_cfg.c +++ b/hw/fw_cfg.c @@ -27,6 +27,7 @@ #include "fw_cfg.h" #include "sysbus.h" #include "qemu-error.h" +#include "guest-trace.h" /* debug firmware config */ //#define DEBUG_FW_CFG @@ -55,6 +56,9 @@ struct FWCfgState { uint16_t cur_entry; uint32_t cur_offset; Notifier machine_ready; + int guest_trace_buf_index; +#define GUEST_TRACE_BUF_SIZE (sizeof(uint64_t) * 7) + uint8_t guest_trace_buf[GUEST_TRACE_BUF_SIZE]; }; #define JPG_FILE 0 @@ -318,6 +322,7 @@ static void fw_cfg_reset(DeviceState *d) FWCfgState *s = DO_UPCAST(FWCfgState, busdev.qdev, d); fw_cfg_select(s, 0); + s->guest_trace_buf_index = 0; } /* Save restore 32 bit int as uint16_t @@ -476,6 +481,27 @@ static void fw_cfg_machine_ready(struct Notifier *n, void *data) fw_cfg_add_file(s, "bootorder", (uint8_t*)bootindex, len); } +static void fw_cfg_guest_trace(void *opaque, uint8_t *data) +{ +#ifdef CONFIG_GUEST_TRACE_FILE + FWCfgState *s = opaque; + + guest_trace(le64_to_cpu(*(uint64_t *)&s->guest_trace_buf[0]), + le64_to_cpu(*(uint64_t *)&s->guest_trace_buf[1]), + le64_to_cpu(*(uint64_t *)&s->guest_trace_buf[2]), + le64_to_cpu(*(uint64_t *)&s->guest_trace_buf[3]), + le64_to_cpu(*(uint64_t *)&s->guest_trace_buf[4]), + le64_to_cpu(*(uint64_t *)&s->guest_trace_buf[5]), + le64_to_cpu(*(uint64_t *)&s->guest_trace_buf[6])); +#endif +} + +static void fw_cfg_guest_trace_init(FWCfgState *s, uint16_t key) +{ + fw_cfg_add_callback(s, key, fw_cfg_guest_trace, s, + s->guest_trace_buf, sizeof(s->guest_trace_buf)); +} + FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port, target_phys_addr_t ctl_addr, target_phys_addr_t data_addr) { @@ -503,6 +529,7 @@ FWCfgState *fw_cfg_init(uint32_t ctl_port, uint32_t data_port, fw_cfg_add_i16(s, FW_CFG_NB_CPUS, (uint16_t)smp_cpus); fw_cfg_add_i16(s, FW_CFG_MAX_CPUS, (uint16_t)max_cpus); fw_cfg_add_i16(s, FW_CFG_BOOT_MENU, (uint16_t)boot_menu); + fw_cfg_guest_trace_init(s, FW_CFG_GUEST_TRACE); fw_cfg_bootsplash(s); s->machine_ready.notify = fw_cfg_machine_ready; diff --git a/hw/fw_cfg.h b/hw/fw_cfg.h index 856bf91..77cd48d 100644 --- a/hw/fw_cfg.h +++ b/hw/fw_cfg.h @@ -33,6 +33,8 @@ #define FW_CFG_MAX_ENTRY (FW_CFG_FILE_FIRST+FW_CFG_FILE_SLOTS) #define FW_CFG_WRITE_CHANNEL 0x4000 +#define FW_CFG_GUEST_TRACE (FW_CFG_WRITE_CHANNEL + 0) + #define FW_CFG_ARCH_LOCAL 0x8000 #define FW_CFG_ENTRY_MASK ~(FW_CFG_WRITE_CHANNEL | FW_CFG_ARCH_LOCAL) diff --git a/scripts/tracetool b/scripts/tracetool index 2155a57..78e7897 100755 --- a/scripts/tracetool +++ b/scripts/tracetool @@ -13,7 +13,7 @@ set -f usage() { cat >&2 <