Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge pull request #213 from bcamus/master
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Mon, 7 Aug 2017 18:55:17 +0000 (20:55 +0200)
committerGitHub <noreply@github.com>
Mon, 7 Aug 2017 18:55:17 +0000 (20:55 +0200)
Fixing a bug in PMs energy consumptions when suspending and resuming VM

19 files changed:
examples/s4u/app-bittorrent/s4u_peer.cpp
examples/s4u/app-bittorrent/s4u_peer.hpp
examples/s4u/app-bittorrent/s4u_tracker.cpp
examples/s4u/app-bittorrent/s4u_tracker.hpp
examples/s4u/app-masterworker/s4u_app-masterworker.cpp
examples/s4u/app-masterworker/s4u_app-masterworker.tesh
src/bindings/java/jmsg_comm.cpp
src/bindings/java/jmsg_host.cpp
src/bindings/java/jmsg_storage.cpp
src/bindings/java/jmsg_vm.cpp
src/kernel/routing/FatTreeZone.cpp
src/msg/msg_vm.cpp
src/smpi/internals/smpi_bench.cpp
src/surf/sg_platf.cpp
src/surf/storage_n11.cpp
src/surf/xml/platf.hpp
src/surf/xml/surfxml_parseplatf.cpp
src/surf/xml/surfxml_sax_cb.cpp
teshsuite/s4u/comm-pt2pt/comm-pt2pt.cpp

index 77e04c4..04bb2e4 100644 (file)
@@ -126,10 +126,11 @@ void Peer::sendHandshakeToAllPeers()
   }
 }
 
-void Peer::sendHandshake(simgrid::s4u::MailboxPtr mailbox)
+void Peer::sendMessage(simgrid::s4u::MailboxPtr mailbox, e_message_type type, uint64_t size)
 {
-  XBT_DEBUG("Sending a HANDSHAKE to %s", mailbox->getName());
-  mailbox->put_init(new Message(MESSAGE_HANDSHAKE, id, mailbox_), MESSAGE_HANDSHAKE_SIZE)->detach();
+  const char* type_names[6] = {"HANDSHAKE", "CHOKE", "UNCHOKE", "INTERESTED", "NOTINTERESTED", "CANCEL"};
+  XBT_DEBUG("Sending %s to %s", type_names[type], mailbox->getName());
+  mailbox->put_init(new Message(type, id, bitfield_, mailbox_), size)->detach();
 }
 
 void Peer::sendBitfield(simgrid::s4u::MailboxPtr mailbox)
@@ -141,45 +142,13 @@ void Peer::sendBitfield(simgrid::s4u::MailboxPtr mailbox)
       ->detach();
 }
 
-void Peer::sendInterested(simgrid::s4u::MailboxPtr mailbox)
-{
-  XBT_DEBUG("Sending INTERESTED to %s", mailbox->getName());
-  mailbox->put_init(new Message(MESSAGE_INTERESTED, id, bitfield_, mailbox_), MESSAGE_INTERESTED_SIZE)->detach();
-}
-
-void Peer::sendNotInterested(simgrid::s4u::MailboxPtr mailbox)
-{
-  XBT_DEBUG("Sending NOTINTERESTED to %s", mailbox->getName());
-  mailbox->put_init(new Message(MESSAGE_NOTINTERESTED, id, bitfield_, mailbox_), MESSAGE_NOTINTERESTED_SIZE)->detach();
-}
-
-void Peer::sendChoked(simgrid::s4u::MailboxPtr mailbox)
-{
-  XBT_DEBUG("Sending CHOKE to %s", mailbox->getName());
-  mailbox->put_init(new Message(MESSAGE_CHOKE, id, mailbox_), MESSAGE_CHOKE_SIZE)->detach();
-}
-
-/** Send a "unchoked" message to a peer */
-void Peer::sendUnchoked(simgrid::s4u::MailboxPtr mailbox)
-{
-  XBT_DEBUG("Sending UNCHOKE to %s", mailbox->getName());
-  mailbox->put_init(new Message(MESSAGE_UNCHOKE, id, mailbox_), MESSAGE_UNCHOKE_SIZE)->detach();
-}
-
 void Peer::sendPiece(simgrid::s4u::MailboxPtr mailbox, unsigned int piece, int block_index, int block_length)
 {
-  xbt_assert(!hasNotPiece(piece), "Tried to send a unavailable piece.");
+  xbt_assert(not hasNotPiece(piece), "Tried to send a unavailable piece.");
   XBT_DEBUG("Sending the PIECE %u (%d,%d) to %s", piece, block_index, block_length, mailbox->getName());
   mailbox->put_init(new Message(MESSAGE_PIECE, id, mailbox_, piece, block_index, block_length), BLOCK_SIZE)->detach();
 }
 
-void Peer::sendRequest(simgrid::s4u::MailboxPtr mailbox, unsigned int piece, int block_index, int block_length)
-{
-  XBT_DEBUG("Sending a REQUEST to %s for piece %u (%d,%d)", mailbox->getName(), piece, block_index, block_length);
-  mailbox->put_init(new Message(MESSAGE_REQUEST, id, mailbox_, piece, block_index, block_length), MESSAGE_REQUEST_SIZE)
-      ->detach();
-}
-
 void Peer::sendHaveToAllPeers(unsigned int piece)
 {
   XBT_DEBUG("Sending HAVE message to all my peers");
@@ -196,7 +165,11 @@ void Peer::sendRequestTo(Connection* remote_peer, unsigned int piece)
   int block_index = getFirstMissingBlockFrom(piece);
   if (block_index != -1) {
     int block_length = MIN(BLOCKS_REQUESTED, PIECES_BLOCKS - block_index);
-    sendRequest(remote_peer->mailbox_, piece, block_index, block_length);
+    XBT_DEBUG("Sending a REQUEST to %s for piece %u (%d,%d)", remote_peer->mailbox_->getName(), piece, block_index,
+              block_length);
+    remote_peer->mailbox_
+        ->put_init(new Message(MESSAGE_REQUEST, id, mailbox_, piece, block_index, block_length), MESSAGE_REQUEST_SIZE)
+        ->detach();
   }
 }
 
@@ -219,6 +192,14 @@ bool Peer::isInterestedBy(Connection* remote_peer)
   return remote_peer->bitfield & (bitfield_ ^ ((1 << FILE_PIECES) - 1));
 }
 
+bool Peer::isInterestedByFree(Connection* remote_peer)
+{
+  for (unsigned int i = 0; i < FILE_PIECES; i++)
+    if (hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i))
+      return true;
+  return false;
+}
+
 void Peer::updatePiecesCountFromBitfield(unsigned int bitfield)
 {
   for (unsigned int i = 0; i < FILE_PIECES; i++)
@@ -308,12 +289,10 @@ void Peer::seed()
 
 void Peer::updateActivePeersSet(Connection* remote_peer)
 {
-  if (remote_peer->interested && not remote_peer->choked_upload) {
-    // add in the active peers set
+  if (remote_peer->interested && not remote_peer->choked_upload)
     active_peers.insert(remote_peer);
-  } else if (active_peers.find(remote_peer) != active_peers.end()) {
+  else
     active_peers.erase(remote_peer);
-  }
 }
 
 void Peer::handleMessage()
@@ -325,13 +304,16 @@ void Peer::handleMessage()
 
   auto known_peer         = connected_peers.find(message->peer_id);
   Connection* remote_peer = (known_peer == connected_peers.end()) ? nullptr : known_peer->second;
+  xbt_assert(remote_peer != nullptr || message->type == MESSAGE_HANDSHAKE,
+             "The impossible did happened: A not-in-our-list peer sent us a message.");
+
   switch (message->type) {
     case MESSAGE_HANDSHAKE:
       // Check if the peer is in our connection list.
       if (remote_peer == nullptr) {
         XBT_DEBUG("This peer %d was unknown, answer to its handshake", message->peer_id);
         connected_peers[message->peer_id] = new Connection(message->peer_id);
-        sendHandshake(message->return_mailbox);
+        sendMessage(message->return_mailbox, MESSAGE_HANDSHAKE, MESSAGE_HANDSHAKE_SIZE);
       }
       // Send our bitfield to the peer
       sendBitfield(message->return_mailbox);
@@ -341,33 +323,29 @@ void Peer::handleMessage()
       updatePiecesCountFromBitfield(message->bitfield);
       // Store the bitfield
       remote_peer->bitfield = message->bitfield;
-      xbt_assert(!remote_peer->am_interested, "Should not be interested at first");
+      xbt_assert(not remote_peer->am_interested, "Should not be interested at first");
       if (isInterestedBy(remote_peer)) {
         remote_peer->am_interested = true;
-        sendInterested(message->return_mailbox);
+        sendMessage(message->return_mailbox, MESSAGE_INTERESTED, MESSAGE_INTERESTED_SIZE);
       }
       break;
     case MESSAGE_INTERESTED:
-      xbt_assert((remote_peer != nullptr), "The impossible did happened: A not-in-our-list peer sent us a message.");
       // Update the interested state of the peer.
       remote_peer->interested = true;
       updateActivePeersSet(remote_peer);
       break;
     case MESSAGE_NOTINTERESTED:
-      xbt_assert((remote_peer != nullptr), "The impossible did happened: A not-in-our-list peer sent us a message.");
       remote_peer->interested = false;
       updateActivePeersSet(remote_peer);
       break;
     case MESSAGE_UNCHOKE:
-      xbt_assert((remote_peer != nullptr), "The impossible did happened: A not-in-our-list peer sent us a message.");
       xbt_assert(remote_peer->choked_download);
       remote_peer->choked_download = false;
       // Send requests to the peer, since it has unchoked us
-      // if (remote_peer->am_interested)
-      requestNewPieceTo(remote_peer);
+      if (remote_peer->am_interested)
+        requestNewPieceTo(remote_peer);
       break;
     case MESSAGE_CHOKE:
-      xbt_assert((remote_peer != nullptr), "The impossible did happened: A not-in-our-list peer sent us a message.");
       xbt_assert(not remote_peer->choked_download);
       remote_peer->choked_download = true;
       if (remote_peer->current_piece != -1)
@@ -382,7 +360,7 @@ void Peer::handleMessage()
       // If the piece is in our pieces, we tell the peer that we are interested.
       if (not remote_peer->am_interested && hasNotPiece(message->piece)) {
         remote_peer->am_interested = true;
-        sendInterested(message->return_mailbox);
+        sendMessage(message->return_mailbox, MESSAGE_INTERESTED, MESSAGE_INTERESTED_SIZE);
         if (not remote_peer->choked_download)
           requestNewPieceTo(remote_peer);
       }
@@ -406,7 +384,7 @@ void Peer::handleMessage()
                 message->block_index + message->block_length);
       xbt_assert(not remote_peer->choked_download);
       xbt_assert(remote_peer->am_interested || ENABLE_END_GAME_MODE,
-                 "Can't received a piece if I'm not interested wihtout end-game mode!"
+                 "Can't received a piece if I'm not interested without end-game mode!"
                  "piece (%d) bitfield (%u) remote bitfield (%u)",
                  message->piece, bitfield_, remote_peer->bitfield);
       xbt_assert(not remote_peer->choked_download, "Can't received a piece if I'm choked !");
@@ -533,9 +511,8 @@ int Peer::selectPieceToDownload(Connection* remote_peer)
     int current_index = 0;
     // compute the smallest number of copies of available pieces
     for (unsigned int i = 0; i < FILE_PIECES; i++) {
-      if (pieces_count[i] < min)
-        if (hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i))
-          min = pieces_count[i];
+      if (pieces_count[i] < min && hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i))
+        min = pieces_count[i];
     }
 
     xbt_assert(min != SHRT_MAX || not isInterestedByFree(remote_peer));
