netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: Resource usages in Linux drivers
       [not found] ` <5538B938.9060607@cogentembedded.com>
@ 2015-04-23  9:29   ` Jia-Ju Bai
  2015-04-23 10:08     ` Jia-Ju Bai
  0 siblings, 1 reply; 6+ messages in thread
From: Jia-Ju Bai @ 2015-04-23  9:29 UTC (permalink / raw)
  To: Sergei Shtylyov; +Cc: Jeff Kirsher, netdev, David Miller, stephen, Neil Horman

Thank you!

On 04/23/2015 05:19 PM, Sergei Shtylyov wrote:
> Hello.
>
> On 4/23/2015 9:45 AM, Jia-Ju Bai wrote:
>
>> Dear Sir,
>
>> I am very sorry to trouble you.
>
>> I find that resource management is error-prone when writing Linux 
>> drivers, and
>> many problems may occur, such as resource leaks.
>> Meanwhile, I find that many applied patches in the kernel mailing 
>> list focus
>> on releasing allocated resources, especially in error-handling paths.
>
>> Therefore, I have a question: is it possible to automatically release
>> allocated resources in drivers before unloading and in error-handling 
>> paths?
>
>    Yes, there's managed device API, look for functions starting with 
> devm_.
> There's one limitation though: it can be used only in the driver's 
> probe() method, so can't be used when e.g. network device is being 
> opened.
I think many APIs, such as kmalloc, can also be managed like garbage 
collection in Java.
Maybe the performance is a matter.

>
>> I am looking forward to your reply, thanks!
>
>    Such questions should actually be asked on the mailing lists, not 
> personally.
>
I am sorry for that, and I will cc to the mailing lists and other 
maintainers.

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

* Re: Resource usages in Linux drivers
  2015-04-23  9:29   ` Resource usages in Linux drivers Jia-Ju Bai
@ 2015-04-23 10:08     ` Jia-Ju Bai
  2015-04-23 10:37       ` Sergei Shtylyov
  0 siblings, 1 reply; 6+ messages in thread
From: Jia-Ju Bai @ 2015-04-23 10:08 UTC (permalink / raw)
  To: Sergei Shtylyov; +Cc: Jeff Kirsher, netdev, David Miller, stephen, Neil Horman

On 04/23/2015 05:29 PM, Jia-Ju Bai wrote:
> Thank you!
>
> On 04/23/2015 05:19 PM, Sergei Shtylyov wrote:
>> Hello.
>>
>> On 4/23/2015 9:45 AM, Jia-Ju Bai wrote:
>>
>>> Dear Sir,
>>
>>> I am very sorry to trouble you.
>>
>>> I find that resource management is error-prone when writing Linux 
>>> drivers, and
>>> many problems may occur, such as resource leaks.
>>> Meanwhile, I find that many applied patches in the kernel mailing 
>>> list focus
>>> on releasing allocated resources, especially in error-handling paths.
>>
>>> Therefore, I have a question: is it possible to automatically release
>>> allocated resources in drivers before unloading and in 
>>> error-handling paths?
>>
>>    Yes, there's managed device API, look for functions starting with 
>> devm_.
>> There's one limitation though: it can be used only in the driver's 
>> probe() method, so can't be used when e.g. network device is being 
>> opened.
> I think many APIs, such as kmalloc, can also be managed like garbage 
> collection in Java.
> Maybe the performance is a matter.
>
>>
>>> I am looking forward to your reply, thanks!
>>
>>    Such questions should actually be asked on the mailing lists, not 
>> personally.
>>
> I am sorry for that, and I will cc to the mailing lists and other 
> maintainers.
>
>

I find that some common APIs are not managed, such as napi_enable and 
napi_start_queue. Is it possible to provide managed APIs for them?
I also find many drivers do not use these managed APIs, especially in 
ethernet card drivers (like e100, r8169). Is it possible to change them?


Best wishes,
Jia-Ju Bai

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

* Re: Resource usages in Linux drivers
  2015-04-23 10:08     ` Jia-Ju Bai
@ 2015-04-23 10:37       ` Sergei Shtylyov
  2015-04-23 23:19         ` Francois Romieu
  0 siblings, 1 reply; 6+ messages in thread
From: Sergei Shtylyov @ 2015-04-23 10:37 UTC (permalink / raw)
  To: Jia-Ju Bai; +Cc: Jeff Kirsher, netdev, David Miller, stephen, Neil Horman

On 4/23/2015 1:08 PM, Jia-Ju Bai wrote:

>>>> I am very sorry to trouble you.

>>>> I find that resource management is error-prone when writing Linux drivers,
>>>> and
>>>> many problems may occur, such as resource leaks.
>>>> Meanwhile, I find that many applied patches in the kernel mailing list focus
>>>> on releasing allocated resources, especially in error-handling paths.

>>>> Therefore, I have a question: is it possible to automatically release
>>>> allocated resources in drivers before unloading and in error-handling paths?

>>>    Yes, there's managed device API, look for functions starting with devm_.
>>> There's one limitation though: it can be used only in the driver's probe()
>>> method, so can't be used when e.g. network device is being opened.

>> I think many APIs, such as kmalloc, can also be managed like garbage
>> collection in Java.
>> Maybe the performance is a matter.

>>>> I am looking forward to your reply, thanks!

>>>    Such questions should actually be asked on the mailing lists, not
>>> personally.

>> I am sorry for that, and I will cc to the mailing lists and other maintainers.

> I find that some common APIs are not managed, such as napi_enable and
> napi_start_queue. Is it possible to provide managed APIs for them?

    No, they're only called from ndo_open() method IIRC. The device managed 
APIs can only be called at the device probing time.

> I also find many drivers do not use these managed APIs, especially in ethernet
> card drivers (like e100, r8169). Is it possible to change them?

    Patches welcome. :-)

> Best wishes,
> Jia-Ju Bai

WBR, Sergei

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

* Re: Resource usages in Linux drivers
  2015-04-23 10:37       ` Sergei Shtylyov
