Implement the ioeventfd_assign_begin() and ioeventfd_assign_commit()
handlers of VirtioBusClass. Basically track that a transaction was
already requested by the device and use this information to prevent
the memory code to generate a transaction for each individual eventfd.
Devices that want to benefit of this batching feature must be converted
to use the virtio_bus_set_host_notifiers() API.
Signed-off-by: Greg Kurz
---
hw/virtio/virtio-pci.h | 1 +
hw/virtio/virtio-pci.c | 53 +-
softmmu/memory.c | 4 ++--
3 files changed, 40 insertions(+), 18 deletions(-)
diff --git a/hw/virtio/virtio-pci.h b/hw/virtio/virtio-pci.h
index d7d5d403a948..a1b3f1bc45c9 100644
--- a/hw/virtio/virtio-pci.h
+++ b/hw/virtio/virtio-pci.h
@@ -141,6 +141,7 @@ struct VirtIOPCIProxy {
bool disable_modern;
bool ignore_backend_features;
OnOffAuto disable_legacy;
+bool ioeventfd_assign_started;
uint32_t class_code;
uint32_t nvectors;
uint32_t dfselect;
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 883045a22354..0a8738c69541 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -243,47 +243,66 @@ static int virtio_pci_ioeventfd_assign(DeviceState *d,
EventNotifier *notifier,
hwaddr modern_addr = virtio_pci_queue_mem_mult(proxy) *
virtio_get_queue_index(vq);
hwaddr legacy_addr = VIRTIO_PCI_QUEUE_NOTIFY;
+bool transaction = !proxy->ioeventfd_assign_started;
if (assign) {
if (modern) {
if (fast_mmio) {
-memory_region_add_eventfd(modern_mr, modern_addr, 0,
- false, n, notifier);
+memory_region_add_eventfd_full(modern_mr, modern_addr, 0,
+ false, n, notifier,
transaction);
} else {
-memory_region_add_eventfd(modern_mr, modern_addr, 2,
- false, n, notifier);
+memory_region_add_eventfd_full(modern_mr, modern_addr, 2,
+ false, n, notifier,
transaction);
}
if (modern_pio) {
-memory_region_add_eventfd(modern_notify_mr, 0, 2,
- true, n, notifier);
+memory_region_add_eventfd_full(modern_notify_mr, 0, 2,
+ true, n, notifier, transaction);
}
}
if (legacy) {
-memory_region_add_eventfd(legacy_mr, legacy_addr, 2,
- true, n, notifier);
+memory_region_add_eventfd_full(legacy_mr, legacy_addr, 2,
+ true, n, notifier, transaction);
}
} else {
if (modern) {
if (fast_mmio) {
-memory_region_del_eventfd(modern_mr, modern_addr, 0,
- false, n, notifier);
+memory_region_del_eventfd_full(modern_mr, modern_addr, 0,
+ false, n, notifier,
transaction);
} else {
-memory_region_del_eventfd(modern_mr, modern_addr, 2,
- false, n, notifier);
+memory_region_del_eventfd_full(modern_mr, modern_addr, 2,
+ false, n, notifier,
transaction);
}
if (modern_pio) {
-memory_region_del_eventfd(modern_notify_mr, 0, 2,
- true, n, notifier);
+memory_region_del_eventfd_full(modern_notify_mr, 0, 2,
+ true, n, notifier, transaction);
}
}
if (legacy) {
-memory_region_del_eventfd(legacy_mr, legacy_addr, 2,
- true, n, notifier);
+memory_region_del_eventfd_full(legacy_mr, legacy_addr, 2,
+ true, n, notifier, transaction);
}
}
return 0;
}
+static void virtio_pci_ioeventfd_assign_begin(DeviceState *d)
+{
+VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
+
+assert(!proxy->ioeventfd_assign_started);
+proxy->ioeventfd_assign_started = true;
+memory_region_transaction_begin();
+}
+
+static void virtio_pci_ioeventfd_assign_commit(DeviceState *d)
+{
+VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
+
+assert(proxy->ioeventfd_assign_started);
+memory_region_transaction_commit();
+proxy->ioeventfd_assign_started = false;
+}
+
static void virtio_pci_start_ioeventfd(VirtIOPCIProxy *proxy)
{
virtio_bus_start_ioeventfd(>bus);
@@ -2161,6 +2180,8 @@ static void virtio_pci_bus_class_init(ObjectClass *klass,
void *data)
k->query_nvectors = virtio_pci_query_nvectors;