dma-buf/fence-array: get signaled state when signaling is disabled
PATCH 1/1 dma-buf/fence-array: get signaled state when signaling is disabled
From: Gustavo Padovan <[email protected]>
If the fences in the fence_array signal on the fence_array does not have signalling enabled num_pending will not be updated accordingly.
So when signaling is disabled check the signal of every fence with fence_is_signaled() and then compare with num_pending to learn if the fence_array was signalled or not.
If we want to keep the poll_does_not_wait optimization I think we need something like this. It keeps the same behaviour if signalling is enabled but tries to calculated the state otherwise.
--- drivers/dma-buf/fence-array.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
drivers/dma-buf/fence-array.c +18 -1
@@ -75,8 +75,25 @@ static bool fence_array_enable_signaling(struct fence *fence)static bool fence_array_signaled (struct fence *fence) {struct fence_array *array =to_fence_array (fence); +int i, num_pending; + + num_pending =atomic_read (&array->num_pending); + +/* +* Before signaling is enabled, num_pending is static (set during array +* construction as a count of all fences or set to 1 if signal_on_any +* flag is passed. To ensure forward progress, i.e. a while +* (!fence_is_signaled()) ; busy-loop eventually proceeds, we need to +* check the current status of our fences. +*/ +if (!test_bit (FENCE_FLAG_ENABLE_SIGNAL_BIT , &fence->flags)) { +for (i =0 ; i < array->num_fences; ++i) { +if (fence_is_signaled (array->fences[i])) + num_pending--; + } + } -return atomic_read (&array->num_pending) <=0 ; +return num_pending <=0 ; }static void fence_array_release (struct fence *fence)
Signature · 6 lines
2.5.5 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerAm 21.09.2016 um 13:36 schrieb Gustavo Padovan:
Quoted 9 lines
From: Gustavo Padovan <[email protected]>
If the fences in the
fence_arraysignal on thefence_arraydoes not have signalling enablednum_pendingwill not be updated accordingly.So when signaling is disabled check the signal of every fence with
fence_is_signaled()and then compare withnum_pendingto learn if thefence_arraywas signalled or not.
Quoted 6 lines
If we want to keep the
poll_does_not_waitoptimization I think we need something like this. It keeps the same behaviour if signalling is enabled but tries to calculated the state otherwise.Signed-off-by Gustavo Padovan <[email protected]>Reviewed-by Chris Wilson <[email protected]>
First of all the patch is horrible wrong because fence_array_signaled() is called without any locks held. So you can run into a race condition between checking the fences here and enable signaling.
Additional to that I'm not sure if that is such a good idea or not, cause fence_array_signaled() should be light weight and without calling enable_signaling there is not guarantee that fences will ever signal.
Regards,
Christian.
Quoted 25 lines
--- drivers/dma-buf/fence-array.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)drivers/dma-buf/fence-array.c +13
-0@@ -75,8 +75,25 @@ static bool fence_array_enable_signaling(struct fence *fence)static bool fence_array_signaled (struct fence *fence) {struct fence_array *array =to_fence_array (fence); +int i, num_pending; + + num_pending =atomic_read (&array->num_pending); + +/* +* Before signaling is enabled, num_pending is static (set during array +* construction as a count of all fences or set to 1 if signal_on_any +* flag is passed. To ensure forward progress, i.e. a while +* (!fence_is_signaled()) ; busy-loop eventually proceeds, we need to +* check the current status of our fences. +*/ +if (!test_bit (FENCE_FLAG_ENABLE_SIGNAL_BIT , &fence->flags)) { +for (i =0 ; i < array->num_fences; ++i) {
drivers/dma-buf/fence-array.c static bool fence_array_enable_signaling(struct fence *fence) · line 99
Quoted 10 lines
drivers/dma-buf/fence-array.c +5
-1+if (fence_is_signaled (array->fences[i])) + num_pending--; + } + } -return atomic_read (&array->num_pending) <=0 ; +return num_pending <=0 ; }static void fence_array_release (struct fence *fence)
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi Christian,
2016-09-21 Christian König <[email protected]>:
Quoted 14 lines
Am 21.09.2016 um 13:36 schrieb Gustavo Padovan:
Quoted 13 lines
From: Gustavo Padovan <[email protected]>
If the fences in the
fence_arraysignal on thefence_arraydoes not have signalling enablednum_pendingwill not be updated accordingly.So when signaling is disabled check the signal of every fence with
fence_is_signaled()and then compare withnum_pendingto learn if thefence_arraywas signalled or not.If we want to keep the
poll_does_not_waitoptimization I think we need something like this. It keeps the same behaviour if signalling is enabled but tries to calculated the state otherwise.
Quoted 6 lines
Quoted 2 lines
Signed-off-by Gustavo Padovan <[email protected]>Reviewed-by Chris Wilson <[email protected]>First of all the patch is horrible wrong because
fence_array_signaled()is called without any locks held. So you can run into a race condition between checking the fences here and enable signaling.
Yes. it can, but I don't think the race condition is actually a problem. Maybe you have some use case that we are not seeing?
Quoted 3 lines
Additional to that I'm not sure if that is such a good idea or not, cause
fence_array_signaled()should be light weight and without callingenable_signalingthere is not guarantee that fences will ever signal.
It is still lightweight for the case when signaling is enabled and fences can signal with signaling enabled or disabled so I don't see that as problem too.
Gustavo
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerAm 22.09.2016 um 09:44 schrieb Gustavo Padovan:
Quoted 18 lines
Hi Christian,
2016-09-21 Christian König <[email protected]>:
Quoted 14 lines
Am 21.09.2016 um 13:36 schrieb Gustavo Padovan:
Quoted 13 lines
From: Gustavo Padovan <[email protected]>
If the fences in the
fence_arraysignal on thefence_arraydoes not have signalling enablednum_pendingwill not be updated accordingly.So when signaling is disabled check the signal of every fence with
fence_is_signaled()and then compare withnum_pendingto learn if thefence_arraywas signalled or not.If we want to keep the
poll_does_not_waitoptimization I think we need something like this. It keeps the same behaviour if signalling is enabled but tries to calculated the state otherwise.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Signed-off-by Gustavo Padovan <[email protected]>Reviewed-by Chris Wilson <[email protected]>First of all the patch is horrible wrong because
fence_array_signaled()is called without any locks held. So you can run into a race condition between checking the fences here and enable signaling.Yes. it can, but I don't think the race condition is actually a problem. Maybe you have some use case that we are not seeing?
I'm not sure if that can really race, but if it does the check would return true while not all necessary fences are signaled yet.
That would be really really bad for things like TTM where we just do a quick check in the page fault handler for example.
I need to double check if that really could be a problem.
Quoted 5 lines
Quoted 3 lines
Additional to that I'm not sure if that is such a good idea or not, cause
fence_array_signaled()should be light weight and without callingenable_signalingthere is not guarantee that fences will ever signal.It is still lightweight for the case when signaling is enabled and fences can signal with signaling enabled or disabled
Nope that's not correct. The signaled callback is only optional.
See the comment on the fence_is_signaled function:
Quoted 5 lines
* Returns true if the fence was already signaled, false if not. Since
this
* function doesn't enable signaling, it is not guaranteed to ever return
* true iffence_add_callback,fence_waitorfence_enable_sw_signaling
* haven't been called before.
E.g. for example it is illegal to do something like "while(!fence_is_signaled(f)) sleep();" without enabling signaling before doing this.
Could just be a misunderstanding, but the comments on your patch actually sounds a bit like somebody is trying to do exactly that.
Regards,
Christian.
Quoted 5 lines
so I don't see that
as problem too.Gustavo
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
2016-09-22 Christian König <[email protected]>:
Quoted 21 lines
Am 22.09.2016 um 09:44 schrieb Gustavo Padovan:
Quoted 20 lines
Hi Christian,
2016-09-21 Christian König <[email protected]>:
Quoted 16 lines
Am 21.09.2016 um 13:36 schrieb Gustavo Padovan:
Quoted 15 lines
From: Gustavo Padovan <[email protected]>
If the fences in the
fence_arraysignal on thefence_arraydoes not have signalling enablednum_pendingwill not be updated accordingly.So when signaling is disabled check the signal of every fence with
fence_is_signaled()and then compare withnum_pendingto learn if thefence_arraywas signalled or not.If we want to keep the
poll_does_not_waitoptimization I think we need something like this. It keeps the same behaviour if signalling is enabled but tries to calculated the state otherwise.Signed-off-by Gustavo Padovan <[email protected]>Reviewed-by Chris Wilson <[email protected]>
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
First of all the patch is horrible wrong because
fence_array_signaled()is called without any locks held. So you can run into a race condition between checking the fences here and enable signaling.Yes. it can, but I don't think the race condition is actually a problem. Maybe you have some use case that we are not seeing?
I'm not sure if that can really race, but if it does the check would return true while not all necessary fences are signaled yet.
How? If signaling is disabled num_pending is equal to the number of fences (or 1 if signal_on_any) then we just check all fences. If all of them are signaled then num_pending will be zero.
Quoted 6 lines
That would be really really bad for things like TTM where we just do a quick check in the page fault handler for example.
I need to double check if that really could be a problem.
Quoted 13 lines
Quoted 5 lines
Quoted 3 lines
Additional to that I'm not sure if that is such a good idea or not, cause
fence_array_signaled()should be light weight and without callingenable_signalingthere is not guarantee that fences will ever signal.It is still lightweight for the case when signaling is enabled and fences can signal with signaling enabled or disabled
Nope that's not correct. The signaled callback is only optional.
See the comment on the
fence_is_signaledfunction:Quoted 5 lines
* Returns true if the fence was already signaled, false if not. Since
this
* function doesn't enable signaling, it is not guaranteed to ever return
* true iffence_add_callback,fence_waitorfence_enable_sw_signaling
* haven't been called before.
Right, I was with explicit fencing in mind, we only enable signaling there if userspace polls.
Quoted 6 lines
E.g. for example it is illegal to do something like "while(!fence_is_signaled(f))
sleep();" without enabling signaling before doing this.Could just be a misunderstanding, but the comments on your patch actually sounds a bit like somebody is trying to do exactly that.
I think the usecase in mind here is poll(fd, timeout=0)
Gustavo
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerDropping the rest of the patch, cause that really doesn't make sense any more.
Am 22.09.2016 um 12:40 schrieb Gustavo Padovan:
Quoted 7 lines
Quoted 6 lines
E.g. for example it is illegal to do something like
Quoted 5 lines
"while(!fence_is_signaled(f))
sleep();" without enabling signaling before doing this.Could just be a misunderstanding, but the comments on your patch actually sounds a bit like somebody is trying to do exactly that.
I think the usecase in mind here is
poll(fd, timeout=0)
Exactly as I feared. Even if userspace polls with timeout=0 you still need to call enable_signaling().
Otherwise you can run into a situation where userspace only uses timeout=0 and so never activates the signaling check in the driver.
This would in turn result in an endless loop on implementations where the driver never signals fences on their own.
Regards,
Christian.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
2016-09-22 Christian König <[email protected]>:
Quoted 12 lines
Dropping the rest of the patch, cause that really doesn't make sense any more.
Am 22.09.2016 um 12:40 schrieb Gustavo Padovan:
Quoted 7 lines
Quoted 6 lines
E.g. for example it is illegal to do something like
Quoted 5 lines
"while(!fence_is_signaled(f))
sleep();" without enabling signaling before doing this.Could just be a misunderstanding, but the comments on your patch actually sounds a bit like somebody is trying to do exactly that.
I think the usecase in mind here is
poll(fd, timeout=0)
Quoted 8 lines
Exactly as I feared. Even if userspace polls with timeout=0 you still need to call
enable_signaling().Otherwise you can run into a situation where userspace only uses timeout=0 and so never activates the signaling check in the driver.
This would in turn result in an endless loop on implementations where the driver never signals fences on their own.
Polling is optional, userspace may never call it. And DRM/KMS or GPU drivers will be doing fence_wait() themselves so signaling is enabled at some point.
Gustavo
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerAm 22.09.2016 um 13:16 schrieb Gustavo Padovan:
Quoted 16 lines
2016-09-22 Christian König <[email protected]>:
Quoted 14 lines
Dropping the rest of the patch, cause that really doesn't make sense any more.
Am 22.09.2016 um 12:40 schrieb Gustavo Padovan:
Quoted 7 lines
Quoted 6 lines
E.g. for example it is illegal to do something like
Quoted 5 lines
"while(!fence_is_signaled(f))
sleep();" without enabling signaling before doing this.Could just be a misunderstanding, but the comments on your patch actually sounds a bit like somebody is trying to do exactly that.
I think the usecase in mind here is
poll(fd, timeout=0)Exactly as I feared. Even if userspace polls with timeout=0 you still need to call
enable_signaling().
Quoted 8 lines
Quoted 5 lines
Otherwise you can run into a situation where userspace only uses timeout=0 and so never activates the signaling check in the driver.
This would in turn result in an endless loop on implementations where the driver never signals fences on their own.
Polling is optional, userspace may never call it. And DRM/KMS or GPU drivers will be doing
fence_wait()themselves so signaling is enabled at some point.
No they won't. We have an use case where we clearly want to avoid that as much as possible because and so the driver never calls enable_signaling() on it's own.
Exposing this poll function to userspace without enabling signaling is a clear NAK from my side.
Christian.
Quoted 3 lines
Gustavo
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerAm 22.09.2016 um 16:11 schrieb Christian König:
Quoted 20 lines
Am 22.09.2016 um 13:16 schrieb Gustavo Padovan:
Quoted 19 lines
2016-09-22 Christian König <[email protected]>:
Quoted 17 lines
Dropping the rest of the patch, cause that really doesn't make sense any more.
Am 22.09.2016 um 12:40 schrieb Gustavo Padovan:
Quoted 7 lines
Quoted 6 lines
E.g. for example it is illegal to do something like
Quoted 5 lines
"while(!fence_is_signaled(f))
sleep();" without enabling signaling before doing this.Could just be a misunderstanding, but the comments on your patch actually sounds a bit like somebody is trying to do exactly that.
I think the usecase in mind here is
poll(fd, timeout=0)Exactly as I feared. Even if userspace polls with timeout=0 you still need to call
enable_signaling().Otherwise you can run into a situation where userspace only uses timeout=0 and so never activates the signaling check in the driver.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
This would in turn result in an endless loop on implementations where the driver never signals fences on their own.
Polling is optional, userspace may never call it. And DRM/KMS or GPU drivers will be doing
fence_wait()themselves so signaling is enabled at some point.No they won't. We have an use case where we clearly want to avoid that as much as possible because and so the driver never calls
enable_signaling()on it's own.
Sorry hitting send to soon. That should read "because of the extreme overhead".
Christian.
Quoted 9 lines
Exposing this poll function to userspace without enabling signaling is a clear NAK from my side.
Christian.
Quoted 3 lines
Gustavo
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
2016-09-22 Christian König <[email protected]>:
Quoted 26 lines
Am 22.09.2016 um 13:16 schrieb Gustavo Padovan:
Quoted 16 lines
2016-09-22 Christian König <[email protected]>:
Quoted 14 lines
Dropping the rest of the patch, cause that really doesn't make sense any more.
Am 22.09.2016 um 12:40 schrieb Gustavo Padovan:
Quoted 7 lines
Quoted 6 lines
E.g. for example it is illegal to do something like
Quoted 5 lines
"while(!fence_is_signaled(f))
sleep();" without enabling signaling before doing this.Could just be a misunderstanding, but the comments on your patch actually sounds a bit like somebody is trying to do exactly that.
I think the usecase in mind here is
poll(fd, timeout=0)Exactly as I feared. Even if userspace polls with timeout=0 you still need to call
enable_signaling().Quoted 8 lines
Quoted 5 lines
Otherwise you can run into a situation where userspace only uses timeout=0 and so never activates the signaling check in the driver.
This would in turn result in an endless loop on implementations where the driver never signals fences on their own.
Polling is optional, userspace may never call it. And DRM/KMS or GPU drivers will be doing
fence_wait()themselves so signaling is enabled at some point.
Quoted 6 lines
No they won't. We have an use case where we clearly want to avoid that as much as possible because and so the driver never calls
enable_signaling()on it's own.Exposing this poll function to userspace without enabling signaling is a clear NAK from my side.
Okay. So you are NAK'ing the does_not_pool_wait change. Should we revert that one then? It is already broken.
Gustavo
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Christian König
maintainerAm 23.09.2016 um 13:30 schrieb Gustavo Padovan:
Quoted 27 lines
2016-09-22 Christian König <[email protected]>:
Quoted 25 lines
Am 22.09.2016 um 13:16 schrieb Gustavo Padovan:
Quoted 24 lines
2016-09-22 Christian König <[email protected]>:
Quoted 11 lines
Dropping the rest of the patch, cause that really doesn't make sense any more.
Am 22.09.2016 um 12:40 schrieb Gustavo Padovan:
Quoted 7 lines
Quoted 6 lines
E.g. for example it is illegal to do something like
Quoted 5 lines
"while(!fence_is_signaled(f))
sleep();" without enabling signaling before doing this.Could just be a misunderstanding, but the comments on your patch actually sounds a bit like somebody is trying to do exactly that.
I think the usecase in mind here is
poll(fd, timeout=0)Quoted 8 lines
Exactly as I feared. Even if userspace polls with timeout=0 you still need to call
enable_signaling().Otherwise you can run into a situation where userspace only uses timeout=0 and so never activates the signaling check in the driver.
This would in turn result in an endless loop on implementations where the driver never signals fences on their own.
Polling is optional, userspace may never call it. And DRM/KMS or GPU drivers will be doing
fence_wait()themselves so signaling is enabled at some point.
Quoted 8 lines
Quoted 6 lines
No they won't. We have an use case where we clearly want to avoid that as much as possible because and so the driver never calls
enable_signaling()on it's own.Exposing this poll function to userspace without enabling signaling is a clear NAK from my side.
Okay. So you are NAK'ing the
does_not_pool_waitchange. Should we revert that one then? It is already broken.
Yeah, that would probably a good idea. The AMD driver changes which really rely on this aren't upstream yet, so if you point me to the commit hash I could revert that as well when we send that out.
On the other hand the idea behind fence_is_signaled() is really that you check the status multiple times after enabling signaling. So I would prefer if you would revert this change preliminary.
Double checking this patch (and thinking about it a bit more) reveals that it is most likely correct. So feel free to commit this one if it is still needed for something.
Regards,
Christian.
Quoted 3 lines
Gustavo
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
2016-09-23 Christian König <[email protected]>:
Quoted 41 lines
Am 23.09.2016 um 13:30 schrieb Gustavo Padovan:
Quoted 27 lines
2016-09-22 Christian König <[email protected]>:
Quoted 25 lines
Am 22.09.2016 um 13:16 schrieb Gustavo Padovan:
Quoted 24 lines
2016-09-22 Christian König <[email protected]>:
Quoted 11 lines
Dropping the rest of the patch, cause that really doesn't make sense any more.
Am 22.09.2016 um 12:40 schrieb Gustavo Padovan:
Quoted 7 lines
Quoted 6 lines
E.g. for example it is illegal to do something like
Quoted 5 lines
"while(!fence_is_signaled(f))
sleep();" without enabling signaling before doing this.Could just be a misunderstanding, but the comments on your patch actually sounds a bit like somebody is trying to do exactly that.
I think the usecase in mind here is
poll(fd, timeout=0)Quoted 8 lines
Exactly as I feared. Even if userspace polls with timeout=0 you still need to call
enable_signaling().Otherwise you can run into a situation where userspace only uses timeout=0 and so never activates the signaling check in the driver.
This would in turn result in an endless loop on implementations where the driver never signals fences on their own.
Polling is optional, userspace may never call it. And DRM/KMS or GPU drivers will be doing
fence_wait()themselves so signaling is enabled at some point.Quoted 8 lines
Quoted 6 lines
No they won't. We have an use case where we clearly want to avoid that as much as possible because and so the driver never calls
enable_signaling()on it's own.Exposing this poll function to userspace without enabling signaling is a clear NAK from my side.
Okay. So you are NAK'ing the
does_not_pool_waitchange. Should we revert that one then? It is already broken.Yeah, that would probably a good idea. The AMD driver changes which really rely on this aren't upstream yet, so if you point me to the commit hash I could revert that as well when we send that out.
Quoted 7 lines
On the other hand the idea behind
fence_is_signaled()is really that you check the status multiple times after enabling signaling. So I would prefer if you would revert this change preliminary.Double checking this patch (and thinking about it a bit more) reveals that it is most likely correct. So feel free to commit this one if it is still needed for something.
It is this patch:
ecebca7 dma-buf/sync-file: Avoid enable fence signaling if poll(.timeout=0)
But if we revert it as you are a proposing we don't need my patch here anymore. However we would need to revert it now because it is broken. Shall I send a revert part?
Gustavo
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 51 lines · Gustavo Padovan
2016-09-23 Christian König <[email protected]>:
Quoted 41 lines
Am 23.09.2016 um 13:30 schrieb Gustavo Padovan:
Quoted 27 lines
2016-09-22 Christian König <[email protected]>:
Quoted 25 lines
Am 22.09.2016 um 13:16 schrieb Gustavo Padovan:
Quoted 24 lines
2016-09-22 Christian König <[email protected]>:
Quoted 11 lines
Dropping the rest of the patch, cause that really doesn't make sense any more.
Am 22.09.2016 um 12:40 schrieb Gustavo Padovan:
Quoted 7 lines
Quoted 6 lines
E.g. for example it is illegal to do something like
Quoted 5 lines
"while(!fence_is_signaled(f))
sleep();" without enabling signaling before doing this.Could just be a misunderstanding, but the comments on your patch actually sounds a bit like somebody is trying to do exactly that.
I think the usecase in mind here is
poll(fd, timeout=0)Quoted 8 lines
Exactly as I feared. Even if userspace polls with timeout=0 you still need to call
enable_signaling().Otherwise you can run into a situation where userspace only uses timeout=0 and so never activates the signaling check in the driver.
This would in turn result in an endless loop on implementations where the driver never signals fences on their own.
Polling is optional, userspace may never call it. And DRM/KMS or GPU drivers will be doing
fence_wait()themselves so signaling is enabled at some point.Quoted 8 lines
Quoted 6 lines
No they won't. We have an use case where we clearly want to avoid that as much as possible because and so the driver never calls
enable_signaling()on it's own.Exposing this poll function to userspace without enabling signaling is a clear NAK from my side.
Okay. So you are NAK'ing the
does_not_pool_waitchange. Should we revert that one then? It is already broken.Yeah, that would probably a good idea. The AMD driver changes which really rely on this aren't upstream yet, so if you point me to the commit hash I could revert that as well when we send that out.
Quoted 7 lines
On the other hand the idea behind
fence_is_signaled()is really that you check the status multiple times after enabling signaling. So I would prefer if you would revert this change preliminary.Double checking this patch (and thinking about it a bit more) reveals that it is most likely correct. So feel free to commit this one if it is still needed for something.
Quoted 7 lines
It is this patch:
ecebca7 dma-buf/sync-file: Avoid enable fence signaling if poll(.timeout=0)
But if we revert it as you are a proposing we don't need my patch here anymore. However we would need to revert it now because it is broken. Shall I send a revert part?
Adding and propagating:
include/linux/fence.h +2 -0
@@ -56,6 +56,7 @@ struct fence_cb;* * FENCE_FLAG_SIGNALED_BIT - fence is already signaled * FENCE_FLAG_ENABLE_SIGNAL_BIT - enable_signaling might have been called* +* FENCE_FLAG_AUTO_SIGNAL_BIT - ops->signaled() is accurate by itself * FENCE_FLAG_USER_BITS - start of the unused bits, can be used by the * implementer of the fence for its own purposes. Can be used in different * ways by different fence implementers, so do not rely on this.
@@ -85,6 +86,7 @@ struct fence {enum fence_flag_bits {FENCE_FLAG_SIGNALED_BIT ,FENCE_FLAG_ENABLE_SIGNAL_BIT , +FENCE_FLAG_AUTO_SIGNAL_BIT ,FENCE_FLAG_USER_BITS ,/* must always be last member */ };
is trivial (I'm just stuck on naming and explaining it in kerneldoc). The race Christian described in this patch is simple to prevent (on x86 all that is missing is a compiler barrier, smp_mb__before_atomic() to be generic), and it allows for external-fences to be as cheap as native fences.
-Chris
Signature · 5 lines
Chris Wilson, Intel Open Source Technology Centre _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 9 lines · Gustavo Padovan
From: Gustavo Padovan <[email protected]>
If the fences in the
fence_arraysignal on thefence_arraydoes not have signalling enablednum_pendingwill not be updated accordingly.So when signaling is disabled check the signal of every fence with
fence_is_signaled()and then compare withnum_pendingto learn if thefence_arraywas signalled or not.
Quoted 6 lines
If we want to keep the
poll_does_not_waitoptimization I think we need something like this. It keeps the same behaviour if signalling is enabled but tries to calculated the state otherwise.Signed-off-by Gustavo Padovan <[email protected]>Reviewed-by Chris Wilson <[email protected]>
Regards,
David Zhou
Quoted 25 lines
--- drivers/dma-buf/fence-array.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)drivers/dma-buf/fence-array.c +13
-0@@ -75,8 +75,25 @@ static bool fence_array_enable_signaling(struct fence *fence)static bool fence_array_signaled (struct fence *fence) {struct fence_array *array =to_fence_array (fence); +int i, num_pending; + + num_pending =atomic_read (&array->num_pending); + +/* +* Before signaling is enabled, num_pending is static (set during array +* construction as a count of all fences or set to 1 if signal_on_any +* flag is passed. To ensure forward progress, i.e. a while +* (!fence_is_signaled()) ; busy-loop eventually proceeds, we need to +* check the current status of our fences. +*/ +if (!test_bit (FENCE_FLAG_ENABLE_SIGNAL_BIT , &fence->flags)) { +for (i =0 ; i < array->num_fences; ++i) {
drivers/dma-buf/fence-array.c static bool fence_array_enable_signaling(struct fence *fence) · line 99
Quoted 10 lines
drivers/dma-buf/fence-array.c +5
-1+if (fence_is_signaled (array->fences[i])) + num_pending--; + } + } -return atomic_read (&array->num_pending) <=0 ; +return num_pending <=0 ; }static void fence_array_release (struct fence *fence)
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel