-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
activity: implement abs/rel wait and overrun detection.
Signed-off-by: Peter Soetens <[email protected]>
- Loading branch information
Peter Soetens
committed
Apr 12, 2015
1 parent
1f1d68b
commit 06146b6
Showing
3 changed files
with
50 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,19 +55,19 @@ namespace RTT | |
|
||
Activity::Activity(RunnableInterface* _r, const std::string& name ) | ||
: ActivityInterface(_r), os::Thread(ORO_SCHED_OTHER, RTT::os::LowestPriority, 0.0, 0, name ), | ||
update_period(0.0), mtimeout(false) | ||
update_period(0.0), mtimeout(false), mstopRequested(false), mabswaitpolicy(false) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
{ | ||
} | ||
|
||
Activity::Activity(int priority, RunnableInterface* r, const std::string& name ) | ||
: ActivityInterface(r), os::Thread(ORO_SCHED_RT, priority, 0.0, 0, name ), | ||
update_period(0.0), mtimeout(false) | ||
update_period(0.0), mtimeout(false), mstopRequested(false), mabswaitpolicy(false) | ||
{ | ||
} | ||
|
||
Activity::Activity(int priority, Seconds period, RunnableInterface* r, const std::string& name ) | ||
: ActivityInterface(r), os::Thread(ORO_SCHED_RT, priority, period, 0, name ), | ||
update_period(period), mtimeout(false) | ||
update_period(period), mtimeout(false), mstopRequested(false), mabswaitpolicy(false) | ||
{ | ||
// We pass the requested period to the constructor to not confuse users with log messages. | ||
// Then we clear it immediately again in order to force the Thread implementation to | ||
|
@@ -82,7 +82,7 @@ namespace RTT | |
|
||
Activity::Activity(int scheduler, int priority, Seconds period, RunnableInterface* r, const std::string& name ) | ||
: ActivityInterface(r), os::Thread(scheduler, priority, period, 0, name ), | ||
update_period(period), mtimeout(false) | ||
update_period(period), mtimeout(false), mstopRequested(false), mabswaitpolicy(false) | ||
{ | ||
// We pass the requested period to the constructor to not confuse users with log messages. | ||
// Then we clear it immediately again in order to force the Thread implementation to | ||
|
@@ -92,7 +92,7 @@ namespace RTT | |
|
||
Activity::Activity(int scheduler, int priority, Seconds period, unsigned cpu_affinity, RunnableInterface* r, const std::string& name ) | ||
: ActivityInterface(r), os::Thread(scheduler, priority, period, cpu_affinity, name ), | ||
update_period(period), mtimeout(false) | ||
update_period(period), mtimeout(false), mstopRequested(false), mabswaitpolicy(false) | ||
{ | ||
// We pass the requested period to the constructor to not confuse users with log messages. | ||
// Then we clear it immediately again in order to force the Thread implementation to | ||
|
@@ -165,7 +165,7 @@ namespace RTT | |
|
||
void Activity::loop() { | ||
nsecs wakeup = 0; | ||
|
||
int overruns = 0; | ||
while ( true ) { | ||
// since update_period may be changed at any time, we need to recheck it each time: | ||
if ( update_period > 0.0) { | ||
|
@@ -209,9 +209,22 @@ namespace RTT | |
bool time_elapsed = ! msg_cond.wait_until(msg_lock,wakeup); | ||
|
||
if (time_elapsed) { | ||
nsecs nsperiod = Seconds_to_nsecs(update_period); | ||
wakeup = wakeup + nsperiod; | ||
// calculate next wakeup point, overruns causes skips: | ||
while ( wakeup < os::TimeService::Instance()->getNSecs() ) | ||
wakeup = wakeup + Seconds_to_nsecs(update_period); | ||
nsecs now = os::TimeService::Instance()->getNSecs(); | ||
if ( wakeup < now ) | ||
{ | ||
++overruns; | ||
if (overruns == maxOverRun) | ||
break; // break while(true) | ||
} | ||
else if (overruns != 0) { | ||
--overruns; | ||
} | ||
if ( !mabswaitpolicy && wakeup < now ) { | ||
wakeup = wakeup + ((now-wakeup)/nsperiod+1)*nsperiod; // assumes that (now-wakeup)/nsperiod rounds down ! | ||
This comment has been minimized.
Sorry, something went wrong.
meyerj
Member
|
||
} | ||
mtimeout = true; | ||
} | ||
} | ||
|
@@ -220,6 +233,16 @@ namespace RTT | |
return; | ||
} | ||
} | ||
if (overruns == maxOverRun) | ||
{ | ||
this->emergencyStop(); | ||
log(Critical) << rtos_task_get_name(this->getTask()) | ||
<< " got too many periodic overruns in step() (" | ||
<< overruns << " times), stopped Thread !" | ||
<< endlog(); | ||
log(Critical) << " See Thread::setMaxOverrun() for info." | ||
<< endlog(); | ||
} | ||
} | ||
|
||
bool Activity::breakLoop() { | ||
|
@@ -309,4 +332,12 @@ namespace RTT | |
return Thread::setCpuAffinity(cpu); | ||
} | ||
|
||
void Activity::setWaitPeriodPolicy(int p) | ||
{ | ||
if ( p == ORO_WAIT_ABS) | ||
mabswaitpolicy = true; | ||
else | ||
mabswaitpolicy = false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@psoetens Was it on purpose that relative wait period policy is the new default since this patch or is the variable name misleading?