From: John Hodge Date: Sat, 27 Jul 2013 15:32:52 +0000 (+0800) Subject: Kernel/x86 - Removed busy wait in MM_MapTemp X-Git-Tag: rel0.15~316 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=9edb6f7c288a93d9f9ce3f7233b577a601471071;p=tpg%2Facess2.git Kernel/x86 - Removed busy wait in MM_MapTemp --- diff --git a/KernelLand/Kernel/arch/x86/mm_virt.c b/KernelLand/Kernel/arch/x86/mm_virt.c index 216bc1e6..b81698c3 100644 --- a/KernelLand/Kernel/arch/x86/mm_virt.c +++ b/KernelLand/Kernel/arch/x86/mm_virt.c @@ -17,6 +17,7 @@ #include #include #include +#include #define TAB 22 @@ -97,6 +98,7 @@ tPAddr MM_DuplicatePage(tVAddr VAddr); #define gaPAE_TmpPDPT ((tTabEnt*)PAE_TMP_PDPT_ADDR) int gbUsePAE = 0; tMutex glTempMappings; +tSemaphore gTempMappingsSem; tMutex glTempFractal; Uint32 gWorkerStacks[(NUM_WORKER_STACKS+31)/32]; int giLastUsedWorker = 0; @@ -117,6 +119,8 @@ void MM_PreinitVirtual(void) { gaInitPageDir[ PAGE_TABLE_ADDR >> 22 ] = ((tTabEnt)&gaInitPageDir - KERNEL_BASE) | 3; INVLPG( PAGE_TABLE_ADDR ); + + Semaphore_Init(&gTempMappingsSem, NUM_TEMP_PAGES, NUM_TEMP_PAGES, "MMVirt", "Temp Mappings"); } /** @@ -980,32 +984,29 @@ tPAddr MM_DuplicatePage(tVAddr VAddr) */ void * MM_MapTemp(tPAddr PAddr) { - int i; - //ENTER("XPAddr", PAddr); PAddr &= ~0xFFF; //LOG("glTempMappings = %i", glTempMappings); - for(;;) + if( Semaphore_Wait(&gTempMappingsSem, 1) != 1 ) + return NULL; + Mutex_Acquire( &glTempMappings ); + for( int i = 0; i < NUM_TEMP_PAGES; i ++ ) { - Mutex_Acquire( &glTempMappings ); - - for( i = 0; i < NUM_TEMP_PAGES; i ++ ) - { - // Check if page used - if(gaPageTable[ (TEMP_MAP_ADDR >> 12) + i ] & 1) continue; - // Mark as used - gaPageTable[ (TEMP_MAP_ADDR >> 12) + i ] = PAddr | 3; - INVLPG( TEMP_MAP_ADDR + (i << 12) ); - //LEAVE('p', TEMP_MAP_ADDR + (i << 12)); - Mutex_Release( &glTempMappings ); - return (void*)( TEMP_MAP_ADDR + (i << 12) ); - } + // Check if page used + if(gaPageTable[ (TEMP_MAP_ADDR >> 12) + i ] & 1) continue; + // Mark as used + gaPageTable[ (TEMP_MAP_ADDR >> 12) + i ] = PAddr | 3; + INVLPG( TEMP_MAP_ADDR + (i << 12) ); + //LEAVE('p', TEMP_MAP_ADDR + (i << 12)); Mutex_Release( &glTempMappings ); - Threads_Yield(); // TODO: Use a sleep queue here instead + return (void*)( TEMP_MAP_ADDR + (i << 12) ); } + Mutex_Release( &glTempMappings ); + Log_KernelPanic("MMVirt", "Semaphore suplied a mapping, but none are avaliable"); + return NULL; } /** @@ -1017,8 +1018,10 @@ void MM_FreeTemp(void *VAddr) int i = (tVAddr)VAddr >> 12; //ENTER("xVAddr", VAddr); - if(i >= (TEMP_MAP_ADDR >> 12)) + if(i >= (TEMP_MAP_ADDR >> 12)) { gaPageTable[ i ] = 0; + Semaphore_Signal(&gTempMappingsSem, 1); + } //LEAVE('-'); }