platform_driver_probe(), can save codespace
PATCH 1/1 platform_driver_probe(), can save codespace
This defines a new platform_driver_probe() method allowing the driver's probe() method, and its support code+data, to safely live in __init sections for typical system configurations.
Many system-on-chip processors could benefit from this API, to the tune of recovering hundreds to thousands of bytes per driver. That's memory which is currently wasted holding code which can never be called after
system startup, yet can not be removed. It can't be removed because of
the linkage requirement that pointers to init section code (like, ideally, probe support) must not live in other sections (like driver method tables) after those pointers would be invalid.
include/linux/platform_device.h +6 -0
@@ -58,6 +58,12 @@ struct platform_driver {extern int platform_driver_register (struct platform_driver *);extern void platform_driver_unregister (struct platform_driver *); +/* non-hotpluggable platform devices may use this so that probe() and +* its support may live in __init sections, conserving runtime memory. +*/ +extern int platform_driver_probe (struct platform_driver *driver, +int (*probe)(struct platform_device *)); +#define platform_get_drvdata (_dev) dev_get_drvdata(&(_dev)->dev)#define platform_set_drvdata (_dev,data) dev_set_drvdata(&(_dev)->dev, (data))
drivers/base/platform.c +48 -0
60 lines not on this page · raw message
drivers/base/platform.c void platform_driver_unregister(struct p · line 495
Quoted 12 lines · David Brownell
drivers/base/platform.c +12
-0+ +/* Fixup that section violation, being paranoid about code scanning +* the list of drivers in order to probe new devices. Check to see +* if the probe was successful, and make sure any forced probes of +* new devices fail. +*/ +spin_lock (&platform_bus_type.klist_drivers.k_lock); + drv->probe =NULL ; +if (code ==0 &&list_empty (&drv->driver.klist_devices.k_list)) + retval = -ENODEV ; + drv->driver.probe = platform_drv_probe_fail; +spin_unlock (&platform_bus_type.klist_drivers.k_lock);
I think this code should not be executed if driver is compiled as a module because __init sections will stay anyway. Also, why don't you also remove "bind" attribute if driver is built-in. That should save a bit of dynamic memory.
Signature · 1 line
Dmitry
Quoted 14 lines · Dmitry Torokhov
drivers/base/platform.c void platform_driver_unregister(struct p · line 495
Quoted 12 lines · David Brownell
drivers/base/platform.c +12
-0+ +/* Fixup that section violation, being paranoid about code scanning +* the list of drivers in order to probe new devices. Check to see +* if the probe was successful, and make sure any forced probes of +* new devices fail. +*/ +spin_lock (&platform_bus_type.klist_drivers.k_lock); + drv->probe =NULL ; +if (code ==0 &&list_empty (&drv->driver.klist_devices.k_list)) + retval = -ENODEV ; + drv->driver.probe = platform_drv_probe_fail; +spin_unlock (&platform_bus_type.klist_drivers.k_lock);
Quoted 2 lines
I think this code should not be executed if driver is compiled as a module because
__initsections will stay anyway.
Huh?? No they won't. Are you thinking "__devinit" with CONFIG_HOTPLUG? (Remember, this routine is not for use with hotpluggable devices.)
Quoted 3 lines
Also, why don't you
also remove "bind" attribute if driver is built-in. That should save a bit of dynamic memory.
That would be an additional nuance. Feel free to submit another patch on top of this one ... :)
- Dave
Quoted 3 lines
Signature · 1 line
Dmitry
Quoted 15 lines · David Brownell
Quoted 14 lines · Dmitry Torokhov
Quoted 12 lines · David Brownell
drivers/base/platform.c +12
-0+ +/* Fixup that section violation, being paranoid about code scanning +* the list of drivers in order to probe new devices. Check to see +* if the probe was successful, and make sure any forced probes of +* new devices fail. +*/ +spin_lock (&platform_bus_type.klist_drivers.k_lock); + drv->probe =NULL ; +if (code ==0 &&list_empty (&drv->driver.klist_devices.k_list)) + retval = -ENODEV ; + drv->driver.probe = platform_drv_probe_fail; +spin_unlock (&platform_bus_type.klist_drivers.k_lock);
Quoted 6 lines
Quoted 2 lines
I think this code should not be executed if driver is compiled as a module because
__initsections will stay anyway.Huh?? No they won't. Are you thinking "
__devinit" withCONFIG_HOTPLUG? (Remember, this routine is not for use with hotpluggable devices.)
Do we discard __init sections in modules nowadays? I thought we did that only for the kernel image itself.
Signature · 1 line
Dmitry
Quoted 2 lines · Dmitry Torokhov
Do we discard
__initsections in modules nowadays? I thought we did that only for the kernel image itself.
When did we _not_ discard them for modules?
Quoted 7 lines · David Brownell
Quoted 2 lines · Dmitry Torokhov
Do we discard
__initsections in modules nowadays? I thought we did that only for the kernel image itself.When did we _not_ discard them for modules?
It looks like the first attempts for that appeared in 2.4.19-rc1...
http://www.ussg.iu.edu/hypermail/linux/kernel/0207.0/0477.html
Signature · 1 line
Dmitry