linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] intel_idle: replace conditionals with static_cpu_has(X86_FEATURE_ARAT)
@ 2017-10-06 17:19 ` Jason Baron
  2017-10-06 18:36   ` Jacob Pan
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Baron @ 2017-10-06 17:19 UTC (permalink / raw)
  To: linux-pm, linux-kernel; +Cc: Jacob Pan, Len Brown, Rafael J. Wysocki

If the 'arat' cpu flag is set, then the conditionals in intel_idle() that
guard calling tick_broadcast_enter()/exit() will never be true. Use
static_cpu_has(X86_FEATURE_ARAT) to create a fast path to replace
the conditional.

Signed-off-by: Jason Baron <jbaron@akamai.com>
Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
Cc: Len Brown <lenb@kernel.org>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/idle/intel_idle.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
index 5dc7ea4..5db5e31 100644
--- a/drivers/idle/intel_idle.c
+++ b/drivers/idle/intel_idle.c
@@ -913,8 +913,7 @@ static __cpuidle int intel_idle(struct cpuidle_device *dev,
 	struct cpuidle_state *state = &drv->states[index];
 	unsigned long eax = flg2MWAIT(state->flags);
 	unsigned int cstate;
-
-	cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) & MWAIT_CSTATE_MASK) + 1;
+	bool uninitialized_var(tick);
 
 	/*
 	 * NB: if CPUIDLE_FLAG_TLB_FLUSHED is set, this idle transition
@@ -923,12 +922,19 @@ static __cpuidle int intel_idle(struct cpuidle_device *dev,
 	 * useful with this knowledge.
 	 */
 
-	if (!(lapic_timer_reliable_states & (1 << (cstate))))
-		tick_broadcast_enter();
+	if (!static_cpu_has(X86_FEATURE_ARAT)) {
+		cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) &
+				MWAIT_CSTATE_MASK) + 1;
+		tick = false;
+		if (!(lapic_timer_reliable_states & (1 << (cstate)))) {
+			tick = true;
+			tick_broadcast_enter();
+		}
+	}
 
 	mwait_idle_with_hints(eax, ecx);
 
-	if (!(lapic_timer_reliable_states & (1 << (cstate))))
+	if (!static_cpu_has(X86_FEATURE_ARAT) && tick)
 		tick_broadcast_exit();
 
 	return index;
-- 
2.6.1

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

* Re: [PATCH] intel_idle: replace conditionals with static_cpu_has(X86_FEATURE_ARAT)
  2017-10-06 17:19 ` [PATCH] intel_idle: replace conditionals with static_cpu_has(X86_FEATURE_ARAT) Jason Baron
@ 2017-10-06 18:36   ` Jacob Pan
  2017-10-06 18:41     ` Jason Baron
  0 siblings, 1 reply; 4+ messages in thread
From: Jacob Pan @ 2017-10-06 18:36 UTC (permalink / raw)
  To: Jason Baron; +Cc: linux-pm, linux-kernel, jacob.jun.pan

On Fri,  6 Oct 2017 13:19:45 -0400
Jason Baron <jbaron@akamai.com> wrote:

> If the 'arat' cpu flag is set, then the conditionals in intel_idle()
> that guard calling tick_broadcast_enter()/exit() will never be true.
> Use static_cpu_has(X86_FEATURE_ARAT) to create a fast path to replace
> the conditional.
> 
> Signed-off-by: Jason Baron <jbaron@akamai.com>
> Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
> Cc: Len Brown <lenb@kernel.org>
> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
>  drivers/idle/intel_idle.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
> index 5dc7ea4..5db5e31 100644
> --- a/drivers/idle/intel_idle.c
> +++ b/drivers/idle/intel_idle.c
> @@ -913,8 +913,7 @@ static __cpuidle int intel_idle(struct
> cpuidle_device *dev, struct cpuidle_state *state =
> &drv->states[index]; unsigned long eax = flg2MWAIT(state->flags);
>  	unsigned int cstate;
> -
> -	cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) &
> MWAIT_CSTATE_MASK) + 1;
> +	bool uninitialized_var(tick);
>  
>  	/*
>  	 * NB: if CPUIDLE_FLAG_TLB_FLUSHED is set, this idle
> transition @@ -923,12 +922,19 @@ static __cpuidle int
> intel_idle(struct cpuidle_device *dev,
>  	 * useful with this knowledge.
>  	 */
>  
> -	if (!(lapic_timer_reliable_states & (1 << (cstate))))
> -		tick_broadcast_enter();
> +	if (!static_cpu_has(X86_FEATURE_ARAT)) {
> +		cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) &
> +				MWAIT_CSTATE_MASK) + 1;
> +		tick = false;
> +		if (!(lapic_timer_reliable_states & (1 <<
> (cstate)))) {
> +			tick = true;
> +			tick_broadcast_enter();
> +		}
> +	}
>  
>  	mwait_idle_with_hints(eax, ecx);
>  
> -	if (!(lapic_timer_reliable_states & (1 << (cstate))))
> +	if (!static_cpu_has(X86_FEATURE_ARAT) && tick)
>  		tick_broadcast_exit();
>  
>  	return index;

Seems better to have a function pointer set up at init time to select
whether we do tick_broadcast or not (two functions). There is no need to
check CPU feature on every entry.

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

* Re: [PATCH] intel_idle: replace conditionals with static_cpu_has(X86_FEATURE_ARAT)
  2017-10-06 18:36   ` Jacob Pan
