From daa638ffa57272cf7ecc9700971b6e1f3ec6e2dd Mon Sep 17 00:00:00 2001 From: alebre Date: Thu, 7 Feb 2013 13:44:35 +0100 Subject: [PATCH] Start to add second CPU model for the VM layer --- src/include/surf/surf.h | 2 ++ src/surf/cpu_cas01.c | 12 +++++++++++- src/surf/vm_workstation.c | 37 ++++++++++++++++++++++++++++-------- src/surf/workstation.c | 40 +++++++++++++++++++++------------------ 4 files changed, 64 insertions(+), 27 deletions(-) diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 4beea38dd0..ef4d9d74d3 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -243,6 +243,8 @@ typedef struct surf_storage_model_extension_public { * Public functions specific to the workstation model. */ typedef struct surf_workstation_model_extension_public { + surf_resource_t cpu; + surf_action_t(*execute) (void *workstation, double size); /**< Execute a computation amount on a workstation and create the corresponding action */ surf_action_t(*sleep) (void *workstation, double duration); /**< Make a workstation sleep during a given duration */ diff --git a/src/surf/cpu_cas01.c b/src/surf/cpu_cas01.c index b492ee1106..cd8fccdfd2 100644 --- a/src/surf/cpu_cas01.c +++ b/src/surf/cpu_cas01.c @@ -9,7 +9,7 @@ #include "maxmin_private.h" #include "simgrid/sg_config.h" -surf_model_t surf_cpu_model = NULL; +surf_model_t *surf_cpu_model; #undef GENERIC_LMM_ACTION #undef GENERIC_ACTION @@ -438,3 +438,13 @@ void surf_cpu_model_init_Cas01() cpu_define_callbacks(); xbt_dynar_push(model_list, &surf_cpu_model); } + +surf_model_t cpu_model_cas01(int level){ + // TODO this table should be allocated + if(!surf_cpu_model[level]) + // allocate it + return surf_cpu_model[level]; +} + + + diff --git a/src/surf/vm_workstation.c b/src/surf/vm_workstation.c index cc34c9cfdc..ffa4ad06bc 100644 --- a/src/surf/vm_workstation.c +++ b/src/surf/vm_workstation.c @@ -7,31 +7,52 @@ #include "xbt/ex.h" #include "xbt/dict.h" #include "portable.h" -#include "surf_private.h" #include "surf/surf_resource.h" #include "simgrid/sg_config.h" +#include "workstation_private.h" + typedef struct workstation_VM2013 { - s_surf_resource_t generic_resource; /* Must remain first to add this to a trace */ - surf_resource_t physical_workstation; // Pointer to the host OS + s_workstation_CLM03_t ws; /* a VM is a ''v''host */ + + workstation_CLM03_t sub_ws; // Pointer to the ''host'' OS e_msg_vm_state_t current_state; // See include/msg/datatypes.h } s_workstation_VM2013_t, *workstation_VM2013_t; XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_vm_workstation, surf, "Logging specific to the SURF VM workstation module"); + + + surf_model_t surf_vm_workstation_model = NULL; static void vm_ws_create(const char *name, void *ind_phys_workstation) { workstation_VM2013_t vm_ws = xbt_new0(s_workstation_VM2013_t, 1); -// TODO Complete the surf vm workstation model - vm_ws->generic_resource.model = surf_vm_workstation_model; - vm_ws->generic_resource.name = xbt_strdup(name); - // ind means ''indirect'' that this is a reference on the whole dict_elm structure (i.e not on the surf_resource_private infos) - vm_ws->physical_workstation = surf_workstation_resource_priv(ind_phys_workstation); + + // //// WORKSTATION RELATED STUFF //// + __init_ws(&(vm_ws->ws), name); + // Override the model with the current VM one. + vm_ws->ws.generic_resource.model = surf_vm_workstation_model; + + // //// CPU RELATED STUFF //// + vm_ws->ws->generic_resource.model.extension.cpu=cpu_model_cas01(0); + + // //// NET RELATED STUFF //// + // Bind virtual net_elm to the host + // TODO rebind each time you migrate a VM + // TODO check how network requests are scheduled between distinct processes competing for the same card. + vm_ws->ws.net_elm=xbt_lib_get_or_null(host_lib,vm_ws->physical_ws->generic_resource.name,ROUTING_HOST_LEVEL); + xbt_lib_set(host_lib, name, ROUTING_HOST_LEVEL, vm_ws->ws.net_elm); + + // //// STORAGE RELATED STUFF //// + + // ind means ''indirect'' that this is a reference on the whole dict_elm structure (i.e not on the surf_resource_private infos) + vm_ws->physical_ws = surf_workstation_resource_priv(ind_phys_workstation); vm_ws->current_state=msg_vm_state_created, xbt_lib_set(host_lib, name, SURF_WKS_LEVEL, vm_ws); + } /* diff --git a/src/surf/workstation.c b/src/surf/workstation.c index 13798ec37c..25ef8efee3 100644 --- a/src/surf/workstation.c +++ b/src/surf/workstation.c @@ -7,32 +7,30 @@ #include "xbt/ex.h" #include "xbt/dict.h" #include "portable.h" -#include "surf_private.h" #include "storage_private.h" #include "surf/surf_resource.h" #include "simgrid/sg_config.h" - -typedef struct workstation_CLM03 { - s_surf_resource_t generic_resource; /* Must remain first to add this to a trace */ - void *net_elm; - xbt_dynar_t storage; -} s_workstation_CLM03_t, *workstation_CLM03_t; +#include "workstation_private.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf, "Logging specific to the SURF workstation module"); surf_model_t surf_workstation_model = NULL; + +void __init_ws(workstation_CLM03_t ws, const char *id){ + ws->generic_resource.model = surf_workstation_model; + ws->generic_resource.name = xbt_strdup(id); + ws->storage = xbt_lib_get_or_null(storage_lib,id,ROUTING_STORAGE_HOST_LEVEL); + ws->net_elm = xbt_lib_get_or_null(host_lib,id,ROUTING_HOST_LEVEL); + XBT_DEBUG("Create ws %s with %ld mounted disks",id,xbt_dynar_length(ws->storage)); + xbt_lib_set(host_lib, id, SURF_WKS_LEVEL, ws); + ws->generic_resource.model.extension.cpu=cpu_model_cas01(0); +} static void workstation_new(sg_platf_host_cbarg_t host) { workstation_CLM03_t workstation = xbt_new0(s_workstation_CLM03_t, 1); - - 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); + __init_ws(workstation, host->id, level); } static int ws_resource_used(void *resource_id) @@ -57,7 +55,9 @@ static int ws_action_unref(surf_action_t action) if (action->model_type == surf_network_model) return surf_network_model->action_unref(action); else if (action->model_type == surf_cpu_model) - return surf_cpu_model->action_unref(action); + return action->model_type->action_unref(action); + // previously was: Adrien/Arnaud 6 feb + // surf_cpu_model->action_unref(action); else if (action->model_type == surf_workstation_model) return ws_parallel_action_free(action); else @@ -117,8 +117,8 @@ static surf_action_t ws_execute(void *workstation, double size) static surf_action_t ws_action_sleep(void *workstation, double duration) { - return surf_cpu_model->extension.cpu. - sleep(workstation, duration); + surf_resource_t cpu = ((surf_resource_t) surf_cpu_resource_priv(workstation)); + return cpu->model->extension.cpu.sleep(workstation, duration); } static void ws_action_suspend(surf_action_t action) @@ -445,9 +445,13 @@ static void surf_workstation_model_init_internal(void) void surf_workstation_model_init_current_default(void) { + surf_workstation_model_init_internal(); + + surf_cpu_model_init_Cas01_phys(); // INSTANTIATE THE CPU PHYSICAL MODEL + surf_cpu_model_init_Cas01_vm(); // INSTANTIATE THE CPU PHYSICAL MODEL + xbt_cfg_setdefault_int(_sg_cfg_set, "network/crosstraffic", 1); - surf_cpu_model_init_Cas01(); surf_network_model_init_LegrandVelho(); xbt_dynar_push(model_list, &surf_workstation_model); -- 2.20.1