The Pedigree Project 0.1
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
HostedTimer Class Reference
+ Inheritance diagram for HostedTimer:
+ Collaboration diagram for HostedTimer:

Classes

class  Alarm
 

Public Member Functions

virtual bool registerHandler (TimerHandler *handler)
 
virtual bool unregisterHandler (TimerHandler *handler)
 
virtual void addAlarm (class Event *pEvent, size_t alarmSecs, size_t alarmUsecs=0)
 
virtual void removeAlarm (class Event *pEvent)
 
virtual size_t removeAlarm (class Event *pEvent, bool bRetZero)
 
virtual size_t getYear ()
 
virtual uint8_t getMonth ()
 
virtual uint8_t getDayOfMonth ()
 
virtual uint8_t getDayOfWeek ()
 
virtual uint8_t getHour ()
 
virtual uint8_t getMinute ()
 
virtual uint8_t getSecond ()
 
virtual uint64_t getNanosecond ()
 
virtual uint64_t getTickCount ()
 
virtual uint64_t getTickCountNano ()
 
bool initialise1 () INITIALISATION_ONLY
 
bool initialise3 ()
 
virtual void synchronise (bool tohw=false)
 
void uninitialise ()
 
- Public Member Functions inherited from Timer
virtual uint64_t getTickCountNanoFast ()
 
virtual Time::CpuTimeSample sampleCpuTime ()
 
virtual Time::Timestamp getUnixTimestamp ()
 
virtual bool armHandler (TimerHandler *, uint64_t)
 
virtual bool supportsDeadlines () const
 
virtual void deadlineInterrupt ()
 

Static Public Member Functions

static HostedTimer & instance ()
 

Protected Member Functions

 HostedTimer () INITIALISATION_ONLY
 
virtual ~HostedTimer ()
 
- Protected Member Functions inherited from Timer
 Timer ()
 
virtual ~Timer ()
 

Private Member Functions

 HostedTimer (const HostedTimer &)
 
HostedTimer & operator= (const HostedTimer &)
 
HardStageDisposition hardIrq (irq_id_t number, InterruptState &state, size_t &work) override
 
void threadedIrq (size_t work) override
 
bool quiesceIrqSources () override
 
void rearmIrqSources (size_t work) override
 
void processTimerBatch (uint64_t delta)
 
- Private Member Functions inherited from SplitIrqHandler
 SplitIrqHandler (const String &name)
 
bool initialiseSplitIrq ()
 
irq_id_t registerIsaSplitIrq (IrqManager &manager, uint8_t irq, const IrqPolicy &policy)
 
irq_id_t registerPciSplitIrq (IrqManager &manager, Device &device, const IrqPolicy &policy)
 
bool shutdownSplitIrq ()
 

Private Attributes

size_t m_Year
 
uint8_t m_Month
 
uint8_t m_DayOfMonth
 
uint8_t m_DayOfWeek
 
uint8_t m_Hour
 
uint8_t m_Minute
 
uint8_t m_Second
 
uint64_t m_Nanosecond
 
HostedTickSource m_TickSource
 
irq_id_t m_IrqId
 
IrqEventCounter m_PendingExpirations
 
TimerHandlerRegistry m_HandlerRegistry
 
List< Alarm * > m_Alarms
 
Spinlock m_AlarmLock
 
bool m_bInitialized = false
 
bool m_bPrepared = false
 

Static Private Attributes

static HostedTimer m_Instance
 

Additional Inherited Members

- Private Types inherited from SplitIrqHandler
enum class  HardStageDisposition : size_t { NotHandled , Handled , Deferred }
 

Detailed Description

Definition at line 38 of file kernel/machine/hosted/Timer.h.

Constructor & Destructor Documentation

◆ HostedTimer() [1/2]

HostedTimer::HostedTimer ( )
protected

The default constructor

Definition at line 317 of file hosted/Timer.cc.

◆ ~HostedTimer()

HostedTimer::~HostedTimer ( )
protectedvirtual

The destructor

Definition at line 65 of file hosted/Timer.cc.

References uninitialise().

◆ HostedTimer() [2/2]

HostedTimer::HostedTimer ( const HostedTimer &  )
private

The copy-constructor

Note
NOT implemented

Member Function Documentation

◆ addAlarm()

void HostedTimer::addAlarm ( class Event *  pEvent,
size_t  alarmSecs,
size_t  alarmUsecs = 0 
)
virtual

Dispatches the Event pEvent to the current thread in alarmSecs time.

Parameters
pEventEvent to dispatch.
alarmSecsNumber of seconds to wait.

Implements Timer.

Definition at line 69 of file hosted/Timer.cc.

References getTickCountNano(), ProcessorBase::information(), m_AlarmLock, and m_Alarms.

◆ getDayOfMonth()

uint8_t HostedTimer::getDayOfMonth ( )
virtual

Get the current day of month

Returns
the current day of month

Implements Timer.

Definition at line 180 of file hosted/Timer.cc.

References m_DayOfMonth.

◆ getDayOfWeek()

uint8_t HostedTimer::getDayOfWeek ( )
virtual

Get the current day of week

Returns
the current day of week

Implements Timer.

Definition at line 184 of file hosted/Timer.cc.

References m_DayOfWeek.

◆ getHour()

uint8_t HostedTimer::getHour ( )
virtual

Get the current hour

Returns
the current hour

Implements Timer.

Definition at line 188 of file hosted/Timer.cc.

References m_Hour.

◆ getMinute()

uint8_t HostedTimer::getMinute ( )
virtual

Get the current minute

Returns
the current minute

Implements Timer.

Definition at line 192 of file hosted/Timer.cc.

References m_Minute.

◆ getMonth()

uint8_t HostedTimer::getMonth ( )
virtual

Get the current month

Returns
the current month

Implements Timer.

Definition at line 176 of file hosted/Timer.cc.

References m_Month.

◆ getNanosecond()

uint64_t HostedTimer::getNanosecond ( )
virtual

Get the current nanosecond

Returns
the current nanosecond

Implements Timer.

Definition at line 200 of file hosted/Timer.cc.

References m_Nanosecond.

◆ getSecond()

uint8_t HostedTimer::getSecond ( )
virtual

Get the current second

Returns
the current second

Implements Timer.

Definition at line 196 of file hosted/Timer.cc.

References m_Second.

◆ getTickCount()

uint64_t HostedTimer::getTickCount ( )
virtual

Get the Tick count (time elapsed since system bootup)

Returns
the tick count in milliseconds

Implements Timer.

Definition at line 204 of file hosted/Timer.cc.

References getTickCountNano().

◆ getTickCountNano()

uint64_t HostedTimer::getTickCountNano ( )
virtual

Get the Tick count (time elapsed since system bootup) in nanosconds.

Returns
the tick count in nanoseconds

Reimplemented from Timer.

Definition at line 208 of file hosted/Timer.cc.

Referenced by addAlarm(), getTickCount(), processTimerBatch(), and removeAlarm().

+ Here is the caller graph for this function:

◆ getYear()

size_t HostedTimer::getYear ( )
virtual

Get the current year

Returns
the current year

Implements Timer.

Definition at line 172 of file hosted/Timer.cc.

References m_Year.

◆ hardIrq()

SplitIrqHandler::HardStageDisposition HostedTimer::hardIrq ( irq_id_t  number,
InterruptState &  state,
size_t &  work 
)
overrideprivatevirtual

Runs in hard IRQ context and must be bounded and nonblocking.

Implements SplitIrqHandler.

Definition at line 334 of file hosted/Timer.cc.

References m_PendingExpirations, m_TickSource, and IrqEventCounter::recordFromInterrupt().

◆ initialise1()

bool HostedTimer::initialise1 ( )

Prepares the unarmed POSIX timer

Returns
true, if successfull, false otherwise

Definition at line 214 of file hosted/Timer.cc.

References m_bInitialized, m_bPrepared, m_HandlerRegistry, m_TickSource, TimerHandlerRegistry::reset(), and synchronise().

◆ initialise3()

bool HostedTimer::initialise3 ( )

◆ instance()

static HostedTimer & HostedTimer::instance ( )
inlinestatic

Definition at line 40 of file kernel/machine/hosted/Timer.h.

◆ operator=()

