From: Martin Quinson Date: Wed, 15 Jul 2015 07:59:34 +0000 (+0200) Subject: [SGpp] make SURF_CPU_LEVEL private X-Git-Tag: v3_12~498 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/91bb77753278264baf1acecdfe389ff7e2fcd270 [SGpp] make SURF_CPU_LEVEL private --- diff --git a/include/simgrid/host.h b/include/simgrid/host.h index fcee52ca98..15c66f5916 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -8,11 +8,20 @@ #define SIMGRID_HOST_H_ #include - SG_BEGIN_DECL() typedef xbt_dictelm_t sg_host_t; - +XBT_PUBLIC(sg_host_t) sg_host_by_name(const char *name); +static XBT_INLINE char *sg_host_get_name(sg_host_t host){ + return host->key; +} + +#ifdef __cplusplus +#define DEFINE_EXTERNAL_CLASS(klass) class klass; +class Cpu; +#else +#define DEFINE_EXTERNAL_CLASS(klass) typedef struct klass klass; +#endif // ========== MSG Layer ============== typedef struct s_msg_host_priv *msg_host_priv_t; @@ -26,7 +35,16 @@ XBT_PUBLIC(smx_host_priv_t) sg_host_simix(sg_host_t host); XBT_PUBLIC(void) sg_host_simix_set(sg_host_t host, smx_host_priv_t priv); XBT_PUBLIC(void) sg_host_simix_destroy(sg_host_t host); -// Module initializer. Won't survive the conversion to C++ +// ========== SURF CPU ============ +DEFINE_EXTERNAL_CLASS(Cpu); +typedef Cpu *surf_cpu_t; +typedef Cpu *CpuPtr; +XBT_PUBLIC(surf_cpu_t) sg_host_surfcpu(sg_host_t host); +XBT_PUBLIC(void) sg_host_surfcpu_set(sg_host_t host, surf_cpu_t cpu); +XBT_PUBLIC(void) sg_host_surfcpu_destroy(sg_host_t host); + + +// Module initializer. Won't survive the conversion to C++. Hopefully. XBT_PUBLIC(void) sg_host_init(void); SG_END_DECL() diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index b85a67dd3f..7047cb7095 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -259,8 +259,6 @@ XBT_PUBLIC(void) SIMIX_process_set_function(const char* process_host, double process_kill_time); /*********************************** Host *************************************/ -//XBT_PUBLIC(xbt_dict_t) SIMIX_host_get_dict(u_smx_scalar_t *args); -XBT_PUBLIC(sg_host_t) SIMIX_host_get_by_name(const char *name); XBT_PUBLIC(sg_host_t) SIMIX_host_self(void); XBT_PUBLIC(const char*) SIMIX_host_self_get_name(void); #define SIMIX_host_get_name(h) sg_host_name(h) /* DEPRECATED: SIMIX_host_get_name */ diff --git a/include/surf/surf_routing.h b/include/surf/surf_routing.h index f44d94cf61..836a5d3fa9 100644 --- a/include/surf/surf_routing.h +++ b/include/surf/surf_routing.h @@ -14,7 +14,6 @@ SG_BEGIN_DECL() XBT_PUBLIC_DATA(xbt_lib_t) host_lib; XBT_PUBLIC_DATA(int) ROUTING_HOST_LEVEL; //Routing level -XBT_PUBLIC_DATA(int) SURF_CPU_LEVEL; //Surf cpu level XBT_PUBLIC_DATA(int) SURF_HOST_LEVEL; //Surf workstation level XBT_PUBLIC_DATA(int) SIMIX_STORAGE_LEVEL; //Simix storage level XBT_PUBLIC_DATA(int) SD_HOST_LEVEL; //Simdag host level diff --git a/src/bindings/java/surf_swig.cpp b/src/bindings/java/surf_swig.cpp index fef1748289..c1cc3afc14 100644 --- a/src/bindings/java/surf_swig.cpp +++ b/src/bindings/java/surf_swig.cpp @@ -35,16 +35,14 @@ void setCpuModel(CpuModel *cpuModel){ } void setCpu(char *name, Cpu *cpu) { - xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu); + sg_host_surfcpu_set(sg_host_by_name(name), cpu); } NetworkLinkDynar getRoute(char *srcName, char *dstName) { RoutingEdge *src = (RoutingEdge*)xbt_lib_get_or_null(host_lib, srcName, ROUTING_HOST_LEVEL); RoutingEdge *dst = (RoutingEdge*)xbt_lib_get_or_null(host_lib, dstName, ROUTING_HOST_LEVEL); - if (src==NULL) - xbt_die("TOTO"); - if (dst==NULL) - xbt_die("TOTO"); + xbt_assert(src,"Cannot get the route from a NULL source"); + xbt_assert(dst,"Cannot get the route to a NULL destination"); xbt_dynar_t route = xbt_dynar_new(sizeof(RoutingEdgePtr), NULL); routing_platf->getRouteAndLatency(src, dst, &route, NULL); return route; diff --git a/src/include/surf/surf.h b/src/include/surf/surf.h index 32dc7ad219..ed552ac83a 100644 --- a/src/include/surf/surf.h +++ b/src/include/surf/surf.h @@ -56,7 +56,6 @@ class ResourceLmm; class Host; class HostCLM03; class NetworkCm02Link; -class Cpu; class Action; class ActionLmm; class StorageActionLmm; @@ -75,7 +74,6 @@ typedef struct ResourceLmm ResourceLmm; typedef struct HostCLM03 HostCLM03; typedef struct Host Host; typedef struct NetworkCm02Link NetworkCm02Link; -typedef struct Cpu Cpu; typedef struct Action Action; typedef struct ActionLmm ActionLmm; typedef struct StorageActionLmm StorageActionLmm; @@ -103,7 +101,6 @@ typedef Resource *surf_cpp_resource_t; typedef Host *surf_host_t; typedef HostCLM03 *surf_host_CLM03_t; typedef NetworkCm02Link *surf_network_link_t; -typedef Cpu *surf_cpu_t; /** @ingroup SURF_c_bindings * \brief Action structure @@ -188,9 +185,6 @@ typedef enum { XBT_PUBLIC_DATA(routing_platf_t) routing_platf; -static inline surf_cpu_t surf_cpu_resource_priv(const void *host) { - return (surf_cpu_t)xbt_lib_get_level((xbt_dictelm_t)host, SURF_CPU_LEVEL); -} static inline surf_host_t surf_host_resource_priv(const void *host){ return (surf_host_t) xbt_lib_get_level((xbt_dictelm_t)host, SURF_HOST_LEVEL); } @@ -201,12 +195,6 @@ static inline void *surf_storage_resource_priv(const void *storage){ return (void*)xbt_lib_get_level((xbt_dictelm_t)storage, SURF_STORAGE_LEVEL); } -static inline void *surf_cpu_resource_by_name(const char *name) { - return xbt_lib_get_elm_or_null(host_lib, name); -} -static inline void *surf_host_resource_by_name(const char *name){ - return xbt_lib_get_elm_or_null(host_lib, name); -} static inline void *surf_storage_resource_by_name(const char *name){ return xbt_lib_get_elm_or_null(storage_lib, name); } diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 03a034f5bb..564aea92f6 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -8,14 +8,29 @@ #include "simgrid/host.h" #include "surf/surf_routing.h" // SIMIX_HOST_LEVEL and friends FIXME: make private here +sg_host_t sg_host_by_name(const char *name){ + return xbt_lib_get_elm_or_null(host_lib, name); +} + +// ========= Layering madness ============== + int SIMIX_HOST_LEVEL; int MSG_HOST_LEVEL; +int SURF_CPU_LEVEL; #include "simix/smx_host_private.h" // SIMIX_host_destroy. FIXME: killme #include "msg/msg_private.h" // MSG_host_priv_free. FIXME: killme +#include "surf/cpu_interface.hpp" + +static XBT_INLINE void surf_cpu_free(void *r) { + delete static_cast(r); +} + + void sg_host_init() { SIMIX_HOST_LEVEL = xbt_lib_add_level(host_lib,SIMIX_host_destroy); MSG_HOST_LEVEL = xbt_lib_add_level(host_lib, (void_f_pvoid_t) __MSG_host_priv_free); + SURF_CPU_LEVEL = xbt_lib_add_level(host_lib,surf_cpu_free); } @@ -36,11 +51,23 @@ smx_host_priv_t sg_host_simix(sg_host_t host){ return (smx_host_priv_t) xbt_lib_get_level(host, SIMIX_HOST_LEVEL); } void sg_host_simix_set(sg_host_t host, smx_host_priv_t smx_host) { - xbt_lib_set(host_lib,host->key,SIMIX_HOST_LEVEL,smx_host); + xbt_lib_set(host_lib,host->key,SIMIX_HOST_LEVEL,smx_host); } void sg_host_simix_destroy(sg_host_t host) { - xbt_lib_unset(host_lib,host->key,SIMIX_HOST_LEVEL,1); + xbt_lib_unset(host_lib,host->key,SIMIX_HOST_LEVEL,1); +} + +// ========== SURF CPU ============ +surf_cpu_t sg_host_surfcpu(sg_host_t host) { + return (surf_cpu_t) xbt_lib_get_level(host, SURF_CPU_LEVEL); } +void sg_host_surfcpu_set(sg_host_t host, surf_cpu_t cpu) { + xbt_lib_set(host_lib, host->key, SURF_CPU_LEVEL, cpu); +} +void sg_host_surfcpu_destroy(sg_host_t host) { + xbt_lib_unset(host_lib,host->key,SURF_CPU_LEVEL,1); +} + /* diff --git a/src/simix/popping_bodies.c b/src/simix/popping_bodies.c index dd5580aeb4..99bee4a923 100644 --- a/src/simix/popping_bodies.c +++ b/src/simix/popping_bodies.c @@ -21,7 +21,7 @@ inline static sg_host_t simcall_BODY_host_get_by_name(const char* name) { smx_process_t self = SIMIX_process_self(); /* Go to that function to follow the code flow through the simcall barrier */ - if (0) SIMIX_host_get_by_name(name); + if (0) sg_host_by_name(name); /* end of the guide intended to the poor programmer wanting to go from MSG to Surf */ self->simcall.call = SIMCALL_HOST_GET_BY_NAME; diff --git a/src/simix/popping_generated.c b/src/simix/popping_generated.c index d3f238865f..66cd986df3 100644 --- a/src/simix/popping_generated.c +++ b/src/simix/popping_generated.c @@ -169,7 +169,7 @@ void SIMIX_simcall_handle(smx_simcall_t simcall, int value) { return; switch (simcall->call) { case SIMCALL_HOST_GET_BY_NAME: - simcall->result.dp = SIMIX_host_get_by_name( simcall->args[0].cc); + simcall->result.dp = sg_host_by_name( simcall->args[0].cc); SIMIX_simcall_answer(simcall); break; diff --git a/src/simix/smx_deployment.c b/src/simix/smx_deployment.c index faf3c7b27c..7a3b025474 100644 --- a/src/simix/smx_deployment.c +++ b/src/simix/smx_deployment.c @@ -23,7 +23,7 @@ extern int surf_parse_lineno; static void parse_process(sg_platf_process_cbarg_t process) { - sg_host_t host = SIMIX_host_get_by_name(process->host); + sg_host_t host = sg_host_by_name(process->host); if (!host) THROWF(arg_error, 0, "Host '%s' unknown", process->host); parse_code = SIMIX_get_registered_function(process->function); @@ -196,7 +196,7 @@ void SIMIX_process_set_function(const char *process_host, { s_sg_platf_process_cbarg_t process = SG_PLATF_PROCESS_INITIALIZER; - sg_host_t host = SIMIX_host_get_by_name(process_host); + sg_host_t host = sg_host_by_name(process_host); if (!host) THROWF(arg_error, 0, "Host '%s' unknown", process_host); process.host = sg_host_name(host); diff --git a/src/simix/smx_global.c b/src/simix/smx_global.c index 9f66e79605..f5ea654e2b 100644 --- a/src/simix/smx_global.c +++ b/src/simix/smx_global.c @@ -206,7 +206,6 @@ void SIMIX_global_init(int *argc, char **argv) simix_timers = xbt_heap_new(8, &free); } - sg_host_init(); SIMIX_STORAGE_LEVEL = xbt_lib_add_level(storage_lib, SIMIX_storage_destroy); if (sg_cfg_get_boolean("clean_atexit")) @@ -486,7 +485,7 @@ void SIMIX_run(void) char *hostname = NULL; xbt_dynar_foreach(host_that_restart,iter,hostname) { XBT_INFO("Restart processes on host: %s",hostname); - SIMIX_host_autorestart(SIMIX_host_get_by_name(hostname)); + SIMIX_host_autorestart(sg_host_by_name(hostname)); } xbt_dynar_reset(host_that_restart); } diff --git a/src/simix/smx_host.c b/src/simix/smx_host.c index 17bc3c93dd..bac8423183 100644 --- a/src/simix/smx_host.c +++ b/src/simix/smx_host.c @@ -148,10 +148,6 @@ void SIMIX_host_destroy(void *h) return; } -sg_host_t SIMIX_host_get_by_name(const char *name){ - return xbt_lib_get_elm_or_null(host_lib, name); -} - sg_host_t SIMIX_host_self(void) { smx_process_t process = SIMIX_process_self(); diff --git a/src/simix/smx_process.c b/src/simix/smx_process.c index 8dbf2764f1..57cc5943d9 100644 --- a/src/simix/smx_process.c +++ b/src/simix/smx_process.c @@ -234,7 +234,7 @@ void SIMIX_process_create(smx_process_t *process, smx_process_t parent_process) { *process = NULL; - sg_host_t host = SIMIX_host_get_by_name(hostname); + sg_host_t host = sg_host_by_name(hostname); XBT_DEBUG("Start process %s on host '%s'", name, hostname); diff --git a/src/simix/smx_vm.c b/src/simix/smx_vm.c index f060683b01..2f4ddbca24 100644 --- a/src/simix/smx_vm.c +++ b/src/simix/smx_vm.c @@ -30,7 +30,7 @@ sg_host_t SIMIX_vm_create(const char *name, sg_host_t ind_phys_host) /* We will be able to register the VM to its physical host, so that we can promptly * retrieve the list VMs on the physical host. */ - return SIMIX_host_get_by_name(name); + return sg_host_by_name(name); } diff --git a/src/surf/cpu_cas01.cpp b/src/surf/cpu_cas01.cpp index d5fb35574b..976b54a97b 100644 --- a/src/surf/cpu_cas01.cpp +++ b/src/surf/cpu_cas01.cpp @@ -113,7 +113,8 @@ CpuPtr CpuCas01Model::createCpu(const char *name, xbt_dynar_t power_peak, xbt_dict_t cpu_properties) { CpuPtr cpu = NULL; - xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)), + sg_host_t host = sg_host_by_name(name); + xbt_assert(!sg_host_surfcpu(host), "Host '%s' declared several times in the platform file", name); xbt_assert(xbt_dynar_getfirst_as(power_peak, double) > 0.0, @@ -121,7 +122,7 @@ CpuPtr CpuCas01Model::createCpu(const char *name, xbt_dynar_t power_peak, xbt_assert(core > 0, "Invalid number of cores %d. Must be larger than 0", core); cpu = new CpuCas01(this, name, power_peak, pstate, power_scale, power_trace, core, state_initial, state_trace, cpu_properties); - xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu); + sg_host_surfcpu_set(host, cpu); return cpu; } @@ -144,7 +145,7 @@ void CpuCas01Model::addTraces() /* connect all traces relative to hosts */ xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) { tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name); - CpuCas01Ptr host = static_cast(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm))); + CpuCas01Ptr host = static_cast(sg_host_surfcpu(sg_host_by_name(elm))); xbt_assert(host, "Host %s undefined", elm); xbt_assert(trace, "Trace %s undefined", trace_name); @@ -154,7 +155,7 @@ void CpuCas01Model::addTraces() xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) { tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name); - CpuCas01Ptr host = static_cast(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm))); + CpuCas01Ptr host = static_cast(sg_host_surfcpu(sg_host_by_name(elm))); xbt_assert(host, "Host %s undefined", elm); xbt_assert(trace, "Trace %s undefined", trace_name); diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index a2dd954e81..045e6fe567 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -17,7 +17,6 @@ class CpuModel; typedef CpuModel *CpuModelPtr; class Cpu; -typedef Cpu *CpuPtr; class CpuAction; typedef CpuAction *CpuActionPtr; diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index 81a156d427..5d3cbf3bc1 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -434,14 +434,15 @@ CpuPtr CpuTiModel::createCpu(const char *name, xbt_dict_t cpuProperties) { xbt_assert(core==1,"Multi-core not handled with this model yet"); - xbt_assert(!surf_cpu_resource_priv(surf_cpu_resource_by_name(name)), + sg_host_t host = sg_host_by_name(name); + xbt_assert(!sg_host_surfcpu(host), "Host '%s' declared several times in the platform file", name); xbt_assert(xbt_dynar_getfirst_as(powerPeak, double) > 0.0, "Power has to be >0.0. Did you forget to specify the mandatory power attribute?"); CpuTiPtr cpu = new CpuTi(this, name, powerPeak, pstate, powerScale, powerTrace, core, stateInitial, stateTrace, cpuProperties); - xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, static_cast(cpu)); + sg_host_surfcpu_set(host, cpu); return cpu; } @@ -495,7 +496,7 @@ void CpuTiModel::addTraces() /* connect all traces relative to hosts */ xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) { tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name); - CpuTiPtr cpu = static_cast(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm))); + CpuTiPtr cpu = static_cast(sg_host_surfcpu(sg_host_by_name(elm))); xbt_assert(cpu, "Host %s undefined", elm); xbt_assert(trace, "Trace %s undefined", trace_name); @@ -511,7 +512,7 @@ void CpuTiModel::addTraces() xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) { tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name); - CpuTiPtr cpu = static_cast(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm))); + CpuTiPtr cpu = static_cast(sg_host_surfcpu(sg_host_by_name(elm))); xbt_assert(cpu, "Host %s undefined", elm); xbt_assert(trace, "Trace %s undefined", trace_name); diff --git a/src/surf/host_clm03.cpp b/src/surf/host_clm03.cpp index 5c1a5d60fa..9cac53fccc 100644 --- a/src/surf/host_clm03.cpp +++ b/src/surf/host_clm03.cpp @@ -56,10 +56,11 @@ HostCLM03Model::~HostCLM03Model() {} HostPtr HostCLM03Model::createHost(const char *name){ + sg_host_t sg_host = sg_host_by_name(name); HostPtr host = new HostCLM03(surf_host_model, name, NULL, (xbt_dynar_t)xbt_lib_get_or_null(storage_lib, name, ROUTING_STORAGE_HOST_LEVEL), (RoutingEdgePtr)xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL), - static_cast(xbt_lib_get_or_null(host_lib, name, SURF_CPU_LEVEL))); + sg_host_surfcpu(sg_host)); XBT_DEBUG("Create host %s with %ld mounted disks", name, xbt_dynar_length(host->p_storage)); xbt_lib_set(host_lib, name, SURF_HOST_LEVEL, host); return host; diff --git a/src/surf/host_ptask_L07.cpp b/src/surf/host_ptask_L07.cpp index 4b7b762f09..053611a34a 100644 --- a/src/surf/host_ptask_L07.cpp +++ b/src/surf/host_ptask_L07.cpp @@ -275,13 +275,15 @@ ActionPtr HostL07Model::executeParallelTask(int host_nb, HostPtr HostL07Model::createHost(const char *name) { HostL07Ptr wk = NULL; - xbt_assert(!surf_host_resource_priv(surf_host_resource_by_name(name)), + sg_host_t sg_host = sg_host_by_name(name); + + xbt_assert(!surf_host_resource_priv(sg_host), "Host '%s' declared several times in the platform file.", name); wk = new HostL07(this, name, NULL, static_cast(xbt_lib_get_or_null(host_lib, name, ROUTING_HOST_LEVEL)), - static_cast(xbt_lib_get_or_null(host_lib, name, SURF_CPU_LEVEL))); + sg_host_surfcpu(sg_host)); xbt_lib_set(host_lib, name, SURF_HOST_LEVEL, wk); @@ -323,8 +325,9 @@ CpuPtr CpuL07Model::createCpu(const char *name, xbt_dynar_t powerPeak, { double power_initial = xbt_dynar_get_as(powerPeak, pstate, double); xbt_dynar_free(&powerPeak); // kill memory leak + sg_host_t sg_host = sg_host_by_name(name); - xbt_assert(!surf_host_resource_priv(surf_host_resource_by_name(name)), + xbt_assert(!surf_host_resource_priv(sg_host), "Host '%s' declared several times in the platform file.", name); @@ -332,7 +335,7 @@ CpuPtr CpuL07Model::createCpu(const char *name, xbt_dynar_t powerPeak, power_initial, power_scale, power_trace, core, state_initial, state_trace); - xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu); + sg_host_surfcpu_set(sg_host, cpu); return cpu; } @@ -373,7 +376,7 @@ void HostL07Model::addTraces() /* Connect traces relative to cpu */ xbt_dict_foreach(trace_connect_list_host_avail, cursor, trace_name, elm) { tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name); - CpuL07Ptr host = static_cast(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm))); + CpuL07Ptr host = static_cast(sg_host_surfcpu(sg_host_by_name(elm))); xbt_assert(host, "Host %s undefined", elm); xbt_assert(trace, "Trace %s undefined", trace_name); @@ -383,7 +386,7 @@ void HostL07Model::addTraces() xbt_dict_foreach(trace_connect_list_power, cursor, trace_name, elm) { tmgr_trace_t trace = (tmgr_trace_t) xbt_dict_get_or_null(traces_set_list, trace_name); - CpuL07Ptr host = static_cast(surf_cpu_resource_priv(surf_cpu_resource_by_name(elm))); + CpuL07Ptr host = static_cast(sg_host_surfcpu(sg_host_by_name(elm))); xbt_assert(host, "Host %s undefined", elm); xbt_assert(trace, "Trace %s undefined", trace_name); diff --git a/src/surf/surf_c_bindings.cpp b/src/surf/surf_c_bindings.cpp index ffcf0abbb9..5a44b9b6c0 100644 --- a/src/surf/surf_c_bindings.cpp +++ b/src/surf/surf_c_bindings.cpp @@ -18,10 +18,6 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(surf_kernel); * TOOLS * *********/ -static CpuPtr get_casted_cpu(surf_resource_t resource){ - return static_cast(surf_cpu_resource_priv(resource)); -} - static HostPtr get_casted_host(surf_resource_t resource){ return static_cast(surf_host_resource_priv(resource)); } @@ -447,7 +443,6 @@ void surf_host_set_params(surf_resource_t host, ws_params_t params){ void surf_vm_destroy(surf_resource_t resource){ /* Before clearing the entries in host_lib, we have to pick up resources. */ - CpuPtr cpu = get_casted_cpu(resource); VMPtr vm = get_casted_vm(resource); RoutingEdgePtr routing = get_casted_routing(resource); char* name = xbt_dict_get_elm_key(resource); @@ -457,14 +452,13 @@ void surf_vm_destroy(surf_resource_t resource){ * Do not call xbt_lib_remove() here. It deletes all levels of the key, * including MSG_HOST_LEVEL and others. We should unregister only what we know. */ - xbt_lib_unset(host_lib, name, SURF_CPU_LEVEL, 0); + sg_host_surfcpu_destroy((sg_host_t)resource); xbt_lib_unset(host_lib, name, ROUTING_HOST_LEVEL, 0); xbt_lib_unset(host_lib, name, SURF_HOST_LEVEL, 0); /* TODO: comment out when VM storage is implemented. */ // xbt_lib_unset(host_lib, name, SURF_STORAGE_LEVEL, 0); - delete cpu; delete vm; delete routing; } @@ -498,7 +492,7 @@ void surf_vm_set_bound(surf_resource_t vm, double bound){ } void surf_vm_set_affinity(surf_resource_t vm, surf_resource_t cpu, unsigned long mask){ - return get_casted_vm(vm)->setAffinity(get_casted_cpu(cpu), mask); + return get_casted_vm(vm)->setAffinity(sg_host_surfcpu(cpu), mask); } int surf_network_link_is_shared(surf_cpp_resource_t link){ @@ -534,11 +528,11 @@ const char* surf_storage_get_host(surf_resource_t resource){ } surf_action_t surf_cpu_execute(surf_resource_t cpu, double size){ - return get_casted_cpu(cpu)->execute(size); + return sg_host_surfcpu(cpu)->execute(size); } surf_action_t surf_cpu_sleep(surf_resource_t cpu, double duration){ - return get_casted_cpu(cpu)->sleep(duration); + return sg_host_surfcpu(cpu)->sleep(duration); } double surf_action_get_start_time(surf_action_t action){ @@ -594,7 +588,7 @@ double surf_action_get_cost(surf_action_t action){ } void surf_cpu_action_set_affinity(surf_action_t action, surf_resource_t cpu, unsigned long mask) { - static_cast(action)->setAffinity(get_casted_cpu(cpu), mask); + static_cast(action)->setAffinity(sg_host_surfcpu(cpu), mask); } void surf_cpu_action_set_bound(surf_action_t action, double bound) { diff --git a/src/surf/surf_interface.cpp b/src/surf/surf_interface.cpp index 3b34cc75ba..cbb2f02a6a 100644 --- a/src/surf/surf_interface.cpp +++ b/src/surf/surf_interface.cpp @@ -365,11 +365,6 @@ static XBT_INLINE void routing_asr_prop_free(void *p) xbt_dict_free(&elm); } -static XBT_INLINE void surf_cpu_free(void *r) -{ - delete static_cast(r); -} - static XBT_INLINE void surf_link_free(void *r) { delete static_cast(r); @@ -403,13 +398,14 @@ void surf_init(int *argc, char **argv) file_lib = xbt_lib_new(); watched_hosts_lib = xbt_dict_new_homogeneous(NULL); + sg_host_init(); + XBT_DEBUG("Add routing levels"); ROUTING_HOST_LEVEL = xbt_lib_add_level(host_lib,routing_asr_host_free); ROUTING_ASR_LEVEL = xbt_lib_add_level(as_router_lib,routing_asr_host_free); ROUTING_PROP_ASR_LEVEL = xbt_lib_add_level(as_router_lib,routing_asr_prop_free); XBT_DEBUG("Add SURF levels"); - SURF_CPU_LEVEL = xbt_lib_add_level(host_lib,surf_cpu_free); SURF_HOST_LEVEL = xbt_lib_add_level(host_lib,surf_host_free); SURF_LINK_LEVEL = xbt_lib_add_level(link_lib,surf_link_free); SURF_STORAGE_LEVEL = xbt_lib_add_level(storage_lib,surf_storage_free); diff --git a/src/surf/surf_interface.hpp b/src/surf/surf_interface.hpp index 8b61329a01..95ac8a6ec7 100644 --- a/src/surf/surf_interface.hpp +++ b/src/surf/surf_interface.hpp @@ -60,7 +60,6 @@ XBT_PUBLIC(double) surf_get_clock(void); } extern double sg_sender_gap; -XBT_PUBLIC_DATA(int) SURF_CPU_LEVEL; //Surf cpu level extern surf_callback(void, void) surfExitCallbacks; diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index 0738974e91..6c723ec1ee 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -24,7 +24,6 @@ xbt_lib_t host_lib; int ROUTING_HOST_LEVEL; //Routing level -int SURF_CPU_LEVEL; //Surf cpu level int SURF_HOST_LEVEL; //Surf host level int SIMIX_STORAGE_LEVEL; //Simix storage level int MSG_STORAGE_LEVEL; //Msg storage level diff --git a/src/surf/vm_hl13.cpp b/src/surf/vm_hl13.cpp index d567fc51f6..b7e7b9b31f 100644 --- a/src/surf/vm_hl13.cpp +++ b/src/surf/vm_hl13.cpp @@ -241,10 +241,7 @@ VMHL13::VMHL13(VMModelPtr model, const char* name, xbt_dict_t props, // //// CPU RELATED STUFF //// // Roughly, create a vcpu resource by using the values of the sub_cpu one. - CpuCas01Ptr sub_cpu = static_cast(surf_cpu_resource_priv(host_PM)); - - /* We can assume one core and cas01 cpu for the first step. - * Do xbt_lib_set(host_lib, name, SURF_CPU_LEVEL, cpu) if you get the resource. */ + CpuCas01Ptr sub_cpu = static_cast(sg_host_surfcpu(host_PM)); p_cpu = surf_cpu_model_vm->createCpu(name, // name sub_cpu->getPowerPeakList(), // host->power_peak, @@ -367,7 +364,7 @@ void VMHL13::migrate(surf_resource_t ind_dst_pm) /* create a cpu action bound to the pm model at the destination. */ CpuActionPtr new_cpu_action = static_cast( - static_cast(surf_cpu_resource_priv(ind_dst_pm))->execute(0)); + static_cast(sg_host_surfcpu(ind_dst_pm))->execute(0)); e_surf_action_state_t state = p_action->getState(); if (state != SURF_ACTION_DONE) diff --git a/teshsuite/surf/surf_usage/surf_usage.c b/teshsuite/surf/surf_usage/surf_usage.c index f6e335ee6c..a1e779e82b 100644 --- a/teshsuite/surf/surf_usage/surf_usage.c +++ b/teshsuite/surf/surf_usage/surf_usage.c @@ -58,12 +58,12 @@ void test(char *platform) /*********************** CPU ***********************************/ XBT_DEBUG("%p", surf_cpu_model_pm); - cpuA = surf_cpu_resource_by_name("Cpu A"); - cpuB = surf_cpu_resource_by_name("Cpu B"); + cpuA = sg_host_by_name("Cpu A"); + cpuB = sg_host_by_name("Cpu B"); /* Let's check that those two processors exist */ - XBT_DEBUG("%s : %p", surf_cpu_name(surf_cpu_resource_priv(cpuA)), cpuA); - XBT_DEBUG("%s : %p", surf_cpu_name(surf_cpu_resource_priv(cpuB)), cpuB); + XBT_DEBUG("%s : %p", surf_cpu_name(sg_host_surfcpu(cpuA)), cpuA); + XBT_DEBUG("%s : %p", surf_cpu_name(sg_host_surfcpu(cpuB)), cpuB); /* Let's do something on it */ actionA = surf_cpu_execute(cpuA, 1000.0); diff --git a/teshsuite/surf/surf_usage/surf_usage2.c b/teshsuite/surf/surf_usage/surf_usage2.c index dbb1c6a75c..585415ba83 100644 --- a/teshsuite/surf/surf_usage/surf_usage2.c +++ b/teshsuite/surf/surf_usage/surf_usage2.c @@ -42,8 +42,8 @@ const char *string_action(e_surf_action_state_t state) void test(char *platform); void test(char *platform) { - void *hostA = NULL; - void *hostB = NULL; + sg_host_t hostA = NULL; + sg_host_t hostB = NULL; double now = -1.0; int running; @@ -52,12 +52,12 @@ void test(char *platform) parse_platform_file(platform); /*********************** HOST ***********************************/ - hostA = surf_host_resource_by_name("Cpu A"); - hostB = surf_host_resource_by_name("Cpu B"); + hostA = sg_host_by_name("Cpu A"); + hostB = sg_host_by_name("Cpu B"); /* Let's check that those two processors exist */ - XBT_DEBUG("%s : %p", surf_resource_name(hostA), hostA); - XBT_DEBUG("%s : %p", surf_resource_name(hostB), hostB); + XBT_DEBUG("%s : %p", sg_host_get_name(hostA), hostA); + XBT_DEBUG("%s : %p", sg_host_get_name(hostB), hostB); /* Let's do something on it */ surf_host_execute(hostA, 1000.0);