Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Oleg Nesterov and committed by
Peter Zijlstra
488f48b3 cc39f387

+5 -15
+5 -15
kernel/sched/cputime.c
··· 313 313 void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times) 314 314 { 315 315 struct signal_struct *sig = tsk->signal; 316 - u64 utime, stime; 317 316 struct task_struct *t; 318 - unsigned int seq, nextseq; 319 - unsigned long flags; 317 + u64 utime, stime; 320 318 321 319 /* 322 320 * Update current task runtime to account pending time since last ··· 327 329 if (same_thread_group(current, tsk)) 328 330 (void) task_sched_runtime(current); 329 331 330 - rcu_read_lock(); 331 - /* Attempt a lockless read on the first round. */ 332 - nextseq = 0; 333 - do { 334 - seq = nextseq; 335 - flags = read_seqbegin_or_lock_irqsave(&sig->stats_lock, &seq); 332 + guard(rcu)(); 333 + scoped_seqlock_read (&sig->stats_lock, ss_lock_irqsave) { 336 334 times->utime = sig->utime; 337 335 times->stime = sig->stime; 338 336 times->sum_exec_runtime = sig->sum_sched_runtime; 339 337 340 - for_each_thread(tsk, t) { 338 + __for_each_thread(sig, t) { 341 339 task_cputime(t, &utime, &stime); 342 340 times->utime += utime; 343 341 times->stime += stime; 344 342 times->sum_exec_runtime += read_sum_exec_runtime(t); 345 343 } 346 - /* If lockless access failed, take the lock. */ 347 - nextseq = 1; 348 - } while (need_seqretry(&sig->stats_lock, seq)); 349 - done_seqretry_irqrestore(&sig->stats_lock, seq, flags); 350 - rcu_read_unlock(); 344 + } 351 345 } 352 346 353 347 #ifdef CONFIG_IRQ_TIME_ACCOUNTING