[PATCH v2 2/2] drm/amdgpu: report the number of bytes moved at buffer creation
Samuel Pitoiset
samuel.pitoiset at gmail.com
Mon Feb 13 17:50:29 UTC 2017
On 02/13/2017 05:28 PM, Nicolai Hähnle wrote:
> On 09.02.2017 11:33, Samuel Pitoiset wrote:
>> Like ttm_bo_validate(), ttm_bo_init() might need to move BO and
>> the number of bytes moved by TTM should be reported. This can help
>> the throttle buffer migration mechanism to make a better decision.
>
> Hmm, this could double-count bytes if there's a concurrent CS submission
> going on.
You are right.
Thanks Christian for taking care of this.
>
> It's only a heuristic, so I guess it's not too bad, but still - having
> at least a comment about this would be nice.
>
> Nicolai
>
>> v2: fix computation
>>
>> Signed-off-by: Samuel Pitoiset <samuel.pitoiset at gmail.com>
>> ---
>> drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 +
>> drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 3 +--
>> drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 6 ++++++
>> 3 files changed, 8 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> index 402a8954c6d8..5227e4d1d5db 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
>> @@ -1720,6 +1720,7 @@ int amdgpu_cs_parser_init(struct
>> amdgpu_cs_parser *p, void *data);
>> int amdgpu_cs_get_ring(struct amdgpu_device *adev, u32 ip_type,
>> u32 ip_instance, u32 ring,
>> struct amdgpu_ring **out_ring);
>> +void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64
>> num_bytes);
>> void amdgpu_ttm_placement_from_domain(struct amdgpu_bo *abo, u32
>> domain);
>> bool amdgpu_ttm_bo_is_amdgpu_bo(struct ttm_buffer_object *bo);
>> int amdgpu_ttm_tt_get_user_pages(struct ttm_tt *ttm, struct page
>> **pages);
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>> index 6e948e4986ec..dade2fa9593a 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
>> @@ -351,8 +351,7 @@ static u64
>> amdgpu_cs_get_threshold_for_moves(struct amdgpu_device *adev)
>> * submission. This can result in a debt that can stop buffer migrations
>> * temporarily.
>> */
>> -static void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev,
>> - u64 num_bytes)
>> +void amdgpu_cs_report_moved_bytes(struct amdgpu_device *adev, u64
>> num_bytes)
>> {
>> spin_lock(&adev->mm_stats.lock);
>> adev->mm_stats.accum_us -= bytes_to_us(adev, num_bytes);
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> index 556236a112c1..4aa2c8a94347 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
>> @@ -323,6 +323,7 @@ int amdgpu_bo_create_restricted(struct
>> amdgpu_device *adev,
>> struct amdgpu_bo *bo;
>> enum ttm_bo_type type;
>> unsigned long page_align;
>> + u64 initial_bytes_moved;
>> size_t acc_size;
>> int r;
>>
>> @@ -399,10 +400,15 @@ int amdgpu_bo_create_restricted(struct
>> amdgpu_device *adev,
>> locked = ww_mutex_trylock(&bo->tbo.ttm_resv.lock);
>> WARN_ON(!locked);
>> }
>> +
>> + initial_bytes_moved = atomic64_read(&adev->num_bytes_moved);
>> r = ttm_bo_init(&adev->mman.bdev, &bo->tbo, size, type,
>> &bo->placement, page_align, !kernel, NULL,
>> acc_size, sg, resv ? resv : &bo->tbo.ttm_resv,
>> &amdgpu_ttm_bo_destroy);
>> + amdgpu_cs_report_moved_bytes(adev,
>> + atomic64_read(&adev->num_bytes_moved) - initial_bytes_moved);
>> +
>> if (unlikely(r != 0)) {
>> if (!resv)
>> ww_mutex_unlock(&bo->tbo.resv->lock);
>>
>
More information about the amd-gfx
mailing list