lkml.org 
[lkml]   [2009]   [Nov]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: utime/stime decreasing on thread exit
    Sorry, forgot to cc Stanislaw...

    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.



    \
     
     \ /
      Last update: 2009-11-09 18:35    [W:4.095 / U:0.168 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site