Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1700719

[PATCH v2 2/4] jump_label: Split out code under the hotplug lock

From Marc Zyngier <marc.zyngier@arm.com>
Newsgroups linux.kernel
Subject [PATCH v2 2/4] jump_label: Split out code under the hotplug lock
Date 2017-08-01 10:10 +0200
Message-ID <u9ApB-HZ-9@gated-at.bofh.it> (permalink)
References <u9ApA-HZ-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


In order to later introduce an "already locked" version of some
of the static key funcions, let's split the code into the core stuff
(the *_cpuslocked functions) and the usual helpers, which now
take/release the hotplug lock and call into the _cpuslocked
versions.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
---
 kernel/jump_label.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/kernel/jump_label.c b/kernel/jump_label.c
index f11b10091100..0ab8b35daa54 100644
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -101,11 +101,10 @@ void static_key_disable(struct static_key *key)
 }
 EXPORT_SYMBOL_GPL(static_key_disable);
 
-void static_key_slow_inc(struct static_key *key)
+static void static_key_slow_inc_cpuslocked(struct static_key *key)
 {
 	int v, v1;
 
-	cpus_read_lock();
 	STATIC_KEY_CHECK_USE();
 
 	/*
@@ -122,10 +121,8 @@ void static_key_slow_inc(struct static_key *key)
 	 */
 	for (v = atomic_read(&key->enabled); v > 0; v = v1) {
 		v1 = atomic_cmpxchg(&key->enabled, v, v + 1);
-		if (likely(v1 == v)) {
-			cpus_read_unlock();
+		if (likely(v1 == v))
 			return;
-		}
 	}
 
 	jump_label_lock();
@@ -137,14 +134,20 @@ void static_key_slow_inc(struct static_key *key)
 		atomic_inc(&key->enabled);
 	}
 	jump_label_unlock();
+}
+
+void static_key_slow_inc(struct static_key *key)
+{
+	cpus_read_lock();
+	static_key_slow_inc_cpuslocked(key);
 	cpus_read_unlock();
 }
 EXPORT_SYMBOL_GPL(static_key_slow_inc);
 
-static void __static_key_slow_dec(struct static_key *key,
-		unsigned long rate_limit, struct delayed_work *work)
+static void static_key_slow_dec_cpuslocked(struct static_key *key,
+					   unsigned long rate_limit,
+					   struct delayed_work *work)
 {
-	cpus_read_lock();
 	/*
 	 * The negative count check is valid even when a negative
 	 * key->enabled is in use by static_key_slow_inc(); a
@@ -155,7 +158,6 @@ static void __static_key_slow_dec(struct static_key *key,
 	if (!atomic_dec_and_mutex_lock(&key->enabled, &jump_label_mutex)) {
 		WARN(atomic_read(&key->enabled) < 0,
 		     "jump label: negative count!\n");
-		cpus_read_unlock();
 		return;
 	}
 
@@ -166,6 +168,14 @@ static void __static_key_slow_dec(struct static_key *key,
 		jump_label_update(key);
 	}
 	jump_label_unlock();
+}
+
+static void __static_key_slow_dec(struct static_key *key,
+				  unsigned long rate_limit,
+				  struct delayed_work *work)
+{
+	cpus_read_lock();
+	static_key_slow_dec_cpuslocked(key, rate_limit, work);
 	cpus_read_unlock();
 }
 
-- 
2.11.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 0/4] Working around CPU hotplug and static keys locking Marc Zyngier <marc.zyngier@arm.com> - 2017-08-01 10:10 +0200
  [PATCH v2 2/4] jump_label: Split out code under the hotplug lock Marc Zyngier <marc.zyngier@arm.com> - 2017-08-01 10:10 +0200
    [tip:locking/core] jump_label: Split out code under the hotplug  lock tip-bot for Marc Zyngier <tipbot@zytor.com> - 2017-08-10 14:20 +0200
  [PATCH v2 3/4] jump_label: Provide hotplug context variants Marc Zyngier <marc.zyngier@arm.com> - 2017-08-01 10:10 +0200
    Re: [PATCH v2 3/4] jump_label: Provide hotplug context variants Peter Zijlstra <peterz@infradead.org> - 2017-08-02 16:40 +0200
      Re: [PATCH v2 3/4] jump_label: Provide hotplug context variants Marc Zyngier <marc.zyngier@arm.com> - 2017-08-02 17:10 +0200
    [tip:locking/core] jump_label: Provide hotplug context variants tip-bot for Marc Zyngier <tipbot@zytor.com> - 2017-08-10 14:20 +0200
  [PATCH v2 4/4] clocksource/arm_arch_timer: Use static_branch_enable_cpuslocked() Marc Zyngier <marc.zyngier@arm.com> - 2017-08-01 10:10 +0200
    [tip:locking/core] clocksource/arm_arch_timer: Use  static_branch_enable_cpuslocked() tip-bot for Marc Zyngier <tipbot@zytor.com> - 2017-08-10 14:20 +0200

csiph-web