RE: How do I make a kernel module "sleep" without affecting other kernel modules?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Yes, you can use schedule_timeout() if you don't need to wait on a condition
to change before timeout expires. 
Now, I've got news....
Schedule_timeout() internally calls kernel timer functions (init, add,
del_sync). Value "expire" for timer is calculated as
jiffies+requested_ticks. No check is done for wraps unless it is done within
timer functions that I really doubt. So either way we are not 
protected :)...
  
Konstantyn


-----Original Message-----
From: Greg KH [mailto:greg@xxxxxxxxx] 
Sent: Tuesday, November 30, 2004 1:01 PM
To: Prokopenko, Konstantyn
Cc: 'Karthik Subramanian'; kernelnewbies
Subject: Re: How do I make a kernel module "sleep" without affecting other
kernel modules?

On Tue, Nov 30, 2004 at 09:25:11AM -0500, Prokopenko, Konstantyn wrote:
> Hello,
> 
> If no external event is there to interrupt your module, you can implement
> simple function to sleep number of ticks:
> 
> Note: Each tick = 1000/HZ where HZ = scheduler frequency (defined in
> asm/param.h)
> 
> void dev_wait(unsigned long ticks)
> {
>     unsigned long awake = jiffies+ticks;
> 
>     current->policy |= SCHED_YIELD
>     while(awake > jiffies)
>         schedule();
> }

No, what happens when jiffies wraps, directly comparing things with
jiffies is not good, please use the wrapper functions for that.

Just use schedule_timeout() if you want to do something like this.

thanks,

greg k-h

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/




[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux