Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix the dummy cpu action when no tasks are on a VM
authorTakahiro Hirofuchi <t.hirofuchi+sg@aist.go.jp>
Fri, 8 Mar 2013 09:57:06 +0000 (10:57 +0100)
committerTakahiro Hirofuchi <t.hirofuchi+sg@aist.go.jp>
Fri, 8 Mar 2013 10:26:16 +0000 (11:26 +0100)
examples/msg/cloud/simple_vm.c
src/surf/workstation.c

index 046cb93..16b4844 100644 (file)
@@ -126,7 +126,9 @@ int master_main(int argc, char *argv[])
   msg_host_t pm2 = xbt_dynar_get_as(hosts_dynar, 2, msg_host_t);
   msg_vm_t vm0, vm1;
 
-  XBT_INFO("## Test 1 (started): check computation on normal PM");
+
+  XBT_INFO("## Test 1 (started): check computation on normal PMs");
+
   XBT_INFO("### Put a task on a PM");
   launch_computation_worker(pm0);
   MSG_process_sleep(2);
@@ -140,28 +142,36 @@ int master_main(int argc, char *argv[])
   launch_computation_worker(pm0);
   launch_computation_worker(pm1);
   MSG_process_sleep(2);
+
   XBT_INFO("## Test 1 (ended)");
 
-  XBT_INFO("## Test 2  (started): check impact of running a task inside a VM (there is no degradation for the moment)");
+
+  XBT_INFO("## Test 2 (started): check impact of running a task inside a VM (there is no degradation for the moment)");
+
   XBT_INFO("### Put a VM on a PM, and put a task to the VM");
   vm0 = MSG_vm_create_core(pm0, "VM0");
   MSG_vm_start(vm0);
   launch_computation_worker(vm0);
   MSG_process_sleep(2);
   MSG_vm_destroy(vm0);
+
   XBT_INFO("## Test 2 (ended)");
+
   
-  XBT_INFO("## Test 3  (started): check impact of running a task collocated with a VM (there is no VM noise for the moment)");
-  XBT_INFO("### Put a VM on a PM, and put a task to the PM (FIXME: broken)");
+  XBT_INFO("## Test 3 (started): check impact of running a task collocated with a VM (there is no VM noise for the moment)");
+
+  XBT_INFO("### Put a VM on a PM, and put a task to the PM");
   vm0 = MSG_vm_create_core(pm0, "VM0");
   MSG_vm_start(vm0);
   launch_computation_worker(pm0);
   MSG_process_sleep(2);
   MSG_vm_destroy(vm0);
+
   XBT_INFO("## Test 3 (ended)");
 
-  XBT_INFO("## Test 4 (started): compare the cost of running two tasks inside two different VMs collocated or not (for the moment, there is no  \
-                                                                                       degradation for the VMs. Hence, the time should be equals to the time of test 1");
+
+  XBT_INFO("## Test 4 (started): compare the cost of running two tasks inside two different VMs collocated or not (for the moment, there is no degradation for the VMs. Hence, the time should be equals to the time of test 1");
+
   XBT_INFO("### Put two VMs on a PM, and put a task to each VM");
   vm0 = MSG_vm_create_core(pm0, "VM0");
   vm1 = MSG_vm_create_core(pm0, "VM1");
@@ -236,6 +246,7 @@ int master_main(int argc, char *argv[])
   MSG_process_sleep(5);
   MSG_vm_destroy(vm0);
   MSG_vm_destroy(vm1);
+
   XBT_INFO("## Test 5 (ended)");
 
 
index e00df15..dc45d07 100644 (file)
@@ -12,6 +12,9 @@
 #include "surf/surf_resource.h"
 #include "simgrid/sg_config.h"
 #include "workstation_private.h"
+#include "vm_workstation_private.h"
+#include "cpu_cas01_private.h"
+#include "maxmin_private.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_workstation, surf,
                                 "Logging specific to the SURF workstation module");
@@ -98,8 +101,70 @@ int ws_resource_used(void *resource_id)
   return -1;
 }
 
+
+/* TODO: The current code would be slow due to the iteration. Later, we can
+ * make it faster. */
+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;
+}
+
+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;
+
+    if (constraint_is_active(cpu_cas01)) {
+      /* 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);
+    }
+  }
+}
+
+
 double ws_share_resources(surf_model_t workstation_model, double now)
 {
+  if (workstation_model->type == SURF_MODEL_TYPE_WORKSTATION)
+    adjust_weight_of_dummy_cpu_actions();
+
   /* Invoke the share_resources() callback of the physical cpu model object and
    * the network model objects. */
   surf_model_t cpu_model = workstation_model->extension.workstation.cpu_model;