[openrtm-commit:02120] r2804 - trunk/OpenRTM-aist/src/lib/rtm
openrtm @ openrtm.org
openrtm @ openrtm.org
2016年 11月 18日 (金) 01:44:45 JST
Author: n-ando
Date: 2016-11-18 01:44:45 +0900 (Fri, 18 Nov 2016)
New Revision: 2804
Modified:
trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextBase.h
trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.cpp
trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.h
trunk/OpenRTM-aist/src/lib/rtm/RTObject.cpp
Log:
[incompat,->RELENG_1_2] CPU affinity setting for ExecutionContext (only PeriodicEC) has been added. refs #3711
Modified: trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextBase.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextBase.h 2016-11-17 16:43:58 UTC (rev 2803)
+++ trunk/OpenRTM-aist/src/lib/rtm/ExecutionContextBase.h 2016-11-17 16:44:45 UTC (rev 2804)
@@ -401,14 +401,14 @@
/*!
* @if jp
- * @brief ExecutionContextの処理を進める
+ * @brief ExecutionContextの初期化を行う
*
- * ExecutionContextの処理を1周期分進める。
+ * ExecutionContextの初期化処理
*
* @else
- * @brief Proceed with tick of ExecutionContext
+ * @brief Initialize the ExecutionContext
*
- * Proceed with tick of ExecutionContext for one period.
+ * This operation initialize the ExecutionContext
*
* @endif
*/
Modified: trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.cpp 2016-11-17 16:43:58 UTC (rev 2803)
+++ trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.cpp 2016-11-17 16:44:45 UTC (rev 2804)
@@ -18,7 +18,10 @@
#include <algorithm>
#include <iostream>
-
+#ifdef RTM_OS_LINUX
+#define _GNU_SOURCE
+#include <pthread.h>
+#endif // RTM_OS_LINUX
#include <coil/Time.h>
#include <coil/TimeValue.h>
@@ -76,6 +79,16 @@
wait();
}
+ void PeriodicExecutionContext::init(coil::Properties& props)
+ {
+ RTC_TRACE(("init()"));
+ ExecutionContextBase::init(props);
+
+ setCpuAffinity(props);
+
+ RTC_DEBUG(("init() done"));
+ }
+
/*------------------------------------------------------------
* Start activity
* ACE_Task class method over ride.
@@ -109,6 +122,37 @@
{
RTC_TRACE(("svc()"));
int count(0);
+
+#ifdef RTM_OS_LINUX
+ pthread_t tid(pthread_self());
+ cpu_set_t cpu_set;
+ CPU_ZERO(&cpu_set);
+
+ for (size_t i(0); i < m_cpu.size(); ++i)
+ {
+ RTC_DEBUG(("CPU affinity mask set to %d", m_cpu[i]));
+ CPU_SET(m_cpu[i], &cpu_set);
+ }
+
+ int result = pthread_setaffinity_np(tid, sizeof(cpu_set_t), &cpu_set);
+ if (result != 0)
+ {
+ RTC_ERROR(("pthread_getaffinity_np():"
+ "CPU affinity mask setting failed"));
+ }
+ CPU_ZERO(&cpu_set);
+ tid = pthread_self();
+ result = pthread_getaffinity_np(tid, sizeof(cpu_set_t), &cpu_set);
+ if (result != 0)
+ {
+ RTC_ERROR(("pthread_getaffinity_np(): returned error."));
+ }
+ for (size_t j(0); j < CPU_SETSIZE; ++j)
+ {
+ if (CPU_ISSET(j, &cpu_set)) { RTC_DEBUG(("CPU %d is set.", j)); }
+ }
+#endif // RTM_OS_LINUX
+
do
{
ExecutionContextBase::invokeWorkerPreDo();
@@ -557,6 +601,28 @@
return RTC::RTC_OK;
}
+ void PeriodicExecutionContext::setCpuAffinity(coil::Properties& props)
+ {
+ RTC_TRACE(("setCpuAffinity()"));
+ std::cout << props;
+ std::string affinity;
+ getProperty(props, "cpu_affinity", affinity);
+ RTC_DEBUG(("CPU affinity property: %s", affinity.c_str()));
+
+ coil::vstring tmp = coil::split(affinity, ",", true);
+ m_cpu.clear();
+
+ for (size_t i(0); i < tmp.size(); ++i)
+ {
+ int num;
+ if (coil::stringTo(num, tmp[i].c_str()))
+ {
+ m_cpu.push_back(num);
+ RTC_DEBUG(("CPU affinity int value: %d added.", num));
+ }
+ }
+ }
+
}; // namespace RTC
extern "C"
Modified: trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.h 2016-11-17 16:43:58 UTC (rev 2803)
+++ trunk/OpenRTM-aist/src/lib/rtm/PeriodicExecutionContext.h 2016-11-17 16:44:45 UTC (rev 2804)
@@ -102,6 +102,21 @@
/*!
* @if jp
+ * @brief ExecutionContextの初期化を行う
+ *
+ * ExecutionContextの初期化処理
+ *
+ * @else
+ * @brief Initialize the ExecutionContext
+ *
+ * This operation initialize the ExecutionContext
+ *
+ * @endif
+ */
+ virtual void init(coil::Properties& props);
+
+ /*!
+ * @if jp
* @brief ExecutionContext用アクティビティスレッドを生成する
*
* Executioncontext 用の内部アクティビティスレッドを生成し起動する。
@@ -571,6 +586,18 @@
throw (CORBA::SystemException);
protected:
+ template <class T>
+ void getProperty(coil::Properties& prop, const char* key, T& value)
+ {
+ if (prop.findNode(key) != 0)
+ {
+ T tmp;
+ if (coil::stringTo(tmp, prop[key].c_str()))
+ {
+ value = tmp;
+ }
+ }
+ }
/*!
* @brief onStarted() template function
*/
@@ -622,6 +649,11 @@
virtual RTC::ReturnCode_t
onReset(RTC_impl::RTObjectStateMachine* comp, long int count);
+ /*!
+ * @brief setting CPU affinity from given properties
+ */
+ virtual void setCpuAffinity(coil::Properties& props);
+
bool threadRunning()
{
Guard guard(m_svcmutex);
@@ -681,6 +713,11 @@
*/
bool m_nowait;
+ /*!
+ * @brief CPU affinity mask list
+ */
+ std::vector<int> m_cpu;
+
}; // class PeriodicExecutionContext
}; // namespace RTC
Modified: trunk/OpenRTM-aist/src/lib/rtm/RTObject.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/RTObject.cpp 2016-11-17 16:43:58 UTC (rev 2803)
+++ trunk/OpenRTM-aist/src/lib/rtm/RTObject.cpp 2016-11-17 16:44:45 UTC (rev 2804)
@@ -2527,6 +2527,7 @@
"activation_timeout",
"deactivation_timeout",
"reset_timeout",
+ "cpu_affinity",
""
};
coil::Properties* p = m_properties.findNode("exec_cxt");
More information about the openrtm-commit
mailing list