Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull request partial deadlock fix #3

Closed
wants to merge 5 commits into from

Conversation

tinti
Copy link

@tinti tinti commented Jul 24, 2013

The OSAL api uses a global lock to perform some operations using mutex,
semaphores, queues and so. This leads to a possible deadlock in the program
due the following situation.

Let "I" be the timer interrupt (SIG63):

   |[Thread 1]
   |  ...
   |  call OS_TaskGetInfo
   |    ...
   |    lock(global)
   |    ...
   +--------------------+
                        |[Interrupt]
                        |  ...
                        |  call OS_TaskGetInfo
                        |    ...
                        |    lock(global)  // DEADLOCK

There are some possible solutions to avoid this problem. One is to never use any
OSAL primitives on the interrupt context, which quite limit the library. Other
would be block all signals during the global lock and let them be pending. This
approach may introduce poor performance. Other would be find out how to remove
these global locks. Another could be use safe locks on interrupt handler.

This patch implements the blocking signals solution because it is the best
trade-off of the current solutions.

tinti added 5 commits June 6, 2013 16:06
The tick duration in microseconds may be calculated to zero depending on the
processor clock speed.

This patch sets it to 1 if the value is 0.

Signed-off-by: Vinicius Tinti <[email protected]>
Map all OSAL internal types to common types already defined in <stdint.h>. Also
adding support for x86_64.

Signed-off-by: Vinicius Tinti <[email protected]>
The OSAL api uses a global lock to perform some operations using mutex,
semaphores, queues and so. This leads to a possible deadlock in the program
due the following situation.

  Let "I" be the timer interrupt (SIG63):

       |[Thread 1]
       |  ...
       |  call OS_TaskGetInfo
       |    ...
       |    lock(global)
       |    ...
  I----+--------------------+
                            |[Interrupt]
                            |  ...
                            |  call OS_TaskGetInfo
                            |    ...
                            |    lock(global)  // DEADLOCK

There are some possible solutions to avoid this problem. One is to never use any
OSAL primitives on the interrupt context, which quite limit the library. Other
would be block all signals during the global lock and let them be pending. This
approach may introduce poor performance. Other would be find out how to remove
these global locks. Another could be use safe locks on interrupt handler.

This patch implements the blocking signals solution because it is the best
trade-off of the current solutions.

There is also a single special case which is not handled by this patch.

Signed-off-by: Vinicius Tinti <[email protected]>
Signed-off-by: Vinicius Tinti <[email protected]>
@skliper
Copy link
Contributor

skliper commented Sep 3, 2019

OSAL primitives in general are not intended to be interrupt safe. Feel free to implement and open source interrupt safe versions if you'd like, but not planning to overhaul the framework OSAL examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants