diff options
Diffstat (limited to 'ace')
-rw-r--r-- | ace/OS_NS_Thread.cpp | 69 | ||||
-rw-r--r-- | ace/OS_NS_Thread.h | 36 | ||||
-rw-r--r-- | ace/README | 1 | ||||
-rw-r--r-- | ace/os_include/os_sched.h | 4 | ||||
-rw-r--r-- | ace/os_include/os_unistd.h | 10 |
5 files changed, 113 insertions, 7 deletions
diff --git a/ace/OS_NS_Thread.cpp b/ace/OS_NS_Thread.cpp index 46175b4396b..ded9b207aaa 100644 --- a/ace/OS_NS_Thread.cpp +++ b/ace/OS_NS_Thread.cpp @@ -23,7 +23,6 @@ ACE_RCSID (ace, #include "ace/Condition_T.h" #include "ace/Guard_T.h" - extern "C" void ACE_MUTEX_LOCK_CLEANUP_ADAPTER_NAME (void *args) { @@ -5015,6 +5014,74 @@ ACE_OS::thr_key_detach (ACE_thread_key_t key, void *) } int +ACE_OS::thr_get_affinity (ACE_hthread_t thr_id, + size_t cpu_set_size, + cpu_set_t * cpu_mask) +{ +#if defined (ACE_HAS_PTHREAD_GETAFFINITY_NP) + // Handle of the thread, which is NPTL thread-id, normally a big number + if (::pthread_getaffinity_np (thr_id, + cpu_set_size, + cpu_mask) != 0) + { + return -1; + } + return 0; +#elif defined (ACE_HAS_SCHED_GETAFFINITY) + // The process-id is expected as <thr_id>, which can be a thread-id of + // linux-thread, thus making binding to cpu of that particular thread only. + // If you are using this flag for NPTL-threads, however, please pass as a + // thr_id process id obtained by ACE_OS::getpid () + if (::sched_getaffinity(thr_id, + cpu_set_size, + cpu_mask) == -1) + { + return -1; + } + return 0; +#else + ACE_UNUSED_ARG (thr_id); + ACE_UNUSED_ARG (cpu_set_size); + ACE_UNUSED_ARG (cpu_mask); + ACE_NOTSUP_RETURN (-1); +#endif +} + +int +ACE_OS::thr_set_affinity (ACE_hthread_t thr_id, + size_t cpu_set_size, + const cpu_set_t * cpu_mask) +{ +#if defined (ACE_HAS_PTHREAD_SETAFFINITY_NP) + if (::pthread_setaffinity_np (thr_id, + cpu_set_size, + cpu_mask) != 0) + { + return -1; + } + return 0; +#elif defined (ACE_HAS_SCHED_SETAFFINITY) + // The process-id is expected as <thr_id>, which can be a thread-id of + // linux-thread, thus making binding to cpu of that particular thread only. + // If you are using this flag for NPTL-threads, however, please pass as a + // thr_id process id obtained by ACE_OS::getpid (), but whole process will bind your CPUs + // + if (::sched_setaffinity (thr_id, + cpu_set_size, + cpu_mask == -1) + { + return -1; + } + return 0; +#else + ACE_UNUSED_ARG (thr_id); + ACE_UNUSED_ARG (cpu_set_size); + ACE_UNUSED_ARG (cpu_mask); + ACE_NOTSUP_RETURN (-1); +#endif +} + +int ACE_OS::thr_key_used (ACE_thread_key_t key) { #if defined (ACE_WIN32) || defined (ACE_HAS_TSS_EMULATION) || (defined (ACE_PSOS) && defined (ACE_PSOS_HAS_TSS)) diff --git a/ace/OS_NS_Thread.h b/ace/OS_NS_Thread.h index 4e19de31800..04b222735a9 100644 --- a/ace/OS_NS_Thread.h +++ b/ace/OS_NS_Thread.h @@ -29,6 +29,7 @@ # include "ace/Basic_Types.h" # include "ace/Default_Constants.h" # include "ace/os_include/os_pthread.h" +# include "ace/os_include/os_sched.h" # include "ace/Base_Thread_Adapter.h" # include "ace/os_include/sys/os_sem.h" # include "ace/os_include/os_semaphore.h" @@ -1744,7 +1745,40 @@ namespace ACE_OS { ACE_THR_FUNC_RETURN *status); /** - * @note the "inst" arge is deprecated. It will be ignored. + * Get the thread affinity + * + * @param thr_id For NPTL-threads, when ACE_HAS_PTHREAD_SETAFFINITY_NP + * defined, this is the thread-id. For linux-threads, when + * ACE_HAS_SCHED_SETAFFINITY defined, it expects a process-id. Since for + * linux-threads a thread is seen as a process, it does the job. + * @param cpu_set_size The size of the cpu_mask + * @param cpu_mask Is a bitmask of CPUs to bind to, e.g value 1 binds the + * thread to the "CPU 0", etc + */ + extern ACE_Export + int thr_get_affinity (ACE_hthread_t id, + size_t cpu_set_size, + cpu_set_t * cpu_mask); + + + /** + * Set the thread affinity + * + * @param thr_id For NPTL-threads, when ACE_HAS_PTHREAD_SETAFFINITY_NP + * defined, this is the thread-id. For linux-threads, when + * ACE_HAS_SCHED_SETAFFINITY defined, it expects a process-id. Since for + * linux-threads a thread is seen as a process, it does the job. + * @param cpu_set_size The size of the cpu_mask + * @param cpu_mask Is a bitmask of CPUs to bind to, e.g value 1 binds the + * thread to the "CPU 0", etc + */ + extern ACE_Export + int thr_set_affinity (ACE_hthread_t thr_id, + size_t cpu_set_size, + const cpu_set_t * cpu_mask); + + /** + * @note the "inst" arg is deprecated. It will be ignored. */ extern ACE_Export int thr_key_detach (ACE_thread_key_t key, void * inst); diff --git a/ace/README b/ace/README index e0864f58a82..b3775f725c7 100644 --- a/ace/README +++ b/ace/README @@ -153,6 +153,7 @@ ACE_THREAD_MANAGER_USES_SAFE_SPAWN Disable the "check before lock" feature macro avoids a potential race condition on platforms with aggressive read/write reordering. +ACE_HAS_CPU_SET_T Platform delivers cpu_set_t. ACE_HAS_PRIOCNTL OS has priocntl (2). ACE_HAS_RECURSIVE_MUTEXES Mutexes are inherently recursive (e.g., Win32) diff --git a/ace/os_include/os_sched.h b/ace/os_include/os_sched.h index ad5f0b2c4d6..bec7b9f59bd 100644 --- a/ace/os_include/os_sched.h +++ b/ace/os_include/os_sched.h @@ -36,6 +36,10 @@ extern "C" { #endif /* __cplusplus */ +#if !defined (ACE_HAS_CPU_SET_T) +typedef ACE_UINT32 cpu_set_t; +#endif + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/ace/os_include/os_unistd.h b/ace/os_include/os_unistd.h index 8a9324cd741..f26efe878cb 100644 --- a/ace/os_include/os_unistd.h +++ b/ace/os_include/os_unistd.h @@ -134,11 +134,11 @@ extern "C" #endif /* _LARGEFILE64_SOURCE */ #if defined (__BORLANDC__) -# define _chdir chdir -# undef _access -# define _access access # if (__BORLANDC__ <= 0x540) # define _getcwd getcwd +# define _chdir chdir +# undef _access +# define _access access # endif # define _isatty isatty #endif /* __BORLANDC__ */ @@ -169,11 +169,11 @@ extern "C" #if defined (ACE_LACKS_SWAB_PROTOTYPE) void swab(const void *, void *, ssize_t); #endif /* ACE_LACKS_SWAB_PROTOTYPE */ - + #if defined (ACE_LACKS_GETOPT_PROTOTYPE) int getopt(int, char * const [], const char *); #endif /* ACE_LACKS_GETOPT_PROTOTYPE */ - + #ifdef __cplusplus } #endif /* __cplusplus */ |