New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement the fine-grained spin lock #2213
Comments
@xiaoxiang781216 However, yes, the current
In my understanding, these APIs are the same as the current
I agree with you. |
@masayuki2009 you are right. Let's introduce spinlock first and replace the usage step by step as note here: #1144. |
After more thinking, we should support two type synchronization:
The major difference is that the caller can't sleep afte hold the spinlock, but critical section can. |
I've just started this work by enhancing the existing APIs.
Here, if the spinlock is NULL, it uses the global spinlock (i.e. g_irq_spin) for SMP. For example, the imxrt does not support SMP, so imxrt_serial.c will have
The behavior is the same as before. (i.e. It just disable/enable CPU interrupt for non-SMP case) For SMP cases, you can also use the above call (i.e. spinlock is NULL). In this case, the behavior is also the same as before. And this will be useful for migration. For the first step, I will do this by just replacing the existing API call with the NULL spinlock. Next step, some drivers would have a local spinlock for SMP, for example, cxd56_serial.c would be something like
In this case, each UART will have a spinlock but only for the SMP case. For the non-SMP case, the spinlock is not allocated but it's OK because the parameter What do you think? |
It's better change to:
It's better change to:
Yes, it is a good compromise.
Can we add some macros for definition and initialization? so we can avoid spread #ifded/#endif in the whole code base.
The propose looks great, thanks @masayuki2009! |
Thanks for your comments.
If we apply the above change, the behavior will be different in the case of CONFIG_SMP=y and CONFIG_SPINLOCK_IRQ=n.
However, I think it's better to remove CONFIG_SPINLOCK_IRQ from Kconfig to avoid complexity.
What do you think? |
Oh, I forgot SPINLOCK_IRQ config, but this option doesn't make sense for me, because the user can freely select:
Two set API is already flexible enough for all use case. |
I wrote the code but I agree with you. |
The fine grant spinlock is implemented, let's close it. |
Right now, NuttX support one big spin lock:
Which isn't good for SMP machine. Compare with Linux(https://elixir.bootlin.com/linux/latest/source/include/linux/irqflags.h#L200), the above API should rename to:
and add the real spinlock(multiple instance) support:
https://www.kernel.org/doc/Documentation/locking/spinlocks.txt
The text was updated successfully, but these errors were encountered: