#include "mc/mc.h"
#include "simgrid/s4u/Engine.hpp"
#include "simgrid/sg_config.h"
-#include "src/instr/instr_private.h" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals
+#include "src/instr/instr_private.hpp" // TRACE_is_enabled(). FIXME: remove by subscribing tracing to the surf signals
#include "src/kernel/routing/NetPoint.hpp"
#include "src/surf/HostImpl.hpp"
#include <string>
#include <vector>
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
XBT_LOG_NEW_CATEGORY(surf, "All SURF categories");
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf, "Logging specific to SURF (kernel)");
return nullptr;
}
-#ifdef _WIN32
-#include <windows.h>
-#define MAX_DRIVE 26
-static const char *disk_drives_letter_table[MAX_DRIVE] = {
- "A:\\","B:\\","C:\\","D:\\","E:\\","F:\\","G:\\","H:\\","I:\\","J:\\","K:\\","L:\\","M:\\",
- "N:\\","O:\\","P:\\","Q:\\","R:\\","S:\\","T:\\","U:\\","V:\\","W:\\","X:\\","Y:\\","Z:\\"
-};
-#endif
-
-/*
- * Returns the initial path. On Windows the initial path is
- * the current directory for the current process in the other
- * case the function returns "./" that represents the current
- * directory on Unix/Linux platforms.
- */
-
-const char *__surf_get_initial_path()
-{
-
-#ifdef _WIN32
- unsigned i;
- char current_directory[MAX_PATH + 1] = { 0 };
- unsigned int len = GetCurrentDirectory(MAX_PATH + 1, current_directory);
- char root[4] = { 0 };
-
- if (not len)
- return nullptr;
-
- strncpy(root, current_directory, 3);
-
- for (i = 0; i < MAX_DRIVE; i++) {
- if (toupper(root[0]) == disk_drives_letter_table[i][0])
- return disk_drives_letter_table[i];
- }
-
- return nullptr;
-#else
- return "./";
-#endif
-}
-
/* The __surf_is_absolute_file_path() returns 1 if
* file_path is a absolute file path, in the other
* case the function returns 0.
printf(" %s: %s\n", table[i].name, table[i].description);
}
-int find_model_description(s_surf_model_description_t* table, const char* name)
+int find_model_description(s_surf_model_description_t* table, std::string name)
{
for (int i = 0; table[i].name; i++)
- if (not strcmp(name, table[i].name)) {
+ if (name == table[i].name)
return i;
- }
if (not table[0].name)
xbt_die("No model is valid! This is a bug.");
- char* name_list = xbt_strdup(table[0].name);
- for (int i = 1; table[i].name; i++) {
- name_list = (char *) xbt_realloc(name_list, strlen(name_list) + strlen(table[i].name) + 3);
- strncat(name_list, ", ", 2);
- strncat(name_list, table[i].name, strlen(table[i].name));
- }
- xbt_die("Model '%s' is invalid! Valid models are: %s.", name, name_list);
+ std::string name_list = std::string(table[0].name);
+ for (int i = 1; table[i].name; i++)
+ name_list = name_list + ", " + table[i].name;
+
+ xbt_die("Model '%s' is invalid! Valid models are: %s.", name.c_str(), name_list.c_str());
return -1;
}
return model_;
}
-const char* Resource::cname() const
+const std::string& Resource::getName() const
+{
+ return name_;
+}
+
+const char* Resource::getCname() const
{
return name_.c_str();
}
xbt_free(category_);
}
-void Action::finish() {
+void Action::finish(Action::State state)
+{
finishTime_ = surf_get_clock();
+ setState(state);
}
Action::State Action::getState()
double Action::getFinishTime()
{
- /* keep the function behavior, some models (cpu_ti) change the finish time before the action end */
- return remains_ <= 0 ? finishTime_ : -1;
+ return finishTime_;
}
void Action::setData(void* data)
{
XBT_IN("(%p)", this);
if (suspended_ != 2) {
- lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), sharingWeight_);
+ lmm_update_variable_weight(getModel()->getMaxminSystem(), getVariable(), getPriority());
suspended_ = 0;
if (getModel()->getUpdateMechanism() == UM_LAZY)
heapRemove(getModel()->getActionHeap());
return remains_;
}
-//FIXME split code in the right places
-void Action::updateRemainingLazy(double now)
-{
- double delta = 0.0;
-
- if (getModel() == surf_network_model) {
- if (suspended_ != 0)
- return;
- } else {
- xbt_assert(stateSet_ == getModel()->getRunningActionSet(), "You're updating an action that is not running.");
- xbt_assert(sharingWeight_ > 0, "You're updating an action that seems suspended.");
- }
-
- delta = now - lastUpdate_;
-
- if (remains_ > 0) {
- XBT_DEBUG("Updating action(%p): remains was %f, last_update was: %f", this, remains_, lastUpdate_);
- double_update(&remains_, lastValue_ * delta, sg_surf_precision*sg_maxmin_precision);
-
- if (getModel() == surf_cpu_model_pm && TRACE_is_enabled()) {
- simgrid::surf::Resource *cpu = static_cast<simgrid::surf::Resource*>(
- lmm_constraint_id(lmm_get_cnst_from_var(getModel()->getMaxminSystem(), getVariable(), 0)));
- TRACE_surf_host_set_utilization(cpu->cname(), getCategory(), lastValue_, lastUpdate_, now - lastUpdate_);
- }
- XBT_DEBUG("Updating action(%p): remains is now %f", this, remains_);
- }
-
- if (getModel() == surf_network_model) {
- if (maxDuration_ != NO_MAX_DURATION)
- double_update(&maxDuration_, delta, sg_surf_precision);
-
- //FIXME: duplicated code
- if (((remains_ <= 0) && (lmm_get_variable_weight(getVariable()) > 0)) ||
- ((maxDuration_ > NO_MAX_DURATION) && (maxDuration_ <= 0))) {
- finish();
- setState(Action::State::done);
- heapRemove(getModel()->getActionHeap());
- }
- }
-
- lastUpdate_ = now;
- lastValue_ = lmm_variable_getvalue(getVariable());
-}
-
}
}