linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Convert get_task_struct to return the task
@ 2019-07-04 22:13 Matthew Wilcox
  2019-07-05 11:46 ` Peter Zijlstra
  2019-07-25 16:16 ` [tip:sched/core] sched/core: Convert get_task_struct() " tip-bot for Matthew Wilcox (Oracle)
  0 siblings, 2 replies; 3+ messages in thread
From: Matthew Wilcox @ 2019-07-04 22:13 UTC (permalink / raw)
  To: linux-kernel, Thomas Gleixner, Ingo Molnar, Peter Zijlstra
  Cc: Matthew Wilcox (Oracle)

From: "Matthew Wilcox (Oracle)" <willy@infradead.org>

Returning the pointer that was passed in allows us to write
slightly more idiomatic code.  Convert a few users.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
 include/linux/sched/task.h        | 6 +++++-
 kernel/events/core.c              | 9 +++------
 kernel/irq/manage.c               | 3 +--
 kernel/locking/rtmutex.c          | 6 ++----
 kernel/locking/rwsem-xadd.c       | 3 +--
 kernel/trace/trace_sched_wakeup.c | 3 +--
 6 files changed, 13 insertions(+), 17 deletions(-)

diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h
index f1227f2c38a4..47032fe3f16c 100644
--- a/include/linux/sched/task.h
+++ b/include/linux/sched/task.h
@@ -89,7 +89,11 @@ extern void sched_exec(void);
 #define sched_exec()   {}
 #endif
 
-#define get_task_struct(tsk) do { refcount_inc(&(tsk)->usage); } while(0)
+static inline struct task_struct *get_task_struct(struct task_struct *t)
+{
+	refcount_inc(&t->usage);
+	return t;
+}
 
 extern void __put_task_struct(struct task_struct *t);
 
diff --git a/kernel/events/core.c b/kernel/events/core.c
index f85929ce13be..f8c3ec50a74b 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -4082,10 +4082,8 @@ alloc_perf_context(struct pmu *pmu, struct task_struct *task)
 		return NULL;
 
 	__perf_event_init_context(ctx);
-	if (task) {
-		ctx->task = task;
-		get_task_struct(task);
-	}
+	if (task)
+		ctx->task = get_task_struct(task);
 	ctx->pmu = pmu;
 
 	return ctx;
@@ -10324,8 +10322,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
 		 * and we cannot use the ctx information because we need the
 		 * pmu before we get a ctx.
 		 */
-		get_task_struct(task);
-		event->hw.target = task;
+		event->hw.target = get_task_struct(task);
 	}
 
 	event->clock = &local_clock;
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index 78f3ddeb7fe4..a6cc41fd562b 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -1229,8 +1229,7 @@ setup_irq_thread(struct irqaction *new, unsigned int irq, bool secondary)
 	 * the thread dies to avoid that the interrupt code
 	 * references an already freed task_struct.
 	 */
-	get_task_struct(t);
-	new->thread = t;
+	new->thread = get_task_struct(t);
 	/*
 	 * Tell the thread to set its affinity. This is
 	 * important for shared interrupt handlers as we do
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index 38fbf9fa7f1b..7ad8dd384d35 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -628,8 +628,7 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
 		}
 
 		/* [10] Grab the next task, i.e. owner of @lock */
-		task = rt_mutex_owner(lock);
-		get_task_struct(task);
+		task = get_task_struct(rt_mutex_owner(lock));
 		raw_spin_lock(&task->pi_lock);
 
 		/*
@@ -709,8 +708,7 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
 	}
 
 	/* [10] Grab the next task, i.e. the owner of @lock */
-	task = rt_mutex_owner(lock);
-	get_task_struct(task);
+	task = get_task_struct(rt_mutex_owner(lock));
 	raw_spin_lock(&task->pi_lock);
 
 	/* [11] requeue the pi waiters if necessary */
