[Bug 865] New: [PATCH] TimerComponent: replace single port for all timers with a separate port for each timer

http://bugs.orocos.org/show_bug.cgi?id=865

Summary: [PATCH] TimerComponent: replace single port for all
timers with a separate port for each timer
Product: Toolchain
Version: unspecified
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P3
Component: OCL
AssignedTo: orocos-dev [..] ...
ReportedBy: ruben [dot] smits [..] ...
CC: orocos-dev [..] ...
Estimated Hours: 0.0

Created attachment 693
--> http://bugs.orocos.org/attachment.cgi?id=693
TimerComponent: replace single port for all timers with a separate port for
each timer

commit bce26d2084502db73bbbbb63d6a1971dc8f15ebb
Author: Ruben Smits <ruben [dot] smits [..] ...>
Date: Fri May 27 11:19:12 2011 +0200

TimerComponent: replace single port for all timers with a separate port for
each timer

Signed-off-by: Ruben Smits <ruben [dot] smits [..] ...>

diff --git a/timer/TimerComponent.cpp b/timer/TimerComponent.cpp
index 2e7c06a..44608ab 100644
--- a/timer/TimerComponent.cpp
+++ b/timer/TimerComponent.cpp
@@ -12,8 +12,8 @@ namespace OCL
using namespace RTT;

