Re: FileDescriptorActivity has a 0.0 period

S Roderick <[email protected]> Tue, 25 Feb 2014 06:37:00 -0500
Newsgroups gmane.science.robotics.orocos.devel
Message-ID <[email protected]>
On Feb 24, 2014, at 18:31 , S Roderick <[email protected]> wrote:

> One issue with the FileDescriptorActivity (FDA) implementation in both RTT v1 and v2, is that it always returns a zero (0.0) period. If the FDA is actually signalled from, for example, a periodic hardware signal, then this is somewhat incorrect. It also makes a component less re-usable if the component requires a periodic activity, as it can't be deployed with an FDA (as the 0.0 period makes it look non-periodic).
> 
> We modified the FDA implementation to leave the underlying "actual" period as 0.0, but then to store and return an "intended" period. This can be set by the deployer as with the period of any other periodic activity, to indicate to the underlying component implementation that this is actually intended to be a periodic component. In our case, the underlying component can distinguish between the signalled wake up and a timeout, so that isn't a problem.
> 
> I wanted to run this by the ML to see whether anyone had any comments or issues? The patch is attached and is pretty straight forward. This is also in the file-descriptor-activity-fixes branch of my gitorious RTT clone, if that's easier.
> 
> Cheers
> S

With the attachment this time - thanks Willy.
S

-- 
Orocos-Dev mailing list
[email protected]
http://lists.mech.kuleuven.be/mailman/listinfo/orocos-dev
0001-extras-Support-an-intended-period-in-FileDescriptorA.patch (application/octet-stream, 6.3 KB)
From 7dee2ea22889ce4af364fd8aaa63417c401f340f Mon Sep 17 00:00:00 2001
From: Stephen Roderick <[email protected]>
Date: Sat, 22 Feb 2014 08:56:08 -0500
Subject: [PATCH] extras: Support an intended period in FileDescriptorActivity

A component querying a FileDescriptorActivity (FDA) will always
receive back a period=0. This may be invalid if the FDA is actually
tracking a periodic signal, e.g. say a sync signal from hardware. In
this case there is a period at deployment time that the component
is intended to run at, but this is not available to the underlying
component.

This adds an intended period and returns that as the period of this
activity. The default intended period is the same as the actual
period=0. The actual period remains the same; 0.
---
 rtt/extras/FileDescriptorActivity.cpp | 29 +++++++++++++++++++++++++++--
 rtt/extras/FileDescriptorActivity.hpp | 25 +++++++++++++++++++++++--
 2 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/rtt/extras/FileDescriptorActivity.cpp b/rtt/extras/FileDescriptorActivity.cpp
