Skip to contentSkip to conversation

export cpu_sibling_map (take 2)

PATCH Stephane Eranian 1 participant 1 message Sep 21, 2006

lore
Share & tools
lore
#0 lore raw

Tony,

Quoted 11 lines
Quoted 10 lines · Stephane Eranian
Quoted 5 lines

For Montecito PMU support, I need to determine, in a kernel module, whether or not threads are enabled. The only reliable way of doing this is to compute the bit-weight of cpu_sibling_map[]. This symbol is exported on x86 systems, but not on IA-64 so far. This patch exports the symbol.

Exporting global variables is a very bad thing, and we only do it if we can't avoid it at all. In this case it could be easily avoided by exporting a nr_siblings_per_cpu() helper.

Quoted 7 lines

I also have my doubts about this in terms of hotplug cpu ... what do you do if not all of the cpus have their siblings on-line? The question "Are threads enabled?" doesn't seem to have a simple yes/no answer. At best you might ask "Does cpu N have any online siblings?" but the answer to that question could change before you could make use of the information.

Ok, here is the second take on this. In fact what I need is to determine whether or not multi-threading is enabled on at least one core. Due to hotplug, threading can be enabled but only one processor active (this can be true at runtime and also at boot time via maxcpus=).

What this patch does is to add a routine in smpboot.c is to check the list of present (!= online) CPU to see if they support multi-threading.

Changelog:
- add is_multithreading_enabled() to check whether multi-threading is enabled independently of which cpu is currently online

Signature · 1 line
-Stephane
arch/ia64/kernel/smpboot.c +24 -0
@@ -879,3 +879,27 @@ identify_siblings(struct cpuinfo_ia64 *c
 	c->core_id = info.log1_cid;
 	c->thread_id = info.log1_tid;
 }
+
+/*
+ * returns non zero, if multi-threading is enabled
+ * on at least one physical package. Due to hotplug cpu
+ * and (maxcpus=), all threads may not necessarily be enabled
+ * even though the processor supports multi-threading.
+ */
+int is_multithreading_enabled(void)
+{
+	int i, j;
+
+	for_each_present_cpu(i) {
+		for_each_present_cpu(j) {
+			if (j == i)
+				continue;
+			if ((cpu_data(j)->socket_id == cpu_data(i)->socket_id)) {
+				if (cpu_data(j)->core_id == cpu_data(i)->core_id)
+					return 1;
+			}
+		}
+	}
+	return 0;
+}
+EXPORT_SYMBOL(is_multithreading_enabled);
include/asm-ia64/smp.h +1 -0
@@ -128,6 +128,7 @@ extern void smp_send_reschedule (int cpu
 extern void lock_ipi_calllock(void);
 extern void unlock_ipi_calllock(void);
 extern void identify_siblings (struct cpuinfo_ia64 *);
+extern int is_multithreading_enabled(void);
 
 #else