@@ -620,11 +597,11 @@ void Peer::updateChokedPeers()
 
   if (choked_peer != chosen_peer) {
     if (choked_peer != nullptr) {
-      xbt_assert((!choked_peer->choked_upload), "Tries to choked a choked peer");
+      xbt_assert(not choked_peer->choked_upload, "Tries to choked a choked peer");
       choked_peer->choked_upload = true;
       updateActivePeersSet(choked_peer);
       XBT_DEBUG("(%d) Sending a CHOKE to %d", id, choked_peer->id);
-      sendChoked(choked_peer->mailbox_);
+      sendMessage(choked_peer->mailbox_, MESSAGE_CHOKE, MESSAGE_CHOKE_SIZE);
     }
     if (chosen_peer != nullptr) {
       xbt_assert((chosen_peer->choked_upload), "Tries to unchoked an unchoked peer");
@@ -633,7 +610,7 @@ void Peer::updateChokedPeers()
       chosen_peer->last_unchoke = simgrid::s4u::Engine::getClock();
       XBT_DEBUG("(%d) Sending a UNCHOKE to %d", id, chosen_peer->id);
       updateActivePeersSet(chosen_peer);
-      sendUnchoked(chosen_peer->mailbox_);
+      sendMessage(chosen_peer->mailbox_, MESSAGE_UNCHOKE, MESSAGE_UNCHOKE_SIZE);
     }
   }
 }
@@ -654,7 +631,7 @@ void Peer::updateInterestedAfterReceive()
 
       if (not interested) { // no more piece to download from connection
         remote_peer->am_interested = false;
-        sendNotInterested(remote_peer->mailbox_);
+        sendMessage(remote_peer->mailbox_, MESSAGE_NOTINTERESTED, MESSAGE_NOTINTERESTED_SIZE);
       }
     }
   }
@@ -672,7 +649,7 @@ void Peer::updateBitfieldBlocks(int piece, int block_index, int block_length)
 bool Peer::hasCompletedPiece(unsigned int piece)
 {
   for (unsigned int i = 0; i < PIECES_BLOCKS; i++)
-    if (!(bitfield_blocks & 1ULL << (piece * PIECES_BLOCKS + i)))
+    if (not(bitfield_blocks & 1ULL << (piece * PIECES_BLOCKS + i)))
       return false;
   return true;
 }
@@ -685,14 +662,6 @@ int Peer::getFirstMissingBlockFrom(int piece)
   return -1;
 }
 
