Skip to content

Commit

Permalink
sched/cpuacct: Use __this_cpu_add() instead of this_cpu_ptr()
Browse files Browse the repository at this point in the history
The cpuacct_charge() and cpuacct_account_field() are called with
rq->lock held, and this means preemption(and IRQs) are indeed
disabled, so it is safe to use __this_cpu_*() to allow for better
code-generation.

Signed-off-by: Muchun Song <songmuchun@bytedance.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20200507031039.32615-1-songmuchun@bytedance.com
  • Loading branch information
Muchun Song authored and Peter Zijlstra committed May 19, 2020
1 parent 7d148be commit 12aa258
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions kernel/sched/cpuacct.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ void cpuacct_charge(struct task_struct *tsk, u64 cputime)
rcu_read_lock();

for (ca = task_ca(tsk); ca; ca = parent_ca(ca))
this_cpu_ptr(ca->cpuusage)->usages[index] += cputime;
__this_cpu_add(ca->cpuusage->usages[index], cputime);

rcu_read_unlock();
}
Expand All @@ -363,7 +363,7 @@ void cpuacct_account_field(struct task_struct *tsk, int index, u64 val)

rcu_read_lock();
for (ca = task_ca(tsk); ca != &root_cpuacct; ca = parent_ca(ca))
this_cpu_ptr(ca->cpustat)->cpustat[index] += val;
__this_cpu_add(ca->cpustat->cpustat[index], val);
rcu_read_unlock();
}

Expand Down

0 comments on commit 12aa258

Please sign in to comment.