qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v1 04/24] vfio-user: add region cache


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH v1 04/24] vfio-user: add region cache
Date: Mon, 12 Dec 2022 12:42:51 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.5.1

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.johnson@oracle.com>
Signed-off-by: Elena Ufimtseva <elena.ufimtseva@oracle.com>
Signed-off-by: Jagannathan Raman <jag.raman@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

[Prev in Thread] Current Thread [Next in Thread]