typedef simgrid::simix::ActorImpl* smx_actor_t;
typedef simgrid::simix::MutexImpl* smx_mutex_t;
typedef simgrid::kernel::activity::MailboxImpl* smx_mailbox_t;
-typedef simgrid::surf::FileImpl* surf_file_t;
+typedef simgrid::surf::StorageImpl* surf_storage_t;
#else
typedef struct s_smx_actor* smx_actor_t;
typedef struct s_smx_mutex* smx_mutex_t;
typedef struct s_smx_mailbox* smx_mailbox_t;
-typedef struct s_surf_file* surf_file_t;
+typedef struct s_surf_storage* surf_storage_t;
#endif
int desc_id = 0;
private:
- surf_file_t pimpl_ = nullptr;
+ simgrid::surf::FileImpl* pimpl_ = nullptr;
std::string path_;
void* userdata_ = nullptr;
};
sg_size_t getSize(); /** Retrieve the total amount of space of this storage element */
sg_size_t getSizeFree();
sg_size_t getSizeUsed();
+ void decrUsedSize(sg_size_t size);
std::map<std::string, std::string>* getProperties();
const char* getProperty(std::string key);
void setUserdata(void* data) { userdata_ = data; }
void* getUserdata() { return userdata_; }
+ sg_size_t read(sg_size_t size);
+ sg_size_t write(sg_size_t size);
surf::StorageImpl* getImpl() { return pimpl_; }
/* The signals */
XBT_PUBLIC(void) simcall_sem_acquire(smx_sem_t sem);
XBT_PUBLIC(void) simcall_sem_acquire_timeout(smx_sem_t sem, double max_duration);
-/***************************** File **********************************/
-XBT_PUBLIC(sg_size_t) simcall_file_read(surf_file_t fd, sg_size_t size);
-XBT_PUBLIC(sg_size_t) simcall_file_write(surf_file_t fd, sg_size_t size);
+/***************************** Storage **********************************/
+XBT_PUBLIC(sg_size_t) simcall_storage_read(surf_storage_t st, sg_size_t size);
+XBT_PUBLIC(sg_size_t) simcall_storage_write(surf_storage_t fd, sg_size_t size);
/************************** MC simcalls **********************************/
XBT_PUBLIC(int) simcall_mc_random(int min, int max);
{
for (smx_simcall_t const& simcall : simcalls) {
switch (simcall->call) {
- case SIMCALL_FILE_WRITE:
- simcall_file_write__set__result(simcall, surf_io->getCost());
- break;
- case SIMCALL_FILE_READ:
- simcall_file_read__set__result(simcall, surf_io->getCost());
- break;
- default:
- break;
+ case SIMCALL_STORAGE_WRITE:
+ simcall_storage_write__set__result(simcall, surf_io->getCost());
+ break;
+ case SIMCALL_STORAGE_READ:
+ simcall_storage_read__set__result(simcall, surf_io->getCost());
+ break;
+ default:
+ break;
}
}
sg_size_t File::read(sg_size_t size)
{
- return simcall_file_read(pimpl_, size);
+ XBT_DEBUG("READ %s on disk '%s'", getPath(), onStorage->getCname());
+ // if the current position is close to the end of the file, we may not be able to read the requested size
+ sg_size_t read_size = onStorage->read(std::min(size, this->size() - this->tell()));
+ pimpl_->incrPosition(read_size);
+ return read_size;
}
sg_size_t File::write(sg_size_t size)
{
- return simcall_file_write(pimpl_, size);
+ XBT_DEBUG("WRITE %s on disk '%s'. size '%llu/%llu'", getPath(), onStorage->getCname(), size, this->size());
+ // If the storage is full before even starting to write
+ if (onStorage->getSizeUsed() >= onStorage->getSize())
+ return 0;
+ /* Substract the part of the file that might disappear from the used sized on the storage element */
+ onStorage->decrUsedSize(this->size() - this->tell());
+
+ sg_size_t write_size = onStorage->write(size);
+ pimpl_->incrPosition(write_size);
+ pimpl_->setSize(this->tell());
+
+ onStorage->getContent()->erase(pimpl_->getName());
+ onStorage->getContent()->insert({pimpl_->getName(), this->size()});
+
+ return write_size;
}
sg_size_t File::size()
/* 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 "../surf/StorageImpl.hpp"
#include "simgrid/s4u/Host.hpp"
#include "simgrid/s4u/Storage.hpp"
#include "simgrid/simix.hpp"
+#include "src/surf/StorageImpl.hpp"
#include <unordered_map>
namespace simgrid {
return simgrid::simix::kernelImmediate([this] { return pimpl_->getUsedSize(); });
}
+void Storage::decrUsedSize(sg_size_t size)
+{
+ simgrid::simix::kernelImmediate([this, size] { pimpl_->usedSize_ -= size; });
+}
+
sg_size_t Storage::getSize()
{
return pimpl_->getSize();
return simgrid::simix::kernelImmediate([this] { return pimpl_->getContent(); });
}
+sg_size_t Storage::read(sg_size_t size)
+{
+ return simcall_storage_read(pimpl_, size);
+}
+
+sg_size_t Storage::write(sg_size_t size)
+{
+ return simcall_storage_write(pimpl_, size);
+}
+
/*************
* Callbacks *
*************/
* \ingroup simix_synchro_management
*
*/
-void simcall_cond_wait_timeout(smx_cond_t cond,
- smx_mutex_t mutex,
- double timeout)
+void simcall_cond_wait_timeout(smx_cond_t cond, smx_mutex_t mutex, double timeout)
{
xbt_assert(std::isfinite(timeout), "timeout is not finite!");
simcall_BODY_cond_wait_timeout(cond, mutex, timeout);
simcall_BODY_sem_acquire_timeout(sem, timeout);
}
-/**
- * \ingroup simix_file_management
- *
- */
-sg_size_t simcall_file_read(surf_file_t fd, sg_size_t size)
+sg_size_t simcall_storage_read(surf_storage_t st, sg_size_t size)
{
- return simcall_BODY_file_read(fd, size);
+ return simcall_BODY_storage_read(st, size);
}
-/**
- * \ingroup simix_file_management
- *
- */
-sg_size_t simcall_file_write(surf_file_t fd, sg_size_t size)
+sg_size_t simcall_storage_write(surf_storage_t st, sg_size_t size)
{
- return simcall_BODY_file_write(fd, size);
+ return simcall_BODY_storage_write(st, size);
}
void simcall_run_kernel(std::function<void()> const& code)
simgrid::simix::marshal<double>(simcall->args[1], arg);
}
-static inline surf_file_t simcall_file_read__get__fd(smx_simcall_t simcall)
+static inline surf_storage_t simcall_storage_read__get__st(smx_simcall_t simcall)
{
- return simgrid::simix::unmarshal<surf_file_t>(simcall->args[0]);
+ return simgrid::simix::unmarshal<surf_storage_t>(simcall->args[0]);
}
-static inline surf_file_t simcall_file_read__getraw__fd(smx_simcall_t simcall)
+static inline surf_storage_t simcall_storage_read__getraw__st(smx_simcall_t simcall)
{
- return simgrid::simix::unmarshal_raw<surf_file_t>(simcall->args[0]);
+ return simgrid::simix::unmarshal_raw<surf_storage_t>(simcall->args[0]);
}
-static inline void simcall_file_read__set__fd(smx_simcall_t simcall, surf_file_t arg)
+static inline void simcall_storage_read__set__st(smx_simcall_t simcall, surf_storage_t arg)
{
- simgrid::simix::marshal<surf_file_t>(simcall->args[0], arg);
+ simgrid::simix::marshal<surf_storage_t>(simcall->args[0], arg);
}
-static inline sg_size_t simcall_file_read__get__size(smx_simcall_t simcall)
+static inline sg_size_t simcall_storage_read__get__size(smx_simcall_t simcall)
{
return simgrid::simix::unmarshal<sg_size_t>(simcall->args[1]);
}
-static inline sg_size_t simcall_file_read__getraw__size(smx_simcall_t simcall)
+static inline sg_size_t simcall_storage_read__getraw__size(smx_simcall_t simcall)
{
return simgrid::simix::unmarshal_raw<sg_size_t>(simcall->args[1]);
}
-static inline void simcall_file_read__set__size(smx_simcall_t simcall, sg_size_t arg)
+static inline void simcall_storage_read__set__size(smx_simcall_t simcall, sg_size_t arg)
{
simgrid::simix::marshal<sg_size_t>(simcall->args[1], arg);
}
-static inline sg_size_t simcall_file_read__get__result(smx_simcall_t simcall)
+static inline sg_size_t simcall_storage_read__get__result(smx_simcall_t simcall)
{
return simgrid::simix::unmarshal<sg_size_t>(simcall->result);
}
-static inline sg_size_t simcall_file_read__getraw__result(smx_simcall_t simcall)
+static inline sg_size_t simcall_storage_read__getraw__result(smx_simcall_t simcall)
{
return simgrid::simix::unmarshal_raw<sg_size_t>(simcall->result);
}
-static inline void simcall_file_read__set__result(smx_simcall_t simcall, sg_size_t result)
+static inline void simcall_storage_read__set__result(smx_simcall_t simcall, sg_size_t result)
{
simgrid::simix::marshal<sg_size_t>(simcall->result, result);
}
-static inline surf_file_t simcall_file_write__get__fd(smx_simcall_t simcall)
+static inline surf_storage_t simcall_storage_write__get__st(smx_simcall_t simcall)
{
- return simgrid::simix::unmarshal<surf_file_t>(simcall->args[0]);
+ return simgrid::simix::unmarshal<surf_storage_t>(simcall->args[0]);
}
-static inline surf_file_t simcall_file_write__getraw__fd(smx_simcall_t simcall)
+static inline surf_storage_t simcall_storage_write__getraw__st(smx_simcall_t simcall)
{
- return simgrid::simix::unmarshal_raw<surf_file_t>(simcall->args[0]);
+ return simgrid::simix::unmarshal_raw<surf_storage_t>(simcall->args[0]);
}
-static inline void simcall_file_write__set__fd(smx_simcall_t simcall, surf_file_t arg)
+static inline void simcall_storage_write__set__st(smx_simcall_t simcall, surf_storage_t arg)
{
- simgrid::simix::marshal<surf_file_t>(simcall->args[0], arg);
+ simgrid::simix::marshal<surf_storage_t>(simcall->args[0], arg);
}
-static inline sg_size_t simcall_file_write__get__size(smx_simcall_t simcall)
+static inline sg_size_t simcall_storage_write__get__size(smx_simcall_t simcall)
{
return simgrid::simix::unmarshal<sg_size_t>(simcall->args[1]);
}
-static inline sg_size_t simcall_file_write__getraw__size(smx_simcall_t simcall)
+static inline sg_size_t simcall_storage_write__getraw__size(smx_simcall_t simcall)
{
return simgrid::simix::unmarshal_raw<sg_size_t>(simcall->args[1]);
}
-static inline void simcall_file_write__set__size(smx_simcall_t simcall, sg_size_t arg)
+static inline void simcall_storage_write__set__size(smx_simcall_t simcall, sg_size_t arg)
{
simgrid::simix::marshal<sg_size_t>(simcall->args[1], arg);
}
-static inline sg_size_t simcall_file_write__get__result(smx_simcall_t simcall)
+static inline sg_size_t simcall_storage_write__get__result(smx_simcall_t simcall)
{
return simgrid::simix::unmarshal<sg_size_t>(simcall->result);
}
-static inline sg_size_t simcall_file_write__getraw__result(smx_simcall_t simcall)
+static inline sg_size_t simcall_storage_write__getraw__result(smx_simcall_t simcall)
{
return simgrid::simix::unmarshal_raw<sg_size_t>(simcall->result);
}
-static inline void simcall_file_write__set__result(smx_simcall_t simcall, sg_size_t result)
+static inline void simcall_storage_write__set__result(smx_simcall_t simcall, sg_size_t result)
{
simgrid::simix::marshal<sg_size_t>(simcall->result, result);
}
XBT_PRIVATE void simcall_HANDLER_cond_wait_timeout(smx_simcall_t simcall, smx_cond_t cond, smx_mutex_t mutex, double timeout);
XBT_PRIVATE void simcall_HANDLER_sem_acquire(smx_simcall_t simcall, smx_sem_t sem);
XBT_PRIVATE void simcall_HANDLER_sem_acquire_timeout(smx_simcall_t simcall, smx_sem_t sem, double timeout);
-XBT_PRIVATE void simcall_HANDLER_file_read(smx_simcall_t simcall, surf_file_t fd, sg_size_t size);
-XBT_PRIVATE void simcall_HANDLER_file_write(smx_simcall_t simcall, surf_file_t fd, sg_size_t size);
+XBT_PRIVATE void simcall_HANDLER_storage_read(smx_simcall_t simcall, surf_storage_t st, sg_size_t size);
+XBT_PRIVATE void simcall_HANDLER_storage_write(smx_simcall_t simcall, surf_storage_t st, sg_size_t size);
XBT_PRIVATE int simcall_HANDLER_mc_random(smx_simcall_t simcall, int min, int max);
\ No newline at end of file
return simcall<void, smx_sem_t, double>(SIMCALL_SEM_ACQUIRE_TIMEOUT, sem, timeout);
}
-inline static sg_size_t simcall_BODY_file_read(surf_file_t fd, sg_size_t size)
+inline static sg_size_t simcall_BODY_storage_read(surf_storage_t st, sg_size_t size)
{
if (0) /* Go to that function to follow the code flow through the simcall barrier */
- simcall_HANDLER_file_read(&SIMIX_process_self()->simcall, fd, size);
- return simcall<sg_size_t, surf_file_t, sg_size_t>(SIMCALL_FILE_READ, fd, size);
+ simcall_HANDLER_storage_read(&SIMIX_process_self()->simcall, st, size);
+ return simcall<sg_size_t, surf_storage_t, sg_size_t>(SIMCALL_STORAGE_READ, st, size);
}
-inline static sg_size_t simcall_BODY_file_write(surf_file_t fd, sg_size_t size)
+inline static sg_size_t simcall_BODY_storage_write(surf_storage_t st, sg_size_t size)
{
if (0) /* Go to that function to follow the code flow through the simcall barrier */
- simcall_HANDLER_file_write(&SIMIX_process_self()->simcall, fd, size);
- return simcall<sg_size_t, surf_file_t, sg_size_t>(SIMCALL_FILE_WRITE, fd, size);
+ simcall_HANDLER_storage_write(&SIMIX_process_self()->simcall, st, size);
+ return simcall<sg_size_t, surf_storage_t, sg_size_t>(SIMCALL_STORAGE_WRITE, st, size);
}
inline static int simcall_BODY_mc_random(int min, int max)
SIMCALL_COND_BROADCAST,
SIMCALL_SEM_ACQUIRE,
SIMCALL_SEM_ACQUIRE_TIMEOUT,
- SIMCALL_FILE_READ,
- SIMCALL_FILE_WRITE,
+ SIMCALL_STORAGE_READ,
+ SIMCALL_STORAGE_WRITE,
SIMCALL_MC_RANDOM,
SIMCALL_SET_CATEGORY,
SIMCALL_RUN_KERNEL,
- SIMCALL_RUN_BLOCKING, NUM_SIMCALLS
+ SIMCALL_RUN_BLOCKING,
+ NUM_SIMCALLS
} e_smx_simcall_t;
"SIMCALL_COND_BROADCAST",
"SIMCALL_SEM_ACQUIRE",
"SIMCALL_SEM_ACQUIRE_TIMEOUT",
- "SIMCALL_FILE_READ",
- "SIMCALL_FILE_WRITE",
+ "SIMCALL_STORAGE_READ",
+ "SIMCALL_STORAGE_WRITE",
"SIMCALL_MC_RANDOM",
"SIMCALL_SET_CATEGORY",
"SIMCALL_RUN_KERNEL",
simcall_HANDLER_sem_acquire_timeout(simcall, simgrid::simix::unmarshal<smx_sem_t>(simcall->args[0]), simgrid::simix::unmarshal<double>(simcall->args[1]));
break;
-case SIMCALL_FILE_READ:
- simcall_HANDLER_file_read(simcall, simgrid::simix::unmarshal<surf_file_t>(simcall->args[0]), simgrid::simix::unmarshal<sg_size_t>(simcall->args[1]));
+case SIMCALL_STORAGE_READ:
+ simcall_HANDLER_storage_read(simcall, simgrid::simix::unmarshal<surf_storage_t>(simcall->args[0]),
+ simgrid::simix::unmarshal<sg_size_t>(simcall->args[1]));
break;
-case SIMCALL_FILE_WRITE:
- simcall_HANDLER_file_write(simcall, simgrid::simix::unmarshal<surf_file_t>(simcall->args[0]), simgrid::simix::unmarshal<sg_size_t>(simcall->args[1]));
+case SIMCALL_STORAGE_WRITE:
+ simcall_HANDLER_storage_write(simcall, simgrid::simix::unmarshal<surf_storage_t>(simcall->args[0]),
+ simgrid::simix::unmarshal<sg_size_t>(simcall->args[1]));
break;
case SIMCALL_MC_RANDOM:
void sem_acquire(smx_sem_t sem) [[block]];
void sem_acquire_timeout(smx_sem_t sem, double timeout) [[block]];
-sg_size_t file_read(surf_file_t fd, sg_size_t size) [[block]];
-sg_size_t file_write(surf_file_t fd, sg_size_t size) [[block]];
+sg_size_t storage_read(surf_storage_t st, sg_size_t size) [[block]];
+sg_size_t storage_write(surf_storage_t st, sg_size_t size) [[block]];
int mc_random(int min, int max);
void set_category(boost::intrusive_ptr<simgrid::kernel::activity::ActivityImpl> synchro, const char* category) [[nohandler]];
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(simix_io, simix, "Logging specific to SIMIX (io)");
-//SIMIX FILE READ
-void simcall_HANDLER_file_read(smx_simcall_t simcall, surf_file_t fd, sg_size_t size)
+void simcall_HANDLER_storage_read(smx_simcall_t simcall, surf_storage_t st, sg_size_t size)
{
- smx_activity_t synchro = SIMIX_file_read(fd, size);
+ smx_activity_t synchro = SIMIX_storage_read(st, size);
synchro->simcalls.push_back(simcall);
simcall->issuer->waiting_synchro = synchro;
}
-smx_activity_t SIMIX_file_read(surf_file_t file, sg_size_t size)
+smx_activity_t SIMIX_storage_read(surf_storage_t st, sg_size_t size)
{
simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl();
- synchro->surf_io = file->read(size);
+ synchro->surf_io = st->read(size);
synchro->surf_io->setData(synchro);
XBT_DEBUG("Create io synchro %p", synchro);
return synchro;
}
-//SIMIX FILE WRITE
-void simcall_HANDLER_file_write(smx_simcall_t simcall, surf_file_t fd, sg_size_t size)
+void simcall_HANDLER_storage_write(smx_simcall_t simcall, surf_storage_t st, sg_size_t size)
{
- smx_activity_t synchro = SIMIX_file_write(fd, size);
+ smx_activity_t synchro = SIMIX_storage_write(st, size);
synchro->simcalls.push_back(simcall);
simcall->issuer->waiting_synchro = synchro;
}
-smx_activity_t SIMIX_file_write(surf_file_t file, sg_size_t size)
+smx_activity_t SIMIX_storage_write(surf_storage_t st, sg_size_t size)
{
simgrid::kernel::activity::IoImpl* synchro = new simgrid::kernel::activity::IoImpl();
- synchro->surf_io = file->write(size);
+ synchro->surf_io = st->write(size);
synchro->surf_io->setData(synchro);
XBT_DEBUG("Create io synchro %p", synchro);
#include "popping_private.hpp"
#include "simgrid/simix.h"
-XBT_PRIVATE smx_activity_t SIMIX_file_read(surf_file_t fd, sg_size_t size);
-XBT_PRIVATE smx_activity_t SIMIX_file_write(surf_file_t fd, sg_size_t size);
+XBT_PRIVATE smx_activity_t SIMIX_storage_read(surf_storage_t fd, sg_size_t size);
+XBT_PRIVATE smx_activity_t SIMIX_storage_write(surf_storage_t fd, sg_size_t size);
XBT_PRIVATE void SIMIX_io_destroy(smx_activity_t synchro);
XBT_PRIVATE void SIMIX_io_finish(smx_activity_t synchro);
}
}
-Action* FileImpl::read(sg_size_t size)
-{
- XBT_DEBUG("READ %s on disk '%s'", getCname(), location_->getCname());
- if (current_position_ + size > size_) {
- if (current_position_ > size_) {
- size = 0;
- } else {
- size = size_ - current_position_;
- }
- current_position_ = size_;
- } else
- current_position_ += size;
-
- return location_->read(size);
-}
-
-Action* FileImpl::write(sg_size_t size)
-{
- XBT_DEBUG("WRITE %s on disk '%s'. size '%llu/%llu'", getCname(), location_->getCname(), size, size_);
-
- StorageAction* action = location_->write(size);
- action->file_ = this;
- /* Substract the part of the file that might disappear from the used sized on the storage element */
- location_->usedSize_ -= (size_ - current_position_);
- // If the storage is full before even starting to write
- if (location_->usedSize_ >= location_->getSize()) {
- action->setState(Action::State::failed);
- }
- return action;
-}
-
int FileImpl::seek(sg_offset_t offset, int origin)
{
switch (origin) {
int seek(sg_offset_t offset, int origin);
int unlink();
void move(std::string fullpath);
- Action* read(sg_size_t size);
- Action* write(sg_size_t size);
private:
StorageImpl* location_;
e_surf_action_storage_type_t type_;
StorageImpl* storage_;
- FileImpl* file_ = nullptr;
};
class StorageType {
action->updateRemains(current_progress);
if (action->type_ == WRITE) {
action->storage_->usedSize_ += current_progress;
- action->file_->incrPosition(current_progress);
- action->file_->setSize(action->file_->tell());
-
- action->storage_->getContent()->erase(action->file_->getCname());
- action->storage_->getContent()->insert({action->file_->getCname(), action->file_->size()});
}
if (action->getMaxDuration() > NO_MAX_DURATION)