From c9b3772b5e0370dfc5d14672e79e8fd8dd2b7f3b Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Tue, 14 Aug 2018 14:17:05 +0300 Subject: [PATCH] eventlib: unify NVDLA/PVA fence types and add fence recording Bug 2170736 Change-Id: If4fdeda140bf2474a08beb2a0d7c3fc1737a1a66 Signed-off-by: Dmitry Antipov Reviewed-on: https://git-master.nvidia.com/r/1750906 Reviewed-by: Saleh Dindar GVS: Gerrit_Virtual_Submit Reviewed-by: Colin Tracey Reviewed-by: Prashant Gaikwad Reviewed-by: mobile promotions Tested-by: mobile promotions --- drivers/video/tegra/host/nvdla/nvdla.h | 7 +- drivers/video/tegra/host/nvdla/nvdla_ioctl.c | 51 +++++------ drivers/video/tegra/host/nvdla/nvdla_queue.c | 91 +++++++++++--------- 3 files changed, 80 insertions(+), 69 deletions(-) diff --git a/drivers/video/tegra/host/nvdla/nvdla.h b/drivers/video/tegra/host/nvdla/nvdla.h index eabe6a91..85e22b05 100644 --- a/drivers/video/tegra/host/nvdla/nvdla.h +++ b/drivers/video/tegra/host/nvdla/nvdla.h @@ -23,6 +23,7 @@ #include #include +#include #include #include "nvhost_buffer.h" @@ -226,7 +227,7 @@ struct nvdla_device { struct nvdla_emu_task { struct nvhost_queue *queue; struct nvhost_syncpt *sp; - struct nvdla_fence postfences[MAX_NUM_NVDLA_POSTFENCES]; + struct nvdev_fence postfences[MAX_NUM_NVDLA_POSTFENCES]; u32 num_postfences; u32 fence; u32 fence_counter; @@ -254,8 +255,8 @@ struct nvdla_task { struct nvhost_queue *queue; struct nvhost_buffers *buffers; struct nvhost_syncpt *sp; - struct nvdla_fence prefences[MAX_NUM_NVDLA_PREFENCES]; - struct nvdla_fence postfences[MAX_NUM_NVDLA_POSTFENCES]; + struct nvdev_fence prefences[MAX_NUM_NVDLA_PREFENCES]; + struct nvdev_fence postfences[MAX_NUM_NVDLA_POSTFENCES]; struct nvdla_status_notify in_task_status[MAX_NUM_NVDLA_IN_TASK_STATUS]; struct nvdla_status_notify out_task_status[MAX_NUM_NVDLA_OUT_TASK_STATUS]; struct nvdla_mem_handle memory_handles[NVDLA_MAX_BUFFERS_PER_TASK]; diff --git a/drivers/video/tegra/host/nvdla/nvdla_ioctl.c b/drivers/video/tegra/host/nvdla/nvdla_ioctl.c index 90306b57..efd68b3d 100644 --- a/drivers/video/tegra/host/nvdla/nvdla_ioctl.c +++ b/drivers/video/tegra/host/nvdla/nvdla_ioctl.c @@ -34,6 +34,7 @@ #include "nvdla/nvdla.h" #include "nvdla/nvdla_debug.h" +#include #include #include "dla_os_interface.h" @@ -126,11 +127,11 @@ static int nvdla_get_q_status(struct nvdla_private *priv, void *args) { struct nvdla_get_q_status_args *queue_arg = (struct nvdla_get_q_status_args *)args; - struct nvdla_fence __user *usr_fence = - (struct nvdla_fence __user *)(uintptr_t)queue_arg->fence; + struct nvdev_fence __user *usr_fence = + (struct nvdev_fence __user *)(uintptr_t)queue_arg->fence; struct platform_device *pdev = priv->pdev; struct nvhost_queue *queue = priv->queue; - struct nvdla_fence fence = {0}; + struct nvdev_fence fence = {0}; int err = 0; nvdla_dbg_fn(pdev, ""); @@ -146,7 +147,7 @@ static int nvdla_get_q_status(struct nvdla_private *priv, void *args) queue->syncpt_id); nvdla_dbg_info(pdev, "syncpt_id[%u] val[%u]\n", fence.syncpoint_index, fence.syncpoint_value); - if (copy_to_user(usr_fence, &fence, sizeof(struct nvdla_fence))) { + if (copy_to_user(usr_fence, &fence, sizeof(struct nvdev_fence))) { err = -EFAULT; nvdla_dbg_err(pdev, "failed to send fence"); goto fail_to_send_fence; @@ -347,7 +348,7 @@ static int nvdla_get_actions(struct nvdla_ioctl_submit_task *user_task, /* get pre fences */ if (copy_from_user(task->prefences, (void __user *)user_task->prefences, - (task->num_prefences * sizeof(struct nvdla_fence)))) { + (task->num_prefences * sizeof(struct nvdev_fence)))) { err = -EFAULT; nvdla_dbg_err(pdev, "failed to copy prefences"); goto fail; @@ -366,7 +367,7 @@ static int nvdla_get_actions(struct nvdla_ioctl_submit_task *user_task, /* get post fences */ if (copy_from_user(task->postfences, (void __user *)user_task->postfences, - (task->num_postfences * sizeof(struct nvdla_fence)))) { + (task->num_postfences * sizeof(struct nvdev_fence)))) { err = -EFAULT; nvdla_dbg_err(pdev, "failed to copy postfences"); goto fail; @@ -395,14 +396,14 @@ static int nvdla_send_emu_postfences(struct nvdla_emu_task *task, struct platform_device *dla_pdev = task->queue->pool->pdev; struct platform_device *host_pdev = to_platform_device(dla_pdev->dev.parent); - struct nvdla_fence __user *postfences = - (struct nvdla_fence __user *)(uintptr_t)user_task->postfences; + struct nvdev_fence __user *postfences = + (struct nvdev_fence __user *)(uintptr_t)user_task->postfences; char fence_name[32]; nvdla_dbg_fn(dla_pdev, "sending post fences"); for (i = 0; i < task->num_postfences; i++) { - if (task->postfences[i].type == NVDLA_FENCE_TYPE_SYNC_FD) { + if (task->postfences[i].type == NVDEV_FENCE_TYPE_SYNC_FD) { struct nvhost_ctrl_sync_fence_info info; info.id = task->postfences[i].syncpoint_index; @@ -432,7 +433,7 @@ static int nvdla_send_emu_postfences(struct nvdla_emu_task *task, nvdla_dbg_fn(dla_pdev, "copy postfences to user"); /* send post fences */ if (copy_to_user(postfences, task->postfences, - (task->num_postfences * sizeof(struct nvdla_fence)))) { + (task->num_postfences * sizeof(struct nvdev_fence)))) { err = -EFAULT; nvdla_dbg_err(dla_pdev, "failed to send postfences"); goto fail; @@ -450,14 +451,14 @@ static int nvdla_update_postfences(struct nvdla_task *task, struct platform_device *dla_pdev = task->queue->pool->pdev; struct platform_device *host_pdev = to_platform_device(dla_pdev->dev.parent); - struct nvdla_fence __user *postfences = - (struct nvdla_fence __user *)(uintptr_t)user_task->postfences; + struct nvdev_fence __user *postfences = + (struct nvdev_fence __user *)(uintptr_t)user_task->postfences; char fence_name[32]; nvdla_dbg_fn(dla_pdev, "copy post fences for user"); for (i = 0; i < task->num_postfences; i++) { - if (task->postfences[i].type == NVDLA_FENCE_TYPE_SYNC_FD) { + if (task->postfences[i].type == NVDEV_FENCE_TYPE_SYNC_FD) { struct nvhost_ctrl_sync_fence_info info; info.id = task->postfences[i].syncpoint_index; @@ -487,7 +488,7 @@ static int nvdla_update_postfences(struct nvdla_task *task, nvdla_dbg_fn(dla_pdev, "copy postfences to user"); /* copy post fences */ if (copy_to_user(postfences, task->postfences, - (task->num_postfences * sizeof(struct nvdla_fence)))) { + (task->num_postfences * sizeof(struct nvdev_fence)))) { err = -EFAULT; nvdla_dbg_err(dla_pdev, "failed to copy postfences"); goto fail; @@ -618,28 +619,28 @@ static void nvdla_dump_task(struct nvdla_task *task) for (i = 0; i < task->num_prefences; i++) { nvdla_dbg_info(pdev, "prefence[%d]: type[%u] syncpt_index[%u]" - " syncpt_val[%u] sync_fd[%u] sem_handle[%u]" - " sem_offset[%u] sem_val[%u]", + " syncpt_val[%u] sync_fd[%u] semaphore_handle[%u]" + " semaphore_offset[%u] semaphore_value[%u]", i, task->prefences[i].type, task->prefences[i].syncpoint_index, task->prefences[i].syncpoint_value, task->prefences[i].sync_fd, - task->prefences[i].sem_handle, - task->prefences[i].sem_offset, - task->prefences[i].sem_val); + task->prefences[i].semaphore_handle, + task->prefences[i].semaphore_offset, + task->prefences[i].semaphore_value); } for (i = 0; i < task->num_postfences; i++) { nvdla_dbg_info(pdev, "postfence[%d]: type[%u] syncpt_index[%u]" - " syncpt_val[%u] sync_fd[%u] sem_handle[%u]" - " sem_offset[%u] sem_val[%u]", + " syncpt_val[%u] sync_fd[%u] semaphore_handle[%u]" + " semaphore_offset[%u] semaphore_value[%u]", i, task->postfences[i].type, task->postfences[i].syncpoint_index, task->postfences[i].syncpoint_value, task->postfences[i].sync_fd, - task->postfences[i].sem_handle, - task->postfences[i].sem_offset, - task->postfences[i].sem_val); + task->postfences[i].semaphore_handle, + task->postfences[i].semaphore_offset, + task->postfences[i].semaphore_value); } for (i = 0; i < task->num_in_task_status; i++) { @@ -719,7 +720,7 @@ static int nvdla_emu_task_submit(struct nvdla_private *priv, void *arg) /* get post fences */ if (copy_from_user(task.postfences, (void __user *)local_tasks[i].postfences, - (task.num_postfences * sizeof(struct nvdla_fence)))) { + (task.num_postfences * sizeof(struct nvdev_fence)))) { err = -EFAULT; nvdla_dbg_err(pdev, "failed to copy postfences"); goto exit; diff --git a/drivers/video/tegra/host/nvdla/nvdla_queue.c b/drivers/video/tegra/host/nvdla/nvdla_queue.c index 6b54de02..8e173944 100644 --- a/drivers/video/tegra/host/nvdla/nvdla_queue.c +++ b/drivers/video/tegra/host/nvdla/nvdla_queue.c @@ -177,9 +177,9 @@ static int nvdla_unmap_task_memory(struct nvdla_task *task) /* unpin prefences memory */ for (ii = 0; ii < task->num_prefences; ii++) { - if ((task->prefences[ii].type == NVDLA_FENCE_TYPE_SEMAPHORE || - task->prefences[ii].type == NVDLA_FENCE_TYPE_TS_SEMAPHORE) && - task->prefences[ii].sem_handle) { + if ((task->prefences[ii].type == NVDEV_FENCE_TYPE_SEMAPHORE || + task->prefences[ii].type == NVDEV_FENCE_TYPE_SEMAPHORE_TS) && + task->prefences[ii].semaphore_handle) { nvhost_buffer_submit_unpin(task->buffers, &task->prefences_sem_dmabuf[ii], 1); dma_buf_put(task->prefences_sem_dmabuf[ii]); @@ -199,9 +199,9 @@ static int nvdla_unmap_task_memory(struct nvdla_task *task) /* unpin postfences memory */ for (ii = 0; ii < task->num_postfences; ii++) { - if ((task->postfences[ii].type == NVDLA_FENCE_TYPE_SEMAPHORE || - task->postfences[ii].type == NVDLA_FENCE_TYPE_TS_SEMAPHORE) && - task->postfences[ii].sem_handle) { + if ((task->postfences[ii].type == NVDEV_FENCE_TYPE_SEMAPHORE || + task->postfences[ii].type == NVDEV_FENCE_TYPE_SEMAPHORE_TS) && + task->postfences[ii].semaphore_handle) { nvhost_buffer_submit_unpin(task->buffers, &task->postfences_sem_dmabuf[ii], 1); dma_buf_put(task->postfences_sem_dmabuf[ii]); @@ -293,7 +293,7 @@ static inline size_t nvdla_profile_status_offset(struct nvdla_task *task) static void nvdla_queue_update(void *priv, int nr_completed) { - int task_complete; + int i, task_complete; struct nvdla_task *task, *safe; struct nvhost_queue *queue = priv; struct platform_device *pdev = queue->pool->pdev; @@ -330,6 +330,11 @@ static void nvdla_queue_update(void *priv, int nr_completed) timestamp_start, timestamp_end); + for (i = 0; i < task->num_postfences; i++) + nvhost_eventlib_log_fence(pdev, + NVDEV_FENCE_KIND_POST, + task->postfences + i, timestamp_end); + nvdla_task_free_locked(task); } } @@ -602,13 +607,13 @@ static int nvdla_fill_postactions(struct nvdla_task *task) /* reset fence counter */ task->fence_counter = 0; + /* fill all postactions */ for (i = 0; i < task->num_postfences; i++) { - /* update action */ switch (task->postfences[i].type) { - case NVDLA_FENCE_TYPE_SYNCPT: - case NVDLA_FENCE_TYPE_SYNC_FD: { + case NVDEV_FENCE_TYPE_SYNCPT: + case NVDEV_FENCE_TYPE_SYNC_FD: { dma_addr_t syncpt_addr; u32 gos_id, gos_offset; @@ -641,22 +646,22 @@ static int nvdla_fill_postactions(struct nvdla_task *task) i, queue->syncpt_id, &syncpt_addr); break; } - case NVDLA_FENCE_TYPE_TS_SEMAPHORE: { + case NVDEV_FENCE_TYPE_SEMAPHORE_TS: { dma_addr_t dma_addr; size_t dma_size; nvdla_dbg_info(pdev, "POSTTS i:%d semh:%u semo:%u v:%d", i, - task->postfences[i].sem_handle, - task->postfences[i].sem_offset, - task->postfences[i].sem_val); + task->postfences[i].semaphore_handle, + task->postfences[i].semaphore_offset, + task->postfences[i].semaphore_value); /* TS SEMAPHORE just has extra memory bytes allocated * to store TS as compared default semaphore. * override action/opecode type here. */ task->postfences_sem_dmabuf[i] = - dma_buf_get(task->postfences[i].sem_handle); + dma_buf_get(task->postfences[i].semaphore_handle); if (IS_ERR_OR_NULL(task->postfences_sem_dmabuf[i])) { task->postfences_sem_dmabuf[i] = NULL; nvdla_dbg_err(pdev, "fail to get buf"); @@ -671,22 +676,22 @@ static int nvdla_fill_postactions(struct nvdla_task *task) } next = add_fence_action(next, POSTACTION_TS_SEM, - dma_addr + task->postfences[i].sem_offset, - task->postfences[i].sem_val); + dma_addr + task->postfences[i].semaphore_offset, + task->postfences[i].semaphore_value); break; } - case NVDLA_FENCE_TYPE_SEMAPHORE: { + case NVDEV_FENCE_TYPE_SEMAPHORE: { dma_addr_t dma_addr; size_t dma_size; nvdla_dbg_info(pdev, "POST i:%d semh:%u semo:%u v:%d", i, - task->postfences[i].sem_handle, - task->postfences[i].sem_offset, - task->postfences[i].sem_val); + task->postfences[i].semaphore_handle, + task->postfences[i].semaphore_offset, + task->postfences[i].semaphore_value); task->postfences_sem_dmabuf[i] = - dma_buf_get(task->postfences[i].sem_handle); + dma_buf_get(task->postfences[i].semaphore_handle); if (IS_ERR_OR_NULL(task->postfences_sem_dmabuf[i])) { task->postfences_sem_dmabuf[i] = NULL; nvdla_dbg_err(pdev, "fail to get buf"); @@ -701,8 +706,8 @@ static int nvdla_fill_postactions(struct nvdla_task *task) } next = add_fence_action(next, POSTACTION_SEM, - dma_addr + task->postfences[i].sem_offset, - task->postfences[i].sem_val); + dma_addr + task->postfences[i].semaphore_offset, + task->postfences[i].semaphore_value); break; } default: @@ -731,6 +736,7 @@ static int nvdla_fill_preactions(struct nvdla_task *task) struct platform_device *pdev = queue->pool->pdev; struct nvhost_master *host = nvhost_get_host(pdev); struct nvhost_syncpt *sp = &host->syncpt; + u64 timestamp = arch_counter_get_cntvct(); struct dla_action_list *preactionl; uint16_t preactionlist_of; u8 *next, *start; @@ -746,8 +752,11 @@ static int nvdla_fill_preactions(struct nvdla_task *task) /* fill all preactions */ for (i = 0; i < task->num_prefences; i++) { + nvhost_eventlib_log_fence(pdev, NVDEV_FENCE_KIND_PRE, + task->prefences + i, timestamp); + switch (task->prefences[i].type) { - case NVDLA_FENCE_TYPE_SYNC_FD: { + case NVDEV_FENCE_TYPE_SYNC_FD: { struct sync_fence *f; struct sync_pt *pt; u32 id, thresh, j; @@ -798,7 +807,7 @@ static int nvdla_fill_preactions(struct nvdla_task *task) } break; } - case NVDLA_FENCE_TYPE_SYNCPT: { + case NVDEV_FENCE_TYPE_SYNCPT: { u32 gos_id, gos_offset; nvdla_dbg_info(pdev, "i[%d] id[%d] val[%d]", @@ -835,19 +844,19 @@ static int nvdla_fill_preactions(struct nvdla_task *task) } break; } - case NVDLA_FENCE_TYPE_SEMAPHORE: - case NVDLA_FENCE_TYPE_TS_SEMAPHORE: { + case NVDEV_FENCE_TYPE_SEMAPHORE: + case NVDEV_FENCE_TYPE_SEMAPHORE_TS: { dma_addr_t dma_addr; size_t dma_size; nvdla_dbg_info(pdev, "i[%d] semh[%u] semo[%u] val[%d]", i, - task->prefences[i].sem_handle, - task->prefences[i].sem_offset, - task->prefences[i].sem_val); + task->prefences[i].semaphore_handle, + task->prefences[i].semaphore_offset, + task->prefences[i].semaphore_value); task->prefences_sem_dmabuf[i] = - dma_buf_get(task->prefences[i].sem_handle); + dma_buf_get(task->prefences[i].semaphore_handle); if (IS_ERR_OR_NULL(task->prefences_sem_dmabuf[i])) { task->prefences_sem_dmabuf[i] = NULL; nvdla_dbg_err(pdev, "fail to get buf"); @@ -862,8 +871,8 @@ static int nvdla_fill_preactions(struct nvdla_task *task) } next = add_fence_action(next, PREACTION_SEM_GE, - dma_addr + task->prefences[i].sem_offset, - task->prefences[i].sem_val); + dma_addr + task->prefences[i].semaphore_offset, + task->prefences[i].semaphore_value); break; } default: @@ -1013,7 +1022,7 @@ static int nvdla_send_cmd_channel(struct platform_device *pdev, /* Pick up fences... */ for (i = 0; i < task->num_prefences; i++) { /* ..and ensure that we have only syncpoints present */ - if (task->prefences[i].type != NVDLA_FENCE_TYPE_SYNCPT) { + if (task->prefences[i].type != NVDEV_FENCE_TYPE_SYNCPT) { nvdla_dbg_err(pdev, "syncpt only supported"); return -EINVAL; } @@ -1077,8 +1086,8 @@ int nvdla_emulator_submit(struct nvhost_queue *queue, struct nvdla_emu_task *tas /* update action */ switch (task->postfences[i].type) { - case NVDLA_FENCE_TYPE_SYNCPT: - case NVDLA_FENCE_TYPE_SYNC_FD: { + case NVDEV_FENCE_TYPE_SYNCPT: + case NVDEV_FENCE_TYPE_SYNC_FD: { task->fence_counter = task->fence_counter + 1; break; } @@ -1100,8 +1109,8 @@ int nvdla_emulator_submit(struct nvhost_queue *queue, struct nvdla_emu_task *tas /* Update postfences for all */ counter = task->fence_counter - 1; for (i = 0; i < task->num_postfences; i++) { - if ((task->postfences[i].type == NVDLA_FENCE_TYPE_SYNCPT) || - (task->postfences[i].type == NVDLA_FENCE_TYPE_SYNC_FD)) { + if ((task->postfences[i].type == NVDEV_FENCE_TYPE_SYNCPT) || + (task->postfences[i].type == NVDEV_FENCE_TYPE_SYNC_FD)) { task->postfences[i].syncpoint_index = queue->syncpt_id; task->postfences[i].syncpoint_value = @@ -1139,8 +1148,8 @@ int nvdla_get_postfences(struct nvhost_queue *queue, void *in_task) /* Update postfences for all */ counter = task->fence_counter - 1; for (i = 0; i < task->num_postfences; i++) { - if ((task->postfences[i].type == NVDLA_FENCE_TYPE_SYNCPT) || - (task->postfences[i].type == NVDLA_FENCE_TYPE_SYNC_FD)) { + if ((task->postfences[i].type == NVDEV_FENCE_TYPE_SYNCPT) || + (task->postfences[i].type == NVDEV_FENCE_TYPE_SYNC_FD)) { task->postfences[i].syncpoint_index = queue->syncpt_id; task->postfences[i].syncpoint_value =