gpu: disable lazy map [1/3]
authorDezhi Kong <dezhi.kong@amlogic.com>
Thu, 30 Jul 2020 12:30:14 +0000 (20:30 +0800)
committerDezhi Kong <dezhi.kong@amlogic.com>
Tue, 18 Aug 2020 11:34:00 +0000 (04:34 -0700)
PD#SWPL-24588

Problem:
low score for mali450 offscreen

Solution:
rm CONFIG_MALI_DMA_BUF_LAZY_MAP which enable in SWPL-21801
add video layer flag check

Verify:
p244#117

Change-Id: Ifb8898381a0c73f3dc015f6d09c26833c3b038ff
Signed-off-by: Dezhi Kong <dezhi.kong@amlogic.com>
13 files changed:
gpu-build.sh
gpu-v2.mk
mali/common/mali_pp_job.c [changed mode: 0755->0644]
mali/common/mali_pp_job.h [changed mode: 0755->0644]
mali/common/mali_scheduler.c [changed mode: 0755->0644]
mali/include/linux/mali/mali_utgard_uk_types.h [changed mode: 0755->0644]
mali/linux/mali_memory_dma_buf.c [changed mode: 0755->0644]
mali/linux/mali_memory_dma_buf.h [changed mode: 0755->0644]
mali/linux/mali_memory_manager.c
mali/linux/mali_memory_manager.h
mali/linux/mali_memory_types.h [changed mode: 0755->0644]
mali/linux/mali_memory_virtual.c
mali/linux/mali_memory_virtual.h

index cdce22220e9f6b88c64d822af2f5929370b1dd78..3463faf255bfbb688eb062b4bee9aa0feb6a3102 100755 (executable)
@@ -63,8 +63,7 @@ utgard_build()
        echo "make mali module MALI_OUT is ${PRODUCT_OUT}/obj/mali ${MALI_OUT}"
        make -C ${KDIR} M=${PRODUCT_OUT}/obj/mali  \
                ARCH=${KERNEL_ARCH} CROSS_COMPILE=${PREFIX_CROSS_COMPILE} CONFIG_MALI400=m  CONFIG_MALI450=m    \
-               CONFIG_MALI_DMA_BUF_LAZY_MAP=y \
-               EXTRA_CFLAGS="-DCONFIG_MALI400=m -DCONFIG_MALI450=m -DCONFIG_MALI_DMA_BUF_LAZY_MAP=y" \
+               EXTRA_CFLAGS="-DCONFIG_MALI400=m -DCONFIG_MALI450=m" \
                EXTRA_LDFLAGS+="--strip-debug" \
                CONFIG_AM_VDEC_H264_4K2K=y 2>&1 | tee mali.txt
 
index 2de274a091103fb3accd1b4a89e64dbb3753a57d..9613e7c0b80bcfa23c37583fb64ab691909149d2 100755 (executable)
--- a/gpu-v2.mk
+++ b/gpu-v2.mk
@@ -37,8 +37,7 @@ define utgard-modules
        PATH=$$(cd ./$(TARGET_HOST_TOOL_PATH); pwd):$$PATH \
        $(MAKE) -C $(shell pwd)/$(PRODUCT_OUT)/obj/KERNEL_OBJ M=$(shell pwd)/$(PRODUCT_OUT)/obj/mali  \
        ARCH=$(3) CROSS_COMPILE=$(PREFIX_CROSS_COMPILE) CONFIG_MALI400=m  CONFIG_MALI450=m    \
-       CONFIG_MALI_DMA_BUF_LAZY_MAP=y \
-       EXTRA_CFLAGS="-DCONFIG_MALI400=m -DCONFIG_MALI450=m -DCONFIG_MALI_DMA_BUF_LAZY_MAP=y" \
+       EXTRA_CFLAGS="-DCONFIG_MALI400=m -DCONFIG_MALI450=m" \
        EXTRA_LDFLAGS+="--strip-debug" \
        CONFIG_AM_VDEC_H264_4K2K=y
 
old mode 100755 (executable)
new mode 100644 (file)
index c2ed210..268912f
@@ -15,7 +15,7 @@
 #include "mali_kernel_common.h"
 #include "mali_uk_types.h"
 #include "mali_executor.h"
-#if defined(CONFIG_DMA_SHARED_BUFFER) && !defined(CONFIG_MALI_DMA_BUF_MAP_ON_ATTACH)
+#if defined(CONFIG_DMA_SHARED_BUFFER)
 #include "linux/mali_memory_dma_buf.h"
 #endif
 #include "mali_memory_swap_alloc.h"
