Skip to contentSkip to conversation

Deprecation of AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED

RFC PATCH Superseded Marek Olšák 5 participants 31 messages Jun 29, 2017 – Jul 4, 2017 26 messages not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi,

Given how our memory manager works and the guesswork that UMDs have to do to determine whether to set the flag, I think the flag isn't useful.

I'm proposing that CPU_ACCESS_REQUIRED:
- will be deprecated.
- It will remain to be accepted by the kernel driver, but it will either not have any effect, or it will serve as a hint that might or might not be followed.
- The only flag that UMDs are expected to set with regard to CPU access is NO_CPU_ACCESS.

The main motivation is the reduction of "virtual" heaps for UMD buffer suballocators and reusable buffer pools. A higher number of heaps means that more memory can be wasted by UMDs.

Opinions?

Thanks,
Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CAAxE2A4x8tkA9DL78EouJqxZ9b2b_PyzN3hg8JJn7AHOpk5b0w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#2 lore raw

Yeah, I was thinking something similar.

See the intention behind CPU_ACCESS_REQUIRED is to always guarantee that CPU access is immediately possible.

If you ask me that is not really useful for the UMD and was never meant to be used by Mesa (only the closed source UMD and some kernel internal use cases).

I would like to keep the behavior in the kernel driver as it is, but we should really stop using this as a hint in Mesa.

Regards,
Christian.

Am 29.06.2017 um 16:41 schrieb Marek Olšák:

Quoted 18 lines

Hi,

Given how our memory manager works and the guesswork that UMDs have to do to determine whether to set the flag, I think the flag isn't useful.

I'm proposing that CPU_ACCESS_REQUIRED:
- will be deprecated.
- It will remain to be accepted by the kernel driver, but it will either not have any effect, or it will serve as a hint that might or might not be followed.
- The only flag that UMDs are expected to set with regard to CPU access is NO_CPU_ACCESS.

The main motivation is the reduction of "virtual" heaps for UMD buffer suballocators and reusable buffer pools. A higher number of heaps means that more memory can be wasted by UMDs.

Quoted 8 lines

Opinions?

Thanks,
Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 8f866ee1-78c0-6707-3f92-b71a2f661457-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#4 lore raw

Do you have any concern if we also stop using the CPU_ACCESS flag on radeon?

Thanks,
Marek

Quoted 9 lines · Christian König

Yeah, I was thinking something similar.

See the intention behind CPU_ACCESS_REQUIRED is to always guarantee that CPU access is immediately possible.

If you ask me that is not really useful for the UMD and was never meant to be used by Mesa (only the closed source UMD and some kernel internal use cases).

Quoted 38 lines

I would like to keep the behavior in the kernel driver as it is, but we should really stop using this as a hint in Mesa.

Regards,
Christian.

Am 29.06.2017 um 16:41 schrieb Marek Olšák:

Quoted 27 lines

Hi,

Given how our memory manager works and the guesswork that UMDs have to do to determine whether to set the flag, I think the flag isn't useful.

I'm proposing that CPU_ACCESS_REQUIRED:
- will be deprecated.
- It will remain to be accepted by the kernel driver, but it will either not have any effect, or it will serve as a hint that might or might not be followed.
- The only flag that UMDs are expected to set with regard to CPU access is NO_CPU_ACCESS.

The main motivation is the reduction of "virtual" heaps for UMD buffer suballocators and reusable buffer pools. A higher number of heaps means that more memory can be wasted by UMDs.

Opinions?

Thanks,
Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CAAxE2A49_j6hO_G0XoWwquFzPsoHVELNhakt5NdmVb8=F0YdSA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#6 lore raw
Quoted 1 line · Marek Olšák

Do you have any concern if we also stop using the CPU_ACCESS flag on radeon?

No concern from my side for radeon.

Quoted 7 lines
Quoted 5 lines · Christian König

Yeah, I was thinking something similar.

See the intention behind CPU_ACCESS_REQUIRED is to always guarantee that CPU access is immediately possible.

Quoted 6 lines
Quoted 6 lines

If you ask me that is not really useful for the UMD and was never meant to be used by Mesa (only the closed source UMD and some kernel internal use cases).

I would like to keep the behavior in the kernel driver as it is, but we should really stop using this as a hint in Mesa.

So we'd have a flag in the userspace ABI which is only used by closed source userspace, and which can be used to artificially create pressure on CPU visible VRAM. I know somebody who would argue vehemently against adding something like that. :)

What does the closed source UMD use the flag for?

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 50b66561-3843-8b70-913e-5692db657640-otUistvHUpPR7s880joybQ@public.gmane.org

#8 lore raw

Am 30.06.2017 um 03:36 schrieb Michel Dänzer:

Quoted 16 lines · Marek Olšák
Quoted 1 line

Do you have any concern if we also stop using the CPU_ACCESS flag on radeon?

No concern from my side for radeon.

Quoted 11 lines
Quoted 9 lines · Christian König

Yeah, I was thinking something similar.

See the intention behind CPU_ACCESS_REQUIRED is to always guarantee that CPU access is immediately possible.

If you ask me that is not really useful for the UMD and was never meant to be used by Mesa (only the closed source UMD and some kernel internal use cases).

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

I would like to keep the behavior in the kernel driver as it is, but we should really stop using this as a hint in Mesa.

So we'd have a flag in the userspace ABI which is only used by closed source userspace, and which can be used to artificially create pressure on CPU visible VRAM. I know somebody who would argue vehemently against adding something like that. :)

Yeah, and I really tried hard to prevent that :)

But unfortunately the milk is already spilled, so not much we can do about that.

Quoted 1 line

What does the closed source UMD use the flag for?

Well it doesn't use the flag, but it has the concept of separate heaps for visible and invisible VRAM and maps that to setting the flag appropriately.

But putting the closed source UMD asside, my primary concern is rather in kernel users of the flag.

Regards,
Christian.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): b7717c04-604f-24c8-2fc7-a94e520845c8-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#10 lore raw
Quoted 23 lines · Christian König

Am 30.06.2017 um 03:36 schrieb Michel Dänzer:

Quoted 15 lines · Marek Olšák
Quoted 14 lines
Quoted 12 lines · Christian König

Yeah, I was thinking something similar.

See the intention behind CPU_ACCESS_REQUIRED is to always guarantee that CPU
access is immediately possible.

If you ask me that is not really useful for the UMD and was never meant to
be used by Mesa (only the closed source UMD and some kernel internal use
cases).

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines

I would like to keep the behavior in the kernel driver as it is, but we should really stop using this as a hint in Mesa.

So we'd have a flag in the userspace ABI which is only used by closed source userspace, and which can be used to artificially create pressure on CPU visible VRAM. I know somebody who would argue vehemently against adding something like that. :)

Quoted 4 lines

Yeah, and I really tried hard to prevent that :)

But unfortunately the milk is already spilled, so not much we can do about that.

Right, sorry I didn't realize this issue when we added this flag.

Quoted 5 lines
Quoted 1 line

What does the closed source UMD use the flag for?

Well it doesn't use the flag, but it has the concept of separate heaps for visible and invisible VRAM and maps that to setting the flag appropriately.

That doesn't require the strict semantics you're defending. John has proven with a lot of hard work that the looser semantics work out better in general.

