Re: Sleeping

Eberhard Moenkeberg (emoenke@gwdg.de)
7 Sep 1996 17:06:42 GMT


Colten Edwards (edwards@panasync.canuck.ca) wrote:

: I haven't been able to find this anywhere, but I need to know what a good
: way to sleep within a kernel module is. I found something called
: lcdpanel-0.50.tar.gz on sunsite and have made the LCD device and compiled
: the module, but I noticed that the module uses for (t=0; t <3000; t++) ;
: for sleeping which is not a good way to wait in the kernel, so I'd like
: to replace it. I tried usleep but that's a lib function so is unsuitable.
: The function is called thusly,

: static int lcd_write (struct inode *inode, struct file *file, const char
: *buf, int count)

3000 times t++ is fairly short these days.
If your time is long enough, you can do something like:

/*
* kernel mode waiting, time unit is jiffy (10 ms)
*/
static void jiffy_sleep(u_int time)
{
current->state = TASK_INTERRUPTIBLE;
current->timeout = jiffies + time;
schedule();
}

The task gets re-scheduled if the time has elapsed.
Calling it with 0 gives an indefinite short time, just allowing
other kernel mode tasks to get the CPU.

Cheers -e

-- 
Eberhard Moenkeberg                         GGG   W   W  DDDD    GGG
                                           G      W   W  D   D  G
E-Mail:   emoenke@gwdg.de                  G GGG  W   W  D   D  G GGG
Phone: +49 551 2011551  Fax: +49 551 21119 G   G  W W W  D   D  G   G
SnailMail:                                  GGG   WW WW  DDDD    GGG
Gesellschaft fuer wissenschaftliche Datenverarbeitung mbH
Am Fassberg, D-37077 Goettingen, GERMANY
At home: Modem ("guest") ++49-551-7704102, ISDN-HDLC 7704103