-
Notifications
You must be signed in to change notification settings - Fork 8.2k
drivers: gpio: emul: replace mutex with spinlock #53480
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
drivers: gpio: emul: replace mutex with spinlock #53480
Conversation
|
@cfriedt second try :-) |
7846b37 to
9fa7520
Compare
90bf3af to
d7dc252
Compare
|
How will switching from a mutex to a spinlock "make the driver usable from ISRs"? If application level code holds the spinlock and an ISR attempts to acquire it, the ISR will spin forever? |
How can an ISR execute if the spinlock is locked? |
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.
Looks OK to me. I was actually not really sure if this would be possible, but I'm impressed. Just some minor changes requested to remove unnecessary changes / update docs.
I would like to take another look at the second draft as well and see if I can break it.
7ba1b5a to
bd101e2
Compare
|
@alexanderwachter - I would go so far as to say that this fixes a bug. Do you know if an issue exists for that already? |
Replace all mutex with spinlocks to make the driver usable from ISRs. Signed-off-by: Alexander Wachter <[email protected]>
bd101e2 to
75d6091
Compare
|
@cfriedt not that I'm aware of. At least not from me. |
@alexanderwachter - Oh, I meant not being able to use gpio_emul in IRQ contexts is a bug actually, so this PR is itself a Bugfix. Can you also please create an issue and link it here?
Right, I think I see what you mean. Actually, that is part of a larger issue that we have in Zephyr. Very few Zephyr system calls have an associated timeout (including GPIO). So there is no clean way at the moment to fail with an error if a such an operation would block. Blocking I/O (with a timeout) would also require a mutex or something along those lines which is almost a step in the reverse direction. It would force users to incur not only the syscall overhead but also the overhead of locking a mutex. Maybe that would be negligible in the future with with zync, but we'll see. One could also argue, much like accessing any kind of data structure, synchronizing control of a GPIO is entirely application dependent and is not needed by the large majority of GPIO users. What you've identified is out of the scope of this PR, so I wouldn't worry about it here. For the time being, the implicit assumption is that GPIO operations are quick and they never fail. |
|
@cfriedt ready for merging? |
|
@alexanderwachter - yes, but I'll let @stephanosio or @laurenmurphyx64 do it once there is another review |
|
@mnkp any input? |
|
@henrikbrixandersen - will you ack? |
|
Is the GPIO interface labeled as ISR safe? This is kind of a confusing change to be honest. |
andyross
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.
All looks reasonable to me. Note that the "release the lock around the callback" pattern opens races if other contexts want to modify the data used by the callback while it's running. That's arguably user error, but might be worth documenting.
Replace all mutex with spinlocks to make the driver usable from ISRs.
Fixes #53964