23 #include "pedigree/kernel/Atomic.h" 24 #include "pedigree/kernel/Spinlock.h" 25 #include "pedigree/kernel/compiler.h" 26 #include "pedigree/kernel/machine/TimerHandler.h" 27 #include "pedigree/kernel/processor/state_forward.h" 28 #include "pedigree/kernel/processor/types.h" 29 #include "pedigree/kernel/utilities/BloomFilter.h" 30 #include "pedigree/kernel/utilities/CacheConstants.h" 31 #include "pedigree/kernel/utilities/List.h" 32 #include "pedigree/kernel/utilities/MemoryAllocator.h" 33 #include "pedigree/kernel/utilities/RequestQueue.h" 34 #include "pedigree/kernel/utilities/Tree.h" 35 #include "pedigree/kernel/utilities/new" 42 #define CACHE_AGE_THRESHOLD 10 46 #define CACHE_NUM_THRESHOLD 2 49 #define CACHE_WRITEBACK_PERIOD 500 56 #ifndef STANDALONE_CACHE 72 void registerCache(
Cache *pCache);
73 void unregisterCache(
Cache *pCache);
80 virtual void timer(uint64_t delta, InterruptState &state);
92 uint64_t p1, uint64_t p2, uint64_t p3, uint64_t p4, uint64_t p5,
93 uint64_t p6, uint64_t p7, uint64_t p8);
103 return (a.p2 == b.p2) && (a.p3 == b.p3);
134 uint64_t checksum[2];
160 bool checkChecksum(uint64_t other[2])
const;
163 bool checkZeroChecksum()
const;
177 typedef void (*writeback_t)(
178 CacheConstants::CallbackCause cause, uintptr_t loc, uintptr_t page,
181 Cache(
size_t pageConstraints = 0);
185 void setCallback(writeback_t newCallback,
void *meta);
188 uintptr_t lookup(uintptr_t key);
200 uintptr_t insert(uintptr_t key,
bool *alreadyExisted =
nullptr);
211 insert(uintptr_t key,
size_t size,
bool *alreadyExisted =
nullptr);
214 bool exists(uintptr_t key,
size_t length);
222 bool evict(uintptr_t key);
232 void release(uintptr_t key);
246 bool pin(uintptr_t key);
259 size_t trim(
size_t count = 1);
265 void sync(uintptr_t key,
bool async);
272 void triggerChecksum(uintptr_t key);
305 void markEditing(uintptr_t key,
size_t length = 0);
310 void markNoLongerEditing(uintptr_t key,
size_t length = 0);
314 bool map(uintptr_t virt)
const;
319 bool evict(uintptr_t key,
bool bLock,
bool bPhysicalLock,
bool bRemove);
327 size_t lruEvict(
bool force =
false);
349 void calculateChecksum(
CachePage *pPage);
354 bool verifyChecksum(
CachePage *pPage,
bool replace =
false);
359 void checksum(
const void *data,
size_t len, uint64_t out[2]);
363 CacheConstants::CallbackCause cause;
364 writeback_t callback;
379 virtual void timer(uint64_t delta, InterruptState &state);
385 uint64_t p1, uint64_t p2, uint64_t p3, uint64_t p4, uint64_t p5,
386 uint64_t p6, uint64_t p7, uint64_t p8);
427 #ifdef STANDALONE_CACHE 429 static void discover_range(uintptr_t &start, uintptr_t &end);
447 uintptr_t m_Location;
uintptr_t key
Key for this page.
BloomFilter< uintptr_t > m_PageFilter
static Spinlock m_AllocatorLock
uintptr_t location
The location of this page in memory.
bool checksumChanging
Marker to check that a page's contents are in flux.
bool trimAll(size_t count=1)
virtual bool compareRequests(const Request &a, const Request &b)
virtual void timer(uint64_t delta, InterruptState &state)
virtual uint64_t executeRequest(uint64_t p1, uint64_t p2, uint64_t p3, uint64_t p4, uint64_t p5, uint64_t p6, uint64_t p7, uint64_t p8)
Status
Current page status.
static MemoryAllocator m_Allocator
CachePage * pNext
Linked list components for LRU.
Tree< uintptr_t, CachePage * > m_Pages
Atomic< size_t > m_bInCritical