rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Data Fields | Private Member Functions | Private Attributes
SingleTimerExecutor Class Referencefinal

#include <single_timer_executor.h>

Inheritance diagram for SingleTimerExecutor:
Inheritance graph
[legend]
Collaboration diagram for SingleTimerExecutor:
Collaboration graph
[legend]

Public Member Functions

 SingleTimerExecutor ()
 
void schedule (const char *msg, scheduling_s *scheduling, efitick_t timeNt, action_s const &action) override
 Schedule an action to be executed in the future.
 
void cancel (scheduling_s *scheduling) override
 Cancel the specified scheduling_s so that, if currently scheduled, it does not execute.
 
void onTimerCallback ()
 

Data Fields

int timerCallbackCounter = 0
 
int scheduleCounter = 0
 
int maxExecuteCounter = 0
 
int executeCounter
 
int executeAllPendingActionsInvocationCounter = 0
 

Private Member Functions

void executeAllPendingActions ()
 
void scheduleTimerCallback ()
 

Private Attributes

EventQueue queue
 
bool reentrantFlag = false
 

Detailed Description

Definition at line 13 of file single_timer_executor.h.

Constructor & Destructor Documentation

◆ SingleTimerExecutor()

SingleTimerExecutor::SingleTimerExecutor ( )

Definition at line 42 of file single_timer_executor.cpp.

44 : queue(US2NT(8))
45{
46}

Member Function Documentation

◆ cancel()

void SingleTimerExecutor::cancel ( scheduling_s scheduling)
overridevirtual

Cancel the specified scheduling_s so that, if currently scheduled, it does not execute.

Parameters
schedulingThe scheduling_s to cancel.

Implements Scheduler.

Definition at line 76 of file single_timer_executor.cpp.

76 {
77 // Lock for queue removal - we may already be locked, but that's ok
78 chibios_rt::CriticalSectionLocker csl;
79
80 queue.remove(scheduling);
81}
void remove(scheduling_s *scheduling)

Referenced by TriggerScheduler::scheduleEventsUntilNextTriggerTooth().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeAllPendingActions()

void SingleTimerExecutor::executeAllPendingActions ( )
private

Let's execute actions we should execute at this point. reentrantFlag takes care of the use case where the actions we are executing are scheduling further invocations

in real life it could be that while we executing listeners time passes and it's already time to execute next listeners. TODO: add a counter & figure out a limit of iterations?

Definition at line 95 of file single_timer_executor.cpp.

95 {
97
99 /**
100 * Let's execute actions we should execute at this point.
101 * reentrantFlag takes care of the use case where the actions we are executing are scheduling
102 * further invocations
103 */
104 reentrantFlag = true;
105
106 /**
107 * in real life it could be that while we executing listeners time passes and it's already time to execute
108 * next listeners.
109 * TODO: add a counter & figure out a limit of iterations?
110 */
111
112 // starts at -1 because do..while will run a minimum of once
113 executeCounter = -1;
114
115 bool didExecute;
116 do {
117 efitick_t nowNt = getTimeNowNt();
118 didExecute = queue.executeOne(nowNt);
119
120 // if we're stuck in a loop executing lots of events, panic!
121 if (executeCounter++ == 500) {
122 firmwareError(ObdCode::CUSTOM_ERR_LOCK_ISSUE, "Maximum scheduling run length exceeded - CPU load too high");
123 }
124
125 } while (didExecute);
126
128
129 if (!isLocked()) {
130 firmwareError(ObdCode::CUSTOM_ERR_LOCK_ISSUE, "Someone has stolen my lock");
131 return;
132 }
133 reentrantFlag = false;
134}
bool executeOne(efitick_t now)
efitick_t getTimeNowNt()
Definition efitime.cpp:19
void firmwareError(ObdCode code, const char *fmt,...)
static bool isLocked
Definition flash_int.cpp:22
@ CUSTOM_ERR_LOCK_ISSUE
@ SingleTimerExecutorDoExecute

Referenced by onTimerCallback(), and schedule().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onTimerCallback()

void SingleTimerExecutor::onTimerCallback ( )

Definition at line 83 of file single_timer_executor.cpp.

83 {
85
86 chibios_rt::CriticalSectionLocker csl;
87
90}

Referenced by globalTimerCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ schedule()

void SingleTimerExecutor::schedule ( const char msg,
scheduling_s scheduling,
efitick_t  targetTime,
action_s const &  action 
)
overridevirtual

