Do you have a question? Post it now! No Registration Necessary
Subject
- Posted on
interruptible_sleep_on
- 10-11-2006
October 11, 2006, 5:37 am

Hi there,
I've two threads respectively used for reading from and writing to a
device through device driver. In order to efficiently use the CPU
resources, respected system-level read or write function has the
ability to put the calling thread to sleep. Here are my questions:
For instance in the device driver code below, i) how do I know that the
&ivm_wq_out is referring to the calling thread, READThread?
Device driver:
my_read(..)
{
if ( condition_true )
interruptible_sleep_on(&my_wq_out);
}
similar, ii) how do I know that the &my_wq_in is referring to the
calling thread, WRITEThread.
my_write(..)
{
if ( condition_true )
interruptible_sleep_on(&my_wq_in);
}
User application:
READThread(void)
{
while(1)
{
..
read(fd, buf, len);
..
}
WRITEThread(void)
{
while(1)
{
..
write(fd, buf, len);
..
}
Thanks in advance. Very appreciate your comments.
vib
I've two threads respectively used for reading from and writing to a
device through device driver. In order to efficiently use the CPU
resources, respected system-level read or write function has the
ability to put the calling thread to sleep. Here are my questions:
For instance in the device driver code below, i) how do I know that the
&ivm_wq_out is referring to the calling thread, READThread?
Device driver:
my_read(..)
{
if ( condition_true )
interruptible_sleep_on(&my_wq_out);
}
similar, ii) how do I know that the &my_wq_in is referring to the
calling thread, WRITEThread.
my_write(..)
{
if ( condition_true )
interruptible_sleep_on(&my_wq_in);
}
User application:
READThread(void)
{
while(1)
{
..
read(fd, buf, len);
..
}
WRITEThread(void)
{
while(1)
{
..
write(fd, buf, len);
..
}
Thanks in advance. Very appreciate your comments.
vib

Re: interruptible_sleep_on

Hi vib,
Threads instruction pointer gets stored in the wait_queue
structure when the queue gets initialized.It uses the function
current_text_address() function to get the current instruction pointer
address.Guess this would directly lead to the corresponding thread
which would have created the queue.Correct me if u thnk im wrong.
-kaushal


Re: interruptible_sleep_on
hi Kaushal,
Thanks for the input. I can't really comment. As far as the user
program is concerned, it has not started yet at the point the device
driver starts and initailizes the init_waitqueue_head. See code below.
int init_module(void)
{
..
..
init_waitqueue_head(&my_wq_out);
init_waitqueue_head(&my_wq_in);
...
...
return(0);
}
back to the question, how the system knows that my_wq_in and my_wq_out
are respectively referring to READThread and WRITEThread?
krishna wrote:

Thanks for the input. I can't really comment. As far as the user
program is concerned, it has not started yet at the point the device
driver starts and initailizes the init_waitqueue_head. See code below.
int init_module(void)
{
..
..
init_waitqueue_head(&my_wq_out);
init_waitqueue_head(&my_wq_in);
...
...
return(0);
}
back to the question, how the system knows that my_wq_in and my_wq_out
are respectively referring to READThread and WRITEThread?
krishna wrote:


Re: interruptible_sleep_on
Ur explanation goes right there.Guess it has got nothing to do
with our threads.Besides the assignment from the function
current_text_address() is in conditional compilation for wait queue
debug.Coming to ur question:
read thread is performing 'read' in an infinite loop.this read would
get mapped to the myread() in the device driver which is dealing with
the my_wq_out alone.similarly write would get mapped to mywrite() which
is dealing with the my_wq_in alone.This mapping is done with the help
of filename (in user space) ,file_operations structure (kernel space)
and major number(both user and kernel spaces).
If we look into the tcb structure for a process,task_struct,we shud be
finding entries for pointing to the threads in that process.So a unique
tuple of thread id,file_operations structures' sub function
pointer(mywrite(),myread()...) shud be available which is nothing but
the requrired link.
-kaushal
vib wrote:

Site Timeline
- » USB: how transmit more than wMaxPacketSize of bulk data in one submission ?
- — Next thread in » Embedded Linux
-
- » Any one has some time for CF testing
- — Previous thread in » Embedded Linux
-
- » Crosscompiling for ARM: reloc type R_ARM_ABS32 is not supported for PIC - ...
- — Newest thread in » Embedded Linux
-
- » Driver LED BP5131 - jak to dziaĆa?
- — The site's Newest Thread. Posted in » Electronics (Polish)
-
- » easy way to calibrate audio frequency generator?
- — The site's Last Updated Thread. Posted in » Electronics Repair
-