diff options
author | Loren Huang <b02279@freescale.com> | 2014-07-03 17:54:04 +0800 |
---|---|---|
committer | Loren Huang <b02279@freescale.com> | 2014-07-03 19:43:42 +0800 |
commit | 0d83d7e87d8d16a097c3c8bec6fa6ac25da225be (patch) | |
tree | 49c3a16fbea8497b38f760786c254768da9efd8b | |
parent | 5af041902b4f5045d5e186a31108d945efd3acbc (diff) |
ENGR00311027 gpu:Limit the memory consumption for webgl
-When system memory is less than 200M, we will block further
memory allocation for webgl.
It's for pass webgl 1.0.2 conformance case conformance/rendering/multisample-cor
ruption.html
It's a temperory patch from vivante, should be removed in 5.0.11p2.
Original patch name:5x_crash_patch.diff
Date: Jul 03, 2014
Signed-off-by: Loren Huang <b02279@freescale.com>
Acked-by: Shawn Guo
5 files changed, 44 insertions, 10 deletions
diff --git a/drivers/mxc/gpu-viv/hal/kernel/gc_hal_kernel.c b/drivers/mxc/gpu-viv/hal/kernel/gc_hal_kernel.c index b9703525df65..d24a08b285b1 100644 --- a/drivers/mxc/gpu-viv/hal/kernel/gc_hal_kernel.c +++ b/drivers/mxc/gpu-viv/hal/kernel/gc_hal_kernel.c @@ -692,6 +692,8 @@ gckKERNEL_AllocateLinearMemory( gctSIZE_T bytes = Bytes; gctUINT32 handle = 0; gceDATABASE_TYPE type; + gctBOOL memlimit = gcvFALSE; + gcmkHEADER_ARG("Kernel=0x%x *Pool=%d Bytes=%lu Alignment=%lu Type=%d", Kernel, *Pool, Bytes, Alignment, Type); @@ -705,7 +707,7 @@ gckKERNEL_AllocateLinearMemory( /* Check flags. */ contiguous = Flag & gcvALLOC_FLAG_CONTIGUOUS; cacheable = Flag & gcvALLOC_FLAG_CACHEABLE; - + memlimit = Flag & gcvALLOC_FLAG_MEMLIMIT; AllocateMemory: /* Get initial pool. */ @@ -747,7 +749,7 @@ AllocateMemory: { /* Create a gcuVIDMEM_NODE for virtual memory. */ gcmkONERROR( - gckVIDMEM_ConstructVirtual(Kernel, gcvFALSE, Bytes, gcvTRUE, &node)); + gckVIDMEM_ConstructVirtual(Kernel, ( memlimit ? (gcvFALSE + gcvALLOC_FLAG_MEMLIMIT):gcvFALSE), Bytes, gcvTRUE, &node)); bytes = node->Virtual.bytes; node->Virtual.type = Type; @@ -768,7 +770,7 @@ AllocateMemory: #endif { /* Create a gcuVIDMEM_NODE from contiguous memory. */ - status = gckVIDMEM_ConstructVirtual(Kernel, gcvTRUE, Bytes, cacheable, &node); + status = gckVIDMEM_ConstructVirtual(Kernel, ( memlimit ? (gcvTRUE + gcvALLOC_FLAG_MEMLIMIT):gcvTRUE), Bytes, cacheable, &node); } if (gcmIS_SUCCESS(status)) @@ -925,6 +927,12 @@ OnError: gcmkVERIFY_OK(gckVIDMEM_Free(Kernel, node)); } + /* For some case like chrome with webgl test, it needs too much memory so that it invokes oom_killer + * And the case is killed by oom_killer, the user wants not to see the crash and hope the case iteself handles the condition + * So the patch reports the out_of_memory to the case */ + if (status == gcvSTATUS_OUT_OF_MEMORY) + gcmkPRINT("OUT of memory\n"); + /* Return the status. */ gcmkFOOTER(); return status; diff --git a/drivers/mxc/gpu-viv/hal/kernel/gc_hal_kernel_video_memory.c b/drivers/mxc/gpu-viv/hal/kernel/gc_hal_kernel_video_memory.c index 35e9fc21451c..41f335e54c7a 100644 --- a/drivers/mxc/gpu-viv/hal/kernel/gc_hal_kernel_video_memory.c +++ b/drivers/mxc/gpu-viv/hal/kernel/gc_hal_kernel_video_memory.c @@ -219,6 +219,7 @@ gckVIDMEM_ConstructVirtual( gcuVIDMEM_NODE_PTR node = gcvNULL; gctPOINTER pointer = gcvNULL; gctINT i; + gctBOOL tempContiguous = Contiguous; gcmkHEADER_ARG("Kernel=0x%x Contiguous=%d Bytes=%lu", Kernel, Contiguous, Bytes); @@ -236,9 +237,15 @@ gckVIDMEM_ConstructVirtual( node = pointer; + if ( Contiguous == (gcvFALSE + gcvALLOC_FLAG_MEMLIMIT) + || Contiguous == (gcvTRUE + gcvALLOC_FLAG_MEMLIMIT)) + { + tempContiguous = Contiguous - gcvALLOC_FLAG_MEMLIMIT; + } + /* Initialize gcuVIDMEM_NODE union for virtual memory. */ node->Virtual.kernel = Kernel; - node->Virtual.contiguous = Contiguous; + node->Virtual.contiguous = tempContiguous; node->Virtual.logical = gcvNULL; node->Virtual.cacheable = cacheable; #if gcdENABLE_VG @@ -280,7 +287,7 @@ gckVIDMEM_ConstructVirtual( { gcmkONERROR( gckOS_AllocatePagedMemoryEx(os, - node->Virtual.contiguous, + Contiguous, node->Virtual.bytes = Bytes, &node->Virtual.physical)); } diff --git a/drivers/mxc/gpu-viv/hal/kernel/inc/gc_hal_enum.h b/drivers/mxc/gpu-viv/hal/kernel/inc/gc_hal_enum.h index 1de132150fd4..5b7ed41d90be 100644 --- a/drivers/mxc/gpu-viv/hal/kernel/inc/gc_hal_enum.h +++ b/drivers/mxc/gpu-viv/hal/kernel/inc/gc_hal_enum.h @@ -1489,7 +1489,7 @@ gceHAL_ARG_VERSION; #define gcvALLOC_FLAG_CONTIGUOUS (1 << 0) #define gcvALLOC_FLAG_CACHEABLE (1 << 1) #define gcvALLOC_FLAG_SECURITY (1 << 2) - +#define gcvALLOC_FLAG_MEMLIMIT (1<<3) /* GL_VIV internal usage */ #ifndef GL_MAP_BUFFER_OBJ_VIV #define GL_MAP_BUFFER_OBJ_VIV 0x10000 diff --git a/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_allocator.c b/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_allocator.c index 9a29e73ca485..9e04c05c908c 100644 --- a/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_allocator.c +++ b/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_allocator.c @@ -226,6 +226,7 @@ _UnmapUserLogical( /***************************************************************************\ ************************ Default Allocator ********************************** \***************************************************************************/ +#define C_MAX_PAGENUM (50*1024) static gceSTATUS _DefaultAlloc( @@ -245,12 +246,22 @@ _DefaultAlloc( gctUINT i = 0; gctBOOL contiguous = Flags & gcvALLOC_FLAG_CONTIGUOUS; + struct sysinfo temsysinfo; + gcmkHEADER_ARG("Mdl=%p NumPages=%d", Mdl, NumPages); numPages = NumPages; bytes = NumPages * PAGE_SIZE; order = get_order(bytes); - + si_meminfo(&temsysinfo); + if ((Flags & gcvALLOC_FLAG_MEMLIMIT)) + { + if ( (temsysinfo.freeram < NumPages) || ((temsysinfo.freeram-NumPages) < C_MAX_PAGENUM) ) + { + gcmkONERROR(gcvSTATUS_OUT_OF_MEMORY); + } + } + if (contiguous) { if (order >= MAX_ORDER) @@ -284,7 +295,7 @@ _DefaultAlloc( } else { - Mdl->u.nonContiguousPages = _NonContiguousAlloc(numPages); + Mdl->u.nonContiguousPages = _NonContiguousAlloc(numPages); } if (Mdl->u.contiguousPages == gcvNULL && Mdl->u.nonContiguousPages == gcvNULL) diff --git a/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_os.c b/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_os.c index 9de9a7a0fadf..9184e9bbd43a 100644 --- a/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_os.c +++ b/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_os.c @@ -4113,6 +4113,7 @@ gckOS_AllocatePagedMemoryEx( gceSTATUS status = gcvSTATUS_OUT_OF_MEMORY; gckALLOCATOR allocator; gctUINT32 flag = 0; + gctBOOL tempContiguous = Contiguous; gcmkHEADER_ARG("Os=0x%X Contiguous=%d Bytes=%lu", Os, Contiguous, Bytes); @@ -4131,8 +4132,15 @@ gckOS_AllocatePagedMemoryEx( gcmkONERROR(gcvSTATUS_OUT_OF_MEMORY); } - if (Contiguous) + if ( (Contiguous == gcvFALSE + gcvALLOC_FLAG_MEMLIMIT) + || (Contiguous == gcvTRUE + gcvALLOC_FLAG_MEMLIMIT)) { + tempContiguous = Contiguous - gcvALLOC_FLAG_MEMLIMIT; + flag |= gcvALLOC_FLAG_MEMLIMIT; + } + + if (tempContiguous) + { flag |= gcvALLOC_FLAG_CONTIGUOUS; } @@ -4158,7 +4166,7 @@ gckOS_AllocatePagedMemoryEx( mdl->addr = 0; mdl->numPages = numPages; mdl->pagedMem = 1; - mdl->contiguous = Contiguous; + mdl->contiguous = tempContiguous; mdl->cacheable=gcvTRUE; #if DYNAMIC_MEMORY_RECORD |