Quoted 2 lines

But putting the closed source UMD asside, my primary concern is rather in kernel users of the flag.

We can deal with that internally in the kernel, while fixing the existing flag for userspace.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): a1c1f000-16b4-220f-70c5-01b2682a632e-otUistvHUpPR7s880joybQ@public.gmane.org

#12 lore raw

Am 30.06.2017 um 08:51 schrieb Michel Dänzer:

Quoted 2 lines

We can deal with that internally in the kernel, while fixing the existing flag for userspace.

And as I said, NAK to that approach. I'm not going to add a CPU_ACCESS_REALLY_REQUIRED flag in the kernel just because mesa has messed up it's use case.

We could agree on filtering that flag from userspace when BOs are created and/or map it to a CREATE_CPU_ACCESS_HINT flag. But I would rather want to avoid that as well.

Christian.

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 8f60b400-1343-9f7f-d202-f3497fb346ae-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#14 lore raw
Quoted 10 lines · Christian König

Am 30.06.2017 um 08:51 schrieb Michel Dänzer:

Quoted 2 lines

We can deal with that internally in the kernel, while fixing the existing flag for userspace.

And as I said, NAK to that approach. I'm not going to add a CPU_ACCESS_REALLY_REQUIRED flag in the kernel just because mesa has messed up it's use case.

We could agree on filtering that flag from userspace when BOs are created and/or map it to a CREATE_CPU_ACCESS_HINT flag.

Then I propose the following:

One patch:

Convert AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED to a kernel internal flag AMDGPU_GEM_CPU_ACCESS_HINT in amdgpu_gem_create_ioctl, which is initially treated the same way as AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED.

Another patch:

Change the treatment of AMDGPU_GEM_CPU_ACCESS_HINT according to John's patch 4 in the latest series, or a variation of that as discussed on IRC.

If any regressions are reported, we will be able to differentiate whether they are due to the addition of the new flag itself or due to the change in its handling.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 160855e9-2517-ae04-fd9d-c638507109cd-otUistvHUpPR7s880joybQ@public.gmane.org

#16 lore raw

Am 30.06.2017 um 09:14 schrieb Michel Dänzer:

Quoted 20 lines · Christian König
Quoted 9 lines

Am 30.06.2017 um 08:51 schrieb Michel Dänzer:

Quoted 2 lines

We can deal with that internally in the kernel, while fixing the existing flag for userspace.

And as I said, NAK to that approach. I'm not going to add a CPU_ACCESS_REALLY_REQUIRED flag in the kernel just because mesa has messed up it's use case.

We could agree on filtering that flag from userspace when BOs are created and/or map it to a CREATE_CPU_ACCESS_HINT flag.

Then I propose the following:

One patch:

Convert AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED to a kernel internal flag AMDGPU_GEM_CPU_ACCESS_HINT in amdgpu_gem_create_ioctl, which is initially treated the same way as AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED.

Another patch:

Quoted 7 lines

Change the treatment of AMDGPU_GEM_CPU_ACCESS_HINT according to John's patch 4 in the latest series, or a variation of that as discussed on IRC.

If any regressions are reported, we will be able to differentiate whether they are due to the addition of the new flag itself or due to the change in its handling.

It just occurred to me that there is a simpler way of handling this: We just never clear the flag on kernel allocations.

See my main concern are the in kernel users of the flag which use it as guarantee that the BO is CPU accessible.

If we handle those specially there shouldn't be a problem clearing the flag for the UMD BOs.

Christian.

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): a5afda83-1c47-a8d2-20ab-a5923603e7fb-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#18 lore raw
Quoted 36 lines · Christian König

Am 30.06.2017 um 09:14 schrieb Michel Dänzer:

Quoted 25 lines · Christian König
Quoted 6 lines

Am 30.06.2017 um 08:51 schrieb Michel Dänzer:

Quoted 3 lines

We can deal with that internally in the kernel, while fixing the existing flag for userspace.

Quoted 6 lines

And as I said, NAK to that approach. I'm not going to add a CPU_ACCESS_REALLY_REQUIRED flag in the kernel just because mesa has messed up it's use case.

We could agree on filtering that flag from userspace when BOs are created and/or map it to a CREATE_CPU_ACCESS_HINT flag.

Then I propose the following:

One patch:

Convert AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED to a kernel internal flag AMDGPU_GEM_CPU_ACCESS_HINT in amdgpu_gem_create_ioctl, which is initially treated the same way as AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED.

Another patch:

Quoted 7 lines

Change the treatment of AMDGPU_GEM_CPU_ACCESS_HINT according to John's patch 4 in the latest series, or a variation of that as discussed on IRC.

If any regressions are reported, we will be able to differentiate whether they are due to the addition of the new flag itself or due to the change in its handling.

Quoted 8 lines

It just occurred to me that there is a simpler way of handling this: We just never clear the flag on kernel allocations.

See my main concern are the in kernel users of the flag which use it as guarantee that the BO is CPU accessible.

If we handle those specially there shouldn't be a problem clearing the flag for the UMD BOs.

Hi,

I don't know what is being talked about here anymore, but I wouldn't like to use CPU_ACCESS_REQUIRED or CPU_ACCESS_REALLY_REQUIRED in userspace. The reason is that userspace doesn't and can't know whether CPU access will be required, and the frequency at which it will be required. 3 heaps {no CPU access, no flag, CPU access required} are too many. Userspace mostly doesn't use the "no flag" heap for VRAM. It uses "CPU access required" for almost everything except tiled textures, which use "no CPU access".

I've been trying to trim down the number of heaps. So far, I have:
- VRAM_NO_CPU_ACCESS (implies WC)
- VRAM (implies WC)
- VRAM_GTT (combined, implies WC)
- GTT_WC
- GTT

See, you can't forbid CPU access for the combined VRAM_GTT heap. It's one of the compromises there.

The more heaps we have, the more memory can be wasted by suballocators. It's silly to have more than 3 suballocators just for VRAM.

Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CAAxE2A6h=0cn_+S9Psw=DkvAqtUdAOZE-kK39LZFpX0xud1gRQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#20 lore raw
Quoted 9 lines · Marek Olšák

I don't know what is being talked about here anymore, but I wouldn't like to use CPU_ACCESS_REQUIRED or CPU_ACCESS_REALLY_REQUIRED in userspace. The reason is that userspace doesn't and can't know whether CPU access will be required, and the frequency at which it will be required. 3 heaps {no CPU access, no flag, CPU access required} are too many. Userspace mostly doesn't use the "no flag" heap for VRAM. It uses "CPU access required" for almost everything except tiled textures, which use "no CPU access".

FWIW, the difference between setting CPU_ACCESS_REQUIRED and not setting it for a BO created in VRAM will be: If it's set, the BO is initially created in CPU visible VRAM, otherwise it's most likely created in CPU invisible VRAM.

If userspace knows that a BO will likely be accessed by the CPU first, setting the flag could save a move from CPU invisible to CPU visible VRAM when the CPU access happens. Conversely, if a BO will likely never be accessed by the CPU, not setting the flag may reduce pressure on CPU visible VRAM.

Not sure radeonsi can make this distinction though.

Quoted 4 lines

