From 8920cf3559c034c947c2dd63892c9dd25453d245 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 22 May 2007 20:18:13 -0700 Subject: [PATCH] Add subroutines to add/remove blocks from the expiry chain Add subroutines to add/remove blocks from the expiry chain. This allows a user to remove a block from expiration and thus hold on to the buffer for some time. --- cache.inc | 69 +++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 15 deletions(-) diff --git a/cache.inc b/cache.inc index 0d9d453..1f514e2 100644 --- a/cache.inc +++ b/cache.inc @@ -13,9 +13,9 @@ section .text struc cptr -.sector: resd 1 ; Sector number -.prev: resw 1 ; LRU pointer to previous (less recent) -.next: resw 1 ; LRU pointer to next (more recent) +.sector: resd 1 ; Sector number +.prev: resw 1 ; LRU pointer to previous (less recent) +.next: resw 1 ; LRU pointer to next (more recent) endstruc cptr_size_lg2 equ 3 @@ -39,6 +39,52 @@ initcache: ret ; +; cache_remove_lru: +; Remove a cache block from the expiry list. Can be used to +; lock down a cache block for future use. +; +; SI = cache block offset (any offset inside the block is OK) +; Assumes CS == DS +; +cache_remove_lru: + pusha + + ; Get metadata pointer + shr si,SECTOR_SHIFT-cptr_size_lg2 + add si,CachePtrs+cptr_size + + mov bx,[si+cptr.prev] + mov di,[si+cptr.next] + mov [bx+cptr.next],di + mov [di+cptr.prev],bx + + popa + ret + +; +; cache_add_lru: +; Add back a cache block to the expiry chain that was removed. +; +; SI = cache block offset (any offset inside the block is OK) +; Assumes CS == DS +; +cache_add_lru: + pusha + + ; Get metadata pointer + shr si,SECTOR_SHIFT-cptr_size_lg2 + add si,CachePtrs+cptr_size + + mov bx,[CachePtrs+cptr.prev] + mov [si+cptr.prev],bx + mov [bx+cptr.next],si + mov [CachePtrs+cptr.prev],si + mov word [si+cptr.next],CachePtrs + + popa + ret + +; ; getcachesector: Check for a particular sector (EAX) in the sector cache, ; and if it is already there, return a pointer in GS:SI ; otherwise load it and return said pointer. @@ -82,21 +128,14 @@ getcachesector: ; Update LRU, then compute buffer address TRACER 'H' + sub si,CachePtrs+cptr_size + shl si,SECTOR_SHIFT-cptr_size_lg2 ; Buffer address + ; Remove from current position in the list - mov bx,[si+cptr.prev] - mov di,[si+cptr.next] - mov [bx+cptr.next],di - mov [di+cptr.prev],bx + call cache_remove_lru ; Add to just before head node - mov bx,[CachePtrs+cptr.prev] - mov [si+cptr.prev],bx - mov [bx+cptr.next],si - mov [CachePtrs+cptr.prev],si - mov word [si+cptr.next],CachePtrs - - sub si,CachePtrs+cptr_size - shl si,SECTOR_SHIFT-cptr_size_lg2 ; Buffer address + call cache_add_lru pop di pop bx -- 2.7.4