There is raw variant of each spin lock available in linux kernel, I want to know its usage ? e.g. :
raw_spin_lock()
, raw_spin_lock_irqsave()
, etc.
spin_lock_irq will disable the interrupt x and take the the lock. spin_unlock_irq will enable the interrupt x.
Spinlock works by making sure nothing else will run. If you don't want an interrupt to run you disable it and proceed safely into the critical section. On multicore machine a spinlock will actually spin waiting for another core that holds the lock to release it.
A spinlock implementation requires a special kind of instruction known as a read-modify-write (RMW) instruction. These expensive operations are useful because they act atomically preventing a data race in multithreaded kernels.
All semaphore API is located in the include/linux/semaphore. h header file. We may see that the semaphore mechanism is represented by the following structure: struct semaphore { raw_spinlock_t lock; unsigned int count; struct list_head wait_list; };
spin_lock*
functions do the same as raw_spin_lock*
ones plus, when lock debugging is enabled(CONFIG_DEBUG_LOCK_ALLOC), perform some additional runtime checks for lock operations, such as checks for deadlock. These checks are performed by lockdep
subsystem.
As a rule, spin_lock*
functions should be used whenever it is possible.
Only in rare cases of very tricky locking policy, when lockdep
can produce false warnings, raw_spin_lock*
functions can be used.
Also, raw_*
functions can be preferred to common ones for reduce memory usage or perfomance reasons. But it should be actual time/space measurements, reflected significant wins from using these optimizations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With