The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] Make RCU task_struct safe for oprofile
@ 2005-11-26 21:07 Paul E. McKenney
  2005-11-27 12:28 ` Ingo Molnar
  0 siblings, 1 reply; 2+ messages in thread
From: Paul E. McKenney @ 2005-11-26 21:07 UTC (permalink / raw)
  To: akpm, mingo; +Cc: linux-kernel, wfg, levon

Hello!

Applying RCU to the task structure broke oprofile, because
free_task_notify() can now be called from softirq.  This means that the
task_mortuary lock must be acquired with irq disabled in order to avoid
intermittent self-deadlock.  Since irq is now disabled, the critical
section within process_task_mortuary() has been restructured to be O(1) in
order to maximize scalability and minimize realtime latency degradation.

Kudos to Wu Fengguang for finding this problem!

CC: <wfg@mail.ustc.edu.cn>
CC: <levon@movementarian.org>
Signed-off-by: <paulmck@us.ibm.com>

---

 buffer_sync.c |   30 +++++++++++++++---------------
 1 files changed, 15 insertions(+), 15 deletions(-)

diff -urpNa -X dontdiff linux-2.6.14-mm2/drivers/oprofile/buffer_sync.c linux-2.6.14-mm2-fixmortuary/drivers/oprofile/buffer_sync.c
--- linux-2.6.14-mm2/drivers/oprofile/buffer_sync.c	2005-10-27 17:02:08.000000000 -0700
+++ linux-2.6.14-mm2-fixmortuary/drivers/oprofile/buffer_sync.c	2005-11-26 07:51:08.000000000 -0800
@@ -43,13 +43,16 @@ static void process_task_mortuary(void);
  * list for processing. Only after two full buffer syncs
  * does the task eventually get freed, because by then
  * we are sure we will not reference it again.
+ * Can be invoked from softirq via RCU callback due to
+ * call_rcu() of the task struct, hence the _irqsave.
  */
 static int task_free_notify(struct notifier_block * self, unsigned long val, void * data)
 {
+	unsigned long flags;
 	struct task_struct * task = data;
-	spin_lock(&task_mortuary);
+	spin_lock_irqsave(&task_mortuary, flags);
 	list_add(&task->tasks, &dying_tasks);
-	spin_unlock(&task_mortuary);
+	spin_unlock_irqrestore(&task_mortuary, flags);
 	return NOTIFY_OK;
 }
 
@@ -431,25 +434,22 @@ static void increment_tail(struct oprofi
  */
 static void process_task_mortuary(void)
 {
-	struct list_head * pos;
-	struct list_head * pos2;
+	unsigned long flags;
+	LIST_HEAD(local_dead_tasks);
 	struct task_struct * task;
+	struct task_struct * ttask;
 
-	spin_lock(&task_mortuary);
+	spin_lock_irqsave(&task_mortuary, flags);
 
-	list_for_each_safe(pos, pos2, &dead_tasks) {
-		task = list_entry(pos, struct task_struct, tasks);
-		list_del(&task->tasks);
-		free_task(task);
-	}
+	list_splice_init(&dead_tasks, &local_dead_tasks);
+	list_splice_init(&dying_tasks, &dead_tasks);
 
-	list_for_each_safe(pos, pos2, &dying_tasks) {
-		task = list_entry(pos, struct task_struct, tasks);
+	spin_unlock_irqrestore(&task_mortuary, flags);
+
+	list_for_each_entry_safe(task, ttask, &local_dead_tasks, tasks) {
 		list_del(&task->tasks);
-		list_add_tail(&task->tasks, &dead_tasks);
+		free_task(task);
 	}
-
-	spin_unlock(&task_mortuary);
 }
 
 

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

* Re: [PATCH] Make RCU task_struct safe for oprofile
  2005-11-26 21:07 [PATCH] Make RCU task_struct safe for oprofile Paul E. McKenney
@ 2005-11-27 12:28 ` Ingo Molnar
  0 siblings, 0 replies; 2+ messages in thread
From: Ingo Molnar @ 2005-11-27 12:28 UTC (permalink / raw)
  To: Paul E. McKenney; +Cc: akpm, linux-kernel, wfg, levon


* Paul E. McKenney <paulmck@us.ibm.com> wrote:

> Hello!
> 
> Applying RCU to the task structure broke oprofile, because 
> free_task_notify() can now be called from softirq.  This means that 
> the task_mortuary lock must be acquired with irq disabled in order to 
> avoid intermittent self-deadlock.  Since irq is now disabled, the 
> critical section within process_task_mortuary() has been restructured 
> to be O(1) in order to maximize scalability and minimize realtime 
> latency degradation.
> 
> Kudos to Wu Fengguang for finding this problem!

thanks, i applied this to the -rt tree.

	Ingo

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

end of thread, other threads:[~2005-11-27 12:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-26 21:07 [PATCH] Make RCU task_struct safe for oprofile Paul E. McKenney
2005-11-27 12:28 ` Ingo Molnar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox