Need for signals in the real time environment

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
AnishaKaul
Member
Member
Posts: 41
Joined: Thu Apr 19, 2012 12:29 am
Location: Gurgaon, India
Contact:

Need for signals in the real time environment

Post by AnishaKaul »

From: http://www.linuxfordevices.com/c/a/Linu ... Interface/
The resultant POSIX support is similar to standard Linux threads, except that parent-child functions (which are not appropriate for real-time tasks, since all threads are considered to be part of a single process) and signal handling (which is currently in development) are not supported.
I am not sure if I am missing some point here.
They say that in real time it makes sense for all the threads to be under one parent. Fine. But in this case then why would they need to implement signals? Signals are used for inter "process" communications.

What's the point that I am missing? Are they saying something else?
http://500px.com/Anisha_Kaul/photos
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: Need for signals in the real time environment

Post by turdus »

AnishaKaul wrote:I am not sure if I am missing some point here.
They say that in real time it makes sense for all the threads to be under one parent. Fine. But in this case then why would they need to implement signals? Signals are used for inter "process" communications.

What's the point that I am missing? Are they saying something else?
Signals can be send not only in parent-child scenario (vertical), but in side-by-side (horizontal) too.

Let's assume you have one parent, and a few children implementing some kind of pipelining. In this case one child has to signal the next that it's done with it's part, and the input is ready for the next child. No signals sent to the parent, yet without signaling it would be impossible to synchronize chidren.

See manual page on signals, namely real time signals (they differ from normal signals in a way they can send a context pointer along too).
User avatar
AnishaKaul
Member
Member
Posts: 41
Joined: Thu Apr 19, 2012 12:29 am
Location: Gurgaon, India
Contact:

Re: Need for signals in the real time environment

Post by AnishaKaul »

turdus wrote:Let's assume you have one parent, and a few children implementing some kind of pipelining. In this case one child has to signal the next that it's done with it's part, and the input is ready for the next child. No signals sent to the parent, yet without signaling it would be impossible to synchronize chidren.
That's very helpful. Thanks.
One more question:
Since in their case they haven't got signals yet, so what can be the possibilities of synchronization in their case?
I have heard the RTAI "is" commonly used. So, they must be having a workaround for the missing signals?
turdus wrote:See manual page on signals, namely real time signals (they differ from normal signals in a way they can send a context pointer along too).
Ah, haven't heard of real time signals. Will check out soon. Thanks.
http://500px.com/Anisha_Kaul/photos
User avatar
turdus
Member
Member
Posts: 496
Joined: Tue Feb 08, 2011 1:58 pm

Re: Need for signals in the real time environment

Post by turdus »

AnishaKaul wrote:Since in their case they haven't got signals yet, so what can be the possibilities of synchronization in their case?
I have heard the RTAI "is" commonly used. So, they must be having a workaround for the missing signals?
Well, I was not precise. You don't need signals, but you need the functionality they provide.
The point is, when a signal arrives, it's handler get called. So when a signal delivered, the process will execute code that the sender expects. You have other methods for that, sure. The point is, you have to stop or make faster a process (or use any other methods like handler), so when the other process wants to talk to it, it must be at a known state.

For example, let's say there's A and B, executing instructions:
A: qwerty
B: asdfgh
for proper functioning A has to execute "e" when B is executing "s", else their communication will be a mess. With signals you can put "erty" in a signal handler in A, and insert a send signal before "s" in B (it's not necessarily the best solution, but correct). This method mostly used when a process can have several independent "discussions" with other processes.

You can also use a busy-wait for that. In this case before "e" you insert an infinite loop (which is infinite because it's expression not modified inside the loop by A). Now in B, before "s" you put an instruction that modifies A's exit criteria (involves IPC or shared memory, since A and B have different address spaces). So when A executes "w", it won't continue to "e", rather wait in a loop. When B executes it's modifier instruction, it will allow A to continue, and go to "s". This way again "e" and "s" will run simultaneously. The busy-wait's exit criteria is usually a boolean and often helped by hardware (like x86's bts (bit test and set) instruction or cmpxchg (compare-and-exchange) etc.).
Although busy-wait look simpler, I would not recommend it, as it's eating up precious cpu time (hence the name busy).

Because of similarities, this point of instructions (after which they will run synchronized) is often called a randezvous point.

It's also important to understand how critical section (mutual exclusion) and synchronization related. Let's assume we have two variables on shared memory. Only one process allowed to access them at a time. For this let's say we have instruction 1 (writing value to variable #1) and 2 (writing to variable #2). We have A and B like
A: 1212
B: 1212
This means that they both wants to write the variables at the same time, which is bad.
11
22
11
22
With synchronization, you can make them like
A: b1212
B: 1k212
(where b means busy-wait, and k is for kill (like in send signal, but remember, it's just an analogy)). Now before A can execute 1, it will stuck in a loop. So when B executes 1, it's okay. When B finishes, it notifies A that it can continue, and go on with 2. When A executes 1, B is executing 2, so no problem here:
1x
21
12
21
x2

There's even more, but it's far beyond the scope of a post. There's many articles and books on the topic.
Few keyword to search for: randezvous point, semaphores, spinlocks, monitors (special language constructions), Dijkstra's sleeping barber problem.
User avatar
AnishaKaul
Member
Member
Posts: 41
Joined: Thu Apr 19, 2012 12:29 am
Location: Gurgaon, India
Contact:

Re: Need for signals in the real time environment

Post by AnishaKaul »

Thanks turdus for explaining all that in detail. Yes it is dumb of me to forget that POSIX
signals are only a kind of API, so if they don't use POSIX, they must be doing it in some
other way! :doh:

I knew about critical sections and synchronization. Your post provided a good refreshment.
Thankful to you for your time. It is sad to see that this forum doesn't have any kind of
reputation system. :(
http://500px.com/Anisha_Kaul/photos
Post Reply