interruptible_sleep_on

Oct 11, 2006 5 Replies

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



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

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) { .. ..

hi vib, 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:

Should the waiting be done in the program (user land) or in the driver (Kernel mode ?)

If in the driver "Linux device drivers" recommends using MUTEX semaphores via "up()", "down()" and friends.

-Michael

Hi Vib,

You need write wake_up function in your code, otherwise, how could the thread in sleep status have the chance to run? You have to wake up your sleeping thread in somewhere.

Take care,

vib wrote:

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required