[07/12] panfrost: Allocate dedicated slab for linear BOs

Submitted by Alyssa Rosenzweig on March 10, 2019, 6:50 a.m.

Details

Message ID 20190310065026.3994-8-alyssa@rosenzweig.io
State New
Headers show
Series "Refactors related to BO layouts" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Alyssa Rosenzweig March 10, 2019, 6:50 a.m.
Previously, linear BOs shared memory with each other to minimize kernel
round-trips / latency, as well as to work around a bug in the free_slab
function. These concerns are invalid now, but continuing to use the slab
allocator for BOs resulted in memory allocation errors. This issue was
aggravated, though not introduced (so not a real regression) in the
previous commit.

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
---
 src/gallium/drivers/panfrost/pan_resource.c | 32 ++++++++++++---------
 1 file changed, 19 insertions(+), 13 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c
index 39783f5a63a..0f11b8e5e38 100644
--- a/src/gallium/drivers/panfrost/pan_resource.c
+++ b/src/gallium/drivers/panfrost/pan_resource.c
@@ -248,14 +248,16 @@  panfrost_create_bo(struct panfrost_screen *screen, const struct pipe_resource *t
                         sz >>= 2;
                 }
         } else {
-                /* But for linear, we can! */
+                /* For a linear resource, allocate a block of memory from
+                 * kernel space */
 
-                struct pb_slab_entry *entry = pb_slab_alloc(&screen->slabs, sz, HEAP_TEXTURE);
-                struct panfrost_memory_entry *p_entry = (struct panfrost_memory_entry *) entry;
-                struct panfrost_memory *backing = (struct panfrost_memory *) entry->slab;
-                bo->entry[0] = p_entry;
-                bo->cpu[0] = backing->cpu + p_entry->offset;
-                bo->gpu[0] = backing->gpu + p_entry->offset;
+                struct panfrost_memory mem;
+
+                unsigned pages = ((sz + 4095) / 4096) * 2;
+                screen->driver->allocate_slab(screen, &mem, pages, true, 0, 0, 0);
+
+                bo->cpu[0] = mem.cpu;
+                bo->gpu[0] = mem.gpu;
 
                 /* TODO: Mipmap */
         }
@@ -325,12 +327,16 @@  panfrost_destroy_bo(struct panfrost_screen *screen, struct panfrost_bo *pbo)
 {
 	struct panfrost_bo *bo = (struct panfrost_bo *)pbo;
 
-        for (int l = 0; l < MAX_MIP_LEVELS; ++l) {
-                if (bo->entry[l] != NULL) {
-                        /* Most allocations have an entry to free */
-                        bo->entry[l]->freed = true;
-                        pb_slab_free(&screen->slabs, &bo->entry[l]->base);
-                }
+        if (bo->layout == PAN_LINEAR) {
+                /* Construct a memory object for all mip levels */
+
+                struct panfrost_memory mem = {
+                        .cpu = bo->cpu[0],
+                        .gpu = bo->gpu[0],
+                        .size = bo->imported_size
+                };
+
+                screen->driver->free_slab(screen, &mem);
         }
 
         if (bo->layout == PAN_TILED) {

Comments

Reviewed-by: Tomeu Vizoso <tomeu.vizoso@collabora.com>

On Sun, 10 Mar 2019 at 07:50, Alyssa Rosenzweig <alyssa@rosenzweig.io> wrote:
>
> Previously, linear BOs shared memory with each other to minimize kernel
> round-trips / latency, as well as to work around a bug in the free_slab
> function. These concerns are invalid now, but continuing to use the slab
> allocator for BOs resulted in memory allocation errors. This issue was
> aggravated, though not introduced (so not a real regression) in the
> previous commit.
>
> Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
> ---
>  src/gallium/drivers/panfrost/pan_resource.c | 32 ++++++++++++---------
>  1 file changed, 19 insertions(+), 13 deletions(-)
>
> diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c
> index 39783f5a63a..0f11b8e5e38 100644
> --- a/src/gallium/drivers/panfrost/pan_resource.c
> +++ b/src/gallium/drivers/panfrost/pan_resource.c
> @@ -248,14 +248,16 @@ panfrost_create_bo(struct panfrost_screen *screen, const struct pipe_resource *t
>                          sz >>= 2;
>                  }
>          } else {
> -                /* But for linear, we can! */
> +                /* For a linear resource, allocate a block of memory from
> +                 * kernel space */
>
> -                struct pb_slab_entry *entry = pb_slab_alloc(&screen->slabs, sz, HEAP_TEXTURE);
> -                struct panfrost_memory_entry *p_entry = (struct panfrost_memory_entry *) entry;
> -                struct panfrost_memory *backing = (struct panfrost_memory *) entry->slab;
> -                bo->entry[0] = p_entry;
> -                bo->cpu[0] = backing->cpu + p_entry->offset;
> -                bo->gpu[0] = backing->gpu + p_entry->offset;
> +                struct panfrost_memory mem;
> +
> +                unsigned pages = ((sz + 4095) / 4096) * 2;
> +                screen->driver->allocate_slab(screen, &mem, pages, true, 0, 0, 0);
> +
> +                bo->cpu[0] = mem.cpu;
> +                bo->gpu[0] = mem.gpu;
>
>                  /* TODO: Mipmap */
>          }
> @@ -325,12 +327,16 @@ panfrost_destroy_bo(struct panfrost_screen *screen, struct panfrost_bo *pbo)
>  {
>         struct panfrost_bo *bo = (struct panfrost_bo *)pbo;
>
> -        for (int l = 0; l < MAX_MIP_LEVELS; ++l) {
> -                if (bo->entry[l] != NULL) {
> -                        /* Most allocations have an entry to free */
> -                        bo->entry[l]->freed = true;
> -                        pb_slab_free(&screen->slabs, &bo->entry[l]->base);
> -                }
> +        if (bo->layout == PAN_LINEAR) {
> +                /* Construct a memory object for all mip levels */
> +
> +                struct panfrost_memory mem = {
> +                        .cpu = bo->cpu[0],
> +                        .gpu = bo->gpu[0],
> +                        .size = bo->imported_size
> +                };
> +
> +                screen->driver->free_slab(screen, &mem);
>          }
>
>          if (bo->layout == PAN_TILED) {
> --
> 2.20.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev