From: etortilopez Date: Mon, 18 Aug 2014 13:26:34 +0000 (+0200) Subject: added option to bind threads to physical cores X-Git-Tag: v3_12~850^2~13^2~1 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/4cebfd8d6fe0ba78ca3aa3a08df69eeebf290793 added option to bind threads to physical cores --- diff --git a/include/xbt/xbt_os_thread.h b/include/xbt/xbt_os_thread.h index 655c8826ff..ebf1b6fccd 100644 --- a/include/xbt/xbt_os_thread.h +++ b/include/xbt/xbt_os_thread.h @@ -51,6 +51,11 @@ XBT_PUBLIC(xbt_os_thread_t) xbt_os_thread_create(const char *name, void *param, void *data); +//#define CORE_BINDING //Uncomment this to enable binding of threads to physical cores. Only Linux. +#ifdef CORE_BINDING +XBT_PUBLIC(int) xbt_os_thread_bind(xbt_os_thread_t thread, int cpu); +#endif + XBT_PUBLIC(void) xbt_os_thread_exit(int *retcode); XBT_PUBLIC(void) xbt_os_thread_detach(xbt_os_thread_t thread); XBT_PUBLIC(xbt_os_thread_t) xbt_os_thread_self(void); diff --git a/src/msg/msg_process.c b/src/msg/msg_process.c index 70725e7341..a14e8828be 100644 --- a/src/msg/msg_process.c +++ b/src/msg/msg_process.c @@ -53,7 +53,6 @@ void MSG_process_cleanup_from_SIMIX(smx_process_t smx_proc) // free the MSG process xbt_free(msg_proc); - SIMIX_process_cleanup(smx_proc); } /* This function creates a MSG process. It has the prototype enforced by SIMIX_function_register_process_create */ diff --git a/src/xbt/parmap.c b/src/xbt/parmap.c index 1b0ab3d793..b5d9025ff2 100644 --- a/src/xbt/parmap.c +++ b/src/xbt/parmap.c @@ -128,12 +128,23 @@ xbt_parmap_t xbt_parmap_new(unsigned int num_workers, e_xbt_parmap_mode_t mode) /* Create the pool of worker threads */ xbt_parmap_thread_data_t data; parmap->workers[0] = NULL; +#ifdef CORE_BINDING + unsigned int core_bind = 0; +#endif for (i = 1; i < num_workers; i++) { data = xbt_new0(s_xbt_parmap_thread_data_t, 1); data->parmap = parmap; data->worker_id = i; parmap->workers[i] = xbt_os_thread_create(NULL, xbt_parmap_worker_main, data, NULL); +#ifdef CORE_BINDING + xbt_os_thread_bind(parmap->workers[i], core_bind); + if(core_bind!=xbt_os_get_numcores()){ + core_bind++; + } else { + core_bind = 0; + } +#endif } return parmap; } diff --git a/src/xbt/xbt_os_thread.c b/src/xbt/xbt_os_thread.c index c9dd6910b9..b97d90e675 100644 --- a/src/xbt/xbt_os_thread.c +++ b/src/xbt/xbt_os_thread.c @@ -26,6 +26,11 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_sync_os, xbt, #include #include +#ifdef CORE_BINDING +#define _GNU_SOURCE +#include +#endif + #ifdef HAVE_MUTEX_TIMEDLOCK /* redefine the function header since we fail to get this from system headers on amd (at least) */ int pthread_mutex_timedlock(pthread_mutex_t * mutex, @@ -193,6 +198,18 @@ xbt_os_thread_t xbt_os_thread_create(const char *name, } +#ifdef CORE_BINDING +int xbt_os_thread_bind(xbt_os_thread_t thread, int cpu){ + pthread_t pthread = thread->t; + int errcode = 0; + cpu_set_t cpuset; + CPU_ZERO(&cpuset); + CPU_SET(cpu, &cpuset); + errcode = pthread_setaffinity_np(pthread, sizeof(cpu_set_t), &cpuset); + return errcode; +} +#endif + void xbt_os_thread_setstacksize(int stack_size) { size_t alignment[] = {