Hi, I am totally newbie for kernel device driver, and starting to learn. When I see a driver code, I found __init. For example, static int __init xxxx(struct platform_device *pdev) I understand "static" and "int", but what is __init? -J.
When I see a driver code, I found __init. For example, static int __init xxxx(struct platform_device *pdev) I understand "static" and "int", but what is __init?
__init places the symbol it qualifies into a special section of the kernel that is discarded from memory once all initialization functions are called. Since an initialization function is called only once during system startup, it does not make sense to keep it once the initialization phase is finished. __init allows to do that. See also http://www.faqs.org/docs/kernel/x277.html Alex.
Thanks! J. On Sun, Feb 6, 2011 at 10:48 PM, Alexandre Courbot <gnurou@gmail.com> wrote:
When I see a driver code, I found __init. For example, static int __init xxxx(struct platform_device *pdev) I understand "static" and "int", but what is __init?
__init places the symbol it qualifies into a special section of the kernel that is discarded from memory once all initialization functions are called. Since an initialization function is called only once during system startup, it does not make sense to keep it once the initialization phase is finished. __init allows to do that.
See also http://www.faqs.org/docs/kernel/x277.html
Alex.
__init is a qualifier to a function or initialized data and a hint to the linker to place all these code and data in a seperate section in the object file, so that once these functions are executed, memory space occupied by these code and data will be freed. It is the onus on the Kernel programmer to decide which functions/data to be marked as __init. For Eg. the init functions of a driver module, in most cases will be executed only once and no other functions will invoke this init function. Thus, init function will be the right candidate to be marked as __init. http://lxr.linux.no/#linux+v2.6.37/include/linux/init.h Regards, Prabhu On Mon, Feb 7, 2011 at 12:11 PM, Joy Sun <joy2sun127@gmail.com> wrote:
Hi,
I am totally newbie for kernel device driver, and starting to learn.
When I see a driver code, I found __init. For example, static int __init xxxx(struct platform_device *pdev)
I understand "static" and "int", but what is __init?
-J.
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Thanks! J. On Sun, Feb 6, 2011 at 10:52 PM, Prabhu nath <gprabhunath@gmail.com> wrote:
__init is a qualifier to a function or initialized data and a hint to the linker to place all these code and data in a seperate section in the object file, so that once these functions are executed, memory space occupied by these code and data will be freed.
It is the onus on the Kernel programmer to decide which functions/data to be marked as __init. For Eg. the init functions of a driver module, in most cases will be executed only once and no other functions will invoke this init function. Thus, init function will be the right candidate to be marked as __init.
http://lxr.linux.no/#linux+v2.6.37/include/linux/init.h
Regards, Prabhu
On Mon, Feb 7, 2011 at 12:11 PM, Joy Sun <joy2sun127@gmail.com> wrote:
Hi,
I am totally newbie for kernel device driver, and starting to learn.
When I see a driver code, I found __init. For example, static int __init xxxx(struct platform_device *pdev)
I understand "static" and "int", but what is __init?
-J.
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
participants (3)
-
Alexandre Courbot -
Joy Sun -
Prabhu nath