@ 2017-10-06 18:41     ` Jason Baron
  2017-10-06 21:09       ` Jacob Pan
  0 siblings, 1 reply; 4+ messages in thread
From: Jason Baron @ 2017-10-06 18:41 UTC (permalink / raw)
  To: Jacob Pan; +Cc: linux-pm, linux-kernel



On 10/06/2017 02:36 PM, Jacob Pan wrote:
> On Fri,  6 Oct 2017 13:19:45 -0400
> Jason Baron <jbaron@akamai.com> wrote:
> 
>> If the 'arat' cpu flag is set, then the conditionals in intel_idle()
>> that guard calling tick_broadcast_enter()/exit() will never be true.
>> Use static_cpu_has(X86_FEATURE_ARAT) to create a fast path to replace
>> the conditional.
>>
>> Signed-off-by: Jason Baron <jbaron@akamai.com>
>> Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
>> Cc: Len Brown <lenb@kernel.org>
>> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>> ---
>>  drivers/idle/intel_idle.c | 16 +++++++++++-----
>>  1 file changed, 11 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
>> index 5dc7ea4..5db5e31 100644
>> --- a/drivers/idle/intel_idle.c
>> +++ b/drivers/idle/intel_idle.c
>> @@ -913,8 +913,7 @@ static __cpuidle int intel_idle(struct
>> cpuidle_device *dev, struct cpuidle_state *state =
>> &drv->states[index]; unsigned long eax = flg2MWAIT(state->flags);
>>  	unsigned int cstate;
>> -
>> -	cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) &
>> MWAIT_CSTATE_MASK) + 1;
>> +	bool uninitialized_var(tick);
>>  
>>  	/*
>>  	 * NB: if CPUIDLE_FLAG_TLB_FLUSHED is set, this idle
>> transition @@ -923,12 +922,19 @@ static __cpuidle int
>> intel_idle(struct cpuidle_device *dev,
>>  	 * useful with this knowledge.
>>  	 */
>>  
>> -	if (!(lapic_timer_reliable_states & (1 << (cstate))))
>> -		tick_broadcast_enter();
>> +	if (!static_cpu_has(X86_FEATURE_ARAT)) {
>> +		cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) &
>> +				MWAIT_CSTATE_MASK) + 1;
>> +		tick = false;
>> +		if (!(lapic_timer_reliable_states & (1 <<
>> (cstate)))) {
>> +			tick = true;
>> +			tick_broadcast_enter();
>> +		}
>> +	}
>>  
>>  	mwait_idle_with_hints(eax, ecx);
>>  
>> -	if (!(lapic_timer_reliable_states & (1 << (cstate))))
>> +	if (!static_cpu_has(X86_FEATURE_ARAT) && tick)
>>  		tick_broadcast_exit();
>>  
>>  	return index;
> 
> Seems better to have a function pointer set up at init time to select
> whether we do tick_broadcast or not (two functions). There is no need to
> check CPU feature on every entry.
> 

Hi,

static_cpu_has() uses alternatives patching, so the cpu feature is not
tested on every entry. With the arat flag set you just have two nops in
the straight-line code path with this patch.

Thanks,

-Jason

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

