Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH] intel_idle: update spec_ctrl register only when necessary
@ 2024-02-06  7:14 Li RongQing
  2024-02-06 17:40 ` Pawan Gupta
  0 siblings, 1 reply; 2+ messages in thread
From: Li RongQing @ 2024-02-06  7:14 UTC (permalink / raw)
  To: linux-pm; +Cc: Li RongQing

spec_ctrl maybe 0 when mitigations is off, and writing spec_ctrl MSR
is expensive operation, so update spec_ctrl only when necessary

Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 drivers/idle/intel_idle.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index bcf1198..8150d5f 100644
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -176,12 +176,12 @@ static __cpuidle int intel_idle_ibrs(struct cpuidle_device *dev,
 	u64 spec_ctrl = spec_ctrl_current();
 	int ret;
 
-	if (smt_active)
+	if (smt_active && spec_ctrl)
 		__update_spec_ctrl(0);
 
 	ret = __intel_idle(dev, drv, index, true);
 
-	if (smt_active)
+	if (smt_active && spec_ctrl)
 		__update_spec_ctrl(spec_ctrl);
 
 	return ret;
-- 
2.9.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] intel_idle: update spec_ctrl register only when necessary
  2024-02-06  7:14 [PATCH] intel_idle: update spec_ctrl register only when necessary Li RongQing
@ 2024-02-06 17:40 ` Pawan Gupta
  0 siblings, 0 replies; 2+ messages in thread
From: Pawan Gupta @ 2024-02-06 17:40 UTC (permalink / raw)
  To: Li RongQing; +Cc: linux-pm

On Tue, Feb 06, 2024 at 03:14:52PM +0800, Li RongQing wrote:
> spec_ctrl maybe 0 when mitigations is off, and writing spec_ctrl MSR
> is expensive operation, so update spec_ctrl only when necessary

Have you observed SPEC_CTRL MSR being written on idle when mitigations
are off?

IIUC, intel_idle_ibrs() will only be called when X86_FEATURE_KERNEL_IBRS
is set:

state_update_enter_method()
{
...
          if (cpu_feature_enabled(X86_FEATURE_KERNEL_IBRS) &&
                          ((state->flags & CPUIDLE_FLAG_IBRS) || ibrs_off)) {
		  ...
                  state->enter = intel_idle_ibrs;
                  return;
          }

And X86_FEATURE_KERNEL_IBRS wont be set when mitigations are off.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-06 17:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-06  7:14 [PATCH] intel_idle: update spec_ctrl register only when necessary Li RongQing
2024-02-06 17:40 ` Pawan Gupta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox