]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ENGR00212489-1 viv_GPU: add reserved memory account handler.
authorZhang Jiejing <jiejing.zhang@freescale.com>
Wed, 6 Jun 2012 02:07:21 +0000 (10:07 +0800)
committerLothar Waßmann <LW@KARO-electronics.de>
Fri, 24 May 2013 06:34:46 +0000 (08:34 +0200)
the original low memory killer only take care of system memory accounting,
but for so large shared memory occupy by GPU, and each process memory
killer account become unfair, very large 3D game will not killed firstly
if it going to background.

Add this account to let real large memory user get killed if going to background
eg, the "angry bird Space" will acquire 68,215,360 GPU memory for 1-6 toll-gate.

The test show it can quicker recovery from memory shortage situation,
since it's very like to be killed after add so much GPU memory for such 3D game.

Signed-off-by: Zhang Jiejing <jiejing.zhang@freescale.com>
drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_driver.c

index c5ce248e77ba94ccfee7dfad2f774fdb765acaa9..1786d09ba87871320f52c292c496a7cddef1a66d 100644 (file)
 #endif
 
 
+#ifdef CONFIG_ANDROID_RESERVED_MEMORY_ACCOUNT
+#    include <linux/resmem_account.h>
+#endif
+
+
 /* Zone used for header/footer. */
 #define _GC_OBJ_ZONE    gcvZONE_DRIVER
 
@@ -140,6 +145,30 @@ static struct file_operations driver_fops =
     .mmap       = drv_mmap,
 };
 
+#ifdef CONFIG_ANDROID_RESERVED_MEMORY_ACCOUNT
+static size_t viv_gpu_resmem_query(struct task_struct *p, struct reserved_memory_account *m);
+static struct reserved_memory_account viv_gpu_resmem_handler = {
+    .name = "viv_gpu",
+    .get_page_used_by_process = viv_gpu_resmem_query,
+};
+
+size_t viv_gpu_resmem_query(struct task_struct *p, struct reserved_memory_account *m)
+{
+    gcuDATABASE_INFO info;
+    unsigned int processid = p->pid;
+    gckKERNEL gpukernel = m->data;
+
+    /* ignore error happens in this api. */
+    if (gckKERNEL_QueryProcessDB(gpukernel, processid, false, gcvDB_VIDEO_MEMORY, &info) != gcvSTATUS_OK)
+       return 0;
+
+    /* we return pages. */
+    if (info.counters.bytes > 0)
+       return info.counters.bytes / PAGE_SIZE;
+    return 0;
+}
+#endif
+
 int drv_open(
     struct inode* inode,
     struct file* filp
@@ -766,6 +795,12 @@ static int drv_init(void)
         device->baseAddress = 0;
     }
 
+#ifdef CONFIG_ANDROID_RESERVED_MEMORY_ACCOUNT
+    viv_gpu_resmem_handler.data = device->kernels[gcvCORE_MAJOR];
+    register_reserved_memory_account(&viv_gpu_resmem_handler);
+#endif
+
+
     /* Register the character device. */
     ret = register_chrdev(major, DRV_NAME, &driver_fops);
 
@@ -845,6 +880,10 @@ static void drv_exit(void)
 {
     gcmkHEADER();
 
+#ifdef CONFIG_ANDROID_RESERVED_MEMORY_ACCOUNT
+    unregister_reserved_memory_account(&viv_gpu_resmem_handler);
+#endif
+
     gcmkASSERT(gpuClass != gcvNULL);
     device_destroy(gpuClass, MKDEV(major, 0));
     class_destroy(gpuClass);