From d5b91248fa5fef0d3a11b9da3546cf9f1023192a Mon Sep 17 00:00:00 2001 From: cristianrosa Date: Thu, 20 Jan 2011 15:45:53 +0000 Subject: [PATCH] Code refactor: move the functions associated to the request enabledness to mc_request.c git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9463 48e7efb5-ca39-0410-a469-dd3cf9ba447f --- src/mc/mc_dpor.c | 4 +- src/mc/mc_global.c | 4 +- src/mc/mc_request.c | 74 +++++++++++++++++++++++++++++++++++++ src/mc/mc_state.c | 6 +-- src/mc/private.h | 6 ++- src/simix/process_private.h | 1 - src/simix/smurf_private.h | 3 -- src/simix/smx_process.c | 8 ---- src/simix/smx_smurf.c | 65 -------------------------------- 9 files changed, 86 insertions(+), 85 deletions(-) diff --git a/src/mc/mc_dpor.c b/src/mc/mc_dpor.c index 7b481c9305..ee8abeb784 100644 --- a/src/mc/mc_dpor.c +++ b/src/mc/mc_dpor.c @@ -32,7 +32,7 @@ void MC_dpor_init() MC_SET_RAW_MEM; /* Get an enabled process and insert it in the interleave set of the initial state */ xbt_swag_foreach(process, simix_global->process_list){ - if(SIMIX_process_is_enabled(process)){ + if(MC_process_is_enabled(process)){ MC_state_interleave_process(initial_state, process); break; } @@ -105,7 +105,7 @@ void MC_dpor(void) /* Get an enabled process and insert it in the interleave set of the next state */ xbt_swag_foreach(process, simix_global->process_list){ - if(SIMIX_process_is_enabled(process)){ + if(MC_process_is_enabled(process)){ MC_state_interleave_process(next_state, process); break; } diff --git a/src/mc/mc_global.c b/src/mc/mc_global.c index 7c77d3788d..4ac7758bd9 100644 --- a/src/mc/mc_global.c +++ b/src/mc/mc_global.c @@ -78,7 +78,7 @@ void MC_wait_for_requests(void) do { SIMIX_context_runall(simix_global->process_to_run); while((req = SIMIX_request_pop())){ - if(!SIMIX_request_is_visible(req)) + if(!MC_request_is_visible(req)) SIMIX_request_pre(req, 0); else if(XBT_LOG_ISENABLED(mc_global, xbt_log_priority_debug)){ req_str = MC_request_to_string(req); @@ -97,7 +97,7 @@ int MC_deadlock_check() deadlock = TRUE; xbt_swag_foreach(process, simix_global->process_list){ if(process->request.call != REQ_NO_REQ - && SIMIX_request_is_enabled(&process->request)){ + && MC_request_is_enabled(&process->request)){ deadlock = FALSE; break; } diff --git a/src/mc/mc_request.c b/src/mc/mc_request.c index e50fe39b84..ac8840e521 100644 --- a/src/mc/mc_request.c +++ b/src/mc/mc_request.c @@ -145,3 +145,77 @@ unsigned int MC_request_testany_fail(smx_req_t req) return TRUE; } + +int MC_request_is_visible(smx_req_t req) +{ + return req->call == REQ_COMM_ISEND + || req->call == REQ_COMM_IRECV + || req->call == REQ_COMM_WAIT + || req->call == REQ_COMM_WAITANY + || req->call == REQ_COMM_TEST + || req->call == REQ_COMM_TESTANY; +} + +int MC_request_is_enabled(smx_req_t req) +{ + unsigned int index = 0; + smx_action_t act; + + switch (req->call) { + + case REQ_COMM_WAIT: + /* FIXME: check also that src and dst processes are not suspended */ + + /* If there is a timeout it will be always enabled because, if the + * communication is not ready, it can timeout. + * This avoids false positives on dead-locks */ + if(req->comm_wait.timeout >= 0) + return TRUE; + + act = req->comm_wait.comm; + return (act->comm.src_proc && act->comm.dst_proc); + break; + + case REQ_COMM_WAITANY: + xbt_dynar_foreach(req->comm_waitany.comms, index, act) { + if (act->comm.src_proc && act->comm.dst_proc){ + return TRUE; + } + } + return FALSE; + break; + + default: + return TRUE; + } +} + +int MC_request_is_enabled_by_idx(smx_req_t req, unsigned int idx) +{ + smx_action_t act; + + switch (req->call) { + + case REQ_COMM_WAIT: + /* FIXME: check also that src and dst processes are not suspended */ + act = req->comm_wait.comm; + return (act->comm.src_proc && act->comm.dst_proc); + break; + + case REQ_COMM_WAITANY: + act = xbt_dynar_get_as(req->comm_waitany.comms, idx, smx_action_t); + return (act->comm.src_proc && act->comm.dst_proc); + break; + + default: + return TRUE; + } +} + +int MC_process_is_enabled(smx_process_t process) +{ + if (process->request.call != REQ_NO_REQ && MC_request_is_enabled(&process->request)) + return TRUE; + + return FALSE; +} diff --git a/src/mc/mc_state.c b/src/mc/mc_state.c index 5d6e506c30..9a5db9f1ee 100644 --- a/src/mc/mc_state.c +++ b/src/mc/mc_state.c @@ -116,12 +116,12 @@ smx_req_t MC_state_get_request(mc_state_t state, int *value) procstate = &state->proc_status[process->pid]; if(procstate->state == MC_INTERLEAVE){ - if(SIMIX_process_is_enabled(process)){ + if(MC_process_is_enabled(process)){ switch(process->request.call){ case REQ_COMM_WAITANY: *value = -1; while(procstate->interleave_count < xbt_dynar_length(process->request.comm_waitany.comms)){ - if(SIMIX_request_is_enabled_by_idx(&process->request, procstate->interleave_count++)){ + if(MC_request_is_enabled_by_idx(&process->request, procstate->interleave_count++)){ *value = procstate->interleave_count-1; break; } @@ -143,7 +143,7 @@ smx_req_t MC_state_get_request(mc_state_t state, int *value) } while(procstate->interleave_count < xbt_dynar_length(process->request.comm_testany.comms)){ - if(SIMIX_request_is_enabled_by_idx(&process->request, procstate->interleave_count++)){ + if(MC_request_is_enabled_by_idx(&process->request, procstate->interleave_count++)){ *value = procstate->interleave_count - 1; break; } diff --git a/src/mc/private.h b/src/mc/private.h index a21924521c..359560edab 100644 --- a/src/mc/private.h +++ b/src/mc/private.h @@ -53,7 +53,11 @@ void MC_dump_stack(xbt_fifo_t stack); int MC_request_depend(smx_req_t req1, smx_req_t req2); char* MC_request_to_string(smx_req_t req); unsigned int MC_request_testany_fail(smx_req_t req); -int MC_waitany_is_enabled_by_comm(smx_req_t req, unsigned int comm); +/*int MC_waitany_is_enabled_by_comm(smx_req_t req, unsigned int comm);*/ +int MC_request_is_visible(smx_req_t req); +int MC_request_is_enabled(smx_req_t req); +int MC_request_is_enabled_by_idx(smx_req_t req, unsigned int idx); +int MC_process_is_enabled(smx_process_t process); /********************************** DPOR **************************************/ void MC_dpor_init(void); diff --git a/src/simix/process_private.h b/src/simix/process_private.h index b7fc26b7b9..e1c44b0a99 100644 --- a/src/simix/process_private.h +++ b/src/simix/process_private.h @@ -69,7 +69,6 @@ void SIMIX_process_set_data(smx_process_t process, void *data); smx_host_t SIMIX_process_get_host(smx_process_t process); const char* SIMIX_process_get_name(smx_process_t process); int SIMIX_process_is_suspended(smx_process_t process); -int SIMIX_process_is_enabled(smx_process_t process); xbt_dict_t SIMIX_process_get_properties(smx_process_t process); void SIMIX_pre_process_sleep(smx_req_t req); smx_action_t SIMIX_process_sleep(smx_process_t process, double duration); diff --git a/src/simix/smurf_private.h b/src/simix/smurf_private.h index 7667dc7338..2d6c1bed56 100644 --- a/src/simix/smurf_private.h +++ b/src/simix/smurf_private.h @@ -476,9 +476,6 @@ smx_req_t SIMIX_request_pop(void); void SIMIX_request_answer(smx_req_t); void SIMIX_request_pre(smx_req_t, int); void SIMIX_request_post(smx_action_t); -int SIMIX_request_is_visible(smx_req_t req); -int SIMIX_request_is_enabled(smx_req_t req); -int SIMIX_request_is_enabled_by_idx(smx_req_t req, unsigned int idx); XBT_INLINE smx_req_t SIMIX_req_mine(void); #endif diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index 094a05d67c..ccd61f541b 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -405,14 +405,6 @@ int SIMIX_process_is_suspended(smx_process_t process) return process->suspended; } -int SIMIX_process_is_enabled(smx_process_t process) -{ - if (process->request.call != REQ_NO_REQ && SIMIX_request_is_enabled(&process->request)) - return TRUE; - - return FALSE; -} - xbt_dict_t SIMIX_process_get_properties(smx_process_t process) { return process->properties; diff --git a/src/simix/smx_smurf.c b/src/simix/smx_smurf.c index c873e2ca2c..f80b6ce2d1 100644 --- a/src/simix/smx_smurf.c +++ b/src/simix/smx_smurf.c @@ -71,71 +71,6 @@ void SIMIX_request_answer(smx_req_t req) } } -int SIMIX_request_is_visible(smx_req_t req) -{ - return req->call == REQ_COMM_ISEND - || req->call == REQ_COMM_IRECV - || req->call == REQ_COMM_WAIT - || req->call == REQ_COMM_WAITANY - || req->call == REQ_COMM_TEST - || req->call == REQ_COMM_TESTANY; -} - -int SIMIX_request_is_enabled(smx_req_t req) -{ - unsigned int index = 0; - smx_action_t act; - - switch (req->call) { - - case REQ_COMM_WAIT: - /* FIXME: check also that src and dst processes are not suspended */ - /* If there is a timeout it will be always enabled because, if the - * communication is not ready, it can timeout. - * This avoids false positives on dead-locks */ - if(req->comm_wait.timeout >= 0) - return TRUE; - - act = req->comm_wait.comm; - return (act->comm.src_proc && act->comm.dst_proc); - break; - - case REQ_COMM_WAITANY: - xbt_dynar_foreach(req->comm_waitany.comms, index, act) { - if (act->comm.src_proc && act->comm.dst_proc){ - return TRUE; - } - } - return FALSE; - break; - - default: - return TRUE; - } -} - -int SIMIX_request_is_enabled_by_idx(smx_req_t req, unsigned int idx) -{ - smx_action_t act; - - switch (req->call) { - - case REQ_COMM_WAIT: - /* FIXME: check also that src and dst processes are not suspended */ - act = req->comm_wait.comm; - return (act->comm.src_proc && act->comm.dst_proc); - break; - - case REQ_COMM_WAITANY: - act = xbt_dynar_get_as(req->comm_waitany.comms, idx, smx_action_t); - return (act->comm.src_proc && act->comm.dst_proc); - break; - - default: - return TRUE; - } -} - void SIMIX_request_pre(smx_req_t req, int value) { switch (req->call) { -- 2.20.1