Opportunistic dma_fence polling
Yo Christian,
I'd like to discuss the dma_fence fast path optimization (ops.is_signaled) again.
As far as I understand by now, the use case is that some drivers will never signal fences; but the consumer of the fence actively polls whether a fence is signaled or not.
Right?
I have a bunch of questions regarding that:
1. What does the party polling the fence typically look like? I bet it's not userspace, is it? Userspace I'd expect to use poll() on a FD, thus an underlying driver has to check the fence somehow.
2. What if that party checks the fence, determines it is unsignaled? Will it then again try later?
3. If it tries again later anyways, then what is the problem with the fence-issuing driver itself checking every 5, 10 or 50 milliseconds what the counter in the GPU ring buffer is, and then signals all those fences?
So it circles around the question why ops.is_signaled is supposedly unavoidable.
Regards
P.
Hi Philip,
I only found this message by coincident, please make sure to always CC my AMD work email address as well.
Quoted 10 lines · Philipp Stanner
Yo Christian,
I'd like to discuss the
dma_fencefast path optimization (ops.is_signaled) again.As far as I understand by now, the use case is that some drivers will never signal fences; but the consumer of the fence actively polls whether a fence is signaled or not.
Right?
Close but not 100% right. The semantic is that enabled_signaling is only called when somebody actively waits for the dma_fence to finish.
So as long as both userspace and kernel only poll for the fence status enable_signaling is never called and only is_signaled is called.
What drivers/fence implementations do with that is up to them. For example userqueues use it as preemption signaling, but most drivers simply try to avoid waking up the system with IRQs.
Quoted 5 lines
I have a bunch of questions regarding that:
1. What does the party polling the fence typically look like? I bet it's not userspace, is it? Userspace I'd expect to use
poll()on a FD, thus an underlying driver has to check the fence somehow.
No no, that is indeed userspace.
As soon as the kernel starts to call dma_fence_wait() (for example) we have the normal guaranteed to signal semantics we always have.
Quoted 2 lines
2. What if that party checks the fence, determines it is unsignaled? Will it then again try later?
I have no idea, that depends on how the userspace component is implemented.
Quoted 4 lines
3. If it tries again later anyways, then what is the problem with the fence-issuing driver itself checking every 5, 10 or 50 milliseconds what the counter in the GPU ring buffer is, and then signals all those fences?
That you need to wake up for that, this costs quite a lot of power.
See two different approach:
1. Interrupt driven, e.g. somebody says signal me as soon as possible when the work is done.
2. Poll driven, e.g. userspace wakes up every N milliseconds anyway and it doesn't matter if the status changes a bit later.
Quoted 2 lines
So it circles around the question why ops.is_signaled is supposedly unavoidable.
Additional to the interrupt/poll handling it is also a really important optimization for multicore systems, e.g. it makes the signaling state visible to other CPU cores even when the core handling the IRQ is still busy.
That is also really important for some use cases as far as I know. Keep in mind that this framework drivers everything from Android mobiles all the way up to supercomputers.
I mean what we could potentially do is to fix the locking invariant of the is_signaled callback, but that is probably the only simplification possible without breaking tons of use cases.
Regards,
Christian.
Quoted 3 lines
Regards
P.
Quoted 3 lines · Christian König
Hi Philip,
I only found this message by coincident, please make sure to always CC my AMD work email address as well.
You've been the direct recipent, in the To: header field :)
Quoted 11 lines · Philipp Stanner
Quoted 9 lines
Yo Christian,
I'd like to discuss the
dma_fencefast path optimization (ops.is_signaled) again.As far as I understand by now, the use case is that some drivers will never signal fences; but the consumer of the fence actively polls whether a fence is signaled or not.
Quoted 5 lines
Quoted 1 line
Right?
Close but not 100% right. The semantic is that
enabled_signalingis only called when somebody actively waits for thedma_fenceto finish.So as long as both userspace and kernel only poll for the fence status
enable_signalingis never called and onlyis_signaledis called.
So you're telling me that enable_signaling enables interrupt-driven signaling, typically. IOW in some cases you can request that a specific fence gets signaled the expensive way (interrupt) while polling on the others.
What is the hw->hw signaling that the documentation details?
hw->sw signaling seems to refer to interrupts.
Quoted 10 lines
What
drivers/fenceimplementations do with that is up to them. For example userqueues use it as preemption signaling, but most drivers simply try to avoid waking up the system with IRQs.Quoted 5 lines
I have a bunch of questions regarding that:
1. What does the party polling the fence typically look like? I bet it's not userspace, is it? Userspace I'd expect to use
poll()on a FD, thus an underlying driver has to check the fence somehow.No no, that is indeed userspace.
Userspace has no direct access to a fence. It's, ultimately a kernel ioctl through which userspace can check a fence. That's what I meant:
it's kernel code implemented in the driver [but running in the user's process context]
Quoted 13 lines
As soon as the kernel starts to call
dma_fence_wait()(for example) we have the normal guaranteed to signal semantics we always have.Quoted 2 lines
2. What if that party checks the fence, determines it is unsignaled? Will it then again try later?
I have no idea, that depends on how the userspace component is implemented.
Quoted 4 lines
3. If it tries again later anyways, then what is the problem with the fence-issuing driver itself checking every 5, 10 or 50 milliseconds what the counter in the GPU ring buffer is, and then signals all those fences?
Quoted 7 lines
That you need to wake up for that, this costs quite a lot of power.
See two different approach:
1. Interrupt driven, e.g. somebody says signal me as soon as possible when the work is done.
2. Poll driven, e.g. userspace wakes up every N milliseconds anyway and it doesn't matter if the status changes a bit later.
Makes sense, I guess.
Quoted 5 lines
Quoted 3 lines
So it circles around the question why ops.is_signaled is supposedly unavoidable.
Additional to the interrupt/poll handling it is also a really important optimization for multicore systems, e.g. it makes the signaling state visible to other CPU cores even when the core handling the IRQ is still busy.
What is the "signaling state"?
A fence's signaled status is indicated through an atomic flag which becomes visible globally once someone, like said interrupt, has signaled the fence.
P.
Quoted 12 lines
That is also really important for some use cases as far as I know. Keep in mind that this framework drivers everything from Android mobiles all the way up to supercomputers.
I mean what we could potentially do is to fix the locking invariant of the
is_signaledcallback, but that is probably the only simplification possible without breaking tons of use cases.Regards,
Christian.Quoted 3 lines
Regards
P.
Quoted 6 lines · Philipp Stanner
Quoted 3 lines · Christian König
Hi Philip,
I only found this message by coincident, please make sure to always CC my AMD work email address as well.
You've been the direct recipent, in the To: header field :)
Yeah, but this is just the gmail account for mailing lists which I use as workaround because AMDs IT has the problem to mangle mails and so make patch review impossible.
Quoted 13 lines
Quoted 13 lines · Philipp Stanner
Quoted 10 lines
Yo Christian,
I'd like to discuss the
dma_fencefast path optimization (ops.is_signaled) again.As far as I understand by now, the use case is that some drivers will never signal fences; but the consumer of the fence actively polls whether a fence is signaled or not.
Right?
Quoted 8 lines
Quoted 3 lines
Close but not 100% right. The semantic is that
enabled_signalingis only called when somebody actively waits for thedma_fenceto finish.So as long as both userspace and kernel only poll for the fence status
enable_signalingis never called and onlyis_signaledis called.So you're telling me that
enable_signalingenables interrupt-driven signaling, typically. IOW in some cases you can request that a specific fence gets signaled the expensive way (interrupt) while polling on the others.
Correct, yes.
Quoted 1 line
What is the
hw->hwsignaling that the documentation details?
Oh, do we still have references to that in the framework documentation?
Initially we tried to make hw->hw signaling a general framework as well, but it was quickly found that this is really problematic and removed/never fully merged.
HW->HW signaling is still used by a bunch of DMA-buf implementations, but that is then implementation specific.
Quoted 1 line
hw->swsignaling seems to refer to interrupts.
HW->SW signaling is both interrupt and polling driven.
Quoted 9 lines
Quoted 9 lines
What
drivers/fenceimplementations do with that is up to them. For example userqueues use it as preemption signaling, but most drivers simply try to avoid waking up the system with IRQs.Quoted 5 lines
I have a bunch of questions regarding that:
1. What does the party polling the fence typically look like? I bet it's not userspace, is it? Userspace I'd expect to use
poll()on a FD, thus an underlying driver has to check the fence somehow.
Quoted 6 lines
Quoted 1 line
No no, that is indeed userspace.
Userspace has no direct access to a fence. It's, ultimately a kernel ioctl through which userspace can check a fence. That's what I meant:
it's kernel code implemented in the driver [but running in the user's process context]
What I meant is that the polling is triggered by userspace.
In other words the kernel doesn't care if fences signal or not as long as it doesn't wait for them. E.g. in case of memory pressure etc...
Quoted 10 lines
Quoted 4 lines
Quoted 2 lines
So it circles around the question why ops.is_signaled is supposedly unavoidable.
Additional to the interrupt/poll handling it is also a really important optimization for multicore systems, e.g. it makes the signaling state visible to other CPU cores even when the core handling the IRQ is still busy.
What is the "signaling state"?
A fence's signaled status is indicated through an atomic flag which becomes visible globally once someone, like said interrupt, has signaled the fence.
Well not quite. The atomic flag is the generalized coherent signaled state of the dma_fence framework over all CPU cores.
But the state inside the dma_fence implementation which you can query directly with the is_signaled callback can be quite different.
For example we have seen the following:
1. MMIO HW registers
2. Local device memory
3. System memory coherent to all CPU cores
4. System memory coherent to only some CPU cores
5. System memory not coherent at all and you need explicit memory barriers
So it is perfectly possible that the is_signaled callback returns true on one CPU core and false on another.
And for some use cases you don't want to wait for the CPU to CPU synchronization of the atomic flag, but rather go ahead and push the depending work etc...
Regards,
Christian.
Quoted 17 lines
P.
Quoted 12 lines
That is also really important for some use cases as far as I know. Keep in mind that this framework drivers everything from Android mobiles all the way up to supercomputers.
I mean what we could potentially do is to fix the locking invariant of the
is_signaledcallback, but that is probably the only simplification possible without breaking tons of use cases.Regards,
Christian.Quoted 3 lines
Regards
P.