Synchronisation between process context and timer function

安稳与你 提交于 2019-12-11 04:42:07

问题


I want to update a data structure atomically in both process context (in queuecommand function to be specific) and timer function. In process context, should I use spin_lock_bh or spin_lock_irq or just spin_lock?

As per my understanding, we should use spin_lock_bh in queuecommand (process context) and just spin_lock in timer function. Am I correct?


回答1:


If I understand correctly, it is about timer_list (bottom half context). Then your assumption is correct: yes, it would be sufficient to use spin_lock_bh in process context and spin_lock in timer handler (function of timer_list). But this is true only if that lock (and the corresponding data structure) is used only in the mentioned contexts is not used it interrupt handler. If so, you need e.g. spin_lock_irq.

Also keep in mind that you shouldn't use sleep-able functions inside spin_lock*-spin_unlock*.

There are a lot of examples in Linux kernel sources, e.g.:

  • spin_lock in timer + spin_lock_bh in process context;
  • spin_lock in interrupt handler and spin_lock_irq in timer.


来源:https://stackoverflow.com/questions/52934695/synchronisation-between-process-context-and-timer-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!