diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2010-07-26 01:16:08 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2010-07-26 01:16:08 +0000 |
commit | 664cb216b6151289d6f13b776136ec7809e6bc63 (patch) | |
tree | 15f6cda3943de3df1cab610586adced87b2e943d | |
parent | 4ea92faf7ff5058b15fa400b2669414d1ae80259 (diff) | |
download | ATCD-664cb216b6151289d6f13b776136ec7809e6bc63.tar.gz |
Mon Jul 26 01:14:21 UTC 2010 William R. Otte <wotte@dre.vanderbilt.edu>
* DAnCE/LocalityManager/Configuration/CPU_Affinity.h:
* DAnCE/LocalityManager/Configuration/CPU_Affinity.cpp:
* DAnCE/LocalityManager/Configuration/CPU_Affinity_export.h:
* DAnCE/LocalityManager/Configuration/Configuration.mpc:
* DAnCE/LocalityManager/Configuration/Process_Name.cpp:
* DAnCE/LocalityManager/Daemon/Locality_Manager_Impl.cpp:
CPU Affinity configuration plugin. Currently works on Linux
kernel 2.5.8 or later.
7 files changed, 257 insertions, 10 deletions
diff --git a/CIAO/ChangeLog b/CIAO/ChangeLog index 9139109bb97..dc1d213d88b 100644 --- a/CIAO/ChangeLog +++ b/CIAO/ChangeLog @@ -1,3 +1,15 @@ +Mon Jul 26 01:14:21 UTC 2010 William R. Otte <wotte@dre.vanderbilt.edu> + + * DAnCE/LocalityManager/Configuration/CPU_Affinity.h: + * DAnCE/LocalityManager/Configuration/CPU_Affinity.cpp: + * DAnCE/LocalityManager/Configuration/CPU_Affinity_export.h: + * DAnCE/LocalityManager/Configuration/Configuration.mpc: + * DAnCE/LocalityManager/Configuration/Process_Name.cpp: + * DAnCE/LocalityManager/Daemon/Locality_Manager_Impl.cpp: + + CPU Affinity configuration plugin. Currently works on Linux + kernel 2.5.8 or later. + Sat Jul 24 07:04:38 UTC 2010 Marcel Smit <msmit@remedy.nl> * connectors/dds4ccm/tests/QueryCondition/DDS/Base/Base.idl: diff --git a/CIAO/DAnCE/LocalityManager/Configuration/CPU_Affinity.cpp b/CIAO/DAnCE/LocalityManager/Configuration/CPU_Affinity.cpp new file mode 100644 index 00000000000..d2175cbed80 --- /dev/null +++ b/CIAO/DAnCE/LocalityManager/Configuration/CPU_Affinity.cpp @@ -0,0 +1,120 @@ +// $Id$ + +#include "CPU_Affinity.h" +#include "DAnCE/DAnCE_PropertiesC.h" +#include "Deployment/Deployment_StartErrorC.h" + +#include "DAnCE/Logger/Log_Macros.h" + +#if defined (LINUX_VERSION_CODE) && defined (KERNEL_VERSION) +# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,8)) +#include <sched.h> +#include <sstream> +#include "ace/Auto_Ptr.h" +#include "ace/Tokenizer_T.h" + +#endif +#endif + +namespace DAnCE +{ + CPU_Affinity::CPU_Affinity (void) + { + } + + // Implementation skeleton destructor + CPU_Affinity::~CPU_Affinity (void) + { + } + + char * CPU_Affinity::type (void) + { + return CORBA::string_dup (DAnCE::DANCE_LM_PROCESSNAME); + } + + void CPU_Affinity::configure (const ::Deployment::Property & prop) + { +#if defined (LINUX_VERSION_CODE) && defined (KERNEL_VERSION) +# if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,8)) + char *affinity; + + if (! (prop.value >>= CORBA::Any::to_string (affinity, 0))) + { + DANCE_ERROR (1, (LM_ERROR, DLINFO + ACE_TEXT ("CPU_Affinity::configure - ") + ACE_TEXT ("Unable to extract CPU affinity string"))); + throw ::Deployment::StartError (prop.name.in (), + "Unable to extract CPU affinity string"); + } + + ACE_Auto_Basic_Array_Ptr<char> safe_affinity (affinity); + + ACE_Tokenizer_T<char> tokenizer(affinity); + tokenizer.delimiter (','); + + char *token; + cpu_set_t mask; + + CPU_ZERO (&mask); + + while ((token = tokenizer.next ())) + { + int i = ACE_OS::atoi (token); + + if (i >= 0) + { + CPU_SET (i, &mask); + } + else + { + DANCE_ERROR (1, (LM_ERROR, DLINFO + ACE_TEXT ("CPU_Affinity::configure - ") + ACE_TEXT ("All affinity values should be greater than 0"))); + throw ::Deployment::StartError (prop.name.in (), + "All affinity values should be greater than 0"); + } + } + + pid_t pid = ACE_OS::getpid (); + + int retval = ::sched_setaffinity (pid, + sizeof (cpu_set_t), + &mask); + + if (retval != 0) + { + std::stringstream str; + ACE_Auto_Basic_Array_Ptr<char> safe_error (ACE_OS::strerror (ACE_OS::last_error ())); + + str << "Unable to set CPU affinity to <" << affinity << ">: " + << safe_error.get (); + std::string message = str.str (); + + DANCE_ERROR (1, (LM_ERROR, DLINFO + ACE_TEXT ("CPU_Affinity::configure - %C\n"), + message.c_str ())); + + throw ::Deployment::StartError (prop.name.in (), + message.c_str ()); + } +#endif +#endif + + throw ::Deployment::StartError (prop.name.in (), + "CPU Affinity not supported on this platform"); + } +} + +extern "C" +{ + DAnCE::LocalityConfiguration_ptr create_CPU_Affinity (void) + { + DAnCE::LocalityConfiguration_ptr retval (0); + + ACE_NEW_THROW_EX (retval, + DAnCE::CPU_Affinity (), + CORBA::NO_MEMORY ()); + + return retval; + } +} diff --git a/CIAO/DAnCE/LocalityManager/Configuration/CPU_Affinity.h b/CIAO/DAnCE/LocalityManager/Configuration/CPU_Affinity.h new file mode 100644 index 00000000000..7fdf3198c65 --- /dev/null +++ b/CIAO/DAnCE/LocalityManager/Configuration/CPU_Affinity.h @@ -0,0 +1,50 @@ +// -*- C++ -*- +// $Id$ + +/** + * @file CPU_Affinity.h + * @author William R. Otte <wotte@dre.vanderbilt.edu> + * + * A simple configuration plugin that will change the process + * name as represented by PS. It is only functional on Linux + */ + +#ifndef CPU_AFFINITY_H +#define CPU_AFFINITY_H + +#include /**/ "ace/pre.h" + +#include "DAnCE/DAnCE_LocalityManagerC.h" +#include "tao/LocalObject.h" + +#include "CPU_Affinity_export.h" + +namespace DAnCE +{ + class CPU_Affinity_Export CPU_Affinity + : public virtual DAnCE::LocalityConfiguration, + public virtual ::CORBA::LocalObject + { + public: + // Constructor + CPU_Affinity (void); + + // Destructor + virtual ~CPU_Affinity (void); + + virtual + char * type (void); + + virtual + void configure (const ::Deployment::Property & prop); + }; +} + +extern "C" +{ + DAnCE::LocalityConfiguration_ptr + CPU_Affinity_Export create_CPU_Affinity (void); +} +#include /**/ "ace/post.h" + +#endif diff --git a/CIAO/DAnCE/LocalityManager/Configuration/CPU_Affinity_export.h b/CIAO/DAnCE/LocalityManager/Configuration/CPU_Affinity_export.h new file mode 100644 index 00000000000..551054557d7 --- /dev/null +++ b/CIAO/DAnCE/LocalityManager/Configuration/CPU_Affinity_export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl CPU_Affinity +// ------------------------------ +#ifndef CPU_AFFINITY_EXPORT_H +#define CPU_AFFINITY_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (CPU_AFFINITY_HAS_DLL) +# define CPU_AFFINITY_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && CPU_AFFINITY_HAS_DLL */ + +#if !defined (CPU_AFFINITY_HAS_DLL) +# define CPU_AFFINITY_HAS_DLL 1 +#endif /* ! CPU_AFFINITY_HAS_DLL */ + +#if defined (CPU_AFFINITY_HAS_DLL) && (CPU_AFFINITY_HAS_DLL == 1) +# if defined (CPU_AFFINITY_BUILD_DLL) +# define CPU_Affinity_Export ACE_Proper_Export_Flag +# define CPU_AFFINITY_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define CPU_AFFINITY_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* CPU_AFFINITY_BUILD_DLL */ +# define CPU_Affinity_Export ACE_Proper_Import_Flag +# define CPU_AFFINITY_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define CPU_AFFINITY_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* CPU_AFFINITY_BUILD_DLL */ +#else /* CPU_AFFINITY_HAS_DLL == 1 */ +# define CPU_Affinity_Export +# define CPU_AFFINITY_SINGLETON_DECLARATION(T) +# define CPU_AFFINITY_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* CPU_AFFINITY_HAS_DLL == 1 */ + +// Set CPU_AFFINITY_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (CPU_AFFINITY_NTRACE) +# if (ACE_NTRACE == 1) +# define CPU_AFFINITY_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define CPU_AFFINITY_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !CPU_AFFINITY_NTRACE */ + +#if (CPU_AFFINITY_NTRACE == 1) +# define CPU_AFFINITY_TRACE(X) +#else /* (CPU_AFFINITY_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define CPU_AFFINITY_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (CPU_AFFINITY_NTRACE == 1) */ + +#endif /* CPU_AFFINITY_EXPORT_H */ + +// End of auto generated file. diff --git a/CIAO/DAnCE/LocalityManager/Configuration/Configuration.mpc b/CIAO/DAnCE/LocalityManager/Configuration/Configuration.mpc index 3e39c4f5264..3a3811b71f1 100644 --- a/CIAO/DAnCE/LocalityManager/Configuration/Configuration.mpc +++ b/CIAO/DAnCE/LocalityManager/Configuration/Configuration.mpc @@ -1,11 +1,14 @@ +// $Id$ project (DAnCE_LM_Config_Plugins) : dance_deployment_stub, dance_stub, dance_lib, dance_output { dynamicflags += PROCESS_NAME_BUILD_DLL Source_Files { Process_Name.cpp + CPU_Affinity.cpp } Header_Files { Process_Name.h + CPU_Affinity.h } -}
\ No newline at end of file +} diff --git a/CIAO/DAnCE/LocalityManager/Configuration/Process_Name.cpp b/CIAO/DAnCE/LocalityManager/Configuration/Process_Name.cpp index e48dfbff3e4..d1d761595e4 100644 --- a/CIAO/DAnCE/LocalityManager/Configuration/Process_Name.cpp +++ b/CIAO/DAnCE/LocalityManager/Configuration/Process_Name.cpp @@ -47,8 +47,8 @@ namespace DAnCE { char *tmp (0); ACE_NEW_THROW_EX (tmp, - char[16], - CORBA::NO_MEMORY ()); + char[16], + CORBA::NO_MEMORY ()); safe_array.reset (tmp); diff --git a/CIAO/DAnCE/LocalityManager/Daemon/Locality_Manager_Impl.cpp b/CIAO/DAnCE/LocalityManager/Daemon/Locality_Manager_Impl.cpp index 6720f004f88..aa587404063 100644 --- a/CIAO/DAnCE/LocalityManager/Daemon/Locality_Manager_Impl.cpp +++ b/CIAO/DAnCE/LocalityManager/Daemon/Locality_Manager_Impl.cpp @@ -151,9 +151,13 @@ namespace DAnCE } PLUGIN_MANAGER::instance ()->register_configuration_plugin ( - ACE_TEXT_CHAR_TO_TCHAR ("DAnCE_LM_Config_Plugins"), + ACE_TEXT_CHAR_TO_TCHAR ("DAnCE_LM_Config_Plugins"), ACE_TEXT_CHAR_TO_TCHAR ("create_Process_Name")); + PLUGIN_MANAGER::instance ()->register_configuration_plugin ( + ACE_TEXT_CHAR_TO_TCHAR ("DAnCE_LM_Config_Plugins"), + ACE_TEXT_CHAR_TO_TCHAR ("create_CPU_Affinity")); + if (this->props_) { if (DAnCE::Utility::get_property_value (DAnCE::LOCALITY_TIMEOUT, @@ -170,18 +174,18 @@ namespace DAnCE { DANCE_DEBUG (8, (LM_DEBUG, DLINFO ACE_TEXT ("LocalityManager_i::init - ") - ACE_TEXT ("Looking up configuration handler for <%C>\n"), - this->props_[i].name.in ())); + ACE_TEXT ("Looking up configuration handler for <%C>\n"), + this->props_[i].name.in ())); ::DAnCE::LocalityConfiguration_var config = PLUGIN_MANAGER::instance ()->get_configuration_handler (this->props_[i].name.in ()); if (config.in ()) { - DANCE_DEBUG (6, (LM_DEBUG, DLINFO - ACE_TEXT ("LocalityManager_i::init - ") - ACE_TEXT ("Invoking configuration handler for <%C>\n"), - this->props_[i].name.in ())); + DANCE_DEBUG (6, (LM_DEBUG, DLINFO + ACE_TEXT ("LocalityManager_i::init - ") + ACE_TEXT ("Invoking configuration handler for <%C>\n"), + this->props_[i].name.in ())); config->configure (this->props_[i]); } } |