linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: K Prateek Nayak <kprateek.nayak@amd.com>
To: Frederic Weisbecker <frederic@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Jacob Pan <jacob.jun.pan@linux.intel.com>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	Daniel Lezcano <daniel.lezcano@linaro.org>,
	<linux-pm@vger.kernel.org>, Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>
Subject: Re: [PATCH 4/6] cpuidle: Handle TIF_NR_POLLING on behalf of CPUIDLE_FLAG_MWAIT states
Date: Fri, 17 Jan 2025 23:39:28 +0530	[thread overview]
Message-ID: <ca4f26e7-aa6a-4dd1-a10d-ea0d9bece6a6@amd.com> (raw)
In-Reply-To: <20250102150201.21639-5-frederic@kernel.org>

Hello Frederic,

On 1/2/2025 8:31 PM, Frederic Weisbecker wrote:
> [..snip..]
> diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
> index 621696269584..9eece3df1080 100644
> --- a/kernel/sched/idle.c
> +++ b/kernel/sched/idle.c
> @@ -114,12 +114,13 @@ void __cpuidle default_idle_call(void)
>   		stop_critical_timings();
>   
>   		ct_cpuidle_enter();
> -		arch_cpu_idle();
> +		arch_cpu_idle(); // XXX assumes !polling
>   		ct_cpuidle_exit();
>   
>   		start_critical_timings();
>   		trace_cpu_idle(PWR_EVENT_EXIT, smp_processor_id());
>   		cond_tick_broadcast_exit();
> +		__current_set_polling();
>   	}
>   	local_irq_enable();
>   	instrumentation_end();
> @@ -128,31 +129,14 @@ void __cpuidle default_idle_call(void)
>   static int call_cpuidle_s2idle(struct cpuidle_driver *drv,
>   			       struct cpuidle_device *dev)
>   {
> +	int ret;
> +
>   	if (current_clr_polling_and_test())
>   		return -EBUSY;
>   
> -	return cpuidle_enter_s2idle(drv, dev);
> -}
> -
> -static int call_cpuidle(struct cpuidle_driver *drv, struct cpuidle_device *dev,
> -		      int next_state)
> -{
> -	/*
> -	 * The idle task must be scheduled, it is pointless to go to idle, just
> -	 * update no idle residency and return.
> -	 */
> -	if (current_clr_polling_and_test()) {

nit.

Previously, if TIF_NEED_RESCHED was set by this point, the CPU would
bail out early before entering the idle state but with this change, I
believe only at need_resched() in mwait_idle_with_hints() do we realize
we have a pending IPI / task wakeup. Is this a concern?

In my testing with ipistorm I could not see any difference in IPI
throughput to polling idle CPUs but a bailout before the entry method
for need_resched() can save a few cycles.

-- 
Thanks and Regards,
Prateek

> -		dev->last_residency_ns = 0;
> -		local_irq_enable();
> -		return -EBUSY;
> -	}
> -
> -	/*
> -	 * Enter the idle state previously returned by the governor decision.
> -	 * This function will block until an interrupt occurs and will take
> -	 * care of re-enabling the local interrupts
> -	 */
> -	return cpuidle_enter(drv, dev, next_state);
> +	ret = cpuidle_enter_s2idle(drv, dev);
> +	__current_set_polling();
> +	return ret;
>   }
>   
>   /**
> @@ -213,7 +197,7 @@ static void cpuidle_idle_call(void)
>   		tick_nohz_idle_stop_tick();
>   
>   		next_state = cpuidle_find_deepest_state(drv, dev, max_latency_ns);
> -		call_cpuidle(drv, dev, next_state);
> +		cpuidle_enter(drv, dev, next_state);
>   	} else {
>   		bool stop_tick = true;
>   
> @@ -227,7 +211,12 @@ static void cpuidle_idle_call	(void)
>   		else
>   			tick_nohz_idle_retain_tick();
>   
> -		entered_state = call_cpuidle(drv, dev, next_state);
> +		/*
> +		 * Enter the idle state previously returned by the governor decision.
> +		 * This function will block until an interrupt occurs and will take
> +		 * care of re-enabling the local interrupts.
> +		 */
> +		entered_state = cpuidle_enter(drv, dev, next_state);
>   		/*
>   		 * Give the governor an opportunity to reflect on the outcome
>   		 */
> @@ -235,7 +224,6 @@ static void cpuidle_idle_call(void)
>   	}
>   
>   exit_idle:
> -	__current_set_polling();
>   
>   	/*
>   	 * It is up to the idle functions to re-enable local interrupts




  parent reply	other threads:[~2025-01-17 18:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-02 15:01 [PATCH 0/6 v3] cpuidle: Handle TIF_NR_POLLING on behalf of polling idle states Frederic Weisbecker
2025-01-02 15:01 ` [PATCH 1/6] cpuidle: Remove unnecessary current_clr_polling_and_test() from haltpoll Frederic Weisbecker
2025-01-02 15:01 ` [PATCH 2/6] cpuidle: Introduce CPUIDLE_FLAG_MWAIT Frederic Weisbecker
2025-01-14 14:01   ` Rafael J. Wysocki
2025-01-14 14:34     ` Sudeep Holla
2025-01-14 14:37       ` Rafael J. Wysocki
2025-01-02 15:01 ` [PATCH 3/6] x86/cpuidle: Move buggy mwait implementations away from CPUIDLE_FLAG_MWAIT Frederic Weisbecker
2025-01-14 14:35   ` Rafael J. Wysocki
2025-01-02 15:01 ` [PATCH 4/6] cpuidle: Handle TIF_NR_POLLING on behalf of CPUIDLE_FLAG_MWAIT states Frederic Weisbecker
2025-01-14 14:50   ` Rafael J. Wysocki
2025-01-17 18:09   ` K Prateek Nayak [this message]
2025-01-02 15:01 ` [PATCH 5/6] cpuidle: Remove call_cpuidle_s2idle() Frederic Weisbecker
2025-01-14 14:53   ` Rafael J. Wysocki
2025-01-02 15:02 ` [PATCH 6/6] cpuidle: Handle TIF_NR_POLLING on behalf of software polling idle states Frederic Weisbecker
2025-01-14 14:56   ` Rafael J. Wysocki
2025-01-17 17:51 ` [PATCH 0/6 v3] cpuidle: Handle TIF_NR_POLLING on behalf of " K Prateek Nayak

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=ca4f26e7-aa6a-4dd1-a10d-ea0d9bece6a6@amd.com \
    --to=kprateek.nayak@amd.com \
    --cc=bp@alien8.de \
    --cc=daniel.lezcano@linaro.org \
    --cc=dave.hansen@linux.intel.com \
    --cc=frederic@kernel.org \
    --cc=jacob.jun.pan@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rafael@kernel.org \
    --cc=tglx@linutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).