LinuxQuestions.org
Visit Jeremy's Blog.
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 11-08-2006, 09:16 AM   #1
minasafwat
LQ Newbie
 
Registered: Nov 2006
Posts: 7

Rep: Reputation: 0
Interrupts bottom halves


hiii i am new to kernel programming

I have 2 problems one with registring softirq and the other with scheduling tasklet

1) Softirq
this is the sample module to define and register softirq
when it run it shows the following error

/*
* hello.c Hello, World! As a Kernel Module + SoftIrq
*/

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/interrupt.h>

void my_softirq_handler(unsigned long data){
printk(KERN_ALERT "My softirq Handler is executing...\n");
/*printk(KERN_ALERT "Data Received: %L ...\n",++data);*/
}

/*
* hello_init the init function, called when the module is loaded.
* Returns zero if successfully loaded, nonzero otherwise.
*/
static int hello_init(void)
{
printk(KERN_ALERT "Module is up Hello!.\n");
open_softirq(MY_SOFTIRQ, my_softirq_handler, NULL);
raise_softirq(MY_SOFTIRQ);
return 0;
}

/*
* hello_exit the exit function, called when the module is removed.
*/
static void hello_exit(void)
{
printk(KERN_ALERT "Module is down bye bye!\n");
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Mina");

The ERROR
---------
# insmod mysoftirq.ko
Using mysoftirq.ko
mysoftirq: Unknown symbol open_softirq
insmod: cannot insert `mysoftirq.ko': Unknown symbol in module (-1): No such file or directory

--------------------------------------------------------------

2) Tasklet
this is the sample module to declare and schedule a tasklet
the problem is when schedule tasklet is invoked the kernel crashes

/*
* hello.c Hello, World! As a Kernel Module
*/

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/interrupt.h>


unsigned long data = 0;

void my_tasklet_handler(unsigned long data){
printk(KERN_ALERT "My Tasklet Handler is executing...\n");
printk(KERN_ALERT "Data Received: %L ...\n",++data);
/*tasklet_schedule(&my_tasklet);*/
}

/*
* hello_init the init function, called when the module is loaded.
* Returns zero if successfully loaded, nonzero otherwise.
*/
static int hello_init(void)
{
printk(KERN_ALERT "Module is up Hello!.\n");
DECLARE_TASKLET(my_tasklet, my_tasklet_handler, data);
tasklet_schedule(&my_tasklet);
return 0;
}

/*
* hello_exit the exit function, called when the module is removed.
*/
static void hello_exit(void)
{
printk(KERN_ALERT "Module is down bye bye!\n");
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Mina");

The ERROR
----------
# insmod mymod.ko
Using mymod.ko
Module is up Hello!.
# Unable to handle kernel paging request at virtual address e3cd1d87
pgd = c1d50000
[e3cd1d87] *pgd=00000000
Internal error: Oops: 1 [#1]
Modules linked in: mymod
CPU: 0
PC is at tasklet_action+0x38/0xe0
LR is at try_to_wake_up+0x24/0x12c
pc : [<c0043ac8>] lr : [<c003b294>] Not tainted
sp : c1d69dc0 ip : e3cd1d7f fp : c1d69dd0
r10: a0000013 r9 : c0023800 r8 : 00000002
r7 : c1c55c02 r6 : 0000000a r5 : c02653b0 r4 : e3cd1d7f
r3 : a0000013 r2 : c0265380 r1 : c0265360 r0 : c0023920
Flags: NzCv IRQs on FIQs on Mode SVC_32 Segment user
Control: 5317F Table: 11D50000 DAC: 00000015
Process sh (pid: 712, stack limit = 0xc1d68250)
Stack: (0xc1d69dc0 to 0xc1d6a000)
9dc0: 00000001 c1d69dec c1d69dd4 c00439c8 c0043aa0 c0210b80 fefe0000 ffffffff
9de0: c1d69dfc c1d69df0 c0043d90 c004397c c1d69e10 c1d69e00 c00256e0 c0043d5c
9e00: ffffffff c1d69e6c c1d69e14 c00249a4 c00256ac c026f054 00000005 fefb0000
9e20: 0000000b 60000013 c1c7dde4 00000000 c1c55c02 00000002 c0023800 a0000013
9e40: c1d69e6c c026f054 c1d69e5c 00000007 c01324bc 20000013 ffffffff 00000000
9e60: c1d69e98 c1d69e70 c0133450 c01324ac 00000002 c0023800 c1c55c00 00000002
9e80: c1d68000 c1c55c00 c03daa00 c1d69ef0 c1d69e9c c012399c c0133370 c002392c
9ea0: 00000000 00000000 00000000 00000000 00000000 00000000 c0339580 c003b39c
9ec0: c002392c c002392c c0023800 00000002 c03daa00 40000000 00000002 00000002
9ee0: c1d68000 c1d69f38 c1d69ef4 c0120aa0 c0123758 c03daa00 c0123748 c002380c
9f00: c0023bd4 00000000 c0314580 00000000 c026d130 00000002 c03daa00 c1d69f80
9f20: c0024f04 c1d68000 00000000 c1d69f58 c1d69f3c c0120bc8 c012092c c03daa00
9f40: 40000000 c1d69f80 00000002 c1d69f7c c1d69f5c c007cbf0 c0120b54 be8aaa90
9f60: 00000000 00000000 c03daa00 00000004 c1d69fa4 c1d69f80 c007d2f4 c007cb48
9f80: 00000000 00000000 00000000 40000000 00000002 000d72ac 00000000 c1d69fa8
9fa0: c0024d60 c007d2b8 40000000 00000002 00000001 40000000 00000002 000d72ac
9fc0: 40000000 00000002 000d72ac 00000002 00000000 000081e4 00000000 000b2b44
9fe0: 000d7000 be8aacc0 0004eda0 00070534 20000010 00000001 00000000 00000000
Backtrace:
[<c0043a90>] (tasklet_action+0x0/0xe0) from [<c00439c8>] (__do_softirq+0x5c/0xd0
)
r4 = 00000001
[<c004396c>] (__do_softirq+0x0/0xd0) from [<c0043d90>] (irq_exit+0x44/0x4c)
r6 = FFFFFFFF r5 = FEFE0000 r4 = C0210B80
[<c0043d4c>] (irq_exit+0x0/0x4c) from [<c00256e0>] (asm_do_IRQ+0x44/0x50)
[<c002569c>] (asm_do_IRQ+0x0/0x50) from [<c00249a4>] (__irq_svc+0x24/0x80)
r4 = FFFFFFFF
[<c013249c>] (uart_start+0x0/0x24) from [<c0133450>] (uart_write+0xf0/0x108)
r4 = 00000000
[<c0133360>] (uart_write+0x0/0x108) from [<c012399c>] (write_chan+0x254/0x370)
[<c0123748>] (write_chan+0x0/0x370) from [<c0120aa0>] (tty_write+0x184/0x228)
[<c012091c>] (tty_write+0x0/0x228) from [<c0120bc8>] (redirected_tty_write+0x84/
0x94)
[<c0120b44>] (redirected_tty_write+0x0/0x94) from [<c007cbf0>] (vfs_write+0xb8/0
x194)
r7 = 00000002 r6 = C1D69F80 r5 = 40000000 r4 = C03DAA00
[<c007cb38>] (vfs_write+0x0/0x194) from [<c007d2f4>] (sys_write+0x4c/0x80)
r7 = 00000004 r6 = C03DAA00 r5 = 00000000 r4 = 00000000
[<c007d2a8>] (sys_write+0x0/0x80) from [<c0024d60>] (ret_fast_syscall+0x0/0x2c)
r6 = 000D72AC r5 = 00000002 r4 = 40000000
Code: e10f3000 e3c33080 e121f003 ea000022 (e59c3008)
<0>Kernel panic - not syncing: Aiee, killing interrupt handler!


waiting for reply , Thanks in advance
 
Old 11-08-2006, 10:32 AM   #2
rick.2g
Member
 
Registered: Sep 2005
Posts: 41

Rep: Reputation: 15
I think tasklets need to be declared outside of the function - if you declare it inside the function, then it's just like you declared "int i;" or something like that - it has no meaning outside the function it's declared in.

try this instead :
Quote:
/*
* hello.c Hello, World! As a Kernel Module
*/

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/interrupt.h>

unsigned long data = 0;

void my_tasklet_handler(unsigned long data){
printk(KERN_ALERT "My Tasklet Handler is executing...\n");
printk(KERN_ALERT "Data Received: %L ...\n",++data);
}

DECLARE_TASKLET(my_tasklet, my_tasklet_handler, data);

/*
* hello_init the init function, called when the module is loaded.
* Returns zero if successfully loaded, nonzero otherwise.
*/
static int hello_init(void)
{
printk(KERN_ALERT "Module is up Hello!.\n");
tasklet_schedule(&my_tasklet);
return 0;
}

/*
* hello_exit the exit function, called when the module is removed.
*/
static void hello_exit(void)
{
printk(KERN_ALERT "Module is down bye bye!\n");
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Mina");

if you look at the DECLARE_TASKLET macro, it's just a declaration and initialization of the tasklet struct. In my mind at least, it's easier to think of it that way.

I'm not sure what will happen if the modules exits before the tasklet starts execution... let me know what happens .
 
Old 11-09-2006, 03:49 AM   #3
minasafwat
LQ Newbie
 
Registered: Nov 2006
Posts: 7

Original Poster
Rep: Reputation: 0
You were right, thanks alot ... the tasklet_schedule() gave exception because of the null pointer because the init destroy its local variable.

i still have problem with the softirq ,,, why when i load the module it tells me

# insmod mysoftirq.ko
Using mysoftirq.ko
mysoftirq: Unknown symbol open_softirq

althought the symbol open_softirq is exported in the linux/interrupt.h

thanks in advance
 
  


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
Interrupts rhcohen Programming 5 12-21-2017 11:25 AM
How to handle interrupts in C swatisameerp Programming 2 01-17-2006 11:37 AM
interrupts registrering sdimag Programming 0 11-02-2004 03:40 AM
about interrupts eshwar_ind Programming 1 02-25-2004 12:38 AM
High interrupts dunkyb Linux - General 4 12-29-2003 08:04 PM

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

All times are GMT -5. The time now is 06:35 PM.

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