Welcome to Linux Forums! With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.
Write an article for LinuxForums Today! Win Great Prizes!
i am trying to find some info on how to create/ destroy kernel thread. There's enough examples for it, including samples from "Linux Device Drivers" book. The problem is: all describe 2.4 kernel and api is changed pretty dramatically for 2.6. I've been trying to hack something together, using bits and pieces from different kernel groups
void thread_func( struct work_struct *arg)
{
int i;
wait_queue_head_t wq;
printk("<1>::Inside Thread Function::\n");
init_waitqueue_head(&wq);
for (i=0; i < 100; i++) {
interruptible_sleep_on_timeout(&wq, HZ);
printk("HELLO THREAD ITERATION %d...\n", i);
}
}
When i try to create it in init_module:
...
work_struct ws;
INIT_WORK(&ws, thread_func);
/* and schedule it for execution */
schedule_work(&ws);
The thread is created ( i see "HELLO THREAD" messages printed in dmesg log) but init_module
never return control - the "insmod ./hello.ko" runs forever.
Can someone points me what the problem might be?
Also, is there some tutorials on LKM development for 2.6 kernels?
Thank you,
As it says, it is current as of 2.6.10 kernel. Your mileage will vary, the API's are constantly changing, you will have to scour some kernel mailing lists.
I did checking on mailing lists. Found plenty of mails complaining about that change.
Did not found anything explaining how to use it ( INIT_WORK) in new context, specifically,
how to pass the data to thread function expecting work_struct* as argument.
Have i been checking the wrong mailing lists?
Here's another thread issue: looks like the thread "sleep" blocks hardware interrupts. Here's simple thread function that makes 10 iterations with going to sleep for some interval of time. While thread function is running, the system is "loosing" input devices, e.g. keyboard and mouse
become nonfunctional. I wonder what the reason is. The "sleep" task is specified as interruptible, there should be no problems with hardware interrupts.
I also tried wait_event_interruptible_timeout - with the same result.
I am missing something ??
void thread_func(void *ptr)
{
int i;
printk("Hello kthread started\n"winking smiley;
for (i=0; i < 10; i++)
{
printk("kthread sleep iteration %d\n", i);
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout (4*HZ);
..
}
Open Source Security Myths Dispelled Dispel the five major myths surrounding Open Source Security and gain the tools necessary to make a truly informed decision for your IT organization subscribe
InformationWeek InformationWeek is the only newsweekly you'll need to stay on top of the latest developments in information technology. subscribe