I managed to port FreeRTOS SMP version onto my SoC, which has 8 ARM cores. I’m not sure whether it is safe to use spinlock directly in my FreeRTOS tasks. Is the following code within a task function safe to run without confusing the FreeRTOS scheduler?
Spin lock is only good as long as all the cores try acquire it before entering the critical section. Is there a reason you do not want to use taskENTER_CRITICAL/taskEXIT_CRITICAL?
The major reason I’d like to use spinlock is performance. It looks like that taskENTER_CRITICAL does a lot of things. A minor reason is that we have some history code using spinlocks (but I can change it if I have to).
If at all the places where the data protected using spin lock is accessed , the SAME spin lock is acquired then I do not think there will be any problem.
In other words, wherever you want to access the shared data shown below, you must acquire the same spin lock -
msk = spin_lock_irqsave(&lock);
//...Access shared data
spin_unlock_irqrestore(&lock, msk);