All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] dec: tulip: de4x5: Replace mdelay with usleep_range in de4x5_hw_init
@ 2018-04-11 15:39 Jia-Ju Bai
  2018-04-11 16:16 ` James Bottomley
  0 siblings, 1 reply; 5+ messages in thread
From: Jia-Ju Bai @ 2018-04-11 15:39 UTC (permalink / raw)
  To: davem, stephen, johannes.berg, arvind.yadav.cs, dhowells
  Cc: netdev, linux-parisc, linux-kernel, Jia-Ju Bai

de4x5_hw_init() is never called in atomic context.

de4x5_hw_init() is only called by de4x5_pci_probe(), which is only 
set as ".probe" in struct pci_driver.

Despite never getting called from atomic context, de4x5_hw_init() 
calls mdelay() to busily wait.
This is not necessary and can be replaced with usleep_range() to 
avoid busy waiting.

This is found by a static analysis tool named DCNS written by myself.
And I also manually check it.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
v2:
* Use usleep_range() to correct usleep() in v1.
	
---
 drivers/net/ethernet/dec/tulip/de4x5.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
index 0affee9..3fb0119 100644
--- a/drivers/net/ethernet/dec/tulip/de4x5.c
+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
@@ -1107,7 +1107,7 @@ static int (*dc_infoblock[])(struct net_device *dev, u_char, u_char *) = {
 	pdev = to_pci_dev (gendev);
 	pci_write_config_byte(pdev, PCI_CFDA_PSM, WAKEUP);
     }
-    mdelay(10);
+    usleep_range(10000, 11000);
 
     RESET_DE4X5;
 
-- 
1.9.1

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

* Re: [PATCH v2] dec: tulip: de4x5: Replace mdelay with usleep_range in de4x5_hw_init
  2018-04-11 15:39 [PATCH v2] dec: tulip: de4x5: Replace mdelay with usleep_range in de4x5_hw_init Jia-Ju Bai
@ 2018-04-11 16:16 ` James Bottomley
  2018-04-12  1:30   ` Jia-Ju Bai
  0 siblings, 1 reply; 5+ messages in thread
From: James Bottomley @ 2018-04-11 16:16 UTC (permalink / raw)
  To: Jia-Ju Bai, davem, stephen, johannes.berg, arvind.yadav.cs, dhowells
  Cc: netdev, linux-parisc, linux-kernel

On Wed, 2018-04-11 at 23:39 +0800, Jia-Ju Bai wrote:
> de4x5_hw_init() is never called in atomic context.
> 
> de4x5_hw_init() is only called by de4x5_pci_probe(), which is only 
> set as ".probe" in struct pci_driver.
> 
> Despite never getting called from atomic context, de4x5_hw_init() 
> calls mdelay() to busily wait. This is not necessary and can be
> replaced with usleep_range() to  avoid busy waiting.
> 
> This is found by a static analysis tool named DCNS written by myself.
> And I also manually check it.

Did you actually test this?  The usual reason for wanting m/udelay is
that the timing must be exact.  The driver is filled with mdelay()s for
this reason.  The one you've picked on is in the init path so it won't
affect the runtime in any way.  I also don't think we have the hrtimer
machinery for usleep_range() to work properly on parisc, so I don't
think the replacement works.

James

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

* Re: [PATCH v2] dec: tulip: de4x5: Replace mdelay with usleep_range in de4x5_hw_init
  2018-04-11 16:16 ` James Bottomley
@ 2018-04-12  1:30   ` Jia-Ju Bai
  2018-04-12  2:21     ` arvindY
  0 siblings, 1 reply; 5+ messages in thread
From: Jia-Ju Bai @ 2018-04-12  1:30 UTC (permalink / raw)
  To: James Bottomley, davem, stephen, johannes.berg, arvind.yadav.cs,
	dhowells
  Cc: netdev, linux-parisc, linux-kernel



On 2018/4/12 0:16, James Bottomley wrote:
> On Wed, 2018-04-11 at 23:39 +0800, Jia-Ju Bai wrote:
>> de4x5_hw_init() is never called in atomic context.
>>
>> de4x5_hw_init() is only called by de4x5_pci_probe(), which is only
>> set as ".probe" in struct pci_driver.
>>
>> Despite never getting called from atomic context, de4x5_hw_init()
>> calls mdelay() to busily wait. This is not necessary and can be
>> replaced with usleep_range() to  avoid busy waiting.
>>
>> This is found by a static analysis tool named DCNS written by myself.
>> And I also manually check it.
> Did you actually test this?  The usual reason for wanting m/udelay is
> that the timing must be exact.  The driver is filled with mdelay()s for
> this reason.  The one you've picked on is in the init path so it won't
> affect the runtime in any way.  I also don't think we have the hrtimer
> machinery for usleep_range() to work properly on parisc, so I don't
> think the replacement works.
>
> James
>

Hello, James.
Thanks for your reply :)

I agree that usleep_range() here will not much affect the real execution 
of this driver.

But I think usleep_range() can more opportunity for other threads to use 
the CPU core to schedule during waiting.
That is why I detect mdelay() that can be replaced with msleep() or 
usleep_range().


Best wishes,
Jia-Ju Bai

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

