/* \file callbacks.h */
#include "maxmin_private.hpp"
+#include "xbt/backtrace.hpp"
#include "xbt/log.h"
#include "xbt/mallocator.h"
#include "xbt/sysdep.h"
static int lmm_concurrency_slack(lmm_constraint_t cnstr);
static int lmm_cnstrs_min_concurrency_slack(lmm_variable_t var);
-inline int lmm_element_concurrency(lmm_element_t elem) {
+static inline int lmm_element_concurrency(lmm_element_t elem)
+{
//Ignore element with weight less than one (e.g. cross-traffic)
return (elem->consumption_weight >= 1) ? 1 : 0;
//There are other alternatives, but they will change the behaviour of the model..
//return (int)ceil(elem->weight);//Include element as the rounded-up integer value of the element weight
}
-inline void lmm_decrease_concurrency(lmm_element_t elem) {
+static inline void lmm_decrease_concurrency(lmm_element_t elem)
+{
xbt_assert(elem->constraint->concurrency_current>=lmm_element_concurrency(elem));
elem->constraint->concurrency_current-=lmm_element_concurrency(elem);
}
-inline void lmm_increase_concurrency(lmm_element_t elem) {
+static inline void lmm_increase_concurrency(lmm_element_t elem)
+{
elem->constraint->concurrency_current+= lmm_element_concurrency(elem);
lmm_constraint_t cnstr=elem->constraint;
}
}
-static inline void lmm_variable_remove(lmm_system_t sys, lmm_variable_t var)
+static void lmm_var_free(lmm_system_t sys, lmm_variable_t var)
{
XBT_IN("(sys=%p, var=%p)", sys, var);
sys->modified = 1;
lmm_check_concurrency(sys);
- XBT_OUT();
-}
-
-static void lmm_var_free(lmm_system_t sys, lmm_variable_t var)
-{
- lmm_variable_remove(sys, var);
xbt_mallocator_release(sys->variable_mallocator, var);
+ XBT_OUT();
}
lmm_system_t lmm_system_new(bool selective_update)
return;
while ((var = (lmm_variable_t) extract_variable(sys))) {
- int status;
- char* demangled = abi::__cxa_demangle(typeid(*var->id).name(), 0, 0, &status);
-
- XBT_WARN("Probable bug: a %s variable (#%d) not removed before the LMM system destruction.", demangled,
+ auto demangled = simgrid::xbt::demangle(typeid(*var->id).name());
+ XBT_WARN("Probable bug: a %s variable (#%d) not removed before the LMM system destruction.", demangled.get(),
var->id_int);
- xbt_free(demangled);
lmm_var_free(sys, var);
}
while ((cnst = (lmm_constraint_t) extract_constraint(sys)))
return (cnst->sharing_policy);
}
-/* @brief Remove a constraint
- * Currently this is dead code, but it is exposed in maxmin.hpp
- * Apparently, this call was designed assuming that constraint would no more have elements in it.
- * If not the case, assertion will fail, and you need to add calls e.g. to lmm_shrink before effectively removing it.
- */
-inline void lmm_constraint_free(lmm_system_t sys,lmm_constraint_t cnst)
-{
- xbt_assert(not xbt_swag_size(&(cnst->active_element_set)), "Removing constraint but it still has active elements");
- xbt_assert(not xbt_swag_size(&(cnst->enabled_element_set)), "Removing constraint but it still has enabled elements");
- xbt_assert(not xbt_swag_size(&(cnst->disabled_element_set)),
- "Removing constraint but it still has disabled elements");
- remove_constraint(sys, cnst);
- lmm_cnst_free(sys, cnst);
-}
-
static void *lmm_variable_mallocator_new_f()
{
return new s_lmm_variable_t;
return (var->bound);
}
-void lmm_shrink(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var)
-{
- auto elem_it = std::find_if(begin(var->cnsts), end(var->cnsts),
- [&cnst](s_lmm_element_t const& x) { return x.constraint == cnst; });
- if (elem_it == end(var->cnsts)) {
- XBT_DEBUG("cnst %p is not found in var %p", cnst, var);
- return;
- }
- s_lmm_element_t& elem = *elem_it;
-
- sys->modified = 1;
-
- XBT_DEBUG("remove elem(value %f, cnst %p, var %p) in var %p", elem.consumption_weight, elem.constraint, elem.variable,
- var);
-
- /* We are going to change the constraint object and the variable object.
- * Propagate this change to other objects. Calling here before removing variable from not active elements
- * (inactive elements are not visited)
- */
- lmm_update_modified_set(sys, cnst);
- //Useful in case var was already removed from the constraint
- lmm_update_modified_set(sys, var->cnsts[0].constraint); // will look up enabled_element_set of this constraint, and
- //then each var in the enabled_element_set, and each var->cnsts[i].
-
- if (xbt_swag_remove(&elem, &(elem.constraint->enabled_element_set)))
- lmm_decrease_concurrency(&elem);
-
- xbt_swag_remove(&elem, &(elem.constraint->active_element_set));
- elem.constraint = nullptr;
- elem.variable = nullptr;
- elem.consumption_weight = 0;
-
- var->cnsts.pop_back();
-
- //No variable in this constraint -> make it inactive
- if (xbt_swag_size(&(cnst->enabled_element_set))+xbt_swag_size(&(cnst->disabled_element_set)) == 0)
- make_constraint_inactive(sys, cnst);
- else {
- //Check maxconcurrency to see if we can enable new variables
- lmm_on_disabled_var(sys, elem.constraint);
- }
-
- lmm_check_concurrency(sys);
-}
-
void lmm_expand(lmm_system_t sys, lmm_constraint_t cnst, lmm_variable_t var, double consumption_weight)
{
sys->modified = 1;
lmm_update_modified_set(sys, var->cnsts[0].constraint);
}
-int lmm_concurrency_slack(lmm_constraint_t cnstr){
- //FIXME MARTIN: Replace by infinite value std::numeric_limits<int>::(max)(), or something better within Simgrid?
- if(cnstr->concurrency_limit<0)
- return 666;
-
+int lmm_concurrency_slack(lmm_constraint_t cnstr)
+{
+ if (cnstr->concurrency_limit < 0)
+ return std::numeric_limits<int>::max();
return cnstr->concurrency_limit - cnstr->concurrency_current;
}
/** \brief Measure the minimum concurrency slack across all constraints where the given var is involved */
-int lmm_cnstrs_min_concurrency_slack(lmm_variable_t var){
+int lmm_cnstrs_min_concurrency_slack(lmm_variable_t var)
+{
int minslack = std::numeric_limits<int>::max();
for (s_lmm_element_t const& elem : var->cnsts) {
int slack = lmm_concurrency_slack(elem.constraint);
-
- //This is only an optimization, to avoid looking at more constraints when slack is already zero
- //Disable it when debugging to let lmm_concurrency_slack catch nasty things
- if (not slack && not XBT_LOG_ISENABLED(surf_maxmin, xbt_log_priority_debug))
- return 0;
-
- if(minslack>slack)
- minslack=slack;
+ if (slack < minslack) {
+ // This is only an optimization, to avoid looking at more constraints when slack is already zero
+ if (slack == 0)
+ return 0;
+ minslack = slack;
+ }
}
-
return minslack;
}
lmm_element_t nextelem = (lmm_element_t)xbt_swag_getNext(elem, cnstr->disabled_element_set.offset);
- if (elem->variable->staged_weight>0 ){
+ if (elem->variable->staged_weight > 0 && lmm_can_enable_var(elem->variable)) {
//Found a staged variable
//TODOLATER: Add random timing function to model reservation protocol fuzziness? Then how to make sure that
//staged variables will eventually be called?
- if(lmm_can_enable_var(elem->variable)){
- lmm_enable_var(sys,elem->variable);
- }
+ lmm_enable_var(sys, elem->variable);
}
xbt_assert(cnstr->concurrency_current<=cnstr->concurrency_limit,"Concurrency overflow!");