]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
seqlock: Change thread_group_cputime() to use scoped_seqlock_read()
authorOleg Nesterov <oleg@redhat.com>
Wed, 8 Oct 2025 12:30:52 +0000 (14:30 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Tue, 21 Oct 2025 10:31:57 +0000 (12:31 +0200)
To simplify the code and make it more readable.

While at it, change thread_group_cputime() to use __for_each_thread(sig).

[peterz: update to new interface]
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
kernel/sched/cputime.c

index 7097de2c8cda2096772c0515b7dab5eabb18e8d3..4f97896887ecbb9fcd3d26e06f5c775d20e3c996 100644 (file)
@@ -313,10 +313,8 @@ static u64 read_sum_exec_runtime(struct task_struct *t)
 void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times)
 {
        struct signal_struct *sig = tsk->signal;
-       u64 utime, stime;
        struct task_struct *t;
-       unsigned int seq, nextseq;
-       unsigned long flags;
+       u64 utime, stime;
 
        /*
         * Update current task runtime to account pending time since last
@@ -329,27 +327,19 @@ void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times)
        if (same_thread_group(current, tsk))
                (void) task_sched_runtime(current);
 
-       rcu_read_lock();
-       /* Attempt a lockless read on the first round. */
-       nextseq = 0;
-       do {
-               seq = nextseq;
-               flags = read_seqbegin_or_lock_irqsave(&sig->stats_lock, &seq);
+       guard(rcu)();
+       scoped_seqlock_read (&sig->stats_lock, ss_lock_irqsave) {
                times->utime = sig->utime;
                times->stime = sig->stime;
                times->sum_exec_runtime = sig->sum_sched_runtime;
 
-               for_each_thread(tsk, t) {
+               __for_each_thread(sig, t) {
                        task_cputime(t, &utime, &stime);
                        times->utime += utime;
                        times->stime += stime;
                        times->sum_exec_runtime += read_sum_exec_runtime(t);
                }
-               /* If lockless access failed, take the lock. */
-               nextseq = 1;
-       } while (need_seqretry(&sig->stats_lock, seq));
-       done_seqretry_irqrestore(&sig->stats_lock, seq, flags);
-       rcu_read_unlock();
+       }
 }
 
 #ifdef CONFIG_IRQ_TIME_ACCOUNTING