Implementing rendezvous_wait system call

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

 



Hi,
 
I am writing a system call which is called as rendezvous_wait(). This system call is passed a character which would act as a kind of identifier. My application program will create threads and each thread will call rendezvous_wait with a character. Consider thread1 calls the system call passing x. Since it is the first one to call that system with parameter x, thread1 will be pushed on a wait list. i.e. kernel should force it to sleep. Whenever any other thread calls rendezvous_wait() with same parameter x, thread1 should be taken out from the wait queue and put on the run queue, which could later be scheduled by the scheduler. This system call is called as rendezvous_wait because it is much similar to meeting where one person waits for other and when other comes, they both live for some another location.
 
I have partly implemented the system call using wait_event_interruptible() and wake_up_interruptible() functions and it is working properly for two threads. However, when more than 2 threads do a rendezvous, it doesn't work as expected. Here is an excerpt of printks in /var/log/messages
 
for a successful run -
Apr 28 19:52:43 tjw099 kernel: Semaphore is = a
Apr 28 19:52:43 tjw099 kernel: index = 0
Apr 28 19:52:43 tjw099 kernel: thread 1700 (test1) is going to sleep
Apr 28 19:52:43 tjw099 kernel: Semaphore is = a
Apr 28 19:52:43 tjw099 kernel: index = 0
Apr 28 19:52:43 tjw099 kernel: thread 1701 (test1) has arrived
Apr 28 19:52:43 tjw099 kernel: woke up the blocked thread
Apr 28 19:52:43 tjw099 kernel: Unblocking thread 1700
 
And for unsuccessful run ( more realistic application with 4 threads wanting to rendezvous )

Apr 28 20:05:38 tjw099 kernel: Semaphore is = a
Apr 28 20:05:38 tjw099 kernel: index = 0
Apr 28 20:05:38 tjw099 kernel: thread 1750 (test1) is going to sleep
Apr 28 20:05:38 tjw099 kernel: Semaphore is = b
Apr 28 20:05:38 tjw099 kernel: index = 1
Apr 28 20:05:38 tjw099 kernel: thread 1751 (test1) is going to sleep
Apr 28 20:05:38 tjw099 kernel: Semaphore is = a
Apr 28 20:05:38 tjw099 kernel: index = 0
Apr 28 20:05:38 tjw099 kernel: thread 1752 (test1) has arrived
Apr 28 20:05:38 tjw099 kernel: woke up the blocked thread
Apr 28 20:05:38 tjw099 kernel: Unblocking thread 1751
Apr 28 20:05:38 tjw099 kernel: Unblocking thread 1750
Apr 28 20:05:38 tjw099 kernel: Semaphore is = b
Apr 28 20:05:38 tjw099 kernel: index = 1
Apr 28 20:05:38 tjw099 kernel: thread 1753 (test1) has arrived
Apr 28 20:05:38 tjw099 kernel: woke up the blocked thread

As said earlier, in above log, when thread 1752 arrives, it wakes up all threads in the wait list. Looks like there is no available functionality to implement a selective wake-up. Any idea of how to go about implementing a selective wake up ? I think we need to maintain our own similar wait list and manually move threads from wait list to run list. But is there any code available to do such things?

Please let me know what you guys think.

Regards,
Onkar Deshpande

[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