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


Groups > linux.kernel > #1494288

[PATCH v3 04/13] futex: Consolidate pure pi_state_list add & delete codes to helpers

From Waiman Long <Waiman.Long@hpe.com>
Newsgroups linux.kernel
Subject [PATCH v3 04/13] futex: Consolidate pure pi_state_list add & delete codes to helpers
Date 2016-09-30 23:40 +0200
Message-ID <sndHb-7ss-3@gated-at.bofh.it> (permalink)
References <sndxv-7oR-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Two new helper functions (task_pi_list_add & task_pi_list_del)
are created to consolidate all the pure pi_state_list addition and
insertion codes. The set_owner argument in task_pi_list_add() will
be needed in a later patch.

Signed-off-by: Waiman Long <Waiman.Long@hpe.com>
---
 kernel/futex.c |   67 +++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 42 insertions(+), 25 deletions(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index ebe59fa..0d1b1be 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -813,6 +813,42 @@ static inline int get_futex_value(u32 *dest, u32 __user *from)
 /*
  * PI code:
  */
+
+/**
+ * task_pi_list_add - add futex state object to a task's pi_state_list
+ * @task :	task structure
+ * @state:	futex state object
+ * @set_owner:	set futex state owner to the given task if true
+ */
+static inline void task_pi_list_add(struct task_struct *task,
+				    struct futex_state *state,
+				    const bool set_owner)
+{
+	raw_spin_lock_irq(&task->pi_lock);
+	WARN_ON(!list_empty(&state->list));
+	list_add(&state->list, &task->pi_state_list);
+	if (set_owner)
+		state->owner = task;
+	raw_spin_unlock_irq(&task->pi_lock);
+}
+
+/**
+ * task_pi_list_del - delete futex state object from a task's pi_state_list
+ * @task : task structure
+ * @state: futex state object
+ * @warn : warn if list is empty when set
+ */
+static inline void task_pi_list_del(struct task_struct *task,
+				    struct futex_state *state,
+				    const bool warn)
+{
+	raw_spin_lock_irq(&task->pi_lock);
+	if (warn)
+		WARN_ON(list_empty(&state->list));
+	list_del_init(&state->list);
+	raw_spin_unlock_irq(&task->pi_lock);
+}
+
 static int refill_futex_state_cache(void)
 {
 	struct futex_state *state;
@@ -865,9 +901,7 @@ static void put_futex_state(struct futex_state *state)
 	 * and has cleaned up the futex state already
 	 */
 	if (state->owner) {
-		raw_spin_lock_irq(&state->owner->pi_lock);
-		list_del_init(&state->list);
-		raw_spin_unlock_irq(&state->owner->pi_lock);
+		task_pi_list_del(state->owner, state, false);
 
 		rt_mutex_proxy_unlock(&state->pi_mutex, state->owner);
 	}
@@ -1388,16 +1422,8 @@ static int wake_futex_pi(u32 __user *uaddr, u32 uval, struct futex_q *this,
 		return ret;
 	}
 
-	raw_spin_lock(&pi_state->owner->pi_lock);
-	WARN_ON(list_empty(&pi_state->list));
-	list_del_init(&pi_state->list);
-	raw_spin_unlock(&pi_state->owner->pi_lock);
-
-	raw_spin_lock(&new_owner->pi_lock);
-	WARN_ON(!list_empty(&pi_state->list));
-	list_add(&pi_state->list, &new_owner->pi_state_list);
-	pi_state->owner = new_owner;
-	raw_spin_unlock(&new_owner->pi_lock);
+	task_pi_list_del(pi_state->owner, pi_state, true);
+	task_pi_list_add(new_owner, pi_state, true);
 
 	raw_spin_unlock_irq(&pi_state->pi_mutex.wait_lock);
 
@@ -2202,19 +2228,10 @@ retry:
 	 * We fixed up user space. Now we need to fix the pi_state
 	 * itself.
 	 */
-	if (pi_state->owner != NULL) {
-		raw_spin_lock_irq(&pi_state->owner->pi_lock);
-		WARN_ON(list_empty(&pi_state->list));
-		list_del_init(&pi_state->list);
-		raw_spin_unlock_irq(&pi_state->owner->pi_lock);
-	}
+	if (pi_state->owner != NULL)
+		task_pi_list_del(pi_state->owner, pi_state, true);
 
-	pi_state->owner = newowner;
-
-	raw_spin_lock_irq(&newowner->pi_lock);
-	WARN_ON(!list_empty(&pi_state->list));
-	list_add(&pi_state->list, &newowner->pi_state_list);
-	raw_spin_unlock_irq(&newowner->pi_lock);
+	task_pi_list_add(newowner, pi_state, true);
 	return 0;
 
 	/*
-- 
1.7.1

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


Thread

[PATCH v3 00/13] futex: Introducing throughput-optimized futexes Waiman Long <Waiman.Long@hpe.com> - 2016-09-30 23:30 +0200
  [PATCH v3 02/13] futex: Rename futex_pi_state to futex_state Waiman Long <Waiman.Long@hpe.com> - 2016-09-30 23:30 +0200
  [PATCH v3 13/13] perf bench: New microbenchmark for userspace mutex performance Waiman Long <Waiman.Long@hpe.com> - 2016-09-30 23:30 +0200
  [PATCH v3 04/13] futex: Consolidate pure pi_state_list add & delete codes to helpers Waiman Long <Waiman.Long@hpe.com> - 2016-09-30 23:40 +0200
  [PATCH v3 06/13] futex: Allow direct attachment of futex_state objects to hash bucket Waiman Long <Waiman.Long@hpe.com> - 2016-09-30 23:40 +0200
  [PATCH v3 07/13] futex: Throughput-optimized (TP) futexes Waiman Long <Waiman.Long@hpe.com> - 2016-09-30 23:40 +0200
    Re: [PATCH v3 07/13] futex: Throughput-optimized (TP) futexes Thomas Gleixner <tglx@linutronix.de> - 2016-10-01 09:00 +0200
  [PATCH v3 10/13] futex: Inform FUTEX_LOCK callers on how the lock is acquired Waiman Long <Waiman.Long@hpe.com> - 2016-09-30 23:40 +0200
  [PATCH v3 11/13] futex: Add timeout support to TP futexes Waiman Long <Waiman.Long@hpe.com> - 2016-09-30 23:40 +0200
  [PATCH v3 05/13] futex: Add a new futex type field into futex_state Waiman Long <Waiman.Long@hpe.com> - 2016-09-30 23:40 +0200
  [PATCH v3 08/13] futex: Enable robust handling of TP futexes Waiman Long <Waiman.Long@hpe.com> - 2016-09-30 23:40 +0200

csiph-web