X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/63c371bbca5afccc4708761d83af6fc2443ca553..4f4d5dd084f0b66318d3830b6165cfec26319639:/src/mc/remote/Client.cpp?ds=sidebyside diff --git a/src/mc/remote/Client.cpp b/src/mc/remote/Client.cpp index 2b25c63917..51b37afc62 100644 --- a/src/mc/remote/Client.cpp +++ b/src/mc/remote/Client.cpp @@ -1,5 +1,4 @@ -/* Copyright (c) 2015. The SimGrid Team. - * All rights reserved. */ +/* Copyright (c) 2015-2017. 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. */ @@ -24,8 +23,9 @@ #include "src/mc/remote/Client.hpp" #include "src/mc/remote/mc_protocol.h" +#include "src/smpi/private.hpp" + // We won't need those once the separation MCer/MCed is complete: -#include "src/mc/mc_ignore.h" #include "src/mc/mc_smx.h" XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_client, mc, "MC client logic"); @@ -39,7 +39,7 @@ Client* Client::initialize() { // We are not in MC mode: // TODO, handle this more gracefully. - if (!getenv(MC_ENV_SOCKET_FD)) + if (not std::getenv(MC_ENV_SOCKET_FD)) return nullptr; // Do not break if we are called multiple times: @@ -50,7 +50,7 @@ Client* Client::initialize() // Fetch socket from MC_ENV_SOCKET_FD: char* fd_env = std::getenv(MC_ENV_SOCKET_FD); - if (!fd_env) + if (not fd_env) xbt_die("No MC socket passed in the environment"); int fd = xbt_str_parse_int(fd_env, bprintf("Variable %s should contain a number but contains '%%s'", MC_ENV_SOCKET_FD)); @@ -89,13 +89,13 @@ void Client::handleMessages() XBT_DEBUG("Waiting messages from model-checker"); char message_buffer[MC_MESSAGE_LENGTH]; - ssize_t s; + ssize_t received_size; - if ((s = channel_.receive(&message_buffer, sizeof(message_buffer))) < 0) + if ((received_size = channel_.receive(&message_buffer, sizeof(message_buffer))) < 0) xbt_die("Could not receive commands from the model-checker"); s_mc_message_t message; - if ((size_t)s < sizeof(message)) + if ((size_t)received_size < sizeof(message)) xbt_die("Received message is too small"); memcpy(&message, message_buffer, sizeof(message)); switch (message.type) { @@ -103,22 +103,20 @@ void Client::handleMessages() case MC_MESSAGE_DEADLOCK_CHECK: { // Check deadlock: bool deadlock = false; - smx_actor_t actor; - if (xbt_swag_size(simix_global->process_list)) { + if (not simix_global->process_list.empty()) { deadlock = true; - xbt_swag_foreach(actor, simix_global->process_list) if (simgrid::mc::actor_is_enabled(actor)) - { - deadlock = false; - break; - } + for (auto kv : simix_global->process_list) + if (simgrid::mc::actor_is_enabled(kv.second)) { + deadlock = false; + break; + } } // Send result: s_mc_int_message_t answer; answer.type = MC_MESSAGE_DEADLOCK_CHECK_REPLY; answer.value = deadlock; - if (channel_.send(answer)) - xbt_die("Could not send response"); + xbt_assert(channel_.send(answer) == 0, "Could not send response"); } break; case MC_MESSAGE_CONTINUE: @@ -126,11 +124,11 @@ void Client::handleMessages() case MC_MESSAGE_SIMCALL_HANDLE: { s_mc_simcall_handle_message_t message; - if (s != sizeof(message)) + if (received_size != sizeof(message)) xbt_die("Unexpected size for SIMCALL_HANDLE"); memcpy(&message, message_buffer, sizeof(message)); smx_actor_t process = SIMIX_process_from_PID(message.pid); - if (!process) + if (not process) xbt_die("Invalid pid %lu", (unsigned long)message.pid); SIMIX_simcall_handle(&process->simcall, message.value); if (channel_.send(MC_MESSAGE_WAITING)) @@ -139,7 +137,7 @@ void Client::handleMessages() case MC_MESSAGE_RESTORE: { s_mc_restore_message_t message; - if (s != sizeof(message)) + if (received_size != sizeof(message)) xbt_die("Unexpected size for SIMCALL_HANDLE"); memcpy(&message, message_buffer, sizeof(message)); #if HAVE_SMPI @@ -153,12 +151,11 @@ void Client::handleMessages() } } -void Client::mainLoop(void) +void Client::mainLoop() { while (1) { simgrid::mc::wait_for_requests(); - if (channel_.send(MC_MESSAGE_WAITING)) - xbt_die("Could not send WAITING mesage to model-checker"); + xbt_assert(channel_.send(MC_MESSAGE_WAITING) == 0, "Could not send WAITING message to model-checker"); this->handleMessages(); } } @@ -208,7 +205,7 @@ void Client::unignoreHeap(void* address, std::size_t size) message.addr = (std::uintptr_t)address; message.size = size; if (channel_.send(message)) - xbt_die("Could not send IGNORE_HEAP mesasge to model-checker"); + xbt_die("Could not send IGNORE_HEAP message to model-checker"); } void Client::declareSymbol(const char* name, int* value) @@ -235,8 +232,8 @@ void Client::declareStack(void* stack, size_t size, smx_actor_t process, ucontex region.size = size; region.block = ((char*)stack - (char*)heap->heapbase) / BLOCKSIZE + 1; #if HAVE_SMPI - if (smpi_privatize_global_variables && process) - region.process_index = smpi_process_index_of_smx_process(process); + if (smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP && process) + region.process_index = process->pid - 1; else #endif region.process_index = -1; @@ -245,7 +242,7 @@ void Client::declareStack(void* stack, size_t size, smx_actor_t process, ucontex message.type = MC_MESSAGE_STACK_REGION; message.stack_region = region; if (channel_.send(message)) - xbt_die("Coule not send STACK_REGION to model-checker"); + xbt_die("Could not send STACK_REGION to model-checker"); } } }