[openrtm-commit:02122] r744 - trunk/OpenRTM-aist-Python/OpenRTM_aist

openrtm @ openrtm.org openrtm @ openrtm.org
2016年 11月 18日 (金) 11:32:06 JST


Author: miyamoto
Date: 2016-11-18 11:32:05 +0900 (Fri, 18 Nov 2016)
New Revision: 744

Modified:
   trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/PeriodicExecutionContext.py
   trunk/OpenRTM-aist-Python/OpenRTM_aist/RTObject.py
Log:
[incompat,->RELENG_1_2] CPU affinity setting has been added.

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py	2016-11-17 10:56:31 UTC (rev 743)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/Manager.py	2016-11-18 02:32:05 UTC (rev 744)
@@ -895,6 +895,7 @@
                     "exec_cxt.activation_timeout",
                     "exec_cxt.deactivation_timeout",
                     "exec_cxt.reset_timeout",
+                    "exec_cxt.cpu_affinity",
                     "logger.enable",
                     "logger.log_level",
                     "naming.enable",
@@ -1841,9 +1842,49 @@
     OpenRTM_aist.PeriodicExecutionContextInit(self)
     OpenRTM_aist.ExtTrigExecutionContextInit(self)
     OpenRTM_aist.OpenHRPExecutionContextInit(self)
+    self.initCpuAffinity()
     return True
 
+  def initCpuAffinity(self):
+    self._rtcout.RTC_TRACE("Manager.initCpuAffinity()")
+    
+    if not self._config.findNode("manager.cpu_affinity"):
+      return
+    
+    try:
+      import affinity
+    except ImportError:
+      self._rtcout.RTC_DEBUG("not found affinity module")
+      return
+    
+    
+    affinity_str = self._config.getProperty("manager.cpu_affinity")
+    self._rtcout.RTC_DEBUG("CPU affinity property: %s", affinity_str)
 
+    tmp = affinity_str.split(",")
+
+    pid = os.getpid()
+    cpu_num = 0
+    for num in tmp:
+      try:
+        p = 0x01 << (int(num)-1)
+        cpu_num += p
+      except:
+        pass
+    
+    self._rtcout.RTC_DEBUG("CPU affinity mask set to %d", cpu_num)
+
+    if cpu_num == 0:
+      return
+    
+    affinity.set_process_affinity_mask(pid, cpu_num)
+    ret = affinity.get_process_affinity_mask(pid)
+    if ret != cpu_num:
+      self._rtcout.RTC_ERROR("get_process_affinity_mask(): returned error.")
+    
+
+
+
   ##
   # @if jp
   # @brief PeriodicECSharedComposite の初期化

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/PeriodicExecutionContext.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/PeriodicExecutionContext.py	2016-11-17 10:56:31 UTC (rev 743)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/PeriodicExecutionContext.py	2016-11-18 02:32:05 UTC (rev 744)
@@ -18,6 +18,7 @@
 import copy
 import threading
 import time
+import os
 from omniORB import CORBA, PortableServer
 
 import OpenRTM_aist
@@ -73,6 +74,8 @@
     self._rtcout.RTC_DEBUG("Actual rate: %d [sec], %d [usec]",
                            (self._profile.getPeriod().sec(), self._profile.getPeriod().usec()))    
 
+    self._cpu = 0
+
     return
 
 
@@ -93,7 +96,12 @@
     Task.__del__(self)
     return
 
+  def init(self, props):
+    OpenRTM_aist.ExecutionContextBase.init(self, props)
+    self.setCpuAffinity(props)
+    self._rtcout.RTC_DEBUG("init() done")
 
+
   ##
   # @if jp
   # @brief コンポーネントのアクティビティスレッド関数
@@ -112,7 +120,9 @@
   def svc(self):
     self._rtcout.RTC_TRACE("svc()")
     count_ = 0
+
     
+    
     while self.threadRunning():
       OpenRTM_aist.ExecutionContextBase.invokeWorkerPreDo(self)
       # Thread will stopped when all RTCs are INACTIVE.
@@ -736,6 +746,25 @@
     return self._svc
 
 
+  def setCpuAffinity(self, props):
+    self._rtcout.RTC_TRACE("setCpuAffinity()")
+    
+    affinity_str = props.getProperty("cpu_affinity")
+    self._rtcout.RTC_DEBUG("CPU affinity property: %s",affinity_str)
+    
+    tmp = affinity_str.split(",")
+    self._cpu = 0
+    for num in tmp:
+      try:
+        p = 0x01 << (int(num)-1)
+        self._cpu += p
+        self._rtcout.RTC_DEBUG("CPU affinity int value: %d added.",int(num))
+      except ValueError:
+        pass
+    
+      
+    
+
   ##
   # @if jp
   # @class WorkerThreadCtrl

Modified: trunk/OpenRTM-aist-Python/OpenRTM_aist/RTObject.py
===================================================================
--- trunk/OpenRTM-aist-Python/OpenRTM_aist/RTObject.py	2016-11-17 10:56:31 UTC (rev 743)
+++ trunk/OpenRTM-aist-Python/OpenRTM_aist/RTObject.py	2016-11-18 02:32:05 UTC (rev 744)
@@ -4702,7 +4702,8 @@
                        "transition_timeout",
                        "activation_timeout",
                        "deactivation_timeout",
-                       "reset_timeout"]
+                       "reset_timeout"
+                       "cpu_affinity"]
 
     p_ = self._properties.findNode("exec_cxt")
     if not p_:
@@ -4916,7 +4917,8 @@
                        "transition_timeout",
                        "activation_timeout",
                        "deactivation_timeout",
-                       "reset_timeout"]
+                       "reset_timeout",
+                       "cpu_affinity"]
 
       p_ = self._properties.findNode("exec_cxt")
       



More information about the openrtm-commit mailing list