@ 2015-04-23 23:19         ` Francois Romieu
  2015-04-24  0:40           ` Florian Fainelli
  0 siblings, 1 reply; 6+ messages in thread
From: Francois Romieu @ 2015-04-23 23:19 UTC (permalink / raw)
  To: Sergei Shtylyov
  Cc: Jia-Ju Bai, Jeff Kirsher, netdev, David Miller, stephen,
	Neil Horman

Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> :
> On 4/23/2015 1:08 PM, Jia-Ju Bai wrote:
[...]
> >I also find many drivers do not use these managed APIs, especially in ethernet
> >card drivers (like e100, r8169). Is it possible to change them?
> 
>    Patches welcome. :-)

I respectfully disagree.

If someone believes basic resouce management to be too hard or error-prone
to handle, he should imvho seriously rise the bar and reconsider the way
he wants to contribute to the kernel.

I may hope he who reads e100.c to think about DMA api, bql or rx ring
holes avoidance to quote a few ones. Managed API ? Mildly...

-- 
Ueimor

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

* Re: Resource usages in Linux drivers
  2015-04-23 23:19         ` Francois Romieu
@ 2015-04-24  0:40           ` Florian Fainelli
  2015-04-24  0:49             ` David Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Florian Fainelli @ 2015-04-24  0:40 UTC (permalink / raw)
  To: Francois Romieu, Sergei Shtylyov
  Cc: Jia-Ju Bai, Jeff Kirsher, netdev, David Miller, stephen,
	Neil Horman

On 23/04/15 16:19, Francois Romieu wrote:
> Sergei Shtylyov <sergei.shtylyov@cogentembedded.com> :
>> On 4/23/2015 1:08 PM, Jia-Ju Bai wrote:
> [...]
>>> I also find many drivers do not use these managed APIs, especially in ethernet
>>> card drivers (like e100, r8169). Is it possible to change them?
>>
>>    Patches welcome. :-)
> 
> I respectfully disagree.

Me too, most of the device managed conversions we have seen were bogus
because they were done in a semi-automated way without understanding the
peculiarities of the network devices, that is the separation between
init/open/close that most other device drivers do not have.

A typical example is this:
http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=6892b41d9701283085b655c6086fb57a5d63fa47

> 
> If someone believes basic resouce management to be too hard or error-prone
> to handle, he should imvho seriously rise the bar and reconsider the way
> he wants to contribute to the kernel.

Well, for one, we could have a device managed register_netdev() which
cleans up resources in case of failures and calls free_netdev()
automatically, but is that adding much value?

> 
> I may hope he who reads e100.c to think about DMA api, bql or rx ring
> holes avoidance to quote a few ones. Managed API ? Mildly...
> 


-- 
Florian

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

* Re: Resource usages in Linux drivers
  2015-04-24  0:40           ` Florian Fainelli
@ 2015-04-24  0:49             ` David Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2015-04-24  0:49 UTC (permalink / raw)
  To: f.fainelli
  Cc: romieu, sergei.shtylyov, baijiaju1990, jeffrey.t.kirsher, netdev,
	stephen, nhorman

From: Florian Fainelli <f.fainelli@gmail.com>
Date: Thu, 23 Apr 2015 17:40:12 -0700

> Well, for one, we could have a device managed register_netdev()
> which cleans up resources in case of failures and calls
> free_netdev() automatically, but is that adding much value?

I don't think it's worth it at all.

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

end of thread, other threads:[~2015-04-24  0:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <5538950F.3040405@163.com>
     [not found] ` <5538B938.9060607@cogentembedded.com>
2015-04-23  9:29   ` Resource usages in Linux drivers Jia-Ju Bai
2015-04-23 10:08     ` Jia-Ju Bai
2015-04-23 10:37       ` Sergei Shtylyov
2015-04-23 23:19         ` Francois Romieu
2015-04-24  0:40           ` Florian Fainelli
2015-04-24  0:49             ` David Miller

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