Skip to contentSkip to conversation

sched/cpuacct: Use __this_cpu_add() instead of this_cpu_ptr()

PATCH Superseded Muchun Song 1 participant 1 message Apr 16, 2020 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sched/cpuacct: Use __this_cpu_add() instead of this_cpu_ptr()

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.

---
Chane in v2:
1. Update changelog.

 kernel/sched/cpuacct.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/sched/cpuacct.c +2 -2
index 9fbb103834345..6448b0438ffb2 100644
@@ -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();
 }
@@ -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();
 }
 
Signature · 1 line
2.11.0