Skip to content

Commit dc6e081

Browse files
Chengming ZhouPeter Zijlstra
authored andcommitted
sched/cpuacct: Optimize away RCU read lock
Since cpuacct_charge() is called from the scheduler update_curr(), we must already have rq lock held, then the RCU read lock can be optimized away. And do the same thing in it's wrapper cgroup_account_cputime(), but we can't use lockdep_assert_rq_held() there, which defined in kernel/sched/sched.h. Suggested-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Chengming Zhou <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 248cc99 commit dc6e081

File tree

2 files changed

+1
-5
lines changed

2 files changed

+1
-5
lines changed

include/linux/cgroup.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,11 +791,9 @@ static inline void cgroup_account_cputime(struct task_struct *task,
791791

792792
cpuacct_charge(task, delta_exec);
793793

794-
rcu_read_lock();
795794
cgrp = task_dfl_cgroup(task);
796795
if (cgroup_parent(cgrp))
797796
__cgroup_account_cputime(cgrp, delta_exec);
798-
rcu_read_unlock();
799797
}
800798

801799
static inline void cgroup_account_cputime_field(struct task_struct *task,

kernel/sched/cpuacct.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,10 @@ void cpuacct_charge(struct task_struct *tsk, u64 cputime)
337337
unsigned int cpu = task_cpu(tsk);
338338
struct cpuacct *ca;
339339

340-
rcu_read_lock();
340+
lockdep_assert_rq_held(cpu_rq(cpu));
341341

342342
for (ca = task_ca(tsk); ca; ca = parent_ca(ca))
343343
*per_cpu_ptr(ca->cpuusage, cpu) += cputime;
344-
345-
rcu_read_unlock();
346344
}
347345

348346
/*

0 commit comments

Comments
 (0)