Skip to contentSkip to conversation

x86, perf,cqm: handle CPU hotplug

PATCH In review Kanaka Juvva 4 participants 5 messages Jun 18, 2015 – Jun 23, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 x86, perf,cqm: handle CPU hotplug

Added lock in event reader function. The cqm_pick_event_reader() function accesses cqm_cpumask and it is critical section between this and cqm_stable().

This situation is true when a CPU is hotplugged. Mutex is used to protect the critical section.

---
 arch/x86/kernel/cpu/perf_event_intel_cqm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/perf_event_intel_cqm.c +4 -1
index 1880761..e17e37f 100644
@@ -1239,12 +1239,15 @@ static inline void cqm_pick_event_reader(int cpu)
 	int phys_id = topology_physical_package_id(cpu);
 	int i;
 
+	mutex_lock(&cache_mutex);
 	for_each_cpu(i, &cqm_cpumask) {
 		if (phys_id == topology_physical_package_id(i))
-			return;	/* already got reader for this socket */
+			goto out; /* already got reader for this socket */
 	}
 
 	cpumask_set_cpu(cpu, &cqm_cpumask);
+out:
+	mutex_unlock(&cache_mutex);
 }
 
 static void intel_cqm_cpu_prepare(unsigned int cpu)
Signature · 1 line
2.1.0
#1 lore raw
Quoted 17 lines · Kanaka Juvva

Added lock in event reader function. The cqm_pick_event_reader() function accesses cqm_cpumask and it is critical section between this and cqm_stable().

This situation is true when a CPU is hotplugged. Mutex is used to protect the critical section.

---
 arch/x86/kernel/cpu/perf_event_intel_cqm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/perf_event_intel_cqm.c +0 -0
index 1880761..e17e37f 100644

arch/x86/kernel/cpu/perf_event_intel_cqm.c static inline void cqm_pick_event_reader(int cpu) · line 1242

Quoted 4 lines
arch/x86/kernel/cpu/perf_event_intel_cqm.c +1 -0
@@ -1239,12 +1239,15 @@ static inline void cqm_pick_event_reader(int cpu)
 	int phys_id = topology_physical_package_id(cpu);
 	int i;
 
+	mutex_lock(&cache_mutex);

I already explained it to Vikas. You CANNOT take a mutex in that code path as it runs with interrupts disabled on a CPU which cannot schedule.

Sigh.

tglx

maintainer
#2 lore raw
Quoted 8 lines · Thomas Gleixner
Quoted 5 lines

arch/x86/kernel/cpu/perf_event_intel_cqm.c static inline void cqm_pick_event_reader(int cpu) · line 1242

Quoted 5 lines
arch/x86/kernel/cpu/perf_event_intel_cqm.c +1 -0
@@ -1239,12 +1239,15 @@ static inline void cqm_pick_event_reader(int cpu)
 	int phys_id = topology_physical_package_id(cpu);
 	int i;
 
+	mutex_lock(&cache_mutex);

I already explained it to Vikas. You CANNOT take a mutex in that code path as it runs with interrupts disabled on a CPU which cannot schedule.

How did lockdep not blow up and scream about this?

#3 lore raw
Quoted 11 lines · Dave Hansen
Quoted 8 lines · Thomas Gleixner
Quoted 5 lines

arch/x86/kernel/cpu/perf_event_intel_cqm.c static inline void cqm_pick_event_reader(int cpu) · line 1242

Quoted 5 lines
arch/x86/kernel/cpu/perf_event_intel_cqm.c +1 -0
@@ -1239,12 +1239,15 @@ static inline void cqm_pick_event_reader(int cpu)
 	int phys_id = topology_physical_package_id(cpu);
 	int i;
 
+	mutex_lock(&cache_mutex);

I already explained it to Vikas. You CANNOT take a mutex in that code path as it runs with interrupts disabled on a CPU which cannot schedule.

How did lockdep not blow up and scream about this?

Dunno. I did not test that stuff.

The might_sleep() in mutex_lock() should catch it as well, IF that code was ever executed AFTER boot on a running system.

Thanks,

tglx

#4 lore raw
In reply to Thomas Gleixner
Quoted 22 lines · Thomas Gleixner
Quoted 20 lines · Kanaka Juvva

Added lock in event reader function. The cqm_pick_event_reader() function accesses cqm_cpumask and it is critical section between this and cqm_stable().

This situation is true when a CPU is hotplugged. Mutex is used to protect the critical section.

---
 arch/x86/kernel/cpu/perf_event_intel_cqm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/kernel/cpu/perf_event_intel_cqm.c +0 -0
index 1880761..e17e37f 100644
@@ -1239,12 +1239,15 @@ static inline void cqm_pick_event_reader(int cpu)
 	int phys_id = topology_physical_package_id(cpu);
 	int i;
 
Quoted 5 lines

arch/x86/kernel/cpu/perf_event_intel_cqm.c static inline void cqm_pick_event_reader(int cpu) · line 1242

Quoted 1 line
arch/x86/kernel/cpu/perf_event_intel_cqm.c +1 -0
+	mutex_lock(&cache_mutex);

I already explained it to Vikas. You CANNOT take a mutex in that code path as it runs with interrupts disabled on a CPU which cannot schedule.

This patch also needs to be merged with the new package mask changes that was added. Will merge and send the fix.

Thanks,
Vikas

Quoted 5 lines

Sigh.

tglx