I've been trying to trim down the number of heaps. So far, I have:
- VRAM_NO_CPU_ACCESS (implies WC)
- VRAM (implies WC)
- VRAM_GTT (combined, implies WC)

Is this useful? It means:

* The BO may be created in VRAM, or if there's no space, in GTT.
* Once the BO is in GTT for any reason, it will never go back to VRAM.

Such BOs will tend to end up in GTT after some time, at the latest after suspend/resume.

I think it would be better for radeonsi to choose either VRAM or GTT as the preferred domain, and let the kernel handle it.

Quoted 2 lines

- GTT_WC
- GTT

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1bb94040-5d80-d1e7-33c9-b09e5282b91c-otUistvHUpPR7s880joybQ@public.gmane.org

#22 lore raw
Quoted 16 lines · Michel Dänzer
Quoted 9 lines · Marek Olšák

I don't know what is being talked about here anymore, but I wouldn't like to use CPU_ACCESS_REQUIRED or CPU_ACCESS_REALLY_REQUIRED in userspace. The reason is that userspace doesn't and can't know whether CPU access will be required, and the frequency at which it will be required. 3 heaps {no CPU access, no flag, CPU access required} are too many. Userspace mostly doesn't use the "no flag" heap for VRAM. It uses "CPU access required" for almost everything except tiled textures, which use "no CPU access".

FWIW, the difference between setting CPU_ACCESS_REQUIRED and not setting it for a BO created in VRAM will be: If it's set, the BO is initially created in CPU visible VRAM, otherwise it's most likely created in CPU invisible VRAM.

Quoted 7 lines

If userspace knows that a BO will likely be accessed by the CPU first, setting the flag could save a move from CPU invisible to CPU visible VRAM when the CPU access happens. Conversely, if a BO will likely never be accessed by the CPU, not setting the flag may reduce pressure on CPU visible VRAM.

Not sure radeonsi can make this distinction though.

It can't.

Either all mappable BOs set CPU_ACCESS_REQUIRED, or all mappable BOs don't set it. Either way, there is only one combination of flags for mappable BOs in VRAM, and therefore only one kind of behavior the kernel can follow.

Quoted 9 lines
Quoted 6 lines

I've been trying to trim down the number of heaps. So far, I have:
- VRAM_NO_CPU_ACCESS (implies WC)
- VRAM (implies WC)
- VRAM_GTT (combined, implies WC)

Is this useful? It means:

Quoted 8 lines

* The BO may be created in VRAM, or if there's no space, in GTT.
* Once the BO is in GTT for any reason, it will never go back to VRAM.

Such BOs will tend to end up in GTT after some time, at the latest after suspend/resume.

I think it would be better for radeonsi to choose either VRAM or GTT as the preferred domain, and let the kernel handle it.

Currently, radeonsi on amdgpu doesn't use VRAM_GTT with the current kernel.

I'm aware of the limited usefulness.

Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CAAxE2A4dNoEi=D8FM=+5kEZmq_V7DdLrwFPYxSFx4uFjUSeTvg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#24 lore raw
Quoted 23 lines · Marek Olšák
Quoted 22 lines · Michel Dänzer
Quoted 9 lines · Marek Olšák

I don't know what is being talked about here anymore, but I wouldn't like to use CPU_ACCESS_REQUIRED or CPU_ACCESS_REALLY_REQUIRED in userspace. The reason is that userspace doesn't and can't know whether CPU access will be required, and the frequency at which it will be required. 3 heaps {no CPU access, no flag, CPU access required} are too many. Userspace mostly doesn't use the "no flag" heap for VRAM. It uses "CPU access required" for almost everything except tiled textures, which use "no CPU access".

FWIW, the difference between setting CPU_ACCESS_REQUIRED and not setting it for a BO created in VRAM will be: If it's set, the BO is initially created in CPU visible VRAM, otherwise it's most likely created in CPU invisible VRAM.

If userspace knows that a BO will likely be accessed by the CPU first, setting the flag could save a move from CPU invisible to CPU visible VRAM when the CPU access happens. Conversely, if a BO will likely never be accessed by the CPU, not setting the flag may reduce pressure on CPU visible VRAM.

Quoted 3 lines
Quoted 1 line

Not sure radeonsi can make this distinction though.

It can't.

Not sure why, but anyway.

Quoted 2 lines

Either all mappable BOs set CPU_ACCESS_REQUIRED, or all mappable BOs don't set it.

FWIW, with kernels without John's fixes, the flag shouldn't be set for all such BOs, because it would prevent them from ever going to CPU invisible VRAM.

With John's fixes, one possibility would be to set the flag based on the existing heuristics or some variant, and use it when a BO is newly created from the kernel, but to ignore the flag when reusing a BO from the cache (with John's fixes, whether or not the flag was set when a BO was created won't directly affect its state WRT the flag when it's reused from the cache).

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): cf4352ec-6838-f599-cf5c-b6a123301461-otUistvHUpPR7s880joybQ@public.gmane.org

#26 lore raw
Quoted 38 lines · Michel Dänzer
Quoted 23 lines · Marek Olšák
Quoted 22 lines · Michel Dänzer
Quoted 9 lines · Marek Olšák

I don't know what is being talked about here anymore, but I wouldn't like to use CPU_ACCESS_REQUIRED or CPU_ACCESS_REALLY_REQUIRED in userspace. The reason is that userspace doesn't and can't know whether CPU access will be required, and the frequency at which it will be required. 3 heaps {no CPU access, no flag, CPU access required} are too many. Userspace mostly doesn't use the "no flag" heap for VRAM. It uses "CPU access required" for almost everything except tiled textures, which use "no CPU access".

FWIW, the difference between setting CPU_ACCESS_REQUIRED and not setting it for a BO created in VRAM will be: If it's set, the BO is initially created in CPU visible VRAM, otherwise it's most likely created in CPU invisible VRAM.

If userspace knows that a BO will likely be accessed by the CPU first, setting the flag could save a move from CPU invisible to CPU visible VRAM when the CPU access happens. Conversely, if a BO will likely never be accessed by the CPU, not setting the flag may reduce pressure on CPU visible VRAM.

Quoted 3 lines
Quoted 1 line

Not sure radeonsi can make this distinction though.

It can't.

Not sure why, but anyway.

Quoted 2 lines

Either all mappable BOs set CPU_ACCESS_REQUIRED, or all mappable BOs don't set it.

FWIW, with kernels without John's fixes, the flag shouldn't be set for all such BOs, because it would prevent them from ever going to CPU invisible VRAM.

Quoted 6 lines

With John's fixes, one possibility would be to set the flag based on the existing heuristics or some variant, and use it when a BO is newly created from the kernel, but to ignore the flag when reusing a BO from the cache (with John's fixes, whether or not the flag was set when a BO was created won't directly affect its state WRT the flag when it's reused from the cache).

Thanks. Based on your comments, I've come to the conclusion that the userspace shouldn't set CPU_ACCESS_REQUIRED, because the only other alternative (always setting the flag) is worse.

Marek
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#27 lore raw
In reply to a message not in the archive
Quoted 20 lines · Christian König
Quoted 9 lines

Am 30.06.2017 um 08:51 schrieb Michel Dänzer:

Quoted 2 lines

We can deal with that internally in the kernel, while fixing the existing flag for userspace.

