Skip to contentSkip to conversation

dma-buf/fence-array: get signaled state when signaling is disabled

PATCH In review Gustavo Padovan 5 participants 14 messages Sep 21, 2016 – Sep 26, 2016 DMA buffer sharing framework

lore
Share & tools
lore
#0 lore raw

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
index f1989fc..1eec271 100644
@@ -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
maintainer
#1 lore raw

Am 21.09.2016 um 13:36 schrieb Gustavo Padovan:

Quoted 9 lines

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.

Quoted 6 lines

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.

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
index f1989fc..1eec271 100644
@@ -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

#2 lore raw

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_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.

Quoted 6 lines
Quoted 2 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?

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 calling enable_signaling there 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

maintainer
#3 lore raw

Am 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_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.

Quoted 7 lines
Quoted 5 lines
Quoted 2 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.

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 calling enable_signaling there 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 if fence_add_callback, fence_wait or fence_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

#4 lore raw

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_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.

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 calling enable_signaling there 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 if fence_add_callback, fence_wait or fence_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

maintainer
#5 lore raw

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.

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

#6 lore raw

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

maintainer
#7 lore raw

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.

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

maintainer
#8 lore raw

Am 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

#9 lore raw
In reply to Christian König

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

maintainer
#10 lore raw

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_wait change. 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

#11 lore raw

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_wait change. 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

#12 lore raw
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_wait change. 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
index 0d763053f97a..ed5e88d2b664 100644
@@ -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
Reviewed-by on v1 1/1
#13 lore raw
In reply to Gustavo Padovan
Quoted 9 lines · Gustavo Padovan

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.

Quoted 6 lines

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.

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
index f1989fc..1eec271 100644
@@ -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