Re: [PATCH RFC] time,signal: protect resource use statistics with seqlock

Oleg Nesterov
2014-08-15T16:52:25Z

On 08/15, Oleg Nesterov wrote:
>
> However, if we only want to make sys_times() more scalable(), then
> perhaps the "lockless" version of thread_group_cputime() makes more
> sense. And given that do_sys_times() uses current we can simplify it;
> is_dead is not possible and we do not need to take ->siglock twice:
>
> void current_group_cputime(struct task_cputime *times)
> {
> struct task_struct *tsk = current, *t;
> struct spinlock_t *siglock = &tsk->sighand->siglock;
> struct signal_struct *sig = tsk->signal;
> bool lockless = true;
> u64 exec;
>
> retry:
> spin_lock_irq(siglock);
> times->utime = sig->utime;
> times->stime = sig->stime;
> times->sum_exec_runtime = exec = sig->sum_sched_runtime;
>
> if (lockless)
> spin_unlock_irq(siglock);
>
> rcu_read_lock();
> for_each_thread(tsk, t) {
> cputime_t utime, stime;
> task_cputime(t, &utime, &stime);
> times->utime += utime;
> times->stime += stime;
> times->sum_exec_runtime += task_sched_runtime(t);
> }
> rcu_read_unlock();
>
> if (lockless) {
> lockless = false;
> spin_unlock_wait(siglock);
> smp_rmb();
> if (exec != sig->sum_sched_runtime)
> goto retry;
> } else {
> spin_unlock_irq(siglock);
> }
> }

Just in case... Yes, sure, "seqlock_t stats_lock" is more scalable. Just
I do not know it's worth the trouble.

Oleg.