From: Martin Quinson Date: Fri, 14 Oct 2016 15:45:14 +0000 (+0200) Subject: Reduce the layering madness a bit X-Git-Tag: v3_14~339 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/b62e431af6ffa480a59647aad94ffe0d292c05a8?hp=10cf0994b175d422edd693db91f25a96418b6862 Reduce the layering madness a bit + the changes requested by the clang-format hook --- diff --git a/examples/msg/process-migration/process-migration.c b/examples/msg/process-migration/process-migration.c index c1e0713549..b0f5157ae4 100644 --- a/examples/msg/process-migration/process-migration.c +++ b/examples/msg/process-migration/process-migration.c @@ -4,7 +4,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "simgrid/msg.h" -#include "xbt/synchro_core.h" +#include "xbt/synchro.h" XBT_LOG_NEW_DEFAULT_CATEGORY(msg_process_migration, "Messages specific for this msg example"); diff --git a/include/simgrid/msg.h b/include/simgrid/msg.h index 5965716b9d..2f826ad2bd 100644 --- a/include/simgrid/msg.h +++ b/include/simgrid/msg.h @@ -458,7 +458,7 @@ XBT_PUBLIC(int) MSG_sem_would_block(msg_sem_t sem); */ #define MSG_BARRIER_SERIAL_PROCESS -1 -typedef struct s_xbt_bar *msg_bar_t; +typedef struct s_msg_bar* msg_bar_t; XBT_PUBLIC(msg_bar_t) MSG_barrier_init( unsigned int count); XBT_PUBLIC(void) MSG_barrier_destroy(msg_bar_t bar); XBT_PUBLIC(int) MSG_barrier_wait(msg_bar_t bar); diff --git a/include/xbt/synchro_core.h b/include/xbt/synchro.h similarity index 78% rename from include/xbt/synchro_core.h rename to include/xbt/synchro.h index 6a54d5a5be..d0664f93db 100644 --- a/include/xbt/synchro_core.h +++ b/include/xbt/synchro.h @@ -1,20 +1,17 @@ -/* xbt/synchro_core.h -- Simulated synchronization */ +/* xbt/synchro.h -- Simulated synchronization */ /* Copyright (c) 2009-2016. The SimGrid Team. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ -/* splited away from synchro.h since we are used by dynar.h, and synchro.h uses dynar */ - - #ifndef _XBT_THREAD_H #define _XBT_THREAD_H #include -#include "xbt/misc.h" /* SG_BEGIN_DECL */ #include "xbt/function_types.h" +#include "xbt/misc.h" /* SG_BEGIN_DECL */ SG_BEGIN_DECL() @@ -31,7 +28,7 @@ SG_BEGIN_DECL() /** @brief Thread mutex data type (opaque object) * @hideinitializer */ -typedef struct s_smx_mutex_ *xbt_mutex_t; +typedef struct s_smx_mutex_* xbt_mutex_t; /** @brief Creates a new mutex variable */ XBT_PUBLIC(xbt_mutex_t) xbt_mutex_init(void); @@ -39,7 +36,7 @@ XBT_PUBLIC(xbt_mutex_t) xbt_mutex_init(void); /** @brief Blocks onto the given mutex variable */ XBT_PUBLIC(void) xbt_mutex_acquire(xbt_mutex_t mutex); -/** @brief Tries to block onto the given mutex variable +/** @brief Tries to block onto the given mutex variable * Tries to lock a mutex, return 1 if the mutex is unlocked, else 0. * This function does not block and wait for the mutex to be unlocked. * \param mutex The mutex @@ -53,11 +50,10 @@ XBT_PUBLIC(void) xbt_mutex_release(xbt_mutex_t mutex); /** @brief Destroyes the given mutex variable */ XBT_PUBLIC(void) xbt_mutex_destroy(xbt_mutex_t mutex); - /** @brief Thread condition data type (opaque object) * @hideinitializer */ -typedef struct s_smx_cond_ *xbt_cond_t; +typedef struct s_smx_cond_* xbt_cond_t; /** @brief Creates a condition variable */ XBT_PUBLIC(xbt_cond_t) xbt_cond_init(void); @@ -74,13 +70,7 @@ XBT_PUBLIC(void) xbt_cond_broadcast(xbt_cond_t cond); /** @brief Destroys the given mutex variable */ XBT_PUBLIC(void) xbt_cond_destroy(xbt_cond_t cond); -#define XBT_BARRIER_SERIAL_PROCESS -1 -typedef struct s_xbt_bar_ *xbt_bar_t; -XBT_PUBLIC(xbt_bar_t) xbt_barrier_init( unsigned int count); -XBT_PUBLIC(void) xbt_barrier_destroy(xbt_bar_t bar); -XBT_PUBLIC(int) xbt_barrier_wait(xbt_bar_t bar); - /** @} */ SG_END_DECL() -#endif /* _XBT_THREAD_H */ +#endif /* _XBT_THREAD_H */ diff --git a/src/bindings/java/jmsg_synchro.cpp b/src/bindings/java/jmsg_synchro.cpp index 7cbac4cb7c..7caebe7d87 100644 --- a/src/bindings/java/jmsg_synchro.cpp +++ b/src/bindings/java/jmsg_synchro.cpp @@ -9,9 +9,9 @@ #include #include "jmsg.h" -#include "xbt/synchro_core.h" #include "jmsg_synchro.h" #include "jxbt_utilities.h" +#include "xbt/synchro.h" XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(jmsg); diff --git a/src/msg/msg_synchro.cpp b/src/msg/msg_synchro.cpp index fa46da9ba5..eb1b25037f 100644 --- a/src/msg/msg_synchro.cpp +++ b/src/msg/msg_synchro.cpp @@ -7,9 +7,9 @@ #include #include "msg_private.h" -#include "xbt/sysdep.h" -#include "xbt/synchro_core.h" #include "xbt/log.h" +#include "xbt/synchro.h" +#include "xbt/sysdep.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(msg_synchro, msg, "Logging specific to MSG (synchro)"); @@ -63,21 +63,43 @@ int MSG_sem_would_block(msg_sem_t sem) { return simcall_sem_would_block(sem); } +/*-**** barrier related functions ****-*/ +typedef struct s_msg_bar { + xbt_mutex_t mutex; + xbt_cond_t cond; + unsigned int arrived_processes; + unsigned int expected_processes; +} s_msg_bar_t; + /** @brief Initializes a barrier, with count elements */ msg_bar_t MSG_barrier_init(unsigned int count) { - return (msg_bar_t)xbt_barrier_init(count); + msg_bar_t bar = xbt_new0(s_msg_bar, 1); + bar->expected_processes = count; + bar->arrived_processes = 0; + bar->mutex = xbt_mutex_init(); + bar->cond = xbt_cond_init(); + return bar; } /** @brief Initializes a barrier, with count elements */ void MSG_barrier_destroy(msg_bar_t bar) { - xbt_barrier_destroy((xbt_bar_t)bar); + xbt_mutex_destroy(bar->mutex); + xbt_cond_destroy(bar->cond); + xbt_free(bar); } /** @brief Performs a barrier already initialized */ int MSG_barrier_wait(msg_bar_t bar) { - if(xbt_barrier_wait((xbt_bar_t)bar) == XBT_BARRIER_SERIAL_PROCESS) + xbt_mutex_acquire(bar->mutex); + if (++bar->arrived_processes == bar->expected_processes) { + xbt_cond_broadcast(bar->cond); + xbt_mutex_release(bar->mutex); + bar->arrived_processes = 0; return MSG_BARRIER_SERIAL_PROCESS; - else - return 0; + } + + xbt_cond_wait(bar->cond, bar->mutex); + xbt_mutex_release(bar->mutex); + return 0; } /**@}*/ diff --git a/src/smpi/private.h b/src/smpi/private.h index 913a3b876e..41d07179d5 100644 --- a/src/smpi/private.h +++ b/src/smpi/private.h @@ -7,15 +7,15 @@ #ifndef SMPI_PRIVATE_H #define SMPI_PRIVATE_H +#include "simgrid/simix.h" +#include "smpi/smpi.h" +#include "src/include/smpi/smpi_interface.h" +#include "src/instr/instr_private.h" #include "src/internal_config.h" #include "xbt.h" #include "xbt/base.h" +#include "xbt/synchro.h" #include "xbt/xbt_os_time.h" -#include "xbt/synchro_core.h" -#include "simgrid/simix.h" -#include "src/include/smpi/smpi_interface.h" -#include "smpi/smpi.h" -#include "src/instr/instr_private.h" SG_BEGIN_DECL() @@ -180,7 +180,8 @@ XBT_PRIVATE int smpi_process_get_sampling(); XBT_PRIVATE void smpi_process_set_replaying(bool s); XBT_PRIVATE bool smpi_process_get_replaying(); -XBT_PRIVATE void smpi_deployment_register_process(const char* instance_id, int rank, int index, MPI_Comm** comm, xbt_bar_t*bar); +XBT_PRIVATE void smpi_deployment_register_process(const char* instance_id, int rank, int index, MPI_Comm** comm, + msg_bar_t* bar); XBT_PRIVATE void smpi_deployment_cleanup_instances(); XBT_PRIVATE void smpi_comm_copy_buffer_callback(smx_activity_t comm, void *buff, size_t buff_size); diff --git a/src/smpi/smpi_deployment.cpp b/src/smpi/smpi_deployment.cpp index d841df18c3..2747f0cb47 100644 --- a/src/smpi/smpi_deployment.cpp +++ b/src/smpi/smpi_deployment.cpp @@ -5,10 +5,10 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "private.h" -#include "xbt/sysdep.h" -#include "xbt/synchro_core.h" -#include "xbt/log.h" +#include "simgrid/msg.h" /* barrier */ #include "xbt/dict.h" +#include "xbt/log.h" +#include "xbt/sysdep.h" static xbt_dict_t smpi_instances = nullptr; extern int process_count; @@ -20,7 +20,7 @@ typedef struct s_smpi_mpi_instance{ int present_processes; int index; MPI_Comm comm_world; - xbt_bar_t finalization_barrier; + msg_bar_t finalization_barrier; } s_smpi_mpi_instance_t; /** \ingroup smpi_simulation @@ -42,7 +42,7 @@ void SMPI_app_instance_register(const char *name, xbt_main_func_t code, int num_ instance->present_processes = 0; instance->index = process_count; instance->comm_world = MPI_COMM_NULL; - instance->finalization_barrier=xbt_barrier_init(num_processes); + instance->finalization_barrier = MSG_barrier_init(num_processes); process_count+=num_processes; @@ -55,7 +55,8 @@ void SMPI_app_instance_register(const char *name, xbt_main_func_t code, int num_ } //get the index of the process in the process_data array -void smpi_deployment_register_process(const char* instance_id, int rank, int index,MPI_Comm** comm, xbt_bar_t* bar){ +void smpi_deployment_register_process(const char* instance_id, int rank, int index, MPI_Comm** comm, msg_bar_t* bar) +{ if(smpi_instances==nullptr){//no instance registered, we probably used smpirun. index_to_process_data[index]=index; @@ -88,7 +89,7 @@ void smpi_deployment_cleanup_instances(){ if(instance->comm_world!=MPI_COMM_NULL) while (smpi_group_unuse(smpi_comm_group(instance->comm_world)) > 0); xbt_free(instance->comm_world); - xbt_barrier_destroy(instance->finalization_barrier); + MSG_barrier_destroy(instance->finalization_barrier); } xbt_dict_free(&smpi_instances); } diff --git a/src/smpi/smpi_global.cpp b/src/smpi/smpi_global.cpp index 542997798f..72a89925a0 100644 --- a/src/smpi/smpi_global.cpp +++ b/src/smpi/smpi_global.cpp @@ -59,7 +59,7 @@ typedef struct s_smpi_process_data { int sampling; /* inside an SMPI_SAMPLE_ block? */ char* instance_id; bool replaying; /* is the process replaying a trace */ - xbt_bar_t finalization_barrier; + msg_bar_t finalization_barrier; int return_value; smpi_trace_call_location_t trace_call_loc; #if HAVE_PAPI @@ -118,7 +118,7 @@ void smpi_process_init(int *argc, char ***argv) } MPI_Comm* temp_comm_world; - xbt_bar_t temp_bar; + msg_bar_t temp_bar; smpi_deployment_register_process(instance_id, rank, index, &temp_comm_world, &temp_bar); smpi_process_data_t data = smpi_process_remote_data(index); data->comm_world = temp_comm_world; @@ -167,7 +167,7 @@ void smpi_process_finalize() int index = smpi_process_index(); // wait for all pending asynchronous comms to finish - xbt_barrier_wait(process_data[index_to_process_data[index]]->finalization_barrier); + MSG_barrier_wait(process_data[index_to_process_data[index]]->finalization_barrier); } /** @brief Check if a process is finalized */ @@ -595,7 +595,7 @@ void smpi_global_init() group = smpi_group_new(process_count); MPI_COMM_WORLD = smpi_comm_new(group, nullptr); MPI_Attr_put(MPI_COMM_WORLD, MPI_UNIVERSE_SIZE, reinterpret_cast(process_count)); - xbt_bar_t bar=xbt_barrier_init(process_count); + msg_bar_t bar = MSG_barrier_init(process_count); for (i = 0; i < process_count; i++) { smpi_group_set_mapping(group, i, i); @@ -607,16 +607,15 @@ void smpi_global_init() void smpi_global_destroy() { int count = smpi_process_count(); - int i; smpi_bench_destroy(); if (MPI_COMM_WORLD != MPI_COMM_UNINITIALIZED){ while (smpi_group_unuse(smpi_comm_group(MPI_COMM_WORLD)) > 0); - xbt_barrier_destroy(process_data[0]->finalization_barrier); + MSG_barrier_destroy(process_data[0]->finalization_barrier); }else{ smpi_deployment_cleanup_instances(); } - for (i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { if(process_data[i]->comm_self!=MPI_COMM_NULL){ smpi_comm_destroy(process_data[i]->comm_self); } diff --git a/src/smpi/smpi_rma.cpp b/src/smpi/smpi_rma.cpp index 21f3e02ea0..d610190252 100644 --- a/src/smpi/smpi_rma.cpp +++ b/src/smpi/smpi_rma.cpp @@ -11,7 +11,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_rma, smpi, "Logging specific to SMPI (RMA o #define RMA_TAG -1234 -xbt_bar_t creation_bar = nullptr; +msg_bar_t creation_bar = nullptr; typedef struct s_smpi_mpi_win{ void* base; @@ -21,7 +21,7 @@ typedef struct s_smpi_mpi_win{ MPI_Info info; int assert; std::vector *requests; - xbt_bar_t bar; + msg_bar_t bar; MPI_Win* connected_wins; char* name; int opened; @@ -53,12 +53,12 @@ MPI_Win smpi_mpi_win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info win->connected_wins[rank] = win; if(rank==0){ - win->bar=xbt_barrier_init(comm_size); + win->bar = MSG_barrier_init(comm_size); } mpi_coll_allgather_fun(&(win->connected_wins[rank]), sizeof(MPI_Win), MPI_BYTE, win->connected_wins, sizeof(MPI_Win), MPI_BYTE, comm); - mpi_coll_bcast_fun( &(win->bar), sizeof(xbt_bar_t), MPI_BYTE, 0, comm); + mpi_coll_bcast_fun(&(win->bar), sizeof(msg_bar_t), MPI_BYTE, 0, comm); mpi_coll_barrier_fun(comm); @@ -67,7 +67,7 @@ MPI_Win smpi_mpi_win_create( void *base, MPI_Aint size, int disp_unit, MPI_Info int smpi_mpi_win_free( MPI_Win* win){ //As per the standard, perform a barrier to ensure every async comm is finished - xbt_barrier_wait((*win)->bar); + MSG_barrier_wait((*win)->bar); delete (*win)->requests; xbt_free((*win)->connected_wins); if ((*win)->name != nullptr){ @@ -80,7 +80,7 @@ int smpi_mpi_win_free( MPI_Win* win){ mpi_coll_barrier_fun((*win)->comm); int rank=smpi_comm_rank((*win)->comm); if(rank == 0) - xbt_barrier_destroy((*win)->bar); + MSG_barrier_destroy((*win)->bar); xbt_free(*win); *win = MPI_WIN_NULL; return MPI_SUCCESS; @@ -111,7 +111,7 @@ int smpi_mpi_win_fence( int assert, MPI_Win win){ if(win->opened==0) win->opened=1; if(assert != MPI_MODE_NOPRECEDE){ - xbt_barrier_wait(win->bar); + MSG_barrier_wait(win->bar); std::vector *reqs = win->requests; int size = static_cast(reqs->size()); @@ -126,7 +126,7 @@ int smpi_mpi_win_fence( int assert, MPI_Win win){ } win->assert = assert; - xbt_barrier_wait(win->bar); + MSG_barrier_wait(win->bar); XBT_DEBUG("Leaving fence "); return MPI_SUCCESS; diff --git a/src/xbt/ex.cpp b/src/xbt/ex.cpp index d2061eba8c..0291f4ca90 100644 --- a/src/xbt/ex.cpp +++ b/src/xbt/ex.cpp @@ -54,7 +54,6 @@ #include "xbt/backtrace.h" #include "xbt/backtrace.hpp" #include "xbt/str.h" -#include "xbt/synchro_core.h" #include "src/xbt_modinter.h" /* backtrace initialization headers */ #include "src/xbt/ex_interface.h" diff --git a/src/xbt/xbt_log_layout_format.c b/src/xbt/xbt_log_layout_format.c index 594f001f50..b9168c9048 100644 --- a/src/xbt/xbt_log_layout_format.c +++ b/src/xbt/xbt_log_layout_format.c @@ -1,13 +1,11 @@ /* layout_simple - a dumb log layout */ -/* Copyright (c) 2007-2014. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2007-2016. The SimGrid Team. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ #include "src/internal_config.h" /* execinfo when available */ -#include "xbt/synchro_core.h" /* xbt_thread_self_name */ #include "xbt/sysdep.h" #include "xbt/strbuff.h" #include "src/xbt/log_private.h" diff --git a/src/xbt/xbt_os_synchro.c b/src/xbt/xbt_os_synchro.c index 22a4908db4..8727228800 100644 --- a/src/xbt/xbt_os_synchro.c +++ b/src/xbt/xbt_os_synchro.c @@ -10,7 +10,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "xbt/ex.h" -#include "xbt/synchro_core.h" +#include "xbt/synchro.h" #include "simgrid/simix.h" /* used implementation */ @@ -72,44 +72,3 @@ void xbt_cond_destroy(xbt_cond_t cond) { SIMIX_cond_unref((smx_cond_t) cond); } - -/***** barrier related functions *****/ -typedef struct s_xbt_bar_ { - xbt_mutex_t mutex; - xbt_cond_t cond; - unsigned int arrived_processes; - unsigned int expected_processes; -} s_xbt_bar_; - -xbt_bar_t xbt_barrier_init(unsigned int count) -{ - xbt_bar_t bar = xbt_new0(s_xbt_bar_, 1); - bar->expected_processes = count; - bar->arrived_processes = 0; - bar->mutex = xbt_mutex_init(); - bar->cond = xbt_cond_init(); - return bar; -} - -int xbt_barrier_wait(xbt_bar_t bar) -{ - int ret=0; - xbt_mutex_acquire(bar->mutex); - if (++bar->arrived_processes == bar->expected_processes) { - xbt_cond_broadcast(bar->cond); - xbt_mutex_release(bar->mutex); - ret=XBT_BARRIER_SERIAL_PROCESS; - bar->arrived_processes = 0; - } else { - xbt_cond_wait(bar->cond, bar->mutex); - xbt_mutex_release(bar->mutex); - } - return ret; -} - -void xbt_barrier_destroy(xbt_bar_t bar) -{ - xbt_mutex_destroy(bar->mutex); - xbt_cond_destroy(bar->cond); - xbt_free(bar); -} diff --git a/teshsuite/mc/mutex-handling/mutex-handling.c b/teshsuite/mc/mutex-handling/mutex-handling.c index e13bd2fdc2..b35cd9ea3d 100644 --- a/teshsuite/mc/mutex-handling/mutex-handling.c +++ b/teshsuite/mc/mutex-handling/mutex-handling.c @@ -19,9 +19,9 @@ * and the MC does not find the counter-example. */ -#include "simgrid/msg.h" #include "mc/mc.h" -#include +#include "simgrid/msg.h" +#include XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index f12548aff8..6e5357ec44 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -703,7 +703,7 @@ set(headers_to_install include/xbt/str.h include/xbt/strbuff.h include/xbt/swag.h - include/xbt/synchro_core.h + include/xbt/synchro.h include/xbt/sysdep.h include/xbt/system_error.hpp include/xbt/utility.hpp