diff --git a/kernel/locking/rwsem-xadd.c b/kernel/locking/rwsem-xadd.c
index 0b1f77957240..b81ba6e93f9c 100644
--- a/kernel/locking/rwsem-xadd.c
+++ b/kernel/locking/rwsem-xadd.c
@@ -223,8 +223,7 @@ static void __rwsem_mark_wake(struct rw_semaphore *sem,
 	list_for_each_entry_safe(waiter, tmp, &wlist, list) {
 		struct task_struct *tsk;
 
-		tsk = waiter->task;
-		get_task_struct(tsk);
+		tsk = get_task_struct(waiter->task);
 
 		/*
 		 * Ensure calling get_task_struct() before setting the reader
diff --git a/kernel/trace/trace_sched_wakeup.c b/kernel/trace/trace_sched_wakeup.c
index 743b2b520d34..5e43b9664eca 100644
--- a/kernel/trace/trace_sched_wakeup.c
+++ b/kernel/trace/trace_sched_wakeup.c
@@ -579,8 +579,7 @@ probe_wakeup(void *ignore, struct task_struct *p)
 	else
 		tracing_dl = 0;
 
-	wakeup_task = p;
-	get_task_struct(wakeup_task);
+	wakeup_task = get_task_struct(p);
 
 	local_save_flags(flags);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Convert get_task_struct to return the task
  2019-07-04 22:13 [PATCH] Convert get_task_struct to return the task Matthew Wilcox
@ 2019-07-05 11:46 ` Peter Zijlstra
  2019-07-25 16:16 ` [tip:sched/core] sched/core: Convert get_task_struct() " tip-bot for Matthew Wilcox (Oracle)
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2019-07-05 11:46 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: linux-kernel, Thomas Gleixner, Ingo Molnar

On Thu, Jul 04, 2019 at 03:13:23PM -0700, Matthew Wilcox wrote:
> From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
> 
> Returning the pointer that was passed in allows us to write
> slightly more idiomatic code.  Convert a few users.
> 
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>

Sure, thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tip:sched/core] sched/core: Convert get_task_struct() to return the task
  2019-07-04 22:13 [PATCH] Convert get_task_struct to return the task Matthew Wilcox
  2019-07-05 11:46 ` Peter Zijlstra
@ 2019-07-25 16:16 ` tip-bot for Matthew Wilcox (Oracle)
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Matthew Wilcox (Oracle) @ 2019-07-25 16:16 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, peterz, torvalds, willy, hpa, mingo, tglx

Commit-ID:  7b3c92b85a65c2db1f542265bc98e1f9e3056eba
Gitweb:     https://git.kernel.org/tip/7b3c92b85a65c2db1f542265bc98e1f9e3056eba
Author:     Matthew Wilcox (Oracle) <willy@infradead.org>
AuthorDate: Thu, 4 Jul 2019 15:13:23 -0700
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 25 Jul 2019 15:51:54 +0200

sched/core: Convert get_task_struct() to return the task

Returning the pointer that was passed in allows us to write
slightly more idiomatic code.  Convert a few users.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190704221323.24290-1-willy@infradead.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 include/linux/sched/task.h        | 6 +++++-
 kernel/events/core.c              | 9 +++------
 kernel/irq/manage.c               | 3 +--
 kernel/locking/rtmutex.c          | 6 ++----
 kernel/trace/trace_sched_wakeup.c | 3 +--
 5 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h
index 0497091e40c1..3d90ed8f75f0 100644
--- a/include/linux/sched/task.h
+++ b/include/linux/sched/task.h
@@ -105,7 +105,11 @@ extern void sched_exec(void);
 #define sched_exec()   {}
 #endif
 
-#define get_task_struct(tsk) do { refcount_inc(&(tsk)->usage); } while(0)
+static inline struct task_struct *get_task_struct(struct task_struct *t)
+{
+	refcount_inc(&t->usage);
+	return t;
+}
 
 extern void __put_task_struct(struct task_struct *t);
 
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 026a14541a38..ea5e8139fe62 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -4089,10 +4089,8 @@ alloc_perf_context(struct pmu *pmu, struct task_struct *task)
 		return NULL;
 
 	__perf_event_init_context(ctx);
-	if (task) {
-		ctx->task = task;
-		get_task_struct(task);
-	}
+	if (task)
+		ctx->task = get_task_struct(task);
 	ctx->pmu = pmu;
 
 	return ctx;
@@ -10355,8 +10353,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
 		 * and we cannot use the ctx information because we need the
 		 * pmu before we get a ctx.
 		 */
-		get_task_struct(task);
-		event->hw.target = task;
+		event->hw.target = get_task_struct(task);
 	}
 
 	event->clock = &local_clock;
diff --git a/kernel/irq/manage.c b/kernel/irq/manage.c
index e8f7f179bf77..9d50fbe5531a 100644
--- a/kernel/irq/manage.c
+++ b/kernel/irq/manage.c
@@ -1255,8 +1255,7 @@ setup_irq_thread(struct irqaction *new, unsigned int irq, bool secondary)
 	 * the thread dies to avoid that the interrupt code
 	 * references an already freed task_struct.
 	 */
-	get_task_struct(t);
-	new->thread = t;
+	new->thread = get_task_struct(t);
 	/*
 	 * Tell the thread to set its affinity. This is
 	 * important for shared interrupt handlers as we do
diff --git a/kernel/locking/rtmutex.c b/kernel/locking/rtmutex.c
index fa83d36e30c6..2874bf556162 100644
--- a/kernel/locking/rtmutex.c
+++ b/kernel/locking/rtmutex.c
@@ -628,8 +628,7 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
 		}
 
 		/* [10] Grab the next task, i.e. owner of @lock */
-		task = rt_mutex_owner(lock);
-		get_task_struct(task);
+		task = get_task_struct(rt_mutex_owner(lock));
 		raw_spin_lock(&task->pi_lock);
 
 		/*
@@ -709,8 +708,7 @@ static int rt_mutex_adjust_prio_chain(struct task_struct *task,
 	}
 
 	/* [10] Grab the next task, i.e. the owner of @lock */
-	task = rt_mutex_owner(lock);
-	get_task_struct(task);
+	task = get_task_struct(rt_mutex_owner(lock));
 	raw_spin_lock(&task->pi_lock);
 
 	/* [11] requeue the pi waiters if necessary */
diff --git a/kernel/trace/trace_sched_wakeup.c b/kernel/trace/trace_sched_wakeup.c
index 743b2b520d34..5e43b9664eca 100644
--- a/kernel/trace/trace_sched_wakeup.c
+++ b/kernel/trace/trace_sched_wakeup.c
@@ -579,8 +579,7 @@ probe_wakeup(void *ignore, struct task_struct *p)
 	else
 		tracing_dl = 0;
 
-	wakeup_task = p;
-	get_task_struct(wakeup_task);
+	wakeup_task = get_task_struct(p);
 
 	local_save_flags(flags);
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-07-25 16:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-04 22:13 [PATCH] Convert get_task_struct to return the task Matthew Wilcox
2019-07-05 11:46 ` Peter Zijlstra
2019-07-25 16:16 ` [tip:sched/core] sched/core: Convert get_task_struct() " tip-bot for Matthew Wilcox (Oracle)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).