replace spinlocks with mutex

This commit is contained in:
Vadim Rozenfeld 2014-06-12 23:34:25 +10:00
parent e04e2d683e
commit c43d7065b6
2 changed files with 43 additions and 44 deletions

View File

@ -2318,7 +2318,7 @@ NTSTATUS VgaDevice::GetModeList(DXGK_DISPLAY_INFORMATION* pDispInfo)
DbgPrint(TRACE_LEVEL_ERROR, ("x86BiosAllocateBuffer failed with Status: 0x%X\n", Status));
return Status;
}
DbgPrint(TRACE_LEVEL_ERROR, ("x86BiosAllocateBuffer 0x%x (%x.%x)\n", VbeInfo.VideoModePtr, m_Segment, m_Offset));
DbgPrint(TRACE_LEVEL_INFORMATION, ("x86BiosAllocateBuffer 0x%x (%x.%x)\n", VbeInfo.VideoModePtr, m_Segment, m_Offset));
Status = x86BiosWriteMemory (m_Segment, m_Offset, "VBE2", 4);
@ -2351,9 +2351,9 @@ NTSTATUS VgaDevice::GetModeList(DXGK_DISPLAY_INFORMATION* pDispInfo)
return STATUS_UNSUCCESSFUL;
}
DbgPrint(TRACE_LEVEL_ERROR, ("VBE BIOS Present (%d.%d, %8ld Kb)\n", VbeInfo.Version / 0x100, VbeInfo.Version & 0xFF, VbeInfo.TotalMemory * 64));
DbgPrint(TRACE_LEVEL_ERROR, ("Capabilities = 0x%x\n", VbeInfo.Capabilities));
DbgPrint(TRACE_LEVEL_ERROR, ("VideoModePtr = 0x%x (0x%x.0x%x)\n", VbeInfo.VideoModePtr, HIWORD( VbeInfo.VideoModePtr), LOWORD( VbeInfo.VideoModePtr)));
DbgPrint(TRACE_LEVEL_INFORMATION, ("VBE BIOS Present (%d.%d, %8ld Kb)\n", VbeInfo.Version / 0x100, VbeInfo.Version & 0xFF, VbeInfo.TotalMemory * 64));
DbgPrint(TRACE_LEVEL_INFORMATION, ("Capabilities = 0x%x\n", VbeInfo.Capabilities));
DbgPrint(TRACE_LEVEL_INFORMATION, ("VideoModePtr = 0x%x (0x%x.0x%x)\n", VbeInfo.VideoModePtr, HIWORD( VbeInfo.VideoModePtr), LOWORD( VbeInfo.VideoModePtr)));
for (ModeCount = 0; ; ModeCount++)
{
@ -2376,12 +2376,12 @@ NTSTATUS VgaDevice::GetModeList(DXGK_DISPLAY_INFORMATION* pDispInfo)
}
}
DbgPrint(TRACE_LEVEL_ERROR, ("ModeCount %d\n", ModeCount));
DbgPrint(TRACE_LEVEL_INFORMATION, ("ModeCount %d\n", ModeCount));
m_ModeInfo = reinterpret_cast<PVIDEO_MODE_INFORMATION> (new (PagedPool) BYTE[sizeof (VIDEO_MODE_INFORMATION) * ModeCount]);
m_ModeNumbers = reinterpret_cast<PUSHORT> (new (PagedPool) BYTE [sizeof (USHORT) * ModeCount]);
m_CurrentMode = 0;
DbgPrint(TRACE_LEVEL_ERROR, ("m_ModeInfo = 0x%p, m_ModeNumbers = 0x%p\n", m_ModeInfo, m_ModeNumbers));
DbgPrint(TRACE_LEVEL_INFORMATION, ("m_ModeInfo = 0x%p, m_ModeNumbers = 0x%p\n", m_ModeInfo, m_ModeNumbers));
for (CurrentMode = 0, SuitableModeCount = 0;
CurrentMode < ModeCount;
CurrentMode++)
@ -2398,7 +2398,7 @@ NTSTATUS VgaDevice::GetModeList(DXGK_DISPLAY_INFORMATION* pDispInfo)
break;
}
DbgPrint(TRACE_LEVEL_ERROR, ("ModeTemp = 0x%X\n", ModeTemp));
DbgPrint(TRACE_LEVEL_INFORMATION, ("ModeTemp = 0x%X\n", ModeTemp));
RtlZeroMemory(&regs, sizeof(regs));
regs.Eax = 0x4F01;
regs.Ecx = ModeTemp;
@ -2442,7 +2442,7 @@ NTSTATUS VgaDevice::GetModeList(DXGK_DISPLAY_INFORMATION* pDispInfo)
}
m_ModeCount = SuitableModeCount;
DbgPrint(TRACE_LEVEL_ERROR, ("ModeCount filtered %d\n", m_ModeCount));
DbgPrint(TRACE_LEVEL_INFORMATION, ("ModeCount filtered %d\n", m_ModeCount));
for (ULONG idx = 0; idx < m_ModeCount; idx++)
{
DbgPrint(TRACE_LEVEL_ERROR, ("type %x, XRes = %d, YRes = %d, BPP = %d\n",
@ -3268,7 +3268,8 @@ BOOL QxlDevice::CreateEvents()
KeInitializeEvent(&m_IoCmdEvent,
SynchronizationEvent,
FALSE);
KeInitializeSpinLock(&m_MemLock);
KeInitializeMutex(&m_MemLock,1);
KeInitializeMutex(&m_CmdLock,1);
DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__));
return TRUE;
@ -3540,32 +3541,6 @@ QxlDevice::ExecutePresentDisplayOnly(
return STATUS_SUCCESS;
}
static inline
KIRQL
AcquireSpinLock(PVOID pSpinLock)
{
KIRQL IRQL;
IRQL = KeGetCurrentIrql();
if (DISPATCH_LEVEL == IRQL)
KeAcquireSpinLockAtDpcLevel((KSPIN_LOCK *)pSpinLock);
else
KeAcquireSpinLock((KSPIN_LOCK *)pSpinLock, &IRQL);
return IRQL;
}
static inline
VOID
ReleaseSpinLock(PVOID pSpinLock, KIRQL IRQL)
{
if (DISPATCH_LEVEL == IRQL)
KeReleaseSpinLockFromDpcLevel((KSPIN_LOCK *)pSpinLock);
else
KeReleaseSpinLock((KSPIN_LOCK *)pSpinLock, IRQL);
}
void QxlDevice::WaitForReleaseRing(void)
{
int wait;
@ -3652,7 +3627,6 @@ UINT64 QxlDevice::ReleaseOutput(UINT64 output_id)
void *QxlDevice::AllocMem(UINT32 mspace_type, size_t size, BOOL force)
{
PVOID ptr;
KIRQL old_irql;
ASSERT(m_MSInfo[mspace_type]._mspace);
DbgPrint(TRACE_LEVEL_VERBOSE, ("--->%s: %p(%d) size %u\n", __FUNCTION__,
@ -3663,14 +3637,21 @@ void *QxlDevice::AllocMem(UINT32 mspace_type, size_t size, BOOL force)
mspace_malloc_stats(m_MSInfo[mspace_type]._mspace);
#endif
KeWaitForSingleObject
(
&m_MemLock,
Executive,
KernelMode,
FALSE,
NULL
);
while (1) {
/* Release lots of queued resources, before allocating, as we
want to release early to minimize fragmentation risks. */
FlushReleaseRing();
old_irql = AcquireSpinLock(&m_MemLock);
ptr = mspace_malloc(m_MSInfo[mspace_type]._mspace, size);
ReleaseSpinLock(&m_MemLock, old_irql);
if (ptr) {
break;
}
@ -3689,6 +3670,7 @@ void *QxlDevice::AllocMem(UINT32 mspace_type, size_t size, BOOL force)
break;
}
}
KeReleaseMutex(&m_MemLock,FALSE);
ASSERT((!ptr && !force) || (ptr >= m_MSInfo[mspace_type].mspace_start &&
ptr < m_MSInfo[mspace_type].mspace_end));
@ -3698,7 +3680,6 @@ void *QxlDevice::AllocMem(UINT32 mspace_type, size_t size, BOOL force)
void QxlDevice::FreeMem(UINT32 mspace_type, void *ptr)
{
KIRQL old_irql;
ASSERT(m_MSInfo[mspace_type]._mspace);
DbgPrint(TRACE_LEVEL_VERBOSE, ("---> %s\n", __FUNCTION__));
@ -3710,9 +3691,16 @@ void QxlDevice::FreeMem(UINT32 mspace_type, void *ptr)
m_MSInfo[mspace_type].mspace_end, mspace_type));
}
#endif
old_irql = AcquireSpinLock(&m_MemLock);
KeWaitForSingleObject
(
&m_MemLock,
Executive,
KernelMode,
FALSE,
NULL
);
mspace_free(m_MSInfo[mspace_type]._mspace, ptr);
ReleaseSpinLock(&m_MemLock, old_irql);
KeReleaseMutex(&m_MemLock,FALSE);
DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__));
}
@ -3851,11 +3839,20 @@ void QxlDevice::PushDrawable(QXLDrawable *drawable) {
QXLCommand *cmd;
DbgPrint(TRACE_LEVEL_VERBOSE, ("---> %s\n", __FUNCTION__));
KeWaitForSingleObject
(
&m_CmdLock,
Executive,
KernelMode,
FALSE,
NULL
);
WaitForCmdRing();
cmd = SPICE_RING_PROD_ITEM(m_CommandRing);
cmd->type = QXL_CMD_DRAW;
cmd->data = PA(drawable, m_MainMemSlot);
PushCmd();
KeReleaseMutex(&m_CmdLock,FALSE);
DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__));
}
@ -4094,7 +4091,7 @@ VOID QxlDevice::DpcRoutine(PVOID ptr)
{
PDXGKRNL_INTERFACE pDxgkInterface = (PDXGKRNL_INTERFACE)ptr;
DbgPrint(TRACE_LEVEL_FATAL, ("---> %s\n", __FUNCTION__));
DbgPrint(TRACE_LEVEL_INFORMATION, ("---> %s\n", __FUNCTION__));
DPC_CB_CONTEXT ctx;
BOOLEAN dummy;
ctx.ptr = this;
@ -4121,7 +4118,7 @@ VOID QxlDevice::DpcRoutine(PVOID ptr)
m_RamHdr->int_mask = QXL_INTERRUPT_MASK;
WRITE_PORT_UCHAR((PUCHAR)(m_IoBase + QXL_IO_UPDATE_IRQ), 0);
DbgPrint(TRACE_LEVEL_VERBOSE, ("<--- %s\n", __FUNCTION__));
DbgPrint(TRACE_LEVEL_INFORMATION, ("<--- %s\n", __FUNCTION__));
}
VOID QxlDevice::UpdateArea(RECTL *area, UINT32 surface_id)

View File

@ -523,7 +523,9 @@ private:
PUCHAR m_LogPort;
PUCHAR m_LogBuf;
KSPIN_LOCK m_MemLock;
KMUTEX m_MemLock;
KMUTEX m_CmdLock;
MspaceInfo m_MSInfo[NUM_MSPACES];
UINT64 m_FreeOutputs;