LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 06-15-2008, 05:30 AM   #1
krap
LQ Newbie
 
Registered: May 2008
Posts: 25

Rep: Reputation: 15
some questions on init_module function


hey guys,

i want to know that after doing insmod module.o module is loaded into the kernel.but what happens after that.how kernel comes to know that module is inserted and when its time to run the code provided by init_module.if u can provide me code of the same,it will be highly appreciatable.

thanking in advance
krap
 
Old 06-15-2008, 05:39 AM   #2
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
The module's "init" function is used to set up parameters which the driver will need later on, and to perform any necessary registration with the kernel. The registration is done by passing a structure with pointers. When a process attempts to access a device, the kernel uses that struct of pointers to invoke various functions such as "open" and "close".

For a very simple example of a driver, look at the watchdog timer code. It is a basic "character" device (of subtype "misc") and it even implements some IOCTLs.

A lot of macro magic also goes on; the kernel hackers have done a pretty good job of hiding a lot of horrible things from the device driver programmer.
 
Old 06-15-2008, 07:01 AM   #3
krap
LQ Newbie
 
Registered: May 2008
Posts: 25

Original Poster
Rep: Reputation: 15
no actually my point is that suppose a periodic task is defined in init_module eg

init_module()
{
pthread_create()
}

so this will create a new thread in kernel space.Now kernel should get some interrupt because of this new thread .who and how will that interrupt be generated????
 
Old 06-15-2008, 08:51 AM   #4
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
If I'm not mistaken, 'pthread_create' is part of libc and not the kernel, nor are any threads created that way within the kernel. If you want to schedule periodic tasks, there are several schemes to accomplish that. For example, you can schedule a 'tasklet' for execution and if it needs to run again later, that tasklet can reschedule itself before exit.

Another point - why would that thread you created generate an interrupt? The kernel has several timers one of which, for example, is used as a "software interrupt" for UART chips which do not generate a real interrupt. So if you look at the kernel serial code you can see the details of how this is implemented. Well, I say that because I know there is such code in the serial driver - I certainly wouldn't recommend the serial driver code as the best example because it is fairly complex code with very little "obvious" about it.

The Linux Device Drivers 3 by Rubini et al might discuss the timers and "soft IRQ" - but even if it doesn't, I'm sure you can learn more about device drivers from it. The chapters are available as electronic copies from O'Reilly; if you plan to do a lot of driver development I would recommend buying a hard copy for reference. From your posts, I would say you need to read the book.

As for real interrupts, you basically request to service an interrupt and register an interrupt handler for it. Since interrupts may be 'shared', life gets a bit more complex because you have to ensure that you check that your driver is the one which needs to handle the interrupt and you must not interfere with other drivers sharing the interrupt. Just to complicate things even more, it is possible for two drivers sharing an interrupt to both have a need to service that same interrupt.
 
Old 06-15-2008, 02:42 PM   #5
krap
LQ Newbie
 
Registered: May 2008
Posts: 25

Original Poster
Rep: Reputation: 15
no.....see i am working on rtlinux......so since there user tasks or better rt tasks share the kernel space........so when init_module is insmod from which pthread_create is called it will create a thread or better a task which will make a new entry in rt_tasks....but my question is when all these things happen......

I mean see init_module is called..then module is loaded....now pthread_create in called....so when and how cpu will be given to perform these tasks..
 
Old 06-15-2008, 05:26 PM   #6
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
RTL responds to all interrupts so that it can prioritize them. Any interrupts not processed by an RT task will be passed onto the Linux kernel for processing. Interrupts are generated by hardware; when you talk about RT it makes absolutely no sense to talk about a 'software interrupt'. So basically you're registering an interrupt handler with RTL rather than the usual Linux interrupt processor; the chief difference is that RTL is meant to give 'deterministic' latency. So basically they are exactly the same to the end user - hardware generates an interrupt, and RTL calls the interrupt handler.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is this ok in a init_module saranjothy Linux - Kernel 1 08-17-2006 05:55 AM
init_module: no such device salaw Linux - Wireless Networking 0 01-05-2005 06:12 PM
intel8x0.o: init_module: No such device SpeedDingo Linux - Hardware 5 05-17-2004 10:29 PM
questions about the daemon( ) function... BrianK Programming 3 10-10-2003 09:29 AM
init_module error blueplazma Linux - Software 0 06-24-2002 11:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 11:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration