From 5539a0b83583cb758cd5f4aaa823c0a3104ec38c Mon Sep 17 00:00:00 2001
From: Michael Hinton <hinton@schedmd.com>
Date: Tue, 23 Feb 2021 17:23:54 -0700
Subject: [PATCH] Allow xcpuinfo_mac_to_abs() to be dictated by configured CPU
 topology

Continuation of 25d74cc45f.
mac_to_abs() is patterned off of abs_to_mac(). But when we reverted a
change to abs_to_mac() in commit 25d74cc45f, we did not make a similar
change to mac_to_abs().

Bug 10932
---
 NEWS                         |  1 +
 src/slurmd/common/xcpuinfo.c | 24 +++++++++++-------------
 2 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/NEWS b/NEWS
index 3af57ccc2a1..e05f5997d40 100644
--- a/NEWS
+++ b/NEWS
@@ -49,6 +49,7 @@ documents those changes that are of interest to users and administrators.
  -- Add job_container/tmps plugin to give a method to provide a private /tmp
     per job.
  -- Set the correct core affinity when using AutoDetect.
+ -- Start relying on the conf again in xcpuinfo_mac_to_abs().
 
 * Changes in Slurm 20.11.4
 ==========================
diff --git a/src/slurmd/common/xcpuinfo.c b/src/slurmd/common/xcpuinfo.c
index 95a88db5585..c2f70725894 100644
--- a/src/slurmd/common/xcpuinfo.c
+++ b/src/slurmd/common/xcpuinfo.c
@@ -1066,18 +1066,16 @@ end_it:
  */
 int xcpuinfo_mac_to_abs(char *in_range, char **out_range)
 {
-	uint16_t total_cores, total_cpus;
+	static int total_cores = -1, total_cpus = -1;
 	bitstr_t *macmap = NULL;
 	bitstr_t *absmap = NULL;
 	bitstr_t *absmap_core = NULL;
 	int rc = SLURM_SUCCESS;
 
-	/* init internal data if not already done */
-	if (xcpuinfo_init() != XCPUINFO_SUCCESS)
-		return SLURM_ERROR;
-
-	total_cores = sockets * cores;
-	total_cpus = block_map_size;
+	if (total_cores == -1) {
+		total_cores = conf->sockets * conf->cores;
+		total_cpus  = conf->block_map_size;
+	}
 
 	/* allocate bitmaps */
 	macmap = bit_alloc(total_cpus);
@@ -1095,18 +1093,18 @@ int xcpuinfo_mac_to_abs(char *in_range, char **out_range)
 		goto end_it;
 	}
 
-	/* mapping machine id to abstract id using block_map_inv */
+	/* mapping machine id to abstract id using conf->block_map_inv */
 	for (int icore = 0; icore < total_cores; icore++) {
-		for (int ithread = 0; ithread < threads; ithread++) {
+		for (int ithread = 0; ithread < conf->threads; ithread++) {
 			int absid, macid;
-			macid = (icore * threads) + ithread;
+			macid = (icore * conf->threads) + ithread;
 			macid %= total_cpus;
 
 			/* Skip this machine CPU id if not in in_range */
 			if (!bit_test(macmap, macid))
 				continue;
 
-			absid = block_map_inv[macid];
+			absid = conf->block_map_inv[macid];
 			absid %= total_cpus;
 
 			bit_set(absmap, absid);
@@ -1115,8 +1113,8 @@ int xcpuinfo_mac_to_abs(char *in_range, char **out_range)
 
 	/* condense abstract CPU bitmap into an abstract core bitmap */
 	for (int icore = 0; icore < total_cores; icore++) {
-		for (int ithread = 0; ithread < threads; ithread++) {
-			int icpu = (icore * threads) + ithread;
+		for (int ithread = 0; ithread < conf->threads; ithread++) {
+			int icpu = (icore * conf->threads) + ithread;
 			icpu %= total_cpus;
 
 			if (bit_test(absmap, icpu)) {
-- 
GitLab