From: Paul Bédaride Date: Wed, 19 Jun 2013 11:42:14 +0000 (+0200) Subject: Merge branch 'master' into hypervisor X-Git-Tag: v3_11_beta~297^2^2~28^2~1 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/12c0f182635ed71b370d608b5b9a614153765cd4 Merge branch 'master' into hypervisor Conflicts: src/bindings/java/jmsg_synchro.c src/bindings/java/org/simgrid/msg/Host.java src/include/surf/surf.h src/smpi/colls/allgather-RDB.c src/smpi/colls/allgather-SMP-simple.c src/surf/cpu_cas01.c src/surf/surf.c src/surf/surf_routing.c src/surf/workstation.c --- 12c0f182635ed71b370d608b5b9a614153765cd4 diff --cc include/msg/msg.h index 89d70d6627,877d3e40a0..0dc3be49f9 --- a/include/msg/msg.h +++ b/include/msg/msg.h @@@ -103,9 -100,9 +102,10 @@@ XBT_PUBLIC(msg_host_t) MSG_host_self(vo XBT_PUBLIC(int) MSG_get_host_msgload(msg_host_t host); /* int MSG_get_msgload(void); This function lacks specification; discard it */ XBT_PUBLIC(double) MSG_get_host_speed(msg_host_t h); + XBT_PUBLIC(int) MSG_get_host_core(msg_host_t h); XBT_PUBLIC(int) MSG_host_is_avail(msg_host_t h); -XBT_PUBLIC(void) __MSG_host_destroy(msg_host_priv_t host); +XBT_PUBLIC(void) __MSG_host_priv_free(msg_host_priv_t priv); +XBT_PUBLIC(void) __MSG_host_destroy(msg_host_t host); /*property handlers*/ XBT_PUBLIC(xbt_dict_t) MSG_host_get_properties(msg_host_t host); diff --cc include/simgrid/simix.h index fe2a5c535e,510bade279..8254d46ca3 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@@ -258,6 -254,6 +256,8 @@@ XBT_PUBLIC(smx_host_t) SIMIX_host_get_b XBT_PUBLIC(smx_host_t) SIMIX_host_self(void); XBT_PUBLIC(const char*) SIMIX_host_self_get_name(void); XBT_PUBLIC(const char*) SIMIX_host_get_name(smx_host_t host); /* FIXME: make private: only the name of SIMIX_host_self() should be public without request */ ++XBT_PUBLIC(void) SIMIX_host_on(smx_host_t host); ++XBT_PUBLIC(void) SIMIX_host_off(smx_host_t host); XBT_PUBLIC(void) SIMIX_host_self_set_data(void *data); XBT_PUBLIC(void*) SIMIX_host_self_get_data(void); XBT_PUBLIC(void*) SIMIX_host_get_data(smx_host_t host); @@@ -297,6 -293,7 +297,9 @@@ XBT_PUBLIC(void) SIMIX_comm_finish(smx_ XBT_PUBLIC(smx_host_t) simcall_host_get_by_name(const char *name); XBT_PUBLIC(const char *) simcall_host_get_name(smx_host_t host); XBT_PUBLIC(xbt_dict_t) simcall_host_get_properties(smx_host_t host); ++XBT_PUBLIC(void) simcall_host_on(smx_host_t host); ++XBT_PUBLIC(void) simcall_host_off(smx_host_t host); + XBT_PUBLIC(int) simcall_host_get_core(smx_host_t host); XBT_PUBLIC(double) simcall_host_get_speed(smx_host_t host); XBT_PUBLIC(double) simcall_host_get_available_speed(smx_host_t host); /* Two possible states, 1 - CPU ON and 0 CPU OFF */ diff --cc src/include/surf/surf.h index 68597e2b6f,3b684fed50..cb867e323b --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@@ -208,8 -193,7 +206,9 @@@ typedef struct surf_cpu_model_extension surf_action_t(*execute) (void *cpu, double size); surf_action_t(*sleep) (void *cpu, double duration); e_surf_resource_state_t(*get_state) (void *cpu); + void(*set_state) (void *cpu, e_surf_resource_state_t state); + + int (*get_core) (void *cpu); double (*get_speed) (void *cpu, double load); double (*get_available_speed) (void *cpu); void (*add_traces) (void); @@@ -264,7 -246,7 +264,8 @@@ typedef struct surf_workstation_model_e and create the corresponding action */ surf_action_t(*sleep) (void *workstation, double duration); /**< Make a workstation sleep during a given duration */ e_surf_resource_state_t(*get_state) (void *workstation); /**< Return the CPU state of a workstation */ + void(*set_state) (void *workstation, e_surf_resource_state_t state); + int (*get_core) (void *workstation); double (*get_speed) (void *workstation, double load); /**< Return the speed of a workstation */ double (*get_available_speed) (void *workstation); /**< Return tha available speed of a workstation */ surf_action_t(*communicate) (void *workstation_src, /**< Execute a communication amount between two workstations */ diff --cc src/simix/smx_host.c index c94a0fbd79,72da17a23c..08ecdf3cd4 --- a/src/simix/smx_host.c +++ b/src/simix/smx_host.c @@@ -38,62 -38,6 +38,62 @@@ smx_host_t SIMIX_host_create(const cha return xbt_lib_get_elm_or_null(host_lib, name); } - void SIMIX_pre_host_on(smx_host_t h) ++void SIMIX_pre_host_on(smx_simcall_t simcall, smx_host_t h) +{ + SIMIX_host_on(h); +} + +/** + * \brief Start the host if it is off + * + */ +void SIMIX_host_on(smx_host_t h) +{ + smx_host_priv_t host = (smx_host_priv_t) h; + + xbt_assert((host != NULL), "Invalid parameters"); + + surf_model_t ws_model = surf_resource_model(h, SURF_WKS_LEVEL); + ws_model->extension.workstation.set_state(host, SURF_RESOURCE_ON); + + SIMIX_host_restart_processes(h); +} + - void SIMIX_pre_host_off(smx_host_t h) ++void SIMIX_pre_host_off(smx_simcall_t simcall, smx_host_t h) +{ + SIMIX_host_off(h); +} + +/** + * \brief Stop the host if it is on + * + */ +void SIMIX_host_off(smx_host_t h) +{ + smx_host_priv_t host = (smx_host_priv_t) h; + + xbt_assert((host != NULL), "Invalid parameters"); + + /* Clean Simulator data */ + if (xbt_swag_size(host->process_list) != 0) { + char *msg = xbt_strdup("Shutting down host, but it's not empty:"); + char *tmp; + smx_process_t process = NULL; + + xbt_swag_foreach(process, host->process_list) { + tmp = bprintf("%s\n\t%s", msg, process->name); + free(msg); + msg = tmp; + } + SIMIX_display_process_status(); + THROWF(arg_error, 0, "%s", msg); + } + xbt_swag_free(host->process_list); + + surf_model_t ws_model = surf_resource_model(h, SURF_WKS_LEVEL); + ws_model->extension.workstation.set_state(host, SURF_RESOURCE_OFF); +} + /** * \brief Internal function to destroy a SIMIX host. * @@@ -201,10 -144,22 +201,22 @@@ double SIMIX_pre_host_get_speed(smx_sim double SIMIX_host_get_speed(smx_host_t host){ xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)"); - return surf_workstation_model->extension.workstation. - get_speed(host, 1.0); + surf_model_t ws_model = surf_resource_model(host, SURF_WKS_LEVEL); + return ws_model->extension.workstation.get_speed(host, 1.0); } + int SIMIX_pre_host_get_core(smx_simcall_t simcall, smx_host_t host){ + return SIMIX_host_get_core(host); + } + int SIMIX_host_get_core(smx_host_t host){ + xbt_assert((host != NULL), "Invalid parameters (simix host is NULL)"); + + return surf_workstation_model->extension.workstation. + get_core(host); + } + + + double SIMIX_pre_host_get_available_speed(smx_simcall_t simcall, smx_host_t host){ return SIMIX_host_get_available_speed(host); } diff --cc src/simix/smx_host_private.h index 2c5e157b2f,adb53b8cef..4ed05a1918 --- a/src/simix/smx_host_private.h +++ b/src/simix/smx_host_private.h @@@ -41,8 -42,8 +42,10 @@@ int SIMIX_host_get_core(smx_host_t host double SIMIX_host_get_speed(smx_host_t host); double SIMIX_host_get_available_speed(smx_host_t host); int SIMIX_host_get_state(smx_host_t host); ++void SIMIX_host_on(smx_host_t host); ++void SIMIX_host_off(smx_host_t host); smx_action_t SIMIX_host_execute(const char *name, - smx_host_t host, double computation_amount, double priority); + smx_host_t host, double computation_amount, double priority, double bound); smx_action_t SIMIX_host_parallel_execute(const char *name, int host_nb, smx_host_t *host_list, double *computation_amount, double *communication_amount, @@@ -59,7 -59,8 +62,10 @@@ void SIMIX_pre_host_execution_wait(smx_ smx_host_t SIMIX_pre_host_get_by_name(smx_simcall_t, const char*); const char* SIMIX_pre_host_self_get_name(smx_simcall_t); const char* SIMIX_pre_host_get_name(smx_simcall_t, smx_host_t); ++void SIMIX_pre_host_on(smx_simcall_t, smx_host_t host); ++void SIMIX_pre_host_off(smx_simcall_t, smx_host_t host); xbt_dict_t SIMIX_pre_host_get_properties(smx_simcall_t, smx_host_t); + int SIMIX_pre_host_get_core(smx_simcall_t, smx_host_t); double SIMIX_pre_host_get_speed(smx_simcall_t, smx_host_t); double SIMIX_pre_host_get_available_speed(smx_simcall_t, smx_host_t); int SIMIX_pre_host_get_state(smx_simcall_t, smx_host_t); diff --cc src/simix/smx_smurf_private.h index b25104bb62,1f5f540af2..ab94860b3c --- a/src/simix/smx_smurf_private.h +++ b/src/simix/smx_smurf_private.h @@@ -261,9 -261,8 +261,10 @@@ #define SIMCALL_LIST1(ACTION, sep) \ ACTION(SIMCALL_HOST_GET_BY_NAME, host_get_by_name, WITH_ANSWER, TSPEC(result, smx_host_t), TSTRING(name)) sep \ ACTION(SIMCALL_HOST_GET_NAME, host_get_name, WITH_ANSWER, TSTRING(result), TSPEC(host, smx_host_t)) sep \ +ACTION(SIMCALL_HOST_ON, host_on, WITH_ANSWER, TVOID(result), TSPEC(host, smx_host_t)) sep \ +ACTION(SIMCALL_HOST_OFF, host_off, WITH_ANSWER, TVOID(result), TSPEC(host, smx_host_t)) sep \ ACTION(SIMCALL_HOST_GET_PROPERTIES, host_get_properties, WITH_ANSWER, TSPEC(result, xbt_dict_t), TSPEC(host, smx_host_t)) sep \ + ACTION(SIMCALL_HOST_GET_CORE, host_get_core, WITH_ANSWER, TINT(result), TSPEC(host, smx_host_t)) sep \ ACTION(SIMCALL_HOST_GET_SPEED, host_get_speed, WITH_ANSWER, TDOUBLE(result), TSPEC(host, smx_host_t)) sep \ ACTION(SIMCALL_HOST_GET_AVAILABLE_SPEED, host_get_available_speed, WITH_ANSWER, TDOUBLE(result), TSPEC(host, smx_host_t)) sep \ ACTION(SIMCALL_HOST_GET_STATE, host_get_state, WITH_ANSWER, TINT(result), TSPEC(host, smx_host_t)) sep \ diff --cc src/surf/cpu_cas01.c index f6c48fc17b,f704612a5c..cae096c6b3 --- a/src/surf/cpu_cas01.c +++ b/src/surf/cpu_cas01.c @@@ -304,6 -298,12 +304,10 @@@ static double cpu_get_speed(void *cpu, return load * ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->power_peak; } + static int cpu_get_core(void *cpu) + { + return ((cpu_Cas01_t)surf_cpu_resource_priv(cpu))->core; + } - - static double cpu_get_available_speed(void *cpu) { /* number between 0 and 1 */ @@@ -333,16 -333,16 +337,16 @@@ static surf_model_t surf_cpu_model_init char *optim = xbt_cfg_get_string(_sg_cfg_set, "cpu/optim"); int select = - xbt_cfg_get_int(_sg_cfg_set, "cpu/maxmin_selective_update"); + xbt_cfg_get_boolean(_sg_cfg_set, "cpu/maxmin_selective_update"); - surf_cpu_model = surf_model_init(); + surf_model_t cpu_model = surf_model_init(); if (!strcmp(optim, "Full")) { - surf_cpu_model->model_private->update_mechanism = UM_FULL; - surf_cpu_model->model_private->selective_update = select; + cpu_model->model_private->update_mechanism = UM_FULL; + cpu_model->model_private->selective_update = select; } else if (!strcmp(optim, "Lazy")) { - surf_cpu_model->model_private->update_mechanism = UM_LAZY; - surf_cpu_model->model_private->selective_update = 1; + cpu_model->model_private->update_mechanism = UM_LAZY; + cpu_model->model_private->selective_update = 1; xbt_assert((select == 1) || (xbt_cfg_is_default_value @@@ -377,44 -376,41 +381,45 @@@ } else xbt_die("Invalid cpu update mechanism!"); - surf_cpu_model->model_private->update_resource_state = + cpu_model->model_private->update_resource_state = cpu_update_resource_state; - surf_cpu_model->model_private->finalize = cpu_finalize; - - surf_cpu_model->suspend = surf_action_suspend; - surf_cpu_model->resume = surf_action_resume; - surf_cpu_model->is_suspended = surf_action_is_suspended; - surf_cpu_model->set_max_duration = surf_action_set_max_duration; - surf_cpu_model->set_priority = surf_action_set_priority; + cpu_model->model_private->finalize = cpu_finalize; + + cpu_model->suspend = surf_action_suspend; + cpu_model->resume = surf_action_resume; + cpu_model->is_suspended = surf_action_is_suspended; + cpu_model->set_max_duration = surf_action_set_max_duration; + cpu_model->set_priority = surf_action_set_priority; + cpu_model->set_bound = surf_action_set_bound; #ifdef HAVE_TRACING - surf_cpu_model->set_category = surf_action_set_category; + cpu_model->set_category = surf_action_set_category; #endif - surf_cpu_model->get_remains = surf_action_get_remains; + cpu_model->get_remains = surf_action_get_remains; - surf_cpu_model->extension.cpu.execute = cpu_execute; - surf_cpu_model->extension.cpu.sleep = cpu_action_sleep; + cpu_model->extension.cpu.execute = cpu_execute; + cpu_model->extension.cpu.sleep = cpu_action_sleep; - surf_cpu_model->extension.cpu.get_state = cpu_get_state; - surf_cpu_model->extension.cpu.get_core = cpu_get_core; - surf_cpu_model->extension.cpu.get_speed = cpu_get_speed; - surf_cpu_model->extension.cpu.get_available_speed = + cpu_model->extension.cpu.get_state = cpu_get_state; + cpu_model->extension.cpu.set_state = cpu_set_state; ++ cpu_model->extension.cpu.get_core = cpu_get_core; + cpu_model->extension.cpu.get_speed = cpu_get_speed; + cpu_model->extension.cpu.get_available_speed = cpu_get_available_speed; - surf_cpu_model->extension.cpu.add_traces = cpu_add_traces_cpu; + cpu_model->extension.cpu.add_traces = cpu_add_traces_cpu; - if (!surf_cpu_model->model_private->maxmin_system) { - surf_cpu_model->model_private->maxmin_system = lmm_system_new(surf_cpu_model->model_private->selective_update); + if (!cpu_model->model_private->maxmin_system) { + cpu_model->model_private->maxmin_system = lmm_system_new(cpu_model->model_private->selective_update); } - if (surf_cpu_model->model_private->update_mechanism == UM_LAZY) { - surf_cpu_model->model_private->action_heap = xbt_heap_new(8, NULL); - xbt_heap_set_update_callback(surf_cpu_model->model_private->action_heap, + if (cpu_model->model_private->update_mechanism == UM_LAZY) { + cpu_model->model_private->action_heap = xbt_heap_new(8, NULL); + xbt_heap_set_update_callback(cpu_model->model_private->action_heap, surf_action_lmm_update_index_heap); - surf_cpu_model->model_private->modified_set = + cpu_model->model_private->modified_set = xbt_swag_new(xbt_swag_offset(comp, generic_lmm_action.action_list_hookup)); - surf_cpu_model->model_private->maxmin_system->keep_track = surf_cpu_model->model_private->modified_set; + cpu_model->model_private->maxmin_system->keep_track = cpu_model->model_private->modified_set; } + + return cpu_model; } /*********************************************************************/ diff --cc src/surf/surf.c index d2ded06483,3463fad79b..2cc050d9e8 --- a/src/surf/surf.c +++ b/src/surf/surf.c @@@ -567,20 -555,9 +566,9 @@@ double surf_solve(double max_date } surf_min_index = 0; - - if (surf_get_nthreads() > 1) { - /* parallel version */ - #ifdef CONTEXT_THREADS - xbt_parmap_apply(surf_parmap, (void_f_pvoid_t) surf_share_resources, model_list_invoke); - #else - xbt_die("Asked to run in parallel, but no thread at hand..."); - #endif - } - else { - /* sequential version */ - xbt_dynar_foreach(model_list_invoke, iter, model) { - surf_share_resources(model); - } + /* sequential version */ - xbt_dynar_foreach(model_list, iter, model) { ++ xbt_dynar_foreach(model_list_invoke, iter, model) { + surf_share_resources(model); } unsigned i; @@@ -655,19 -632,10 +643,10 @@@ XBT_DEBUG("Duration set to %f", min); NOW = NOW + min; -- - if (surf_get_nthreads() > 1) { - /* parallel version */ - #ifdef CONTEXT_THREADS - xbt_parmap_apply(surf_parmap, (void_f_pvoid_t) surf_update_actions_state, model_list); - #endif - } - else { - /* FIXME: model_list or model_list_invoke? revisit here later */ - /* sequential version */ - xbt_dynar_foreach(model_list, iter, model) { - surf_update_actions_state(model); - } ++ /* FIXME: model_list or model_list_invoke? revisit here later */ + /* sequential version */ + xbt_dynar_foreach(model_list, iter, model) { + surf_update_actions_state(model); } #ifdef HAVE_TRACING @@@ -697,47 -665,10 +676,9 @@@ static void surf_share_resources(surf_m static void surf_update_actions_state(surf_model_t model) { - model->model_private->update_actions_state(NOW, min); + model->model_private->update_actions_state(model, NOW, min); } - /** - * \brief Returns the number of parallel threads used to update the models. - * \return the number of threads (1 means no parallelism) - */ - int surf_get_nthreads(void) { - return surf_nthreads; - } - - /** - * \brief Sets the number of parallel threads used to update the models. - * - * A value of 1 means no parallelism. - * - * \param nb_threads the number of threads to use - */ - void surf_set_nthreads(int nthreads) { - - if (nthreads<=0) { - nthreads = xbt_os_get_numcores(); - XBT_INFO("Auto-setting surf/nthreads to %d",nthreads); - } - - #ifdef CONTEXT_THREADS - xbt_parmap_destroy(surf_parmap); - surf_parmap = NULL; - #endif - - if (nthreads > 1) { - #ifdef CONTEXT_THREADS - surf_parmap = xbt_parmap_new(nthreads, XBT_PARMAP_DEFAULT); - #else - THROWF(arg_error, 0, "Cannot activate parallel threads in Surf: your architecture does not support threads"); - #endif - } - - surf_nthreads = nthreads; - } -- /* This function is a pimple that we ought to fix. But it won't be easy. * * The surf_solve() function does properly return the set of actions that changed. diff --cc src/surf/workstation.c index 5e2271c018,aec832a014..dbaf9ae184 --- a/src/surf/workstation.c +++ b/src/surf/workstation.c @@@ -21,23 -23,24 +21,22 @@@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_wo surf_model_t surf_workstation_model = NULL; + static void workstation_new(sg_platf_host_cbarg_t host) { - workstation_CLM03_t workstation = xbt_new0(s_workstation_CLM03_t, 1); + const char *name = host->id; - workstation->generic_resource.model = surf_workstation_model; - workstation->generic_resource.name = xbt_strdup(host->id); - workstation->storage = xbt_lib_get_or_null(storage_lib,host->id,ROUTING_STORAGE_HOST_LEVEL); - workstation->net_elm = xbt_lib_get_or_null(host_lib,host->id,ROUTING_HOST_LEVEL); - XBT_DEBUG("Create workstation %s with %ld mounted disks",host->id,xbt_dynar_length(workstation->storage)); - xbt_lib_set(host_lib, host->id, SURF_WKS_LEVEL, workstation); -} + /* NOTE: The properties object is NULL, because the current code uses that of + * that of a cpu resource. */ + workstation_CLM03_t ws = (workstation_CLM03_t) surf_resource_new(sizeof(s_workstation_CLM03_t), surf_workstation_model, name, NULL); -static int ws_resource_used(void *resource_id) -{ - THROW_IMPOSSIBLE; /* This model does not implement parallel tasks */ - return -1; + ws->storage = xbt_lib_get_or_null(storage_lib, name, ROUTING_STORAGE_HOST_LEVEL); + ws->net_elm = xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL); + + XBT_DEBUG("Create ws %s with %ld mounted disks", name, xbt_dynar_length(ws->storage)); + xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, ws); } - static void ws_parallel_action_cancel(surf_action_t action) { THROW_UNIMPLEMENTED; /* This model does not implement parallel tasks */ @@@ -326,28 -215,30 +325,33 @@@ static surf_action_t ws_communicate(voi dst->net_elm, size, rate); } -static e_surf_resource_state_t ws_get_state(void *workstation) +e_surf_resource_state_t ws_get_state(void *workstation) { - return surf_cpu_model->extension.cpu. - get_state(workstation); + surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation)); + return cpu->model->extension.cpu.get_state(workstation); } - void ws_set_state(void *workstation, e_surf_resource_state_t state) -static double ws_get_speed(void *workstation, double load) ++static void ws_set_state(void *workstation, e_surf_resource_state_t state) { - return surf_cpu_model->extension.cpu. - get_speed(workstation, load); + surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation)); + cpu->model->extension.cpu.set_state(workstation, state); } -static int ws_get_core(void *workstation) +double ws_get_speed(void *workstation, double load) { - return surf_cpu_model->extension.cpu. - get_core(workstation); + surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation)); + return cpu->model->extension.cpu.get_speed(workstation, load); } - - ++static int ws_get_core(void *workstation) ++{ ++ surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation)); ++ return cpu->model->extension.cpu.get_core(workstation); ++} static double ws_get_available_speed(void *workstation) { - return surf_cpu_model->extension.cpu. - get_available_speed(workstation); + surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation)); + return cpu->model->extension.cpu.get_available_speed(workstation); } static surf_action_t ws_execute_parallel_task(int workstation_nb, @@@ -493,114 -407,77 +514,120 @@@ static surf_action_t ws_action_ls(void return model->extension.storage.ls(st, path); } + static size_t ws_file_get_size(void *workstation, surf_file_t fd) + { + return fd->size; + } + -static void surf_workstation_model_init_internal(void) +void ws_get_params(void *ws, ws_params_t params) { - surf_workstation_model = surf_model_init(); - - surf_workstation_model->name = "Workstation"; - surf_workstation_model->action_unref = ws_action_unref; - surf_workstation_model->action_cancel = ws_action_cancel; - surf_workstation_model->action_state_set = ws_action_state_set; - - surf_workstation_model->model_private->resource_used = ws_resource_used; - surf_workstation_model->model_private->share_resources = - ws_share_resources; - surf_workstation_model->model_private->update_actions_state = - ws_update_actions_state; - surf_workstation_model->model_private->update_resource_state = - ws_update_resource_state; - surf_workstation_model->model_private->finalize = ws_finalize; - - surf_workstation_model->suspend = ws_action_suspend; - surf_workstation_model->resume = ws_action_resume; - surf_workstation_model->is_suspended = ws_action_is_suspended; - surf_workstation_model->set_max_duration = ws_action_set_max_duration; - surf_workstation_model->set_priority = ws_action_set_priority; -#ifdef HAVE_TRACING - surf_workstation_model->set_category = ws_action_set_category; -#endif - surf_workstation_model->get_remains = ws_action_get_remains; -#ifdef HAVE_LATENCY_BOUND_TRACKING - surf_workstation_model->get_latency_limited = ws_get_latency_limited; -#endif + workstation_CLM03_t ws_clm03 = surf_workstation_resource_priv(ws); + memcpy(params, &ws_clm03->params, sizeof(s_ws_params_t)); +} + +void ws_set_params(void *ws, ws_params_t params) +{ + workstation_CLM03_t ws_clm03 = surf_workstation_resource_priv(ws); + /* may check something here. */ + memcpy(&ws_clm03->params, params, sizeof(s_ws_params_t)); +} + +static xbt_dynar_t ws_get_vms(void *pm) +{ + xbt_dynar_t dyn = xbt_dynar_new(sizeof(smx_host_t), NULL); + + /* iterate for all hosts including virtual machines */ + xbt_lib_cursor_t cursor; + char *key; + void **ind_host; + xbt_lib_foreach(host_lib, cursor, key, ind_host) { + workstation_CLM03_t ws_clm03 = ind_host[SURF_WKS_LEVEL]; + if (!ws_clm03) + continue; + /* skip if it is not a virtual machine */ + if (ws_clm03->generic_resource.model != surf_vm_workstation_model) + continue; + + /* It is a virtual machine, so we can cast it to workstation_VM2013_t */ + workstation_VM2013_t ws_vm2013 = (workstation_VM2013_t) ws_clm03; + if (pm == ws_vm2013->sub_ws) + xbt_dynar_push(dyn, &ws_vm2013->sub_ws); + } + + return dyn; +} - surf_workstation_model->extension.workstation.execute = ws_execute; - surf_workstation_model->extension.workstation.sleep = ws_action_sleep; - surf_workstation_model->extension.workstation.get_state = ws_get_state; - surf_workstation_model->extension.workstation.get_core = ws_get_core; - surf_workstation_model->extension.workstation.get_speed = ws_get_speed; - surf_workstation_model->extension.workstation.get_available_speed = + +static void surf_workstation_model_init_internal(void) +{ + surf_model_t model = surf_model_init(); + + model->name = "Workstation"; + model->type = SURF_MODEL_TYPE_WORKSTATION; + model->action_unref = ws_action_unref; + model->action_cancel = ws_action_cancel; + model->action_state_set = ws_action_state_set; + + model->model_private->resource_used = ws_resource_used; + model->model_private->share_resources = ws_share_resources; + model->model_private->update_actions_state = ws_update_actions_state; + model->model_private->update_resource_state = ws_update_resource_state; + model->model_private->finalize = ws_finalize; + + model->suspend = ws_action_suspend; + model->resume = ws_action_resume; + model->is_suspended = ws_action_is_suspended; + model->set_max_duration = ws_action_set_max_duration; + model->set_priority = ws_action_set_priority; + model->set_bound = ws_action_set_bound; + #ifdef HAVE_TRACING + model->set_category = ws_action_set_category; + #endif + model->get_remains = ws_action_get_remains; + #ifdef HAVE_LATENCY_BOUND_TRACKING + model->get_latency_limited = ws_get_latency_limited; + #endif + + /* For VM support, we have a surf cpu model object for each workstation model + * object. The physical workstation model object has the cpu model object of + * the physical machine layer. */ + xbt_assert(surf_cpu_model_pm); + model->extension.workstation.cpu_model = surf_cpu_model_pm; + + model->extension.workstation.execute = ws_execute; + model->extension.workstation.sleep = ws_action_sleep; + model->extension.workstation.get_state = ws_get_state; + model->extension.workstation.set_state = ws_set_state; ++ model->extension.workstation.get_core = ws_get_core; + model->extension.workstation.get_speed = ws_get_speed; - model->extension.workstation.get_available_speed = ws_get_available_speed; ++ model->extension.workstation.get_available_speed = + ws_get_available_speed; - surf_workstation_model->extension.workstation.communicate = - ws_communicate; - surf_workstation_model->extension.workstation.get_route = ws_get_route; - surf_workstation_model->extension.workstation.execute_parallel_task = - ws_execute_parallel_task; - surf_workstation_model->extension.workstation.get_link_bandwidth = - ws_get_link_bandwidth; - surf_workstation_model->extension.workstation.get_link_latency = - ws_get_link_latency; - surf_workstation_model->extension.workstation.link_shared = - ws_link_shared; - surf_workstation_model->extension.workstation.get_properties = - ws_get_properties; - - surf_workstation_model->extension.workstation.open = ws_action_open; - surf_workstation_model->extension.workstation.close = ws_action_close; - surf_workstation_model->extension.workstation.read = ws_action_read; - surf_workstation_model->extension.workstation.write = ws_action_write; - surf_workstation_model->extension.workstation.unlink = ws_file_unlink; - surf_workstation_model->extension.workstation.ls = ws_action_ls; - surf_workstation_model->extension.workstation.get_size = ws_file_get_size; + model->extension.workstation.communicate = ws_communicate; + model->extension.workstation.get_route = ws_get_route; + model->extension.workstation.execute_parallel_task = ws_execute_parallel_task; + model->extension.workstation.get_link_bandwidth = ws_get_link_bandwidth; + model->extension.workstation.get_link_latency = ws_get_link_latency; + model->extension.workstation.link_shared = ws_link_shared; + model->extension.workstation.get_properties = ws_get_properties; + + model->extension.workstation.open = ws_action_open; + model->extension.workstation.close = ws_action_close; + model->extension.workstation.read = ws_action_read; + model->extension.workstation.write = ws_action_write; - model->extension.workstation.stat = ws_action_stat; - model->extension.workstation.unlink = ws_action_unlink; ++ model->extension.workstation.unlink = ws_file_unlink; + model->extension.workstation.ls = ws_action_ls; + + model->extension.workstation.get_params = ws_get_params; + model->extension.workstation.set_params = ws_set_params; + model->extension.workstation.get_vms = ws_get_vms; + + surf_workstation_model = model; } void surf_workstation_model_init_current_default(void) { - xbt_cfg_setdefault_int(_sg_cfg_set, "network/crosstraffic", 1); - surf_workstation_model_init_internal(); + xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/crosstraffic", xbt_strdup("yes")); surf_cpu_model_init_Cas01(); surf_network_model_init_LegrandVelho();