Re: query about schedule.

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

 



On Fri, 2002-05-24 at 00:54, Sudeep Rege wrote:
> Hi,
> 
> I have the following piece of code which is written for a device read
> file_operation, I want a process to block till a packet queue becomes
> non-zero in length...
> 
> .
> .
> .
> set_current_state (TASK_INTERRUPTIBLE);
> for (;!skb_queue_len (&p->pkt_queue);) {
> 	schedule ();
> 	if (signal_pending (current)) {
> 		/* ouch! another doubt */
> 		rv = -ERESTARTSYS;
> 		goto ret;
> 	}
> }
> .
> .
> .
> ret:
> 	set_current_state (TASK_RUNNING);
> 	schedule ();
> 	return rv;
> }
> .
> .
> .
> 
> I want to know the following:
> 
> 1. does schedule return immediately, or blocks by shifting
> CPU attention to another process (because we are not TASK_RUNNING)
> 

schedule() invokes the scheduler, which generally swaps the current
process out and swaps in a new process to run on that CPU. Depending on
the priority of the calling process, and the number of other processes
in the runqueue, the scheduler may choose the calling process as the
next process to run, in which case schedule() returns almost
immediately. But generally, it blocks.

> 2. if not, does this mean a busy wait
> 
> 3. when schedule returns, are we TASK_RUNNING
>

Yes.
 
> Please comment on the above code.
> 
> Since I ensure that only one process will be waiting on a particular
> queue, I do not want to use a wait queue.
>

Nevertheless, you may want to check out the wait_event_interruptible()
call (described in Linux Device Drivers, Chapter 5:
http://www.xml.com/ldd/chapter/book/ch05.html). It basically does the
same thing you are trying to do; in fact, what you've written above is
very similar to wait_event_interruptible() in <linux/sched.h>. I haven't
used it myself yet, but I think you could do something like:

wait_queue_head_t wq;
init_waitqueue_head(&wq);
.
.
.
ret = wait_event_interruptible(&wq, !skb_queue_len(&p->pkt_queue));
if (ret)
	return ret; /* return value is -ERESTARTSYS if a 
	             * signal is pending. */
.
.
.
<rest of function, if no signal pending>
.
.
.

Anyway, it's something to think about...
 
> Thanks in advance
> 
> --
> Sudeep
> 

-- 
Trevor Hamm

--
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