LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-29-2007, 03:10 PM   #1
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Rep: Reputation: 30
Kernel Module Writing


How would you use sleep in a kernel module? would you suggest wait_event_interruptible()?
I want to use timed delays.


Code:
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/unistd.h>
#include <linux/module.h>
#include <linux/sched.h>


MODULE_DESCRIPTION("My kernel module");
MODULE_AUTHOR("Itzhak A. (itz2000+LKMPOST[@]gmail.com)");
MODULE_LICENSE("$LICENSE$");

static int c_proj_hello_module_init_module(void)
{
//sleep?
	return 0;
}

static void c_proj_hello_module_exit_module(void)
{
	printk( KERN_DEBUG "Module c_proj_hello_module exit\n" );
}

module_init(c_proj_hello_module_init_module);
module_exit(c_proj_hello_module_exit_module);

would give me :
Code:
root @ WhiteCastle ~ $ insmod /lib/modules/2.6.21.5-smp/kernel/drivers/misc/c_proj_hello_module-driver.ko
insmod: error inserting '/lib/modules/2.6.21.5-smp/kernel/drivers/misc/c_proj_hello_module-driver.ko': -1 Unknown symbol in module


Thanks for your help.

Last edited by itz2000; 12-06-2010 at 11:28 AM.
 
Old 09-29-2007, 04:27 PM   #2
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
You cannot sleep() in a kernel module. Take a look at wait_event_interruptible(). Also, if you want timed delays, take a look at setting/using timers and having them trigger interrupts to force a return from wait_event_interruptible().
 
Old 09-29-2007, 06:04 PM   #3
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by jiml8 View Post
You cannot sleep() in a kernel module. Take a look at wait_event_interruptible(). Also, if you want timed delays, take a look at setting/using timers and having them trigger interrupts to force a return from wait_event_interruptible().
Manuals for kernel code needs improvement...

Last edited by itz2000; 12-06-2010 at 11:25 AM.
 
Old 09-29-2007, 07:56 PM   #4
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
google is your friend.

At least, it is for things like this.
 
Old 09-29-2007, 11:36 PM   #5
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Original Poster
Rep: Reputation: 30
Thanks...

Last edited by itz2000; 12-06-2010 at 11:24 AM.
 
Old 09-30-2007, 12:00 AM   #6
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
When I googled for it I came up with pages of responses, including one for an online book about the Linux kernel, and a link to the online versions of the O'Reilly books about Linux device drivers. The O'Reilly book is the best resource, and it can be downloaded as HTML or as PDF. Don't have a link offhand, but it is out there.
 
Old 10-05-2007, 04:54 PM   #7
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by jiml8 View Post
When I googled for it I came up with pages of responses, including one for an online book about the Linux kernel, and a link to the online versions of the O'Reilly books about Linux device drivers. The O'Reilly book is the best resource, and it can be downloaded as HTML or as PDF. Don't have a link offhand, but it is out there.
...

Last edited by itz2000; 12-06-2010 at 11:24 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Tutorial for writing cypher kernel module ta0kira Programming 7 06-19-2011 11:43 PM
need help in writing Makefile for module in 2.6 kernel videsh Programming 1 01-19-2006 08:35 AM
need help in writing Makefile for module in 2.6 kernel videsh Linux - Software 3 01-19-2006 08:30 AM


All times are GMT -5. The time now is 11:40 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration