Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

use of spin variants in network processing

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?

like image 718
RootPhoenix Avatar asked Oct 12 '15 12:10

RootPhoenix


1 Answers

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.

like image 187
Jeremy Kerr Avatar answered Nov 16 '22 23:11

Jeremy Kerr