From b66dd193ce8a5d33bf68bfc86b2a961d917f5103 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Wed, 15 Jul 2015 02:57:44 +0200 Subject: [PATCH 1/1] [SGpp] make MSG_HOST_LEVEL private --- include/simgrid/host.h | 10 +++++++-- include/simgrid/msg.h | 41 ++++++++++++------------------------ include/surf/surf_routing.h | 1 - src/bindings/lua/lua_host.c | 4 ++-- src/bindings/lua/lua_platf.c | 5 ++--- src/msg/msg_global.c | 1 - src/msg/msg_host.c | 14 +++++------- src/msg/msg_private.h | 5 +---- src/msg/msg_vm.c | 23 ++++++++++---------- src/simgrid/host.cpp | 21 ++++++++++++++++-- src/surf/surf_routing.cpp | 1 - 11 files changed, 63 insertions(+), 63 deletions(-) diff --git a/include/simgrid/host.h b/include/simgrid/host.h index b7a79f0549..fcee52ca98 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -13,9 +13,15 @@ SG_BEGIN_DECL() typedef xbt_dictelm_t sg_host_t; -typedef struct s_smx_host_priv *smx_host_priv_t; -// Function returning the SIMIX's private part of the host +// ========== MSG Layer ============== +typedef struct s_msg_host_priv *msg_host_priv_t; +msg_host_priv_t sg_host_msg(sg_host_t host); +XBT_PUBLIC(void) sg_host_msg_set(sg_host_t host, msg_host_priv_t priv); +XBT_PUBLIC(void) sg_host_msg_destroy(sg_host_t host); + +// ========== Simix layer ============= +typedef struct s_smx_host_priv *smx_host_priv_t; 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); diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index f04ce916ab..9afe122fb6 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2004-2014. The SimGrid Team. +/* Copyright (c) 2004-2015. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -33,8 +33,6 @@ typedef struct As *msg_as_t; /* ******************************** Host ************************************ */ -XBT_PUBLIC_DATA(int) MSG_HOST_LEVEL; - /** @brief Host datatype. @ingroup m_host_management @@ -45,9 +43,9 @@ XBT_PUBLIC_DATA(int) MSG_HOST_LEVEL; some private data that can be only accessed by local process. */ -typedef xbt_dictelm_t msg_host_t; +typedef sg_host_t msg_host_t; -typedef struct msg_host_priv { +typedef struct s_msg_host_priv { int dp_enabled; xbt_dict_t dp_objs; double dp_updated_by_deleted_tasks; @@ -58,13 +56,7 @@ typedef struct msg_host_priv { #ifdef MSG_USE_DEPRECATED msg_mailbox_t *mailboxes; /**< the channels */ #endif -} s_msg_host_priv_t, *msg_host_priv_t; - -static inline msg_host_priv_t MSG_host_priv(msg_host_t host){ - return (msg_host_priv_t )xbt_lib_get_level(host, MSG_HOST_LEVEL); -} - - +} s_msg_host_priv_t; /* ******************************** Task ************************************ */ @@ -89,11 +81,6 @@ typedef struct msg_task *msg_task_t; /* ******************************** VM ************************************* */ typedef msg_host_t msg_vm_t; -typedef msg_host_priv_t msg_vm_priv_t; - -static inline msg_vm_priv_t MSG_vm_priv(msg_vm_t vm){ - return (msg_vm_priv_t) xbt_lib_get_level(vm, MSG_HOST_LEVEL); -} /** ******************************** File ************************************ */ @@ -288,7 +275,7 @@ XBT_PUBLIC(msg_error_t) MSG_file_move(msg_file_t fd, const char* fullpath); XBT_PUBLIC(msg_error_t) MSG_file_rcopy(msg_file_t fd, msg_host_t host, const char* fullpath); XBT_PUBLIC(msg_error_t) MSG_file_rmove(msg_file_t fd, msg_host_t host, const char* fullpath); /************************** Storage handling ***********************************/ -XBT_PUBLIC(msg_host_t) MSG_get_storage_by_name(const char *name); +XBT_PUBLIC(msg_host_t) MSG_get_storage_by_name(const char *name); //FIXME: WAAAT? That cannot exist XBT_PUBLIC(const char *) MSG_storage_get_name(msg_storage_t storage); XBT_PUBLIC(sg_size_t) MSG_storage_get_free_size(msg_storage_t storage); XBT_PUBLIC(sg_size_t) MSG_storage_get_used_size(msg_storage_t storage); @@ -309,6 +296,8 @@ XBT_PUBLIC(xbt_dict_t) MSG_as_router_get_properties(const char* asr); XBT_PUBLIC(void) MSG_as_router_set_property_value(const char* asr, const char *name, char *value,void_f_pvoid_t free_ctn); /************************** Host handling ***********************************/ +XBT_PUBLIC(msg_host_t) MSG_host_get_by_name(const char *name); +#define MSG_get_host_by_name(n) MSG_host_get_by_name(n) /* Rewrite the old name into the new one transparently */ XBT_PUBLIC(msg_error_t) MSG_host_set_data(msg_host_t host, void *data); XBT_PUBLIC(void *) MSG_host_get_data(msg_host_t host); XBT_PUBLIC(const char *) MSG_host_get_name(msg_host_t host); @@ -324,7 +313,6 @@ XBT_PUBLIC(int) MSG_host_is_off(msg_host_t h); XBT_PUBLIC(double) MSG_host_get_wattmin_at(msg_host_t host, int pstate); XBT_PUBLIC(double) MSG_host_get_wattmax_at(msg_host_t host, int pstate); -XBT_PUBLIC(void) __MSG_host_priv_free(msg_host_priv_t priv); XBT_PUBLIC(void) __MSG_host_destroy(msg_host_t host); XBT_PUBLIC(double) MSG_host_get_power_peak_at(msg_host_t h, int pstate); @@ -332,6 +320,13 @@ XBT_PUBLIC(double) MSG_host_get_current_power_peak(msg_host_t h); XBT_PUBLIC(int) MSG_host_get_nb_pstates(msg_host_t h); XBT_PUBLIC(void) MSG_host_set_pstate(msg_host_t h, int pstate); XBT_PUBLIC(int) MSG_host_get_pstate(msg_host_t host); +XBT_PUBLIC(xbt_dynar_t) MSG_hosts_as_dynar(void); +XBT_PUBLIC(int) MSG_get_host_number(void); +XBT_PUBLIC(void) MSG_host_get_params(msg_host_t ind_pm, ws_params_t params); +XBT_PUBLIC(void) MSG_host_set_params(msg_host_t ind_pm, ws_params_t params); +XBT_PUBLIC(xbt_dict_t) MSG_host_get_mounted_storage_list(msg_host_t host); +XBT_PUBLIC(xbt_dynar_t) MSG_host_get_attached_storage_list(msg_host_t host); +XBT_PUBLIC(xbt_dict_t) MSG_host_get_storage_content(msg_host_t host); XBT_PUBLIC(double) MSG_host_get_consumed_energy(msg_host_t h); @@ -346,14 +341,6 @@ XBT_PUBLIC(void) MSG_host_set_property_value(msg_host_t host, XBT_PUBLIC(void) MSG_create_environment(const char *file); -XBT_PUBLIC(msg_host_t) MSG_get_host_by_name(const char *name); -XBT_PUBLIC(xbt_dynar_t) MSG_hosts_as_dynar(void); -XBT_PUBLIC(int) MSG_get_host_number(void); -XBT_PUBLIC(void) MSG_host_get_params(msg_host_t ind_pm, ws_params_t params); -XBT_PUBLIC(void) MSG_host_set_params(msg_host_t ind_pm, ws_params_t params); -XBT_PUBLIC(xbt_dict_t) MSG_host_get_mounted_storage_list(msg_host_t host); -XBT_PUBLIC(xbt_dynar_t) MSG_host_get_attached_storage_list(msg_host_t host); -XBT_PUBLIC(xbt_dict_t) MSG_host_get_storage_content(msg_host_t host); /************************** Process handling *********************************/ XBT_PUBLIC(msg_process_t) MSG_process_create(const char *name, xbt_main_func_t code, diff --git a/include/surf/surf_routing.h b/include/surf/surf_routing.h index d6a68df24e..f44d94cf61 100644 --- a/include/surf/surf_routing.h +++ b/include/surf/surf_routing.h @@ -17,7 +17,6 @@ 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) MSG_HOST_LEVEL; //Msg level XBT_PUBLIC_DATA(int) SD_HOST_LEVEL; //Simdag host level XBT_PUBLIC_DATA(int) SD_STORAGE_LEVEL; //Simdag storage level XBT_PUBLIC_DATA(int) COORD_HOST_LEVEL; //Coordinates level diff --git a/src/bindings/lua/lua_host.c b/src/bindings/lua/lua_host.c index 21c697cf4f..04c6eb6e87 100644 --- a/src/bindings/lua/lua_host.c +++ b/src/bindings/lua/lua_host.c @@ -183,8 +183,8 @@ static int l_host_sleep(lua_State *L) */ static int l_host_destroy(lua_State *L) { - msg_host_t ht = sglua_check_host(L, 1); - __MSG_host_priv_free(MSG_host_priv(ht)); + //msg_host_t ht = sglua_check_host(L, 1); + //FIXME: not working..__MSG_host_priv_free(MSG_host_priv(ht)); return 0; } diff --git a/src/bindings/lua/lua_platf.c b/src/bindings/lua/lua_platf.c index 2cd35f4f89..1a73c97818 100644 --- a/src/bindings/lua/lua_platf.c +++ b/src/bindings/lua/lua_platf.c @@ -370,7 +370,7 @@ int console_set_function(lua_State *L) { lua_pop(L, 1); // FIXME: hackish to go under MSG that way - msg_host_t host = xbt_lib_get_or_null(host_lib,host_id,MSG_HOST_LEVEL); + msg_host_t host = MSG_host_get_by_name(host_id); if (!host) { XBT_ERROR("no host '%s' found",host_id); return -1; @@ -409,8 +409,7 @@ int console_host_set_property(lua_State *L) { prop_value = lua_tostring(L,-1); lua_pop(L, 1); - // FIXME: hackish to go under MSG that way - msg_host_t host = xbt_lib_get_or_null(host_lib,name,MSG_HOST_LEVEL); + msg_host_t host = MSG_host_get_by_name(name); if (!host) { XBT_ERROR("no host '%s' found",name); return -1; diff --git a/src/msg/msg_global.c b/src/msg/msg_global.c index bfb859b5b8..4a39e27b04 100644 --- a/src/msg/msg_global.c +++ b/src/msg/msg_global.c @@ -70,7 +70,6 @@ void MSG_init_nocheck(int *argc, char **argv) { } XBT_DEBUG("ADD MSG LEVELS"); - MSG_HOST_LEVEL = xbt_lib_add_level(host_lib, (void_f_pvoid_t) __MSG_host_priv_free); MSG_STORAGE_LEVEL = xbt_lib_add_level(storage_lib, (void_f_pvoid_t) __MSG_storage_destroy); MSG_FILE_LEVEL = xbt_lib_add_level(file_lib, (void_f_pvoid_t) __MSG_file_destroy); if(sg_cfg_get_boolean("clean_atexit")) atexit(MSG_exit); diff --git a/src/msg/msg_host.c b/src/msg/msg_host.c index 06e5a2551d..a708a94212 100644 --- a/src/msg/msg_host.c +++ b/src/msg/msg_host.c @@ -26,9 +26,8 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(msg); */ /********************************* Host **************************************/ -msg_host_t __MSG_host_create(sg_host_t host) +msg_host_t __MSG_host_create(sg_host_t host) // FIXME: don't return our parameter { - const char *name = SIMIX_host_get_name(host); msg_host_priv_t priv = xbt_new0(s_msg_host_priv_t, 1); #ifdef MSG_USE_DEPRECATED @@ -55,12 +54,11 @@ msg_host_t __MSG_host_create(sg_host_t host) priv->affinity_mask_db = xbt_dict_new_homogeneous(NULL); - xbt_lib_set(host_lib, name, MSG_HOST_LEVEL, priv); + sg_host_msg_set(host,priv); - return xbt_lib_get_elm_or_null(host_lib, name); + return host; } - /** \ingroup m_host_management * \brief Finds a msg_host_t using its name. * @@ -68,7 +66,7 @@ msg_host_t __MSG_host_create(sg_host_t host) * \param name the name of an host. * \return the corresponding host */ -msg_host_t MSG_get_host_by_name(const char *name) +msg_host_t MSG_host_get_by_name(const char *name) { return (msg_host_t) xbt_lib_get_elm_or_null(host_lib,name); } @@ -165,13 +163,11 @@ void __MSG_host_priv_free(msg_host_priv_t priv) */ void __MSG_host_destroy(msg_host_t host) { - const char *name = MSG_host_get_name(host); /* TODO: * What happens if VMs still remain on this host? * Revisit here after the surf layer gets stable. **/ - - xbt_lib_unset(host_lib, name, MSG_HOST_LEVEL, 1); + sg_host_msg_destroy(host); } /** \ingroup m_host_management diff --git a/src/msg/msg_private.h b/src/msg/msg_private.h index 4303aaf9ec..c3cfcdb0c8 100644 --- a/src/msg/msg_private.h +++ b/src/msg/msg_private.h @@ -157,6 +157,7 @@ XBT_PUBLIC_DATA(MSG_Global_t) msg_global; msg_host_t __MSG_host_create(sg_host_t host); msg_storage_t __MSG_storage_create(smx_storage_t storage); void __MSG_host_destroy(msg_host_t host); +void __MSG_host_priv_free(msg_host_priv_t priv); void __MSG_storage_destroy(msg_storage_priv_t host); void __MSG_file_destroy(msg_file_priv_t host); @@ -171,10 +172,6 @@ void MSG_comm_copy_data_from_SIMIX(smx_synchro_t comm, void* buff, size_t buff_s void MSG_post_create_environment(void); -static inline void *msg_host_resource_priv(const void *host) { - return xbt_lib_get_level((void *)host, MSG_HOST_LEVEL); -} - void MSG_host_add_task(msg_host_t host, msg_task_t task); void MSG_host_del_task(msg_host_t host, msg_task_t task); diff --git a/src/msg/msg_vm.c b/src/msg/msg_vm.c index c60a3eb171..1c2efedb7c 100644 --- a/src/msg/msg_vm.c +++ b/src/msg/msg_vm.c @@ -16,6 +16,7 @@ #include "xbt/sysdep.h" #include "xbt/log.h" #include "simgrid/platf.h" +#include "simgrid/host.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_vm, msg, "Cloud-oriented parts of the MSG API"); @@ -118,7 +119,7 @@ int MSG_vm_is_running(msg_vm_t vm) */ int MSG_vm_is_migrating(msg_vm_t vm) { - msg_host_priv_t priv = msg_host_resource_priv(vm); + msg_host_priv_t priv = sg_host_msg(vm); return priv->is_migrating; } @@ -390,7 +391,7 @@ static int migration_rx_fun(int argc, char *argv[]) msg_vm_t vm = ms->vm; msg_host_t src_pm = ms->src_pm; msg_host_t dst_pm = ms-> dst_pm; - msg_host_priv_t priv = msg_host_resource_priv(vm); + msg_host_priv_t priv = sg_host_msg(vm); // // TODO: we have an issue, if the DST node is turning off during the three next calls, then the VM is in an inconsistent state // // I should check with Takahiro in order to make this portion of code atomic @@ -416,7 +417,7 @@ static int migration_rx_fun(int argc, char *argv[]) { // Now the VM is running on the new host (the migration is completed) (even if the SRC crash) - msg_host_priv_t priv = msg_host_resource_priv(vm); + msg_host_priv_t priv = sg_host_msg(vm); priv->is_migrating = 0; XBT_DEBUG("VM(%s) moved from PM(%s) to PM(%s)", ms->vm->key, ms->src_pm->key, ms->dst_pm->key); TRACE_msg_vm_change_host(ms->vm, ms->src_pm, ms->dst_pm); @@ -449,7 +450,7 @@ static int migration_rx_fun(int argc, char *argv[]) static void reset_dirty_pages(msg_vm_t vm) { - msg_host_priv_t priv = msg_host_resource_priv(vm); + msg_host_priv_t priv = sg_host_msg(vm); char *key = NULL; xbt_dict_cursor_t cursor = NULL; @@ -465,7 +466,7 @@ static void reset_dirty_pages(msg_vm_t vm) static void start_dirty_page_tracking(msg_vm_t vm) { - msg_host_priv_t priv = msg_host_resource_priv(vm); + msg_host_priv_t priv = sg_host_msg(vm); priv->dp_enabled = 1; reset_dirty_pages(vm); @@ -473,7 +474,7 @@ static void start_dirty_page_tracking(msg_vm_t vm) static void stop_dirty_page_tracking(msg_vm_t vm) { - msg_host_priv_t priv = msg_host_resource_priv(vm); + msg_host_priv_t priv = sg_host_msg(vm); priv->dp_enabled = 0; } @@ -509,7 +510,7 @@ static double get_computed(char *key, msg_vm_t vm, dirty_page_t dp, double remai static double lookup_computed_flop_counts(msg_vm_t vm, int stage_for_fancy_debug, int stage2_round_for_fancy_debug) { - msg_host_priv_t priv = msg_host_resource_priv(vm); + msg_host_priv_t priv = sg_host_msg(vm); double total = 0; char *key = NULL; @@ -546,7 +547,7 @@ static double lookup_computed_flop_counts(msg_vm_t vm, int stage_for_fancy_debug // msg_process_t MSG_process_create(const char *name, xbt_main_func_t code, void *data, msg_host_t host) void MSG_host_add_task(msg_host_t host, msg_task_t task) { - msg_host_priv_t priv = msg_host_resource_priv(host); + msg_host_priv_t priv = sg_host_msg(host); double remaining = MSG_task_get_flops_amount(task); char *key = bprintf("%s-%p", task->name, task); @@ -568,7 +569,7 @@ void MSG_host_add_task(msg_host_t host, msg_task_t task) void MSG_host_del_task(msg_host_t host, msg_task_t task) { - msg_host_priv_t priv = msg_host_resource_priv(host); + msg_host_priv_t priv = sg_host_msg(host); char *key = bprintf("%s-%p", task->name, task); @@ -978,7 +979,7 @@ void MSG_vm_migrate(msg_vm_t vm, msg_host_t new_pm) if (MSG_vm_is_migrating(vm)) THROWF(vm_error, 0, "VM(%s) is already migrating", sg_host_name(vm)); - msg_host_priv_t priv = msg_host_resource_priv(vm); + msg_host_priv_t priv = sg_host_msg(vm); priv->is_migrating = 1; { @@ -1126,7 +1127,7 @@ void MSG_vm_set_bound(msg_vm_t vm, double bound) */ void MSG_vm_set_affinity(msg_vm_t vm, msg_host_t pm, unsigned long mask) { - msg_host_priv_t priv = msg_host_resource_priv(vm); + msg_host_priv_t priv = sg_host_msg(vm); if (mask == 0) xbt_dict_remove_ext(priv->affinity_mask_db, (char *) pm, sizeof(pm)); diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 969a7387ff..03a034f5bb 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -8,13 +8,30 @@ #include "simgrid/host.h" #include "surf/surf_routing.h" // SIMIX_HOST_LEVEL and friends FIXME: make private here -int SIMIX_HOST_LEVEL; //Simix host level +int SIMIX_HOST_LEVEL; +int MSG_HOST_LEVEL; #include "simix/smx_host_private.h" // SIMIX_host_destroy. FIXME: killme +#include "msg/msg_private.h" // MSG_host_priv_free. FIXME: killme void sg_host_init() { - SIMIX_HOST_LEVEL = xbt_lib_add_level(host_lib,SIMIX_host_destroy); + 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); } + +// ========== MSG Layer ============== +msg_host_priv_t sg_host_msg(sg_host_t host) { + return (msg_host_priv_t) xbt_lib_get_level(host, MSG_HOST_LEVEL); +} +void sg_host_msg_set(sg_host_t host, msg_host_priv_t smx_host) { + xbt_lib_set(host_lib,host->key,MSG_HOST_LEVEL,smx_host); +} +void sg_host_msg_destroy(sg_host_t host) { + xbt_lib_unset(host_lib,host->key,MSG_HOST_LEVEL,1); +} + +// ========== Simix layer ============= + smx_host_priv_t sg_host_simix(sg_host_t host){ return (smx_host_priv_t) xbt_lib_get_level(host, SIMIX_HOST_LEVEL); } diff --git a/src/surf/surf_routing.cpp b/src/surf/surf_routing.cpp index 16485fbc99..0738974e91 100644 --- a/src/surf/surf_routing.cpp +++ b/src/surf/surf_routing.cpp @@ -27,7 +27,6 @@ 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_HOST_LEVEL; //Msg host level int MSG_STORAGE_LEVEL; //Msg storage level int MSG_FILE_LEVEL; //Msg file level int SD_HOST_LEVEL; //Simdag host level -- 2.20.1