And as I said, NAK to that approach. I'm not going to add a CPU_ACCESS_REALLY_REQUIRED flag in the kernel just because mesa has messed up it's use case.

We could agree on filtering that flag from userspace when BOs are created and/or map it to a CREATE_CPU_ACCESS_HINT flag.

Then I propose the following:

One patch:

Convert AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED to a kernel internal flag AMDGPU_GEM_CPU_ACCESS_HINT in amdgpu_gem_create_ioctl, which is initially treated the same way as AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED.

Another patch:

Quoted 8 lines

Change the treatment of AMDGPU_GEM_CPU_ACCESS_HINT according to John's patch 4 in the latest series, or a variation of that as discussed on IRC.

If any regressions are reported, we will be able to differentiate whether they are due to the addition of the new flag itself or due to the change in its handling.

How about this?
Note: I haven't tested this beyond compiling.

See replies for:
[PATCH RFC 1/2] drm/amdgpu: Add AMDGPU_BO_FLAG_CPU_ACCESS [PATCH RFC 2/2] drm/amdgpu: Set/clear CPU_ACCESS flag on page fault

John

Quoted 4 lines
Signature · 3 lines
-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1498835932-5053-1-git-send-email-john-xq/[email protected]

#29 lore raw

RFC PATCH 1/2 drm/amdgpu: Add AMDGPU_BO_FLAG_CPU_ACCESS

For userspace BO allocations, replace AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED with a new AMDGPU_BO_FLAG_CPU_ACCESS flag. This flag will be used to indicate that a BO should currently be CPU accessible. Unlike the CPU_ACCESS_REQUIRED flag, it is meant to be an ephemeral rather than a permanent constraint. Currently, however, it is treated no differently.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h        | 3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 9 ++++++++-
 include/uapi/drm/amdgpu_drm.h              | 1 +
 3 files changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3 -0