TimerComponent::TimerComponent( std::string name /*= "os::Timer" */ )
- : TaskContext( name, PreOperational ), mtimer( 32, mtimeoutEvent ),
- mtimeoutEvent("timeout"),
+ : TaskContext( name, PreOperational ), port_timers(32),
+ mtimer( port_timers ),
waitForCommand( "waitFor", &TimerComponent::waitFor, this), //,
&TimerComponent::isTimerExpired, this),
waitCommand( "wait", &TimerComponent::wait, this)
//&TimerComponent::isTimerExpired, this)
{
@@ -28,11 +28,18 @@ namespace OCL
this->addOperation("setMaxTimers", &os::Timer::setMaxTimers , &mtimer,
RTT::ClientThread).doc("Raise or lower the maximum amount of timers.").arg("ti
this->addOperation( waitForCommand ).doc("Wait until a timer
expires.").arg("timerId", "A numeric id of the timer to wait for.");
this->addOperation( waitCommand ).doc("Arm and wait until that timer
expires.").arg("timerId", "A numeric id of the timer to arm and to wait
for.").a
- this->addPort(mtimeoutEvent).doc("This port is written each time a
timer expires. The timer id is the value sent in this port.");
+ for(unsigned int i=0;i<port_timers.size();i++){
+ ostringstream port_name;
+ port_name<<"timer_"< + port_timers[i] = new
RTT::OutputPort + this->addPort(*(port_timers[i])).doc(string("This port is written
each time ")+port_name.str()+string(" expires. The timer id is the value sent i
+ }
}

TimerComponent::~TimerComponent() {
this->stop();
+ for(unsigned int i=0;i<port_timers.size();i++)
+ delete port_timers[i];
}

bool TimerComponent::startHook()
diff --git a/timer/TimerComponent.hpp b/timer/TimerComponent.hpp
index 50d77f0..0ac337c 100644
--- a/timer/TimerComponent.hpp
+++ b/timer/TimerComponent.hpp
@@ -26,17 +26,17 @@ namespace OCL
* Helper class for catching the virtual timeout function of Timer.
*/
struct TimeoutCatcher : public os::Timer {
- RTT::OutputPort - TimeoutCatcher(RTT::os::Timer::TimerId max_timers,
RTT::OutputPort<RTT::os::Timer::TimerId>& e) :
- os::Timer(max_timers, ORO_SCHED_RT, os::HighestPriority),
me(e)
+ std::vector<RTT::OutputPort m_port_timers;
+
TimeoutCatcher(std::vector<RTT::OutputPort port_timers) :
+ os::Timer(port_timers.size(), ORO_SCHED_RT,
os::HighestPriority), m_port_timers(port_timers)
{}
virtual void timeout(os::Timer::TimerId id) {
- me.write(id);
+ m_port_timers[id]->write(id);
}
};

+ std::vector<OutputPort TimeoutCatcher mtimer;
- OutputPort<RTT::os::Timer::TimerId> mtimeoutEvent;

/**
* This hook will check if a Activity has been properly

[Bug 865] [PATCH] TimerComponent: replace single port for all ti

http://bugs.orocos.org/show_bug.cgi?id=865

Peter Soetens <peter [..] ...> changed:

What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED

--- Comment #1 from Peter Soetens <peter [..] ...> 2011-07-15 18:33:14 CEST ---
(In reply to comment #0)
> Created attachment 693
> TimerComponent: replace single port for all timers with a separate port for each
> timer
>
> commit bce26d2084502db73bbbbb63d6a1971dc8f15ebb
> Author: Ruben Smits <ruben [dot] smits [..] ...>
> Date: Fri May 27 11:19:12 2011 +0200
>
> TimerComponent: replace single port for all timers with a separate port for
> each timer
>
> Signed-off-by: Ruben Smits <ruben [dot] smits [..] ...>
>

Applied on OCL master.

[Bug 865] New: [PATCH] TimerComponent: replace single port for a

On May 27, 2011, at 05:25 , Ruben Smits wrote:

>
> http://bugs.orocos.org/show_bug.cgi?id=865
>
> Summary: [PATCH] TimerComponent: replace single port for all
> timers with a separate port for each timer
> Product: Toolchain
> Version: unspecified
> Platform: All
> OS/Version: All
> Status: NEW
> Severity: enhancement
> Priority: P3
> Component: OCL
> AssignedTo: orocos-dev [..] ...
> ReportedBy: ruben [dot] smits [..] ...
> CC: orocos-dev [..] ...
> Estimated Hours: 0.0
>
>
> Created attachment 693
> --> http://bugs.orocos.org/attachment.cgi?id=693
> TimerComponent: replace single port for all timers with a separate port for
> each timer
>
> commit bce26d2084502db73bbbbb63d6a1971dc8f15ebb
> Author: Ruben Smits <ruben [dot] smits [..] ...>
> Date: Fri May 27 11:19:12 2011 +0200
>
> TimerComponent: replace single port for all timers with a separate port for
> each timer
>
> Signed-off-by: Ruben Smits <ruben [dot] smits [..] ...>
>
<sni

What problem are you solving here Ruben?
S

[Bug 865] New: [PATCH] TimerComponent: replace single port for a

On Fri, May 27, 2011 at 12:34:44PM +0200, S Roderick wrote:
> On May 27, 2011, at 05:25 , Ruben Smits wrote:
>
> >
> > http://bugs.orocos.org/show_bug.cgi?id=865
> >
> > Summary: [PATCH] TimerComponent: replace single port for all
> > timers with a separate port for each timer
> > Product: Toolchain
> > Version: unspecified
> > Platform: All
> > OS/Version: All
> > Status: NEW
> > Severity: enhancement
> > Priority: P3
> > Component: OCL
> > AssignedTo: orocos-dev [..] ...
> > ReportedBy: ruben [dot] smits [..] ...
> > CC: orocos-dev [..] ...
> > Estimated Hours: 0.0
> >
> >
> > Created attachment 693
> > --> http://bugs.orocos.org/attachment.cgi?id=693
> > TimerComponent: replace single port for all timers with a separate port for
> > each timer
> >
> > commit bce26d2084502db73bbbbb63d6a1971dc8f15ebb
> > Author: Ruben Smits <ruben [dot] smits [..] ...>
> > Date: Fri May 27 11:19:12 2011 +0200
> >
> > TimerComponent: replace single port for all timers with a separate port for
> > each timer
> >
> > Signed-off-by: Ruben Smits <ruben [dot] smits [..] ...>
> >
> <sni

>
> What problem are you solving here Ruben?

The rationale is the following: the TimerComponent serves as a source
of events. If the timer expiration events are communicated via one
single port, the result is that all components listening
event-driven'ly to this port are woken up. But commonly few are
interested in this particular timer expiring, and hence only wake up
to find out that they can go back to sleep again. This effect gets
worse when mixing high and low frequency timers, essentially leading
to the well know thundering herd problem.

Markus

[Bug 865] New: [PATCH] TimerComponent: replace single port for a

On May 27, 2011, at 10:57 , Markus Klotzbuecher wrote:

> On Fri, May 27, 2011 at 12:34:44PM +0200, S Roderick wrote:
>> On May 27, 2011, at 05:25 , Ruben Smits wrote:
>>
>>>
>>> http://bugs.orocos.org/show_bug.cgi?id=865
>>>
>>> Summary: [PATCH] TimerComponent: replace single port for all
>>> timers with a separate port for each timer
>>> Product: Toolchain
>>> Version: unspecified
>>> Platform: All
>>> OS/Version: All
>>> Status: NEW
>>> Severity: enhancement
>>> Priority: P3
>>> Component: OCL
>>> AssignedTo: orocos-dev [..] ...
>>> ReportedBy: ruben [dot] smits [..] ...
>>> CC: orocos-dev [..] ...
>>> Estimated Hours: 0.0
>>>
>>>
>>> Created attachment 693
>>> --> http://bugs.orocos.org/attachment.cgi?id=693
>>> TimerComponent: replace single port for all timers with a separate port for
>>> each timer
>>>
>>> commit bce26d2084502db73bbbbb63d6a1971dc8f15ebb
>>> Author: Ruben Smits <ruben [dot] smits [..] ...>
>>> Date: Fri May 27 11:19:12 2011 +0200
>>>
>>> TimerComponent: replace single port for all timers with a separate port for
>>> each timer
>>>
>>> Signed-off-by: Ruben Smits <ruben [dot] smits [..] ...>
>>>
>> <sni

>>
>> What problem are you solving here Ruben?
>
> The rationale is the following: the TimerComponent serves as a source
> of events. If the timer expiration events are communicated via one
> single port, the result is that all components listening
> event-driven'ly to this port are woken up. But commonly few are
> interested in this particular timer expiring, and hence only wake up
> to find out that they can go back to sleep again. This effect gets
> worse when mixing high and low frequency timers, essentially leading
> to the well know thundering herd problem.

Makes sense. My problem was that the bug report and patch didn't tie into the recent ML discussion, so it wasn't clear what was being solved.
S