The Pedigree Project 0.1
Classes | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
TimerHandlerRegistry Class Reference

#include <TimerHandlerRegistry.h>

+ Collaboration diagram for TimerHandlerRegistry:

Classes

struct  ActiveDispatch
 
struct  DispatchCleanup
 
struct  HandlerSlot
 

Public Member Functions

bool registerHandler (TimerHandler *handler)
 
bool unregisterHandler (TimerHandler *handler)
 
bool dispatch (uint64_t delta, TimerHandler *onlyHandler=nullptr)
 
void reset ()
 

Private Types

enum class  SlotMode : size_t {
  Empty = 0 , Enabled , Draining , Deferred ,
  Retiring
}
 

Private Member Functions

bool retireSlot (HandlerSlot &slot, size_t expectedPublication, TimerHandler *expectedHandler)
 
ActiveDispatchpublishDispatch (HandlerSlot &slot, void *owner, void *token)
 
bool unpublishDispatch (void *token, HandlerSlot &slot, size_t admittedPublication, bool required)
 
bool hasActiveDispatch (HandlerSlot &slot) const
 
bool findCurrentDispatch (void *owner, HandlerSlot *target, bool &callbackContext) const
 

Static Private Member Functions

static size_t makePublication (size_t generation, SlotMode mode, bool selfRemoval=false, bool synchronousDrain=false)
 
static size_t generationOf (size_t publication)
 
static SlotMode modeOf (size_t publication)
 
static bool selfRemovalOf (size_t publication)
 
static bool synchronousDrainOf (size_t publication)
 
static void abandonDispatch (void *context)
 
static void * currentDispatchOwner ()
 

Private Attributes

HandlerSlot m_Handlers [MaxHandlerSlots]
 
ActiveDispatch m_ActiveDispatches [MaxActiveDispatches]
 
WaitQueue m_DispatchWaiters
 
Spinlock m_HandlerLock
 

Static Private Attributes

static constexpr size_t MaxHandlerSlots = 32
 
static constexpr size_t MaxActiveDispatches = 64
 
static constexpr size_t ModeBits = 3
 
static constexpr size_t ModeMask = (1 << ModeBits) - 1
 
static constexpr size_t SelfRemovalBit = 1 << ModeBits
 
static constexpr size_t SynchronousDrainBit = 1 << (ModeBits + 1)
 
static constexpr size_t GenerationShift = ModeBits + 2
 

Detailed Description

Allocation-free timer callback registry with synchronous removal.

Dispatch pins atomically published slots without taking the writer lock. Removal closes admission before draining callbacks which committed a pin.

Definition at line 26 of file TimerHandlerRegistry.h.

Member Enumeration Documentation

◆ SlotMode

enum class TimerHandlerRegistry::SlotMode : size_t
strongprivate

Definition at line 69 of file TimerHandlerRegistry.h.

Constructor & Destructor Documentation

◆ TimerHandlerRegistry()

TimerHandlerRegistry::TimerHandlerRegistry ( )

Definition at line 18 of file TimerHandlerRegistry.cc.

Member Function Documentation

◆ abandonDispatch()

void TimerHandlerRegistry::abandonDispatch ( void *  context)
staticprivate

Definition at line 187 of file TimerHandlerRegistry.cc.

◆ currentDispatchOwner()

void * TimerHandlerRegistry::currentDispatchOwner ( )
staticprivate

Definition at line 237 of file TimerHandlerRegistry.cc.

◆ dispatch()

bool TimerHandlerRegistry::dispatch ( uint64_t  delta,
TimerHandler onlyHandler = nullptr 
)

Calls each handler admitted by the current publication.

Definition at line 468 of file TimerHandlerRegistry.cc.

References ProcessorBase::information(), and TimerHandler::timer().

Referenced by Rtc::processElapsedTime(), and HostedTimer::processTimerBatch().

+ Here is the caller graph for this function:

◆ findCurrentDispatch()

bool TimerHandlerRegistry::findCurrentDispatch ( void *  owner,
HandlerSlot target,
bool &  callbackContext 
) const
private

Definition at line 210 of file TimerHandlerRegistry.cc.

◆ generationOf()

size_t TimerHandlerRegistry::generationOf ( size_t  publication)
staticprivate

Definition at line 39 of file TimerHandlerRegistry.cc.

◆ hasActiveDispatch()

bool TimerHandlerRegistry::hasActiveDispatch ( HandlerSlot slot) const
private

Definition at line 192 of file TimerHandlerRegistry.cc.

◆ makePublication()

size_t TimerHandlerRegistry::makePublication ( size_t  generation,
SlotMode  mode,
bool  selfRemoval = false,
bool  synchronousDrain = false 
)
staticprivate

Definition at line 33 of file TimerHandlerRegistry.cc.

