Questions tagged [spinlock]

A spinlock is a lock which causes a thread trying to acquire it to simply wait in a loop ("spin") while repeatedly checking if the lock is available.

318 questions
3
votes
1 answer

Can the SoftIRQ prempt currently running the same SoftIRQ with Linux kernel?

I am working on a performance improvement of a driver and should consider the possibility of deadlock. In a SoftIRQ context, spin_lock will be held and protect some variable. In this case, should I use spin_lock or spin_lock_bh? spin_lock_bh sounds…
Owen Kwon
  • 33
  • 2
3
votes
1 answer

CMU: Semaphores

Check My Understanding of semaphores, please! I understand the idea behind counting semaphores and binary semaphores. However the difference between a spinlock and semaphore implemented with signal() and wait() kind of blend together to me. For…
user427390
3
votes
1 answer

Why spinlock in linux kernel is in the ".subsection 1" (or ".text.lock.smth")?

In linux kernel in the implementation of spinlocks, e.g. http://lxr.linux.no/#linux+v2.6.18/include/asm-i386/semaphore.h#L97 97static inline void down(struct semaphore * sem) 98{ 99 might_sleep(); 100 __asm__ __volatile__( 101 …
osgx
  • 90,338
  • 53
  • 357
  • 513
3
votes
2 answers

Is returning while holding a spinlock automatically unsafe?

The venerated book Linux Driver Development says that The flags argument passed to spin_unlock_irqrestore must be the same variable passed to spin_lock_irqsave. You must also call spin_lock_irqsave and spin_unlock_irqrestore in the same function;…
Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
3
votes
2 answers

How is spin lock implemented under the hood?

This is a lock that can be held by only one thread of execution at a time. An attempt to acquire the lock by another thread of execution makes the latter loop until the lock is released. How does it handle the case when two threads try…
httpinterpret
  • 6,409
  • 9
  • 33
  • 37
3
votes
1 answer

Linux kernel: Unlocking an unlocked mutex

I am trying to understand the "unlocking an unlocked mutex" is not allowed will lead to unpredictable behavior w.r.t Linux kernel mutex, when i look at the code i do not see anything to this effect. Specifically: /** * try to promote the mutex from…
newbie
  • 41
  • 3
3
votes
2 answers

What provides spinlocks effectiveness?

Spinlocks may be effective only on systems with real parallelism i.e. multicore/processor systems. That is not surprising due to their design. Nonetheless, threads sharing the resource must execute on different cores. Otherwise situation is…
Pavel Voronin
  • 13,503
  • 7
  • 71
  • 137
3
votes
1 answer

spinlock lockup suspected reasons

What could be reasons for the following message: BUG: spinlock lockup suspected on CPU#0, sh/11786 lock: kmap_lock+0x0/0x40, .magic: dead4ead, .owner: sh/11787, .owner_cpu: 1
ashish
  • 813
  • 3
  • 10
  • 18
3
votes
3 answers

Linux Kernel - Can I lock and unlock Spinlock in different functions?

I'm new to Kernel programming and programming with locks. Is it safe to lock and unlock a spinlock in different functions? I am doing this to synchronize the code flow. Also, is it safe to use spinlock (lock & unlock) in __schedule()? Is it safe to…
stackoverflow
  • 399
  • 2
  • 14
3
votes
4 answers

Implementing a spinlock in Boost. Example Needed

I wanted to know if boost has any libraries that assist in implementing spin locks. I know boost supports mutexes but I could not find any examples that show or describe spinlocks in boost.Any examples showing how to implement a spin lock using…
Rajeshwar
  • 11,179
  • 26
  • 86
  • 158
3
votes
1 answer

Why does this code deadlock?

I created 2 Linux kernel threads in my loadable module and I bind them to separate CPU cores running on a dual core Android device. After I run this few times, I noticed that the device reboots with a HW watchdog timer reset. I hit the issue…
Gupta
  • 33
  • 1
  • 4
3
votes
1 answer

How to monitor linux spinlock waiting time?

I read the spinlock function code in the linux kernel. There are two functions related to spinlock. See the code below: static __always_inline void __ticket_spin_lock(raw_spinlock_t *lock) { short inc = 0x0100; asm volatile ( …
Charles0429
  • 1,406
  • 5
  • 15
  • 31
3
votes
1 answer

spinlock_t already locked at the first use

Hi i'm programming kernel (2.6) for the first time and i have a problem using spinlocks. I'm trying to add this system call (inserisci_nodo) that externalizes a structure (an ibrid list-hashtable) and try to add a node (Persona) in this structure,…
Pietro Luciani
  • 247
  • 1
  • 4
  • 14
3
votes
2 answers

When should & shouldn't I use this C# utility class to control threads via Interlocked

I'm trying to understand the logic behind how this class was written, and when I should and shouldn't use it. Any insight would be appreciated internal struct SpinLock { private volatile int lockHeld; private readonly static int…
makerofthings7
  • 60,103
  • 53
  • 215
  • 448
2
votes
2 answers

The PAUSE instruction may not work in my test

the detail of test program I tested it in user mode using examples from Intel SDM, The details of this test are as follows: Provide an global lock using SystemV shared memory for multiple processes use it Use the assembly example in Intel SDM as…