public static void main(String[] args) {
Msg.init(args);
+ Msg.fileSystemInit();
if(args.length < 1) {
Msg.info("Usage : IO platform_file ");
Msg.info("example : IO ../platforms/storage/storage.xml ");
public static void main(String[] args) {
Msg.init(args);
+ Msg.fileSystemInit();
if(args.length < 1) {
Msg.info("Usage : Storage platform_file ");
Msg.info("example : Storage ../platforms/storage/storage.xml ");
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "simgrid/msg.h"
+#include "simgrid/plugins/file_system.h"
XBT_LOG_NEW_DEFAULT_CATEGORY(io_file, "Messages specific for this io example");
int main(int argc, char **argv)
{
MSG_init(&argc, argv);
+ MSG_storage_file_system_init();
+
MSG_create_environment(argv[1]);
xbt_dynar_t hosts = MSG_hosts_as_dynar();
MSG_function_register("host", host);
$ ${bindir:=.}/io-file ${srcdir:=.}/storage/storage.xml "--log=root.fmt:[%10.6r]%e(%i:%P@%h)%e%m%n"
> [ 0.000000] (0:maestro@) Number of host '4'
> [ 0.000000] (1:host@alice) Open file 'c:\Windows\setupact.log'
+> [ 0.000000] (1:host@alice) Capacity of the storage element 'c:\Windows\setupact.log' is stored on: 2391537133 / 536870912000
> [ 0.000000] (2:host@bob) Open file '/home/doc/simgrid/examples/platforms/nancy.xml'
+> [ 0.000000] (2:host@bob) Capacity of the storage element '/home/doc/simgrid/examples/platforms/nancy.xml' is stored on: 36933331 / 536870912000
> [ 0.000000] (3:host@carl) Open file '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml'
+> [ 0.000000] (3:host@carl) Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml' is stored on: 36933331 / 536870912000
> [ 0.000000] (4:host@denise) File Descriptor information:
> Full path: '/home/doc/simgrid/examples/platforms/g5k.xml'
> Size: 17028
> Storage Type: 'single_SSD'
> File Descriptor Id: 0
> [ 0.000000] (4:host@denise) Open file '/home/doc/simgrid/examples/platforms/g5k.xml'
-> [ 0.000000] (1:host@alice) Capacity of the storage element 'c:\Windows\setupact.log' is stored on: 2391537133 / 536870912000
-> [ 0.000000] (2:host@bob) Capacity of the storage element '/home/doc/simgrid/examples/platforms/nancy.xml' is stored on: 36933331 / 536870912000
-> [ 0.000000] (3:host@carl) Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k_cabinets.xml' is stored on: 36933331 / 536870912000
> [ 0.000000] (4:host@denise) Capacity of the storage element '/home/doc/simgrid/examples/platforms/g5k.xml' is stored on: 13221994 / 536870912000
> [ 0.000040] (2:host@bob) Have read 4028 from '/home/doc/simgrid/examples/platforms/nancy.xml'
> [ 0.000085] (4:host@denise) Have read 17028 from '/home/doc/simgrid/examples/platforms/g5k.xml'
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "simgrid/msg.h"
+#include "simgrid/plugins/file_system.h"
#define INMEGA (1024*1024)
msg_storage_t st;
MSG_init(&argc, argv);
+ MSG_storage_file_system_init();
+
MSG_create_environment(argv[1]);
MSG_function_register("host", host);
MSG_launch_application(argv[2]);
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "simgrid/msg.h"
+#include "simgrid/plugins/file_system.h"
XBT_LOG_NEW_DEFAULT_CATEGORY(storage,"Messages specific for this simulation");
int main(int argc, char *argv[])
{
MSG_init(&argc, argv);
+ MSG_storage_file_system_init();
+
MSG_create_environment(argv[1]);
MSG_function_register("host", host);
xbt_dynar_t hosts = MSG_hosts_as_dynar();
int main(int argc, char* argv[])
{
simgrid::s4u::Engine e(&argc, argv);
+ sg_storage_file_system_init();
xbt_assert(argc > 3, "Usage: %s platform_file deployment_file [action_files]\n"
"\texample: %s platform.xml deployment.xml actions # if all actions are in the same file\n"
int main(int argc, char **argv)
{
simgrid::s4u::Engine e(&argc, argv);
+ sg_storage_file_system_init();
e.loadPlatform("../../platforms/storage/storage.xml");
simgrid::s4u::Actor::createActor("host", simgrid::s4u::Host::by_name("denise"), MyHost());
e.run();
--- /dev/null
+/* Copyright (c) 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. */
+
+#ifndef SIMGRID_PLUGINS_FILE_SYSTEM_H_
+#define SIMGRID_PLUGINS_FILE_SYSTEM_H_
+
+#include <simgrid/forward.h>
+#include <xbt/base.h>
+
+SG_BEGIN_DECL()
+
+XBT_PUBLIC(void) sg_storage_file_system_init();
+
+#define MSG_storage_file_system_init() sg_storage_file_system_init()
+
+SG_END_DECL()
+
+#endif
#ifndef SIMGRID_S4U_FILE_HPP
#define SIMGRID_S4U_FILE_HPP
+#include "simgrid/plugins/file_system.h"
+#include <xbt/Extendable.hpp>
#include <xbt/base.h>
#include <simgrid/simix.h>
sg_size_t current_position_ = SEEK_SET;
void* userdata_ = nullptr;
};
+
+class FileSystemStorageExt {
+public:
+ static simgrid::xbt::Extension<simgrid::s4u::Storage, FileSystemStorageExt> EXTENSION_ID;
+ explicit FileSystemStorageExt(simgrid::s4u::Storage* ptr);
+ ~FileSystemStorageExt();
+ std::map<std::string, sg_size_t>* parseContent(std::string filename);
+ std::map<std::string, sg_size_t>* getContent() { return content_; }
+ sg_size_t getUsedSize() { return usedSize_; }
+ void decrUsedSize(sg_size_t size) { usedSize_ -= size; }
+ void incrUsedSize(sg_size_t size) { usedSize_ += size; }
+private:
+ std::map<std::string, sg_size_t>* content_;
+ sg_size_t usedSize_ = 0;
+};
}
} // namespace simgrid::s4u
#ifndef INCLUDE_SIMGRID_S4U_STORAGE_HPP_
#define INCLUDE_SIMGRID_S4U_STORAGE_HPP_
+#include "xbt/Extendable.hpp"
#include <map>
#include <simgrid/s4u/forward.hpp>
#include <simgrid/simix.h>
#include <xbt/base.h>
namespace simgrid {
+namespace xbt {
+extern template class XBT_PUBLIC() Extendable<simgrid::s4u::Storage>;
+}
namespace s4u {
XBT_ATTRIB_PUBLIC std::map<std::string, Storage*>* allStorages();
-XBT_PUBLIC_CLASS Storage
+XBT_PUBLIC_CLASS Storage : public simgrid::xbt::Extendable<Storage>
{
friend s4u::Engine;
friend simgrid::surf::StorageImpl;
sg_size_t getSizeFree();
sg_size_t getSizeUsed();
void decrUsedSize(sg_size_t size);
+ void incrUsedSize(sg_size_t size);
std::map<std::string, std::string>* getProperties();
const char* getProperty(std::string key);
#include "simgrid/msg.h"
#include "simgrid/plugins/energy.h"
+#include "simgrid/plugins/file_system.h"
#include "simgrid/simix.h"
#include "simgrid/s4u/Host.hpp"
JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_energyInit() {
sg_host_energy_plugin_init();
}
+
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_fileSystemInit()
+{
+ sg_storage_file_system_init();
+}
} // extern "C"
/** Run a Java org.simgrid.msg.Process
JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_init(JNIEnv* env, jclass cls, jobjectArray jargs);
JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_energyInit();
+JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_fileSystemInit();
JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_debug(JNIEnv* env, jclass cls, jstring jargs);
JNIEXPORT void JNICALL Java_org_simgrid_msg_Msg_verb(JNIEnv* env, jclass cls, jstring jargs);
/** Tell the kernel that you want to use the energy plugin */
public static final native void energyInit();
+ public static final native void fileSystemInit();
/** Run the MSG simulation.
*
#include "simgrid/simix.hpp"
#include "src/surf/HostImpl.hpp"
+#include <algorithm>
+#include <boost/algorithm/string.hpp>
+#include <boost/algorithm/string/join.hpp>
+#include <boost/algorithm/string/split.hpp>
+#include <fstream>
+
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_file,"S4U files");
namespace simgrid {
namespace s4u {
+simgrid::xbt::Extension<s4u::Storage, FileSystemStorageExt> FileSystemStorageExt::EXTENSION_ID;
File::File(std::string fullpath, void* userdata) : File(fullpath, Host::current(), userdata){};
localStorage->decrUsedSize(size_ - current_position_);
sg_size_t write_size = localStorage->write(size);
+ localStorage->incrUsedSize(write_size);
+
current_position_ += write_size;
size_ = current_position_;
}
}
-}} // namespace simgrid::s4u
+FileSystemStorageExt::FileSystemStorageExt(simgrid::s4u::Storage* ptr)
+{
+ content_ = parseContent(ptr->getImpl()->content_name);
+}
+
+FileSystemStorageExt::~FileSystemStorageExt()
+{
+ delete content_;
+}
+
+std::map<std::string, sg_size_t>* FileSystemStorageExt::parseContent(std::string filename)
+{
+ if (filename.empty())
+ return nullptr;
+
+ std::map<std::string, sg_size_t>* parse_content = new std::map<std::string, sg_size_t>();
+
+ std::ifstream* fs = surf_ifsopen(filename);
+
+ std::string line;
+ std::vector<std::string> tokens;
+ do {
+ std::getline(*fs, line);
+ boost::trim(line);
+ if (line.length() > 0) {
+ boost::split(tokens, line, boost::is_any_of(" \t"), boost::token_compress_on);
+ xbt_assert(tokens.size() == 2, "Parse error in %s: %s", filename.c_str(), line.c_str());
+ sg_size_t size = std::stoull(tokens.at(1));
+
+ usedSize_ += size;
+ parse_content->insert({tokens.front(), size});
+ }
+ } while (not fs->eof());
+ delete fs;
+ return parse_content;
+}
+}
+}
+
+using simgrid::s4u::FileSystemStorageExt;
+
+static void onStorageCreation(simgrid::s4u::Storage& st)
+{
+ st.extension_set(new FileSystemStorageExt(&st));
+}
+
+static void onStorageDestruction(simgrid::s4u::Storage& st)
+{
+ XBT_INFO("BLIH");
+}
+
+/* **************************** Public interface *************************** */
+SG_BEGIN_DECL()
+
+void sg_storage_file_system_init()
+{
+
+ if (FileSystemStorageExt::EXTENSION_ID.valid())
+ return;
+
+ FileSystemStorageExt::EXTENSION_ID = simgrid::s4u::Storage::extension_create<FileSystemStorageExt>();
+
+ simgrid::s4u::Storage::onCreation.connect(&onStorageCreation);
+ simgrid::s4u::Storage::onDestruction.connect(&onStorageDestruction);
+}
+
+SG_END_DECL()
/* 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 "simgrid/s4u/File.hpp"
#include "simgrid/s4u/Host.hpp"
#include "simgrid/s4u/Storage.hpp"
#include "simgrid/simix.hpp"
#include <unordered_map>
namespace simgrid {
+namespace xbt {
+template class Extendable<simgrid::s4u::Storage>;
+}
+
namespace s4u {
std::map<std::string, Storage*>* allStorages()
sg_size_t Storage::getSizeFree()
{
- return simgrid::simix::kernelImmediate([this] { return pimpl_->getFreeSize(); });
+ FileSystemStorageExt* file_system = extension<FileSystemStorageExt>();
+
+ return pimpl_->getSize() - file_system->getUsedSize();
}
sg_size_t Storage::getSizeUsed()
{
- return simgrid::simix::kernelImmediate([this] { return pimpl_->getUsedSize(); });
+ FileSystemStorageExt* file_system = extension<FileSystemStorageExt>();
+ return file_system->getUsedSize();
}
void Storage::decrUsedSize(sg_size_t size)
{
- simgrid::simix::kernelImmediate([this, size] { pimpl_->usedSize_ -= size; });
+ FileSystemStorageExt* file_system = extension<FileSystemStorageExt>();
+ file_system->decrUsedSize(size);
+}
+
+void Storage::incrUsedSize(sg_size_t size)
+{
+ FileSystemStorageExt* file_system = extension<FileSystemStorageExt>();
+ file_system->incrUsedSize(size);
}
sg_size_t Storage::getSize()
std::map<std::string, sg_size_t>* Storage::getContent()
{
- return simgrid::simix::kernelImmediate([this] { return pimpl_->getContent(); });
+ FileSystemStorageExt* file_system = extension<FileSystemStorageExt>();
+ return file_system->getContent();
}
sg_size_t Storage::read(sg_size_t size)
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "StorageImpl.hpp"
-
#include "surf_private.hpp"
-#include <algorithm>
-#include <boost/algorithm/string.hpp>
-#include <boost/algorithm/string/join.hpp>
-#include <boost/algorithm/string/split.hpp>
-#include <fstream>
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_storage, surf, "Logging specific to the SURF storage module");
: Resource(model, name.c_str(), lmm_constraint_new(maxminSystem, this, std::max(bread, bwrite)))
, piface_(this)
, typeId_(type_id)
+ , content_name(content_name)
, size_(size)
, attach_(attach)
{
- content_ = parseContent(content_name);
StorageImpl::turnOn();
XBT_DEBUG("Create resource with Bread '%f' Bwrite '%f' and Size '%llu'", bread, bwrite, size);
constraintRead_ = lmm_constraint_new(maxminSystem, this, bread);
StorageImpl::~StorageImpl()
{
storageDestructedCallbacks(this);
- if (content_ != nullptr)
- delete content_;
}
-std::map<std::string, sg_size_t>* StorageImpl::parseContent(std::string filename)
-{
- usedSize_ = 0;
- if (filename.empty())
- return nullptr;
-
- std::map<std::string, sg_size_t>* parse_content = new std::map<std::string, sg_size_t>();
-
- std::ifstream* fs = surf_ifsopen(filename);
-
- std::string line;
- std::vector<std::string> tokens;
- do {
- std::getline(*fs, line);
- boost::trim(line);
- if (line.length() > 0) {
- boost::split(tokens, line, boost::is_any_of(" \t"), boost::token_compress_on);
- xbt_assert(tokens.size() == 2, "Parse error in %s: %s", filename.c_str(), line.c_str());
- sg_size_t size = std::stoull(tokens.at(1));
-
- usedSize_ += size;
- parse_content->insert({tokens.front(), size});
- }
- } while (not fs->eof());
- delete fs;
- return parse_content;
-}
bool StorageImpl::isUsed()
{
}
}
-std::map<std::string, sg_size_t>* StorageImpl::getContent()
-{
- /* For the moment this action has no cost, but in the future we could take in account access latency of the disk */
- return content_;
-}
-
-sg_size_t StorageImpl::getFreeSize()
-{
- return size_ - usedSize_;
-}
-
-sg_size_t StorageImpl::getUsedSize()
-{
- return usedSize_;
-}
-
/**********
* Action *
**********/
* @return The StorageAction corresponding to the writing
*/
virtual StorageAction* write(sg_size_t size) = 0;
-
- /**
- * @brief Get the content of the current Storage
- *
- * @return A map with path as keys and size in bytes as values
- */
- virtual std::map<std::string, sg_size_t>* getContent();
-
- /**
- * @brief Get the available size in bytes of the current Storage
- *
- * @return The available size in bytes of the current Storage
- */
- virtual sg_size_t getFreeSize();
-
- /**
- * @brief Get the used size in bytes of the current Storage
- *
- * @return The used size in bytes of the current Storage
- */
- virtual sg_size_t getUsedSize();
virtual sg_size_t getSize() { return size_; }
virtual std::string getHost() { return attach_; }
- std::map<std::string, sg_size_t>* parseContent(std::string filename);
static std::unordered_map<std::string, StorageImpl*>* storagesMap() { return StorageImpl::storages; }
lmm_constraint_t constraintWrite_; /* Constraint for maximum write bandwidth*/
std::string typeId_;
sg_size_t usedSize_ = 0;
+ std::string content_name;
private:
sg_size_t size_;
static std::unordered_map<std::string, StorageImpl*>* storages;
- std::map<std::string, sg_size_t>* content_;
// Name of the host to which this storage is attached. Only used at platform parsing time, then the interface stores
// the Host directly.
std::string attach_;
for (auto it = std::begin(*getRunningActionSet()); it != std::end(*getRunningActionSet());) {
StorageAction& action = static_cast<StorageAction&>(*it);
++it; // increment iterator here since the following calls to action.finish() may invalidate it
- double current_progress = lrint(lmm_variable_getvalue(action.getVariable()) * delta);
- action.updateRemains(current_progress);
- if (action.type_ == WRITE) {
- action.storage_->usedSize_ += current_progress;
- }
+ action.updateRemains(lrint(lmm_variable_getvalue(action.getVariable()) * delta));
if (action.getMaxDuration() > NO_MAX_DURATION)
action.updateMaxDuration(delta);
- if (action.getRemainsNoUpdate() > 0 && lmm_get_variable_weight(action.getVariable()) > 0 &&
- action.storage_->usedSize_ == action.storage_->getSize()) {
- action.finish(Action::State::failed);
- } else if (((action.getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action.getVariable()) > 0)) ||
- ((action.getMaxDuration() > NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) {
+ if (((action.getRemainsNoUpdate() <= 0) && (lmm_get_variable_weight(action.getVariable()) > 0)) ||
+ ((action.getMaxDuration() > NO_MAX_DURATION) && (action.getMaxDuration() <= 0))) {
action.finish(Action::State::done);
}
}
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "simgrid/msg.h"
+#include "simgrid/plugins/file_system.h"
#include <xbt/replay.hpp>
XBT_LOG_NEW_DEFAULT_CATEGORY(storage_actions, "Messages specific for this example");
int main(int argc, char* argv[])
{
MSG_init(&argc, argv);
+ MSG_storage_file_system_init();
/* Explicit initialization of the action module is required */
MSG_action_init();
* under the terms of the license (GNU LGPL) which comes with this package. */
#include "simgrid/s4u.hpp"
-#include <unistd.h>
-
-#define FILENAME1 "/home/doc/simgrid/examples/platforms/g5k.xml"
XBT_LOG_NEW_DEFAULT_CATEGORY(s4u_test, "Messages specific for this s4u test");
static void host()
{
- char name[2048];
+ simgrid::s4u::Storage* storage = simgrid::s4u::Storage::byName("Disk1");
int id = simgrid::s4u::this_actor::getPid();
- snprintf(name, 2048, "%s%i", FILENAME1, id);
- simgrid::s4u::File* file = new simgrid::s4u::File(name, NULL);
XBT_INFO("process %d is writing!", id);
- file->write(3000000);
+ storage->write(3000000);
XBT_INFO("process %d goes to sleep for %d seconds", id, id);
simgrid::s4u::this_actor::sleep_for(id);
XBT_INFO("process %d is writing again!", id);
- file->write(3000000);
+ storage->write(3000000);
XBT_INFO("process %d goes to sleep for %d seconds", id, 6 - id);
simgrid::s4u::this_actor::sleep_for(6 - id);
XBT_INFO("process %d is reading!", id);
- file->seek(0);
- file->read(3000000);
+ storage->read(3000000);
XBT_INFO("process %d goes to sleep for %d seconds", id, id);
simgrid::s4u::this_actor::sleep_for(id);
XBT_INFO("process %d is reading again!", id);
- file->seek(0);
- file->read(3000000);
-
- XBT_INFO("process %d => Size of %s: %llu", id, name, file->size());
- // Close the file
- delete file;
+ storage->read(3000000);
}
int main(int argc, char** argv)
> [ 6.750000] (host@bob) process 4 goes to sleep for 4 seconds
> [ 6.750000] (host@bob) process 5 goes to sleep for 5 seconds
> [ 7.750000] (host@bob) process 1 is reading again!
-> [ 7.780000] (host@bob) process 1 => Size of /home/doc/simgrid/examples/platforms/g5k.xml1: 6000000
> [ 8.750000] (host@bob) process 2 is reading again!
-> [ 8.780000] (host@bob) process 2 => Size of /home/doc/simgrid/examples/platforms/g5k.xml2: 6000000
> [ 9.750000] (host@bob) process 3 is reading again!
-> [ 9.780000] (host@bob) process 3 => Size of /home/doc/simgrid/examples/platforms/g5k.xml3: 6000000
> [ 10.750000] (host@bob) process 4 is reading again!
-> [ 10.780000] (host@bob) process 4 => Size of /home/doc/simgrid/examples/platforms/g5k.xml4: 6000000
> [ 11.750000] (host@bob) process 5 is reading again!
-> [ 11.780000] (host@bob) process 5 => Size of /home/doc/simgrid/examples/platforms/g5k.xml5: 6000000
> [ 11.780000] (maestro@) Simulation time 11.78
int main(int argc, char* argv[])
{
simgrid::s4u::Engine e(&argc, argv);
+ sg_storage_file_system_init();
xbt_assert(argc == 2, "Usage: %s platform_file\n", argv[0]);
e.loadPlatform(argv[1]);
> [ 0.806104] (server@alice) 6217 bytes on 6217 bytes have been written by server on /sd1
> [ 1.207952] (server@alice) *** Storage info on alice ***
> [ 1.207952] (server@alice) Storage name: Disk2, mount name: c:
+> [ 1.207952] (server@alice) Free size: 534479367024 bytes
+> [ 1.207952] (server@alice) Used size: 2391544976 bytes
> [ 1.207952] (client@bob) *** GET/SET DATA for storage element: Disk1 ***
> [ 1.207952] (client@bob) Get data: '(null)'
> [ 1.207952] (client@bob) Set and get data: 'Some data'
-> [ 1.207952] (server@alice) Free size: 534479367024 bytes
-> [ 1.207952] (server@alice) Used size: 2391544976 bytes
> [ 1.207952] (server@alice) No property attached.
> [ 1.207952] (server@alice) *** Dump a storage element ***
> [ 1.207952] (server@alice) Print the content of the storage element: Disk2
set(headers_to_install
include/simgrid/chrono.hpp
include/simgrid/plugins/energy.h
+ include/simgrid/plugins/file_system.h
include/simgrid/plugins/load.h
include/simgrid/instr.h
include/simgrid/msg.h