P2L4 Thread Design Considerations - Interrupts and Signals with Threads Flashcards

1
Q

What’s the potential issue if a interrupt or signal handler needs to lock a mutex? What’s the workaround described in the Solaris papers?

A

Deadlock with itself - as stack is shared and interrupt handler is in same context as interrupted thread.

Solaris paper suggests handler in its own thread.

This way, when the thread tries to acquire the mutex, it will block just like any other thread, but will not deadlock.

Eventually the thread holding the mutex will release it, and the handling thread may acquire it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False?

  • Dynamically creating a thread on every interrupt is a relatively cheap operation.
  • If the handler doesn’t contain blocking code, execute on interrupted thread’s stack.
  • If the handler does contain blocking code, execute in its own thread
  • To reduce CPU cycles, the kernel pre-creates and initializes thread structures for interrupt routines.
A
  • False - Dynamic thread creation is expensive!
  • True
  • True
  • True
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Describe what is meant by top and bottom halves of interrupt/signal handling.

A

This refers to interrupt/signal handling that is done in two parts:

Top: the first, non-blocking, quick part done in the interrupted thread

Bottom: more complexity, allowed to block - done in separate thread.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

There are two components of signal handling. The _______ half of signal handling occurs in the context of the interrupted thread (before the handler thread is created).

This half must be ____ , non-_______ , and include a minimal amount of _________ .

Once we have created our thread, the ______ half can contain arbitrary _______ , as we have now stepped out of the context of our main program into a separate _______ .

A

There are two components of signal handling. The top half of signal handling occurs in the context of the interrupted thread (before the handler thread is created).

This half must be fast, non-blocking, and include a minimal amount of processing.

Once we have created our thread, the bottom half can contain arbitrary complexity, as we have now stepped out of the context of our main program into a separate thread.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain how handling interrupts in their own thread actually is good for performance even though it adds 40 SPARC instructions to each interrupt handling operation.

A

Case of ‘optimization for the common case’

Disabling the signal before a mutex and re-enabling after a mutex unlocked takes 12 instructions.

But mutex lock/unlock is very frequent, so we save 12 instructions many more times than we ‘waste’ 40 …

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

List 4 cases of user vs. kernel level masking of signals

A
  1. One user level signal mask enabled to one kernel level (LWP) mask enabled
  2. Two user level masks - one set to 0, one to 1. One kernel level mask set to 1
  3. Two user level masks - one set to 0, one to 1. Two kernel level masks set to 1
  4. Two user level masks - both set to 1. Two kernel level masks both set to 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Describe the reason and role of user level threading library

A

When a user level thread wants to disable a signal, it clears the appropriate bit in the signal mask, which occurs at user level. The kernel level mask is not updated.

When a signal occurs, the kernel needs to know what to do with the signal. It is possible that the kernel mask has that signal bit set to one, so from the kernel’s point of view the signal is still enabled.

If we don’t want to have to make a system call, crossing from user level into kernel level each time a user level threads updates the signal mask, we need to come up with some kind of policy.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When a ____ level thread wants to disable a signal, it clears the appropriate bit in the signal mask, which occurs at user level. The _______ level mask is not updated.

When a signal occurs, the kernel needs to know what to do with the signal. It is possible that the kernel mask has that signal bit set to one, so from the kernel’s point of view the signal is still _______.

If we don’t want to have to make a ______ ______, crossing from user level into kernel level each time a user level threads updates the signal mask, we need to come up with some kind of ______.

A

When a user level thread wants to disable a signal, it clears the appropriate bit in the signal mask, which occurs at user level. The kernel level mask is not updated.

When a signal occurs, the kernel needs to know what to do with the signal. It is possible that the kernel mask has that signal bit set to one, so from the kernel’s point of view the signal is still enabled.

If we don’t want to have to make a system call, crossing from user level into kernel level each time a user level threads updates the signal mask, we need to come up with some kind of policy.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

If both the kernel level thread and the user level thread have the bit ________, the kernel will send the signal up to the user level thread and we have no problem.

Let’s look at a more complicated scenario, in which the kernel level thread has a particular signal bit enabled, and the currently executing user level thread does not. However, there is a runnable user level thread that does have the bit enabled.

What we would like to do is to be able to ____the thread that cannot handle the signal, and _____ the thread that can.

We can achieve this by having the ___ ____ ________ ______ (which has visibility in all threads for a process) being the entity that installs the signal handler. This way, when the signal occurs, the library can invoke the scheduler to __________________________________ Once this thread is executing, the signal is passed to its handler.

A

If both the kernel level thread and the user level thread have the bit enabled, the kernel will send the signal up to the user level thread and we have no problem.

Let’s look at a more complicated scenario, in which the kernel level thread has a particular signal bit enabled, and the currently executing user level thread does not. However, there is a runnable user level thread that does have the bit enabled.

What we would like to do is to be able to stop the thread that cannot handle the signal, and start the thread that can.

We can achieve this by having the user level threading library (which has visibility in all threads for a process) being the entity that installs the signal handler. This way, when the signal occurs, the library can invoke the scheduler to swap in a thread that can handle the signal. Once this thread is executing, the signal is passed to its handler.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In the case of the threading library, give another example of optimizing for the common case

A

Thread library makes system calls requesting that the kernel level thread change its signal mask for this particular signal, disabling/enabling it.

Signals themselves occur much less frequently than does the need to update the signal mask. Updates of the signal mask are cheap. They occur at the user level and avoid system calls.

Signal handling becomes more expensive - as system calls may be needed to correct discrepancies - but they occur less frequently so we the added cost is acceptable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

“Signals themselves occur much less frequently than does the need to update the signal mask” is a reason for applying which principle?

A

Optimize for the common case

How well did you know this?
1
Not at all
2
3
4
5
Perfectly