<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi Christian,</div><div><br></div><div>I just pushed the commits.<br></div><div><br></div><div>The best way to reproduce the out-of-memory errors is to run 2 instances of the test simultaneously:</div><div><br></div><div>R600_DEBUG=testgdsmm glxgears &</div><div>R600_DEBUG=testgdsmm glxgears &</div><div><br></div><div>It takes about 10 seconds to finish and you'll get a lot of errors. <br></div><div><br></div><div>If you run it again, all GDS allocations will fail:</div><div><br></div><div>R600_DEBUG=testgdsmm glxgears</div><div>amdgpu: Failed to allocate a buffer:<br>amdgpu: size : 32768 bytes<br>amdgpu: alignment : 4 bytes<br>amdgpu: domains : 8<br></div><div><br></div><div>Marek<br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Nov 28, 2018 at 2:16 PM Christian König <<a href="mailto:ckoenig.leichtzumerken@gmail.com" target="_blank">ckoenig.leichtzumerken@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Are those committed yet? They don't seem to apply cleanly on master.<br>
<br>
Christian.<br>
<br>
Am 27.11.18 um 02:56 schrieb Marek Olšák:<br>
> From: Marek Olšák <<a href="mailto:marek.olsak@amd.com" target="_blank">marek.olsak@amd.com</a>><br>
><br>
> ---<br>
> .../drivers/radeonsi/si_compute_blit.c | 4 +-<br>
> src/gallium/drivers/radeonsi/si_cp_dma.c | 49 ++++++++++---------<br>
> src/gallium/drivers/radeonsi/si_pipe.h | 8 +--<br>
> .../drivers/radeonsi/si_test_dma_perf.c | 3 +-<br>
> 4 files changed, 33 insertions(+), 31 deletions(-)<br>
><br>
> diff --git a/src/gallium/drivers/radeonsi/si_compute_blit.c b/src/gallium/drivers/radeonsi/si_compute_blit.c<br>
> index 20e4f591fbb..086793637f0 100644<br>
> --- a/src/gallium/drivers/radeonsi/si_compute_blit.c<br>
> +++ b/src/gallium/drivers/radeonsi/si_compute_blit.c<br>
> @@ -212,22 +212,22 @@ void si_clear_buffer(struct si_context *sctx, struct pipe_resource *dst,<br>
> */<br>
> if (clear_value_size > 4 ||<br>
> (clear_value_size == 4 &&<br>
> offset % 4 == 0 &&<br>
> (size > 32*1024 || sctx->chip_class <= VI))) {<br>
> si_compute_do_clear_or_copy(sctx, dst, offset, NULL, 0,<br>
> aligned_size, clear_value,<br>
> clear_value_size, coher);<br>
> } else {<br>
> assert(clear_value_size == 4);<br>
> - si_cp_dma_clear_buffer(sctx, dst, offset,<br>
> - aligned_size, *clear_value, coher,<br>
> + si_cp_dma_clear_buffer(sctx, sctx->gfx_cs, dst, offset,<br>
> + aligned_size, *clear_value, 0, coher,<br>
> get_cache_policy(sctx, coher, size));<br>
> }<br>
> <br>
> offset += aligned_size;<br>
> size -= aligned_size;<br>
> }<br>
> <br>
> /* Handle non-dword alignment. */<br>
> if (size) {<br>
> assert(dst);<br>
> diff --git a/src/gallium/drivers/radeonsi/si_cp_dma.c b/src/gallium/drivers/radeonsi/si_cp_dma.c<br>
> index 839b31b7fdf..33220d9f0fa 100644<br>
> --- a/src/gallium/drivers/radeonsi/si_cp_dma.c<br>
> +++ b/src/gallium/drivers/radeonsi/si_cp_dma.c<br>
> @@ -47,25 +47,24 @@ static inline unsigned cp_dma_max_byte_count(struct si_context *sctx)<br>
> <br>
> /* make it aligned for optimal performance */<br>
> return max & ~(SI_CPDMA_ALIGNMENT - 1);<br>
> }<br>
> <br>
> <br>
> /* Emit a CP DMA packet to do a copy from one buffer to another, or to clear<br>
> * a buffer. The size must fit in bits [20:0]. If CP_DMA_CLEAR is set, src_va is a 32-bit<br>
> * clear value.<br>
> */<br>
> -static void si_emit_cp_dma(struct si_context *sctx, uint64_t dst_va,<br>
> - uint64_t src_va, unsigned size, unsigned flags,<br>
> - enum si_cache_policy cache_policy)<br>
> +static void si_emit_cp_dma(struct si_context *sctx, struct radeon_cmdbuf *cs,<br>
> + uint64_t dst_va, uint64_t src_va, unsigned size,<br>
> + unsigned flags, enum si_cache_policy cache_policy)<br>
> {<br>
> - struct radeon_cmdbuf *cs = sctx->gfx_cs;<br>
> uint32_t header = 0, command = 0;<br>
> <br>
> assert(size <= cp_dma_max_byte_count(sctx));<br>
> assert(sctx->chip_class != SI || cache_policy == L2_BYPASS);<br>
> <br>
> if (sctx->chip_class >= GFX9)<br>
> command |= S_414_BYTE_COUNT_GFX9(size);<br>
> else<br>
> command |= S_414_BYTE_COUNT_GFX6(size);<br>
> <br>
> @@ -139,21 +138,21 @@ static void si_emit_cp_dma(struct si_context *sctx, uint64_t dst_va,<br>
> }<br>
> <br>
> void si_cp_dma_wait_for_idle(struct si_context *sctx)<br>
> {<br>
> /* Issue a dummy DMA that copies zero bytes.<br>
> *<br>
> * The DMA engine will see that there's no work to do and skip this<br>
> * DMA request, however, the CP will see the sync flag and still wait<br>
> * for all DMAs to complete.<br>
> */<br>
> - si_emit_cp_dma(sctx, 0, 0, 0, CP_DMA_SYNC, L2_BYPASS);<br>
> + si_emit_cp_dma(sctx, sctx->gfx_cs, 0, 0, 0, CP_DMA_SYNC, L2_BYPASS);<br>
> }<br>
> <br>
> static void si_cp_dma_prepare(struct si_context *sctx, struct pipe_resource *dst,<br>
> struct pipe_resource *src, unsigned byte_count,<br>
> uint64_t remaining_size, unsigned user_flags,<br>
> enum si_coherency coher, bool *is_first,<br>
> unsigned *packet_flags)<br>
> {<br>
> /* Fast exit for a CPDMA prefetch. */<br>
> if ((user_flags & SI_CPDMA_SKIP_ALL) == SI_CPDMA_SKIP_ALL) {<br>
> @@ -200,51 +199,53 @@ static void si_cp_dma_prepare(struct si_context *sctx, struct pipe_resource *dst<br>
> */<br>
> if (!(user_flags & SI_CPDMA_SKIP_SYNC_AFTER) &&<br>
> byte_count == remaining_size) {<br>
> *packet_flags |= CP_DMA_SYNC;<br>
> <br>
> if (coher == SI_COHERENCY_SHADER)<br>
> *packet_flags |= CP_DMA_PFP_SYNC_ME;<br>
> }<br>
> }<br>
> <br>
> -void si_cp_dma_clear_buffer(struct si_context *sctx, struct pipe_resource *dst,<br>
> - uint64_t offset, uint64_t size, unsigned value,<br>
> - enum si_coherency coher,<br>
> - enum si_cache_policy cache_policy)<br>
> +void si_cp_dma_clear_buffer(struct si_context *sctx, struct radeon_cmdbuf *cs,<br>
> + struct pipe_resource *dst, uint64_t offset,<br>
> + uint64_t size, unsigned value, unsigned user_flags,<br>
> + enum si_coherency coher, enum si_cache_policy cache_policy)<br>
> {<br>
> struct r600_resource *rdst = r600_resource(dst);<br>
> uint64_t va = (rdst ? rdst->gpu_address : 0) + offset;<br>
> bool is_first = true;<br>
> <br>
> assert(size && size % 4 == 0);<br>
> <br>
> /* Mark the buffer range of destination as valid (initialized),<br>
> * so that transfer_map knows it should wait for the GPU when mapping<br>
> * that range. */<br>
> if (rdst)<br>
> util_range_add(&rdst->valid_buffer_range, offset, offset + size);<br>
> <br>
> /* Flush the caches. */<br>
> - sctx->flags |= SI_CONTEXT_PS_PARTIAL_FLUSH |<br>
> - SI_CONTEXT_CS_PARTIAL_FLUSH |<br>
> - si_get_flush_flags(sctx, coher, cache_policy);<br>
> + if (rdst && !(user_flags & SI_CPDMA_SKIP_GFX_SYNC)) {<br>
> + sctx->flags |= SI_CONTEXT_PS_PARTIAL_FLUSH |<br>
> + SI_CONTEXT_CS_PARTIAL_FLUSH |<br>
> + si_get_flush_flags(sctx, coher, cache_policy);<br>
> + }<br>
> <br>
> while (size) {<br>
> unsigned byte_count = MIN2(size, cp_dma_max_byte_count(sctx));<br>
> unsigned dma_flags = CP_DMA_CLEAR | (rdst ? 0 : CP_DMA_DST_IS_GDS);<br>
> <br>
> - si_cp_dma_prepare(sctx, dst, NULL, byte_count, size, 0, coher,<br>
> - &is_first, &dma_flags);<br>
> + si_cp_dma_prepare(sctx, dst, NULL, byte_count, size, user_flags,<br>
> + coher, &is_first, &dma_flags);<br>
> <br>
> /* Emit the clear packet. */<br>
> - si_emit_cp_dma(sctx, va, value, byte_count, dma_flags, cache_policy);<br>
> + si_emit_cp_dma(sctx, cs, va, value, byte_count, dma_flags, cache_policy);<br>
> <br>
> size -= byte_count;<br>
> va += byte_count;<br>
> }<br>
> <br>
> if (rdst && cache_policy != L2_BYPASS)<br>
> rdst->TC_L2_dirty = true;<br>
> <br>
> /* If it's not a framebuffer fast clear... */<br>
> if (coher == SI_COHERENCY_SHADER)<br>
> @@ -283,21 +284,21 @@ static void si_cp_dma_realign_engine(struct si_context *sctx, unsigned size,<br>
> return;<br>
> <br>
> si_mark_atom_dirty(sctx, &sctx->atoms.s.scratch_state);<br>
> }<br>
> <br>
> si_cp_dma_prepare(sctx, &sctx->scratch_buffer->b.b,<br>
> &sctx->scratch_buffer->b.b, size, size, user_flags,<br>
> coher, is_first, &dma_flags);<br>
> <br>
> va = sctx->scratch_buffer->gpu_address;<br>
> - si_emit_cp_dma(sctx, va, va + SI_CPDMA_ALIGNMENT, size, dma_flags,<br>
> + si_emit_cp_dma(sctx, sctx->gfx_cs, va, va + SI_CPDMA_ALIGNMENT, size, dma_flags,<br>
> cache_policy);<br>
> }<br>
> <br>
> /**<br>
> * Do memcpy between buffers using CP DMA.<br>
> * If src or dst is NULL, it means read or write GDS, respectively.<br>
> *<br>
> * \param user_flags bitmask of SI_CPDMA_*<br>
> */<br>
> void si_cp_dma_copy_buffer(struct si_context *sctx,<br>
> @@ -366,37 +367,37 @@ void si_cp_dma_copy_buffer(struct si_context *sctx,<br>
> main_src_offset = src_offset + skipped_size;<br>
> <br>
> while (size) {<br>
> unsigned byte_count = MIN2(size, cp_dma_max_byte_count(sctx));<br>
> unsigned dma_flags = gds_flags;<br>
> <br>
> si_cp_dma_prepare(sctx, dst, src, byte_count,<br>
> size + skipped_size + realign_size,<br>
> user_flags, coher, &is_first, &dma_flags);<br>
> <br>
> - si_emit_cp_dma(sctx, main_dst_offset, main_src_offset,<br>
> + si_emit_cp_dma(sctx, sctx->gfx_cs, main_dst_offset, main_src_offset,<br>
> byte_count, dma_flags, cache_policy);<br>
> <br>
> size -= byte_count;<br>
> main_src_offset += byte_count;<br>
> main_dst_offset += byte_count;<br>
> }<br>
> <br>
> /* Copy the part we skipped because src wasn't aligned. */<br>
> if (skipped_size) {<br>
> unsigned dma_flags = gds_flags;<br>
> <br>
> si_cp_dma_prepare(sctx, dst, src, skipped_size,<br>
> skipped_size + realign_size, user_flags,<br>
> coher, &is_first, &dma_flags);<br>
> <br>
> - si_emit_cp_dma(sctx, dst_offset, src_offset, skipped_size,<br>
> + si_emit_cp_dma(sctx, sctx->gfx_cs, dst_offset, src_offset, skipped_size,<br>
> dma_flags, cache_policy);<br>
> }<br>
> <br>
> /* Finally, realign the engine if the size wasn't aligned. */<br>
> if (realign_size) {<br>
> si_cp_dma_realign_engine(sctx, realign_size, user_flags, coher,<br>
> cache_policy, &is_first);<br>
> }<br>
> <br>
> if (dst && cache_policy != L2_BYPASS)<br>
> @@ -546,35 +547,35 @@ void cik_emit_prefetch_L2(struct si_context *sctx, bool vertex_stage_only)<br>
> <br>
> void si_test_gds(struct si_context *sctx)<br>
> {<br>
> struct pipe_context *ctx = &sctx->b;<br>
> struct pipe_resource *src, *dst;<br>
> unsigned r[4] = {};<br>
> unsigned offset = debug_get_num_option("OFFSET", 16);<br>
> <br>
> src = pipe_buffer_create(ctx->screen, 0, PIPE_USAGE_DEFAULT, 16);<br>
> dst = pipe_buffer_create(ctx->screen, 0, PIPE_USAGE_DEFAULT, 16);<br>
> - si_cp_dma_clear_buffer(sctx, src, 0, 4, 0xabcdef01, SI_COHERENCY_SHADER, L2_BYPASS);<br>
> - si_cp_dma_clear_buffer(sctx, src, 4, 4, 0x23456789, SI_COHERENCY_SHADER, L2_BYPASS);<br>
> - si_cp_dma_clear_buffer(sctx, src, 8, 4, 0x87654321, SI_COHERENCY_SHADER, L2_BYPASS);<br>
> - si_cp_dma_clear_buffer(sctx, src, 12, 4, 0xfedcba98, SI_COHERENCY_SHADER, L2_BYPASS);<br>
> - si_cp_dma_clear_buffer(sctx, dst, 0, 16, 0xdeadbeef, SI_COHERENCY_SHADER, L2_BYPASS);<br>
> + si_cp_dma_clear_buffer(sctx, sctx->gfx_cs, src, 0, 4, 0xabcdef01, 0, SI_COHERENCY_SHADER, L2_BYPASS);<br>
> + si_cp_dma_clear_buffer(sctx, sctx->gfx_cs, src, 4, 4, 0x23456789, 0, SI_COHERENCY_SHADER, L2_BYPASS);<br>
> + si_cp_dma_clear_buffer(sctx, sctx->gfx_cs, src, 8, 4, 0x87654321, 0, SI_COHERENCY_SHADER, L2_BYPASS);<br>
> + si_cp_dma_clear_buffer(sctx, sctx->gfx_cs, src, 12, 4, 0xfedcba98, 0, SI_COHERENCY_SHADER, L2_BYPASS);<br>
> + si_cp_dma_clear_buffer(sctx, sctx->gfx_cs, dst, 0, 16, 0xdeadbeef, 0, SI_COHERENCY_SHADER, L2_BYPASS);<br>
> <br>
> si_cp_dma_copy_buffer(sctx, NULL, src, offset, 0, 16, 0, SI_COHERENCY_NONE, L2_BYPASS);<br>
> si_cp_dma_copy_buffer(sctx, dst, NULL, 0, offset, 16, 0, SI_COHERENCY_NONE, L2_BYPASS);<br>
> <br>
> pipe_buffer_read(ctx, dst, 0, sizeof(r), r);<br>
> printf("GDS copy = %08x %08x %08x %08x -> %s\n", r[0], r[1], r[2], r[3],<br>
> r[0] == 0xabcdef01 && r[1] == 0x23456789 &&<br>
> r[2] == 0x87654321 && r[3] == 0xfedcba98 ? "pass" : "fail");<br>
> <br>
> - si_cp_dma_clear_buffer(sctx, NULL, offset, 16, 0xc1ea4146, SI_COHERENCY_NONE, L2_BYPASS);<br>
> + si_cp_dma_clear_buffer(sctx, sctx->gfx_cs, NULL, offset, 16, 0xc1ea4146, 0, SI_COHERENCY_NONE, L2_BYPASS);<br>
> si_cp_dma_copy_buffer(sctx, dst, NULL, 0, offset, 16, 0, SI_COHERENCY_NONE, L2_BYPASS);<br>
> <br>
> pipe_buffer_read(ctx, dst, 0, sizeof(r), r);<br>
> printf("GDS clear = %08x %08x %08x %08x -> %s\n", r[0], r[1], r[2], r[3],<br>
> r[0] == 0xc1ea4146 && r[1] == 0xc1ea4146 &&<br>
> r[2] == 0xc1ea4146 && r[3] == 0xc1ea4146 ? "pass" : "fail");<br>
> <br>
> pipe_resource_reference(&src, NULL);<br>
> pipe_resource_reference(&dst, NULL);<br>
> exit(0);<br>
> diff --git a/src/gallium/drivers/radeonsi/si_pipe.h b/src/gallium/drivers/radeonsi/si_pipe.h<br>
> index 023e0f0a0f9..3ec645f9c71 100644<br>
> --- a/src/gallium/drivers/radeonsi/si_pipe.h<br>
> +++ b/src/gallium/drivers/radeonsi/si_pipe.h<br>
> @@ -1152,24 +1152,24 @@ void si_init_compute_blit_functions(struct si_context *sctx);<br>
> #define SI_CPDMA_SKIP_SYNC_BEFORE (1 << 2) /* don't wait for DMA before the copy (RAW hazards) */<br>
> #define SI_CPDMA_SKIP_GFX_SYNC (1 << 3) /* don't flush caches and don't wait for PS/CS */<br>
> #define SI_CPDMA_SKIP_BO_LIST_UPDATE (1 << 4) /* don't update the BO list */<br>
> #define SI_CPDMA_SKIP_ALL (SI_CPDMA_SKIP_CHECK_CS_SPACE | \<br>
> SI_CPDMA_SKIP_SYNC_AFTER | \<br>
> SI_CPDMA_SKIP_SYNC_BEFORE | \<br>
> SI_CPDMA_SKIP_GFX_SYNC | \<br>
> SI_CPDMA_SKIP_BO_LIST_UPDATE)<br>
> <br>
> void si_cp_dma_wait_for_idle(struct si_context *sctx);<br>
> -void si_cp_dma_clear_buffer(struct si_context *sctx, struct pipe_resource *dst,<br>
> - uint64_t offset, uint64_t size, unsigned value,<br>
> - enum si_coherency coher,<br>
> - enum si_cache_policy cache_policy);<br>
> +void si_cp_dma_clear_buffer(struct si_context *sctx, struct radeon_cmdbuf *cs,<br>
> + struct pipe_resource *dst, uint64_t offset,<br>
> + uint64_t size, unsigned value, unsigned user_flags,<br>
> + enum si_coherency coher, enum si_cache_policy cache_policy);<br>
> void si_cp_dma_copy_buffer(struct si_context *sctx,<br>
> struct pipe_resource *dst, struct pipe_resource *src,<br>
> uint64_t dst_offset, uint64_t src_offset, unsigned size,<br>
> unsigned user_flags, enum si_coherency coher,<br>
> enum si_cache_policy cache_policy);<br>
> void cik_prefetch_TC_L2_async(struct si_context *sctx, struct pipe_resource *buf,<br>
> uint64_t offset, unsigned size);<br>
> void cik_emit_prefetch_L2(struct si_context *sctx, bool vertex_stage_only);<br>
> void si_test_gds(struct si_context *sctx);<br>
> <br>
> diff --git a/src/gallium/drivers/radeonsi/si_test_dma_perf.c b/src/gallium/drivers/radeonsi/si_test_dma_perf.c<br>
> index 6c04720e963..657c4ebeff8 100644<br>
> --- a/src/gallium/drivers/radeonsi/si_test_dma_perf.c<br>
> +++ b/src/gallium/drivers/radeonsi/si_test_dma_perf.c<br>
> @@ -174,21 +174,22 @@ void si_test_dma_perf(struct si_screen *sscreen)<br>
> for (unsigned iter = 0; iter < NUM_RUNS; iter++) {<br>
> q[iter] = ctx->create_query(ctx, query_type, 0);<br>
> ctx->begin_query(ctx, q[iter]);<br>
> <br>
> if (test_cp) {<br>
> /* CP DMA */<br>
> if (is_copy) {<br>
> si_cp_dma_copy_buffer(sctx, dst, src, 0, 0, size, 0,<br>
> SI_COHERENCY_NONE, cache_policy);<br>
> } else {<br>
> - si_cp_dma_clear_buffer(sctx, dst, 0, size, clear_value,<br>
> + si_cp_dma_clear_buffer(sctx, sctx->gfx_cs, dst, 0, size,<br>
> + clear_value, 0,<br>
> SI_COHERENCY_NONE, cache_policy);<br>
> }<br>
> } else if (test_sdma) {<br>
> /* SDMA */<br>
> if (is_copy) {<br>
> struct pipe_box box;<br>
> u_box_1d(0, size, &box);<br>
> sctx->dma_copy(ctx, dst, 0, 0, 0, 0, src, 0, &box);<br>
> } else {<br>
> si_sdma_clear_buffer(sctx, dst, 0, size, clear_value);<br>
<br>
</blockquote></div></div>