include examples/cpp/network-ns3/s4u-network-ns3.cpp
include examples/cpp/network-wifi/s4u-network-wifi.cpp
include examples/cpp/network-wifi/s4u-network-wifi.tesh
+include examples/cpp/operation-io/s4u-operation-io.cpp
+include examples/cpp/operation-io/s4u-operation-io.tesh
include examples/cpp/operation-simple/s4u-operation-simple.cpp
include examples/cpp/operation-simple/s4u-operation-simple.tesh
include examples/cpp/operation-switch-host/s4u-operation-switch-host.cpp
mc-bugged1 mc-bugged1-liveness mc-bugged2 mc-bugged2-liveness mc-centralized-mutex mc-electric-fence mc-failing-assert
network-ns3 network-ns3-wifi network-wifi
io-async io-priority io-degradation io-file-system io-file-remote io-disk-raw io-dependent
- operation-simple operation-variable-load operation-switch-host
+ operation-io operation-simple operation-variable-load operation-switch-host
platform-comm-serialize platform-failures platform-profile platform-properties
plugin-host-load plugin-link-load plugin-prodcons
replay-comm replay-io
--setenv srcdir=${CMAKE_CURRENT_SOURCE_DIR}/${example}
--cd ${CMAKE_CURRENT_SOURCE_DIR}/${example}
${CMAKE_HOME_DIRECTORY}/examples/cpp/${example}/s4u-${example}-nodpor.tesh)
- endif()
+ endif()
set(tesh_files ${tesh_files} ${CMAKE_HOME_DIRECTORY}/examples/cpp/${example}/s4u-${example}-statequality.tesh)
set(tesh_files ${tesh_files} ${CMAKE_HOME_DIRECTORY}/examples/cpp/${example}/s4u-${example}-nodpor.tesh)
endforeach()
--- /dev/null
+/* Copyright (c) 2017-2023. 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. */
+
+/* This example demonstrate basic use of the operation plugin.
+ *
+ * We model the following graph:
+ *
+ * exec1 -> comm -> exec2
+ *
+ * exec1 and exec2 are execution operations.
+ * comm is a communication operation.
+ */
+
+#include <simgrid/plugins/file_system.h>
+#include "simgrid/plugins/operation.hpp"
+#include "simgrid/s4u.hpp"
+
+XBT_LOG_NEW_DEFAULT_CATEGORY(operation_simple, "Messages specific for this operation example");
+
+int main(int argc, char* argv[])
+{
+ simgrid::s4u::Engine e(&argc, argv);
+ sg_storage_file_system_init();
+ e.load_platform(argv[1]);
+ simgrid::plugins::Operation::init();
+
+ // Retrieve hosts
+ auto bob = e.host_by_name("bob");
+ auto carl = e.host_by_name("carl");
+
+ // Create operations
+ auto exec1 = simgrid::plugins::ExecOp::init("exec1", 1e9, bob);
+ auto exec2 = simgrid::plugins::ExecOp::init("exec2", 1e9, carl);
+ auto write = simgrid::plugins::IoOp::init("write", 1e7, bob->get_disks().front(), simgrid::s4u::Io::OpType::WRITE);
+ auto read = simgrid::plugins::IoOp::init("read", 1e7, carl->get_disks().front(), simgrid::s4u::Io::OpType::READ);
+
+ // Create the graph by defining dependencies between operations
+ exec1->add_successor(write);
+ write->add_successor(read);
+ read->add_successor(exec2);
+
+ // Add a function to be called when operations end for log purpose
+ simgrid::plugins::Operation::on_end_cb([](const simgrid::plugins::Operation* op) {
+ XBT_INFO("Operation %s finished (%d)", op->get_name().c_str(), op->get_count());
+ });
+
+ // Enqueue two executions for operation exec1
+ exec1->enqueue_execs(2);
+
+ // Start the simulation
+ e.run();
+ return 0;
+}
--- /dev/null
+#!/usr/bin/env tesh
+
+$ ${bindir:=.}/s4u-operation-io ${platfdir}/hosts_with_disks.xml
+> [1.000000] [operation_simple/INFO] Operation exec1 finished (1)
+> [1.250000] [operation_simple/INFO] Operation write finished (1)
+> [1.350000] [operation_simple/INFO] Operation read finished (1)
+> [2.000000] [operation_simple/INFO] Operation exec1 finished (2)
+> [2.250000] [operation_simple/INFO] Operation write finished (2)
+> [2.350000] [operation_simple/INFO] Operation exec2 finished (1)
+> [2.350000] [operation_simple/INFO] Operation read finished (2)
+> [3.350000] [operation_simple/INFO] Operation exec2 finished (2)
#define SIMGRID_PLUGINS_OPERATION_H_
#include <simgrid/s4u/Activity.hpp>
+#include <simgrid/s4u/Io.hpp>
#include <xbt/Extendable.hpp>
#include <atomic>
using CommOpPtr = boost::intrusive_ptr<CommOp>;
XBT_PUBLIC void intrusive_ptr_release(CommOp* c);
XBT_PUBLIC void intrusive_ptr_add_ref(CommOp* c);
+class IoOp;
+using IoOpPtr = boost::intrusive_ptr<IoOp>;
+XBT_PUBLIC void intrusive_ptr_release(IoOp* i);
+XBT_PUBLIC void intrusive_ptr_add_ref(IoOp* i);
struct ExtendedAttributeActivity {
static simgrid::xbt::Extension<simgrid::s4u::Activity, ExtendedAttributeActivity> EXTENSION_ID;
};
class Operation {
-private:
static bool inited_;
std::set<Operation*> successors_ = {};
std::map<Operation*, unsigned int> predecessors_ = {};
};
class ExecOp : public Operation {
-private:
s4u::Host* host_;
explicit ExecOp(const std::string& name);
};
class CommOp : public Operation {
-private:
s4u::Host* source_;
s4u::Host* destination_;
friend void inline intrusive_ptr_release(CommOp* c) { intrusive_ptr_release(static_cast<Operation*>(c)); }
friend void inline intrusive_ptr_add_ref(CommOp* c) { intrusive_ptr_add_ref(static_cast<Operation*>(c)); }
};
+
+class IoOp : public Operation {
+ s4u::Disk* disk_;
+ s4u::Io::OpType type_;
+ explicit IoOp(const std::string& name);
+ void execute() override;
+
+public:
+ static IoOpPtr init(const std::string& name);
+ static IoOpPtr init(const std::string& name, double bytes, s4u::Disk* disk, s4u::Io::OpType type);
+ IoOpPtr set_disk(s4u::Disk* disk);
+ IoOpPtr set_bytes(double bytes);
+ IoOpPtr set_op_type(s4u::Io::OpType type);
+
+ friend void inline intrusive_ptr_release(IoOp* i) { intrusive_ptr_release(static_cast<Operation*>(i)); }
+ friend void inline intrusive_ptr_add_ref(IoOp* i) { intrusive_ptr_add_ref(static_cast<Operation*>(i)); }
+};
} // namespace simgrid::plugins
#endif
#include <simgrid/plugins/operation.hpp>
#include <simgrid/s4u/Comm.hpp>
#include <simgrid/s4u/Exec.hpp>
+#include <simgrid/s4u/Io.hpp>
#include <simgrid/simix.hpp>
#include "src/simgrid/module.hpp"
simgrid::s4u::Comm::on_completion_cb([](simgrid::s4u::Comm const& comm) {
comm.extension<ExtendedAttributeActivity>()->operation_->complete();
});
+ simgrid::s4u::Io::on_completion_cb([](simgrid::s4u::Io const& io) {
+ io.extension<ExtendedAttributeActivity>()->operation_->complete();
+ });
}
/** @ingroup plugin_operation
return this;
}
+/**
+ * @brief Default constructor.
+ */
+IoOp::IoOp(const std::string& name) : Operation(name) {}
+
+/** @ingroup plugin_operation
+ * @brief Smart Constructor.
+ */
+IoOpPtr IoOp::init(const std::string& name)
+{
+ return IoOpPtr(new IoOp(name));
+}
+
+/** @ingroup plugin_operation
+ * @brief Smart Constructor.
+ */
+IoOpPtr IoOp::init(const std::string& name, double bytes, s4u::Disk* disk, s4u::Io::OpType type)
+{
+ return init(name)->set_bytes(bytes)->set_disk(disk)->set_op_type(type);
+}
+
+/** @ingroup plugin_operation
+ * @param disk The disk to set.
+ * @brief Set a new disk.
+ */
+IoOpPtr IoOp::set_disk(s4u::Disk* disk)
+{
+ kernel::actor::simcall_answered([this, disk] { disk_ = disk; });
+ return this;
+}
+
+/** @ingroup plugin_operation
+ * @param bytes The amount of bytes to set.
+ */
+IoOpPtr IoOp::set_bytes(double bytes)
+{
+ kernel::actor::simcall_answered([this, bytes] { amount_ = bytes; });
+ return this;
+}
+
+/** @ingroup plugin_operation
+ * @param bytes The amount of bytes to set.
+ */
+IoOpPtr IoOp::set_op_type(s4u::Io::OpType type)
+{
+ kernel::actor::simcall_answered([this, type] { type_ = type; });
+ return this;
+}
+
+void IoOp::execute()
+{
+ for (auto start_func : start_func_handlers_)
+ start_func(this);
+ Operation::on_start(this);
+ kernel::actor::simcall_answered([this] {
+ working_ = true;
+ queued_execs_ = std::max(queued_execs_ - 1, 0);
+ });
+ s4u::IoPtr io = s4u::Io::init();
+ io->set_name(name_);
+ io->set_size(amount_);
+ io->set_disk(disk_);
+ io->set_op_type(type_);
+ io->start();
+ io->extension_set(new ExtendedAttributeActivity());
+ io->extension<ExtendedAttributeActivity>()->operation_ = this;
+ kernel::actor::simcall_answered([this, io] { current_activity_ = io; });
+}
+
+
} // namespace simgrid::plugins
simgrid::xbt::Extension<simgrid::s4u::Activity, simgrid::plugins::ExtendedAttributeActivity>