[openrtm-commit:02119] r2803 - in trunk/OpenRTM-aist: etc src/lib/rtm
openrtm @ openrtm.org
openrtm @ openrtm.org
2016年 11月 18日 (金) 01:43:59 JST
Author: n-ando
Date: 2016-11-18 01:43:58 +0900 (Fri, 18 Nov 2016)
New Revision: 2803
Modified:
trunk/OpenRTM-aist/etc/rtc.conf.sample
trunk/OpenRTM-aist/src/lib/rtm/Manager.cpp
trunk/OpenRTM-aist/src/lib/rtm/Manager.h
Log:
[incompat,->RELENG_1_2] CPU affinity setting has been added. refs #3711
Modified: trunk/OpenRTM-aist/etc/rtc.conf.sample
===================================================================
--- trunk/OpenRTM-aist/etc/rtc.conf.sample 2016-11-16 09:45:47 UTC (rev 2802)
+++ trunk/OpenRTM-aist/etc/rtc.conf.sample 2016-11-17 16:43:58 UTC (rev 2803)
@@ -47,6 +47,21 @@
manager.shutdown_auto: YES
manager.auto_shutdown_duration: 10.0
+#------------------------------------------------------------
+# Manager process's CPU affinity setting
+#
+# This option make the process bound to specific CPU(s). Options must
+# be one or more comma separated numbers to identify CPU ID. CPU ID
+# is started from 0, and maximum number is number of CPU core -1. If
+# invalid CPU ID is specified, all the CPU will be used for the
+# process.
+#
+# Example:
+# manager.cpu_affinity: 0, 1, 2, ...
+#
+manager.cpu_affinity: 0
+
+
#============================================================
# CORBA configuration
#============================================================
Modified: trunk/OpenRTM-aist/src/lib/rtm/Manager.cpp
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/Manager.cpp 2016-11-16 09:45:47 UTC (rev 2802)
+++ trunk/OpenRTM-aist/src/lib/rtm/Manager.cpp 2016-11-17 16:43:58 UTC (rev 2803)
@@ -16,6 +16,7 @@
*
*/
+
#include <rtm/Manager.h>
#include <rtm/ManagerConfig.h>
#include <rtm/ModuleManager.h>
@@ -42,6 +43,13 @@
#include <rtm/LocalServiceAdmin.h>
#include <rtm/SystemLogger.h>
+#ifdef RTM_OS_LINUX
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif // _GNU_SOURCE
+#include <pthread.h>
+#endif // RTM_OS_LINUX
+
#if defined(minor)
#undef minor
#endif
@@ -819,6 +827,7 @@
"exec_cxt.activation_timeout",
"exec_cxt.deactivation_timeout",
"exec_cxt.reset_timeout",
+ "exec_cxt.cpu_affinity",
"logger.enable",
"logger.log_level",
"naming.enable",
@@ -1217,13 +1226,13 @@
if (coil::toBool(m_config["timer.enable"], "YES", "NO", true))
{
coil::TimeValue tm(0, 100000);
- std::string tick(m_config["timer.tick"]);
- if (!tick.empty())
- {
- tm = atof(tick.c_str());
- m_timer = new coil::Timer(tm);
- m_timer->start();
- }
+ std::string tick(m_config["timer.tick"]);
+ if (!tick.empty())
+ {
+ tm = atof(tick.c_str());
+ m_timer = new coil::Timer(tm);
+ m_timer->start();
+ }
}
if (coil::toBool(m_config["manager.shutdown_auto"], "YES", "NO", true) &&
@@ -1732,6 +1741,12 @@
PeriodicExecutionContextInit(this);
ExtTrigExecutionContextInit(this);
OpenHRPExecutionContextInit(this);
+
+ // initialize CPU affinity
+#ifdef RTM_OS_LINUX
+ initCpuAffinity();
+#endif // RTM_OS_LINUX
+
return true;
}
@@ -1750,6 +1765,52 @@
return true;
}
+ void Manager::initCpuAffinity()
+ {
+ RTC_TRACE(("initCpuAffinity()"));
+#ifdef RTM_OS_LINUX
+ if (m_config.findNode("manager.cpu_affinity") == 0) { return; }
+
+ std::string& affinity(m_config["manager.cpu_affinity"]);
+ RTC_DEBUG(("CPU affinity property: %s", affinity.c_str()));
+
+ coil::vstring tmp = coil::split(affinity, ",", true);
+
+ pid_t pid = getpid();
+ cpu_set_t cpu_set; CPU_ZERO(&cpu_set);
+
+ for (size_t i(0); i < tmp.size(); ++i)
+ {
+ int num;
+ if (coil::stringTo(num, tmp[i].c_str()))
+ {
+ CPU_SET(num, &cpu_set);
+ RTC_DEBUG(("CPU affinity mask set to %d", num));
+ }
+ }
+
+ int result = sched_setaffinity(pid, sizeof(cpu_set_t), &cpu_set);
+ if (result != 0)
+ {
+ RTC_ERROR(("pthread_getaffinity_np():"
+ "CPU affinity mask setting failed"));
+ }
+ CPU_ZERO(&cpu_set);
+ result = sched_getaffinity(pid, 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(("Current CPU affinity mask is %d.", j));
+ }
+ }
+#endif // RTM_OS_LINUX
+ }
+
/*!
* @if jp
* @brief Timer の初期化
Modified: trunk/OpenRTM-aist/src/lib/rtm/Manager.h
===================================================================
--- trunk/OpenRTM-aist/src/lib/rtm/Manager.h 2016-11-16 09:45:47 UTC (rev 2802)
+++ trunk/OpenRTM-aist/src/lib/rtm/Manager.h 2016-11-17 16:43:58 UTC (rev 2803)
@@ -1581,6 +1581,8 @@
*/
bool initFactories();
+ void initCpuAffinity();
+
/*!
* @if jp
* @brief Timer の初期化
More information about the openrtm-commit
mailing list