Why can the kernel be stuck by a busy kernel thread ?
Hi, I code a kernel module which do some nop. When inserted into the kernel, the kernel will be stuck and can not reponse my keypress anymore. So, I have to reboot to get out. Why? #include <linux/init.h> #include <linux/module.h> #include <linux/kernel.h> #include <linux/kthread.h> struct task_struct *ktask = NULL; static int thread_func(void *data) { int i; while (!kthread_should_stop()){ for (i = 0; i < 1000; i++){ asm volatile ("nop\n\t"); } } return 0; } static int tst_init(void) { ktask = kthread_run(thread_func, NULL, "mythread"); return 0; } static void tst_exit(void) { if (ktask){ kthread_stop(ktask); ktask = NULL; } } module_init(tst_init); module_exit(tst_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Parmenides"); MODULE_DESCRIPTION("Something.");
On Fri, Oct 14, 2011 at 5:04 PM, Parmenides <mobile.parmenides@gmail.com> wrote:
Hi,
I code a kernel module which do some nop. When inserted into the kernel, the kernel will be stuck and can not reponse my keypress anymore. So, I have to reboot to get out. Why?
Is kernel preemption activated? Could you check for # grep CONFIG_PREEMPT .config? thanks, Daniel.
On Fri, Oct 14, 2011 at 23:43, Parmenides <mobile.parmenides@gmail.com> wrote:
2011/10/14 Daniel Baluta <daniel.baluta@gmail.com>:
Is kernel preemption activated? Could you check for # grep CONFIG_PREEMPT .config?
Yes. I really have not select CONFIG_PREEMPT option. Now, I turn it on and things are ok. Thanks a lot.
As you can easily derive, quite likely you didn't enable kernel level preemption before, and since kernel thread only operates in kernel mode and you made it just spinned there...so there you go..... -- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com
participants (3)
-
Daniel Baluta -
Mulyadi Santosa -
Parmenides