qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@redhat.com>
To: qemu-devel@nongnu.org, Alex Williamson <alex.williamson@redhat.com>
Cc: "Avihai Horon" <avihaih@nvidia.com>,
	"Eric Auger" <eric.auger@redhat.com>,
	"Zhenzhong Duan" <zhenzhong.duan@intel.com>,
	"John Levon" <john.levon@nutanix.com>,
	"Joao Martins" <joao.m.martins@oracle.com>,
	"Cédric Le Goater" <clg@redhat.com>,
	"Kirti Wankhede" <kwankhede@nvidia.com>,
	"Prasad Pandit" <pjp@fedoraproject.org>
Subject: [PATCH v3 03/37] vfio: Introduce a new header file for external migration services
Date: Tue, 22 Apr 2025 18:01:50 +0200	[thread overview]
Message-ID: <20250422160224.199714-4-clg@redhat.com> (raw)
In-Reply-To: <20250422160224.199714-1-clg@redhat.com>

The migration core subsystem makes use of the VFIO migration API to
collect statistics on the number of bytes transferred. These services
are declared in "hw/vfio/vfio-common.h" which also contains VFIO
internal declarations. Move the migration declarations into a new
header file "hw/vfio/vfio-migration.h" to reduce the exposure of VFIO
internals.

While at it, use a 'vfio_migration_' prefix for these services.

To be noted, vfio_migration_add_bytes_transferred() is a VFIO
migration internal service which we will be moved in the subsequent
patches.

Cc: Kirti Wankhede <kwankhede@nvidia.com>
Cc: Avihai Horon <avihaih@nvidia.com>
Reviewed-by: Prasad Pandit <pjp@fedoraproject.org>
Reviewed-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Avihai Horon <avihaih@nvidia.com>
Link: https://lore.kernel.org/qemu-devel/20250326075122.1299361-4-clg@redhat.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
 include/hw/vfio/vfio-common.h    |  5 +----
 include/hw/vfio/vfio-migration.h | 16 ++++++++++++++++
 hw/vfio/migration-multifd.c      |  5 +++--
 hw/vfio/migration.c              | 11 ++++++-----
 migration/target.c               |  8 ++++----
 5 files changed, 30 insertions(+), 15 deletions(-)
 create mode 100644 include/hw/vfio/vfio-migration.h

diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 9cfb3fb6931e71395ef1d67b0a743d8bc1433fdc..fd424a4a3d40132e940f457f9250458e50ea0b71 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -290,13 +290,10 @@ extern VFIODeviceList vfio_device_list;
 extern const MemoryListener vfio_memory_listener;
 extern int vfio_kvm_device_fd;
 
-bool vfio_mig_active(void);
 int vfio_block_multiple_devices_migration(VFIODevice *vbasedev, Error **errp);
 void vfio_unblock_multiple_devices_migration(void);
 bool vfio_viommu_preset(VFIODevice *vbasedev);
-int64_t vfio_mig_bytes_transferred(void);
-void vfio_mig_reset_bytes_transferred(void);
-void vfio_mig_add_bytes_transferred(unsigned long val);
+void vfio_migration_add_bytes_transferred(unsigned long val);
 bool vfio_device_state_is_running(VFIODevice *vbasedev);
 bool vfio_device_state_is_precopy(VFIODevice *vbasedev);
 
diff --git a/include/hw/vfio/vfio-migration.h b/include/hw/vfio/vfio-migration.h
new file mode 100644
index 0000000000000000000000000000000000000000..0d4ecd33d5d8c214bb77e0652b4405b6e43bcafa
--- /dev/null
+++ b/include/hw/vfio/vfio-migration.h
@@ -0,0 +1,16 @@
+/*
+ * VFIO migration interface
+ *
+ * Copyright Red Hat, Inc. 2025
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef HW_VFIO_VFIO_MIGRATION_H
+#define HW_VFIO_VFIO_MIGRATION_H
+
+bool vfio_migration_active(void);
+int64_t vfio_migration_bytes_transferred(void);
+void vfio_migration_reset_bytes_transferred(void);
+
+#endif /* HW_VFIO_VFIO_MIGRATION_H */
diff --git a/hw/vfio/migration-multifd.c b/hw/vfio/migration-multifd.c
index 378f6f3bf01f6a4155fb424f8028cb5380f27f02..09aa57f5f890f37f7e36c857fd813f55b1da2fce 100644
--- a/hw/vfio/migration-multifd.c
+++ b/hw/vfio/migration-multifd.c
@@ -11,6 +11,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-migration.h"
 #include "migration/misc.h"
 #include "qapi/error.h"
 #include "qemu/bswap.h"
@@ -575,7 +576,7 @@ vfio_save_complete_precopy_thread_config_state(VFIODevice *vbasedev,
         return false;
     }
 
-    vfio_mig_add_bytes_transferred(packet_len);
+    vfio_migration_add_bytes_transferred(packet_len);
 
     return true;
 }
@@ -645,7 +646,7 @@ vfio_multifd_save_complete_precopy_thread(SaveLiveCompletePrecopyThreadData *d,
             goto thread_exit;
         }
 
-        vfio_mig_add_bytes_transferred(packet_size);
+        vfio_migration_add_bytes_transferred(packet_size);
     }
 
     if (!vfio_save_complete_precopy_thread_config_state(vbasedev,
diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
index 8bf65b8e11094b8363692dba3084b762362c7dd6..582d65932a6c590eaecd8bf0b765f27d93896c72 100644
--- a/hw/vfio/migration.c
+++ b/hw/vfio/migration.c
@@ -17,6 +17,7 @@
 
 #include "system/runstate.h"
 #include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-migration.h"
 #include "migration/misc.h"
 #include "migration/savevm.h"
 #include "migration/vmstate.h"
@@ -373,7 +374,7 @@ static ssize_t vfio_save_block(QEMUFile *f, VFIOMigration *migration)
     qemu_put_be64(f, VFIO_MIG_FLAG_DEV_DATA_STATE);
     qemu_put_be64(f, data_size);
     qemu_put_buffer(f, migration->data_buffer, data_size);
-    vfio_mig_add_bytes_transferred(data_size);
+    vfio_migration_add_bytes_transferred(data_size);
 
     trace_vfio_save_block(migration->vbasedev->name, data_size);
 
@@ -1047,22 +1048,22 @@ static int vfio_block_migration(VFIODevice *vbasedev, Error *err, Error **errp)
 
 /* ---------------------------------------------------------------------- */
 
-int64_t vfio_mig_bytes_transferred(void)
+int64_t vfio_migration_bytes_transferred(void)
 {
     return MIN(qatomic_read(&bytes_transferred), INT64_MAX);
 }
 
-void vfio_mig_reset_bytes_transferred(void)
+void vfio_migration_reset_bytes_transferred(void)
 {
     qatomic_set(&bytes_transferred, 0);
 }
 
-void vfio_mig_add_bytes_transferred(unsigned long val)
+void vfio_migration_add_bytes_transferred(unsigned long val)
 {
     qatomic_add(&bytes_transferred, val);
 }
 
-bool vfio_mig_active(void)
+bool vfio_migration_active(void)
 {
     VFIODevice *vbasedev;
 
diff --git a/migration/target.c b/migration/target.c
index f5d8cfe7c2a3473f4bd3f5068145598c60973c58..12fd399f0c521c5c28535b58f24feab6845947fd 100644
--- a/migration/target.c
+++ b/migration/target.c
@@ -11,21 +11,21 @@
 #include CONFIG_DEVICES
 
 #ifdef CONFIG_VFIO
-#include "hw/vfio/vfio-common.h"
+#include "hw/vfio/vfio-migration.h"
 #endif
 
 #ifdef CONFIG_VFIO
 void migration_populate_vfio_info(MigrationInfo *info)
 {
-    if (vfio_mig_active()) {
+    if (vfio_migration_active()) {
         info->vfio = g_malloc0(sizeof(*info->vfio));
-        info->vfio->transferred = vfio_mig_bytes_transferred();
+        info->vfio->transferred = vfio_migration_bytes_transferred();
     }
 }
 
 void migration_reset_vfio_bytes_transferred(void)
 {
-    vfio_mig_reset_bytes_transferred();
+    vfio_migration_reset_bytes_transferred();
 }
 #else
 void migration_populate_vfio_info(MigrationInfo *info)
-- 
2.49.0



  parent reply	other threads:[~2025-04-22 16:04 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-22 16:01 [PATCH v3 00/37] vfio: Spring cleanup Cédric Le Goater
2025-04-22 16:01 ` [PATCH v3 01/37] vfio: Move vfio_mig_active() into migration.c Cédric Le Goater
2025-04-22 16:01 ` [PATCH v3 02/37] vfio: Rename vfio_reset_bytes_transferred() Cédric Le Goater
2025-04-22 16:01 ` Cédric Le Goater [this message]
2025-04-22 16:01 ` [PATCH v3 04/37] vfio: Make vfio_un/block_multiple_devices_migration() static Cédric Le Goater
2025-04-22 16:01 ` [PATCH v3 05/37] vfio: Make vfio_viommu_preset() static Cédric Le Goater
2025-04-22 16:01 ` [PATCH v3 06/37] vfio: Introduce a new header file for internal migration services Cédric Le Goater
2025-04-22 16:01 ` [PATCH v3 07/37] vfio: Move vfio_device_state_is_running/precopy() into migration.c Cédric Le Goater
2025-04-22 16:01 ` [PATCH v3 08/37] vfio: Introduce a new header file for VFIOdisplay declarations Cédric Le Goater
2025-04-22 16:01 ` [PATCH v3 09/37] vfio: Move VFIOHostDMAWindow definition into spapr.c Cédric Le Goater
2025-04-22 16:01 ` [PATCH v3 10/37] vfio: Introduce a new header file for VFIOIOMMUFD declarations Cédric Le Goater
2025-04-22 16:01 ` [PATCH v3 11/37] vfio: Introduce new files for VFIORegion definitions and declarations Cédric Le Goater
2025-04-22 16:01 ` [PATCH v3 12/37] vfio: Introduce a new header file for VFIOcontainer declarations Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 13/37] vfio: Make vfio_group_list static Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 14/37] vfio: Move VFIOAddressSpace helpers into container-base.c Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 15/37] vfio: Move Host IOMMU type declarations into their respective files Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 16/37] vfio: Introduce a new header file for helper services Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 17/37] vfio: Move vfio_get_info_dma_avail() into helpers.c Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 18/37] vfio: Move vfio_kvm_device_add/del_fd() to helpers.c Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 19/37] vfio: Move vfio_get_device_info() " Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 20/37] vfio: Introduce a new file for VFIODevice definitions Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 21/37] vfio: Introduce new files for CPR definitions and declarations Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 22/37] vfio: Move vfio_kvm_device_fd() into helpers.c Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 23/37] vfio: Move vfio_device_list into device.c Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 24/37] vfio: Move vfio_de/attach_device() " Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 25/37] vfio: Move vfio_reset_handler() " Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 26/37] vfio: Move dirty tracking related services into container-base.c Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 27/37] vfio: Make vfio_devices_query_dirty_bitmap() static Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 28/37] vfio: Make vfio_container_query_dirty_bitmap() static Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 29/37] vfio: Rename vfio_devices_all_dirty_tracking_started() Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 30/37] vfio: Rename vfio_devices_all_device_dirty_tracking() Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 31/37] vfio: Rename vfio_get_dirty_bitmap() Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 32/37] vfio: Introduce new files for VFIO MemoryListener Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 33/37] vfio: Rename RAM discard related services Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 34/37] vfio: Introduce vfio_listener_un/register() routines Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 35/37] vfio: Rename vfio-common.h to vfio-device.h Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 36/37] vfio: Rename VFIODevice related services Cédric Le Goater
2025-04-22 16:02 ` [PATCH v3 37/37] vfio: Rename VFIOContainer " Cédric Le Goater
2025-04-22 16:55 ` [PATCH v3 00/37] vfio: Spring cleanup Cédric Le Goater
2025-04-25  7:57 ` Cédric Le Goater

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250422160224.199714-4-clg@redhat.com \
    --to=clg@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=avihaih@nvidia.com \
    --cc=eric.auger@redhat.com \
    --cc=joao.m.martins@oracle.com \
    --cc=john.levon@nutanix.com \
    --cc=kwankhede@nvidia.com \
    --cc=pjp@fedoraproject.org \
    --cc=qemu-devel@nongnu.org \
    --cc=zhenzhong.duan@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).