* Re: [PATCH v2] dec: tulip: de4x5: Replace mdelay with usleep_range in de4x5_hw_init
  2018-04-12  1:30   ` Jia-Ju Bai
@ 2018-04-12  2:21     ` arvindY
  2018-04-12  2:26       ` Jia-Ju Bai
  0 siblings, 1 reply; 5+ messages in thread
From: arvindY @ 2018-04-12  2:21 UTC (permalink / raw)
  To: Jia-Ju Bai, James Bottomley, davem, stephen, johannes.berg, dhowells
  Cc: netdev, linux-parisc, linux-kernel



On Thursday 12 April 2018 07:00 AM, Jia-Ju Bai wrote:
>
>
> On 2018/4/12 0:16, James Bottomley wrote:
>> On Wed, 2018-04-11 at 23:39 +0800, Jia-Ju Bai wrote:
>>> de4x5_hw_init() is never called in atomic context.
>>>
>>> de4x5_hw_init() is only called by de4x5_pci_probe(), which is only
>>> set as ".probe" in struct pci_driver.
>>>
>>> Despite never getting called from atomic context, de4x5_hw_init()
>>> calls mdelay() to busily wait. This is not necessary and can be
>>> replaced with usleep_range() to  avoid busy waiting.
>>>
>>> This is found by a static analysis tool named DCNS written by myself.
>>> And I also manually check it.
>> Did you actually test this?  The usual reason for wanting m/udelay is
>> that the timing must be exact.  The driver is filled with mdelay()s for
>> this reason.  The one you've picked on is in the init path so it won't
>> affect the runtime in any way.  I also don't think we have the hrtimer
>> machinery for usleep_range() to work properly on parisc, so I don't
>> think the replacement works.
>>
>> James
>>
>
> Hello, James.
> Thanks for your reply :)
>
> I agree that usleep_range() here will not much affect the real 
> execution of this driver.
>
> But I think usleep_range() can more opportunity for other threads to 
> use the CPU core to schedule during waiting.
> That is why I detect mdelay() that can be replaced with msleep() or 
> usleep_range().
>

James is right, You have added all usleep_range() during system boot-up 
time.
During boot-up system will run as single threaded. Where this change will
not make much sense. System first priority is match the exact timing on
each and every boot-up.

~arvind

>
> Best wishes,
> Jia-Ju Bai

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

* Re: [PATCH v2] dec: tulip: de4x5: Replace mdelay with usleep_range in de4x5_hw_init
  2018-04-12  2:21     ` arvindY
@ 2018-04-12  2:26       ` Jia-Ju Bai
  0 siblings, 0 replies; 5+ messages in thread
From: Jia-Ju Bai @ 2018-04-12  2:26 UTC (permalink / raw)
  To: arvindY, James Bottomley, davem, stephen, johannes.berg, dhowells
  Cc: netdev, linux-parisc, linux-kernel



On 2018/4/12 10:21, arvindY wrote:
>
>
> On Thursday 12 April 2018 07:00 AM, Jia-Ju Bai wrote:
>>
>>
>> On 2018/4/12 0:16, James Bottomley wrote:
>>> On Wed, 2018-04-11 at 23:39 +0800, Jia-Ju Bai wrote:
>>>> de4x5_hw_init() is never called in atomic context.
>>>>
>>>> de4x5_hw_init() is only called by de4x5_pci_probe(), which is only
>>>> set as ".probe" in struct pci_driver.
>>>>
>>>> Despite never getting called from atomic context, de4x5_hw_init()
>>>> calls mdelay() to busily wait. This is not necessary and can be
>>>> replaced with usleep_range() to  avoid busy waiting.
>>>>
>>>> This is found by a static analysis tool named DCNS written by myself.
>>>> And I also manually check it.
>>> Did you actually test this?  The usual reason for wanting m/udelay is
>>> that the timing must be exact.  The driver is filled with mdelay()s for
>>> this reason.  The one you've picked on is in the init path so it won't
>>> affect the runtime in any way.  I also don't think we have the hrtimer
>>> machinery for usleep_range() to work properly on parisc, so I don't
>>> think the replacement works.
>>>
>>> James
>>>
>>
>> Hello, James.
>> Thanks for your reply :)
>>
>> I agree that usleep_range() here will not much affect the real 
>> execution of this driver.
>>
>> But I think usleep_range() can more opportunity for other threads to 
>> use the CPU core to schedule during waiting.
>> That is why I detect mdelay() that can be replaced with msleep() or 
>> usleep_range().
>>
>
> James is right, You have added all usleep_range() during system 
> boot-up time.
> During boot-up system will run as single threaded. Where this change will
> not make much sense. System first priority is match the exact timing on
> each and every boot-up.
>

Hello, Arvind.
Thanks for your reply :)

I admit I am not familiar with this driver.
I did not know this driver is only loaded during system boot-up time,
I thought this driver can be loaded as a kernel module (like many 
drivers) after system booting.
After knowing this, I admit my patch is not proper, sorry...


Best wishes,
Jia-Ju Bai

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

end of thread, other threads:[~2018-04-12  2:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-11 15:39 [PATCH v2] dec: tulip: de4x5: Replace mdelay with usleep_range in de4x5_hw_init Jia-Ju Bai
2018-04-11 16:16 ` James Bottomley
2018-04-12  1:30   ` Jia-Ju Bai
2018-04-12  2:21     ` arvindY
2018-04-12  2:26       ` Jia-Ju Bai

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.