瀏覽代碼

msm: eva: Add process name for debugging

Also fix a persistbuf optimization problem that failed
multi-loop DMM test.

Change-Id: Ib197077a708dea99967f0a9f4ed1c09d12023edc
Signed-off-by: George Shen <[email protected]>
George Shen 3 年之前
父節點
當前提交
1cb056362c
共有 8 個文件被更改,包括 79 次插入44 次删除
  1. 3 3
      msm/eva/cvp.c
  2. 1 1
      msm/eva/cvp_smem.c
  3. 38 11
      msm/eva/msm_cvp_buf.c
  4. 2 2
      msm/eva/msm_cvp_common.c
  5. 12 9
      msm/eva/msm_cvp_core.c
  6. 2 1
      msm/eva/msm_cvp_core.h
  7. 19 17
      msm/eva/msm_cvp_dsp.c
  8. 2 0
      msm/eva/msm_cvp_internal.h

+ 3 - 3
msm/eva/cvp.c

@@ -41,7 +41,7 @@ static int cvp_open(struct inode *inode, struct file *filp)
 
 
 	dprintk(CVP_SESS, "%s: core->id: %d\n", __func__, core->id);
 	dprintk(CVP_SESS, "%s: core->id: %d\n", __func__, core->id);
 
 
-	inst = msm_cvp_open(core->id, MSM_CVP_USER);
+	inst = msm_cvp_open(core->id, MSM_CVP_USER, current);
 	if (!inst) {
 	if (!inst) {
 		dprintk(CVP_ERR, "Failed to create cvp instance\n");
 		dprintk(CVP_ERR, "Failed to create cvp instance\n");
 		return -ENOMEM;
 		return -ENOMEM;
@@ -266,7 +266,7 @@ static ssize_t boot_store(struct device *dev,
 	if (val > 0 && booted == 0) {
 	if (val > 0 && booted == 0) {
 		struct msm_cvp_inst *inst;
 		struct msm_cvp_inst *inst;
 
 
-		inst = msm_cvp_open(MSM_CORE_CVP, MSM_CVP_BOOT);
+		inst = msm_cvp_open(MSM_CORE_CVP, MSM_CVP_BOOT, current);
 		if (!inst) {
 		if (!inst) {
 			dprintk(CVP_ERR,
 			dprintk(CVP_ERR,
 			"Failed to create cvp instance\n");
 			"Failed to create cvp instance\n");
@@ -281,7 +281,7 @@ static ssize_t boot_store(struct device *dev,
 	} else if ((val == 2) && booted) {
 	} else if ((val == 2) && booted) {
 		struct msm_cvp_inst *inst;
 		struct msm_cvp_inst *inst;
 
 
-		inst = msm_cvp_open(MSM_CORE_CVP, MSM_CVP_USER);
+		inst = msm_cvp_open(MSM_CORE_CVP, MSM_CVP_USER, current);
 		if (!inst) {
 		if (!inst) {
 			dprintk(CVP_ERR,
 			dprintk(CVP_ERR,
 			"Failed to create eva instance\n");
 			"Failed to create eva instance\n");

+ 1 - 1
msm/eva/cvp_smem.c

@@ -104,8 +104,8 @@ static int msm_dma_get_device_address(struct dma_buf *dbuf, u32 align,
 
 
 		table = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
 		table = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL);
 		if (IS_ERR_OR_NULL(table)) {
 		if (IS_ERR_OR_NULL(table)) {
+			dprintk(CVP_ERR, "Failed to map table %d\n", PTR_ERR(table));
 			rc = PTR_ERR(table) ?: -ENOMEM;
 			rc = PTR_ERR(table) ?: -ENOMEM;
-			dprintk(CVP_ERR, "Failed to map table\n");
 			goto mem_map_table_failed;
 			goto mem_map_table_failed;
 		}
 		}
 
 

+ 38 - 11
msm/eva/msm_cvp_buf.c

@@ -63,8 +63,8 @@ int print_smem(u32 tag, const char *str, struct msm_cvp_inst *inst,
 			}
 			}
 
 
 		dprintk(tag,
 		dprintk(tag,
-			"%s: %x : %s size %d flags %#x iova %#x idx %d ref %d pkt_type %s buf_idx %#x",
-			str, hash32_ptr(inst->session), smem->dma_buf->name,
+			"%s: %x : %pK size %d flags %#x iova %#x idx %d ref %d pkt_type %s buf_idx %#x",
+			str, hash32_ptr(inst->session), smem->dma_buf,
 			smem->size, smem->flags, smem->device_addr,
 			smem->size, smem->flags, smem->device_addr,
 			smem->bitmap_index, atomic_read(&smem->refcount),
 			smem->bitmap_index, atomic_read(&smem->refcount),
 			name, smem->buf_idx);
 			name, smem->buf_idx);
@@ -80,9 +80,9 @@ static void print_internal_buffer(u32 tag, const char *str,
 
 
 	if (cbuf->smem->dma_buf) {
 	if (cbuf->smem->dma_buf) {
 		dprintk(tag,
 		dprintk(tag,
-		"%s: %x : fd %d off %d %s size %d iova %#x",
+		"%s: %x : fd %d off %d %pK size %d iova %#x",
 		str, hash32_ptr(inst->session), cbuf->fd,
 		str, hash32_ptr(inst->session), cbuf->fd,
-		cbuf->offset, cbuf->smem->dma_buf->name, cbuf->size,
+		cbuf->offset, cbuf->smem->dma_buf, cbuf->size,
 		cbuf->smem->device_addr);
 		cbuf->smem->device_addr);
 	} else {
 	} else {
 		dprintk(tag,
 		dprintk(tag,
@@ -1233,6 +1233,7 @@ static u32 msm_cvp_map_user_persist_buf(struct msm_cvp_inst *inst,
 {
 {
 	u32 iova = 0;
 	u32 iova = 0;
 	struct msm_cvp_smem *smem = NULL;
 	struct msm_cvp_smem *smem = NULL;
+	struct list_head *ptr, *next;
 	struct cvp_internal_buf *pbuf;
 	struct cvp_internal_buf *pbuf;
 
 
 	if (!inst) {
 	if (!inst) {
@@ -1240,9 +1241,26 @@ static u32 msm_cvp_map_user_persist_buf(struct msm_cvp_inst *inst,
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
 
 
+	mutex_lock(&inst->persistbufs.lock);
+	list_for_each_safe(ptr, next, &inst->persistbufs.list) {
+		pbuf = list_entry(ptr, struct cvp_internal_buf, list);
+		if (buf->fd == pbuf->fd) {
+			pbuf->size =
+				(pbuf->size >= buf->size) ?
+				pbuf->size : buf->size;
+			iova = pbuf->smem->device_addr + buf->offset;
+			mutex_unlock(&inst->persistbufs.lock);
+			return iova;
+		}
+	}
+	mutex_unlock(&inst->persistbufs.lock);
+
 	pbuf = kmem_cache_zalloc(cvp_driver->buf_cache, GFP_KERNEL);
 	pbuf = kmem_cache_zalloc(cvp_driver->buf_cache, GFP_KERNEL);
-	if (!pbuf)
+	if (!pbuf) {
+		dprintk(CVP_ERR, "%s failed to allocate kmem obj\n",
+			__func__);
 		return 0;
 		return 0;
+	}
 
 
 	smem = msm_cvp_session_get_smem(inst, buf, true);
 	smem = msm_cvp_session_get_smem(inst, buf, true);
 	if (!smem)
 	if (!smem)
@@ -1251,6 +1269,7 @@ static u32 msm_cvp_map_user_persist_buf(struct msm_cvp_inst *inst,
 	smem->flags |= SMEM_PERSIST;
 	smem->flags |= SMEM_PERSIST;
 	smem->pkt_type = pkt_type;
 	smem->pkt_type = pkt_type;
 	smem->buf_idx = buf_idx;
 	smem->buf_idx = buf_idx;
+	atomic_inc(&smem->refcount);
 	pbuf->smem = smem;
 	pbuf->smem = smem;
 	pbuf->fd = buf->fd;
 	pbuf->fd = buf->fd;
 	pbuf->size = buf->size;
 	pbuf->size = buf->size;
@@ -1657,6 +1676,7 @@ struct cvp_internal_buf *cvp_allocate_arp_bufs(struct msm_cvp_inst *inst,
 	buf->smem->pkt_type = buf->smem->buf_idx = 0;
 	buf->smem->pkt_type = buf->smem->buf_idx = 0;
 
 
 	buf->smem->pkt_type = buf->smem->buf_idx = 0;
 	buf->smem->pkt_type = buf->smem->buf_idx = 0;
+	atomic_inc(&buf->smem->refcount);
 	buf->size = buf->smem->size;
 	buf->size = buf->smem->size;
 	buf->type = HFI_BUFFER_INTERNAL_PERSIST_1;
 	buf->type = HFI_BUFFER_INTERNAL_PERSIST_1;
 	buf->ownership = DRIVER;
 	buf->ownership = DRIVER;
@@ -1729,14 +1749,21 @@ int cvp_release_arp_buffers(struct msm_cvp_inst *inst)
 
 
 		list_del(&buf->list);
 		list_del(&buf->list);
 
 
-		if (buf->ownership == DRIVER) {
+		if (buf->ownership == DRIVER)
 			dprintk(CVP_MEM,
 			dprintk(CVP_MEM,
-			"%s: %x : fd %d %s size %d",
+			"%s: %x : fd %d %pK size %d",
 			"free arp", hash32_ptr(inst->session), buf->fd,
 			"free arp", hash32_ptr(inst->session), buf->fd,
-			smem->dma_buf->name, buf->size);
-			msm_cvp_smem_free(smem);
-			kmem_cache_free(cvp_driver->smem_cache, smem);
-		}
+			smem->dma_buf, buf->size);
+		else
+			dprintk(CVP_MEM,
+			"%s: %x : fd %d %pK size %d",
+			"free user persistent", hash32_ptr(inst->session), buf->fd,
+			smem->dma_buf, buf->size);
+
+		atomic_dec(&smem->refcount);
+		msm_cvp_smem_free(smem);
+		kmem_cache_free(cvp_driver->smem_cache, smem);
+
 		buf->smem = NULL;
 		buf->smem = NULL;
 		kmem_cache_free(cvp_driver->buf_cache, buf);
 		kmem_cache_free(cvp_driver->buf_cache, buf);
 	}
 	}

+ 2 - 2
msm/eva/msm_cvp_common.c

@@ -1560,8 +1560,8 @@ int cvp_print_inst(u32 tag, struct msm_cvp_inst *inst)
 		return -EINVAL;
 		return -EINVAL;
 	}
 	}
 
 
-	dprintk(tag, "inst %pK id = %#x type %#x prio %#x secure %#x kmask %#x dmask %#x, kref %#x state %#x\n",
-		inst, hash32_ptr(inst->session),
+	dprintk(tag, "%s inst stype %d %pK id = %#x ptype %#x prio %#x secure %#x kmask %#x dmask %#x, kref %#x state %#x\n",
+		inst->proc_name, inst->session_type, inst, hash32_ptr(inst->session),
 		inst->prop.type, inst->prop.priority, inst->prop.is_secure,
 		inst->prop.type, inst->prop.priority, inst->prop.is_secure,
 		inst, inst->prop.kernel_mask, inst->prop.dsp_mask,
 		inst, inst->prop.kernel_mask, inst->prop.dsp_mask,
 		kref_read(&inst->kref), inst->state);
 		kref_read(&inst->kref), inst->state);

+ 12 - 9
msm/eva/msm_cvp_core.c

@@ -124,7 +124,7 @@ static void __deinit_session_queue(struct msm_cvp_inst *inst)
 	wake_up_all(&inst->session_queue.wq);
 	wake_up_all(&inst->session_queue.wq);
 }
 }
 
 
-void *msm_cvp_open(int core_id, int session_type)
+void *msm_cvp_open(int core_id, int session_type, struct task_struct *task)
 {
 {
 	struct msm_cvp_inst *inst = NULL;
 	struct msm_cvp_inst *inst = NULL;
 	struct msm_cvp_core *core = NULL;
 	struct msm_cvp_core *core = NULL;
@@ -167,9 +167,9 @@ void *msm_cvp_open(int core_id, int session_type)
 		goto err_invalid_core;
 		goto err_invalid_core;
 	}
 	}
 
 
-	pr_info_ratelimited(
-		CVP_DBG_TAG "Opening cvp instance: %pK type %d\n",
-		"sess", inst, session_type);
+	pr_info(
+		CVP_DBG_TAG "%s opening cvp instance: %pK type %d\n",
+		"sess", task->comm, inst, session_type);
 	mutex_init(&inst->sync_lock);
 	mutex_init(&inst->sync_lock);
 	mutex_init(&inst->lock);
 	mutex_init(&inst->lock);
 	spin_lock_init(&inst->event_handler.lock);
 	spin_lock_init(&inst->event_handler.lock);
@@ -225,6 +225,7 @@ void *msm_cvp_open(int core_id, int session_type)
 
 
 	inst->debugfs_root =
 	inst->debugfs_root =
 		msm_cvp_debugfs_init_inst(inst, core->debugfs_root);
 		msm_cvp_debugfs_init_inst(inst, core->debugfs_root);
+	strlcpy(inst->proc_name, task->comm, TASK_COMM_LEN);
 
 
 	return inst;
 	return inst;
 fail_init:
 fail_init:
@@ -305,7 +306,7 @@ wait_dsp:
 			(inst->core->resources.msm_cvp_hw_rsp_timeout >> 5)
 			(inst->core->resources.msm_cvp_hw_rsp_timeout >> 5)
 			- max_retries);
 			- max_retries);
 	max_retries =  inst->core->resources.msm_cvp_hw_rsp_timeout >> 1;
 	max_retries =  inst->core->resources.msm_cvp_hw_rsp_timeout >> 1;
-wait:
+wait_frame:
 	mutex_lock(&inst->frames.lock);
 	mutex_lock(&inst->frames.lock);
 	empty = list_empty(&inst->frames.list);
 	empty = list_empty(&inst->frames.list);
 	if (!empty && max_retries > 0) {
 	if (!empty && max_retries > 0) {
@@ -314,7 +315,7 @@ wait:
 		msm_cvp_clean_sess_queue(inst, sqf);
 		msm_cvp_clean_sess_queue(inst, sqf);
 		msm_cvp_clean_sess_queue(inst, sq);
 		msm_cvp_clean_sess_queue(inst, sq);
 		max_retries--;
 		max_retries--;
-		goto wait;
+		goto wait_frame;
 	}
 	}
 	mutex_unlock(&inst->frames.lock);
 	mutex_unlock(&inst->frames.lock);
 
 
@@ -385,9 +386,11 @@ int msm_cvp_destroy(struct msm_cvp_inst *inst)
 	__deinit_fence_queue(inst);
 	__deinit_fence_queue(inst);
 	core->synx_ftbl->cvp_sess_deinit_synx(inst);
 	core->synx_ftbl->cvp_sess_deinit_synx(inst);
 
 
-	pr_info_ratelimited(
-		CVP_DBG_TAG "Closed cvp instance: %pK session_id = %d type %d\n",
-		"sess", inst, hash32_ptr(inst->session), inst->session_type);
+	pr_info(
+		CVP_DBG_TAG
+		"%s closed cvp instance: %pK session_id = %d type %d\n",
+		"sess", inst->proc_name, inst, hash32_ptr(inst->session),
+		inst->session_type);
 	inst->session = (void *)0xdeadbeef;
 	inst->session = (void *)0xdeadbeef;
 	kfree(inst);
 	kfree(inst);
 	return 0;
 	return 0;

+ 2 - 1
msm/eva/msm_cvp_core.h

@@ -7,6 +7,7 @@
 #define _MSM_CVP_CORE_H_
 #define _MSM_CVP_CORE_H_
 
 
 #include <linux/poll.h>
 #include <linux/poll.h>
+#include <linux/sched.h>
 #include <linux/types.h>
 #include <linux/types.h>
 #include <linux/dma-buf.h>
 #include <linux/dma-buf.h>
 #include <linux/refcount.h>
 #include <linux/refcount.h>
@@ -33,7 +34,7 @@ enum session_type {
 	MSM_CVP_MAX_DEVICES = MSM_CVP_UNKNOWN,
 	MSM_CVP_MAX_DEVICES = MSM_CVP_UNKNOWN,
 };
 };
 
 
-void *msm_cvp_open(int core_id, int session_type);
+void *msm_cvp_open(int core_id, int session_type, struct task_struct *task);
 int msm_cvp_close(void *instance);
 int msm_cvp_close(void *instance);
 int msm_cvp_suspend(int core_id);
 int msm_cvp_suspend(int core_id);
 int msm_cvp_poll(void *instance, struct file *filp,
 int msm_cvp_poll(void *instance, struct file *filp,

+ 19 - 17
msm/eva/msm_cvp_dsp.c

@@ -1372,14 +1372,31 @@ static void __dsp_cvp_sess_create(struct cvp_dsp_cmd_msg *cmd)
 		dsp2cpu_cmd->is_secure,
 		dsp2cpu_cmd->is_secure,
 		dsp2cpu_cmd->pid);
 		dsp2cpu_cmd->pid);
 
 
+	pid_s = find_get_pid(dsp2cpu_cmd->pid);
+	if (pid_s == NULL) {
+		dprintk(CVP_WARN, "%s incorrect pid\n", __func__);
+		cmd->ret = -1;
+		return;
+	}
+	dprintk(CVP_DSP, "%s get pid_s 0x%x from pidA 0x%x\n", __func__,
+			pid_s, dsp2cpu_cmd->pid);
+
+	task = get_pid_task(pid_s, PIDTYPE_TGID);
+	if (!task) {
+		dprintk(CVP_WARN, "%s task doesn't exist\n", __func__);
+		cmd->ret = -1;
+		return;
+	}
+
 	rc = eva_fastrpc_driver_register(dsp2cpu_cmd->pid);
 	rc = eva_fastrpc_driver_register(dsp2cpu_cmd->pid);
 	if (rc) {
 	if (rc) {
 		dprintk(CVP_ERR, "%s Register fastrpc driver fail\n", __func__);
 		dprintk(CVP_ERR, "%s Register fastrpc driver fail\n", __func__);
+		put_task_struct(task);
 		cmd->ret = -1;
 		cmd->ret = -1;
 		return;
 		return;
 	}
 	}
 
 
-	inst = msm_cvp_open(MSM_CORE_CVP, MSM_CVP_DSP);
+	inst = msm_cvp_open(MSM_CORE_CVP, MSM_CVP_DSP, task);
 	if (!inst) {
 	if (!inst) {
 		dprintk(CVP_ERR, "%s Failed create instance\n", __func__);
 		dprintk(CVP_ERR, "%s Failed create instance\n", __func__);
 		goto fail_msm_cvp_open;
 		goto fail_msm_cvp_open;
@@ -1415,20 +1432,6 @@ static void __dsp_cvp_sess_create(struct cvp_dsp_cmd_msg *cmd)
 	if (frpc_node)
 	if (frpc_node)
 		eva_fastrpc_driver_add_sess(frpc_node, inst);
 		eva_fastrpc_driver_add_sess(frpc_node, inst);
 
 
-	pid_s = find_get_pid(inst->process_id);
-	if (pid_s == NULL) {
-		dprintk(CVP_WARN, "%s incorrect pid\n", __func__);
-		goto fail_get_pid;
-	}
-	dprintk(CVP_DSP, "%s get pid_s 0x%x from pidA 0x%x\n", __func__,
-			pid_s, inst->process_id);
-
-	task = get_pid_task(pid_s, PIDTYPE_TGID);
-	if (!task) {
-		dprintk(CVP_WARN, "%s task doesn't exist\n", __func__);
-		goto fail_get_task;
-	}
-
 	inst->task = task;
 	inst->task = task;
 	dprintk(CVP_DSP,
 	dprintk(CVP_DSP,
 		"%s CREATE_SESS id 0x%x, cpu_low 0x%x, cpu_high 0x%x\n",
 		"%s CREATE_SESS id 0x%x, cpu_low 0x%x, cpu_high 0x%x\n",
@@ -1443,14 +1446,13 @@ static void __dsp_cvp_sess_create(struct cvp_dsp_cmd_msg *cmd)
 
 
 	return;
 	return;
 
 
-fail_get_pid:
-fail_get_task:
 fail_get_session_info:
 fail_get_session_info:
 fail_session_create:
 fail_session_create:
 	msm_cvp_close(inst);
 	msm_cvp_close(inst);
 fail_msm_cvp_open:
 fail_msm_cvp_open:
 	/* unregister fastrpc driver */
 	/* unregister fastrpc driver */
 	eva_fastrpc_driver_unregister(dsp2cpu_cmd->pid, false);
 	eva_fastrpc_driver_unregister(dsp2cpu_cmd->pid, false);
+	put_task_struct(task);
 	cmd->ret = -1;
 	cmd->ret = -1;
 }
 }
 
 

+ 2 - 0
msm/eva/msm_cvp_internal.h

@@ -7,6 +7,7 @@
 #define _MSM_CVP_INTERNAL_H_
 #define _MSM_CVP_INTERNAL_H_
 
 
 #include <linux/atomic.h>
 #include <linux/atomic.h>
+#include <linux/sched.h>
 #include <linux/list.h>
 #include <linux/list.h>
 #include <linux/time.h>
 #include <linux/time.h>
 #include <linux/types.h>
 #include <linux/types.h>
@@ -412,6 +413,7 @@ struct msm_cvp_inst {
 	u32 prev_error_code;
 	u32 prev_error_code;
 	struct synx_session synx_session_id;
 	struct synx_session synx_session_id;
 	struct cvp_fence_queue fence_cmd_queue;
 	struct cvp_fence_queue fence_cmd_queue;
+	char proc_name[TASK_COMM_LEN];
 };
 };
 
 
 extern struct msm_cvp_drv *cvp_driver;
 extern struct msm_cvp_drv *cvp_driver;