Skip to content

Commit 00d8b03

Browse files
hcahcaVasily Gorbik
authored andcommitted
s390/idle: Slightly optimize idle time accounting
Slightly optimize account_idle_time_irq() and update_timer_idle(): - Use fast single instruction __atomic64() primitives to update per cpu idle_time and idle_count, instead of READ_ONCE() / WRITE_ONCE() pairs - stcctm() is an inline assembly with a full memory barrier. This leads to a not necessary extra dereference of smp_cpu_mtid in update_timer_idle(). Avoid this and read smp_cpu_mtid into a variable - Use __this_cpu_add() instead of this_cpu_add() to avoid disabling / enabling of preemption several times in a loop in update_timer_idle(). Reviewed-by: Sven Schnelle <svens@linux.ibm.com> Signed-off-by: Heiko Carstens <hca@linux.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
1 parent aefa6ec commit 00d8b03

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

arch/s390/kernel/idle.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ void update_timer_idle(void)
2626
struct s390_idle_data *idle = this_cpu_ptr(&s390_idle);
2727
struct lowcore *lc = get_lowcore();
2828
u64 cycles_new[8];
29-
int i;
29+
int i, mtid;
3030

31-
if (smp_cpu_mtid) {
32-
stcctm(MT_DIAG, smp_cpu_mtid, cycles_new);
33-
for (i = 0; i < smp_cpu_mtid; i++)
34-
this_cpu_add(mt_cycles[i], cycles_new[i] - idle->mt_cycles_enter[i]);
31+
mtid = smp_cpu_mtid;
32+
if (mtid) {
33+
stcctm(MT_DIAG, mtid, cycles_new);
34+
for (i = 0; i < mtid; i++)
35+
__this_cpu_add(mt_cycles[i], cycles_new[i] - idle->mt_cycles_enter[i]);
3536
}
3637

3738
/*
@@ -58,8 +59,8 @@ void account_idle_time_irq(void)
5859
idle_time = get_lowcore()->int_clock - idle->clock_idle_enter;
5960

6061
/* Account time spent with enabled wait psw loaded as idle time. */
61-
WRITE_ONCE(idle->idle_time, READ_ONCE(idle->idle_time) + idle_time);
62-
WRITE_ONCE(idle->idle_count, READ_ONCE(idle->idle_count) + 1);
62+
__atomic64_add(idle_time, &idle->idle_time);
63+
__atomic64_add_const(1, &idle->idle_count);
6364
account_idle_time(cputime_to_nsecs(idle_time));
6465
}
6566

0 commit comments

Comments
 (0)