All of lore.kernel.org
 help / color / mirror / Atom feed
From: "tip-bot2 for Peter Zijlstra" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Peter Zijlstra <peterz@infradead.org>,
	Frederic Weisbecker <frederic@kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: timers/nohz] tick/nohz: Evaluate the CPU expression after the static key
Date: Thu, 13 May 2021 13:17:29 -0000	[thread overview]
Message-ID: <162091184985.29796.1926500160516806098.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20210512232924.150322-2-frederic@kernel.org>

The following commit has been merged into the timers/nohz branch of tip:

Commit-ID:     f105dfec0a951cd0d5bfbfe9dc067ea69f71ad5c
Gitweb:        https://git.kernel.org/tip/f105dfec0a951cd0d5bfbfe9dc067ea69f71ad5c
Author:        Peter Zijlstra <peterz@infradead.org>
AuthorDate:    Thu, 13 May 2021 01:29:15 +02:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Thu, 13 May 2021 14:21:20 +02:00

tick/nohz: Evaluate the CPU expression after the static key

When tick_nohz_full_cpu() is called with smp_processor_id(), the latter
is unconditionally evaluated whether the static key is on or off. It is
not necessary in the off-case though, so make sure the cpu expression
is executed at the last moment.

Illustrate with the following test function:

	int tick_nohz_test(void)
	{
		return tick_nohz_full_cpu(smp_processor_id());
	}

The resulting code before was:

	mov    %gs:0x7eea92d1(%rip),%eax   # smp_processor_id() fetch
	nopl   0x0(%rax,%rax,1)
	xor    %eax,%eax
	retq
	cmpb   $0x0,0x29d393a(%rip)        # <tick_nohz_full_running>
	je     tick_nohz_test+0x29         # jump to below eax clear
	mov    %eax,%eax
	bt     %rax,0x29d3936(%rip)        # <tick_nohz_full_mask>
	setb   %al
	movzbl %al,%eax
	retq
	xor    %eax,%eax
	retq

Now it becomes:

	nopl   0x0(%rax,%rax,1)
	xor    %eax,%eax
	retq
	cmpb   $0x0,0x29d3871(%rip)        # <tick_nohz_full_running>
	je     tick_nohz_test+0x29         # jump to below eax clear
	mov    %gs:0x7eea91f0(%rip),%eax   # smp_processor_id() fetch, after static key
	mov    %eax,%eax
	bt     %rax,0x29d3866(%rip)        # <tick_nohz_full_mask>
	setb   %al
	movzbl %al,%eax
	retq
	xor    %eax,%eax
	retq

Signed-off-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20210512232924.150322-2-frederic@kernel.org
---
 include/linux/tick.h | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/include/linux/tick.h b/include/linux/tick.h
index 7340613..2258984 100644
--- a/include/linux/tick.h
+++ b/include/linux/tick.h
@@ -185,13 +185,17 @@ static inline bool tick_nohz_full_enabled(void)
 	return tick_nohz_full_running;
 }
 
-static inline bool tick_nohz_full_cpu(int cpu)
-{
-	if (!tick_nohz_full_enabled())
-		return false;
-
-	return cpumask_test_cpu(cpu, tick_nohz_full_mask);
-}
+/*
+ * Check if a CPU is part of the nohz_full subset. Arrange for evaluating
+ * the cpu expression (typically smp_processor_id()) _after_ the static
+ * key.
+ */
+#define tick_nohz_full_cpu(_cpu) ({					\
+	bool __ret = false;						\
+	if (tick_nohz_full_enabled())					\
+		__ret = cpumask_test_cpu((_cpu), tick_nohz_full_mask);	\
+	__ret;								\
+})
 
 static inline void tick_nohz_full_add_cpus_to(struct cpumask *mask)
 {

  reply	other threads:[~2021-05-13 13:19 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-12 23:29 [GIT PULL] tick/nohz updates v3 Frederic Weisbecker
2021-05-12 23:29 ` [PATCH 01/10] tick/nohz: Evaluate the CPU expression after the static key Frederic Weisbecker
2021-05-13 13:17   ` tip-bot2 for Peter Zijlstra [this message]
2021-05-12 23:29 ` [PATCH 02/10] tick/nohz: Conditionally restart tick on idle exit Frederic Weisbecker
2021-05-13 13:17   ` [tip: timers/nohz] " tip-bot2 for Yunfeng Ye
2021-05-12 23:29 ` [PATCH 03/10] tick/nohz: Remove superflous check for CONFIG_VIRT_CPU_ACCOUNTING_NATIVE Frederic Weisbecker
2021-05-13 13:17   ` [tip: timers/nohz] " tip-bot2 for Frederic Weisbecker
2021-05-12 23:29 ` [PATCH 04/10] tick/nohz: Update idle_exittime on actual idle exit Frederic Weisbecker
2021-05-13 13:17   ` [tip: timers/nohz] " tip-bot2 for Yunfeng Ye
2021-05-12 23:29 ` [PATCH 05/10] tick/nohz: Update nohz_full Kconfig help Frederic Weisbecker
2021-05-13 13:17   ` [tip: timers/nohz] " tip-bot2 for Frederic Weisbecker
2021-05-12 23:29 ` [PATCH 06/10] tick/nohz: Only wakeup a single target cpu when kicking a task Frederic Weisbecker
2021-05-13 13:17   ` [tip: timers/nohz] tick/nohz: Only wake up " tip-bot2 for Frederic Weisbecker
2021-05-12 23:29 ` [PATCH 07/10] tick/nohz: Change signal tick dependency to wakeup CPUs of member tasks Frederic Weisbecker
2021-05-13 13:17   ` [tip: timers/nohz] tick/nohz: Change signal tick dependency to wake up " tip-bot2 for Marcelo Tosatti
2021-05-12 23:29 ` [PATCH 08/10] tick/nohz: Kick only _queued_ task whose tick dependency is updated Frederic Weisbecker
2021-05-13 13:17   ` [tip: timers/nohz] " tip-bot2 for Marcelo Tosatti
2021-05-12 23:29 ` [PATCH 09/10] tick/nohz: Call tick_nohz_task_switch() with interrupts disabled Frederic Weisbecker
2021-05-13 13:17   ` [tip: timers/nohz] " tip-bot2 for Peter Zijlstra
2021-05-12 23:29 ` [PATCH 10/10] MAINTAINERS: Add myself as context tracking maintainer Frederic Weisbecker
2021-05-19  9:21   ` [tip: timers/nohz] " tip-bot2 for Frederic Weisbecker
2021-05-13 12:23 ` [GIT PULL] tick/nohz updates v3 Ingo Molnar

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=162091184985.29796.1926500160516806098.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=frederic@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=peterz@infradead.org \
    --cc=x86@kernel.org \
    /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.