#include "surf_private.h"
#include "surf.hpp"
+#include "network.hpp"
#include "cpu.hpp"
+#include "workstation.hpp"
#include "simix/smx_host_private.h"
#include "surf_routing.hpp"
#include "simgrid/sg_config.h"
xbt_dict_free(&elm);
}
-static XBT_INLINE void surf_resource_free(void *r)
+static XBT_INLINE void surf_cpu_free(void *r)
{
- ResourcePtr resource = (ResourcePtr) r;
- delete resource;
+ delete static_cast<CpuPtr>(r);
}
+static XBT_INLINE void surf_link_free(void *r)
+{
+ delete static_cast<NetworkCm02LinkPtr>(r);
+}
+
+static XBT_INLINE void surf_workstation_free(void *r)
+{
+ delete static_cast<WorkstationCLM03Ptr>(r);
+}
+
+
void sg_version(int *ver_major,int *ver_minor,int *ver_patch) {
*ver_major = SIMGRID_VERSION_MAJOR;
*ver_minor = SIMGRID_VERSION_MINOR;
ROUTING_PROP_ASR_LEVEL = xbt_lib_add_level(as_router_lib,routing_asr_prop_free);
XBT_DEBUG("Add SURF levels");
- SURF_CPU_LEVEL = xbt_lib_add_level(host_lib,surf_resource_free);
- SURF_WKS_LEVEL = xbt_lib_add_level(host_lib,surf_resource_free);
- SURF_LINK_LEVEL = xbt_lib_add_level(link_lib,surf_resource_free);
+ SURF_CPU_LEVEL = xbt_lib_add_level(host_lib,surf_cpu_free);
+ SURF_WKS_LEVEL = xbt_lib_add_level(host_lib,surf_workstation_free);
+ SURF_LINK_LEVEL = xbt_lib_add_level(link_lib,surf_link_free);
xbt_init(argc, argv);
if (!model_list)
double Model::shareResources(double now)
{
- //FIXME: to implement
+ //FIXME: set the good function once and for all
+ if (p_updateMechanism == UM_LAZY)
+ shareResourcesLazy(now);
+ else if (p_updateMechanism == UM_FULL)
+ shareResourcesFull(now);
+ else
+ xbt_die("Invalid cpu update mechanism!");
}
double Model::shareResourcesLazy(double now)
return min;
}
+double Model::shareResourcesFull(double now) {
+ THROW_UNIMPLEMENTED;
+}
+
+
double Model::shareResourcesMaxMin(xbt_swag_t running_actions,
size_t offset,
lmm_system_t sys,
Resource::Resource(){
//FIXME:free(m_name);
- xbt_dict_free(&m_properties);
+ //FIXME:xbt_dict_free(&m_properties);
}
const char *Resource::getName()
e_surf_resource_state_t Resource::getState()
{
- return m_stateCurrent;
+ return p_stateCurrent;
}
bool Resource::isOn()
return m_remains == 0 ? m_finish : -1;
}
+double Action::getRemains()
+{
+ XBT_IN("(%p)", this);
+ XBT_OUT();
+ return m_remains;
+}
+
void Action::setData(void* data)
{
p_data = data;
int ActionLmm::unref(){
m_refcount--;
if (!m_refcount) {
- xbt_swag_remove(this, p_stateSet);
+ xbt_swag_remove(static_cast<ActionPtr>(this), p_stateSet);
if (p_variable)
lmm_variable_free(p_model->p_maxminSystem, p_variable);
if (p_model->p_updateMechanism == UM_LAZY) {
m_indexHeap = i;
}
-
double ActionLmm::getRemains()
{
XBT_IN("(%p)", this);
/* update remains before return it */
- if (p_updateMechanism == UM_LAZY) /* update remains before return it */
+ if (p_model->p_updateMechanism == UM_LAZY) /* update remains before return it */
updateRemainingLazy(surf_get_clock());
XBT_OUT();
return m_remains;
}
+//FIXME split code in the right places
+void ActionLmm::updateRemainingLazy(double now)
+{
+ double delta = 0.0;
+
+ if(p_model == static_cast<ModelPtr>(surf_network_model))
+ {
+ if (m_suspended != 0)
+ return;
+ }
+ else
+ {
+ xbt_assert(p_stateSet == p_model->p_runningActionSet,
+ "You're updating an action that is not running.");
+
+ /* bogus priority, skip it */
+ xbt_assert(m_priority > 0,
+ "You're updating an action that seems suspended.");
+ }
+
+ delta = now - m_lastUpdate;
+
+ if (m_remains > 0) {
+ XBT_DEBUG("Updating action(%p): remains was %lf, last_update was: %lf", this, m_remains, m_lastUpdate);
+ double_update(&m_remains, m_lastValue * delta);
+
+#ifdef HAVE_TRACING
+ if (p_model == static_cast<ModelPtr>(surf_cpu_model) && TRACE_is_enabled()) {
+ ResourcePtr cpu = static_cast<ResourcePtr>(lmm_constraint_id(lmm_get_cnst_from_var(p_model->p_maxminSystem, p_variable, 0)));
+ TRACE_surf_host_set_utilization(cpu->m_name, p_category, m_lastValue, m_lastUpdate, now - m_lastUpdate);
+ }
+#endif
+ XBT_DEBUG("Updating action(%p): remains is now %lf", this, m_remains);
+ }
+
+ if(p_model == static_cast<ModelPtr>(surf_network_model))
+ {
+ if (m_maxDuration != NO_MAX_DURATION)
+ double_update(&m_maxDuration, delta);
+
+ //FIXME: duplicated code
+ if ((m_remains <= 0) &&
+ (lmm_get_variable_weight(p_variable) > 0)) {
+ m_finish = surf_get_clock();
+ setState(SURF_ACTION_DONE);
+ heapRemove(p_model->p_actionHeap);
+ } else if (((m_maxDuration != NO_MAX_DURATION)
+ && (m_maxDuration <= 0))) {
+ m_finish = surf_get_clock();
+ setState(SURF_ACTION_DONE);
+ heapRemove(p_model->p_actionHeap);
+ }
+ }
+
+ m_lastUpdate = now;
+ m_lastValue = lmm_variable_getvalue(p_variable);
+}
+
/*void Action::cancel()
{
p_model->notifyActionCancel(this);