|
The Pedigree Project 0.1
|
#include <Cache.h>
Inheritance diagram for CacheManager:
Collaboration diagram for CacheManager:Classes | |
| struct | CacheRequest |
| struct | TimerStamp |
Public Member Functions | |
| void | initialise () |
| MUST_USE_RESULT bool | shutdown () |
| void | registerCache (Cache *pCache) |
| void | unregisterCache (Cache *pCache) |
| bool | trimAll (size_t count=1) |
| virtual void | timer (uint64_t delta) |
| void | trimThread () |
Public Member Functions inherited from RequestQueue | |
| RequestQueue (const String &name) | |
| virtual void | destroy () |
| MUST_USE_RESULT uint64_t | addRequest (size_t priority, uint64_t p1=0, uint64_t p2=0, uint64_t p3=0, uint64_t p4=0, uint64_t p5=0, uint64_t p6=0, uint64_t p7=0, uint64_t p8=0) |
| MUST_USE_RESULT uint64_t | addRequest (size_t priority, ActionOnDuplicate action, uint64_t p1=0, uint64_t p2=0, uint64_t p3=0, uint64_t p4=0, uint64_t p5=0, uint64_t p6=0, uint64_t p7=0, uint64_t p8=0) |
| uint64_t | addAsyncRequest (size_t priority, uint64_t p1=0, uint64_t p2=0, uint64_t p3=0, uint64_t p4=0, uint64_t p5=0, uint64_t p6=0, uint64_t p7=0, uint64_t p8=0) |
| bool | canWaitForCompletion () |
| MUST_USE_RESULT bool | waitForPreallocated (PreallocatedRequest &request) |
| MUST_USE_RESULT PreallocatedPublishResult | publishPreallocated (PreallocatedRequest &request, size_t priority, uint64_t p1=0, uint64_t p2=0, uint64_t p3=0, uint64_t p4=0, uint64_t p5=0, uint64_t p6=0, uint64_t p7=0, uint64_t p8=0) |
| MUST_USE_RESULT PreallocatedPublishResult | republishPreallocatedWhileReleasing (PreallocatedRequest &request, size_t priority, uint64_t p1=0, uint64_t p2=0, uint64_t p3=0, uint64_t p4=0, uint64_t p5=0, uint64_t p6=0, uint64_t p7=0, uint64_t p8=0) |
| MUST_USE_RESULT bool | halt () |
| MUST_USE_RESULT bool | resume () |
| LifecycleState | getLifecycleState () |
| bool | drain () |
Static Public Member Functions | |
| static CacheManager & | instance () |
| static void | destroyInstance () |
Private Member Functions | |
| void | stopPeriodicWork () |
| void | timerTick (uint64_t delta, bool memoryPressure) |
| bool | findNextCache (uint64_t afterId, uint64_t maximumId, Cache *&cache, uint64_t &cacheId, bool timersOnly=false) |
| bool | takeTimerStamp (TimerStamp &stamp) |
| void | dispatchTimer (Cache *cache, const TimerStamp &stamp) |
| bool | callbackContext () const |
| bool | acquireCache (Cache *cache, uint64_t &generation, OperationBarrier::Lease &lease) |
| bool | acquireNextCache (uint64_t afterId, uint64_t maximumId, Cache *&cache, uint64_t &cacheId, OperationBarrier::Lease &lease, bool timersOnly=false) |
| uint64_t | cacheGenerationWatermark () |
| uint64_t | addCacheRequest (Cache *cache, bool asynchronous, CacheConstants::CallbackCause cause, uintptr_t key, uintptr_t location=0, bool transferredPin=false, bool onlyIfDirty=false, bool batch=false) |
| 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) |
| virtual void | cancelRequest (const Request &request) |
| virtual bool | compareRequests (const Request &a, const Request &b) |
Private Attributes | |
| Tree< uint64_t, Cache * > | m_Caches |
| uint64_t | m_NextCacheId |
| TimerStamp | m_TimerClock |
| uint64_t | m_TrimDelta |
| Mutex | m_CachesLock |
| Thread * | m_pTrimThread |
| WaitQueue | m_TrimWaiters |
| bool | m_bTrimRequested |
| bool | m_bActive |
| Timer * | m_pTimer |
| Atomic< size_t > | m_TerminalState |
Static Private Attributes | |
| static CacheManager * | m_Instance = nullptr |
Friends | |
| class | Cache |
| class | CacheManagerTestPeer |
Additional Inherited Members | |
Public Types inherited from RequestQueue | |
| enum class | OverrunStatus { Clear , Armed , Stalled , Overloaded } |
| enum class | PreallocatedPublishResult { Accepted , TokenBusy , QueueStopped , QueueFull , InvalidPriority } |
| enum | ActionOnDuplicate { Block , NewRequest , ReturnImmediately } |
| enum class | LifecycleState { Stopped , Accepting , Stopping , Destroyed } |
Protected Types inherited from RequestQueue | |
| enum class | NextRequestResult { Item , Empty , Retry } |
Protected Member Functions inherited from RequestQueue | |
| virtual bool | workerPlacement (ThreadPlacement &) const |
| RequestQueue (const RequestQueue &) | |
| void | operator= (const RequestQueue &) |
| int | work () |
| NextRequestResult | getNextRequest (Request *&request) |
| bool | drainIntakeLocked (size_t priority) |
| void | publishRequest (Request *request) |
| Request * | findDuplicate (const Request &request) |
| void | discardRequest (Request *request) |
| uint64_t | addAsyncRequestInternal (size_t priority, uint64_t p1, uint64_t p2, uint64_t p3, uint64_t p4, uint64_t p5, uint64_t p6, uint64_t p7, uint64_t p8) |
| PreallocatedPublishResult | publishPreallocatedRequest (PreallocatedRequest &request, PreallocatedRequest::State availableState, size_t priority, uint64_t p1, uint64_t p2, uint64_t p3, uint64_t p4, uint64_t p5, uint64_t p6, uint64_t p7, uint64_t p8) |
| void | releasePreallocatedRequest (Request *request) |
| void | invokeCancelRequest (const Request &request) |
| bool | callbackActiveOnCurrentThread () const |
| void | releaseRequest (Request *request) |
| uint64_t | waitForRequest (Request *request) |
| bool | startWorker () |
| bool | stopWorker () |
| void | closePreallocatedAdmission () |
| void | waitForPreallocatedPublishers () |
Static Protected Member Functions inherited from RequestQueue | |
| static int | trampoline (void *p) |
| static void | completeRequest (Request *request, uint64_t returnValue, bool rejected) |
| static void | retainRequest (Request *request) |
Protected Attributes inherited from RequestQueue | |
| IntakeLane | m_IntakeLanes [REQUEST_QUEUE_NUM_PRIORITIES] |
| Request * | m_pRequestQueue [REQUEST_QUEUE_NUM_PRIORITIES] |
| Request * | m_pRequestQueueTail [REQUEST_QUEUE_NUM_PRIORITIES] |
| Request * | m_pActiveRequest |
| Atomic< size_t > | m_State |
| Mutex | m_LifecycleMutex |
| WaitQueue | m_RequestQueueWaiters |
| WaitQueue | m_WorkerWaiters |
| Thread * | m_pThread |
| Atomic< PerProcessorScheduler * > | m_pWorkerScheduler |
| SchedulerWorkerWake | m_WorkerWake |
| Atomic< size_t > | m_bWorkerReady |
| Atomic< size_t > | m_bWorkerActive |
| size_t | m_WorkerProgressGeneration |
| RequestQueueOverrunChecker | m_OverrunChecker |
| Timer * | m_pOverrunTimer |
| Atomic< size_t > | m_PublicationState |
| size_t | m_nMaxAsyncRequests |
| Atomic< size_t > | m_nAsyncRequests |
| Atomic< size_t > | m_nTotalRequests |
| Atomic< size_t > | m_nActiveRequests |
| NormalStaticString | m_Name |
Static Protected Attributes inherited from RequestQueue | |
| static constexpr size_t | PublicationClosed = static_cast<size_t>(1) << ((sizeof(size_t) * 8) - 1) |
| static constexpr size_t | PublicationCountMask = ~PublicationClosed |
|
private |
Pins a registered Cache while a request is being published.
Definition at line 382 of file Cache.cc.
References Tree< K, E >::begin(), Tree< K, E >::end(), and m_CachesLock.
Referenced by addCacheRequest().
Here is the caller graph for this function:
|
private |
Finds and pins the first registered cache after a stable manager ID.
Definition at line 400 of file Cache.cc.
References findNextCache(), and m_CachesLock.
Referenced by shutdown(), and trimAll().
Here is the caller graph for this function:
|
private |
Publishes a request which owns the target Cache lifetime.
Definition at line 421 of file Cache.cc.
References acquireCache(), RequestQueue::addAsyncRequest(), RequestQueue::addRequest(), RequestQueue::callbackActiveOnCurrentThread(), Mutex::isOwnedByCurrentThread(), RequestQueue::m_LifecycleMutex, and m_TerminalState.
Referenced by Cache::release(), Cache::sync(), and Cache::timer().
Here is the caller graph for this function:
|
private |
Captures the last identity present at the start of a manager scan.
Definition at line 415 of file Cache.cc.
References m_CachesLock, and m_NextCacheId.
Referenced by shutdown(), and trimAll().
Here is the caller graph for this function:
|
privatevirtual |
Releases payload ownership for a request that will not execute.
This runs without the queue guard for rejected candidates (including stopped queues, duplicates and capacity limits) and queued requests cancelled by destroy(). Implementations used by allocation-free producers must not sleep. Derived destructors must call destroy() while their override and member state are still alive. During destroy(), the lifecycle is serialized: halt() and resume() on this queue return false, while recursive destroy() is a fatal contract violation.
Reimplemented from RequestQueue.
|
inlineprivatevirtual |
Used to ensure we only ever fire a WriteBack for the same page once - that is, we don't constantly write back the same page over and over while it's still queued.
Reimplemented from RequestQueue.
|
private |
|
privatevirtual |
RequestQueue doer - children give us new jobs, and we call out to them when they hit the front of the queue.
Implements RequestQueue.
Definition at line 480 of file Cache.cc.
References Tree< K, E >::begin(), Tree< K, E >::end(), and Cache::executeRequest().
|
private |
Registry lock must be held in threaded builds.
Definition at line 367 of file Cache.cc.
References Tree< K, E >::lowerBound().
Referenced by acquireNextCache(), shutdown(), and trimAll().
Here is the caller graph for this function:
|
virtual |
Initialises the queue, spawning the worker thread.
Reimplemented from RequestQueue.
Definition at line 192 of file Cache.cc.
References Process::getParent(), Machine::getTimer(), ProcessorBase::information(), RequestQueue::initialise(), and m_bActive.
|
inlinestatic |
| bool CacheManager::shutdown | ( | ) |
Stops background work and flushes dirty pages for terminal system shutdown. External cache users must already be quiesced; backend callbacks must remain usable. Retained owners and their page loans keep their storage and registry alive. This does not relax the ordinary destructor's empty-registry contract.
Definition at line 126 of file Cache.cc.
References acquireNextCache(), cacheGenerationWatermark(), Tree< K, E >::count(), RequestQueue::destroy(), findNextCache(), m_CachesLock, m_NextCacheId, and m_TerminalState.
|
private |
|
virtual |
Called when the handler is registered with the Timer class and a timer event occurred.
| [in] | delta | time elapsed since the last event, in nanoseconds. |
Implements TimerHandler.
Definition at line 292 of file Cache.cc.
References PhysicalMemoryManager::freePageCount(), PhysicalMemoryManager::instance(), and m_TerminalState.
|
private |
| bool CacheManager::trimAll | ( | size_t | count = 1 | ) |
Trim each cache we know about until 'count' pages have been evicted.
Definition at line 256 of file Cache.cc.
References acquireNextCache(), cacheGenerationWatermark(), findNextCache(), m_NextCacheId, and m_TerminalState.
|
friend |
|
private |
Protected by m_TrimWaiters when threading is enabled.
Definition at line 199 of file Cache.h.
Referenced by initialise().
|
private |
Serialises cache registration with callback admission.
Definition at line 191 of file Cache.h.
Referenced by acquireCache(), acquireNextCache(), cacheGenerationWatermark(), and shutdown().
|
staticprivate |
|
private |
Monotonic identity used to walk caches without retaining iterators.
Definition at line 185 of file Cache.h.
Referenced by cacheGenerationWatermark(), shutdown(), and trimAll().
|
private |
0 running, 1 terminal drain, 2 completed, 3 writeback failure.
Definition at line 203 of file Cache.h.
Referenced by addCacheRequest(), shutdown(), timer(), and trimAll().
|
private |