◆ modeOf()

TimerHandlerRegistry::SlotMode TimerHandlerRegistry::modeOf ( size_t  publication)
staticprivate

Definition at line 43 of file TimerHandlerRegistry.cc.

◆ publishDispatch()

TimerHandlerRegistry::ActiveDispatch * TimerHandlerRegistry::publishDispatch ( HandlerSlot slot,
void *  owner,
void *  token 
)
private

Definition at line 72 of file TimerHandlerRegistry.cc.

◆ registerHandler()

bool TimerHandlerRegistry::registerHandler ( TimerHandler handler)

Definition at line 243 of file TimerHandlerRegistry.cc.

◆ reset()

void TimerHandlerRegistry::reset ( )

Clears quiescent registry state during timer lifecycle transitions.

Definition at line 540 of file TimerHandlerRegistry.cc.

Referenced by HostedTimer::initialise1(), Rtc::initialise1(), HostedTimer::uninitialise(), and Rtc::uninitialise().

+ Here is the caller graph for this function:

◆ retireSlot()

bool TimerHandlerRegistry::retireSlot ( HandlerSlot slot,
size_t  expectedPublication,
TimerHandler expectedHandler 
)
private

Definition at line 55 of file TimerHandlerRegistry.cc.

◆ selfRemovalOf()

bool TimerHandlerRegistry::selfRemovalOf ( size_t  publication)
staticprivate

Definition at line 47 of file TimerHandlerRegistry.cc.

◆ synchronousDrainOf()

bool TimerHandlerRegistry::synchronousDrainOf ( size_t  publication)
staticprivate

Definition at line 51 of file TimerHandlerRegistry.cc.

◆ unpublishDispatch()

bool TimerHandlerRegistry::unpublishDispatch ( void *  token,
HandlerSlot slot,
size_t  admittedPublication,
bool  required 
)
private

Definition at line 104 of file TimerHandlerRegistry.cc.

◆ unregisterHandler()

bool TimerHandlerRegistry::unregisterHandler ( TimerHandler handler)

Stops future callbacks and drains callbacks already in progress.

Self-removal is deferred until the callback returns and reports false, preserving Timer's synchronous boolean contract. Other atomic callers report false instead of waiting for an in-flight callback. A synchronous caller must not retain a resource which the active handler needs to finish.

Definition at line 297 of file TimerHandlerRegistry.cc.

References Spinlock::acquire(), ProcessorBase::getInterrupts(), ProcessorBase::information(), ProcessorBase::pause(), and Spinlock::release().

Member Data Documentation

◆ GenerationShift

constexpr size_t TimerHandlerRegistry::GenerationShift = ModeBits + 2
staticconstexprprivate

Definition at line 81 of file TimerHandlerRegistry.h.

◆ m_ActiveDispatches

ActiveDispatch TimerHandlerRegistry::m_ActiveDispatches[MaxActiveDispatches]
private

Definition at line 133 of file TimerHandlerRegistry.h.

◆ m_DispatchWaiters

WaitQueue TimerHandlerRegistry::m_DispatchWaiters
private

Definition at line 134 of file TimerHandlerRegistry.h.

◆ m_HandlerLock

Spinlock TimerHandlerRegistry::m_HandlerLock
private

Definition at line 135 of file TimerHandlerRegistry.h.

◆ m_Handlers

HandlerSlot TimerHandlerRegistry::m_Handlers[MaxHandlerSlots]
private

Definition at line 132 of file TimerHandlerRegistry.h.

◆ MaxActiveDispatches

constexpr size_t TimerHandlerRegistry::MaxActiveDispatches = 64
staticconstexprprivate

Definition at line 67 of file TimerHandlerRegistry.h.

◆ MaxHandlerSlots

constexpr size_t TimerHandlerRegistry::MaxHandlerSlots = 32
staticconstexprprivate

Definition at line 66 of file TimerHandlerRegistry.h.

◆ ModeBits

constexpr size_t TimerHandlerRegistry::ModeBits = 3
staticconstexprprivate

Definition at line 77 of file TimerHandlerRegistry.h.

◆ ModeMask

constexpr size_t TimerHandlerRegistry::ModeMask = (1 << ModeBits) - 1
staticconstexprprivate

Definition at line 78 of file TimerHandlerRegistry.h.

◆ SelfRemovalBit

constexpr size_t TimerHandlerRegistry::SelfRemovalBit = 1 << ModeBits
staticconstexprprivate

Definition at line 79 of file TimerHandlerRegistry.h.

◆ SynchronousDrainBit

constexpr size_t TimerHandlerRegistry::SynchronousDrainBit = 1 << (ModeBits + 1)
staticconstexprprivate

Definition at line 80 of file TimerHandlerRegistry.h.


The documentation for this class was generated from the following files: