From 334e868fd56cf359ef71557b7eba026687fbef73 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Fri, 6 May 2016 18:04:43 +0200 Subject: [PATCH] smx: synchro->suspend() and synchro->resume() as proper methods --- src/simix/Synchro.h | 3 ++ src/simix/SynchroComm.cpp | 22 ++++++++++++ src/simix/SynchroComm.hpp | 4 +++ src/simix/SynchroExec.cpp | 19 +++++++++++ src/simix/SynchroExec.hpp | 4 +++ src/simix/SynchroIo.cpp | 19 +++++++++++ src/simix/SynchroIo.hpp | 4 +++ src/simix/SynchroRaw.cpp | 16 +++++++++ src/simix/SynchroRaw.hpp | 4 +++ src/simix/SynchroSleep.cpp | 15 +++++++++ src/simix/SynchroSleep.hpp | 4 +++ src/simix/smx_host.cpp | 8 ++--- src/simix/smx_network.cpp | 14 ++------ src/simix/smx_process.cpp | 57 +++++--------------------------- tools/cmake/DefinePackages.cmake | 5 +++ 15 files changed, 131 insertions(+), 67 deletions(-) create mode 100644 src/simix/SynchroComm.cpp create mode 100644 src/simix/SynchroExec.cpp create mode 100644 src/simix/SynchroIo.cpp create mode 100644 src/simix/SynchroRaw.cpp create mode 100644 src/simix/SynchroSleep.cpp diff --git a/src/simix/Synchro.h b/src/simix/Synchro.h index b55a2b9a4f..9ed8f9f019 100644 --- a/src/simix/Synchro.h +++ b/src/simix/Synchro.h @@ -22,6 +22,9 @@ namespace simix { char *name; /* synchro name if any */ xbt_fifo_t simcalls; /* List of simcalls waiting for this synchro */ char *category = nullptr; /* For instrumentation */ + + virtual void suspend()=0; + virtual void resume()=0; }; }} // namespace simgrid::simix #else /* not C++ */ diff --git a/src/simix/SynchroComm.cpp b/src/simix/SynchroComm.cpp new file mode 100644 index 0000000000..27ac085cba --- /dev/null +++ b/src/simix/SynchroComm.cpp @@ -0,0 +1,22 @@ +/* Copyright (c) 2007-2016. The SimGrid Team. All rights reserved. */ + +/* 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/simix/SynchroComm.hpp" +#include "src/surf/surf_interface.hpp" + +void simgrid::simix::Comm::suspend() { + /* FIXME: shall we suspend also the timeout synchro? */ + if (surf_comm) + surf_comm->suspend(); + /* in the other case, the action will be suspended on creation, in SIMIX_comm_start() */ + +} + +void simgrid::simix::Comm::resume() { + /*FIXME: check what happen with the timeouts */ + if (surf_comm) + surf_comm->resume(); + /* in the other case, the synchro were not really suspended yet, see SIMIX_comm_suspend() and SIMIX_comm_start() */ +} diff --git a/src/simix/SynchroComm.hpp b/src/simix/SynchroComm.hpp index 03c71d70e8..58e0466c38 100644 --- a/src/simix/SynchroComm.hpp +++ b/src/simix/SynchroComm.hpp @@ -6,6 +6,7 @@ #ifndef _SIMIX_SYNCHRO_COMM_HPP #define _SIMIX_SYNCHRO_COMM_HPP +#include "surf/surf.h" #include "src/simix/Synchro.h" typedef enum { @@ -20,6 +21,9 @@ namespace simix { XBT_PUBLIC_CLASS Comm : public Synchro { public: + void suspend(); + void resume(); + e_smx_comm_type_t type; /* Type of the communication (SIMIX_COMM_SEND or SIMIX_COMM_RECEIVE) */ smx_mailbox_t mbox; /* Rendez-vous where the comm is queued */ diff --git a/src/simix/SynchroExec.cpp b/src/simix/SynchroExec.cpp new file mode 100644 index 0000000000..db79ea0cad --- /dev/null +++ b/src/simix/SynchroExec.cpp @@ -0,0 +1,19 @@ +/* Copyright (c) 2007-2016. The SimGrid Team. All rights reserved. */ + +/* 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/simix/SynchroExec.hpp" +#include "src/surf/surf_interface.hpp" + +void simgrid::simix::Exec::suspend() +{ + if (surf_exec) + surf_exec->suspend(); +} + +void simgrid::simix::Exec::resume() +{ + if (surf_exec) + surf_exec->resume(); +} diff --git a/src/simix/SynchroExec.hpp b/src/simix/SynchroExec.hpp index 27b62fdb41..c81b6b7b0f 100644 --- a/src/simix/SynchroExec.hpp +++ b/src/simix/SynchroExec.hpp @@ -6,6 +6,7 @@ #ifndef _SIMIX_SYNCHRO_EXEC_HPP #define _SIMIX_SYNCHRO_EXEC_HPP +#include "surf/surf.h" #include "src/simix/Synchro.h" namespace simgrid { @@ -13,6 +14,9 @@ namespace simix { XBT_PUBLIC_CLASS Exec : public Synchro { public: + void suspend(); + void resume(); + sg_host_t host; /* The host where the execution takes place */ surf_action_t surf_exec; /* The Surf execution action encapsulated */ }; diff --git a/src/simix/SynchroIo.cpp b/src/simix/SynchroIo.cpp new file mode 100644 index 0000000000..e27e5f573b --- /dev/null +++ b/src/simix/SynchroIo.cpp @@ -0,0 +1,19 @@ +/* Copyright (c) 2007-2016. The SimGrid Team. All rights reserved. */ + +/* 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/simix/SynchroIo.hpp" +#include "src/surf/surf_interface.hpp" + +void simgrid::simix::Io::suspend() +{ + if (surf_io) + surf_io->suspend(); +} + +void simgrid::simix::Io::resume() +{ + if (surf_io) + surf_io->resume(); +} diff --git a/src/simix/SynchroIo.hpp b/src/simix/SynchroIo.hpp index a3039b75ef..3d0aa2b2d3 100644 --- a/src/simix/SynchroIo.hpp +++ b/src/simix/SynchroIo.hpp @@ -6,6 +6,7 @@ #ifndef _SIMIX_SYNCHRO_IO_HPP #define _SIMIX_SYNCHRO_IO_HPP +#include "surf/surf.h" #include "src/simix/Synchro.h" namespace simgrid { @@ -13,6 +14,9 @@ namespace simix { XBT_PUBLIC_CLASS Io : public Synchro { public: + void suspend(); + void resume(); + sg_host_t host; surf_action_t surf_io; }; diff --git a/src/simix/SynchroRaw.cpp b/src/simix/SynchroRaw.cpp new file mode 100644 index 0000000000..e73fe3d27c --- /dev/null +++ b/src/simix/SynchroRaw.cpp @@ -0,0 +1,16 @@ +/* Copyright (c) 2007-2016. The SimGrid Team. All rights reserved. */ + +/* 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/simix/SynchroRaw.hpp" +#include "src/surf/surf_interface.hpp" + +void simgrid::simix::Raw::suspend() { + /* The suspension of raw synchros is delayed to when the process is rescheduled. */ +} + +void simgrid::simix::Raw::resume() { + /* I cannot resume raw synchros directly. This is delayed to when the process is rescheduled at + * the end of the synchro. */ +} diff --git a/src/simix/SynchroRaw.hpp b/src/simix/SynchroRaw.hpp index 3d8a28e473..c0a34442a7 100644 --- a/src/simix/SynchroRaw.hpp +++ b/src/simix/SynchroRaw.hpp @@ -6,6 +6,7 @@ #ifndef _SIMIX_SYNCHRO_RAW_HPP #define _SIMIX_SYNCHRO_RAW_HPP +#include "surf/surf.h" #include "src/simix/Synchro.h" namespace simgrid { @@ -14,6 +15,9 @@ namespace simix { /** Used to implement mutexes, semaphores and conditions */ XBT_PUBLIC_CLASS Raw : public Synchro { public: + void suspend(); + void resume(); + surf_action_t sleep; }; diff --git a/src/simix/SynchroSleep.cpp b/src/simix/SynchroSleep.cpp new file mode 100644 index 0000000000..23959509e3 --- /dev/null +++ b/src/simix/SynchroSleep.cpp @@ -0,0 +1,15 @@ +/* Copyright (c) 2007-2016. The SimGrid Team. All rights reserved. */ + +/* 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/simix/SynchroSleep.hpp" +#include "src/surf/surf_interface.hpp" + +void simgrid::simix::Sleep::suspend() { + surf_sleep->suspend(); +} + +void simgrid::simix::Sleep::resume() { + surf_sleep->resume(); +} diff --git a/src/simix/SynchroSleep.hpp b/src/simix/SynchroSleep.hpp index 8e4b9a156f..5a87136e40 100644 --- a/src/simix/SynchroSleep.hpp +++ b/src/simix/SynchroSleep.hpp @@ -6,6 +6,7 @@ #ifndef _SIMIX_SYNCHRO_SLEEP_HPP #define _SIMIX_SYNCHRO_SLEEP_HPP +#include "surf/surf.h" #include "src/simix/Synchro.h" namespace simgrid { @@ -13,6 +14,9 @@ namespace simix { XBT_PUBLIC_CLASS Sleep : public Synchro { public: + void suspend(); + void resume(); + sg_host_t host; /* The host that is sleeping */ surf_action_t surf_sleep; /* The Surf sleeping action encapsulated */ }; diff --git a/src/simix/smx_host.cpp b/src/simix/smx_host.cpp index 800a511cc1..2115a8090d 100644 --- a/src/simix/smx_host.cpp +++ b/src/simix/smx_host.cpp @@ -416,16 +416,12 @@ void simcall_HANDLER_execution_wait(smx_simcall_t simcall, smx_synchro_t synchro void SIMIX_execution_suspend(smx_synchro_t synchro) { - simgrid::simix::Exec *exec = static_cast(synchro); - if(exec->surf_exec) - exec->surf_exec->suspend(); + synchro->suspend(); // FIXME: USELESS } void SIMIX_execution_resume(smx_synchro_t synchro) { - simgrid::simix::Exec *exec = static_cast(synchro); - if(exec->surf_exec) - exec->surf_exec->resume(); + synchro->resume(); // FIXME: USELESS } void SIMIX_execution_finish(smx_synchro_t synchro) diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index 8d808d7136..03d3519271 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -854,22 +854,12 @@ void SIMIX_comm_cancel(smx_synchro_t synchro) void SIMIX_comm_suspend(smx_synchro_t synchro) { - simgrid::simix::Comm *comm = static_cast(synchro); - - /*FIXME: shall we suspend also the timeout synchro? */ - if (comm->surf_comm) - comm->surf_comm->suspend(); - /* in the other case, the action will be suspended on creation, in SIMIX_comm_start() */ + synchro->suspend(); // FIXME: USELESS } void SIMIX_comm_resume(smx_synchro_t synchro) { - simgrid::simix::Comm *comm = static_cast(synchro); - - /*FIXME: check what happen with the timeouts */ - if (comm->surf_comm) - comm->surf_comm->resume(); - /* in the other case, the synchro were not really suspended yet, see SIMIX_comm_suspend() and SIMIX_comm_start() */ + synchro->resume(); // FIXME: USELESS } diff --git a/src/simix/smx_process.cpp b/src/simix/smx_process.cpp index c20273ac17..ed6a6d0ebb 100644 --- a/src/simix/smx_process.cpp +++ b/src/simix/smx_process.cpp @@ -644,8 +644,6 @@ void simcall_HANDLER_process_suspend(smx_simcall_t simcall, smx_process_t proces smx_synchro_t SIMIX_process_suspend(smx_process_t process, smx_process_t issuer) { - xbt_assert((process != NULL), "Invalid parameters"); - if (process->suspended) { XBT_DEBUG("Process '%s' is already suspended", process->name); return NULL; @@ -653,32 +651,14 @@ smx_synchro_t SIMIX_process_suspend(smx_process_t process, smx_process_t issuer) process->suspended = 1; - /* If we are suspending another process, and it is waiting on a sync, suspend its synchronization. */ + /* If we are suspending another process that is waiting on a sync, suspend its synchronization. */ if (process != issuer) { - if (process->waiting_synchro) { - - simgrid::simix::Exec *exec = dynamic_cast(process->waiting_synchro); - if (exec != nullptr) { - SIMIX_execution_suspend(process->waiting_synchro); - } - - simgrid::simix::Comm *comm = dynamic_cast(process->waiting_synchro); - if (comm != nullptr) { - SIMIX_comm_suspend(process->waiting_synchro); - } - - simgrid::simix::Sleep *sleep = dynamic_cast(process->waiting_synchro); - if (sleep != nullptr) { - SIMIX_process_sleep_suspend(process->waiting_synchro); - } + if (process->waiting_synchro) + process->waiting_synchro->suspend(); + /* If the other process is not waiting, its suspension is delayed to when the process is rescheduled. */ - /* The suspension of raw synchros is delayed to when the process is rescheduled. */ - return NULL; - } else { - /* If the other process is not waiting, its suspension is delayed to when the process is rescheduled. */ - return NULL; - } + return NULL; } else { /* FIXME: computation size is zero. Is it okay that bound is zero ? */ return SIMIX_execution_start(process, "suspend", 0.0, 1.0, 0.0, 0); @@ -706,24 +686,7 @@ void SIMIX_process_resume(smx_process_t process, smx_process_t issuer) if (process != issuer) { if (process->waiting_synchro) { - simgrid::simix::Exec *exec = dynamic_cast(process->waiting_synchro); - if (exec != nullptr) { - SIMIX_execution_resume(process->waiting_synchro); - } - - simgrid::simix::Comm *comm = dynamic_cast(process->waiting_synchro); - if (comm != nullptr) { - SIMIX_comm_resume(process->waiting_synchro); - } - - simgrid::simix::Sleep *sleep = dynamic_cast(process->waiting_synchro); - if (sleep != nullptr) { - SIMIX_process_sleep_resume(process->waiting_synchro); - } - - /* I cannot resume raw synchros now. This is delayed to when the process is rescheduled at - * the end of the synchro. */ - + process->waiting_synchro->resume(); } } else XBT_WARN("Strange. Process %p is trying to resume himself.", issuer); @@ -951,16 +914,12 @@ void SIMIX_process_sleep_destroy(smx_synchro_t synchro) void SIMIX_process_sleep_suspend(smx_synchro_t synchro) { - simgrid::simix::Sleep *sleep = static_cast(synchro); - sleep->surf_sleep->suspend(); + synchro->suspend(); //FIXME: USELESS } void SIMIX_process_sleep_resume(smx_synchro_t synchro) { - XBT_DEBUG("Synchro state is %d on process_sleep_resume.", synchro->state); - simgrid::simix::Sleep *sleep = static_cast(synchro); - - sleep->surf_sleep->resume(); + synchro->resume(); //FIXME: USELESS } /** diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index d079dd865c..d805523e67 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -348,6 +348,11 @@ set(SIMIX_SRC src/simix/smx_vm.cpp src/simix/popping.cpp src/simix/Synchro.cpp + src/simix/SynchroComm.cpp + src/simix/SynchroExec.cpp + src/simix/SynchroSleep.cpp + src/simix/SynchroRaw.cpp + src/simix/SynchroIo.cpp ${SIMIX_GENERATED_SRC} ) -- 2.20.1