[Spice-devel] [PATCH qxl-wddm-dod 1/8] Compute automatically memory space in FreeMem

Frediano Ziglio fziglio at redhat.com
Mon Apr 10 15:30:56 UTC 2017


This make easier to change allocation of memory using different
memory Bars.

Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 qxldod/QxlDod.cpp | 43 +++++++++++++++++++++++--------------------
 qxldod/QxlDod.h   |  2 +-
 2 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/qxldod/QxlDod.cpp b/qxldod/QxlDod.cpp
index b06b410..86d7f98 100755
--- a/qxldod/QxlDod.cpp
+++ b/qxldod/QxlDod.cpp
@@ -4032,7 +4032,7 @@ UINT64 QxlDevice::ReleaseOutput(UINT64 output_id)
         RELEASE_RES(*now);
     }
     next = *(UINT64*)output->data;
-    FreeMem(MSPACE_TYPE_VRAM, output);
+    FreeMem(output);
     DbgPrint(TRACE_LEVEL_VERBOSE, ("<---%s\n", __FUNCTION__));
     return next;
 }
@@ -4086,24 +4086,27 @@ void *QxlDevice::AllocMem(UINT32 mspace_type, size_t size, BOOL force)
     return ptr;
 }
 
-void QxlDevice::FreeMem(UINT32 mspace_type, void *ptr)
+void QxlDevice::FreeMem(void *ptr)
 {
     PAGED_CODE();
-    ASSERT(m_MSInfo[mspace_type]._mspace);
     DbgPrint(TRACE_LEVEL_VERBOSE, ("---> %s\n", __FUNCTION__));
 
-#ifdef DBG
-    if (!((UINT8 *)ptr >= m_MSInfo[mspace_type].mspace_start &&
-                 (UINT8 *)ptr < m_MSInfo[mspace_type].mspace_end)) {
-        DbgPrint(TRACE_LEVEL_ERROR, ("ASSERT failed @ %s, %p not in [%p, %p) (%d)\n", __FUNCTION__,
-            ptr, m_MSInfo[mspace_type].mspace_start,
-            m_MSInfo[mspace_type].mspace_end, mspace_type));
+    for (const MspaceInfo *info = m_MSInfo; ; ++info)
+    {
+        if (info == m_MSInfo + _countof(m_MSInfo))
+        {
+            DbgPrint(TRACE_LEVEL_ERROR, ("ASSERT failed @ %s, %p not in device memory\n",
+                                        __FUNCTION__, ptr));
+            break;
+        }
+        if (info->_mspace && ptr >= info->mspace_start && ptr < info->mspace_end)
+        {
+            BOOLEAN locked = WaitForObject(&m_MemLock, NULL);
+            mspace_free(info->_mspace, ptr);
+            ReleaseMutex(&m_MemLock, locked);
+            break;
+        }
     }
-#endif
-    BOOLEAN locked = FALSE;
-    locked = WaitForObject(&m_MemLock, NULL);
-    mspace_free(m_MSInfo[mspace_type]._mspace, ptr);
-    ReleaseMutex(&m_MemLock, locked);
     DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__));
 }
 
@@ -4209,9 +4212,9 @@ void QxlDevice::FreeClipRects(Resource *res)
     while (chunk_phys) {
         QXLDataChunk *chunk = (QXLDataChunk *)VA(chunk_phys, m_SurfaceMemSlot);
         chunk_phys = chunk->next_chunk;
-        FreeMem(MSPACE_TYPE_VRAM, chunk);
+        FreeMem(chunk);
     }
-    FreeMem(MSPACE_TYPE_VRAM, res);
+    FreeMem(res);
     DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__));
 }
 
@@ -4236,10 +4239,10 @@ void QxlDevice::FreeBitmapImage(Resource *res)
     while (chunk_phys) {
         QXLDataChunk *chunk = (QXLDataChunk *)VA(chunk_phys, m_SurfaceMemSlot);
         chunk_phys = chunk->next_chunk;
-        FreeMem(MSPACE_TYPE_VRAM, chunk);
+        FreeMem(chunk);
     }
 
-    FreeMem(MSPACE_TYPE_VRAM, res);
+    FreeMem(res);
     DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__));
 }
 
@@ -4261,10 +4264,10 @@ void QxlDevice::FreeCursor(Resource *res)
     while (chunk_phys) {
         QXLDataChunk *chunk = (QXLDataChunk *)VA(chunk_phys, m_SurfaceMemSlot);
         chunk_phys = chunk->next_chunk;
-        FreeMem(MSPACE_TYPE_VRAM, chunk);
+        FreeMem(chunk);
     }
 
-    FreeMem(MSPACE_TYPE_VRAM, res);
+    FreeMem(res);
     DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__));
 }
 
diff --git a/qxldod/QxlDod.h b/qxldod/QxlDod.h
index a1e9634..1868069 100755
--- a/qxldod/QxlDod.h
+++ b/qxldod/QxlDod.h
@@ -583,7 +583,7 @@ private:
     void InitMonitorConfig();
     void InitMspace(UINT32 mspace_type, UINT8 *start, size_t capacity);
     void FlushReleaseRing();
-    void FreeMem(UINT32 mspace_type, void *ptr);
+    void FreeMem(void *ptr);
     UINT64 ReleaseOutput(UINT64 output_id);
     void WaitForReleaseRing(void);
     void EmptyReleaseRing(void);
-- 
2.9.3



More information about the Spice-devel mailing list