index b0fbc9b..23ba4c3 100644
--- a/rtt/extras/FileDescriptorActivity.cpp
+++ b/rtt/extras/FileDescriptorActivity.cpp
@@ -80,6 +80,7 @@ FileDescriptorActivity::FileDescriptorActivity(int priority, RunnableInterface*
     : Activity(priority, 0.0, _r, name)
     , m_running(false)
     , m_timeout_us(0)
+    , m_period(0)
 {
     FD_ZERO(&m_fd_set);
     FD_ZERO(&m_fd_work);
@@ -99,16 +100,29 @@ FileDescriptorActivity::FileDescriptorActivity(int scheduler, int priority, Runn
     : Activity(scheduler, priority, 0.0, _r, name)
     , m_running(false)
     , m_timeout_us(0)
+    , m_period(0)
 {
     FD_ZERO(&m_fd_set);
     FD_ZERO(&m_fd_work);
     m_interrupt_pipe[0] = m_interrupt_pipe[1] = -1;
 }
 
-FileDescriptorActivity::FileDescriptorActivity(int scheduler, int priority, unsigned cpu_affinity, RunnableInterface* _r, const std::string& name )
-    : Activity(scheduler, priority, 0.0, cpu_affinity, _r, name)
+FileDescriptorActivity::FileDescriptorActivity(int scheduler, int priority, Seconds period, RunnableInterface* _r, const std::string& name )
+    : Activity(scheduler, priority, 0.0, _r, name)	// actual period == 0.0
     , m_running(false)
     , m_timeout_us(0)
+    , m_period(period >= 0.0 ? period : 0.0)        // intended period
+{
+    FD_ZERO(&m_fd_set);
+    FD_ZERO(&m_fd_work);
+    m_interrupt_pipe[0] = m_interrupt_pipe[1] = -1;
+}
+
+FileDescriptorActivity::FileDescriptorActivity(int scheduler, int priority, Seconds period, unsigned cpu_affinity, RunnableInterface* _r, const std::string& name )
+    : Activity(scheduler, priority, 0.0, cpu_affinity, _r, name)	// actual period == 0.0
+    , m_running(false)
+    , m_timeout_us(0)
+    , m_period(period >= 0.0 ? period : 0.0)        // intended period
 {
     FD_ZERO(&m_fd_set);
     FD_ZERO(&m_fd_work);
@@ -120,6 +134,17 @@ FileDescriptorActivity::~FileDescriptorActivity()
     stop();
 }
 
+Seconds FileDescriptorActivity::getPeriod() const
+{ return m_period; }
+
+bool FileDescriptorActivity::setPeriod(Seconds p)
+{
+	if (p < 0)
+        return false;
+	m_period = p;
+	return true;
+}
+
 bool FileDescriptorActivity::isRunning() const
 { return Activity::isRunning() && m_running; }
 int FileDescriptorActivity::getTimeout() const
diff --git a/rtt/extras/FileDescriptorActivity.hpp b/rtt/extras/FileDescriptorActivity.hpp
index 12772a4..9a60315 100644
--- a/rtt/extras/FileDescriptorActivity.hpp
+++ b/rtt/extras/FileDescriptorActivity.hpp
@@ -106,6 +106,7 @@ namespace RTT { namespace extras {
         bool m_running;
         int  m_interrupt_pipe[2];
         int  m_timeout_us;		//! timeout in microseconds
+        Seconds m_period;		//! intended period
         /** Lock that protects the access to m_fd_set and m_watched_fds */
         mutable RTT::os::Mutex m_lock;
         fd_set m_fd_set;
@@ -147,23 +148,43 @@ namespace RTT { namespace extras {
         FileDescriptorActivity(int scheduler, int priority, base::RunnableInterface* _r = 0, const std::string& name ="FileDescriptorActivity" );
 
         /**
-         * Create a FileDescriptorActivity with a given scheduler type, priority,
+         * Create a FileDescriptorActivity with a given scheduler type, priority, _intended_ period, and
+         * RunnableInterface instance.
+         * @param scheduler
+         *        The scheduler in which the activitie's thread must run. Use ORO_SCHED_OTHER or
+         *        ORO_SCHED_RT.
+         * @param priority The priority of the underlying thread.
+         * @param period The _intended_ periodicity of the activity
+         * @param _r The optional runner, if none, this->loop() is called.
+         * @param name The name of the underlying thread.
+         */
+        FileDescriptorActivity(int scheduler, int priority, Seconds period, base::RunnableInterface* _r = 0, const std::string& name ="FileDescriptorActivity" );
+
+        /**
+         * Create a FileDescriptorActivity with a given scheduler type, priority, _intended_ period,
          * CPU affinity, and RunnableInterface instance.
          * @param scheduler
          *        The scheduler in which the activitie's thread must run. Use ORO_SCHED_OTHER or
          *        ORO_SCHED_RT.
          * @param priority The priority of the underlying thread.
+         * @param period The _intended_ periodicity of the activity
          * @param cpu_affinity The prefered cpu to run on (a mask)
          * @param _r The optional runner, if none, this->loop() is called.
          * @param name The name of the underlying thread.
          */
-        FileDescriptorActivity(int scheduler, int priority, unsigned cpu_affinity,
+        FileDescriptorActivity(int scheduler, int priority, Seconds period, unsigned cpu_affinity,
 							   base::RunnableInterface* _r = 0, const std::string& name ="FileDescriptorActivity" );
 
         virtual ~FileDescriptorActivity();
 
         bool isRunning() const;
 
+		/// Get the _intended_ period (not the actual running period)
+        virtual Seconds getPeriod() const;
+
+		/// Set the _intended_ period (not the actual running period)
+        virtual bool setPeriod(Seconds period);
+
         /** Sets the file descriptor the activity should be listening to.
          * @arg close_on_stop { if true, the file descriptor will be closed by the
          * activity when stop() is called. Otherwise, the file descriptor is
-- 
1.8.2.3