dma-buf: Add __dma_fence_is_signaled()
Subsystems (5)
Philipp Stanner
maintainerPATCH 1/2 dma-buf: Add __dma_fence_is_signaled()
Some parties want to check whether a function is already signaled without actually signaling the fence, which is what dma_fence_is_signaled() might due if the fence ops 'signaled' callback is implemented.
Add __dma_fence_is_signaled(), which _only_ checks whether a fence is signaled. Use it internally.
--- include/linux/dma-fence.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)
include/linux/dma-fence.h +22 -2
@@ -381,6 +381,26 @@ bool dma_fence_remove_callback(struct dma_fence *fence, struct dma_fence_cb *cb);void dma_fence_enable_sw_signaling (struct dma_fence *fence); +/** +* __dma_fence_is_signaled - Only check whether a fence is signaled yet. +* @fence: the fence to check +* +* This function just checks whether @fence is signaled, without interacting +* with the fence in any way. The user must, therefore, ensure through other +* means that fences get signaled eventually. +* +* This function does not require locking. +* +* See also dma_fence_is_signaled(). +* +* Return: true if signaled, false otherwise. +*/ +static inline bool +__dma_fence_is_signaled (struct dma_fence *fence) +{ +return test_bit (DMA_FENCE_FLAG_SIGNALED_BIT , &fence->flags); +} +/** * dma_fence_is_signaled_locked - Return an indication if the fence * is signaled yet.
@@ -398,7 +418,7 @@ void dma_fence_enable_sw_signaling(struct dma_fence *fence);static inline bool dma_fence_is_signaled_locked (struct dma_fence *fence) { -if (test_bit (DMA_FENCE_FLAG_SIGNALED_BIT , &fence->flags)) +if (__dma_fence_is_signaled (fence))return true;if (fence->ops->signaled && fence->ops->signaled (fence)) {
@@ -428,7 +448,7 @@ dma_fence_is_signaled_locked(struct dma_fence *fence)static inline bool dma_fence_is_signaled (struct dma_fence *fence) { -if (test_bit (DMA_FENCE_FLAG_SIGNALED_BIT , &fence->flags)) +if (__dma_fence_is_signaled (fence))return true;if (fence->ops->signaled && fence->ops->signaled (fence)) {
Signature · 1 line
2.49.0
Philipp Stanner
maintainerPATCH 2/2 drm/nouveau: Don't signal when killing the fence context
dma_fence_is_signaled_locked(), which is used in nouveau_fence_context_kill(), can signal fences below the surface through a callback.
There is neither need for nor use in doing that when killing a fence context.
Replace dma_fence_is_signaled_locked() with __dma_fence_is_signaled(), a function which only checks, never signals.
--- drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/nouveau/nouveau_fence.c +1 -1
@@ -88,7 +88,7 @@ nouveau_fence_context_kill(struct nouveau_fence_chan *fctx, int error)spin_lock_irqsave (&fctx->lock, flags);list_for_each_entry_safe (fence, tmp, &fctx->pending, head) { -if (error && !dma_fence_is_signaled_locked (&fence->base)) +if (error && !__dma_fence_is_signaled (&fence->base))dma_fence_set_error (&fence->base, error);if (nouveau_fence_signal (fence))
Signature · 1 line
2.49.0
Christian König
maintainerRe: [PATCH 2/2] drm/nouveau: Don't signal when killing the fence context
Quoted 9 lines · Philipp Stanner
dma_fence_is_signaled_locked(), which is used innouveau_fence_context_kill(), can signal fences below the surface through a callback.There is neither need for nor use in doing that when killing a fence context.
Replace
dma_fence_is_signaled_locked()with__dma_fence_is_signaled(), a function which only checks, never signals.
That is not a good approach.
Having the __dma_fence_is_signaled() means that other would be allowed to call it as well.
But nouveau can do that here only because it knows that the fence was issued by nouveau.
What nouveau can to is to test the signaled flag directly, but that's what you try to avoid as well.
Regards,
Christian.
Quoted 19 lines
Signed-off-by Philipp Stanner <[email protected]>--- drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/nouveau/nouveau_fence.c +1
-1@@ -88,7 +88,7 @@ nouveau_fence_context_kill(struct nouveau_fence_chan *fctx, int error)spin_lock_irqsave (&fctx->lock, flags);list_for_each_entry_safe (fence, tmp, &fctx->pending, head) { -if (error && !dma_fence_is_signaled_locked (&fence->base)) +if (error && !__dma_fence_is_signaled (&fence->base))dma_fence_set_error (&fence->base, error);if (nouveau_fence_signal (fence))
Re: [PATCH 2/2] drm/nouveau: Don't signal when killing the fence context
Quoted 15 lines · Christian König
Quoted 11 lines · Philipp Stanner
dma_fence_is_signaled_locked(), which is used innouveau_fence_context_kill(), can signal fences below the surface through a callback.There is neither need for nor use in doing that when killing a fence
context.Replace
dma_fence_is_signaled_locked()with__dma_fence_is_signaled(), a
function which only checks, never signals.That is not a good approach.
Quoted 8 lines
Having the
__dma_fence_is_signaled()means that other would be allowed to call it as well.But nouveau can do that here only because it knows that the fence was issued by nouveau.
What nouveau can to is to test the signaled flag directly, but that's what you try to avoid as well.
There's many parties who check the bit already.
And if Nouveau is allowed to do that, one can just as well provide a wrapper for it.
That has the advantage of centralizing the responsibility and documenting it.
P.
Quoted 29 lines
Regards,
Christian.Quoted 24 lines
Signed-off-by Philipp Stanner <[email protected]>---
drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/nouveau/nouveau_fence.c +0
-0@@ -88,7 +88,7 @@ nouveau_fence_context_kill(struct nouveau_fence_chan *fctx, int error)
spin_lock_irqsave(&fctx->lock, flags);list_for_each_entry_safe(fence, tmp, &fctx->pending, head){drivers/gpu/drm/nouveau/nouveau_fence.c +0
-1- if (error && !dma_fence_is_signaled_locked(&fence-Quoted 1 line
base))
drivers/gpu/drm/nouveau/nouveau_fence.c +1
-0+ if (error && !__dma_fence_is_signaled(&fence-Quoted 1 line
base))
dma_fence_set_error(&fence->base, error);
if (nouveau_fence_signal(fence))
Christian König
maintainerRe: [PATCH 2/2] drm/nouveau: Don't signal when killing the fence context
Quoted 22 lines · Philipp Stanner
Quoted 21 lines · Christian König
Quoted 11 lines · Philipp Stanner
dma_fence_is_signaled_locked(), which is used innouveau_fence_context_kill(), can signal fences below the surface through a callback.There is neither need for nor use in doing that when killing a fence
context.Replace
dma_fence_is_signaled_locked()with__dma_fence_is_signaled(), a
function which only checks, never signals.That is not a good approach.
Having the
__dma_fence_is_signaled()means that other would be allowed to call it as well.But nouveau can do that here only because it knows that the fence was issued by nouveau.
Quoted 7 lines
Quoted 2 lines
What nouveau can to is to test the signaled flag directly, but that's what you try to avoid as well.
There's many parties who check the bit already.
And if Nouveau is allowed to do that, one can just as well provide a wrapper for it.
No, exactly that's what is usually avoided in cases like this here.
See all the functions inside include/linux/dma-fence.h can be used by everybody. It's basically the public interface of the dma_fence object.
So testing if a fence is signaled without calling the callback is only allowed by whoever implemented the fence.
In other words nouveau can test nouveau fences, i915 can test i915 fences, amdgpu can test amdgpu fences etc... But if you have the wrapper that makes it officially allowed that nouveau starts testing i915 fences and that would be problematic.
Regards,
Christian.
Quoted 36 lines
That has the advantage of centralizing the responsibility and documenting it.
P.
Quoted 29 lines
Regards,
Christian.Quoted 24 lines
Signed-off-by Philipp Stanner <[email protected]>---
drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/nouveau/nouveau_fence.c +0
-0@@ -88,7 +88,7 @@ nouveau_fence_context_kill(struct nouveau_fence_chan *fctx, int error)
spin_lock_irqsave(&fctx->lock, flags);list_for_each_entry_safe(fence, tmp, &fctx->pending, head){drivers/gpu/drm/nouveau/nouveau_fence.c +0
-1- if (error && !dma_fence_is_signaled_locked(&fence-Quoted 1 line
base))
drivers/gpu/drm/nouveau/nouveau_fence.c +1
-0+ if (error && !__dma_fence_is_signaled(&fence-Quoted 1 line
base))
dma_fence_set_error(&fence->base, error);
if (nouveau_fence_signal(fence))
Re: [PATCH 2/2] drm/nouveau: Don't signal when killing the fence context
Quoted 35 lines · Christian König
Quoted 28 lines · Philipp Stanner
Quoted 19 lines · Christian König
Quoted 5 lines · Philipp Stanner
dma_fence_is_signaled_locked(), which is used innouveau_fence_context_kill(), can signal fences below the surface
through a callback.Quoted 7 lines
There is neither need for nor use in doing that when killing a fence
context.Replace
dma_fence_is_signaled_locked()with__dma_fence_is_signaled(), a
function which only checks, never signals.That is not a good approach.
Having the
__dma_fence_is_signaled()means that other would be allowed to call it as well.Quoted 7 lines
But nouveau can do that here only because it knows that the fence was
issued by nouveau.What nouveau can to is to test the signaled flag directly, but that's
what you try to avoid as well.Quoted 5 lines
There's many parties who check the bit already.
And if Nouveau is allowed to do that, one can just as well provide a
wrapper for it.
Quoted 8 lines
No, exactly that's what is usually avoided in cases like this here.
See all the functions inside
include/linux/dma-fence.hcan be used by everybody. It's basically the public interface of thedma_fenceobject.So testing if a fence is signaled without calling the callback is only allowed by whoever implemented the fence.
Why?
See, who owns the callback? -> the driver which emitted the fence. If the driver doesn't guarantee that all fences will be signaled, the callback (always returning false) doesn't help you in any way.
I think the issue you're seeing is more that a party that only ever checks a fence's state through callbacks (and doesn't signal them through interrupts for example) would run danger of fences never getting signaled.
But that's already the case if someone doesn't implement the callback.
The fundamental basis is always the same: The driver must guarantee that all fences get signaled. Independently from other users checking the fence this or that way, independently from the callback being implemented.
Quoted 5 lines
In other words nouveau can test nouveau fences, i915 can test i915 fences, amdgpu can test amdgpu fences etc... But if you have the wrapper that makes it officially allowed that nouveau starts testing i915 fences and that would be problematic.
I don't see the context here. That applies to the other functions as well.
P.
Quoted 44 lines
Regards,
Christian.Quoted 39 lines
That has the advantage of centralizing the responsibility and documenting it.
P.
Quoted 32 lines
Regards,
Christian.Quoted 27 lines
Signed-off-by Philipp Stanner <[email protected]>---
drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/nouveau/nouveau_fence.c +0
-0@@ -88,7 +88,7 @@ nouveau_fence_context_kill(struct nouveau_fence_chan *fctx, int error)
spin_lock_irqsave(&fctx->lock, flags);list_for_each_entry_safe(fence, tmp, &fctx->pending, head)
{drivers/gpu/drm/nouveau/nouveau_fence.c +0
-1- if (error &&!dma_fence_is_signaled_locked(&fence-
Quoted 1 line
base))
drivers/gpu/drm/nouveau/nouveau_fence.c +1
-0+ if (error && !__dma_fence_is_signaled(&fence-Quoted 1 line
base))
dma_fence_set_error(&fence->base, error);
if (nouveau_fence_signal(fence))
Christian König
maintainerRe: [PATCH 2/2] drm/nouveau: Don't signal when killing the fence context
Quoted 47 lines · Philipp Stanner
Quoted 35 lines · Christian König
Quoted 28 lines · Philipp Stanner
Quoted 19 lines · Christian König
Quoted 5 lines · Philipp Stanner
dma_fence_is_signaled_locked(), which is used innouveau_fence_context_kill(), can signal fences below the surface
through a callback.Quoted 7 lines
There is neither need for nor use in doing that when killing a fence
context.Replace
dma_fence_is_signaled_locked()with__dma_fence_is_signaled(), a
function which only checks, never signals.That is not a good approach.
Having the
__dma_fence_is_signaled()means that other would be allowed to call it as well.Quoted 7 lines
But nouveau can do that here only because it knows that the fence was
issued by nouveau.What nouveau can to is to test the signaled flag directly, but that's
what you try to avoid as well.Quoted 5 lines
There's many parties who check the bit already.
And if Nouveau is allowed to do that, one can just as well provide a
wrapper for it.Quoted 8 lines
No, exactly that's what is usually avoided in cases like this here.
See all the functions inside
include/linux/dma-fence.hcan be used by everybody. It's basically the public interface of thedma_fenceobject.So testing if a fence is signaled without calling the callback is only allowed by whoever implemented the fence.
Why?
Quoted 8 lines
See, who owns the callback? -> the driver which emitted the fence. If the driver doesn't guarantee that all fences will be signaled, the callback (always returning false) doesn't help you in any way.
I think the issue you're seeing is more that a party that only ever checks a fence's state through callbacks (and doesn't signal them through interrupts for example) would run danger of fences never getting signaled.
Partially correct, yes.
Quoted 1 line
But that's already the case if someone doesn't implement the callback.
But than this implementation must always signal somehow else.
Quoted 4 lines
The fundamental basis is always the same: The driver must guarantee that all fences get signaled. Independently from other users checking the fence this or that way, independently from the callback being implemented.
Yeah, but it is invalid for a caller to not ask the implementation if it's signaled or not. See the rational behind that is to avoid abuse of the interface.
E.g. when you don't know the implementation side use the defined API and don't mess with the internals. If you do know the implementation side then it's valid that you check the internals.
Regards,
Christian.
Quoted 58 lines
Quoted 6 lines
In other words nouveau can test nouveau fences, i915 can test i915 fences, amdgpu can test amdgpu fences etc... But if you have the wrapper that makes it officially allowed that nouveau starts testing i915 fences and that would be problematic.
I don't see the context here. That applies to the other functions as well.
P.
Quoted 44 lines
Regards,
Christian.Quoted 39 lines
That has the advantage of centralizing the responsibility and documenting it.
P.
Quoted 32 lines
Regards,
Christian.Quoted 27 lines
Signed-off-by Philipp Stanner <[email protected]>---
drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/nouveau/nouveau_fence.c +0
-0@@ -88,7 +88,7 @@ nouveau_fence_context_kill(struct nouveau_fence_chan *fctx, int error)
spin_lock_irqsave(&fctx->lock, flags);list_for_each_entry_safe(fence, tmp, &fctx->pending, head)
{drivers/gpu/drm/nouveau/nouveau_fence.c +0
-1- if (error &&!dma_fence_is_signaled_locked(&fence-
Quoted 1 line
base))
drivers/gpu/drm/nouveau/nouveau_fence.c +1
-0+ if (error && !__dma_fence_is_signaled(&fence-Quoted 1 line
base))
dma_fence_set_error(&fence->base, error);
if (nouveau_fence_signal(fence))
Danilo Krummrich
maintainerRe: [PATCH 2/2] drm/nouveau: Don't signal when killing the fence context
Quoted 1 line · Christian König
E.g. when you don't know the implementation side use the defined API and don't mess with the internals. If you do know the implementation side then it's valid that you check the internals.
I assume you meant this as "bothering with the internals of you *own* fence is fine, but not with foreign ones".
And if the driver messes with the internals of its own fence code that's fine, but in this case we talk about the generic dma_fence implementation, i.e. an internal flag of the dma_fence implementation.
In general, a driver should *never* bother with implementation details of a generic component, regardless whether the author knows the internal details. Things are *always* prone to change and then this may result into subtle bugs.
Christian König
maintainerRe: [PATCH 2/2] drm/nouveau: Don't signal when killing the fence context
Quoted 5 lines · Danilo Krummrich
Quoted 1 line · Christian König
E.g. when you don't know the implementation side use the defined API and don't mess with the internals. If you do know the implementation side then it's valid that you check the internals.
I assume you meant this as "bothering with the internals of you *own* fence is fine, but not with foreign ones".
Yes, exactly that.
Quoted 3 lines
And if the driver messes with the internals of its own fence code that's fine, but in this case we talk about the generic
dma_fenceimplementation, i.e. an internal flag of thedma_fenceimplementation.
Well the flag is under the control of the fence implementation.
Quoted 3 lines
In general, a driver should *never* bother with implementation details of a generic component, regardless whether the author knows the internal details. Things are *always* prone to change and then this may result into subtle bugs.
Yeah, I know what you mean. The implementation kind of sub-classes the dma_fence component to use it to implement it's specific function.
In C++ we would distinct the function between into private: protected: and public: sections, but we don't have that luxury here.
But you already convinced me with the argument that this needs to be better documented, I'm just not sure if adding the function documentation would do it.
Regards,
Christian.
Re: [PATCH 2/2] drm/nouveau: Don't signal when killing the fence context
In reply to Christian KönigQuoted 31 lines · Christian König
Quoted 22 lines · Philipp Stanner
Quoted 21 lines · Christian König
Quoted 11 lines · Philipp Stanner
dma_fence_is_signaled_locked(), which is used innouveau_fence_context_kill(), can signal fences below the surface through a callback.There is neither need for nor use in doing that when killing a fence
context.Replace
dma_fence_is_signaled_locked()with__dma_fence_is_signaled(), a
function which only checks, never signals.That is not a good approach.
Having the
__dma_fence_is_signaled()means that other would be allowed to call it as well.But nouveau can do that here only because it knows that the fence was issued by nouveau.
Quoted 7 lines
Quoted 2 lines
What nouveau can to is to test the signaled flag directly, but that's what you try to avoid as well.
There's many parties who check the bit already.
And if Nouveau is allowed to do that, one can just as well provide a wrapper for it.
Quoted 7 lines
No, exactly that's what is usually avoided in cases like this here.
See all the functions inside
include/linux/dma-fence.hcan be used by everybody. It's basically the public interface of thedma_fenceobject.So testing if a fence is signaled without calling the callback is only allowed by whoever implemented the fence.
In other words nouveau can test nouveau fences, i915 can test i915 fences, amdgpu can test amdgpu fences etc... But if you have the wrapper that makes it officially allowed that nouveau starts testing i915 fences and that would be problematic.
But why? Say for example scheduler dependencies - why the scheduler couldn't ignore them at add time, but it can before trying to install a callback on them, and instead has to opportunistically signal someone else's fences?
I don't see it. But even if there is a reason, advantage of the helper is that it can document this at a centralised place.
Regards,
Tvrtko
Quoted 36 lines
Quoted 35 lines
That has the advantage of centralizing the responsibility and documenting it.
P.
Quoted 29 lines
Regards,
Christian.Quoted 24 lines
Signed-off-by Philipp Stanner <[email protected]>--- drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/nouveau/nouveau_fence.c +1
-1@@ -88,7 +88,7 @@ nouveau_fence_context_kill(struct nouveau_fence_chan *fctx, int error) spin_lock_irqsave(&fctx->lock, flags); list_for_each_entry_safe(fence, tmp, &fctx->pending, head) { -if (error && !dma_fence_is_signaled_locked (&fence- > base)) + if (error && !__dma_fence_is_signaled(&fence-Quoted 1 line
base))
dma_fence_set_error(&fence->base, error);if (
nouveau_fence_signal(fence))
Christian König
maintainerRe: [PATCH 2/2] drm/nouveau: Don't signal when killing the fence context
Quoted 35 lines · Tvrtko Ursulin
Quoted 33 lines · Christian König
Quoted 22 lines · Philipp Stanner
Quoted 21 lines · Christian König
Quoted 11 lines · Philipp Stanner
dma_fence_is_signaled_locked(), which is used innouveau_fence_context_kill(), can signal fences below the surface through a callback.There is neither need for nor use in doing that when killing a fence
context.Replace
dma_fence_is_signaled_locked()with__dma_fence_is_signaled(), a
function which only checks, never signals.That is not a good approach.
Having the
__dma_fence_is_signaled()means that other would be allowed to call it as well.But nouveau can do that here only because it knows that the fence was issued by nouveau.
Quoted 7 lines
Quoted 2 lines
What nouveau can to is to test the signaled flag directly, but that's what you try to avoid as well.
There's many parties who check the bit already.
And if Nouveau is allowed to do that, one can just as well provide a wrapper for it.
No, exactly that's what is usually avoided in cases like this here.
Quoted 7 lines
Quoted 5 lines
See all the functions inside
include/linux/dma-fence.hcan be used by everybody. It's basically the public interface of thedma_fenceobject.So testing if a fence is signaled without calling the callback is only allowed by whoever implemented the fence.
In other words nouveau can test nouveau fences, i915 can test i915 fences, amdgpu can test amdgpu fences etc... But if you have the wrapper that makes it officially allowed that nouveau starts testing i915 fences and that would be problematic.
But why? Say for example scheduler dependencies - why the scheduler couldn't ignore them at add time, but it can before trying to install a callback on them, and instead has to opportunistically signal someone else's fences?
We had cases where people tested the signaling status from time to time and were then surprised that the fence never signaled.
Quoted 1 line
I don't see it. But even if there is a reason, advantage of the helper is that it can document this at a centralised place.
Yeah, that is basically the only argument I can see which speaks in favor of that approach.
Regards,
Christian.
Quoted 40 lines
Regards,
Tvrtko
Quoted 34 lines
Quoted 33 lines
That has the advantage of centralizing the responsibility and documenting it.
P.
Quoted 27 lines
Regards,
Christian.Quoted 22 lines
Signed-off-by Philipp Stanner <[email protected]>---
drivers/gpu/drm/nouveau/nouveau_fence.c | 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/gpu/drm/nouveau/nouveau_fence.c +1
-1@@ -88,7 +88,7 @@ nouveau_fence_context_kill(struct nouveau_fence_chan *fctx, int error) spin_lock_irqsave(&fctx->lock, flags); list_for_each_entry_safe(fence, tmp, &fctx->pending, head) { - if (error && !dma_fence_is_signaled_locked(&fence- > base)) + if (error && !__dma_fence_is_signaled(&fence- > base))
dma_fence_set_error(&fence->base, error); if (nouveau_fence_signal(fence))
Danilo Krummrich
maintainerRe: [PATCH 2/2] drm/nouveau: Don't signal when killing the fence context
In reply to Christian KönigQuoted 1 line · Christian König
See all the functions inside
include/linux/dma-fence.hcan be used by everybody. It's basically the public interface of thedma_fenceobject.
As you write below, in certain cases it is valid to call this from drivers, so it's not unreasonable to have it as part of the public API.
Quoted 3 lines
So testing if a fence is signaled without calling the callback is only allowed by whoever implemented the fence.
In other words nouveau can test nouveau fences, i915 can test i915 fences, amdgpu can test amdgpu fences etc... But if you have the wrapper that makes it officially allowed that nouveau starts testing i915 fences and that would be problematic.
In general, I like the __dma_fence_is_signaled() helper, because this way we can document in which cases it is allowed to be used, i.e. the ones you descibe above.
test_bit() can be called by anyone and there is no documentation comment explaining that it is only allowed under certain conditions.
Having the __dma_fence_is_signaled() helper properly documented could get you rid of having to explain in which case the test_bit() dance is allowed to do over and over again. :-)
I also think the name is good, since the '__' prefix already implies that there are some restrictions on the use of this helper.
Christian König
maintainerRe: [PATCH 2/2] drm/nouveau: Don't signal when killing the fence context
Quoted 5 lines · Danilo Krummrich
Quoted 1 line · Christian König
See all the functions inside
include/linux/dma-fence.hcan be used by everybody. It's basically the public interface of thedma_fenceobject.As you write below, in certain cases it is valid to call this from drivers, so it's not unreasonable to have it as part of the public API.
The question is from which drivers?
Quoted 10 lines
Quoted 3 lines
So testing if a fence is signaled without calling the callback is only allowed by whoever implemented the fence.
In other words nouveau can test nouveau fences, i915 can test i915 fences, amdgpu can test amdgpu fences etc... But if you have the wrapper that makes it officially allowed that nouveau starts testing i915 fences and that would be problematic.
In general, I like the
__dma_fence_is_signaled()helper, because this way we can document in which cases it is allowed to be used, i.e. the ones you descibe above.
test_bit()can be called by anyone and there is no documentation comment explaining that it is only allowed under certain conditions.
That's a rather good argument.
Quoted 3 lines
Having the
__dma_fence_is_signaled()helper properly documented could get you rid of having to explain in which case thetest_bit()dance is allowed to do over and over again. :-)
That's an even better argument.
Quoted 2 lines
I also think the name is good, since the '__' prefix already implies that there are some restrictions on the use of this helper.
I'm still hesitating. Adding something to the API always made it usable by everybody.
Now suddenly saying we add that to the include/linux/dma-fence.h header but only certainly code can use it still sounds questionable to me.
Regards,
Christian.
Re: [PATCH 2/2] drm/nouveau: Don't signal when killing the fence context
Quoted 44 lines · Christian König
Quoted 8 lines · Danilo Krummrich
Quoted 3 lines · Christian König
See all the functions inside
include/linux/dma-fence.hcan be used by everybody. It's basically the public interface of thedma_fenceobject.As you write below, in certain cases it is valid to call this from drivers, so
it's not unreasonable to have it as part of the public API.The question is from which drivers?
Quoted 14 lines
Quoted 7 lines
So testing if a fence is signaled without calling the callback is only allowed by whoever implemented the fence.
In other words nouveau can test nouveau fences, i915 can test i915 fences, amdgpu can test amdgpu fences etc... But if you have the wrapper that makes it officially allowed that nouveau starts testing i915 fences and that would be problematic.
In general, I like the
__dma_fence_is_signaled()helper, because this way we
can document in which cases it is allowed to be used, i.e. the ones you descibe
above.Quoted 3 lines
test_bit()can be called by anyone and there is no documentation comment
explaining that it is only allowed under certain conditions.That's a rather good argument.
Quoted 5 lines
Having the
__dma_fence_is_signaled()helper properly documented could get you
rid of having to explain in which case thetest_bit()dance is allowed to do
over and over again. :-)That's an even better argument.
Quoted 3 lines
I also think the name is good, since the '__' prefix already implies that there
are some restrictions on the use of this helper.
Quoted 6 lines
I'm still hesitating. Adding something to the API always made it usable by everybody.
Now suddenly saying we add that to the
include/linux/dma-fence.hheader but only certainly code can use it still sounds questionable to me.
If I understand the current code correctly, the documentation state and the question "which driver is allowed to do it?" is the same, because the documentation for the signaled callback doesn't specify that:
/**
* @signaled:
*
* Peek whether the fence is signaled, as a fastpath optimization for
* e.g. dma_fence_wait() or dma_fence_add_callback(). Note that this
* callback does not need to make any guarantees beyond that a fence
* once indicates as signalled must always return true from this
* callback. This callback may return false even if the fence has
* completed already, in this case information hasn't propogated throug
* the system yet. See also dma_fence_is_signaled().
*
* May set &dma_fence.error if returning true.
*
* This callback is optional.
*/
bool (*signaled)(struct dma_fence *fence);
"optional". What if I don't ipmlement it? Who should implement it?
If the callback is optional, then dma_fence_is_signaled() is the same as __dma_fence_is_signaled().
IOW, it already needs to be better documented who needs to implement the callback and who doesn't. If we get clarity on that, we also get clarity on who may use __dma_fence_is_signaled().
P.
Quoted 3 lines
Regards,
Christian.
Christian König
maintainerRe: [PATCH 2/2] drm/nouveau: Don't signal when killing the fence context
Quoted 75 lines · Philipp Stanner
Quoted 44 lines · Christian König
Quoted 8 lines · Danilo Krummrich
Quoted 3 lines · Christian König
See all the functions inside
include/linux/dma-fence.hcan be used by everybody. It's basically the public interface of thedma_fenceobject.As you write below, in certain cases it is valid to call this from drivers, so
it's not unreasonable to have it as part of the public API.The question is from which drivers?
Quoted 14 lines
Quoted 7 lines
So testing if a fence is signaled without calling the callback is only allowed by whoever implemented the fence.
In other words nouveau can test nouveau fences, i915 can test i915 fences, amdgpu can test amdgpu fences etc... But if you have the wrapper that makes it officially allowed that nouveau starts testing i915 fences and that would be problematic.
In general, I like the
__dma_fence_is_signaled()helper, because this way we
can document in which cases it is allowed to be used, i.e. the ones you descibe
above.Quoted 3 lines
test_bit()can be called by anyone and there is no documentation comment
explaining that it is only allowed under certain conditions.That's a rather good argument.
Quoted 5 lines
Having the
__dma_fence_is_signaled()helper properly documented could get you
rid of having to explain in which case thetest_bit()dance is allowed to do
over and over again. :-)That's an even better argument.
Quoted 3 lines
I also think the name is good, since the '__' prefix already implies that there
are some restrictions on the use of this helper.Quoted 6 lines
I'm still hesitating. Adding something to the API always made it usable by everybody.
Now suddenly saying we add that to the
include/linux/dma-fence.hheader but only certainly code can use it still sounds questionable to me.If I understand the current code correctly, the documentation state and the question "which driver is allowed to do it?" is the same, because the documentation for the signaled callback doesn't specify that:
/**
* @signaled:
*
* Peek whether the fence is signaled, as a fastpath optimization for
* e.g.dma_fence_wait()ordma_fence_add_callback(). Note that this
* callback does not need to make any guarantees beyond that a fence
* once indicates as signalled must always return true from this
* callback. This callback may return false even if the fence has
* completed already, in this case information hasn't propogated throug
* the system yet. See alsodma_fence_is_signaled().
*
* May set &dma_fence.error if returning true.
*
* This callback is optional.
*/
bool (*signaled)(structdma_fence*fence);
Quoted 8 lines
"optional". What if I don't ipmlement it? Who should implement it?
If the callback is optional, then
dma_fence_is_signaled()is the same as__dma_fence_is_signaled().IOW, it already needs to be better documented who needs to implement the callback and who doesn't. If we get clarity on that, we also get clarity on who may use
__dma_fence_is_signaled().
Well there is no need to implement it, but when it is implemented the caller *must* call it when polling.
IIRC the background that we didn't allowed this was that we already had the case that users only looked at the signaling bit and then where surprised that it never changed.
Regards,
Christian.
Quoted 8 lines
P.
Quoted 3 lines
Regards,
Christian.
Re: [PATCH 2/2] drm/nouveau: Don't signal when killing the fence context
Quoted 99 lines · Christian König
Quoted 98 lines · Philipp Stanner
Quoted 52 lines · Christian König
Quoted 10 lines · Danilo Krummrich
Quoted 3 lines · Christian König
See all the functions inside
include/linux/dma-fence.hcan be used by everybody. It's basically the public interface of thedma_fenceobject.As you write below, in certain cases it is valid to call this from
drivers, so
it's not unreasonable to have it as part of the public API.The question is from which drivers?
Quoted 19 lines
Quoted 10 lines
So testing if a fence is signaled without calling the callback is
only allowed by whoever implemented the fence.In other words nouveau can test nouveau fences, i915 can test i915 fences, amdgpu can test amdgpu fences etc... But if you have
the wrapper that makes it officially allowed that nouveau starts
testing i915 fences and that would be problematic.In general, I like the
__dma_fence_is_signaled()helper, because
this way we
can document in which cases it is allowed to be used, i.e. the ones
you descibe
above.Quoted 4 lines
test_bit()can be called by anyone and there is no documentation
comment
explaining that it is only allowed under certain conditions.That's a rather good argument.
Quoted 5 lines
Having the
__dma_fence_is_signaled()helper properly documented could get you
rid of having to explain in which case thetest_bit()dance is allowed to do
over and over again. :-)That's an even better argument.
Quoted 3 lines
I also think the name is good, since the '__' prefix already implies that there
are some restrictions on the use of this helper.Quoted 7 lines
I'm still hesitating. Adding something to the API always made it usable by everybody.
Now suddenly saying we add that to the
include/linux/dma-fence.hheader but only certainly code can use it still sounds questionable
to me.If I understand the current code correctly, the documentation state and
the question "which driver is allowed to do it?" is the same, because
the documentation for the signaled callback doesn't specify that:/** * @signaled: * * Peek whether the fence is signaled, as a fastpathoptimization for
* e.g.dma_fence_wait()ordma_fence_add_callback(). Note
that this
* callback does not need to make any guarantees beyond
that a fence
* once indicates as signalled must always return true
from this
* callback. This callback may return false even if the
fence has
* completed already, in this case information hasn't
propogated throug* the system yet. See also dma_fence_is_signaled(). * * May set &dma_fence.error if returning true. * * This callback is optional. */ bool (*signaled)(struct dma_fence *fence);"optional". What if I don't ipmlement it? Who should implement it?
If the callback is optional, then
dma_fence_is_signaled()is the same
as__dma_fence_is_signaled().
Quoted 8 lines
Quoted 5 lines
IOW, it already needs to be better documented who needs to implement
the callback and who doesn't. If we get clarity on that, we also get
clarity on who may use__dma_fence_is_signaled().Well there is no need to implement it, but when it is implemented the caller *must* call it when polling.
I don't understand. Please elaborate on that a bit more. If there's no need to implement it, then why can't one have a __dma_fence_is_signaled(), which is then identical?
Quoted 4 lines
IIRC the background that we didn't allowed this was that we already had the case that users only looked at the signaling bit and then where surprised that it never changed.
Why would anyone expect that a fence gets signaled by calling a function with the name "dma_fence_is_signaled()"? :-)
That was my original point, the name is not intuitive at all.
For example, if a driver doesn't implement that callback but signals fences in interrupt handlers, and then forgets to (re-)activate the interrupt, fences will never get signaled and callers to dma_fence_is_signaled() will never read 'true', which isn't surprising.
Again, the point remains the same: the driver must guarantee that fences will get signaled. Independently from how consumers of the fence check it. Consumers could just stop calling dma_fence_is_signaled() after the point in time T alltogether and then the driver would still have to signal everything.
P.
Quoted 13 lines
Regards,
Christian.Quoted 8 lines
P.
Quoted 3 lines
Regards,
Christian.
Christian König
maintainerRe: [PATCH 2/2] drm/nouveau: Don't signal when killing the fence context
Quoted 7 lines · Philipp Stanner
Quoted 3 lines
Well there is no need to implement it, but when it is implemented the caller *must* call it when polling.
I don't understand. Please elaborate on that a bit more. If there's no need to implement it, then why can't one have a
__dma_fence_is_signaled(), which is then identical?
Because the caller then doesn't call it when it is implemented.
E.g. you give people a function which ignores the callback.
Quoted 7 lines
Quoted 4 lines
IIRC the background that we didn't allowed this was that we already had the case that users only looked at the signaling bit and then where surprised that it never changed.
Why would anyone expect that a fence gets signaled by calling a function with the name "
dma_fence_is_signaled()"? :-)
Because when that function returns true the fence is considered signaled.
Quoted 7 lines
That was my original point, the name is not intuitive at all.
For example, if a driver doesn't implement that callback but signals fences in interrupt handlers, and then forgets to (re-)activate the interrupt, fences will never get signaled and callers to
dma_fence_is_signaled()will never read 'true', which isn't surprising.
Quoted 5 lines
Again, the point remains the same: the driver must guarantee that fences will get signaled. Independently from how consumers of the fence check it. Consumers could just stop calling
dma_fence_is_signaled()after the point in time T alltogether and then the driver would still have to signal everything.
No it doesn't. You need to call dma_fence_enable_signaling for that.
Regards,
Christian.
Quoted 20 lines
P.
Quoted 13 lines
Regards,
Christian.Quoted 8 lines
P.
Quoted 3 lines
Regards,
Christian.
Danilo Krummrich
maintainerRe: [PATCH 2/2] drm/nouveau: Don't signal when killing the fence context
In reply to Christian KönigQuoted 8 lines · Christian König
Quoted 5 lines · Danilo Krummrich
Quoted 1 line · Christian König
See all the functions inside
include/linux/dma-fence.hcan be used by everybody. It's basically the public interface of thedma_fenceobject.As you write below, in certain cases it is valid to call this from drivers, so it's not unreasonable to have it as part of the public API.
The question is from which drivers?
Well, any driver that uses it to check its own fences, as you say below.
Quoted 17 lines
Quoted 10 lines
Quoted 3 lines
So testing if a fence is signaled without calling the callback is only allowed by whoever implemented the fence.
In other words nouveau can test nouveau fences, i915 can test i915 fences, amdgpu can test amdgpu fences etc... But if you have the wrapper that makes it officially allowed that nouveau starts testing i915 fences and that would be problematic.
In general, I like the
__dma_fence_is_signaled()helper, because this way we can document in which cases it is allowed to be used, i.e. the ones you descibe above.
test_bit()can be called by anyone and there is no documentation comment explaining that it is only allowed under certain conditions.That's a rather good argument.
Quoted 3 lines
Having the
__dma_fence_is_signaled()helper properly documented could get you rid of having to explain in which case thetest_bit()dance is allowed to do over and over again. :-)
Quoted 6 lines
That's an even better argument.
Quoted 2 lines
I also think the name is good, since the '__' prefix already implies that there are some restrictions on the use of this helper.
I'm still hesitating. Adding something to the API always made it usable by everybody.
You can't prevent that, the test_bit() dance can be done by anyone, but you can document it properly with this helper. :-)
Quoted 3 lines · Philipp Stanner
Some parties want to check whether a function is already signaled without actually signaling the fence, which is what
dma_fence_is_signaled()might due if the fence ops 'signaled' callback
s/due/do/
Quoted 16 lines
is implemented.
Add
__dma_fence_is_signaled(), which _only_ checks whether a fence is signaled. Use it internally.Suggested-by Tvrtko Ursulin <[email protected]>Signed-off-by Philipp Stanner <[email protected]>--- include/linux/dma-fence.h | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)include/linux/dma-fence.h +0
-0
include/linux/dma-fence.h bool dma_fence_remove_callback(struct dma_fence *fence, · line 389
Quoted 9 lines
include/linux/dma-fence.h +6
-0@@ -381,6 +381,26 @@ bool dma_fence_remove_callback(struct dma_fence *fence, struct dma_fence_cb *cb);void dma_fence_enable_sw_signaling (struct dma_fence *fence); +/** +* __dma_fence_is_signaled - Only check whether a fence is signaled yet. +* @fence: the fence to check +* +* This function just checks whether @fence is signaled, without interacting +* with the fence in any way. The user must, therefore, ensure through other
s/user/caller/ ?
Otherwise looks good to me. For if/when Christian approves you can add my:
Regards,
Tvrtko
Quoted 35 lines
include/linux/dma-fence.h +16
-2+* means that fences get signaled eventually. +* +* This function does not require locking. +* +* See also dma_fence_is_signaled(). +* +* Return: true if signaled, false otherwise. +*/ +static inline bool +__dma_fence_is_signaled (struct dma_fence *fence) +{ +return test_bit (DMA_FENCE_FLAG_SIGNALED_BIT , &fence->flags); +} +/** * dma_fence_is_signaled_locked - Return an indication if the fence * is signaled yet. @@ -398,7 +418,7 @@ void dma_fence_enable_sw_signaling(struct dma_fence *fence);static inline bool dma_fence_is_signaled_locked (struct dma_fence *fence) { -if (test_bit (DMA_FENCE_FLAG_SIGNALED_BIT , &fence->flags)) +if (__dma_fence_is_signaled (fence))return true;if (fence->ops->signaled && fence->ops->signaled (fence)) {@@ -428,7 +448,7 @@ dma_fence_is_signaled_locked(struct dma_fence *fence)static inline bool dma_fence_is_signaled (struct dma_fence *fence) { -if (test_bit (DMA_FENCE_FLAG_SIGNALED_BIT , &fence->flags)) +if (__dma_fence_is_signaled (fence))return true;if (fence->ops->signaled && fence->ops->signaled (fence)) {