[Spice-devel] [PATCH 8/8] Add simple cache to speed up surface allocation

alexl at redhat.com alexl at redhat.com
Fri Aug 20 11:54:40 PDT 2010


From: Alexander Larsson <alexl at redhat.com>

We store the lowest id that could possibly be free and start our
search there. This should keep us from a bunch of unnecessary checks.
---
 display/qxldd.h   |    1 +
 display/res.c     |    1 +
 display/surface.h |   12 ++++++++++--
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/display/qxldd.h b/display/qxldd.h
index aa20ef4..ec872ef 100644
--- a/display/qxldd.h
+++ b/display/qxldd.h
@@ -192,6 +192,7 @@ typedef struct DevRes {
     UINT32 num_palettes;
 
     SurfaceInfo *surfaces_info;
+    UINT32 first_free_surface;
     UINT32 *surfaces_used;
 
     HANDLE driver;
diff --git a/display/res.c b/display/res.c
index 4569315..bcb1d76 100644
--- a/display/res.c
+++ b/display/res.c
@@ -407,6 +407,7 @@ static void InitRes(PDev *pdev)
     if (!pdev->Res.surfaces_used) {
         PANIC(pdev, "Res surfaces_used allocation failed\n");
     }
+    pdev->Res.first_free_surface = 1;
 
     pdev->Res.surfaces_info = (SurfaceInfo *)EngAllocMem(FL_ZERO_MEMORY,
 							 sizeof(SurfaceInfo) * pdev->n_surfaces, 
diff --git a/display/surface.h b/display/surface.h
index 2b23272..25dc6b5 100644
--- a/display/surface.h
+++ b/display/surface.h
@@ -38,12 +38,16 @@ static _inline void FreeSurface(PDev *pdev, UINT32 surface_id)
     bitmask = (~0x80000000) >> (surface_id % 32);
 
     pdev->Res.surfaces_used[i] &= bitmask;
-}
 
+    if (surface_id != 0 &&
+        surface_id < pdev->Res.first_free_surface) {
+        pdev->Res.first_free_surface = surface_id;
+    }
+}
 
 static UINT32 GetFreeSurface(PDev *pdev)
 {
-    UINT32 start = 1;
+    UINT32 start = pdev->Res.first_free_surface;
     UINT32 bit;
     UINT32 i, end_i;
     UINT32 bitmask;
@@ -79,6 +83,10 @@ static UINT32 GetFreeSurface(PDev *pdev)
         res = 0;
     }
 
+    if (res != 0) {
+        pdev->Res.first_free_surface = res + 1;
+    }
+
     return res;
 }
 
-- 
1.7.2.1



More information about the Spice-devel mailing list