linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: psci: Use udelay() instead of msleep() to reduce waiting time
@ 2019-09-11  8:50 Yunfeng Ye
  2019-09-12  8:48 ` David Laight
  0 siblings, 1 reply; 3+ messages in thread
From: Yunfeng Ye @ 2019-09-11  8:50 UTC (permalink / raw)
  To: catalin.marinas, will
  Cc: kstewart, gregkh, ard.biesheuvel, tglx, linux-arm-kernel,
	linux-kernel, wuyun.wu

We want to reduce the time of cpu_down() for saving power, found that
cpu_psci_cpu_kill() cost 10ms after psci_ops.affinity_info() fail.

Normally the time cpu dead is very short, it is no need to wait 10ms.
so use udelay 10us to instead msleep 10ms in every waiting loop, and add
cond_resched() to give a chance to run a higher-priority process.

Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
---
 arch/arm64/kernel/psci.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/arm64/kernel/psci.c b/arch/arm64/kernel/psci.c
index 85ee7d0..9e9d8a6 100644
--- a/arch/arm64/kernel/psci.c
+++ b/arch/arm64/kernel/psci.c
@@ -86,15 +86,15 @@ static int cpu_psci_cpu_kill(unsigned int cpu)
 	 * while it is dying. So, try again a few times.
 	 */

-	for (i = 0; i < 10; i++) {
+	for (i = 0; i < 10000; i++) {
 		err = psci_ops.affinity_info(cpu_logical_map(cpu), 0);
 		if (err == PSCI_0_2_AFFINITY_LEVEL_OFF) {
 			pr_info("CPU%d killed.\n", cpu);
 			return 0;
 		}

-		msleep(10);
-		pr_info("Retrying again to check for CPU kill\n");
+		cond_resched();
+		udelay(10);
 	}

 	pr_warn("CPU%d may not have shut down cleanly (AFFINITY_INFO reports %d)\n",
-- 
1.8.3.1


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

* RE: [PATCH] arm64: psci: Use udelay() instead of msleep() to reduce waiting time
  2019-09-11  8:50 [PATCH] arm64: psci: Use udelay() instead of msleep() to reduce waiting time Yunfeng Ye
@ 2019-09-12  8:48 ` David Laight
  2019-09-16 15:26   ` Yunfeng Ye
  0 siblings, 1 reply; 3+ messages in thread
From: David Laight @ 2019-09-12  8:48 UTC (permalink / raw)
  To: 'Yunfeng Ye', catalin.marinas, will
  Cc: kstewart, gregkh, ard.biesheuvel, tglx, linux-arm-kernel,
	linux-kernel, wuyun.wu

From: Yunfeng Ye
> Sent: 11 September 2019 09:50
> We want to reduce the time of cpu_down() for saving power, found that
> cpu_psci_cpu_kill() cost 10ms after psci_ops.affinity_info() fail.
> 
> Normally the time cpu dead is very short, it is no need to wait 10ms.
> so use udelay 10us to instead msleep 10ms in every waiting loop, and add
> cond_resched() to give a chance to run a higher-priority process.
> 
> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
> ---
>  arch/arm64/kernel/psci.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm64/kernel/psci.c b/arch/arm64/kernel/psci.c
> index 85ee7d0..9e9d8a6 100644
> --- a/arch/arm64/kernel/psci.c
> +++ b/arch/arm64/kernel/psci.c
> @@ -86,15 +86,15 @@ static int cpu_psci_cpu_kill(unsigned int cpu)
>  	 * while it is dying. So, try again a few times.
>  	 */
> 
> -	for (i = 0; i < 10; i++) {
> +	for (i = 0; i < 10000; i++) {
>  		err = psci_ops.affinity_info(cpu_logical_map(cpu), 0);
>  		if (err == PSCI_0_2_AFFINITY_LEVEL_OFF) {
>  			pr_info("CPU%d killed.\n", cpu);
>  			return 0;
>  		}
> 
> -		msleep(10);
> -		pr_info("Retrying again to check for CPU kill\n");
> +		cond_resched();
> +		udelay(10);

You really don't want to be doing 10000 udelay(10) before giving up.

If udelay(10) is long enough for the normal case, then do that once.
After that use usleep_range().

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

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

* Re: [PATCH] arm64: psci: Use udelay() instead of msleep() to reduce waiting time
  2019-09-12  8:48 ` David Laight
@ 2019-09-16 15:26   ` Yunfeng Ye
  0 siblings, 0 replies; 3+ messages in thread
From: Yunfeng Ye @ 2019-09-16 15:26 UTC (permalink / raw)
  To: David Laight, catalin.marinas, will
  Cc: kstewart, gregkh, ard.biesheuvel, tglx, linux-arm-kernel,
	linux-kernel, wuyun.wu



On 2019/9/12 16:48, David Laight wrote:
> From: Yunfeng Ye
>> Sent: 11 September 2019 09:50
>> We want to reduce the time of cpu_down() for saving power, found that
>> cpu_psci_cpu_kill() cost 10ms after psci_ops.affinity_info() fail.
>>
>> Normally the time cpu dead is very short, it is no need to wait 10ms.
>> so use udelay 10us to instead msleep 10ms in every waiting loop, and add
>> cond_resched() to give a chance to run a higher-priority process.
>>
>> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
>> ---
>>  arch/arm64/kernel/psci.c | 6 +++---
>>  1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/arch/arm64/kernel/psci.c b/arch/arm64/kernel/psci.c
>> index 85ee7d0..9e9d8a6 100644
>> --- a/arch/arm64/kernel/psci.c
>> +++ b/arch/arm64/kernel/psci.c
>> @@ -86,15 +86,15 @@ static int cpu_psci_cpu_kill(unsigned int cpu)
>>  	 * while it is dying. So, try again a few times.
>>  	 */
>>
>> -	for (i = 0; i < 10; i++) {
>> +	for (i = 0; i < 10000; i++) {
>>  		err = psci_ops.affinity_info(cpu_logical_map(cpu), 0);
>>  		if (err == PSCI_0_2_AFFINITY_LEVEL_OFF) {
>>  			pr_info("CPU%d killed.\n", cpu);
>>  			return 0;
>>  		}
>>
>> -		msleep(10);
>> -		pr_info("Retrying again to check for CPU kill\n");
>> +		cond_resched();
>> +		udelay(10);
> 
> You really don't want to be doing 10000 udelay(10) before giving up.
> 
> If udelay(10) is long enough for the normal case, then do that once.
> After that use usleep_range().
> > 	David
> 
Thanks for your advice. the delay depend on the num of cores, range
from 50us to 500us, I have test the time on the 140+ cores cpu:

  (10us every time)
  [ 1177.979642] psci: CPU1 killed. total wait 4 times
  [ 1178.011369] psci: CPU2 killed. total wait 6 times
  [ 1178.035247] psci: CPU3 killed. total wait 3 times
  [ 1178.071134] psci: CPU4 killed. total wait 8 times
  ......
  [ 1190.128202] psci: CPU139 killed. total wait 50 times
  [ 1190.156266] psci: CPU140 killed. total wait 48 times
  [ 1190.192082] psci: CPU141 killed. total wait 46 times
  [ 1190.224104] psci: CPU142 killed. total wait 46 times

Can I bust-wait 1ms,which is 100 tiems udelay(10), after that, use
usleep_range(1000, 10000) ?  I don't want other process occupy cpu
for a long time when I let out the cpu. thanks.

> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
> 


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

end of thread, other threads:[~2019-09-16 15:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-11  8:50 [PATCH] arm64: psci: Use udelay() instead of msleep() to reduce waiting time Yunfeng Ye
2019-09-12  8:48 ` David Laight
2019-09-16 15:26   ` Yunfeng Ye

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