All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heiko Carstens <hca@linux.ibm.com>
To: Frederic Weisbecker <frederic@kernel.org>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	Sven Schnelle <svens@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org
Subject: [PATCH 4/9] s390/idle: Slightly optimize idle time accounting
Date: Wed, 18 Feb 2026 15:20:07 +0100	[thread overview]
Message-ID: <20260218142012.863464-5-hca@linux.ibm.com> (raw)
In-Reply-To: <20260218142012.863464-1-hca@linux.ibm.com>

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().

Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
---
 arch/s390/kernel/idle.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/arch/s390/kernel/idle.c b/arch/s390/kernel/idle.c
index 4e09f126d4fc..627d82dd900e 100644
--- a/arch/s390/kernel/idle.c
+++ b/arch/s390/kernel/idle.c
@@ -26,12 +26,13 @@ void update_timer_idle(void)
 	struct s390_idle_data *idle = this_cpu_ptr(&s390_idle);
 	struct lowcore *lc = get_lowcore();
 	u64 cycles_new[8];
-	int i;
+	int i, mtid;
 
-	if (smp_cpu_mtid) {
-		stcctm(MT_DIAG, smp_cpu_mtid, cycles_new);
-		for (i = 0; i < smp_cpu_mtid; i++)
-			this_cpu_add(mt_cycles[i], cycles_new[i] - idle->mt_cycles_enter[i]);
+	mtid = smp_cpu_mtid;
+	if (mtid) {
+		stcctm(MT_DIAG, mtid, cycles_new);
+		for (i = 0; i < mtid; i++)
+			__this_cpu_add(mt_cycles[i], cycles_new[i] - idle->mt_cycles_enter[i]);
 	}
 
 	/*
@@ -58,8 +59,8 @@ void account_idle_time_irq(void)
 	idle_time = get_lowcore()->int_clock - idle->clock_idle_enter;
 
 	/* Account time spent with enabled wait psw loaded as idle time. */
-	WRITE_ONCE(idle->idle_time, READ_ONCE(idle->idle_time) + idle_time);
-	WRITE_ONCE(idle->idle_count, READ_ONCE(idle->idle_count) + 1);
+	__atomic64_add(idle_time, &idle->idle_time);
+	__atomic64_add_const(1, &idle->idle_count);
 	account_idle_time(cputime_to_nsecs(idle_time));
 }
 
-- 
2.51.0


  parent reply	other threads:[~2026-02-18 14:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-18 14:20 [PATCH 0/9] s390/idle/vtime: Minor fixes and cleanups Heiko Carstens
2026-02-18 14:20 ` [PATCH 1/9] s390/idle: Fix cpu idle exit cpu time accounting Heiko Carstens
2026-03-04 14:16   ` Frederic Weisbecker
2026-02-18 14:20 ` [PATCH 2/9] s390/vtime: Fix virtual timer forwarding Heiko Carstens
2026-03-04 14:23   ` Frederic Weisbecker
2026-02-18 14:20 ` [PATCH 3/9] s390/idle: Add comment for non obvious code Heiko Carstens
2026-03-04 14:38   ` Frederic Weisbecker
2026-02-18 14:20 ` Heiko Carstens [this message]
2026-02-18 14:20 ` [PATCH 5/9] s390/idle: Inline update_timer_idle() Heiko Carstens
2026-03-04 15:07   ` Frederic Weisbecker
2026-02-18 14:20 ` [PATCH 6/9] s390/irq/idle: Remove psw bits early Heiko Carstens
2026-02-18 14:20 ` [PATCH 7/9] s390/vtime: Use __this_cpu_read() / get rid of READ_ONCE() Heiko Carstens
2026-03-04 14:49   ` Frederic Weisbecker
2026-02-18 14:20 ` [PATCH 8/9] s390/vtime: Use lockdep_assert_irqs_disabled() instead of BUG_ON() Heiko Carstens
2026-03-04 15:08   ` Frederic Weisbecker
2026-02-18 14:20 ` [PATCH 9/9] s390/idle: Remove psw_idle() prototype Heiko Carstens
2026-03-04 15:09   ` Frederic Weisbecker
2026-02-25  9:19 ` [PATCH 0/9] s390/idle/vtime: Minor fixes and cleanups Sven Schnelle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260218142012.863464-5-hca@linux.ibm.com \
    --to=hca@linux.ibm.com \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=frederic@kernel.org \
    --cc=gor@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=svens@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.