Skip to content

Commit 5f40d80

Browse files
lizf-osingomolnar
authored andcommitted
sched/cpuacct: Remove redundant NULL checks in cpuacct_acount_field()
This is a micro optimazation for a hot path. - We don't need to check if @ca returned from task_ca() is NULL. - We don't need to check if @ca returned from parent_ca() is NULL. Signed-off-by: Li Zefan <lizefan@huawei.com> Acked-by: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/r/515536B7.6060602@huawei.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 543bc0e commit 5f40d80

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

‎kernel/sched/cpuacct.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,10 @@ void cpuacct_account_field(struct task_struct *p, int index, u64 val)
237237

238238
rcu_read_lock();
239239
ca = task_ca(p);
240-
while (ca && (ca != &root_cpuacct)) {
240+
while (ca != &root_cpuacct) {
241241
kcpustat = this_cpu_ptr(ca->cpustat);
242242
kcpustat->cpustat[index] += val;
243-
ca = parent_ca(ca);
243+
ca = __parent_ca(ca);
244244
}
245245
rcu_read_unlock();
246246
}

‎kernel/sched/cpuacct.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ static inline struct cpuacct *task_ca(struct task_struct *tsk)
3434
struct cpuacct, css);
3535
}
3636

37+
static inline struct cpuacct *__parent_ca(struct cpuacct *ca)
38+
{
39+
return cgroup_ca(ca->css.cgroup->parent);
40+
}
41+
3742
static inline struct cpuacct *parent_ca(struct cpuacct *ca)
3843
{
3944
if (!ca->css.cgroup->parent)

0 commit comments

Comments
 (0)