From 1f55ccc5e0a9f3b3e66506f7ea2d4267890ad5b6 Mon Sep 17 00:00:00 2001 From: Stephen Roderick Date: Mon, 13 Jun 2011 06:51:35 -0400 Subject: [PATCH 2/2] deployment: Support CPU affinity in XML Supports setting the CPU affinity using XML in Activity, PeriodicActivity and NonPeriodicActivity. Does _not_ support it via the deployment interface. Add to test case. --- deployment/DeploymentComponent.cpp | 42 +++++++++++++++++++++++++++++++---- deployment/DeploymentComponent.hpp | 25 +++++++++++++++++++++ deployment/tests/deployment.cpf | 13 +++++++++++ deployment/tests/main.cpp | 2 + 4 files changed, 77 insertions(+), 5 deletions(-) diff --git a/deployment/DeploymentComponent.cpp b/deployment/DeploymentComponent.cpp index f03438a..9bc0848 100644 --- a/deployment/DeploymentComponent.cpp +++ b/deployment/DeploymentComponent.cpp @@ -722,6 +722,14 @@ namespace OCL log(Error)<<"Please specify priority as for "<< nm.rvalue().getType()< cpu_affinity_prop = nm.rvalue().getProperty("CpuAffinity"); + if(cpu_affinity_prop.ready()) { + cpu_affinity = cpu_affinity_prop.get(); + } + // else ignore as is optional + Property sched; if (nm.rvalue().getProperty("Scheduler") ) sched = nm.rvalue().getProperty("Scheduler"); // work around RTT 1.0.2 bug @@ -732,7 +740,7 @@ namespace OCL valid = false; } if (valid) { - this->setNamedActivity(comp.getName(), nm.rvalue().getType(), per.get(), prio.get(), scheduler ); + this->setNamedActivity(comp.getName(), nm.rvalue().getType(), per.get(), prio.get(), scheduler, cpu_affinity ); } } else if ( nm.rvalue().getType() == "NonPeriodicActivity" ) { @@ -743,6 +751,14 @@ namespace OCL log(Error)<<"Please specify priority of NonPeriodicActivity."< cpu_affinity_prop = nm.rvalue().getProperty("CpuAffinity"); + if(cpu_affinity_prop.ready()) { + cpu_affinity = cpu_affinity_prop.get(); + } + // else ignore as is optional + Property sched; if (nm.rvalue().getProperty("Scheduler") ) sched = nm.rvalue().getProperty("Scheduler"); // work around RTT 1.0.2 bug @@ -753,7 +769,7 @@ namespace OCL valid = false; } if (valid) { - this->setNamedActivity(comp.getName(), nm.rvalue().getType(), 0.0, prio.get(), scheduler ); + this->setNamedActivity(comp.getName(), nm.rvalue().getType(), 0.0, prio.get(), scheduler, cpu_affinity ); } } else if ( nm.rvalue().getType() == "SlaveActivity" ) { @@ -1444,6 +1460,22 @@ namespace OCL double period, int priority, int scheduler, const std::string& master_name) { + return setNamedActivity(comp_name, + act_type, + period, + priority, + scheduler, + ~0, // cpu_affinity == all CPUs + master_name); + } + + bool DeploymentComponent::setNamedActivity(const std::string& comp_name, + const std::string& act_type, + double period, int priority, + int scheduler, + unsigned cpu_affinity, + const std::string& master_name) + { // This helper function does not actualy set the activity, it just creates it and // stores it in comps[comp_name].act TaskContext* peer = 0; @@ -1487,10 +1519,10 @@ namespace OCL ActivityInterface* newact = 0; if ( act_type == "PeriodicActivity" && period != 0.0) - newact = new PeriodicActivity(scheduler, priority, period); + newact = new PeriodicActivity(scheduler, priority, period, cpu_affinity); else if ( act_type == "NonPeriodicActivity" && period == 0.0) - newact = new NonPeriodicActivity(scheduler, priority); + newact = new NonPeriodicActivity(scheduler, priority, cpu_affinity); else if ( act_type == "SlaveActivity" ) { if ( master_act == 0 ) @@ -1502,7 +1534,7 @@ namespace OCL } else if (act_type == "Activity") { - newact = new Activity(scheduler, priority, period, 0, comp_name); + newact = new Activity(scheduler, priority, period, cpu_affinity, 0, comp_name); } else if (act_type == "SequentialActivity") { diff --git a/deployment/DeploymentComponent.hpp b/deployment/DeploymentComponent.hpp index d2099aa..cd319c7 100644 --- a/deployment/DeploymentComponent.hpp +++ b/deployment/DeploymentComponent.hpp @@ -405,6 +405,8 @@ namespace OCL /** * (Re-)set the activity of a component. * + * CPU affinity defaults to all available CPUs + * * @param comp_name The name of the component to change. * @param act_type The Activity type: 'Activity', 'PeriodicActivity', 'NonPeriodicActivity' or 'SlaveActivity'. * @param priority The scheduler priority (OS dependent). @@ -421,6 +423,29 @@ namespace OCL int scheduler, const std::string& master_name = ""); /** + * (Re-)set the activity of a component. + * + * CPU affinity defaults to all available CPUs + * + * @param comp_name The name of the component to change. + * @param act_type The Activity type: 'Activity', 'PeriodicActivity', 'NonPeriodicActivity' or 'SlaveActivity'. + * @param priority The scheduler priority (OS dependent). + * @param period The period of the activity. + * @param scheduler The scheduler type \a ORO_SCHED_RT or \a ORO_SCHED_OTHER. + * @param cpu_affinity The prefered cpu to run on (a mask) + * @param master_name The name of the master component in case of a SlaveActivity with a master. + * + * @return false if one of the parameters does not match or if the + * component is running. + */ + bool setNamedActivity(const std::string& comp_name, + const std::string& act_type, + double period, int priority, + int scheduler, + unsigned cpu_affinity, + const std::string& master_name = ""); + + /** * Load a (partial) application XML configuration from disk. The * necessary components are located or loaded, but no * component configuration is yet applied. One can load diff --git a/deployment/tests/deployment.cpf b/deployment/tests/deployment.cpf index 80bb77f..9c55bd3 100644 --- a/deployment/tests/deployment.cpf +++ b/deployment/tests/deployment.cpf @@ -2,6 +2,19 @@ + + + + 0.41 + 1 + ORO_SCHED_RT + 3 + + 1 + 1 + + + diff --git a/deployment/tests/main.cpp b/deployment/tests/main.cpp index 3a18e31..d97d7b6 100644 --- a/deployment/tests/main.cpp +++ b/deployment/tests/main.cpp @@ -37,11 +37,13 @@ int ORO_main(int, char**) { MyTask t1("ComponentA"); MyTask t2("ComponentB"); + MyTask t3("ComponentC"); { DeploymentComponent dc; dc.addPeer( &t1 ); dc.addPeer( &t2 ); + dc.addPeer( &t3 ); dc.kickStart("deployment.cpf"); TaskBrowser tb(&dc); -- 1.7.4.4