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.
Find the answer to your Linux question:
New to Linux Forums? Register here for free!
    Linux Forums > GNU Linux Zone > The Linux Kernel > how to create kernel thread in 2.6 - ??

Forgot Password?
 The Linux Kernel   Compiling, theory, programming or other discussion about the linux kernel

Site Navigation
Linux Articles
Linux Forums
Linux Downloads
Linux Hosting
Free Magazines
Job Board
IRC Chat
RSS Feeds


Linux Forum Topics
Linux Forums
Your Distro
Linux Resources
GNU Linux Zone
The Community
Reply
 
Thread Tools Display Modes
Old 10-18-2009   #1 (permalink)
Just Joined!
 
Join Date: Oct 2009
Posts: 5
how to create kernel thread in 2.6 - ??

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,
vlyamtse is offline  


Reply With Quote
Old 10-18-2009   #2 (permalink)
Linux Guru
 
coopstah13's Avatar
 
Join Date: Nov 2007
Location: NH, USA
Posts: 1,758
3rd edition of this book covers 2.6 kernel. Fortunately it has been open sourced and is available online in PDF format here.
coopstah13 is offline   Reply With Quote
Old 4 Weeks Ago   #3 (permalink)
Just Joined!
 
Join Date: Oct 2009
Posts: 5
O'Reilly 3-rd edition is still outdated, For example, the book:

INIT_WORK(struct work_struct *work, void (*function)(void *), void *data);
In reality, current 2.6 kernel defines INIT_WORK with 2 arguments

INIT_WORK(struct work_struct *work, void (*function)(work_struct *));
vlyamtse is offline   Reply With Quote
Old 4 Weeks Ago   #4 (permalink)
Linux Guru
 
coopstah13's Avatar
 
Join Date: Nov 2007
Location: NH, USA
Posts: 1,758
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.
coopstah13 is offline   Reply With Quote
Old 4 Weeks Ago   #5 (permalink)
Just Joined!
 
Join Date: Oct 2009
Posts: 5
re:

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?
vlyamtse is offline   Reply With Quote
Old 4 Weeks Ago   #6 (permalink)
Linux Guru
 
coopstah13's Avatar
 
Join Date: Nov 2007
Location: NH, USA
Posts: 1,758
You could try asking on the mailing list.
coopstah13 is offline   Reply With Quote
Old 4 Weeks Ago   #7 (permalink)
Just Joined!
 
Join Date: Oct 2009
Posts: 5
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);
..
}


}
DECLARE_WORK(work, thread_func, (void*) NULL);
static int hello_init(void)
{
printk("Hello, world\n"winking smiley;
schedule_work(&work);
return 0;
}
vlyamtse is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Free Magazines
Run Your Own Web Server Using Linux & Apache - Free 191 Page Preview
Learn about everything you'll need to build and maintain your Linux servers, and to deploy Web applications to them.
subscribe
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



All times are GMT. The time now is 03:45 PM.






© 2000 - 2009 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.3.0 RC2