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
4
votes
1 answer

what happens when the tasklet is interrupted by a hardware interrupt?

I wanted to know this part. We know that tasklets can't sleep, then if the HW interrupt comes in what happens to the tasklets? I am facing a crash, in which the tasklet is interrupted by a hW interrupt. I have used spinlock in my tasklet. Should I…
Invictus
  • 2,653
  • 8
  • 31
  • 50
4
votes
1 answer

Understanding spinlocks in netfilter hook

I am writing a small kernel module for measuring the time that a network packet takes to exit a node. This module is a hook in the netfilter library. For each packet it receives it calculates an hash, gets the tstamp from skbuff and the actual…
Hugo Alves
  • 188
  • 1
  • 10
4
votes
2 answers

When to use MCS lock

I have been reading about MCS locks which I feel is pretty cool. Now that I know how it's implemented the next question is when to use it. Below are my thoughts. Please feel free to add items to the list 1) Ideally should be used when there more…
KodeWarrior
  • 3,538
  • 3
  • 26
  • 40
4
votes
1 answer

Broken GLSL Spinlock/GLSL Locks Compendium

I have a setup where I need to lock, read some data, process, write some data, and then unlock. To this end, I made a locking texture as a layout(r32ui) coherent uniform uimage2D. The critical section's data is declared similarly. Unfortunately,…
geometrian
  • 14,775
  • 10
  • 56
  • 132
4
votes
1 answer

Linux kernel dump: How to get the owner of a spinlock

I have a linux kernel dump generated on a 24-core system. Most of the tasks are stuck on a spinlock. Is there a way to get the owner of a spinlock?
Alex Fiddler
  • 213
  • 1
  • 3
  • 8
4
votes
1 answer

Synchronization between user space process and interupt context code

Recently I attended couple of interviews. Out of all kernel questions which were asked, there is one specific question which I couldn’t find convincing answer of. How will you use different synchronization techniques while sharing data between user…
yogi_peace
  • 111
  • 2
  • 5
3
votes
2 answers

replace spin lock with signal

i have alot of spin locks in my multithread code and most of the time they are waiting for other threads to do work and thus chew alot of cpu usage. In linux i normally use pthread_cond_wait and pthread_cond_signal to pause a thread and wake up when…
Lodle
  • 31,277
  • 19
  • 64
  • 91
3
votes
1 answer

Why are the implementations of the spin lock different between Windows XP and Windows 7?

I know the spinlock is exported by hal.dll in Windows, so I reverse engineered the code for the spin lock. The results are below. Windows XP's decompiled spinlock. unsigned __int32 __thiscall KfAcquireSpinLock(signed __int32 *this) { unsigned…
Sim Sun
  • 587
  • 1
  • 4
  • 28
3
votes
2 answers

What's a good alternative to PAUSE for use in the implementation of a spinlock?

I am working on making a fiber-based job system for my latest project which will depend on the use of spinlocks for proper functionality. I had intended to use the PAUSE instruction as that seems to be the gold-standard for the waiting portion of…
3
votes
0 answers

KeAcquireSpinLock long execution time

I am currently developing a Windows Kernel Driver that implements its own networking stack. While testing some base functionality of the implemented stack, I noticed that replies to pings would sometimes take noticeably longer than usual.…
ApiTiger
  • 31
  • 2
3
votes
1 answer

Bare metal spinlock implementation in rust

I am working on bare metal programming in rust on a Raspberry Pi 3 running in 64 bit mode. I have implemented a spinlock as follows: use core::{sync::atomic::{AtomicBool, Ordering}, cell::UnsafeCell, ops::{Deref, DerefMut}}; pub struct SpinMutex
Someone
  • 800
  • 1
  • 7
  • 25
3
votes
2 answers

Faster lock than pthreads

We are building an extremely latency sensitive application. Our full application takes about 2500 clock cycles in a process apart from locking, and there are two locks that need to be acquired and released. We expect no contention 99.98% of the…
Humble Debugger
  • 4,439
  • 11
  • 39
  • 56
3
votes
2 answers

Implementing a SpinLock in a HLSL DirectCompute shader

I try to implement a spin lock in a compute shader. But my implementation it doesn't seems to lock anything. Here is how I implement the spin lock: void LockAcquire() { uint Value = 1; [allow_uav_condition] while (Value) { …
fpiette
  • 11,983
  • 1
  • 24
  • 46
3
votes
0 answers

What is difference between spin_lock and spin_lock_bh

I want to understand difference between spin_lock and spin_lock_bh. As per https://www.kernel.org/doc/html/v4.15/kernel-hacking/locking.html#cheat-sheet-for-locking if critical section is between softirq and userspace process     we should use…
Anand
  • 119
  • 1
  • 11
3
votes
1 answer

Spinlock implementation reasoning

I want to improve the performance of a program by replacing some of the mutexes with spinlocks. I have found a spinlock implementation in http://www.boost.org/doc/libs/1_36_0/boost/detail/spinlock_sync.hpp which I intend to reuse. I believe this…
sotiris
  • 315
  • 6
  • 13