From 1ccf8a72fef6dfd6db657a0eddb5035442f11deb Mon Sep 17 00:00:00 2001
From: Danny Auble <da@schedmd.com>
Date: Thu, 8 Dec 2016 11:13:05 -0700
Subject: [PATCH] Fix issue where task/cgroup would not always honor
 --cpu_bind=threads.

---
 NEWS                                         |  1 +
 src/plugins/task/cgroup/task_cgroup_cpuset.c | 14 ++++++++++++--
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 54aa88fd4a5..40c238ada4e 100644
--- a/NEWS
+++ b/NEWS
@@ -79,6 +79,7 @@ documents those changes that are of interest to users and administrators.
  -- jobcomp/elasticsearch - fix printf format for a value on 32-bit builds.
  -- task/cgroup - Change error message if CPU binding can not take place to
     better identify the root cause of the problem.
+ -- Fix issue where task/cgroup would not always hone --cpu_bind=threads.
 
 * Changes in Slurm 16.05.6
 ==========================
diff --git a/src/plugins/task/cgroup/task_cgroup_cpuset.c b/src/plugins/task/cgroup/task_cgroup_cpuset.c
index 96b98694b47..b363d1a6e10 100644
--- a/src/plugins/task/cgroup/task_cgroup_cpuset.c
+++ b/src/plugins/task/cgroup/task_cgroup_cpuset.c
@@ -1531,14 +1531,24 @@ extern int task_cgroup_cpuset_set_task_affinity(stepd_step_rec_t *job)
 	    (job->job_core_spec != CORE_SPEC_THREAD)) {
 		spec_threads = job->job_core_spec & (~CORE_SPEC_THREAD);
 	}
-	if (npus >= (jnpus + spec_threads) || bind_type & CPU_BIND_TO_THREADS) {
+
+	/* Set this to PU but realise it could be overridden later if we can
+	 * fill up a core.
+	 */
+	if (npus >= (jnpus + spec_threads)) {
 		hwtype = HWLOC_OBJ_PU;
 		nobj = npus;
 	}
-	if (ncores >= jnpus || bind_type & CPU_BIND_TO_CORES) {
+
+	/* Force to bind to Threads */
+	if (bind_type & CPU_BIND_TO_THREADS) {
+		hwtype = HWLOC_OBJ_PU;
+		nobj = npus;
+	} else if (ncores >= jnpus || bind_type & CPU_BIND_TO_CORES) {
 		hwtype = HWLOC_OBJ_CORE;
 		nobj = ncores;
 	}
+
 	if (nsockets >= jntasks &&
 	    bind_type & CPU_BIND_TO_SOCKETS) {
 		hwtype = socket_or_node;
-- 
GitLab