[Mesa-dev] [PATCH v2 3/4] r600,compute: Plug memory leaks
Marek Olšák
maraeo at gmail.com
Sat Jun 6 14:27:22 PDT 2015
Please move the inline functions to a .c file.
Also, if they are not used by drivers/radeon or radeonsi, they
shouldn't be in drivers/radeon.
Marek
On Sat, Jun 6, 2015 at 10:33 PM, Jan Vesely <jan.vesely at rutgers.edu> wrote:
> v2: drop inline keyword
> drop radeon_llvm_dispose_kernel_module wrapper
>
> Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
> ---
>
> I decided to keep radeon_shader_binary_clean,a nd dropped the other one.
>
> src/gallium/drivers/r600/evergreen_compute.c | 24 +++++++++++++++++++++---
> src/gallium/drivers/r600/r600_llvm.c | 14 +++++++++-----
> src/gallium/drivers/r600/r600_llvm.h | 2 ++
> src/gallium/drivers/radeon/r600_pipe_common.h | 17 +++++++++++++++++
> 4 files changed, 49 insertions(+), 8 deletions(-)
>
> diff --git a/src/gallium/drivers/r600/evergreen_compute.c b/src/gallium/drivers/r600/evergreen_compute.c
> index 25f5f7d..14d3165 100644
> --- a/src/gallium/drivers/r600/evergreen_compute.c
> +++ b/src/gallium/drivers/r600/evergreen_compute.c
> @@ -225,7 +225,7 @@ void *evergreen_create_compute_state(
> }
> }
> #else
> - memset(&shader->binary, 0, sizeof(shader->binary));
> + radeon_shader_binary_init(&shader->binary);
> radeon_elf_read(code, header->num_bytes, &shader->binary, true);
> r600_create_shader(&shader->bc, &shader->binary, &use_kill);
>
> @@ -261,13 +261,31 @@ void *evergreen_create_compute_state(
> return shader;
> }
>
> -void evergreen_delete_compute_state(struct pipe_context *ctx, void* state)
> +void evergreen_delete_compute_state(struct pipe_context *ctx_, void* state)
> {
> - struct r600_pipe_compute *shader = (struct r600_pipe_compute *)state;
> + struct r600_context *ctx = (struct r600_context *)ctx_;
> + COMPUTE_DBG(ctx->screen, "*** evergreen_delete_compute_state\n");
> + struct r600_pipe_compute *shader = state;
>
> if (!shader)
> return;
>
> +#ifdef HAVE_OPENCL
> +#if HAVE_LLVM < 0x0306
> + for (unsigned i = 0; i < shader->num_kernels; i++) {
> + struct r600_kernel *kernel = &shader->kernels[i];
> + LLVMDisposeModule(module);
> + }
> + FREE(shader->kernels);
> + LLVMContextDispose(shader->llvm_ctx);
> +#else
> + radeon_shader_binary_clean(&shader->binary);
> + r600_destroy_shader(&shader->bc);
> +
> + /* TODO destroy shader->code_bo, shader->const_bo
> + * we'll need something like r600_buffer_free */
> +#endif
> +#endif
> FREE(shader);
> }
>
> diff --git a/src/gallium/drivers/r600/r600_llvm.c b/src/gallium/drivers/r600/r600_llvm.c
> index 94085fc..ac34d5c 100644
> --- a/src/gallium/drivers/r600/r600_llvm.c
> +++ b/src/gallium/drivers/r600/r600_llvm.c
> @@ -872,6 +872,12 @@ unsigned r600_create_shader(struct r600_bytecode *bc,
> return 0;
> }
>
> +void r600_destroy_shader(struct r600_bytecode *bc)
> +{
> + FREE(bc->bytecode);
> + FREE(bc->rodata);
> +}
> +
> unsigned r600_llvm_compile(
> LLVMModuleRef mod,
> enum radeon_family family,
> @@ -883,15 +889,13 @@ unsigned r600_llvm_compile(
> struct radeon_shader_binary binary;
> const char * gpu_family = r600_get_llvm_processor_name(family);
>
> - memset(&binary, 0, sizeof(struct radeon_shader_binary));
> + radeon_shader_binary_init(&binary);
> +
> r = radeon_llvm_compile(mod, &binary, gpu_family, dump, NULL);
>
> r = r600_create_shader(bc, &binary, use_kill);
>
> - FREE(binary.code);
> - FREE(binary.config);
> - FREE(binary.rodata);
> - FREE(binary.global_symbol_offsets);
> + radeon_shader_binary_clean(&binary);
>
> return r;
> }
> diff --git a/src/gallium/drivers/r600/r600_llvm.h b/src/gallium/drivers/r600/r600_llvm.h
> index 9b5304d..442b312 100644
> --- a/src/gallium/drivers/r600/r600_llvm.h
> +++ b/src/gallium/drivers/r600/r600_llvm.h
> @@ -28,6 +28,8 @@ unsigned r600_create_shader(struct r600_bytecode *bc,
> const struct radeon_shader_binary *binary,
> boolean *use_kill);
>
> +void r600_destroy_shader(struct r600_bytecode *bc);
> +
> void r600_shader_binary_read_config(const struct radeon_shader_binary *binary,
> struct r600_bytecode *bc,
> uint64_t symbol_offset,
> diff --git a/src/gallium/drivers/radeon/r600_pipe_common.h b/src/gallium/drivers/radeon/r600_pipe_common.h
> index 6ce81d3..254f682 100644
> --- a/src/gallium/drivers/radeon/r600_pipe_common.h
> +++ b/src/gallium/drivers/radeon/r600_pipe_common.h
> @@ -38,6 +38,7 @@
>
> #include "util/u_blitter.h"
> #include "util/list.h"
> +#include "util/u_memory.h"
> #include "util/u_range.h"
> #include "util/u_slab.h"
> #include "util/u_suballoc.h"
> @@ -132,6 +133,22 @@ struct radeon_shader_binary {
> int disassembled;
> };
>
> +static void radeon_shader_binary_init(struct radeon_shader_binary *b)
> +{
> + memset(b, 0, sizeof(*b));
> +}
> +
> +static void radeon_shader_binary_clean(struct radeon_shader_binary *b)
> +{
> + if (!b)
> + return;
> + FREE(b->code);
> + FREE(b->config);
> + FREE(b->rodata);
> + FREE(b->global_symbol_offsets);
> + FREE(b->relocs);
> +}
> +
> struct r600_resource {
> struct u_resource b;
>
> --
> 2.4.2
>
More information about the mesa-dev
mailing list