From: cristianrosa Date: Tue, 1 Feb 2011 12:37:27 +0000 (+0000) Subject: Replace the req_todo heap with a table of swags one for each running thread. X-Git-Tag: v3.6_beta2~379 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/8ac6fbb93b5f76c67840f90d011e4845c0b6f318 Replace the req_todo heap with a table of swags one for each running thread. git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9550 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- diff --git a/src/simix/smurf_private.h b/src/simix/smurf_private.h index f7d17fc682..3bc9d09f87 100644 --- a/src/simix/smurf_private.h +++ b/src/simix/smurf_private.h @@ -119,7 +119,7 @@ SIMIX_REQ_LIST * \brief Represents a SIMIX request. */ typedef struct s_smx_req { - s_xbt_swag_hookup_t state_hookup; + s_xbt_swag_hookup_t reqtable_hookup; e_smx_req_t call; smx_process_t issuer; @@ -504,6 +504,7 @@ typedef struct s_smx_req { void SIMIX_request_init(void); void SIMIX_request_destroy(void); +xbt_swag_t SIMIX_request_get_reqlist(int thread_pid); void SIMIX_request_push(void); smx_req_t SIMIX_request_pop(void); void SIMIX_request_answer(smx_req_t); diff --git a/src/simix/smx_smurf.c b/src/simix/smx_smurf.c index f671b723a9..6b0d817b12 100644 --- a/src/simix/smx_smurf.c +++ b/src/simix/smx_smurf.c @@ -5,21 +5,34 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_smurf, simix, "Logging specific to SIMIX (SMURF)"); -/* Requests to handle at the end of this round of scheduling user processes */ -static xbt_heap_t req_todo; -/* to protect the write actions in the heap */ -static xbt_os_mutex_t sync_req_positions; +/* Tables with the requests to handle at the end of this round of scheduling + * user processes. There is one for each thread of execution. */ +static xbt_swag_t *req_lists; void SIMIX_request_init(void) { - req_todo = xbt_heap_new(5,NULL); - sync_req_positions = xbt_os_mutex_init(); + s_smx_req_t req; + int i, nthreads = SIMIX_context_get_parallel_threads(); + + req_lists = xbt_new0(xbt_swag_t, nthreads); + for(i=0; i < nthreads; i++) + req_lists[i] = xbt_swag_new(xbt_swag_offset(req, reqtable_hookup)); + } void SIMIX_request_destroy(void) { - xbt_heap_free(req_todo); - xbt_os_mutex_destroy(sync_req_positions); + int i, nthreads = SIMIX_context_get_parallel_threads(); + + for(i=0; i < nthreads; i++) + xbt_swag_free(req_lists[i]); + + xbt_free(req_lists); +} + +xbt_swag_t SIMIX_request_get_reqlist(int thread_pid) +{ + return req_lists[thread_pid]; } /* FIXME: we may want to save the initialization of issuer... */ @@ -30,18 +43,18 @@ XBT_INLINE smx_req_t SIMIX_req_mine() { void SIMIX_request_push() { + xbt_swag_t req_table; smx_process_t issuer = SIMIX_process_self(); + if (issuer != simix_global->maestro_process){ issuer->request.issuer = issuer; + req_table = SIMIX_request_get_reqlist(SIMIX_context_get_thread_id()); + + xbt_swag_insert_at_tail(&issuer->request, req_table); - if (SIMIX_context_is_parallel()) - xbt_os_mutex_acquire(sync_req_positions); - xbt_heap_push(req_todo,&issuer->request,issuer->pid); - DEBUG4("Pushed request %s (%d) of %s; now %d requests waiting", + DEBUG3("Pushed request %s (%d) of %s", SIMIX_request_name(issuer->request.call), issuer->request.call, - issuer->name,xbt_heap_size(req_todo)); - if (SIMIX_context_is_parallel()) - xbt_os_mutex_release(sync_req_positions); + issuer->name); DEBUG3("Yield process '%s' on request of type %s (%d)", issuer->name, SIMIX_request_name(issuer->request.call), issuer->request.call); @@ -53,13 +66,21 @@ void SIMIX_request_push() smx_req_t SIMIX_request_pop(void) { - smx_req_t req = xbt_heap_pop(req_todo); - if(req) - DEBUG4("Popped request %s (%d) of %s; now %d requests waiting", - SIMIX_request_name(req->issuer->request.call), - req->issuer->request.call, - req->issuer->name,xbt_heap_size(req_todo)); - return req; + int i; + smx_req_t req = NULL; + int nthreads = SIMIX_context_get_parallel_threads(); + + for(i=0; i < nthreads; i++){ + if((req = xbt_swag_extract(req_lists[i]))){ + DEBUG3("Popped request %s (%d) of %s", + SIMIX_request_name(req->issuer->request.call), + req->issuer->request.call, + req->issuer->name); + return req; + } + } + + return NULL; } void SIMIX_request_answer(smx_req_t req)