+ /* This model does not implement parallel tasks */
+ THROW_IMPOSSIBLE;
+ return -1;
+}
+
+
+/* TODO: iterating active constraint_set may be faster? */
+#if 0
+static void deactivate_dummy_cpu_action(void)
+{
+ lmm_system_t sys = surf_cpu_model_vm->model_private->maxmin_system;
+
+ lmm_constraint_t cnst;
+ xbt_swag_foreach(cnst, &sys->active_constraint_set) {
+ /* get vcpu resource */
+ surf_resource_t cpu = lmm_constraint_id(cnst);
+ xbt_assert(cpu->model == surf_cpu_model_vm);
+
+ /* get vm_ws resource */
+ workstation_CLM03_t ws = xbt_lib_get_or_null(host_lib, cpu->name, SURF_WKS_LEVEL);
+
+ /* make sure we can cast */
+ xbt_assert(ws->generic_resouce.model == surf_vm_workstation_model);
+ workstation_VM2013_t vm_ws = (workstation_VM2013_t) ws;
+
+ /* make it active in the PM layer */
+ surf_action_set_priority(vm_ws->cpu_action, 1);
+ }
+}
+#endif
+
+
+/* TODO: Delete this unused code if everything looks good. */
+#if 0
+static int constraint_is_active(cpu_Cas01_t cpu_cas01)
+{
+ surf_model_t cpu_model = cpu_cas01->generic_resource.model;
+ lmm_system_t sys = cpu_model->model_private->maxmin_system;
+ int found = 0;
+ lmm_constraint_t cnst_tmp;
+
+ xbt_swag_foreach(cnst_tmp, &sys->active_constraint_set) {
+ if (cnst_tmp == cpu_cas01->constraint) {
+ found = 1;
+ break;
+ }
+ }
+
+ return found;
+}
+#endif
+
+
+/* Each VM has a dummy CPU action on the PM layer. This CPU action works as the
+ * constraint (capacity) of the VM in the PM layer. If the VM does not have any
+ * active task, the dummy CPU action must be deactivated, so that the VM does
+ * not get any CPU share in the PM layer. */
+static void adjust_weight_of_dummy_cpu_actions(void)
+{
+ /* iterate for all hosts including virtual machines */
+ xbt_lib_cursor_t cursor;
+ char *key;
+ void **ind_host;
+
+ xbt_lib_foreach(host_lib, cursor, key, ind_host) {
+ workstation_CLM03_t ws_clm03 = ind_host[SURF_WKS_LEVEL];
+ cpu_Cas01_t cpu_cas01 = ind_host[SURF_CPU_LEVEL];
+
+ if (!ws_clm03)
+ continue;
+ /* skip if it is not a virtual machine */
+ if (ws_clm03->generic_resource.model != surf_vm_workstation_model)
+ continue;
+ xbt_assert(cpu_cas01, "cpu-less workstation");
+
+ /* It is a virtual machine, so we can cast it to workstation_VM2013_t */
+ workstation_VM2013_t ws_vm2013 = (workstation_VM2013_t) ws_clm03;
+
+ lmm_system_t sys = surf_cpu_model_vm->model_private->maxmin_system;
+ int is_active = lmm_constraint_used(sys, cpu_cas01->constraint);
+ // int is_active_old = constraint_is_active(cpu_cas01);
+
+ // {
+ // xbt_assert(is_active == is_active_old, "%d %d", is_active, is_active_old);
+ // }
+
+ if (is_active) {
+ /* some tasks exist on this VM */
+ XBT_DEBUG("set the weight of the dummy CPU action on PM to 1");
+
+ /* FIXME: we shoud use lmm_update_variable_weight() ? */
+ /* FIXME: If we assgign 1.05 and 0.05, the system makes apparently wrong values. */
+ surf_action_set_priority(ws_vm2013->cpu_action, 1);
+
+ } else {
+ /* no task exits on this VM */
+ XBT_DEBUG("set the weight of the dummy CPU action on PM to 0");
+
+ surf_action_set_priority(ws_vm2013->cpu_action, 0);
+ }
+ }