RootPhoenix
RootPhoenix

Reputation: 1767

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?

Upvotes: 10

Views: 285

Answers (2)

Jeremy Kerr
Jeremy Kerr

Reputation: 1935

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.

Upvotes: 1

Surajit
Surajit

Reputation: 21

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.

Upvotes: 0

Related Questions