All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC,PATCH 2/2] cputimers/proc: do_task_stat()->thread_group_times() is racy and O(n) under ->siglock
@ 2010-03-24 20:45 Oleg Nesterov
  2010-03-24 20:54 ` Peter Zijlstra
  0 siblings, 1 reply; 5+ messages in thread
From: Oleg Nesterov @ 2010-03-24 20:45 UTC (permalink / raw)
  To: Andrew Morton, Americo Wang, Balbir Singh, Eric W. Biederman,
	Hidetoshi Seto, Ingo Molnar, Peter Zijlstra, Roland McGrath,
	Spencer Candland, Stanislaw Gruszka
  Cc: linux-kernel

Nowadays ->siglock is overloaded, it would be really nice to change
do_task_stat() to walk through the list of threads lockless. And note
that we are doing while_each_thread() twice!

while_each_thread() is rcu-safe, but thread_group_times() also needs
->siglock to serialize the modifications of signal_struct->prev_Xtime
members.

(however, please note that currently do_task_stat() can race with
 wait_task_zombie() which calls thread_group_times() without siglock).

This patch changes the code back to use thread_group_cputime(), as we
did before 0cf55e1e "sched, cputime: Introduce thread_group_times()".

Of course, this makes the output from /proc/pid/stat less accurate, but
otoh this allows us to make do_task_stat() (apart from ->tty bits).

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---

 fs/proc/array.c |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

--- 34-rc1/fs/proc/array.c~PROC_5_DTS_TGTS_IS_PITA	2010-03-24 20:47:19.000000000 +0100
+++ 34-rc1/fs/proc/array.c	2010-03-24 20:47:51.000000000 +0100
@@ -403,6 +403,7 @@ static int do_task_stat(struct seq_file 
 
 	if (lock_task_sighand(task, &flags)) {
 		struct signal_struct *sig = task->signal;
+		struct task_cputime cputime;
 
 		if (sig->tty) {
 			struct pid *pgrp = tty_get_pgrp(sig->tty);
@@ -433,8 +434,11 @@ static int do_task_stat(struct seq_file 
 
 			min_flt += sig->min_flt;
 			maj_flt += sig->maj_flt;
-			thread_group_times(task, &utime, &stime);
+
 			gtime = cputime_add(gtime, sig->gtime);
+			thread_group_cputime(task, &cputime);
+			utime = cputime.utime;
+			stime = cputime.stime;
 		}
 
 		sid = task_session_nr_ns(task, ns);


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

end of thread, other threads:[~2010-03-26  8:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-24 20:45 [RFC,PATCH 2/2] cputimers/proc: do_task_stat()->thread_group_times() is racy and O(n) under ->siglock Oleg Nesterov
2010-03-24 20:54 ` Peter Zijlstra
2010-03-25 12:12   ` Oleg Nesterov
2010-03-25 12:19     ` Peter Zijlstra
2010-03-26  7:59     ` Stanislaw Gruszka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.