HostedTimer & HostedTimer::operator= ( const HostedTimer &  )
private

The assignment operator

Note
NOT implemented

◆ processTimerBatch()

void HostedTimer::processTimerBatch ( uint64_t  delta)
private

Applies one captured expiration batch in ordinary thread context.

Definition at line 391 of file hosted/Timer.cc.

References Spinlock::acquire(), TimerHandlerRegistry::dispatch(), TargetInfo::getPageSize(), Machine::getSerial(), getTickCountNano(), m_AlarmLock, m_Alarms, m_HandlerRegistry, m_Nanosecond, Spinlock::release(), Thread::sendEvent(), synchronise(), IrqManager::tick(), and UNLIKELY.

Referenced by threadedIrq().

+ Here is the caller graph for this function:

◆ quiesceIrqSources()

bool HostedTimer::quiesceIrqSources ( )
overrideprivatevirtual

Prevents new device interrupts before registry admission is closed. This runs in thread context and must be idempotent across failed retries.

Implements SplitIrqHandler.

Definition at line 382 of file hosted/Timer.cc.

References m_TickSource.

◆ rearmIrqSources()

void HostedTimer::rearmIrqSources ( size_t  work)
overrideprivatevirtual

Rearms drained device sources unless shutdown has begun.

This runs in thread context with interrupts disabled and is serialised against quiesceIrqSources(). It must be bounded and nonblocking.

Implements SplitIrqHandler.

Definition at line 386 of file hosted/Timer.cc.

◆ registerHandler()

bool HostedTimer::registerHandler ( TimerHandler *  handler)
virtual

Implements Timer.

Definition at line 122 of file hosted/Timer.cc.

◆ removeAlarm() [1/2]

void HostedTimer::removeAlarm ( class Event *  pEvent)
virtual

Removes the event pEvent from the alarm queue. Once this returns, the timer will not begin another delivery of this event.

Parameters
pEventEvent to remove alarm for.

Implements Timer.

Definition at line 78 of file hosted/Timer.cc.

References m_AlarmLock, and m_Alarms.

◆ removeAlarm() [2/2]

size_t HostedTimer::removeAlarm ( class Event *  pEvent,
bool  bRetZero 
)
virtual

Removes the event pEvent from the alarm queue. Once this returns, the timer will not begin another delivery of this event.

Parameters
pEventEvent to remove alarm for.
bRetZeroIf true, returns zero rather the time until firing
Returns
The number of seconds before the event would have fired, or zero if bRetZero is true.

Implements Timer.

Definition at line 90 of file hosted/Timer.cc.

References getTickCountNano(), m_AlarmLock, and m_Alarms.

◆ synchronise()

void HostedTimer::synchronise ( bool  tohw = false)
virtual

Synchronise the time/date with the hardware

Reimplemented from Timer.

Definition at line 268 of file hosted/Timer.cc.

References m_DayOfMonth, m_DayOfWeek, m_Hour, m_Minute, m_Month, m_Nanosecond, m_Second, and m_Year.

Referenced by initialise1(), processTimerBatch(), and uninitialise().

+ Here is the caller graph for this function:

◆ threadedIrq()

void HostedTimer::threadedIrq ( size_t  work)
overrideprivatevirtual

Runs in ordinary thread context and may use blocking APIs. The owned worker normally calls it; teardown may call it synchronously after the worker is joined to drain a rejected publication. It must not re-enable an interrupt source.

Implements SplitIrqHandler.

Definition at line 363 of file hosted/Timer.cc.

References m_PendingExpirations, processTimerBatch(), and IrqEventCounter::takeAll().

◆ uninitialise()

void HostedTimer::uninitialise ( )

Uninitialises the class

Definition at line 288 of file hosted/Timer.cc.

References m_AlarmLock, m_Alarms, m_bInitialized, m_bPrepared, m_HandlerRegistry, m_IrqId, m_TickSource, TimerHandlerRegistry::reset(), SplitIrqHandler::shutdownSplitIrq(), and synchronise().

Referenced by HostedMachine::deinitialise(), and ~HostedTimer().

+ Here is the caller graph for this function:

◆ unregisterHandler()

bool HostedTimer::unregisterHandler ( TimerHandler *  handler)
virtual

