use of spin variants in network processing

非 Y 不嫁゛ 提交于 2019-12-08 15:41:20

问题


I have written a Kernel module that is interacting with net-filter hooks. The net-filter hooks operate in Softirq context.

I am accessing a global data structure "Hash Table" from the softirq context as well as from Process context. The process context access is due to a sysctl file being used to modify the contents of the Hash-table.

I am using spinlock_irq_save.

Is this choice of spin_lock api correct ?? In terms of performance and locking standards.

what would happen if an interrupt is scheduled on another processor? while on the current processor lock is already hold by a process context code?


回答1:


Firstly:

So, with all the above details I concluded that my softirqs can run concurrently on both cores.

Yes, this is correct. Your softirq handler may be executed "simultaneously on more than one CPU".

Your conclusion to use spinlocks sounds correct to me. However, this assumes that the critical section (ie., that which is executed with the spinlock held) has the following properties:

  • It must not sleep (for example, acquire a blocking mutex)
  • It should be as short as possible

Generally, if you're just updating your hash table, you should be fine here.

If an IRQ handler tries to acquire a spinlock that is held by a process context, that's fine. As long as your process context does not sleep with that lock held, the lock should be released within a short amount of time, allowing the IRQ handler to make forward progress.




回答2:


I think the solution is appropriate . Softirqs anyways runs with preemption disabled . To share a data with a process, the process must also disable both preemption and interrupts. In case of timer, which only reduces the time stamp of an entry can do it atomically i.e. the time stamp variable must be atomic. If in another core softirqs run and wants to acquire the spinlock, when it is already held in the other core,it must wait.



来源:https://stackoverflow.com/questions/33081481/use-of-spin-variants-in-network-processing

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