@@ -144,6 +144,9 @@ fail:
 void mali_pp_job_delete(struct mali_pp_job *job)
 {
        struct mali_session_data *session;
+#if defined(CONFIG_DMA_SHARED_BUFFER) && !defined(CONFIG_MALI_DMA_BUF_LAZY_MAP)
+       u32 i, have_video = 0;
+#endif
 
        MALI_DEBUG_ASSERT_POINTER(job);
        MALI_DEBUG_ASSERT(_mali_osk_list_empty(&job->list));
@@ -153,10 +156,26 @@ void mali_pp_job_delete(struct mali_pp_job *job)
        MALI_DEBUG_ASSERT_POINTER(session);
 
        if (NULL != job->memory_cookies) {
-#if defined(CONFIG_DMA_SHARED_BUFFER) && !defined(CONFIG_MALI_DMA_BUF_MAP_ON_ATTACH)
+#if defined(CONFIG_DMA_SHARED_BUFFER) && !defined(CONFIG_MALI_DMA_BUF_LAZY_MAP)
+               if (job)
+                       session = job->session;
+               for (i = 0; job && session && i < job->uargs.num_memory_cookies; i++) {
+                       mali_mem_backend *mem_backend = NULL;
+                       u32 mali_addr  = mali_pp_job_get_memory_cookie(job, i);
+
+                       mem_backend = __mali_mem_backend_struct_search(session, mali_addr);
+                       if (mem_backend &&
+                               (mem_backend->flags & MALI_MEM_BACKEND_FLAG_VIDEO_LAZY_MAP)) {
+                               have_video = 1;
+                               break;
+                       } else
+                               have_video = 0;
+               }
                /* Unmap buffers attached to job */
-               mali_dma_buf_unmap_job(job);
+               if (have_video)
 #endif
+                       mali_dma_buf_unmap_job(job);
+
                if (MALI_NO_SWAP_IN != job->swap_status) {
                        mali_mem_swap_out_pages(job);
                }
old mode 100755 (executable)
new mode 100644 (file)
index 0ebd138..fe4ab29
@@ -22,7 +22,7 @@
 #include "mali_timeline.h"
 #include "mali_scheduler.h"
 #include "mali_executor.h"
-#if defined(CONFIG_DMA_SHARED_BUFFER) && !defined(CONFIG_MALI_DMA_BUF_MAP_ON_ATTACH)
+#if defined(CONFIG_DMA_SHARED_BUFFER)
 #include "linux/mali_memory_dma_buf.h"
 #endif
 #if defined(CONFIG_MALI_DMA_BUF_FENCE)
old mode 100755 (executable)
new mode 100644 (file)
index 5410f86..629b1dd
@@ -43,7 +43,7 @@
  * if in atomic context, since both might sleep.
  */
 #if defined(CONFIG_DMA_SHARED_BUFFER)
-#if !defined(CONFIG_MALI_DMA_BUF_MAP_ON_ATTACH)
+#if 1//!defined(CONFIG_MALI_DMA_BUF_MAP_ON_ATTACH)
 #define MALI_SCHEDULER_USE_DEFERRED_PP_JOB_QUEUE 1
 #endif
 #endif
@@ -513,6 +513,10 @@ mali_scheduler_mask mali_scheduler_activate_gp_job(struct mali_gp_job *job)
 
 mali_scheduler_mask mali_scheduler_activate_pp_job(struct mali_pp_job *job)
 {
+#if defined(MALI_SCHEDULER_USE_DEFERRED_PP_JOB_QUEUE)
+       u32 i, have_video;
+       struct mali_session_data *session;
+#endif
        MALI_DEBUG_ASSERT_POINTER(job);
 
        MALI_DEBUG_PRINT(4, ("Mali PP scheduler: Timeline activation for job %u (0x%08X).\n",
@@ -537,7 +541,24 @@ mali_scheduler_mask mali_scheduler_activate_pp_job(struct mali_pp_job *job)
        }
 
 #if defined(MALI_SCHEDULER_USE_DEFERRED_PP_JOB_QUEUE)
-       if (mali_pp_job_needs_dma_buf_mapping(job)) {
+       if (job)
+               session = job->session;
+       for (i = 0; job && session && i < job->uargs.num_memory_cookies; i++) {
+               mali_mem_backend *mem_backend = NULL;
+               u32 mali_addr  = mali_pp_job_get_memory_cookie(job, i);
+
+               mem_backend = __mali_mem_backend_struct_search(session, mali_addr);
+               if (mem_backend &&
+                       (mem_backend->flags & MALI_MEM_BACKEND_FLAG_VIDEO_LAZY_MAP)) {
+                       have_video = 1;
+                       break;
+               } else
+                       have_video = 0;
+       }
+#if defined(CONFIG_MALI_DMA_BUF_LAZY_MAP)
+       have_video = 1;
+#endif
+       if (have_video && mali_pp_job_needs_dma_buf_mapping(job)) {
                mali_scheduler_deferred_pp_job_queue(job);
                return MALI_SCHEDULER_MASK_EMPTY;
        }
old mode 100755 (executable)
new mode 100644 (file)
index dc0dfa1..fd989b7
@@ -859,7 +859,7 @@ typedef struct {
 
 /** Flag for _mali_uk_map_external_mem_s, _mali_uk_attach_ump_mem_s and _mali_uk_attach_dma_buf_s */
 #define _MALI_MAP_EXTERNAL_MAP_GUARD_PAGE (1<<0)
-
+#define _MALI_MAP_VIDEO_LAYER (1<<31)
 
 typedef struct {
        u64 ctx;                                /**< [in,out] user-kernel context (trashed on output) */
old mode 100755 (executable)
new mode 100644 (file)
index d4f79ae..beff5f8
@@ -68,10 +68,12 @@ static int mali_dma_buf_map(mali_mem_backend *mem_backend)
        mem->map_ref++;
 
        MALI_DEBUG_PRINT(5, ("Mali DMA-buf: map attachment %p, new map_ref = %d\n", mem, mem->map_ref));
+       MALI_DEBUG_PRINT(5, ("Mali DMA-buf: is_mapped %d, new map_ref = %d\n", mem->is_mapped, mem_backend->flags));
 #if (!defined(CONFIG_MALI_DMA_BUF_MAP_ON_ATTACH)) && (defined(CONFIG_MALI_DMA_BUF_LAZY_MAP))
        if (MALI_FALSE == mem->is_mapped)
 #else
-       if (1 == mem->map_ref)
+       if (1 == mem->map_ref || (MALI_FALSE == mem->is_mapped &&
+               mem_backend->flags & MALI_MEM_BACKEND_FLAG_VIDEO_LAZY_MAP))
 #endif
        {
                /* First reference taken, so we need to map the dma buf */
@@ -150,7 +152,7 @@ static void mali_dma_buf_unmap(mali_mem_allocation *alloc, struct mali_dma_buf_a
        mem->map_ref--;
 
        MALI_DEBUG_PRINT(5, ("Mali DMA-buf: unmap attachment %p, new map_ref = %d\n", mem, mem->map_ref));
-
+       MALI_DEBUG_PRINT(5, ("Mali DMA-buf: unmap is_mapped %d\n", mem->is_mapped));
        if (0 == mem->map_ref) {
                if (NULL != mem->sgt) {
                        dma_buf_unmap_attachment(mem->attachment, mem->sgt, DMA_BIDIRECTIONAL);
@@ -169,7 +171,7 @@ static void mali_dma_buf_unmap(mali_mem_allocation *alloc, struct mali_dma_buf_a
        mali_session_memory_unlock(alloc->session);
 }
 
-#if !defined(CONFIG_MALI_DMA_BUF_MAP_ON_ATTACH)
+#if 1//!defined(CONFIG_MALI_DMA_BUF_MAP_ON_ATTACH)
 int mali_dma_buf_map_job(struct mali_pp_job *job)
 {
        struct mali_dma_buf_attachment *mem;
@@ -329,6 +331,8 @@ _mali_osk_errcode_t mali_mem_bind_dma_buf(mali_mem_allocation *alloc,
 #else
        dma_mem->map_ref = 0;
 #endif
+       if (flags & _MALI_MAP_VIDEO_LAYER)
+               dma_mem->map_ref = 1;
        init_waitqueue_head(&dma_mem->wait_queue);
 
        dma_mem->attachment = dma_buf_attach(dma_mem->buf, &mali_platform_device->dev);
@@ -343,10 +347,10 @@ _mali_osk_errcode_t mali_mem_bind_dma_buf(mali_mem_allocation *alloc,
                alloc->flags |= MALI_MEM_FLAG_MALI_GUARD_PAGE;
        }
 
-
 #if defined(CONFIG_MALI_DMA_BUF_MAP_ON_ATTACH)
        /* Map memory into session's Mali virtual address space. */
-       if (0 != mali_dma_buf_map(mem_backend)) {
+       if (!(flags & _MALI_MAP_VIDEO_LAYER) &&
+               (0 != mali_dma_buf_map(mem_backend))) {
                goto Failed_dma_map;
        }
 #endif
@@ -417,20 +421,22 @@ _mali_osk_errcode_t meson_update_video_texture(struct  mali_session_data *sessio
 
        attachment = dma_buf_attach(buf, &mali_platform_device->dev);
        if (NULL == attachment) {
+               MALI_DEBUG_PRINT_ERROR(("Failed to attach dma-buf\n"));
                ret = _MALI_OSK_ERR_FAULT;
                goto failed_dma_attach;
        }
 
        sgt = dma_buf_map_attachment(attachment, DMA_BIDIRECTIONAL);
        if (IS_ERR_OR_NULL(sgt)) {
-               MALI_DEBUG_PRINT_ERROR(("Failed to map dma-buf attachment\n"));
+               MALI_DEBUG_PRINT_ERROR(("Failed to dma-buf-map attachment\n"));
                ret = _MALI_OSK_ERR_FAULT;
-               return -EFAULT;
+               goto failed_dma_map;
        }
 
        dma_buf_unmap_attachment(attachment, sgt, DMA_BIDIRECTIONAL);
        sgt = NULL;
 
+failed_dma_map:
        dma_buf_detach(buf, attachment);
 failed_dma_attach:
        dma_buf_put(buf);
old mode 100755 (executable)
new mode 100644 (file)
index 4110ef6..03c14de
@@ -42,7 +42,7 @@ _mali_osk_errcode_t mali_mem_bind_dma_buf(mali_mem_allocation *alloc,
                mali_mem_backend *mem_backend,
                int fd, u32 flags);
 
-#if !defined(CONFIG_MALI_DMA_BUF_MAP_ON_ATTACH)
+#if 1//!defined(CONFIG_MALI_DMA_BUF_MAP_ON_ATTACH)
 int mali_dma_buf_map_job(struct mali_pp_job *job);
 void mali_dma_buf_unmap_job(struct mali_pp_job *job);
 #endif
index 621ff153e928251fd1d5eb3951728b1246f7b12e..7da24947ea89d3d85ef1bcff87774d91c05ef339 100644 (file)
@@ -210,6 +210,26 @@ mali_mem_backend *mali_mem_backend_struct_search(struct mali_session_data *sessi
        return mem_bkend;
 }
 
+mali_mem_backend *__mali_mem_backend_struct_search(struct mali_session_data *session, u32 mali_address)
+{
+       struct mali_vma_node *mali_vma_node = NULL;
+       mali_mem_backend *mem_bkend = NULL;
+       mali_mem_allocation *mali_alloc = NULL;
+       MALI_DEBUG_ASSERT_POINTER(session);
+       mali_vma_node = __mali_vma_offset_search(&session->allocation_mgr, mali_address, 0);
+       if (NULL == mali_vma_node)  {
+               MALI_DEBUG_PRINT(1, ("mali_mem_backend_struct_search:vma node was NULL\n"));
+               return NULL;
+       }
+       mali_alloc = container_of(mali_vma_node, struct mali_mem_allocation, mali_vma_node);
+       /* Get backend memory & Map on CPU */
+       //mutex_lock(&mali_idr_mutex);
+       mem_bkend = idr_find(&mali_backend_idr, mali_alloc->backend_handle);
+       //mutex_unlock(&mali_idr_mutex);
+       MALI_DEBUG_ASSERT(NULL != mem_bkend);
+       return mem_bkend;
+}
+
 static _mali_osk_errcode_t mali_mem_resize(struct mali_session_data *session, mali_mem_backend *mem_backend, u32 physical_size)
 {
        _mali_osk_errcode_t ret = _MALI_OSK_ERR_FAULT;
@@ -717,6 +737,10 @@ _mali_osk_errcode_t _mali_ukk_mem_bind(_mali_uk_bind_mem_s *args)
 #if defined(CONFIG_DMA_SHARED_BUFFER)
                mali_allocation->type = MALI_MEM_DMA_BUF;
                mem_backend->type = MALI_MEM_DMA_BUF;
+               MALI_DEBUG_PRINT(3, (" _mali_ukk_mem_bind, bind_dma_buf.flags=0x%x, size=0x%x \n",
+                       args->mem_union.bind_dma_buf.flags, args->size));
+               if (args->mem_union.bind_dma_buf.flags & _MALI_MAP_VIDEO_LAYER)
+                       mem_backend->flags |= MALI_MEM_BACKEND_FLAG_VIDEO_LAZY_MAP;
                ret = mali_mem_bind_dma_buf(mali_allocation, mem_backend,
                                            args->mem_union.bind_dma_buf.mem_fd, args->mem_union.bind_dma_buf.flags);
                if (_MALI_OSK_ERR_OK != ret) {
index dd535aa48fd6eace1acccd9af79ee98b2ea4af89..98f99ea805cc5cae6fde3ea8166b5589dcc9e456 100644 (file)
@@ -39,6 +39,7 @@ void  mali_mem_allocation_struct_destory(mali_mem_allocation *alloc);
 
 _mali_osk_errcode_t mali_mem_add_mem_size(struct mali_session_data *session, u32 mali_addr, u32 add_size);
 mali_mem_backend *mali_mem_backend_struct_search(struct mali_session_data *session, u32 mali_address);
+mali_mem_backend *__mali_mem_backend_struct_search(struct mali_session_data *session, u32 mali_address);
 _mali_osk_errcode_t _mali_ukk_mem_allocate(_mali_uk_alloc_mem_s *args);
 _mali_osk_errcode_t _mali_ukk_mem_free(_mali_uk_free_mem_s *args);
 _mali_osk_errcode_t _mali_ukk_mem_bind(_mali_uk_bind_mem_s *args);
old mode 100755 (executable)
new mode 100644 (file)
index 60cd9f4..483eaa1
@@ -188,6 +188,7 @@ typedef struct mali_mem_secure {
 #define MALI_MEM_BACKEND_FLAG_UNSWAPPED_IN            (0x8)
 #define MALI_MEM_BACKEND_FLAG_NOT_BINDED              (0x1 << 5) /* this backend it not back with physical memory, used for defer bind */
 #define MALI_MEM_BACKEND_FLAG_BINDED              (0x1 << 6) /* this backend it back with physical memory, used for defer bind */
+#define MALI_MEM_BACKEND_FLAG_VIDEO_LAZY_MAP      (0x1 << 7) /* this backend it back with physical memory, used for video layer lazy map */
 
 typedef struct mali_mem_backend {
        mali_mem_type type;                /**< Type of backend memory */
index a217e43632ce4bf746643f11aec0216219bf9d6a..2b0cc7c14bdaabfea6b7f5c157f7839493ad5c64 100644 (file)
@@ -125,3 +125,37 @@ struct mali_vma_node *mali_vma_offset_search(struct mali_allocation_manager *mgr
        return best;
 }
 
+/* copy from mali_vma_offset_search, delete the lock operation */
+struct mali_vma_node *__mali_vma_offset_search(struct mali_allocation_manager *mgr,
+               unsigned long start, unsigned long pages)
+{
+       struct mali_vma_node *node, *best;
+       struct rb_node *iter;
+       unsigned long offset;
+       //read_lock(&mgr->vm_lock);
+
+       iter = mgr->allocation_mgr_rb.rb_node;
+       best = NULL;
+
+       while (likely(iter)) {
+               node = rb_entry(iter, struct mali_vma_node, vm_rb);
+               offset = node->vm_node.start;
+               if (start >= offset) {
+                       iter = iter->rb_right;
+                       best = node;
+                       if (start == offset)
+                               break;
+               } else {
+                       iter = iter->rb_left;
+               }
+       }
+
+       if (best) {
+               offset = best->vm_node.start + best->vm_node.size;
+               if (offset <= start + pages)
+                       best = NULL;
+       }
+       //read_unlock(&mgr->vm_lock);
+
+       return best;
+}
index 2a70cbb9ce23a7f6dac1df70c0b3e0b89d460cb7..2a12918839719348bd1ba38d01033bbc63fa6bf7 100644 (file)
@@ -31,5 +31,6 @@ void mali_vma_offset_remove(struct mali_allocation_manager *mgr,
 
 struct mali_vma_node *mali_vma_offset_search(struct mali_allocation_manager *mgr,
                unsigned long start,    unsigned long pages);
-
+struct mali_vma_node *__mali_vma_offset_search(struct mali_allocation_manager *mgr,
+               unsigned long start,    unsigned long pages);
 #endif