Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Disallow setting an affinity to multiple cores
authorTakahiro Hirofuchi <t.hirofuchi+sg@aist.go.jp>
Fri, 25 Oct 2013 10:55:23 +0000 (12:55 +0200)
committerTakahiro Hirofuchi <t.hirofuchi+sg@aist.go.jp>
Fri, 25 Oct 2013 10:55:23 +0000 (12:55 +0200)
src/msg/msg_task.c
src/surf/cpu_cas01.c

index a35198a..f41ad31 100644 (file)
@@ -466,6 +466,14 @@ void MSG_task_set_bound(msg_task_t task, double bound)
 /** \ingroup m_task_management
  * \brief Changes the CPU affinity of a computation task.
  *
+ * When pinning the given task to the first CPU core of the given host, use
+ * 0x01 for the mask value. Each bit of the mask value corresponds to each CPU
+ * core. See taskset(1) on Linux.
+ *
+ * \param task a target task
+ * \param host the host having a multi-core CPU
+ * \param mask the value specifying the CPU affinity setting of the task
+ *
  */
 void MSG_task_set_affinity(msg_task_t task, msg_host_t host, unsigned long mask)
 {
index 897cfcd..4b9d9cc 100644 (file)
@@ -255,6 +255,24 @@ static void cpu_update_resource_state(void *id,
   return;
 }
 
+
+/*
+ *
+ * This function formulates a constraint problem that pins a given task to
+ * particular cores. Currently, it is possible to pin a task to an exactly one
+ * specific core. The system links the variable object of the task to the
+ * per-core constraint object.
+ *
+ * But, the taskset command on Linux takes a mask value specifying a CPU
+ * affinity setting of a given task. If the mask value is 0x03, the given task
+ * will be executed on the first core (CPU0) or the second core (CPU1) on the
+ * given PM. The schedular will determine appropriate placements of tasks,
+ * considering given CPU affinities and task activities.
+ *
+ * How should the system formulate constraint problems for an affinity to
+ * multiple cores?
+ *
+ */
 static void cpu_action_set_affinity(surf_action_t action, void *cpu, unsigned long mask)
 {
   lmm_variable_t var_obj = ((surf_action_lmm_t) action)->variable;
@@ -265,6 +283,25 @@ static void cpu_action_set_affinity(surf_action_t action, void *cpu, unsigned lo
 
   XBT_IN("(%p,%lx)", action, mask);
 
+  {
+    unsigned long nbits = 0;
+
+    /* FIXME: There is much faster algorithms doing this. */
+    unsigned long i;
+    for (i = 0; i < CPU->core; i++) {
+      unsigned long has_affinity = (1UL << i) & mask;
+      if (has_affinity)
+        nbits += 1;
+    }
+
+    if (nbits > 1) {
+      XBT_CRITICAL("Do not specify multiple cores for an affinity mask.");
+      XBT_CRITICAL("See the comment in cpu_action_set_affinity().");
+      DIE_IMPOSSIBLE;
+    }
+  }
+
+
 
   unsigned long i;
   for (i = 0; i < CPU->core; i++) {