Skip to contentSkip to conversation

x86: avoid tlbstate lock if no enough cpus

PATCH In review Shaohua Li 1 participant 2 messages Jan 17, 2011 – Feb 14, 2011

Subsystems (2)
lore
Share & tools
lore

Shaohua Li

author
#0 lore raw

PATCH 4/4 x86: avoid tlbstate lock if no enough cpus

This one isn't related to previous patch. If online cpus are below NUM_INVALIDATE_TLB_VECTORS, we don't need the lock. The comments in the code declares we don't need the check, but a hot lock still needs an atomic operation and expensive, so add the check here.

Uses nr_cpu_ids here as suggested by Eric Dumazet.

---
 arch/x86/mm/tlb.c |   11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
arch/x86/mm/tlb.c +4 -7
Index: linux/arch/x86/mm/tlb.c
===================================================================
@@ -179,12 +179,8 @@ static void flush_tlb_others_ipi(const s
 	sender = this_cpu_read(tlb_vector_offset);
 	f = &flush_state[sender];
 
-	/*
-	 * Could avoid this lock when
-	 * num_online_cpus() <= NUM_INVALIDATE_TLB_VECTORS, but it is
-	 * probably not worth checking this for a cache-hot lock.
-	 */
-	raw_spin_lock(&f->tlbstate_lock);
+	if (nr_cpu_ids > NUM_INVALIDATE_TLB_VECTORS)
+		raw_spin_lock(&f->tlbstate_lock);
 
 	f->flush_mm = mm;
 	f->flush_va = va;
@@ -202,7 +198,8 @@ static void flush_tlb_others_ipi(const s
 
 	f->flush_mm = NULL;
 	f->flush_va = 0;
-	raw_spin_unlock(&f->tlbstate_lock);
+	if (nr_cpu_ids > NUM_INVALIDATE_TLB_VECTORS)
+		raw_spin_unlock(&f->tlbstate_lock);
 }
 
 void native_flush_tlb_others(const struct cpumask *cpumask,
#1 lore raw

[tip:x86/mm] x86: Avoid tlbstate lock if not enough cpus

Commit-ID:  7064d865af804b9b841e7b9a3e9b653e40c3e5ca
Gitweb:     http://git.kernel.org/tip/7064d865af804b9b841e7b9a3e9b653e40c3e5ca
Author:     Shaohua Li <[email protected]>
AuthorDate: Mon, 17 Jan 2011 10:52:10 +0800
Committer:  Ingo Molnar <[email protected]>
CommitDate: Mon, 14 Feb 2011 13:03:08 +0100

x86: Avoid tlbstate lock if not enough cpus

This one isn't related to previous patch. If online cpus are below NUM_INVALIDATE_TLB_VECTORS, we don't need the lock. The comments in the code declares we don't need the check, but a hot lock still needs an atomic operation and expensive, so add the check here.

Uses nr_cpu_ids here as suggested by Eric Dumazet.

LKML-Reference: <1295232730.1949.710.camel@sli10-conroe>

---
 arch/x86/mm/tlb.c |   11 ++++-------
 1 files changed, 4 insertions(+), 7 deletions(-)
arch/x86/mm/tlb.c +4 -7
index 6acc724..55272d7 100644
@@ -179,12 +179,8 @@ static void flush_tlb_others_ipi(const struct cpumask *cpumask,
 	sender = this_cpu_read(tlb_vector_offset);
 	f = &flush_state[sender];
 
-	/*
-	 * Could avoid this lock when
-	 * num_online_cpus() <= NUM_INVALIDATE_TLB_VECTORS, but it is
-	 * probably not worth checking this for a cache-hot lock.
-	 */
-	raw_spin_lock(&f->tlbstate_lock);
+	if (nr_cpu_ids > NUM_INVALIDATE_TLB_VECTORS)
+		raw_spin_lock(&f->tlbstate_lock);
 
 	f->flush_mm = mm;
 	f->flush_va = va;
@@ -202,7 +198,8 @@ static void flush_tlb_others_ipi(const struct cpumask *cpumask,
 
 	f->flush_mm = NULL;
 	f->flush_va = 0;
-	raw_spin_unlock(&f->tlbstate_lock);
+	if (nr_cpu_ids > NUM_INVALIDATE_TLB_VECTORS)
+		raw_spin_unlock(&f->tlbstate_lock);
 }
 
 void native_flush_tlb_others(const struct cpumask *cpumask,