All of lore.kernel.org
 help / color / mirror / Atom feed
From: "tip-bot2 for Waiman Long" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Waiman Long <longman@redhat.com>, Ingo Molnar <mingo@kernel.org>,
	"Rafael J. Wysocki" <rafael.j.wysocki@intel.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: sched/core] x86/idle: Disable IBRS when CPU is offline to improve single-threaded performance
Date: Sat, 07 Oct 2023 17:10:58 -0000	[thread overview]
Message-ID: <169669865877.3135.4050101364714116656.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20230727184600.26768-3-longman@redhat.com>

The following commit has been merged into the sched/core branch of tip:

Commit-ID:     2743fe89d4d41616ffbe1e7e96e443ae7a4b1cc6
Gitweb:        https://git.kernel.org/tip/2743fe89d4d41616ffbe1e7e96e443ae7a4b1cc6
Author:        Waiman Long <longman@redhat.com>
AuthorDate:    Thu, 27 Jul 2023 14:45:58 -04:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Sat, 07 Oct 2023 11:33:28 +02:00

x86/idle: Disable IBRS when CPU is offline to improve single-threaded performance

Commit bf5835bcdb96 ("intel_idle: Disable IBRS during long idle")
disables IBRS when the CPU enters long idle. However, when a CPU
becomes offline, the IBRS bit is still set when X86_FEATURE_KERNEL_IBRS
is enabled. That will impact the performance of a sibling CPU. Mitigate
this performance impact by clearing all the mitigation bits in SPEC_CTRL
MSR when offline. When the CPU is online again, it will be re-initialized
and so restoring the SPEC_CTRL value isn't needed.

Add a comment to say that native_play_dead() is a __noreturn function,
but it can't be marked as such to avoid confusion about the missing
MSR restoration code.

When DPDK is running on an isolated CPU thread processing network packets
in user space while its sibling thread is idle. The performance of the
busy DPDK thread with IBRS on and off in the sibling idle thread are:

                                IBRS on         IBRS off
                                -------         --------
  packets/second:                  7.8M           10.4M
  avg tsc cycles/packet:         282.26          209.86

This is a 25% performance degradation. The test system is a Intel Xeon
4114 CPU @ 2.20GHz.

[ mingo: Extended the changelog with performance data from the 0/4 mail. ]

Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20230727184600.26768-3-longman@redhat.com
---
 arch/x86/kernel/smpboot.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 48e0406..02765d9 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -87,6 +87,7 @@
 #include <asm/hw_irq.h>
 #include <asm/stackprotector.h>
 #include <asm/sev.h>
+#include <asm/spec-ctrl.h>
 
 /* representing HT siblings of each logical CPU */
 DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map);
@@ -1623,8 +1624,15 @@ void __noreturn hlt_play_dead(void)
 		native_halt();
 }
 
+/*
+ * native_play_dead() is essentially a __noreturn function, but it can't
+ * be marked as such as the compiler may complain about it.
+ */
 void native_play_dead(void)
 {
+	if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS))
+		__update_spec_ctrl(0);
+
 	play_dead_common();
 	tboot_shutdown(TB_SHUTDOWN_WFS);
 

  parent reply	other threads:[~2023-10-07 17:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-27 18:45 [PATCH v6 0/4] x86/speculation: Disable IBRS when idle Waiman Long
2023-07-27 18:45 ` [PATCH v6 1/4] x86/speculation: Add __update_spec_ctrl() helper Waiman Long
2023-10-04 15:47   ` [tip: sched/core] " tip-bot2 for Waiman Long
2023-10-07 17:10   ` tip-bot2 for Waiman Long
2023-07-27 18:45 ` [PATCH v6 2/4] x86/idle: Disable IBRS when cpu is offline Waiman Long
2023-10-04 15:47   ` [tip: sched/core] x86/idle: Disable IBRS when CPU is offline to improve single-threaded performance tip-bot2 for Waiman Long
2023-10-07 17:10   ` tip-bot2 for Waiman Long [this message]
2023-07-27 18:45 ` [PATCH v6 3/4] intel_idle: Use __update_spec_ctrl() in intel_idle_ibrs() Waiman Long
2023-10-04 15:47   ` [tip: sched/core] " tip-bot2 for Waiman Long
2023-10-07 17:10   ` tip-bot2 for Waiman Long
2023-07-27 18:46 ` [PATCH v6 4/4] intel_idle: Add ibrs_off module parameter to force disable IBRS Waiman Long
2023-10-04 15:47   ` [tip: sched/core] intel_idle: Add ibrs_off module parameter to force-disable IBRS tip-bot2 for Waiman Long
2023-10-07 17:10   ` tip-bot2 for Waiman Long
2023-08-16 20:42 ` [PATCH v6 0/4] x86/speculation: Disable IBRS when idle Waiman Long
2023-10-04 11:50 ` Ingo Molnar
2023-10-04 16:11   ` Waiman Long

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=169669865877.3135.4050101364714116656.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=longman@redhat.com \
    --cc=mingo@kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=torvalds@linux-foundation.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.