Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4468736b authored by Ruofei Ma's avatar Ruofei Ma Committed by Gerrit - the friendly Code Review server
Browse files

msm: cvp: Move kmem_cache to cvp driver struct



Allocation and free kmem_cache struct for each session has performance
impact. Move it to cvp driver struct for all sessions to share.

Change-Id: Ib00bf5fa1ac7e6ed097e4893a45512dfea0e3202
Signed-off-by: default avatarRuofei Ma <ruofeim@codeaurora.org>
parent d93d9d09
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -496,7 +496,7 @@ static int hfi_process_session_cvp_msg(u32 device_id,
					inst->deprecate_bitmask);
	}

	sess_msg = kmem_cache_alloc(inst->session_queue.msg_cache, GFP_KERNEL);
	sess_msg = kmem_cache_alloc(cvp_driver->msg_cache, GFP_KERNEL);
	if (sess_msg == NULL) {
		dprintk(CVP_ERR, "%s runs out msg cache memory\n", __func__);
		return -ENOMEM;
@@ -526,7 +526,7 @@ static int hfi_process_session_cvp_msg(u32 device_id,

error_handle_msg:
	spin_unlock(&inst->session_queue.lock);
	kmem_cache_free(inst->session_queue.msg_cache, sess_msg);
	kmem_cache_free(cvp_driver->msg_cache, sess_msg);
	return -ENOMEM;
}

+26 −24
Original line number Diff line number Diff line
@@ -184,7 +184,7 @@ static int msm_cvp_map_buf_dsp(struct msm_cvp_inst *inst,
		return -EINVAL;
	}

	cbuf = kmem_cache_zalloc(inst->internal_buf_cache, GFP_KERNEL);
	cbuf = kmem_cache_zalloc(cvp_driver->internal_buf_cache, GFP_KERNEL);
	if (!cbuf) {
		return -ENOMEM;
	}
@@ -228,7 +228,7 @@ static int msm_cvp_map_buf_dsp(struct msm_cvp_inst *inst,
exit:
	if (cbuf->smem.device_addr)
		msm_cvp_smem_unmap_dma_buf(inst, &cbuf->smem);
	kmem_cache_free(inst->internal_buf_cache, cbuf);
	kmem_cache_free(cvp_driver->internal_buf_cache, cbuf);
	cbuf = NULL;

	return rc;
@@ -286,7 +286,7 @@ static int msm_cvp_unmap_buf_dsp(struct msm_cvp_inst *inst,
	list_del(&cbuf->list);
	mutex_unlock(&inst->cvpdspbufs.lock);

	kmem_cache_free(inst->internal_buf_cache, cbuf);
	kmem_cache_free(cvp_driver->internal_buf_cache, cbuf);
	return rc;
}

@@ -318,7 +318,7 @@ static int msm_cvp_map_buf_cpu_d(struct msm_cvp_inst *inst,
		return -EINVAL;
	}

	cbuf = kmem_cache_zalloc(inst->internal_buf_cache, GFP_KERNEL);
	cbuf = kmem_cache_zalloc(cvp_driver->internal_buf_cache, GFP_KERNEL);
	if (!cbuf)
		return -ENOMEM;

@@ -348,7 +348,7 @@ static int msm_cvp_map_buf_cpu_d(struct msm_cvp_inst *inst,
exit:
	if (cbuf->smem.device_addr)
		msm_cvp_smem_unmap_dma_buf(inst, &cbuf->smem);
	kmem_cache_free(inst->internal_buf_cache, cbuf);
	kmem_cache_free(cvp_driver->internal_buf_cache, cbuf);
	cbuf = NULL;

	return rc;
@@ -477,7 +477,7 @@ static int msm_cvp_map_buf_cpu(struct msm_cvp_inst *inst,
	if (!rc && *iova != 0)
		return 0;

	cbuf = kmem_cache_zalloc(inst->internal_buf_cache, GFP_KERNEL);
	cbuf = kmem_cache_zalloc(cvp_driver->internal_buf_cache, GFP_KERNEL);
	if (!cbuf)
		return -ENOMEM;

@@ -511,7 +511,7 @@ static int msm_cvp_map_buf_cpu(struct msm_cvp_inst *inst,

	*iova = cbuf->smem.device_addr + cbuf->buf.offset;

	frame_buf = kmem_cache_zalloc(inst->frame_buf_cache, GFP_KERNEL);
	frame_buf = kmem_cache_zalloc(cvp_driver->frame_buf_cache, GFP_KERNEL);
	if (!frame_buf) {
		rc = -ENOMEM;
		goto exit2;
@@ -533,7 +533,7 @@ static int msm_cvp_map_buf_cpu(struct msm_cvp_inst *inst,
	list_del(&cbuf->list);
	mutex_unlock(&inst->cvpcpubufs.lock);
exit:
	kmem_cache_free(inst->internal_buf_cache, cbuf);
	kmem_cache_free(cvp_driver->internal_buf_cache, cbuf);
	cbuf = NULL;

	return rc;
@@ -559,7 +559,7 @@ static void __unmap_buf(struct msm_cvp_inst *inst,
			list_del(&cbuf->list);
			print_internal_buffer(CVP_DBG, "unmap", inst, cbuf);
			msm_cvp_smem_unmap_dma_buf(inst, &cbuf->smem);
			kmem_cache_free(inst->internal_buf_cache, cbuf);
			kmem_cache_free(cvp_driver->internal_buf_cache, cbuf);
			break;
		}
	}
@@ -589,12 +589,12 @@ void msm_cvp_unmap_buf_cpu(struct msm_cvp_inst *inst, u64 ktid)
						&frame->bufs.list, list) {
				list_del(&frame_buf->list);
				__unmap_buf(inst, frame_buf);
				kmem_cache_free(inst->frame_buf_cache,
				kmem_cache_free(cvp_driver->frame_buf_cache,
						frame_buf);
			}
			mutex_unlock(&frame->bufs.lock);
			DEINIT_MSM_CVP_LIST(&frame->bufs);
			kmem_cache_free(inst->frame_cache, frame);
			kmem_cache_free(cvp_driver->frame_cache, frame);
			break;
		}
	}
@@ -695,7 +695,7 @@ static int msm_cvp_session_receive_hfi(struct msm_cvp_inst *inst,

		memcpy(out_pkt, &msg->pkt,
			sizeof(struct cvp_hfi_msg_session_hdr));
		kmem_cache_free(inst->session_queue.msg_cache, msg);
		kmem_cache_free(cvp_driver->msg_cache, msg);
	}

exit:
@@ -778,7 +778,7 @@ static int msm_cvp_map_buf(struct msm_cvp_inst *inst,
		cmd_hdr->client_data.kdata1 = (u32)ktid;
		cmd_hdr->client_data.kdata2 = (u32)(ktid >> 32);

		frame = kmem_cache_zalloc(inst->frame_cache, GFP_KERNEL);
		frame = kmem_cache_zalloc(cvp_driver->frame_cache, GFP_KERNEL);
		if (!frame)
			return -ENOMEM;

@@ -833,11 +833,11 @@ static int msm_cvp_map_buf(struct msm_cvp_inst *inst,
					list_del(&frame_buf->list);
					__unmap_buf(inst, frame_buf);
					kmem_cache_free(
					inst->frame_buf_cache,
					cvp_driver->frame_buf_cache,
					frame_buf);
				}
				DEINIT_MSM_CVP_LIST(&frame->bufs);
				kmem_cache_free(inst->frame_cache,
				kmem_cache_free(cvp_driver->frame_cache,
						frame);
				return rc;
			}
@@ -1323,7 +1323,7 @@ static int msm_cvp_thread_fence_run(void *data)
	}

exit:
	kmem_cache_free(inst->fence_data_cache, fence_thread_data);
	kmem_cache_free(cvp_driver->fence_data_cache, fence_thread_data);
	inst->cur_cmd_type = 0;
	cvp_put_inst(inst);
	do_exit(rc);
@@ -1355,7 +1355,7 @@ static int msm_cvp_session_process_hfi_fence(
		return -ECONNRESET;

	inst->cur_cmd_type = CVP_KMD_SEND_FENCE_CMD_PKT;
	fence_thread_data = kmem_cache_alloc(inst->fence_data_cache,
	fence_thread_data = kmem_cache_alloc(cvp_driver->fence_data_cache,
			GFP_KERNEL);
	if (!fence_thread_data) {
		dprintk(CVP_ERR, "%s: fence_thread_data alloc failed\n",
@@ -1388,7 +1388,7 @@ static int msm_cvp_session_process_hfi_fence(

	rc = msm_cvp_map_buf(inst, in_pkt, offset, buf_num);
	if (rc)
		goto exit;
		goto free_and_exit;

	thread_num = thread_num + 1;
	fence_thread_data->inst = inst;
@@ -1401,14 +1401,15 @@ static int msm_cvp_session_process_hfi_fence(
	thread = kthread_run(msm_cvp_thread_fence_run,
			fence_thread_data, thread_fence_name);
	if (!thread) {
		kmem_cache_free(inst->fence_data_cache, fence_thread_data);
		dprintk(CVP_ERR, "%s fail to create kthread\n", __func__);
		rc = -ECHILD;
		goto exit;
		goto free_and_exit;
	}

	return 0;

free_and_exit:
	kmem_cache_free(cvp_driver->fence_data_cache, fence_thread_data);
exit:
	inst->cur_cmd_type = 0;
	cvp_put_inst(s);
@@ -2275,7 +2276,7 @@ int msm_cvp_session_deinit(struct msm_cvp_inst *inst)
									cbuf);
		msm_cvp_smem_unmap_dma_buf(inst, &cbuf->smem);
		list_del(&cbuf->list);
		kmem_cache_free(inst->internal_buf_cache, cbuf);
		kmem_cache_free(cvp_driver->internal_buf_cache, cbuf);
	}
	mutex_unlock(&inst->cvpcpubufs.lock);

@@ -2295,7 +2296,7 @@ int msm_cvp_session_deinit(struct msm_cvp_inst *inst)

		msm_cvp_smem_unmap_dma_buf(inst, &cbuf->smem);
		list_del(&cbuf->list);
		kmem_cache_free(inst->internal_buf_cache, cbuf);
		kmem_cache_free(cvp_driver->internal_buf_cache, cbuf);
	}
	mutex_unlock(&inst->cvpdspbufs.lock);

@@ -2315,11 +2316,12 @@ int msm_cvp_session_deinit(struct msm_cvp_inst *inst)
				buf->dbuf->name);

			list_del(&frame_buf->list);
			kmem_cache_free(inst->frame_buf_cache, frame_buf);
			kmem_cache_free(cvp_driver->frame_buf_cache,
					frame_buf);
		}
		mutex_unlock(&frame->bufs.lock);
		DEINIT_MSM_CVP_LIST(&frame->bufs);
		kmem_cache_free(inst->frame_cache, frame);
		kmem_cache_free(cvp_driver->frame_cache, frame);
	}
	mutex_unlock(&inst->frames.lock);

+1 −22
Original line number Diff line number Diff line
@@ -226,11 +226,6 @@ static int _init_session_queue(struct msm_cvp_inst *inst)
	INIT_LIST_HEAD(&inst->session_queue.msgs);
	inst->session_queue.msg_count = 0;
	init_waitqueue_head(&inst->session_queue.wq);
	inst->session_queue.msg_cache = KMEM_CACHE(cvp_session_msg, 0);
	if (!inst->session_queue.msg_cache) {
		dprintk(CVP_ERR, "Failed to allocate msg quque\n");
		return -ENOMEM;
	}
	inst->session_queue.state = QUEUE_ACTIVE;
	return 0;
}
@@ -243,15 +238,13 @@ static void _deinit_session_queue(struct msm_cvp_inst *inst)
	spin_lock(&inst->session_queue.lock);
	list_for_each_entry_safe(msg, tmpmsg, &inst->session_queue.msgs, node) {
		list_del_init(&msg->node);
		kmem_cache_free(inst->session_queue.msg_cache, msg);
		kmem_cache_free(cvp_driver->msg_cache, msg);
	}
	inst->session_queue.msg_count = 0;
	inst->session_queue.state = QUEUE_STOP;
	spin_unlock(&inst->session_queue.lock);

	wake_up_all(&inst->session_queue.wq);

	kmem_cache_destroy(inst->session_queue.msg_cache);
}

void *msm_cvp_open(int core_id, int session_type)
@@ -318,10 +311,6 @@ void *msm_cvp_open(int core_id, int session_type)
	inst->clk_data.bitrate = 0;
	inst->clk_data.core_id = 0;
	inst->deprecate_bitmask = 0;
	inst->fence_data_cache = KMEM_CACHE(msm_cvp_fence_thread_data, 0);
	inst->frame_cache = KMEM_CACHE(msm_cvp_frame, 0);
	inst->frame_buf_cache = KMEM_CACHE(msm_cvp_frame_buf, 0);
	inst->internal_buf_cache = KMEM_CACHE(msm_cvp_internal_buffer, 0);

	for (i = SESSION_MSG_INDEX(SESSION_MSG_START);
		i <= SESSION_MSG_INDEX(SESSION_MSG_END); i++) {
@@ -362,11 +351,6 @@ void *msm_cvp_open(int core_id, int session_type)
	DEINIT_MSM_CVP_LIST(&inst->cvpdspbufs);
	DEINIT_MSM_CVP_LIST(&inst->frames);

	kmem_cache_destroy(inst->fence_data_cache);
	kmem_cache_destroy(inst->frame_cache);
	kmem_cache_destroy(inst->frame_buf_cache);
	kmem_cache_destroy(inst->internal_buf_cache);

	kfree(inst);
	inst = NULL;
err_invalid_core:
@@ -407,11 +391,6 @@ int msm_cvp_destroy(struct msm_cvp_inst *inst)
	DEINIT_MSM_CVP_LIST(&inst->cvpdspbufs);
	DEINIT_MSM_CVP_LIST(&inst->frames);

	kmem_cache_destroy(inst->fence_data_cache);
	kmem_cache_destroy(inst->frame_cache);
	kmem_cache_destroy(inst->frame_buf_cache);
	kmem_cache_destroy(inst->internal_buf_cache);

	mutex_destroy(&inst->sync_lock);
	mutex_destroy(&inst->lock);

+5 −5
Original line number Diff line number Diff line
@@ -161,6 +161,11 @@ struct msm_cvp_drv {
	struct dentry *debugfs_root;
	int thermal_level;
	u32 sku_version;
	struct kmem_cache *msg_cache;
	struct kmem_cache *fence_data_cache;
	struct kmem_cache *frame_cache;
	struct kmem_cache *frame_buf_cache;
	struct kmem_cache *internal_buf_cache;
};

enum profiling_points {
@@ -250,7 +255,6 @@ struct cvp_session_queue {
	unsigned int msg_count;
	struct list_head msgs;
	wait_queue_head_t wq;
	struct kmem_cache *msg_cache;
};

struct cvp_session_prop {
@@ -343,11 +347,7 @@ struct msm_cvp_inst {
	unsigned long deprecate_bitmask;
	struct cvp_kmd_request_power power;
	struct cvp_session_prop prop;
	struct kmem_cache *fence_data_cache;
	u32 cur_cmd_type;
	struct kmem_cache *frame_cache;
	struct kmem_cache *frame_buf_cache;
	struct kmem_cache *internal_buf_cache;
};

struct msm_cvp_fence_thread_data {
+14 −0
Original line number Diff line number Diff line
@@ -570,13 +570,27 @@ static int __init msm_cvp_init(void)
		debugfs_remove_recursive(cvp_driver->debugfs_root);
		kfree(cvp_driver);
		cvp_driver = NULL;
		return rc;
	}

	cvp_driver->msg_cache = KMEM_CACHE(cvp_session_msg, 0);
	cvp_driver->fence_data_cache = KMEM_CACHE(msm_cvp_fence_thread_data, 0);
	cvp_driver->frame_cache = KMEM_CACHE(msm_cvp_frame, 0);
	cvp_driver->frame_buf_cache = KMEM_CACHE(msm_cvp_frame_buf, 0);
	cvp_driver->internal_buf_cache = KMEM_CACHE(msm_cvp_internal_buffer, 0);

	return rc;
}

static void __exit msm_cvp_exit(void)
{

	kmem_cache_destroy(cvp_driver->msg_cache);
	kmem_cache_destroy(cvp_driver->fence_data_cache);
	kmem_cache_destroy(cvp_driver->frame_cache);
	kmem_cache_destroy(cvp_driver->frame_buf_cache);
	kmem_cache_destroy(cvp_driver->internal_buf_cache);

	platform_driver_unregister(&msm_cvp_driver);
	debugfs_remove_recursive(cvp_driver->debugfs_root);
	mutex_destroy(&cvp_driver->lock);