* Re: [PATCH] intel_idle: replace conditionals with static_cpu_has(X86_FEATURE_ARAT)
  2017-10-06 18:41     ` Jason Baron
@ 2017-10-06 21:09       ` Jacob Pan
  0 siblings, 0 replies; 4+ messages in thread
From: Jacob Pan @ 2017-10-06 21:09 UTC (permalink / raw)
  To: Jason Baron; +Cc: linux-pm, linux-kernel, jacob.jun.pan

On Fri, 6 Oct 2017 14:41:07 -0400
Jason Baron <jbaron@akamai.com> wrote:

> On 10/06/2017 02:36 PM, Jacob Pan wrote:
> > On Fri,  6 Oct 2017 13:19:45 -0400
> > Jason Baron <jbaron@akamai.com> wrote:
> >   
> >> If the 'arat' cpu flag is set, then the conditionals in
> >> intel_idle() that guard calling tick_broadcast_enter()/exit() will
> >> never be true. Use static_cpu_has(X86_FEATURE_ARAT) to create a
> >> fast path to replace the conditional.
> >>
> >> Signed-off-by: Jason Baron <jbaron@akamai.com>
> >> Cc: Jacob Pan <jacob.jun.pan@linux.intel.com>
> >> Cc: Len Brown <lenb@kernel.org>
> >> Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> >> ---
> >>  drivers/idle/intel_idle.c | 16 +++++++++++-----
> >>  1 file changed, 11 insertions(+), 5 deletions(-)
> >>
> >> diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c
> >> index 5dc7ea4..5db5e31 100644
> >> --- a/drivers/idle/intel_idle.c
> >> +++ b/drivers/idle/intel_idle.c
> >> @@ -913,8 +913,7 @@ static __cpuidle int intel_idle(struct
> >> cpuidle_device *dev, struct cpuidle_state *state =
> >> &drv->states[index]; unsigned long eax = flg2MWAIT(state->flags);
> >>  	unsigned int cstate;
> >> -
> >> -	cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) &
> >> MWAIT_CSTATE_MASK) + 1;
> >> +	bool uninitialized_var(tick);
> >>  
> >>  	/*
> >>  	 * NB: if CPUIDLE_FLAG_TLB_FLUSHED is set, this idle
> >> transition @@ -923,12 +922,19 @@ static __cpuidle int
> >> intel_idle(struct cpuidle_device *dev,
> >>  	 * useful with this knowledge.
> >>  	 */
> >>  
> >> -	if (!(lapic_timer_reliable_states & (1 << (cstate))))
> >> -		tick_broadcast_enter();
> >> +	if (!static_cpu_has(X86_FEATURE_ARAT)) {
> >> +		cstate = (((eax) >> MWAIT_SUBSTATE_SIZE) &
> >> +				MWAIT_CSTATE_MASK) + 1;
> >> +		tick = false;
> >> +		if (!(lapic_timer_reliable_states & (1 <<
> >> (cstate)))) {
> >> +			tick = true;
> >> +			tick_broadcast_enter();
> >> +		}
> >> +	}
> >>  
> >>  	mwait_idle_with_hints(eax, ecx);
> >>  
> >> -	if (!(lapic_timer_reliable_states & (1 << (cstate))))
> >> +	if (!static_cpu_has(X86_FEATURE_ARAT) && tick)
> >>  		tick_broadcast_exit();
> >>  
> >>  	return index;  
> > 
> > Seems better to have a function pointer set up at init time to
> > select whether we do tick_broadcast or not (two functions). There
> > is no need to check CPU feature on every entry.
> >   
> 
> Hi,
> 
> static_cpu_has() uses alternatives patching, so the cpu feature is not
> tested on every entry. With the arat flag set you just have two nops
> in the straight-line code path with this patch.
> 
Thanks for explaining, i didn't know it was self modifying.

Acked-by: Jacob Pan <jacob.jun.pan@linux.intel.com>

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

end of thread, other threads:[~2017-10-06 21:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <bug-109051-18156@https.bugzilla.kernel.org/>
2017-10-06 17:19 ` [PATCH] intel_idle: replace conditionals with static_cpu_has(X86_FEATURE_ARAT) Jason Baron
2017-10-06 18:36   ` Jacob Pan
2017-10-06 18:41     ` Jason Baron
2017-10-06 21:09       ` Jacob Pan

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