On 9/11/22 00:13, John Johnson wrote:
cache VFIO_DEVICE_GET_REGION_INFO results to reduce
memory alloc/free cycles and as prep work for vfio-user

Signed-off-by: John G Johnson <john.g.john...@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimts...@oracle.com>
Signed-off-by: Jagannathan Raman <jag.ra...@oracle.com>
---
  hw/vfio/ccw.c                 |  5 -----
  hw/vfio/common.c              | 41 +++++++++++++++++++++++++++++++++++------
  hw/vfio/igd.c                 | 23 +++++++++--------------
  hw/vfio/migration.c           |  2 --
  hw/vfio/pci-quirks.c          | 19 +++++--------------
  hw/vfio/pci.c                 |  8 --------
  include/hw/vfio/vfio-common.h |  2 ++
  7 files changed, 51 insertions(+), 49 deletions(-)


  void vfio_put_base_device(VFIODevice *vbasedev)
  {
+    if (vbasedev->regions != NULL) {
+        int i;
+
+        for (i = 0; i < vbasedev->num_regions; i++) {
+            g_free(vbasedev->regions[i]);
+        }
+        g_free(vbasedev->regions);
+        vbasedev->regions = NULL;
+    }
+
      if (!vbasedev->group) {
          return;
      }
@@ -2432,6 +2451,17 @@ int vfio_get_region_info(VFIODevice *vbasedev, int index,
  {
      size_t argsz = sizeof(struct vfio_region_info);
+ /* create region cache */
+    if (vbasedev->regions == NULL) {
+        vbasedev->regions = g_new0(struct vfio_region_info *,
+                                   vbasedev->num_regions);
+    }
+    /* check cache */
+    if (vbasedev->regions[index] != NULL) {
+        *info = vbasedev->regions[index];
+        return 0;
+    }

What about simply allocating/releasing once regions[] in
vfio_instance_init / vfio_instance_finalize?

Reply via email to