1

I have some data that are shared between a tasklet, a timer, and a kthread on a SMP ARM. What is the proper type of spin lock to use?

According to Cheat Sheet For Locking, it seems like a regular spin_lock()/spin_unlock() would do the job. But as this is purely bottom halves, shouldn't spin_lock_bh() be enough?

Thanks!

2 Answers 2

0

You need to use spin_lock_bh here because you're sharing a data structure between a tasklet and a kthread.

Using only a spin_lock may result in a deadlock:

  1. kthread takes lock
  2. irq occurs
  3. softirq runs after leaving irq context
  4. your tasklet runs
  5. tasklet tries to take lock
Sign up to request clarification or add additional context in comments.

Comments

0

spin_lock() might lead to deadlock issues. Consider a case where process acquires lock for critical section and a software interrupt arrives on same CPU which also tries to acquire the same lock which process have. This is case of deadlock where none process can move forward. Hence we require that when spinlock acquired on CPU, local software interrupts should be disabled. This is done by spin_lock_bh().

Hence when a data structure is shared between a process context and bottom half, it is secured by spin_lock_bh().

However, sharing of data structure between process context and bottom half is not recommended unless extremely necessary to do. Per-cpu variables could be a replacement to avoid locking.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.