Implements Timer.

Definition at line 126 of file hosted/Timer.cc.

Member Data Documentation

◆ m_AlarmLock

Spinlock HostedTimer::m_AlarmLock
private

Alarm modification lock.

Definition at line 177 of file kernel/machine/hosted/Timer.h.

Referenced by addAlarm(), processTimerBatch(), removeAlarm(), removeAlarm(), and uninitialise().

◆ m_Alarms

List<Alarm*> HostedTimer::m_Alarms
private

List of alarms.

Definition at line 174 of file kernel/machine/hosted/Timer.h.

Referenced by addAlarm(), processTimerBatch(), removeAlarm(), removeAlarm(), and uninitialise().

◆ m_bInitialized

bool HostedTimer::m_bInitialized = false
private

Are we init-ed?

Definition at line 184 of file kernel/machine/hosted/Timer.h.

Referenced by initialise1(), initialise3(), and uninitialise().

◆ m_bPrepared

bool HostedTimer::m_bPrepared = false
private

Has the unarmed POSIX timer been created?

Definition at line 187 of file kernel/machine/hosted/Timer.h.

Referenced by initialise1(), initialise3(), and uninitialise().

◆ m_DayOfMonth

uint8_t HostedTimer::m_DayOfMonth
private

The current day of month

Definition at line 132 of file kernel/machine/hosted/Timer.h.

Referenced by getDayOfMonth(), and synchronise().

◆ m_DayOfWeek

uint8_t HostedTimer::m_DayOfWeek
private

The current day of week

Definition at line 134 of file kernel/machine/hosted/Timer.h.

Referenced by getDayOfWeek(), and synchronise().

◆ m_HandlerRegistry

TimerHandlerRegistry HostedTimer::m_HandlerRegistry
private

Timer handlers and their callback lifetime state.

Definition at line 157 of file kernel/machine/hosted/Timer.h.

Referenced by initialise1(), processTimerBatch(), and uninitialise().

◆ m_Hour

uint8_t HostedTimer::m_Hour
private

The current hour

Definition at line 136 of file kernel/machine/hosted/Timer.h.

Referenced by getHour(), and synchronise().

◆ m_Instance

HostedTimer HostedTimer::m_Instance
staticprivate

The HostedTimer class instance

Definition at line 154 of file kernel/machine/hosted/Timer.h.

◆ m_IrqId

irq_id_t HostedTimer::m_IrqId
private

Registered handler.

Definition at line 148 of file kernel/machine/hosted/Timer.h.

Referenced by initialise3(), and uninitialise().

◆ m_Minute

uint8_t HostedTimer::m_Minute
private

The current minute

Definition at line 138 of file kernel/machine/hosted/Timer.h.

Referenced by getMinute(), and synchronise().

◆ m_Month

uint8_t HostedTimer::m_Month
private

The current month

Definition at line 130 of file kernel/machine/hosted/Timer.h.

Referenced by getMonth(), and synchronise().

◆ m_Nanosecond

uint64_t HostedTimer::m_Nanosecond
private

The current nanosecond

Definition at line 142 of file kernel/machine/hosted/Timer.h.

Referenced by getNanosecond(), processTimerBatch(), and synchronise().

◆ m_PendingExpirations

IrqEventCounter HostedTimer::m_PendingExpirations
private

Delivered expirations preserved across worker coalescing.

Definition at line 151 of file kernel/machine/hosted/Timer.h.

Referenced by hardIrq(), initialise3(), and threadedIrq().

◆ m_Second

uint8_t HostedTimer::m_Second
private

The current second

Definition at line 140 of file kernel/machine/hosted/Timer.h.

Referenced by getSecond(), and synchronise().

◆ m_TickSource

HostedTickSource HostedTimer::m_TickSource
private

Periodic signal source.

Definition at line 145 of file kernel/machine/hosted/Timer.h.

Referenced by hardIrq(), initialise1(), initialise3(), quiesceIrqSources(), and uninitialise().

◆ m_Year

size_t HostedTimer::m_Year
private

The current year

Definition at line 128 of file kernel/machine/hosted/Timer.h.

Referenced by getYear(), and synchronise().


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