Skip to content

Commit 488f48b

Browse files
oleg-nesterovPeter Zijlstra
authored andcommitted
seqlock: Change thread_group_cputime() to use scoped_seqlock_read()
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>
1 parent cc39f38 commit 488f48b

1 file changed

Lines changed: 5 additions & 15 deletions

File tree

kernel/sched/cputime.c

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,8 @@ static u64 read_sum_exec_runtime(struct task_struct *t)
313313
void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times)
314314
{
315315
struct signal_struct *sig = tsk->signal;
316-
u64 utime, stime;
317316
struct task_struct *t;
318-
unsigned int seq, nextseq;
319-
unsigned long flags;
317+
u64 utime, stime;
320318

321319
/*
322320
* 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)
329327
if (same_thread_group(current, tsk))
330328
(void) task_sched_runtime(current);
331329

332-
rcu_read_lock();
333-
/* Attempt a lockless read on the first round. */
334-
nextseq = 0;
335-
do {
336-
seq = nextseq;
337-
flags = read_seqbegin_or_lock_irqsave(&sig->stats_lock, &seq);
330+
guard(rcu)();
331+
scoped_seqlock_read (&sig->stats_lock, ss_lock_irqsave) {
338332
times->utime = sig->utime;
339333
times->stime = sig->stime;
340334
times->sum_exec_runtime = sig->sum_sched_runtime;
341335

342-
for_each_thread(tsk, t) {
336+
__for_each_thread(sig, t) {
343337
task_cputime(t, &utime, &stime);
344338
times->utime += utime;
345339
times->stime += stime;
346340
times->sum_exec_runtime += read_sum_exec_runtime(t);
347341
}
348-
/* If lockless access failed, take the lock. */
349-
nextseq = 1;
350-
} while (need_seqretry(&sig->stats_lock, seq));
351-
done_seqretry_irqrestore(&sig->stats_lock, seq, flags);
352-
rcu_read_unlock();
342+
}
353343
}
354344

355345
#ifdef CONFIG_IRQ_TIME_ACCOUNTING

0 commit comments

Comments
 (0)