index 12d61ed..a724e4f 100644
@@ -411,6 +411,9 @@ struct amdgpu_bo_va {
 
 #define AMDGPU_GEM_DOMAIN_MAX		0x3
 
+/* BO internal flags */
+#define AMDGPU_BO_FLAG_CPU_ACCESS	(AMDGPU_GEM_CREATE_MAX << 1)
+
 struct amdgpu_bo {
 	/* Protected by tbo.reserved */
 	u32				prefered_domains;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +8 -1
index 8ee6965..fa8aeca 100644
@@ -128,7 +128,8 @@ static void amdgpu_ttm_placement_init(struct amdgpu_device *adev,
 		places[c].flags = TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED |
 			TTM_PL_FLAG_VRAM;
 
-		if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED)
+		if (flags & (AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
+			     AMDGPU_BO_FLAG_CPU_ACCESS))
 			places[c].lpfn = visible_pfn;
 		else
 			places[c].flags |= TTM_PL_FLAG_TOPDOWN;
@@ -361,6 +362,12 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
 	if (!kernel && bo->allowed_domains == AMDGPU_GEM_DOMAIN_VRAM)
 		bo->allowed_domains |= AMDGPU_GEM_DOMAIN_GTT;
 
+	if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
+		flags |= AMDGPU_BO_FLAG_CPU_ACCESS;
+		/* Treat CPU_ACCESS_REQUIRED only as a hint if given by UMD */
+		if (!kernel)
+			flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
+	}
 	bo->flags = flags;
 
 #ifdef CONFIG_X86_32
include/uapi/drm/amdgpu_drm.h +1 -0
index d9aa4a3..473076f 100644
@@ -87,6 +87,7 @@ extern "C" {
 #define AMDGPU_GEM_CREATE_SHADOW		(1 << 4)
 /* Flag that allocating the BO should use linear VRAM */
 #define AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS	(1 << 5)
+#define AMDGPU_GEM_CREATE_MAX			(1 << 5)
 
 struct drm_amdgpu_gem_create_in  {
 	/** the requested memory size */
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1498835932-5053-2-git-send-email-john-xq/[email protected]

#31 lore raw

Re: [PATCH RFC 1/2] drm/amdgpu: Add AMDGPU_BO_FLAG_CPU_ACCESS

Am 30.06.2017 um 17:18 schrieb John Brooks:

Quoted 18 lines

For userspace BO allocations, replace AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED with a new AMDGPU_BO_FLAG_CPU_ACCESS flag. This flag will be used to indicate that a BO should currently be CPU accessible. Unlike the CPU_ACCESS_REQUIRED flag, it is meant to be an ephemeral rather than a permanent constraint. Currently, however, it is treated no differently.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu.h        | 3 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 9 ++++++++-
  include/uapi/drm/amdgpu_drm.h              | 1 +
  3 files changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0 -0
index 12d61ed..a724e4f 100644

drivers/gpu/drm/amd/amdgpu/amdgpu.h struct amdgpu_bo_va { · line 415

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2 -0
@@ -411,6 +411,9 @@ struct amdgpu_bo_va {
 
  #define AMDGPU_GEM_DOMAIN_MAX		0x3
 
+/* BO internal flags */
+#define AMDGPU_BO_FLAG_CPU_ACCESS	(AMDGPU_GEM_CREATE_MAX << 1)

Better put this into amdgpu_drm.h to keep all the flags together. We can reject kernel internal flags when we create the BO.

But in general I would still say we should stop clearing the flag when "bo->tbo.type != ttm_bo_type_device".

This way we are always on the save side and don't modify flags for kernel BOs.

Regards,
Christian.

Quoted 36 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
+
  struct amdgpu_bo {
  	/* Protected by tbo.reserved */
  	u32				prefered_domains;
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +8 -1
index 8ee6965..fa8aeca 100644
@@ -128,7 +128,8 @@ static void amdgpu_ttm_placement_init(struct amdgpu_device *adev,
  		places[c].flags = TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED |
  			TTM_PL_FLAG_VRAM;
 
-		if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED)
+		if (flags & (AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
+			     AMDGPU_BO_FLAG_CPU_ACCESS))
  			places[c].lpfn = visible_pfn;
  		else
  			places[c].flags |= TTM_PL_FLAG_TOPDOWN;
@@ -361,6 +362,12 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
  	if (!kernel && bo->allowed_domains == AMDGPU_GEM_DOMAIN_VRAM)
  		bo->allowed_domains |= AMDGPU_GEM_DOMAIN_GTT;
 
+	if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
+		flags |= AMDGPU_BO_FLAG_CPU_ACCESS;
+		/* Treat CPU_ACCESS_REQUIRED only as a hint if given by UMD */
+		if (!kernel)
+			flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
+	}
  	bo->flags = flags;
 
  #ifdef CONFIG_X86_32
include/uapi/drm/amdgpu_drm.h +0 -0
index d9aa4a3..473076f 100644

include/uapi/drm/amdgpu_drm.h extern "C" { · line 93

Quoted 7 lines
include/uapi/drm/amdgpu_drm.h +1 -0
@@ -87,6 +87,7 @@ extern "C" {
  #define AMDGPU_GEM_CREATE_SHADOW		(1 << 4)
  /* Flag that allocating the BO should use linear VRAM */
  #define AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS	(1 << 5)
+#define AMDGPU_GEM_CREATE_MAX			(1 << 5)
 
  struct drm_amdgpu_gem_create_in  {
  	/** the requested memory size */

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 33d2358f-b1c8-d774-fe43-19a024c79d24-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#33 lore raw

RFC PATCH v2 1/2 drm/amdgpu: Add AMDGPU_BO_FLAG_CPU_ACCESS

For userspace BO allocations, replace AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED with a new AMDGPU_BO_FLAG_CPU_ACCESS flag. This flag will be used to indicate that a BO should currently be CPU accessible. Unlike the CPU_ACCESS_REQUIRED flag, it is meant to be an ephemeral rather than a permanent constraint. Currently, however, it is treated no differently.

v2: Put the new flag in amdgpu_drm.h, only clear CPU_ACCESS_REQUIRED if

    bo->tbo.type == ttm_bo_type_device (Christian König)
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 9 ++++++++-
 include/uapi/drm/amdgpu_drm.h              | 2 ++
 2 files changed, 10 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +8 -1
index 8ee6965..a5e73f8 100644
@@ -128,7 +128,8 @@ static void amdgpu_ttm_placement_init(struct amdgpu_device *adev,
 		places[c].flags = TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED |
 			TTM_PL_FLAG_VRAM;
 
-		if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED)
+		if (flags & (AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
+			     AMDGPU_BO_FLAG_CPU_ACCESS))
 			places[c].lpfn = visible_pfn;
 		else
 			places[c].flags |= TTM_PL_FLAG_TOPDOWN;
@@ -361,6 +362,12 @@ int amdgpu_bo_create_restricted(struct amdgpu_device *adev,
 	if (!kernel && bo->allowed_domains == AMDGPU_GEM_DOMAIN_VRAM)
 		bo->allowed_domains |= AMDGPU_GEM_DOMAIN_GTT;
 
+	if (flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED) {
+		flags |= AMDGPU_BO_FLAG_CPU_ACCESS;
+		/* Treat CPU_ACCESS_REQUIRED only as a hint if given by UMD */
+		if (type == ttm_bo_type_device)
+			flags &= ~AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
+	}
 	bo->flags = flags;
 
 #ifdef CONFIG_X86_32
include/uapi/drm/amdgpu_drm.h +2 -0
index d9aa4a3..aeff910 100644
@@ -87,6 +87,8 @@ extern "C" {
 #define AMDGPU_GEM_CREATE_SHADOW		(1 << 4)
 /* Flag that allocating the BO should use linear VRAM */
 #define AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS	(1 << 5)
+/* Flag that the BO is actively being used by the CPU. Internal use only */
+#define AMDGPU_BO_FLAG_CPU_ACCESS		(1 << 6)
 
 struct drm_amdgpu_gem_create_in  {
 	/** the requested memory size */
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#34 lore raw

RFC PATCH 2/2 drm/amdgpu: Set/clear CPU_ACCESS flag on page fault and move to VRAM

In reply to a message not in the archive

When a BO is moved to VRAM, clear AMDGPU_BO_FLAG_CPU_ACCESS. This allows it to potentially later move to invisible VRAM if the CPU does not access it again.

Setting the CPU_ACCESS flag in amdgpu_fault_reserve_notify() also means that we can remove the loop to restrict lpfn to the end of visible VRAM, because amdgpu_ttm_placement_init() will do it for us.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    | 8 ++++++++
 2 files changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3 -0
index fa8aeca..19bd2fd 100644
@@ -953,6 +953,9 @@ int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
 		return 0;
 
 	abo = container_of(bo, struct amdgpu_bo, tbo);
+
+	abo->flags |= AMDGPU_BO_FLAG_CPU_ACCESS;
+
 	if (bo->mem.mem_type != TTM_PL_VRAM)
 		return 0;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +8 -0
index c9b131b..cc65cdd 100644
@@ -417,6 +417,7 @@ static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo,
 				struct ttm_mem_reg *new_mem)
 {
 	struct amdgpu_device *adev;
+	struct amdgpu_bo *abo;
 	struct ttm_mem_reg *old_mem = &bo->mem;
 	struct ttm_mem_reg tmp_mem;
 	struct ttm_placement placement;
@@ -424,6 +425,7 @@ static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo,
 	int r;
 
 	adev = amdgpu_ttm_adev(bo->bdev);
+	abo = container_of(bo, struct amdgpu_bo, tbo);
 	tmp_mem = *new_mem;
 	tmp_mem.mm_node = NULL;
 	placement.num_placement = 1;
@@ -446,6 +448,12 @@ static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo,
 	if (unlikely(r)) {
 		goto out_cleanup;
 	}
+
+	/* The page fault handler will re-set this if the CPU accesses the BO
+	 * after it's moved.
+	 */
+	abo->flags &= ~AMDGPU_BO_FLAG_CPU_ACCESS;
+
 out_cleanup:
 	ttm_bo_mem_put(bo, &tmp_mem);
 	return r;
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1498835932-5053-3-git-send-email-john-xq/[email protected]

#36 lore raw

RFC PATCH v2 1/1 drm/amdgpu: Set/clear CPU_ACCESS flag on page fault and move to VRAM

When a BO is moved to VRAM, clear AMDGPU_BO_FLAG_CPU_ACCESS. This allows it to potentially later move to invisible VRAM if the CPU does not access it again.

Setting the CPU_ACCESS flag in amdgpu_bo_fault_reserve_notify() also means that we can remove the loop to restrict lpfn to the end of visible VRAM, because amdgpu_ttm_placement_init() will do it for us.

---

Whoops, I forgot to actually remove that loop.
Also, in the changelog: amdgpu_fault_reserve_notify -> amdgpu_bo_fault_reserve_notify

 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 15 +++++----------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  8 ++++++++
 2 files changed, 13 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +5 -10
index fa8aeca..7164f8c 100644
@@ -946,13 +946,16 @@ int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
 {
 	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->bdev);
 	struct amdgpu_bo *abo;
-	unsigned long offset, size, lpfn;
-	int i, r;
+	unsigned long offset, size;
+	int r;
 
 	if (!amdgpu_ttm_bo_is_amdgpu_bo(bo))
 		return 0;
 
 	abo = container_of(bo, struct amdgpu_bo, tbo);
+
+	abo->flags |= AMDGPU_BO_FLAG_CPU_ACCESS;
+
 	if (bo->mem.mem_type != TTM_PL_VRAM)
 		return 0;
 
@@ -969,14 +972,6 @@ int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
 	/* hurrah the memory is not visible ! */
 	atomic64_inc(&adev->num_vram_cpu_page_faults);
 	amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_VRAM);
-	lpfn =	adev->mc.visible_vram_size >> PAGE_SHIFT;
-	for (i = 0; i < abo->placement.num_placement; i++) {
-		/* Force into visible VRAM */
-		if ((abo->placements[i].flags & TTM_PL_FLAG_VRAM) &&
-		    (!abo->placements[i].lpfn ||
-		     abo->placements[i].lpfn > lpfn))
-			abo->placements[i].lpfn = lpfn;
-	}
 	r = ttm_bo_validate(bo, &abo->placement, false, false);
 	if (unlikely(r == -ENOMEM)) {
 		amdgpu_ttm_placement_from_domain(abo, AMDGPU_GEM_DOMAIN_GTT);
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +8 -0
index c9b131b..cc65cdd 100644
@@ -417,6 +417,7 @@ static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo,
 				struct ttm_mem_reg *new_mem)
 {
 	struct amdgpu_device *adev;
+	struct amdgpu_bo *abo;
 	struct ttm_mem_reg *old_mem = &bo->mem;
 	struct ttm_mem_reg tmp_mem;
 	struct ttm_placement placement;
@@ -424,6 +425,7 @@ static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo,
 	int r;
 
 	adev = amdgpu_ttm_adev(bo->bdev);
+	abo = container_of(bo, struct amdgpu_bo, tbo);
 	tmp_mem = *new_mem;
 	tmp_mem.mm_node = NULL;
 	placement.num_placement = 1;
@@ -446,6 +448,12 @@ static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo,
 	if (unlikely(r)) {
 		goto out_cleanup;
 	}
+
+	/* The page fault handler will re-set this if the CPU accesses the BO
+	 * after it's moved.
+	 */
+	abo->flags &= ~AMDGPU_BO_FLAG_CPU_ACCESS;
+
 out_cleanup:
 	ttm_bo_mem_put(bo, &tmp_mem);
 	return r;
Signature · 6 lines
2.7.4

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 1498836668-5872-1-git-send-email-john-xq/[email protected]

#38 lore raw

Re: [PATCH RFC v2] drm/amdgpu: Set/clear CPU_ACCESS flag on page fault and move to VRAM

Quoted 9 lines · John Brooks

When a BO is moved to VRAM, clear AMDGPU_BO_FLAG_CPU_ACCESS. This allows it to potentially later move to invisible VRAM if the CPU does not access it again.

Setting the CPU_ACCESS flag in amdgpu_bo_fault_reserve_notify() also means that we can remove the loop to restrict lpfn to the end of visible VRAM, because amdgpu_ttm_placement_init() will do it for us.

[...]

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo, · line 455

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +5 -0
@@ -446,6 +448,12 @@ static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo,
 	if (unlikely(r)) {
 		goto out_cleanup;
 	}
+
+	/* The page fault handler will re-set this if the CPU accesses the BO
+	 * after it's moved.
+	 */
+	abo->flags &= ~AMDGPU_BO_FLAG_CPU_ACCESS;

I've come to realize that the flag also needs to be cleared at the end of amdgpu_bo_create_restricted, otherwise we will incorrectly assume that every BO created with this flag has been accessed by the CPU.

BTW, there's also a minor issue here in that the flags member is u64, but the flags are defined as ints. Probably doesn't matter so far, but it would as soon as any flag's value is >= (1 << 32).

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#39 lore raw

Re: [PATCH RFC 2/2] drm/amdgpu: Set/clear CPU_ACCESS flag on page fault and move to VRAM

In reply to a message not in the archive

Am 30.06.2017 um 17:18 schrieb John Brooks:

Quoted 49 lines

When a BO is moved to VRAM, clear AMDGPU_BO_FLAG_CPU_ACCESS. This allows it to potentially later move to invisible VRAM if the CPU does not access it again.

Setting the CPU_ACCESS flag in amdgpu_fault_reserve_notify() also means that we can remove the loop to restrict lpfn to the end of visible VRAM, because amdgpu_ttm_placement_init() will do it for us.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 3 +++
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    | 8 ++++++++
  2 files changed, 11 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +3 -0
index fa8aeca..19bd2fd 100644
@@ -953,6 +953,9 @@ int amdgpu_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
  		return 0;
 
  	abo = container_of(bo, struct amdgpu_bo, tbo);
+
+	abo->flags |= AMDGPU_BO_FLAG_CPU_ACCESS;
+
  	if (bo->mem.mem_type != TTM_PL_VRAM)
  		return 0;
 
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -0
index c9b131b..cc65cdd 100644
@@ -417,6 +417,7 @@ static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo,
  				struct ttm_mem_reg *new_mem)
  {
  	struct amdgpu_device *adev;
+	struct amdgpu_bo *abo;
  	struct ttm_mem_reg *old_mem = &bo->mem;
  	struct ttm_mem_reg tmp_mem;
  	struct ttm_placement placement;
@@ -424,6 +425,7 @@ static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo,
  	int r;
 
  	adev = amdgpu_ttm_adev(bo->bdev);
+	abo = container_of(bo, struct amdgpu_bo, tbo);
  	tmp_mem = *new_mem;
  	tmp_mem.mm_node = NULL;
  	placement.num_placement = 1;

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo, · line 456

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +6 -0
@@ -446,6 +448,12 @@ static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo,
  	if (unlikely(r)) {
  		goto out_cleanup;
  	}
+
+	/* The page fault handler will re-set this if the CPU accesses the BO
+	 * after it's moved.
+	 */
+	abo->flags &= ~AMDGPU_BO_FLAG_CPU_ACCESS;
+

This is the wrong place for clearing the flag. This code path is only called when we move things back in after suspend/resume (or run out of GTT space).

Regards,
Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo, · line 459

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +0 -0
  out_cleanup:
  	ttm_bo_mem_put(bo, &tmp_mem);
  	return r;

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 4236c636-8b80-7088-6b55-8b9dee1c2b3f-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#41 lore raw

Re: [PATCH RFC 2/2] drm/amdgpu: Set/clear CPU_ACCESS flag on page fault and move to VRAM

Quoted 11 lines · Christian König

Am 30.06.2017 um 17:18 schrieb John Brooks:

Quoted 10 lines

When a BO is moved to VRAM, clear AMDGPU_BO_FLAG_CPU_ACCESS. This allows it
to potentially later move to invisible VRAM if the CPU does not access it again.

Setting the CPU_ACCESS flag in amdgpu_fault_reserve_notify() also means that we can remove the loop to restrict lpfn to the end of visible VRAM, because amdgpu_ttm_placement_init() will do it for us.

[...]

Quoted 10 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo, · line 454

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -0
@@ -446,6 +448,12 @@ static int amdgpu_move_ram_vram(struct
 ttm_buffer_object *bo,
      if (unlikely(r)) {
          goto out_cleanup;
      }
+
+    /* The page fault handler will re-set this if the CPU accesses

the BO

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -0
+     * after it's moved.
+     */

Maybe say "amdgpu_bo_fault_reserve_notify" explicitly here instead of "The page fault handler".

Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo, · line 456

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -0
+    abo->flags &= ~AMDGPU_BO_FLAG_CPU_ACCESS;
+

This is the wrong place for clearing the flag. This code path is only called when we move things back in after suspend/resume (or run out of GTT space).

Surely amdgpu_move_ram_vram is called whenever a BO is moved to VRAM, for any reason. I suggested clearing the flag here to John on IRC. The idea is briefly described in the commit log, let me elaborate a bit on that:

When a BO is moved to VRAM which has the AMDGPU_BO_FLAG_CPU_ACCESS flag set, it is put in CPU visible VRAM, and the flag is cleared. If the CPU doesn't access the BO, the next time it will be moved to VRAM (after it was evicted from there, for any reason), the flag will no longer be set, and the BO will likely be moved to CPU invisible VRAM.

If the BO is accessed by the CPU again though (no matter where the BO is currently located at that time), the flag is set again, and the cycle from the previous paragraph starts over.

The end result should be similar as with the timestamp based solution in John's earlier series: BOs which are at least occasionally accessed by the CPU will tend to be in CPU visible VRAM, those which are never accessed by the CPU can be in CPU invisible VRAM.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 3a28996f-2a7c-918c-6c39-65a25d4ea976-otUistvHUpPR7s880joybQ@public.gmane.org

#43 lore raw

Re: [PATCH RFC 2/2] drm/amdgpu: Set/clear CPU_ACCESS flag on page fault and move to VRAM

Am 03.07.2017 um 03:34 schrieb Michel Dänzer:

Quoted 28 lines · Christian König
Quoted 11 lines

Am 30.06.2017 um 17:18 schrieb John Brooks:

Quoted 10 lines

When a BO is moved to VRAM, clear AMDGPU_BO_FLAG_CPU_ACCESS. This allows it
to potentially later move to invisible VRAM if the CPU does not access it again.

Setting the CPU_ACCESS flag in amdgpu_fault_reserve_notify() also means that we can remove the loop to restrict lpfn to the end of visible VRAM, because amdgpu_ttm_placement_init() will do it for us.

[...]

Quoted 10 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo, · line 454

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -0
@@ -446,6 +448,12 @@ static int amdgpu_move_ram_vram(struct
 ttm_buffer_object *bo,
       if (unlikely(r)) {
           goto out_cleanup;
       }
+
+    /* The page fault handler will re-set this if the CPU accesses

the BO

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -0
+     * after it's moved.
+     */

Maybe say "amdgpu_bo_fault_reserve_notify" explicitly here instead of "The page fault handler".

Quoted 6 lines
Quoted 5 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo, · line 456

Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -0
+    abo->flags &= ~AMDGPU_BO_FLAG_CPU_ACCESS;
+

This is the wrong place for clearing the flag. This code path is only called when we move things back in after suspend/resume (or run out of GTT space).

Surely amdgpu_move_ram_vram is called whenever a BO is moved to VRAM,

No, that isn't even remotely correct. amdgpu_move_ram_vram() is only called when the BO is moved directly from the system domain to the VRAM domain.

Normally BOs are only moved from the GTT domain to the VRAM domain, except after resume and when we ran out of GTT space.

Quoted 9 lines

for any reason. I suggested clearing the flag here to John on IRC. The idea is briefly described in the commit log, let me elaborate a bit on that:

When a BO is moved to VRAM which has the AMDGPU_BO_FLAG_CPU_ACCESS flag set, it is put in CPU visible VRAM, and the flag is cleared. If the CPU doesn't access the BO, the next time it will be moved to VRAM (after it was evicted from there, for any reason), the flag will no longer be set, and the BO will likely be moved to CPU invisible VRAM.

Quoted 8 lines

If the BO is accessed by the CPU again though (no matter where the BO is currently located at that time), the flag is set again, and the cycle from the previous paragraph starts over.

The end result should be similar as with the timestamp based solution in John's earlier series: BOs which are at least occasionally accessed by the CPU will tend to be in CPU visible VRAM, those which are never accessed by the CPU can be in CPU invisible VRAM.

Yeah, I understand the intention. But the implementation isn't even remotely correct.

First of all the flag must be cleared in the CS which wants to move the BO, not in the move functions when the decision where to put it is already made.

Second currently the flag is set on page fault, but never cleared because the place where the code to clear it was added is just completely incorrect (see above).

Instead of messing with all this I suggest that we just add a jiffies based timeout to the BO when we can clear the flag. For kernel BOs this timeout is just infinity.

Then we check in amdgpu_cs_bo_validate() before generating the placements if we could clear the flag and do so based on the timeout.

I can help implementing this when I'm done getting ride of the BO move size limitation (swapped all of this stuff for that task back into my brain anyway).

Regards,
Christian.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 894e892e-3076-9f52-5dba-71ac135b7d61-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#45 lore raw

Re: [PATCH RFC 2/2] drm/amdgpu: Set/clear CPU_ACCESS flag on page fault and move to VRAM

Quoted 20 lines · Christian König

Am 03.07.2017 um 03:34 schrieb Michel Dänzer:

Quoted 10 lines

[...] I suggested clearing the flag here to John on IRC. The idea is briefly described in the commit log, let me elaborate a bit on that:

When a BO is moved to VRAM which has the AMDGPU_BO_FLAG_CPU_ACCESS flag set, it is put in CPU visible VRAM, and the flag is cleared. If the CPU doesn't access the BO, the next time it will be moved to VRAM (after it was evicted from there, for any reason), the flag will no longer be set, and the BO will likely be moved to CPU invisible VRAM.

Quoted 8 lines

If the BO is accessed by the CPU again though (no matter where the BO is currently located at that time), the flag is set again, and the cycle from the previous paragraph starts over.

The end result should be similar as with the timestamp based solution in John's earlier series: BOs which are at least occasionally accessed by the CPU will tend to be in CPU visible VRAM, those which are never accessed by the CPU can be in CPU invisible VRAM.

Quoted 6 lines

Yeah, I understand the intention. But the implementation isn't even remotely correct.

First of all the flag must be cleared in the CS which wants to move the BO, not in the move functions when the decision where to put it is already made.

For the purpose of this patch, we should clear the flag when the BO is actually moved to VRAM, regardless of how or why.

Quoted 3 lines

Second currently the flag is set on page fault, but never cleared because the place where the code to clear it was added is just completely incorrect (see above).

My bad, thanks for pointing this out. The following at the end of amdgpu_bo_move should do the trick:

	if (new_mem->mem_type == TTM_PL_VRAM &&
	    old_mem->mem_type != TTM_PL_VRAM) {
		/* amdgpu_bo_fault_reserve_notify will re-set this if
		 * the CPU accesses the BO after it's moved.
		 */
		abo->flags &= ~AMDGPU_BO_FLAG_CPU_ACCESS;
	}
Quoted 6 lines

Instead of messing with all this I suggest that we just add a jiffies based timeout to the BO when we can clear the flag. For kernel BOs this timeout is just infinity.

Then we check in amdgpu_cs_bo_validate() before generating the placements if we could clear the flag and do so based on the timeout.

The idea for this patch was to save the memory and CPU cycles needed for that approach.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 45ae166f-70f5-d05e-a5bb-99429b3de063-otUistvHUpPR7s880joybQ@public.gmane.org

#47 lore raw

Re: [PATCH RFC 2/2] drm/amdgpu: Set/clear CPU_ACCESS flag on page fault and move to VRAM

Am 03.07.2017 um 11:49 schrieb Michel Dänzer:

Quoted 8 lines
Quoted 6 lines

Instead of messing with all this I suggest that we just add a jiffies based timeout to the BO when we can clear the flag. For kernel BOs this timeout is just infinity.

Then we check in amdgpu_cs_bo_validate() before generating the placements if we could clear the flag and do so based on the timeout.

The idea for this patch was to save the memory and CPU cycles needed for that approach.

But when we clear the flag on the end of the move we already moved the BO to visible VRAM again.

Only on after the next swapout/swapin cycle we see an effect of that change.

Is that the intended approach?

Regards,
Christian.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): bf62998e-0174-f714-9503-d99295213d8f-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org

#49 lore raw

Re: [PATCH RFC 2/2] drm/amdgpu: Set/clear CPU_ACCESS flag on page fault and move to VRAM

Quoted 11 lines · Christian König

Am 03.07.2017 um 11:49 schrieb Michel Dänzer:

Quoted 8 lines
Quoted 6 lines

Instead of messing with all this I suggest that we just add a jiffies based timeout to the BO when we can clear the flag. For kernel BOs this timeout is just infinity.

Then we check in amdgpu_cs_bo_validate() before generating the placements if we could clear the flag and do so based on the timeout.

The idea for this patch was to save the memory and CPU cycles needed for that approach.

But when we clear the flag on the end of the move we already moved the BO to visible VRAM again.

Right. Clearing the flag before the move would make the flag ineffective. We want to put the BO in CPU visible VRAM when the flag is set, because it means the BO has been accessed by the CPU since it was created or since it was last moved to VRAM.

Quoted 2 lines

Only on after the next swapout/swapin cycle we see an effect of that change.

Right, clearing the flag cannot have any effect before the next time the BO is moved to VRAM anyway.

Quoted 1 line

Is that the intended approach?

So yes, it is.

The only significant difference to the timestamp based approach (for which John already posted patches before) is that this patch will remember any CPU access until the next time the BO is moved to VRAM, no matter how much time passes in between.

BTW, one issue with the timestamp based approach is that we only get a page fault on the first CPU access after the BO was moved. So the timestamp only says how much time has passed since the first CPU access, not since the last CPU access.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#50 lore raw
In reply to a message not in the archive

Vulkan allows the application to decide whether it wants the allocation to be host visible and device local. If we drop the flag, what will happen if we did not set the NO_CPU_ACCESS flag?
Will it fail the map in case the allocation could be placed in invisible heap then?

Thanks.
Best Regards,
David
On 29 Jun 2017, at 11:03 PM, Marek Olšák <[email protected]<mailto:[email protected]>> wrote:

Do you have any concern if we also stop using the CPU_ACCESS flag on radeon?

Thanks,
Marek

On Thu, Jun 29, 2017 at 4:51 PM, Christian König <[email protected]<mailto:[email protected]>> wrote:
Yeah, I was thinking something similar.

See the intention behind CPU_ACCESS_REQUIRED is to always guarantee that CPU access is immediately possible.

If you ask me that is not really useful for the UMD and was never meant to be used by Mesa (only the closed source UMD and some kernel internal use cases).

I would like to keep the behavior in the kernel driver as it is, but we should really stop using this as a hint in Mesa.

Regards,
Christian.

Am 29.06.2017 um 16:41 schrieb Marek Olšák:

Hi,

Given how our memory manager works and the guesswork that UMDs have to do to determine whether to set the flag, I think the flag isn't useful.

I'm proposing that CPU_ACCESS_REQUIRED:
- will be deprecated.
- It will remain to be accepted by the kernel driver, but it will either not have any effect, or it will serve as a hint that might or might not be followed.
- The only flag that UMDs are expected to set with regard to CPU access is NO_CPU_ACCESS.

The main motivation is the reduction of "virtual" heaps for UMD buffer suballocators and reusable buffer pools. A higher number of heaps means that more memory can be wasted by UMDs.

Opinions?

Thanks,
Marek
_______________________________________________
amd-gfx mailing list [email protected]<mailto:[email protected]>
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list [email protected]<mailto:[email protected]>
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): FE84B835-C930-424E-B380-649F4895274C-5C7GfCeVMHo@public.gmane.org

#52 lore raw
Quoted 6 lines · David

Vulkan allows the application to decide whether it wants the allocation to be host visible and device local.
If we drop the flag, what will happen if we did not set the NO_CPU_ACCESS flag?
Will it fail the map in case the allocation could be placed in invisible heap then?

No, it'll work just as well. On attempted CPU access, amdgpu_bo_fault_reserve_notify will ensure that it's CPU accessible.

The difference is that it'll allow BOs which aren't being actively accessed by the CPU to be in CPU invisible VRAM, reducing pressure on CPU visible VRAM.

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 17988a78-85c4-24c2-961a-b07f7222446f-otUistvHUpPR7s880joybQ@public.gmane.org

#54 lore raw

Sounds good!
One thing to confirm, If the original location is already in the invisible, will the notifier callback to move the bo from invisible to visible? if it is true and the logic is already available in the kernel, can we use NO_CPU_ACCESS flag by default to accomplish the similar purpose for now? It also reminds me of another related topic, can we always take visible heap as priority against to the remote in this case?
So far, kernel don’t have the heap priority.
IIRC, if the LFB bo moved to GTT, it will never be moved back since GTT is also its preferred heap. (Kernel seems to add the GTT even if the UMD only ask for LFB).

Thanks.
Best Regards,
David
On 30 Jun 2017, at 11:36 AM, Michel Dänzer <[email protected]<mailto:[email protected]>> wrote:

On 30/06/17 10:55 AM, Mao, David wrote:
Vulkan allows the application to decide whether it wants the allocation to be host visible and device local.
If we drop the flag, what will happen if we did not set the NO_CPU_ACCESS flag?
Will it fail the map in case the allocation could be placed in invisible heap then?

No, it'll work just as well. On attempted CPU access, amdgpu_bo_fault_reserve_notify will ensure that it's CPU accessible.

The difference is that it'll allow BOs which aren't being actively accessed by the CPU to be in CPU invisible VRAM, reducing pressure on CPU visible VRAM.

--
Earthling Michel Dänzer | http://www.amd.com
Libre software enthusiast | Mesa and X developer

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 0C38ED78-D50C-4212-AA7A-0DACBFDB5680-5C7GfCeVMHo@public.gmane.org

#56 lore raw
Quoted 4 lines · David

Sounds good!
One thing to confirm, If the original location is already in the invisible, will the notifier callback to move the bo from invisible to visible?

Yes.

Quoted 3 lines

if it is true and the logic is already available in the kernel, can we use NO_CPU_ACCESS flag by default to accomplish the similar purpose for now?

You mean set the NO_CPU_ACCESS flag for BOs in the "CPU invisible heap"? Yes, that's a good idea.

However, we can also improve the kernel driver's handling of the CPU_ACCESS_REQUIRED flag so that userspace code can continue using it the way it has been.

Quoted 5 lines

It also reminds me of another related topic, can we always take visible heap as priority against to the remote in this case?
So far, kernel don’t have the heap priority.
IIRC, if the LFB bo moved to GTT, it will never be moved back since GTT is also its preferred heap.

That can happen if userspace specifies both VRAM and GTT as preferred domains. It's one reason why that isn't recommended.

Quoted 1 line

(Kernel seems to add the GTT even if the UMD only ask for LFB).

I can only see

                robj->allowed_domains = robj->prefered_domains;
                if (robj->allowed_domains == AMDGPU_GEM_DOMAIN_VRAM)
                        robj->allowed_domains |= AMDGPU_GEM_DOMAIN_GTT;

which adds GTT as an *allowed* domain for BOs which only have VRAM as the preferred domain. Since VRAM is the only preferred domain, the driver will attempt to move the BO from GTT to VRAM on userspace command stream submissions (subject to throttling).

Signature · 6 lines
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx