[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20091109172020.GA7751@redhat.com>
Date: Mon, 9 Nov 2009 18:20:20 +0100
From: Oleg Nesterov <oleg@...hat.com>
To: Peter Zijlstra <peterz@...radead.org>
Cc: Hidetoshi Seto <seto.hidetoshi@...fujitsu.com>,
Spencer Candland <spencer@...ehost.com>,
linux-kernel@...r.kernel.org, Ingo Molnar <mingo@...e.hu>
Subject: Re: utime/stime decreasing on thread exit
On 11/09, Peter Zijlstra wrote:
>
> On Thu, 2009-11-05 at 14:24 +0900, Hidetoshi Seto wrote:
>
> > Problem [1]:
> > thread_group_cputime() vs exit
> >
> > +void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times)
> > +{
> > + struct sighand_struct *sighand;
> > + struct signal_struct *sig;
> > + struct task_struct *t;
> > +
> > + *times = INIT_CPUTIME;
> > +
> > + rcu_read_lock();
> > + sighand = rcu_dereference(tsk->sighand);
> > + if (!sighand)
> > + goto out;
> > +
> > + sig = tsk->signal;
> > +
> > + t = tsk;
> > + do {
> > + times->utime = cputime_add(times->utime, t->utime);
> > + times->stime = cputime_add(times->stime, t->stime);
> > + times->sum_exec_runtime += t->se.sum_exec_runtime;
> > +
> > + t = next_thread(t);
> > + } while (t != tsk);
> > +
> > + times->utime = cputime_add(times->utime, sig->utime);
> > + times->stime = cputime_add(times->stime, sig->stime);
> > + times->sum_exec_runtime += sig->sum_sched_runtime;
> > +out:
> > + rcu_read_unlock();
> > +}
> >
> > If one of (thousands) threads do exit while a thread is doing do-while
> > above, the s/utime of exited thread can be accounted twice, at do-while
> > (before exit) and at cputime_add() at last (after exit).
> >
> > I suppose this is hard to fix: Taking lock on signal would solve this
> > problem, but it could block all other threads long and cause serious
> > performance issue and so on...
>
> I just checked .22 and there we seem to hold p->sighand->siglock over
> the full task iteration.
Yes. Then thread_group_cputime() was changed so that it didn't itearate
over sub-threads, then this callsite was move outside of ->siglock, now
it does while_each_thread() again.
> So we might as well revert back to that if
> people really mind counting things twice :-)
Stanislaw has already sent the patch, but I don't know what happened
with this patch:
[PATCH 1/2] posix-cpu-timers: avoid do_sys_times() races with __exit_signal()
http://marc.info/?l=linux-kernel&m=124505545131145
Oleg.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists