lockdep: debugging deadlocks
Locking mechanisms are often used in embedded systems to ensure that hardware resources are not accessed simultaneously. As embedded software engineers, we know that incorrectly using locking mechanisms can result in a deadlock. A deadlock occurs when a system stalls because multiple software entities are vying for the same hardware resource. The following figure shows how a deadlock may occur (borrowed from https://www.mathworks.com/products/polyspace/static-analysis-notes/what-deadlocks-how-prevent-during-software-development.html):

Figure 12.7 – Deadlock occurrence
The following sequence occurs in the preceding figure:
- Task 1 uses Mutex #1 to lock Shared Resource #1. Task 1 attempts to use Mutex #2 to lock Shared Resource #2.
- Task 2 preempts Task 1 and uses Mutex #2 to lock Shared Resource #2.
- Then, Task 2 attempts to use Mutex #1 to lock Shared Resource #1. However, since Task 1 is already holding the lock...