From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44776) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgz4a-0005PW-26 for qemu-devel@nongnu.org; Mon, 05 Sep 2016 14:56:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bgz4X-0008OT-HB for qemu-devel@nongnu.org; Mon, 05 Sep 2016 14:56:47 -0400 Received: from roura.ac.upc.edu ([147.83.33.10]:57350 helo=roura.ac.upc.es) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgz4X-0008OP-46 for qemu-devel@nongnu.org; Mon, 05 Sep 2016 14:56:45 -0400 From: =?utf-8?b?TGx1w61z?= Vilanova Date: Mon, 5 Sep 2016 20:56:44 +0200 Message-Id: <147310180392.10840.12864372901014347462.stgit@fimbulvetr.bsc.es> In-Reply-To: <147310178240.10840.14758930096407696981.stgit@fimbulvetr.bsc.es> References: <147310178240.10840.14758930096407696981.stgit@fimbulvetr.bsc.es> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2 4/6] hypertrace: [softmmu] Add QEMU-side proxy to "guest_hypertrace" event List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Daniel P Berrange , Luiz Capitulino , Eric Blake , Stefan Hajnoczi , "Michael S. Tsirkin" , Marcel Apfelbaum Uses a virtual device to trigger the hypertrace channel event. Signed-off-by: Llu=C3=ADs Vilanova --- hypertrace/Makefile.objs | 5 + hypertrace/softmmu.c | 235 ++++++++++++++++++++++++++++++++++++++++= ++++++ include/hw/pci/pci.h | 2=20 3 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 hypertrace/softmmu.c diff --git a/hypertrace/Makefile.objs b/hypertrace/Makefile.objs index 24e8fb4..0025207 100644 --- a/hypertrace/Makefile.objs +++ b/hypertrace/Makefile.objs @@ -1,9 +1,12 @@ # -*- mode: makefile -*- =20 target-obj-$(CONFIG_USER_ONLY) +=3D user.o +ifdef CONFIG_PCI +target-obj-$(CONFIG_SOFTMMU) +=3D softmmu.o +endif target-obj-y +=3D common.o =20 -$(obj)/user.o: $(obj)/emit.c +$(obj)/user.o $(obj)/softmmu.o: $(obj)/emit.c =20 $(obj)/emit.c: $(obj)/emit.c-timestamp $(BUILD_DIR)/config-host.mak @cmp $< $@ >/dev/null 2>&1 || cp $< $@ diff --git a/hypertrace/softmmu.c b/hypertrace/softmmu.c new file mode 100644 index 0000000..ca4d1ad --- /dev/null +++ b/hypertrace/softmmu.c @@ -0,0 +1,235 @@ +/* + * QEMU-side management of hypertrace in softmmu emulation. + * + * Copyright (C) 2016 Llu=C3=ADs Vilanova + * + * This work is licensed under the terms of the GNU GPL, version 2 or la= ter. + * See the COPYING file in the top-level directory. + */ + +/* + * Implementation details + * =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + * + * There are 3 channels, each a BAR of a virtual device that can be used= through + * MMIO. + * + * + * - Configuration channel: Exposes configuration parameters. + * + * - Data channel: Lets guests write argument values. Each guest client = should + * use a different offset to avoid concurrency problems. + * + * - Control channel: Triggers the hypertrace event on a write, providin= g the + * first argument. Offset in the control channel sets the offset in th= e data + * channel. + */ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "exec/ram_addr.h" +#include "hypertrace/common.h" +#include "hw/pci/pci.h" +#include "migration/migration.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "trace.h" + + +#define PAGE_SIZE TARGET_PAGE_SIZE + + +typedef struct HypertraceState +{ + PCIDevice dev; + + uint64_t max_clients; + struct hypertrace_config hconfig; + + MemoryRegion config; + void *config_ptr; + MemoryRegion data; + void *data_ptr; + MemoryRegion control; + void *control_ptr; + + Error *migration_blocker; +} HypertraceState; + + +static uint64_t hypertrace_control_io_read(void *opaque, hwaddr addr, + unsigned size) +{ + uint64_t res; + HypertraceState *s =3D opaque; + char *mem =3D &((char*)s->control_ptr)[addr]; + + switch (size) { + case 1: + { + res =3D ((uint8_t*)mem)[0]; + break; + } + case 2: + { + res =3D ((uint16_t*)mem)[0]; + break; + } + case 4: + { + res =3D ((uint32_t*)mem)[0]; + break; + } + case 8: + { + res =3D ((uint64_t*)mem)[0]; + break; + } + default: + error_report("error: hypertrace: Unexpected read of size %d\n", = size); + } + + return res; +} + +#include "hypertrace/emit.c" + +static void hypertrace_control_io_write(void *opaque, hwaddr addr, + uint64_t data, unsigned size) +{ + HypertraceState *s =3D opaque; + char *mem =3D &((char*)s->control_ptr)[addr]; + + switch (size) { + case 1: + { + uint8_t *res =3D (uint8_t*)mem; + *res =3D (uint8_t)data; + break; + } + case 2: + { + uint16_t *res =3D (uint16_t*)mem; + *res =3D (uint16_t)data; + break; + } + case 4: + { + uint32_t *res =3D (uint32_t*)mem; + *res =3D (uint32_t)data; + break; + } + case 8: + { + uint64_t *res =3D (uint64_t*)mem; + *res =3D (uint64_t)data; + break; + } + default: + error_report("error: hypertrace: Unexpected write of size %d\n",= size); + } + + if ((addr + size) % sizeof(uint64_t) =3D=3D 0) { + uint64_t client =3D addr / sizeof(uint64_t); + uint64_t vcontrol =3D ((uint64_t*)s->control_ptr)[client]; + uint64_t *data_ptr =3D (uint64_t*)s->data_ptr; + data_ptr =3D &data_ptr[client * s->hconfig.client_data_size]; + hypertrace_emit(current_cpu, vcontrol, data_ptr); + } +} + +static const MemoryRegionOps hypertrace_control_ops =3D { + .read =3D &hypertrace_control_io_read, + .write =3D &hypertrace_control_io_write, + .endianness =3D DEVICE_NATIVE_ENDIAN, + .impl =3D { + .min_access_size =3D 1, + .max_access_size =3D 8, + }, +}; + + +static void hypertrace_realize(PCIDevice *dev, Error **errp) +{ + struct hypertrace_config *config; + HypertraceState *s =3D DO_UPCAST(HypertraceState, dev, dev); + Error *err =3D NULL; + + if (s->max_clients < 1) { + error_setg(errp, "hypertrace: must have at least one client\n"); + return; + } + + hypertrace_init_config(&s->hconfig, s->max_clients); + + error_setg(&s->migration_blocker, "The 'hypertrace' device cannot be= migrated"); + migrate_add_blocker(s->migration_blocker); + + pci_set_word(s->dev.config + PCI_COMMAND, + PCI_COMMAND_IO | PCI_COMMAND_MEMORY); + + /* config channel */ + memory_region_init_ram(&s->config, OBJECT(s), "hypertrace.config", + TARGET_PAGE_SIZE, &err); + if (err) { + error_propagate(errp, err); + return; + } + pci_register_bar(&s->dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->conf= ig); + s->config_ptr =3D qemu_map_ram_ptr(s->config.ram_block, 0); + config =3D s->config_ptr; + config->max_clients =3D tswap64(s->hconfig.max_clients); + config->client_args =3D tswap64(s->hconfig.client_args); + config->client_data_size =3D tswap64(s->hconfig.client_data_size); + config->control_size =3D tswap64(s->hconfig.control_size); + config->data_size =3D tswap64(s->hconfig.data_size); + + /* data channel */ + memory_region_init_ram(&s->data, OBJECT(s), "hypertrace.data", + s->hconfig.data_size, &err); + if (err) { + error_propagate(errp, err); + return; + } + pci_register_bar(&s->dev, 1, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->data= ); + s->data_ptr =3D qemu_map_ram_ptr(s->data.ram_block, 0); + + /* control channel */ + memory_region_init_io(&s->control, OBJECT(s), &hypertrace_control_op= s, s, + "hypertrace.control", s->hconfig.control_size)= ; + pci_register_bar(&s->dev, 2, PCI_BASE_ADDRESS_SPACE_MEMORY, &s->cont= rol); + s->control_ptr =3D qemu_map_ram_ptr(s->control.ram_block, 0); +} + + +static Property hypertrace_properties[] =3D { + DEFINE_PROP_UINT64("max-clients", HypertraceState, max_clients, 1), + DEFINE_PROP_END_OF_LIST(), +}; + +static void hypertrace_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + PCIDeviceClass *k =3D PCI_DEVICE_CLASS(klass); + + k->realize =3D hypertrace_realize; + k->vendor_id =3D PCI_VENDOR_ID_REDHAT_QUMRANET; + k->device_id =3D PCI_DEVICE_ID_HYPERTRACE; + k->class_id =3D PCI_CLASS_MEMORY_RAM; + dc->desc =3D "Hypertrace communication channel", + dc->props =3D hypertrace_properties; +} + +static TypeInfo hypertrace_info =3D { + .name =3D "hypertrace", + .parent =3D TYPE_PCI_DEVICE, + .instance_size =3D sizeof(HypertraceState), + .class_init =3D hypertrace_class_init, +}; + +static void hypertrace_register_types(void) +{ + type_register_static(&hypertrace_info); +} + +type_init(hypertrace_register_types) diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 929ec2f..8973f57 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -80,6 +80,8 @@ #define PCI_DEVICE_ID_VIRTIO_RNG 0x1005 #define PCI_DEVICE_ID_VIRTIO_9P 0x1009 =20 +#define PCI_DEVICE_ID_HYPERTRACE 0x10f0 + #define PCI_VENDOR_ID_REDHAT 0x1b36 #define PCI_DEVICE_ID_REDHAT_BRIDGE 0x0001 #define PCI_DEVICE_ID_REDHAT_SERIAL 0x0002