-
Notifications
You must be signed in to change notification settings - Fork 349
Convert spinlock to Zephyr API #5286
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
Conversation
839765e to
40e3679
Compare
|
@lyakh can you fix the conflict as coherent fix merged. Thanks. |
|
CI failures are due to "sof-logger already dead" |
kv2019i
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lyakh @lgirdwood Just removing all the "_irq" variants does not seem right. There so many that is really hard to review (in this big patchset) that they are all ok. E.g. should some non-irq uses of spinlocks be better replaced with mutex'es? At minimim, the rationale why this change is considered safe to do has to be added to the commit message (or code comments).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we keep the "_irq" variants still in SOF code and map them to same Zephyr call in some header. Or did we go through the call sites and assessed they are all invalid uses?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Zephyr's k_spin_lock() is disabling local interrupts. Zephyr doesn't have separate IRQ and non-IRQ versions of spin-locks. So, all these calls now disable interrupts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but all calls to spin_unlock() (before your patch) mark places where IRQs do not have to be enabled and are potentially cases we could replace with a mutex. With this patch, we lose information of all these cases. Have you gone through all cases that it is safe to drop the distinction? There are so many, it's hard to review in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lyakh ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kv2019i don't think so. Where spin_lock() was used only means that you do not have to lock IRQs there. E.g. you can (and often do, at least in the kernel) use spin_lock() in interrupt handlers, where you certainly cannot use mutexes. Or where interrupts are already disabled. Isn't it the same in SOF?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in other words - you can use both spin_lock() and spin_lock_irq() in both atomic and non-atomic contexts, don't think it tells you anything about where you can or cannot use mutexes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lyakh It's just not evident this applies to all cases. We had two variants for some reason. Maybe 95% is just superfluous, but e.g. kernel has spinlocks never taken in IRQ context and the plain spin_lock() variant is used on purpose. I mean, maybe we don't have any cases like this, and then I'm ok to get rid of the additional variant altogeher. But my main point, in a huge patch lke this, it's impossible to review each and every call site. If you say you've gone through all cases, then ok, let's go ahead, but please add a note to commit message. If unsure, I'd leave the two variants and zap them out in smaller PRs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, with the updated commit message, I'm ok.
src/audio/crossover/crossover.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This removal seems safer as the "_irq" has been done with a specific pattern and we can now review and conclude it is not needed and we can remove the variant.
Yeah, the orig patch kept the irq and no irq mappings in the code so that xtos behavior would be the same, but on Zephyr all default to IRQ type. |
cujomalainey
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approve for google processing files
kv2019i
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lyakh comment inline on the irqsave variants
|
@kv2019i @lrgirdwo to summarise:
|
Align the SOF spinlock API with Zephyr spinlock API. Currently SOF spinlock has two locking variants: with and without disabling local IRQs. Since taking a spinlock potentially puts the CPU into busy-looping, periods of time for holding spinlocks should be kept as short as possible. This also means, that usually the CPU, holding a spinlock shouldn't be interrupted. So usually spinlocks should be taken in atomic contexts. Therefore using the version, not locking local IRQs should only be done when IRQs are already disabled. This then saves several CPU cycles, avoiding reading and writing CPU status again. However, this should be only done with extreme care and it introduces potential for current and future bugs, including dead-locks. Zephyr spinlock API always disables local IRQs. This makes it simpler and less error prone. Switching to it potentially wastes several CPU cycles in some locations, but makes the code more robust. This is first part of work for spinlock Zephyr alignment, subsequent updates will align headers and associated splinlock dependecies. Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com> Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
Now coherent_acquire_irq() has become equivalent to coherent_acquire(), similar for coherent_release() and coherent_shared(). Remove the _irq version and its only user - the buffer locking API. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
|
@kv2019i @lgirdwood I extended the commit message of the first commit. No changes otherwise. I've also looked at current uses of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, with the updated commit message, I'm ok.
|
@kv2019i @lyakh I assume this is a known issue https://sof-ci.01.org/sofpr/PR5286/build11918/devicetest/?model=APL_UP2_NOCODEC_ZEPHYR&testcase=multiple-pipeline-all |
|
@lgirdwood hmm, not to me... Don't think it was there in previous rounds... checking |
Ack - its known issue an not related to this PR. |
This extends on and replaces #5229. This is a draft for now because it also includes a commit from #5285
Note, that this version blatantly replaces all SOF calls to
spin_lock()andspin_lock_irq()withk_spin_lock()which does also disable IRQs. I.e. Zephyr ATM doesn't have a spin-lock version that wouldn't disable IRQs. After this is merged we should consider all cases where we added disabling IRQs and see if we can replace some of them with less restrictive locking, e.g. with mutexes