hi, El Fri, 16 Feb 2007 14:50:44 +0530 "Ganesh PS" <ganesh.p7@xxxxxxxxx> ha escrit: > Hi i am facing the following problem while running my kernel module: > > The code is: > -------------- > struct timer_list myTimer; > void gen_sig(void){ > struct task_struct *p=NULL; > p=kmalloc(sizeof(struct task_struct), GFP_KERNEL); > > p = find_task_by_pid(pid); /*Received from a user program through > ioctl()*/ > > if (p == NULL) { > printk("Unable to find task for process id %d\n",pid); > return; > } > > if ( send_sig(SIG_NO,p,0) != 0 ) { /* SIG_NO=51 */ > printk("Sending signal failed . . .\n"); > } > > myTimer.function = (void*)gen_sig; > myTimer.expires = jiffies + TIMER_REFRESH_SUBSCRIBED_TABLE; > add_timer (&myTimer); > return; > } > static int watchdog_init (void) { > myTimer.function = (void*)gen_sig; > myTimer.expires = TIMER_REFRESH_SUBSCRIBED_TABLE; /*Value is 1*/ > add_timer (&myTimer); > return 0; > } > int init_module(void){ > init_timer (&myTimer); > watchdog_init(); > } > > The code is working fine but it's giving the following message in > "dmesg" > ---------------------------------------------------------------------- > Debug: sleeping function called from invalid context at > mm/slab.c:2055 in_atomic():1, irqs_disabled():0 [<c011d475>] > __might_sleep+0x95/0xb0 [<c0158820>] kmem_cache_alloc+0x50/0x60 > [<d02bc000>] gen_sig+0x0/0xc0 [sighnd] > [<d02bc012>] generate_signal+0x12/0xc0 [sighnd] > [<c013f0b0>] autoremove_wake_function+0x0/0x50 > [<c012c57c>] run_timer_softirq+0xfc/0x3e0 > [<c014a592>] handle_IRQ_event+0x32/0x70 > [<c0179454>] vfs_read+0xe4/0x130 > [<c0127842>] __do_softirq+0x42/0x90 > [<c01278b7>] do_softirq+0x27/0x30 > [<c010568b>] do_IRQ+0x3b/0x70 > [<c0103ae2>] common_interrupt+0x1a/0x20 > --------------------------------------------------------------------- > This message comes on repeatedly and after some times the module > hangs up. > > Same error occurs for every function that is being called through the > timer. > > Is it wrong to call functions through timer in kernel?. Please give me > suggestions to solve this problem. you cannot sleep in interrupt context (timer code is interrupt context), the function kmalloc might sleep if not invoked with GFP_ATOMIC flag. btw, avoid doing heavy tasks in timer code, use workqueues (that execute in process context) or kernel threads (also in process context) regards, topi > Thanks > Ganesh > ganesh.p7[at]gmail.com -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