Schedule an action to be executed in the future.

scheduleByAngle is useful if you want to schedule something in terms of crank angle instead of time.

Parameters
msgName of this event to use for logging in case of an error.
schedulingStorage to use for the scheduled event. If null, one will be used from the pool.
targetTimeWhen to execute the specified action. If this time is in the past or very near future, it may execute immediately.
actionAn action to execute at the specified time.

Implements Scheduler.

Definition at line 48 of file single_timer_executor.cpp.

48 {
50
51#if EFI_ENABLE_ASSERTS
52 efidur_t deltaTimeNt = nt - getTimeNowNt();
53
54 if (deltaTimeNt >= TOO_FAR_INTO_FUTURE_NT) {
55 // we are trying to set callback for too far into the future. This does not look right at all
56 int32_t intDeltaTimeNt = (int32_t)deltaTimeNt;
57 firmwareError(ObdCode::RUNTIME_CRITICAL_TASK_TIMER_OVERFLOW, "schedule() too far: %ld %s", intDeltaTimeNt, msg);
58 return;
59 }
60#endif
61
63
64 // Lock for queue insertion - we may already be locked, but that's ok
65 chibios_rt::CriticalSectionLocker csl;
66
67 bool needToResetTimer = queue.insertTask(scheduling, nt, action);
68 if (!reentrantFlag) {
70 if (needToResetTimer) {
72 }
73 }
74}
bool insertTask(scheduling_s *scheduling, efitick_t timeX, action_s const &action)
@ RUNTIME_CRITICAL_TASK_TIMER_OVERFLOW
@ SingleTimerExecutorScheduleByTimestamp
efitick_t efidur_t

Referenced by fireSparkAndPrepareNextSchedule(), runBench(), scheduleByAngle(), scheduleSparkEvent(), triggerScopeGetBuffer(), validateHardwareTimer(), and watchDogBuddyCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ scheduleTimerCallback()

void SingleTimerExecutor::scheduleTimerCallback ( )
private

This method is always invoked under a lock

Let's grab fresh time value

Definition at line 139 of file single_timer_executor.cpp.

139 {
141
142 /**
143 * Let's grab fresh time value
144 */
145 efitick_t nowNt = getTimeNowNt();
146 expected<efitick_t> nextEventTimeNt = queue.getNextEventTime(nowNt);
147
148 if (!nextEventTimeNt) {
149 return; // no pending events in the queue
150 }
151
152 efiAssertVoid(ObdCode::CUSTOM_ERR_6625, nextEventTimeNt.Value > nowNt, "setTimer constraint");
153
154 setHardwareSchedulerTimer(nowNt, nextEventTimeNt.Value);
155}
expected< efitick_t > getNextEventTime(efitick_t nowUs) const
void setHardwareSchedulerTimer(efitick_t nowNt, efitick_t setTimeNt)
@ CUSTOM_ERR_6625
@ SingleTimerExecutorScheduleTimerCallback

Referenced by onTimerCallback(), and schedule().

Here is the call graph for this function:
Here is the caller graph for this function:

Field Documentation

◆ executeAllPendingActionsInvocationCounter

int SingleTimerExecutor::executeAllPendingActionsInvocationCounter = 0

Definition at line 24 of file single_timer_executor.h.

Referenced by executeAllPendingActions(), and executorStatistics().

◆ executeCounter

int SingleTimerExecutor::executeCounter

Definition at line 23 of file single_timer_executor.h.

Referenced by executeAllPendingActions(), and executorStatistics().

◆ maxExecuteCounter

int SingleTimerExecutor::maxExecuteCounter = 0

Definition at line 22 of file single_timer_executor.h.

Referenced by executeAllPendingActions(), and executorStatistics().

◆ queue

EventQueue SingleTimerExecutor::queue
private

◆ reentrantFlag

bool SingleTimerExecutor::reentrantFlag = false
private

Definition at line 27 of file single_timer_executor.h.

Referenced by executeAllPendingActions(), and schedule().

◆ scheduleCounter

int SingleTimerExecutor::scheduleCounter = 0

Definition at line 21 of file single_timer_executor.h.

Referenced by executorStatistics(), and schedule().

◆ timerCallbackCounter

int SingleTimerExecutor::timerCallbackCounter = 0

Definition at line 20 of file single_timer_executor.h.

Referenced by executorStatistics(), and onTimerCallback().


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