-bool Peer::isInterestedByFree(Connection* remote_peer)
-{
-  for (unsigned int i = 0; i < FILE_PIECES; i++)
-    if (hasNotPiece(i) && remote_peer->hasPiece(i) && isNotDownloadingPiece(i))
-      return true;
-  return false;
-}
-
 /** Returns a piece that is partially downloaded and stored by the remote peer if any -1 otherwise. */
 int Peer::partiallyDownloadedPiece(Connection* remote_peer)
 {
index 97630d9..c37eca9 100644 (file)
@@ -24,7 +24,7 @@ public:
   bool choked_upload   = true;  // Indicates if the peer is choked for the current peer
   bool choked_download = true;  // Indicates if the peer has choked the current peer
 
-  Connection(int id) : id(id), mailbox_(simgrid::s4u::Mailbox::byName(std::to_string(id))){};
+  explicit Connection(int id) : id(id), mailbox_(simgrid::s4u::Mailbox::byName(std::to_string(id))){};
   ~Connection() = default;
   void addSpeedValue(double speed) { peer_speed = peer_speed * 0.6 + speed * 0.4; }
   bool hasPiece(unsigned int piece) { return bitfield & 1U << piece; }
@@ -35,6 +35,7 @@ class Peer {
   double deadline;
   RngStream stream;
   simgrid::s4u::MailboxPtr mailbox_;
+  std::unordered_map<int, Connection*> connected_peers;
   std::set<Connection*> active_peers; // active peers list
 
   unsigned int bitfield_             = 0;       // list of pieces the peer has.
@@ -44,7 +45,6 @@ class Peer {
   double begin_receive_time = 0; // time when the receiving communication has begun, useful for calculating host speed.
   int round_                = 0; // current round for the chocking algorithm.
 
-  std::unordered_map<int, Connection*> connected_peers;
   simgrid::s4u::CommPtr comm_received = nullptr; // current comm
   Message* message                    = nullptr; // current message being received
 public:
@@ -75,15 +75,10 @@ public:
   void requestNewPieceTo(Connection* remote_peer);
 
   bool getPeersFromTracker();
-  void sendHandshake(simgrid::s4u::MailboxPtr mailbox);
+  void sendMessage(simgrid::s4u::MailboxPtr mailbox, e_message_type type, uint64_t size);
   void sendBitfield(simgrid::s4u::MailboxPtr mailbox);
   void sendPiece(simgrid::s4u::MailboxPtr mailbox, unsigned int piece, int block_index, int block_length);
-  void sendInterested(simgrid::s4u::MailboxPtr mailbox);
-  void sendChoked(simgrid::s4u::MailboxPtr mailbox);
-  void sendUnchoked(simgrid::s4u::MailboxPtr mailbox);
-  void sendNotInterested(simgrid::s4u::MailboxPtr mailbox);
   void sendHandshakeToAllPeers();
-  void sendRequest(simgrid::s4u::MailboxPtr mailbox, unsigned int piece, int block_index, int block_length);
   void sendHaveToAllPeers(unsigned int piece);
   void sendRequestTo(Connection* remote_peer, unsigned int piece);
 
index 5a30b19..7ddd5e0 100644 (file)
@@ -66,6 +66,5 @@ void Tracker::operator()()
       simgrid::s4u::this_actor::sleep_for(1);
     }
   }
-  // TODO See if some cleanup is needed
   XBT_INFO("Tracker is leaving");
 }
index 5ed077e..b342b7a 100644 (file)
@@ -42,6 +42,7 @@ class Tracker {
 
 public:
   explicit Tracker(std::vector<std::string> args);
+  Tracker(const Tracker&) = delete;
   void operator()();
 };
 
index 8e13fc5..04102b7 100644 (file)
@@ -40,17 +40,18 @@ public:
         XBT_INFO("Sending \"%s\" (of %ld) to mailbox \"%s\"", (std::string("Task_") + std::to_string(i)).c_str(),
                  number_of_tasks, mailbox->getName());
 
-      /* - Send the task to the @ref worker */
-      char* payload = bprintf("%f", comp_size);
-      mailbox->put(payload, comm_size);
+      /* - Send the computation amount to the @ref worker */
+      mailbox->put(static_cast<void*>(&comp_size), comm_size);
     }
 
     XBT_INFO("All tasks have been dispatched. Let's tell everybody the computation is over.");
     for (int i = 0; i < workers_count; i++) {
       /* - Eventually tell all the workers to stop by sending a "finalize" task */
       mailbox = simgrid::s4u::Mailbox::byName(std::string("worker-") + std::to_string(i % workers_count));
-      mailbox->put(xbt_strdup("finalize"), 0);
+      double finalize = -1;
+      mailbox->put(static_cast<void*>(&finalize), 0);
     }
+    simgrid::s4u::this_actor::sleep_for(.1); // Grace time to ensure everyone finishes.
   }
 };
 
@@ -70,19 +71,15 @@ public:
   void operator()()
   {
     while (1) { /* The worker waits in an infinite loop for tasks sent by the \ref master */
-      char* res = static_cast<char*>(mailbox->get());
-      xbt_assert(res != nullptr, "MSG_task_get failed");
-
-      if (strcmp(res, "finalize") == 0) { /* - Exit if 'finalize' is received */
-        xbt_free(res);
+      double* comp_size = static_cast<double*>(mailbox->get());
+      xbt_assert(comp_size != nullptr, "MSG_task_get failed");
+      if (*comp_size < 0) { /* - Exit if 'finalize' is received */
+        XBT_INFO("I'm done. See you!");
         break;
       }
       /*  - Otherwise, process the task */
-      double comp_size = std::stod(res);
-      xbt_free(res);
-      simgrid::s4u::this_actor::execute(comp_size);
+      simgrid::s4u::this_actor::execute(*comp_size);
     }
-    XBT_INFO("I'm done. See you!");
   }
 };
 
index f9b20df..ff2092d 100644 (file)
@@ -31,6 +31,6 @@ $ $SG_TEST_EXENV ${bindir:=.}/s4u_app-masterworker$EXEEXT ${srcdir:=.}/small_pla
 > [  4.057541] (worker@Jupiter) I'm done. See you!
 > [  4.083249] (worker@Fafard) I'm done. See you!
 > [  4.931805] (worker@Ginette) I'm done. See you!
-> [  5.094868] (maestro@) Simulation time 5.09487
 > [  5.094868] (worker@Bourassa) I'm done. See you!
+> [  5.194868] (maestro@) Simulation time 5.19487
 
index 8d52bfe..47f14d6 100644 (file)
@@ -10,6 +10,8 @@
 #include "jmsg.h"
 
 #include <simgrid/msg.h>
+#include <string>
+
 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java);
 
 SG_BEGIN_DECL()
@@ -79,7 +81,7 @@ JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Comm_test(JNIEnv *env, jobject j
   }
 
   if (not comm) {
-    jxbt_throw_null(env, bprintf("comm is null"));
+    jxbt_throw_null(env, "comm is null");
     return JNI_FALSE;
   }
 
@@ -99,7 +101,7 @@ JNIEXPORT jboolean JNICALL Java_org_simgrid_msg_Comm_test(JNIEnv *env, jobject j
 JNIEXPORT void JNICALL Java_org_simgrid_msg_Comm_waitCompletion(JNIEnv *env, jobject jcomm, jdouble timeout) {
   msg_comm_t comm = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind);
   if (not comm) {
-    jxbt_throw_null(env, bprintf("comm is null"));
+    jxbt_throw_null(env, "comm is null");
     return;
   }
 
@@ -130,7 +132,7 @@ static msg_comm_t* jarray_to_commArray(JNIEnv *env, jobjectArray jcomms, /* OUT
 
      comms[i] = (msg_comm_t) (uintptr_t) env->GetLongField(jcomm, jcomm_field_Comm_bind);
      if (not comms[i]) {
-       jxbt_throw_null(env, bprintf("comm at rank %d is null", i));
+       jxbt_throw_null(env, std::string("comm at rank ") + std::to_string(i) + " is null");
        return nullptr;
      }
 
index db414b9..28804e7 100644 (file)
@@ -56,7 +56,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Host_getByName(JNIEnv * env, jcla
 
   /* get the C string from the java string */
   if (jname == nullptr) {
-    jxbt_throw_null(env,bprintf("No host can have a null name"));
+    jxbt_throw_null(env, "No host can have a null name");
     return nullptr;
   }
   const char *name = env->GetStringUTFChars(jname, 0);
index 2d3a029..7b5003f 100644 (file)
@@ -56,7 +56,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_Storage_getByName(JNIEnv * env, j
 
   /* get the C string from the java string */
   if (jname == nullptr) {
-    jxbt_throw_null(env,bprintf("No host can have a null name"));
+    jxbt_throw_null(env, "No host can have a null name");
     return nullptr;
   }
   const char *name = env->GetStringUTFChars(jname, 0);
index d7e9ea1..b570d72 100644 (file)
@@ -174,7 +174,7 @@ JNIEXPORT jobject JNICALL Java_org_simgrid_msg_VM_getVMByName(JNIEnv* env, jclas
 
   /* get the C string from the java string */
   if (jname == nullptr) {
-    jxbt_throw_null(env, bprintf("No VM can have a null name"));
+    jxbt_throw_null(env, "No VM can have a null name");
     return nullptr;
   }
   const char* name = env->GetStringUTFChars(jname, 0);
index 49f8b8b..7eba193 100644 (file)
@@ -241,9 +241,9 @@ void FatTreeZone::generateSwitches()
     this->nodesByLevel_[0] *= this->lowerLevelNodesNumber_[i];
 
   if (this->nodesByLevel_[0] != this->nodes_.size()) {
-    surf_parse_error("The number of provided nodes does not fit with the wanted topology."
-                     " Please check your platform description (We need %u nodes, we got %zu)",
-                     this->nodesByLevel_[0], this->nodes_.size());
+    surf_parse_error(std::string("The number of provided nodes does not fit with the wanted topology.") +
+                     " Please check your platform description (We need " + std::to_string(this->nodesByLevel_[0]) +
+                     "nodes, we got " + std::to_string(this->nodes_.size()));
     return;
   }
 
index 99a3c5d..7cf836a 100644 (file)
@@ -755,15 +755,9 @@ void MSG_vm_migrate(msg_vm_t vm, msg_host_t dst_pm)
   char *pr_rx_name = get_mig_process_rx_name(vm, src_pm, dst_pm);
   char *pr_tx_name = get_mig_process_tx_name(vm, src_pm, dst_pm);
 
-  char** argv = xbt_new(char*, 2);
-  argv[0]     = pr_rx_name;
-  argv[1]     = nullptr;
-  MSG_process_create_with_arguments(pr_rx_name, migration_rx_fun, ms, dst_pm, 1, argv);
-
-  argv        = xbt_new(char*, 2);
-  argv[0]     = pr_tx_name;
-  argv[1]     = nullptr;
-  MSG_process_create_with_arguments(pr_tx_name, migration_tx_fun, ms, src_pm, 1, argv);
+  MSG_process_create(pr_rx_name, migration_rx_fun, ms, dst_pm);
+
+  MSG_process_create(pr_tx_name, migration_tx_fun, ms, src_pm);
 
   /* wait until the migration have finished or on error has occurred */
   XBT_DEBUG("wait for reception of the final ACK (i.e. migration has been correctly performed");
index cbe42c8..8e17376 100644 (file)
@@ -277,11 +277,12 @@ typedef struct {
 
 std::unordered_map<std::string, local_data_t*> samples; /* Allocated on first use */
 
-static char *sample_location(int global, const char *file, int line) {
+static std::string sample_location(int global, const char* file, int line)
+{
   if (global) {
-    return bprintf("%s:%d", file, line);
+    return std::string(file) + ":" + std::to_string(line);
   } else {
-    return bprintf("%s:%d:%d", file, line, smpi_process()->index());
+    return std::string(file) + ":" + std::to_string(line) + ":" + std::to_string(smpi_process()->index());
   }
 }
 
@@ -300,7 +301,7 @@ static int sample_enough_benchs(local_data_t *data) {
 
 void smpi_sample_1(int global, const char *file, int line, int iters, double threshold)
 {
-  char *loc = sample_location(global, file, line);
+  std::string loc = sample_location(global, file, line);
 
   smpi_bench_end();     /* Take time from previous, unrelated computation into account */
   smpi_process()->set_sampling(1);
@@ -319,35 +320,33 @@ void smpi_sample_1(int global, const char *file, int line, int iters, double thr
     data->benching = 1; // If we have no data, we need at least one
     data->mean = 0;
     samples[loc]    = data;
-    XBT_DEBUG("XXXXX First time ever on benched nest %s.",loc);
+    XBT_DEBUG("XXXXX First time ever on benched nest %s.", loc.c_str());
   } else {
     data = ld->second;
     if (data->iters != iters || data->threshold != threshold) {
       XBT_ERROR("Asked to bench block %s with different settings %d, %f is not %d, %f. "
                 "How did you manage to give two numbers at the same line??",
-                loc, data->iters, data->threshold, iters, threshold);
+                loc.c_str(), data->iters, data->threshold, iters, threshold);
       THROW_IMPOSSIBLE;
     }
 
     // if we already have some data, check whether sample_2 should get one more bench or whether it should emulate
     // the computation instead
     data->benching = (sample_enough_benchs(data) == 0);
-    XBT_DEBUG("XXXX Re-entering the benched nest %s. %s", loc,
+    XBT_DEBUG("XXXX Re-entering the benched nest %s. %s", loc.c_str(),
               (data->benching ? "more benching needed" : "we have enough data, skip computes"));
   }
-  xbt_free(loc);
 }
 
 int smpi_sample_2(int global, const char *file, int line)
 {
-  char *loc = sample_location(global, file, line);
+  std::string loc = sample_location(global, file, line);
   int res;
 
   xbt_assert(not samples.empty(),
              "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
   local_data_t* data = samples.at(loc);
-  XBT_DEBUG("sample2 %s",loc);
-  xbt_free(loc);
+  XBT_DEBUG("sample2 %s", loc.c_str());
 
   if (data->benching==1) {
     // we need to run a new bench
@@ -370,13 +369,12 @@ int smpi_sample_2(int global, const char *file, int line)
 
 void smpi_sample_3(int global, const char *file, int line)
 {
-  char *loc = sample_location(global, file, line);
+  std::string loc = sample_location(global, file, line);
 
   xbt_assert(not samples.empty(),
              "Y U NO use SMPI_SAMPLE_* macros? Stop messing directly with smpi_sample_* functions!");
   local_data_t* data = samples.at(loc);
-  XBT_DEBUG("sample3 %s",loc);
-  xbt_free(loc);
+  XBT_DEBUG("sample3 %s", loc.c_str());
 
   if (data->benching==0)
     THROW_IMPOSSIBLE;
index 6813d36..016f201 100644 (file)
@@ -685,7 +685,7 @@ void sg_platf_new_hostlink(sg_platf_host_link_cbarg_t hostlink)
   auto as_cluster = static_cast<simgrid::kernel::routing::ClusterZone*>(current_routing);
 
   if (as_cluster->privateLinks_.find(netpoint->id()) != as_cluster->privateLinks_.end())
-    surf_parse_error("Host_link for '%s' is already defined!",hostlink->id);
+    surf_parse_error(std::string("Host_link for '") + hostlink->id + "' is already defined!");
 
   XBT_DEBUG("Push Host_link for host '%s' to position %u", netpoint->cname(), netpoint->id());
   as_cluster->privateLinks_.insert({netpoint->id(), {linkUp, linkDown}});
index 5ae236e..f026497 100644 (file)
@@ -20,8 +20,8 @@ static void check_disk_attachment()
   for (auto s : *simgrid::surf::StorageImpl::storagesMap()) {
     simgrid::kernel::routing::NetPoint* host_elm = sg_netpoint_by_name_or_null(s.second->getHost().c_str());
     if (not host_elm)
-      surf_parse_error("Unable to attach storage %s: host %s does not exist.", s.second->cname(),
-                       s.second->getHost().c_str());
+      surf_parse_error(std::string("Unable to attach storage ") + s.second->cname() + ": host " + s.second->getHost() +
+                       " does not exist.");
     else
       s.second->piface_.attached_to_ = sg_host_by_name(s.second->getHost().c_str());
   }
index e7343a0..1a7dc48 100644 (file)
@@ -18,8 +18,8 @@ XBT_PUBLIC(void) sg_platf_exit();
 
 XBT_PUBLIC(void) surf_parse_open(const char *file);
 XBT_PUBLIC(void) surf_parse_close();
-XBT_PUBLIC(void) surf_parse_assert(bool cond, const char *fmt, ...) XBT_ATTRIB_PRINTF(2,3);
-XBT_PUBLIC(void) XBT_ATTRIB_NORETURN surf_parse_error(const char *msg,...) XBT_ATTRIB_PRINTF(1,2);
+XBT_PUBLIC(void) surf_parse_assert(bool cond, std::string msg);
+XBT_PUBLIC(void) XBT_ATTRIB_NORETURN surf_parse_error(std::string msg);
 XBT_PUBLIC(void) surf_parse_assert_netpoint(char* hostname, const char* pre, const char* post);
 XBT_PUBLIC(void) surf_parse_warn(const char *msg,...) XBT_ATTRIB_PRINTF(1,2);
 
index 21d9a55..fb6e7b5 100644 (file)
@@ -57,8 +57,8 @@ void sg_platf_trace_connect(sg_platf_trace_connect_cbarg_t trace_connect)
     trace_connect_list_link_lat.insert({trace_connect->trace, trace_connect->element});
     break;
   default:
-    surf_parse_error("Cannot connect trace %s to %s: kind of trace unknown", trace_connect->trace,
-                     trace_connect->element);
+    surf_parse_error(std::string("Cannot connect trace ") + trace_connect->trace + " to " + trace_connect->element +
+                     ": unknown kind of trace");
     break;
   }
 }
@@ -167,7 +167,7 @@ void parse_platform_file(const char *file)
     surf_parse_close();
 
     if (parse_status)
-      surf_parse_error("Parse error in %s", file);
+      surf_parse_error(std::string("Parse error in ") + file);
   }
 }
 
index 829e026..9b844b4 100644 (file)
@@ -30,30 +30,25 @@ std::vector<simgrid::surf::LinkImpl*> parsed_link_list; /* temporary store of cu
 /*
  * Helping functions
  */
-void surf_parse_assert(bool cond, const char *fmt, ...) {
+void surf_parse_assert(bool cond, std::string msg)
+{
   if (not cond) {
-    va_list va;
-    va_start(va,fmt);
     int lineno = surf_parse_lineno;
-    char *msg = bvprintf(fmt,va);
-    va_end(va);
     cleanup();
-    XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
+    XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg.c_str());
     surf_exit();
     xbt_die("Exiting now");
   }
 }
-void surf_parse_error(const char *fmt, ...) {
-  va_list va;
-  va_start(va,fmt);
+void surf_parse_error(std::string msg)
+{
   int lineno = surf_parse_lineno;
-  char *msg = bvprintf(fmt,va);
-  va_end(va);
   cleanup();
-  XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg);
+  XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg.c_str());
   surf_exit();
   xbt_die("Exiting now");
 }
+
 void surf_parse_assert_netpoint(char* hostname, const char* pre, const char* post)
 {
   if (sg_netpoint_by_name_or_null(hostname) != nullptr) // found
@@ -85,7 +80,7 @@ void surf_parse_assert_netpoint(char* hostname, const char* pre, const char* pos
       break;
     }
   }
-  surf_parse_error("%s", msg.c_str());
+  surf_parse_error(msg);
 }
 
 void surf_parse_warn(const char *fmt, ...) {
@@ -101,7 +96,7 @@ double surf_parse_get_double(const char *string) {
   double res;
   int ret = sscanf(string, "%lg", &res);
   if (ret != 1)
-    surf_parse_error("%s is not a double", string);
+    surf_parse_error(std::string(string) + " is not a double");
   return res;
 }
 
@@ -109,7 +104,7 @@ int surf_parse_get_int(const char *string) {
   int res;
   int ret = sscanf(string, "%d", &res);
   if (ret != 1)
-    surf_parse_error("%s is not an integer", string);
+    surf_parse_error(std::string(string) + " is not an integer");
   return res;
 }
 
@@ -135,7 +130,7 @@ static std::vector<int>* explodesRadical(const char* radicals)
         end = surf_parse_get_int((radical_ends.back()).c_str());
         break;
       default:
-        surf_parse_error("Malformed radical: %s", group.c_str());
+        surf_parse_error(std::string("Malformed radical: ") + group);
         break;
     }
     for (int i = start; i <= end; i++)
@@ -159,9 +154,9 @@ static double surf_parse_get_value_with_unit(const char *string, const struct un
   errno = 0;
   double res   = strtod(string, &ptr);
   if (errno == ERANGE)
-    surf_parse_error("value out of range: %s", string);
+    surf_parse_error(std::string("value out of range: ") + string);
   if (ptr == string)
-    surf_parse_error("cannot parse number: %s", string);
+    surf_parse_error(std::string("cannot parse number:") + string);
   if (ptr[0] == '\0') {
     if (res == 0)
       return res; // Ok, 0 can be unit-less
@@ -174,7 +169,7 @@ static double surf_parse_get_value_with_unit(const char *string, const struct un
   if (units[i].unit != nullptr)
     res *= units[i].scale;
   else
-    surf_parse_error("unknown unit: %s", ptr);
+    surf_parse_error(std::string("unknown unit: ") + ptr);
   return res;
 }
 
@@ -601,8 +596,7 @@ void ETag_surfxml_cluster(){
     cluster.topology= SURF_CLUSTER_DRAGONFLY ;
     break;
   default:
-    surf_parse_error("Invalid cluster topology for cluster %s",
-                     cluster.id);
+    surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id);
     break;
   }
   cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
@@ -619,7 +613,7 @@ void ETag_surfxml_cluster(){
     cluster.sharing_policy = SURF_LINK_FATPIPE;
     break;
   default:
-    surf_parse_error("Invalid cluster sharing policy for cluster %s", cluster.id);
+    surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id);
     break;
   }
   switch (AX_surfxml_cluster_bb___sharing___policy) {
@@ -630,7 +624,7 @@ void ETag_surfxml_cluster(){
     cluster.bb_sharing_policy = SURF_LINK_SHARED;
     break;
   default:
-    surf_parse_error("Invalid bb sharing policy in cluster %s", cluster.id);
+    surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id);
     break;
   }
 
@@ -706,7 +700,7 @@ void ETag_surfxml_link(){
      link.policy = SURF_LINK_FULLDUPLEX;
      break;
   default:
-    surf_parse_error("Invalid sharing policy in link %s", link.id.c_str());
+    surf_parse_error(std::string("Invalid sharing policy in link ") + link.id);
     break;
   }
 
@@ -731,7 +725,7 @@ void STag_surfxml_link___ctn(){
     link      = simgrid::surf::LinkImpl::byName(link_name);
     break;
   default:
-    surf_parse_error("Invalid direction for link %s", link_name);
+    surf_parse_error(std::string("Invalid direction for link ") + link_name);
     break;
   }
   xbt_free(link_name); // no-op if it's already nullptr
@@ -747,7 +741,7 @@ void STag_surfxml_link___ctn(){
     default:
       dirname = "";
   }
-  surf_parse_assert(link != nullptr, "No such link: '%s'%s", A_surfxml_link___ctn_id, dirname);
+  surf_parse_assert(link != nullptr, std::string("No such link: '") + A_surfxml_link___ctn_id + "'" + dirname);
   parsed_link_list.push_back(link);
 }
 
index 430bb73..68dfbc0 100644 (file)
@@ -50,7 +50,7 @@ static void sender(std::vector<std::string> args)
   XBT_INFO("Sender spec: %s", args[0].c_str());
   for (unsigned int test = 1; test <= args[0].size(); test++) {
     this_actor::sleep_until(test * 5 - 5);
-    char* mboxName                = bprintf("Test #%u", test);
+    const char* mboxName          = (std::string("Test #") + std::to_string(test)).c_str();
     simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mboxName);
 
     switch (args[0][test - 1]) {
@@ -97,7 +97,7 @@ static void receiver(std::vector<std::string> args)
   XBT_INFO("Receiver spec: %s", args[0].c_str());
   for (unsigned int test = 1; test <= args[0].size(); test++) {
     this_actor::sleep_until(test * 5 - 5);
-    char* mboxName                = bprintf("Test #%u", test);
+    const char* mboxName          = (std::string("Test #") + std::to_string(test)).c_str();
     simgrid::s4u::MailboxPtr mbox = simgrid::s4u::Mailbox::byName(mboxName);
     void* received                = nullptr;
 
@@ -148,8 +148,6 @@ static void receiver(std::vector<std::string> args)
     }
 
     xbt_assert(strcmp(static_cast<char*>(received), mboxName) == 0);
-    xbt_free(received);
-    xbt_free(mboxName);
     XBT_INFO("Test %u OK", test);
   }
   simgrid::s4u::this_actor::sleep_for(0.5);