Re: [PATCH RFC] time: drop do_sys_times spinlock
From: Peter Zijlstra
Date: Wed Aug 13 2014 - 13:41:09 EST
On Wed, Aug 13, 2014 at 07:22:30PM +0200, Oleg Nesterov wrote:
> On 08/12, Rik van Riel wrote:
> >
> > Any other ideas?
>
> To simplify, lets suppose that we only need sum_exec_runtime.
>
> Perhaps we can do something like this
>
> u64 thread_group_sched_runtime(void)
> {
> struct task_struct *tsk = current;
> spinlock_t *siglock = &tsk->sighand->siglock; /* stable */
> struct task_struct *t;
> u64 x1, x2;
>
> retry:
> x1 = tsk->signal->sum_sched_runtime;
> rmb();
> spin_unlock_wait(siglock);
> rmb();
>
> x2 = 0;
> rcu_read_lock();
> for_each_thread(tsk, t)
> x2 += task_sched_runtime(t);
> rcu_read_unlock();
>
> rmb();
> spin_unlock_wait(siglock);
> rmb();
>
> if (x1 != tsk->signal->sum_sched_runtime)
> goto retry;
>
> return x1 + x2;
> }
>
> ?
>
> We do not care if for_each_thread() misses the new thread, we can pretend
> thread_group_sched_runtime() was called before clone.
>
> We do not care if a thread with sum_sched_runtime == 0 exits, obviously.
>
> Otherwise "x1 != tsk->signal->sum_sched_runtime" should tell us that we
> raced with __exit_signal().
So the problem with the above is the lack of fwd progress; if there's
enough clone()/exit() happening in the thread group (and the more CPUs
the more possible), we'll keep repeating.
Attachment:
pgpPHmxr2H1Ok.pgp
Description: PGP signature