Skip to main content

Posts

Per CPU Variable

https://elixir.bootlin.com/linux/latest/source/arch/arm/kernel/process.c#L40 example:   #if  defined ( CONFIG_CURRENT_POINTER_IN_TPIDRURO ) ||  defined ( CONFIG_SMP ) DEFINE_PER_CPU ( struct task_struct * , __entry_task ); #endif
Recent posts

Spin Lock Understanding in Basic Language

  Spin lock  It's a spinning (polling) lock which is running and try to take a lock in a tight loop and checking again and again if lock is got freed up or not and once it free it will immediately take it up . Basically spin lock divided in to 4 Parts : 1.  Preempt Disable  : 1st operation spinlock will disable other Hardware interrupts so that what ever context is got scheduled will not preempt  2.  Spin_lock_acquire : It will generate a lock context for further tracking in lock dep  3.  do_spin_try_lock : Spinning in a loop (do -while) to take the lock and spin till not get the lock free. 4.  do_spin_lock :  Take the lock  After taking the lock it use to put a memory barrier to make sure memory will not be overwritten mistakenly Spin unlock  use to unlock the spin lock . Divided in to 3 parts. 1.  Spin_release : Mark in lock context for lock dep that we are going to release the lock for this particular lock context 2....

Interview Prep for Embedded Engineer

Locking and Synchronization 1. On a uniprocessor machine with preemption disabled, what will happen internally when we say spin_lock()? Answer: Hog the CPU 2. Can I lock a spinlock in one CPU and unlock it another CPU? Answer: No it should be on same CPU as that preemption is disabled for that core and spinlock which locked the core need to disable the preemption and go out of that core only 3. What are the pros and cons of using per CPU variable as synchronization method? https://www.makelinux.net/ldd3/chp-8-sect-5.shtml https://0xax.gitbook.io/linux-insides/summary/concepts/linux-cpu-1 https://distkeys.com/operating%20systems/linux/2013/10/07/process-synchronization-in-linux-kernel.html 4. What is the maximum amount of time CPU can be in critical section after acquiring spinlock? https://coffeebeforearch.github.io/2020/11/07/spinlocks-6.html it could remain in critical section till we don't do spinlock_unlock or another core hit watchdog bite (300ms) . Ideally critical section ti...