From patchwork Fri Dec 1 10:36:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Stach X-Patchwork-Id: 10086821 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EB0EF6035E for ; Fri, 1 Dec 2017 10:38:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0052829FE8 for ; Fri, 1 Dec 2017 10:38:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E83522A0D6; Fri, 1 Dec 2017 10:38:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4C07B29FE8 for ; Fri, 1 Dec 2017 10:38:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A0BDC6ED09; Fri, 1 Dec 2017 10:36:34 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.ORG Delivered-To: dri-devel@lists.freedesktop.ORG Received: from metis.ext.pengutronix.de (metis.ext.pengutronix.de [IPv6:2001:67c:670:201:290:27ff:fe1d:cc33]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1B0A36ECC1 for ; Fri, 1 Dec 2017 10:36:28 +0000 (UTC) Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7] helo=dude.pengutronix.de.) by metis.ext.pengutronix.de with esmtp (Exim 4.84_2) (envelope-from ) id 1eKigE-0004JB-4u; Fri, 01 Dec 2017 11:36:26 +0100 From: Lucas Stach To: etnaviv@lists.freedesktop.org Subject: [PATCH 21/27] drm/etnaviv: move PMRs to submit object Date: Fri, 1 Dec 2017 11:36:18 +0100 Message-Id: <20171201103624.6565-22-l.stach@pengutronix.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171201103624.6565-1-l.stach@pengutronix.de> References: <20171201103624.6565-1-l.stach@pengutronix.de> X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: l.stach@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: dri-devel@lists.freedesktop.org Cc: patchwork-lst@pengutronix.de, kernel@pengutronix.de, dri-devel@lists.freedesktop.org, Russell King X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP To make them available to the event worker even after the actual command stream execution has finished. Signed-off-by: Lucas Stach --- drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c | 14 +--------- drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.h | 5 +--- drivers/gpu/drm/etnaviv/etnaviv_gem.h | 5 ++-- drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c | 40 ++++++++++++++++------------ drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 27 ++++++++++--------- drivers/gpu/drm/etnaviv/etnaviv_gpu.h | 2 +- 6 files changed, 44 insertions(+), 49 deletions(-) diff --git a/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c b/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c index 66ac79558bbd..4ce4639d028d 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c @@ -88,10 +88,9 @@ void etnaviv_cmdbuf_suballoc_destroy(struct etnaviv_cmdbuf_suballoc *suballoc) struct etnaviv_cmdbuf * etnaviv_cmdbuf_new(struct etnaviv_cmdbuf_suballoc *suballoc, u32 size, - size_t nr_bos, size_t nr_pmrs) + size_t nr_bos) { struct etnaviv_cmdbuf *cmdbuf; - struct etnaviv_perfmon_request *pmrs; size_t sz = size_vstruct(nr_bos, sizeof(cmdbuf->bo_map[0]), sizeof(*cmdbuf)); int granule_offs, order, ret; @@ -100,12 +99,6 @@ etnaviv_cmdbuf_new(struct etnaviv_cmdbuf_suballoc *suballoc, u32 size, if (!cmdbuf) return NULL; - sz = sizeof(*pmrs) * nr_pmrs; - pmrs = kzalloc(sz, GFP_KERNEL); - if (!pmrs) - goto out_free_cmdbuf; - - cmdbuf->pmrs = pmrs; cmdbuf->suballoc = suballoc; cmdbuf->size = size; @@ -132,10 +125,6 @@ etnaviv_cmdbuf_new(struct etnaviv_cmdbuf_suballoc *suballoc, u32 size, cmdbuf->vaddr = suballoc->vaddr + cmdbuf->suballoc_offset; return cmdbuf; - -out_free_cmdbuf: - kfree(cmdbuf); - return NULL; } void etnaviv_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf) @@ -151,7 +140,6 @@ void etnaviv_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf) suballoc->free_space = 1; mutex_unlock(&suballoc->lock); wake_up_all(&suballoc->free_event); - kfree(cmdbuf->pmrs); kfree(cmdbuf); } diff --git a/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.h b/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.h index b6348b9f2a9d..930b9c7f2249 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.h @@ -39,9 +39,6 @@ struct etnaviv_cmdbuf { u32 exec_state; /* per GPU in-flight list */ struct list_head node; - /* perfmon requests */ - unsigned int nr_pmrs; - struct etnaviv_perfmon_request *pmrs; /* BOs attached to this command buffer */ unsigned int nr_bos; struct etnaviv_vram_mapping *bo_map[0]; @@ -53,7 +50,7 @@ void etnaviv_cmdbuf_suballoc_destroy(struct etnaviv_cmdbuf_suballoc *suballoc); struct etnaviv_cmdbuf * etnaviv_cmdbuf_new(struct etnaviv_cmdbuf_suballoc *suballoc, u32 size, - size_t nr_bos, size_t nr_pmrs); + size_t nr_bos); void etnaviv_cmdbuf_free(struct etnaviv_cmdbuf *cmdbuf); u32 etnaviv_cmdbuf_get_va(struct etnaviv_cmdbuf *buf); diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem.h b/drivers/gpu/drm/etnaviv/etnaviv_gem.h index 4238f8d8541d..f525fd1ef63c 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem.h @@ -97,14 +97,15 @@ struct etnaviv_gem_submit_bo { /* Created per submit-ioctl, to track bo's and cmdstream bufs, etc, * associated with the cmdstream submission for synchronization (and - * make it easier to unwind when things go wrong, etc). This only - * lasts for the duration of the submit-ioctl. + * make it easier to unwind when things go wrong, etc). */ struct etnaviv_gem_submit { struct kref refcount; struct etnaviv_gpu *gpu; struct dma_fence *out_fence, *in_fence; u32 flags; + unsigned int nr_pmrs; + struct etnaviv_perfmon_request *pmrs; unsigned int nr_bos; struct etnaviv_gem_submit_bo bos[0]; /* No new members here, the previous one is variable-length! */ diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c index 9b4436c380ea..c8c576993c62 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gem_submit.c @@ -33,15 +33,23 @@ #define BO_PINNED 0x2000 static struct etnaviv_gem_submit *submit_create(struct drm_device *dev, - struct etnaviv_gpu *gpu, size_t nr) + struct etnaviv_gpu *gpu, size_t nr_bos, size_t nr_pmrs) { struct etnaviv_gem_submit *submit; - size_t sz = size_vstruct(nr, sizeof(submit->bos[0]), sizeof(*submit)); + size_t sz = size_vstruct(nr_bos, sizeof(submit->bos[0]), sizeof(*submit)); submit = kzalloc(sz, GFP_KERNEL); if (!submit) return NULL; + submit->pmrs = kcalloc(nr_pmrs, sizeof(struct etnaviv_perfmon_request), + GFP_KERNEL); + if (!submit->pmrs) { + kfree(submit); + return NULL; + } + submit->nr_pmrs = nr_pmrs; + submit->gpu = gpu; kref_init(&submit->refcount); @@ -295,13 +303,11 @@ static int submit_reloc(struct etnaviv_gem_submit *submit, void *stream, } static int submit_perfmon_validate(struct etnaviv_gem_submit *submit, - struct etnaviv_cmdbuf *cmdbuf, - const struct drm_etnaviv_gem_submit_pmr *pmrs, - u32 nr_pms) + u32 exec_state, const struct drm_etnaviv_gem_submit_pmr *pmrs) { u32 i; - for (i = 0; i < nr_pms; i++) { + for (i = 0; i < submit->nr_pmrs; i++) { const struct drm_etnaviv_gem_submit_pmr *r = pmrs + i; struct etnaviv_gem_submit_bo *bo; int ret; @@ -326,17 +332,17 @@ static int submit_perfmon_validate(struct etnaviv_gem_submit *submit, return -EINVAL; } - if (etnaviv_pm_req_validate(r, cmdbuf->exec_state)) { + if (etnaviv_pm_req_validate(r, exec_state)) { DRM_ERROR("perfmon request: domain or signal not valid"); return -EINVAL; } - cmdbuf->pmrs[i].flags = r->flags; - cmdbuf->pmrs[i].domain = r->domain; - cmdbuf->pmrs[i].signal = r->signal; - cmdbuf->pmrs[i].sequence = r->sequence; - cmdbuf->pmrs[i].offset = r->read_offset; - cmdbuf->pmrs[i].bo_vma = etnaviv_gem_vmap(&bo->obj->base); + submit->pmrs[i].flags = r->flags; + submit->pmrs[i].domain = r->domain; + submit->pmrs[i].signal = r->signal; + submit->pmrs[i].sequence = r->sequence; + submit->pmrs[i].offset = r->read_offset; + submit->pmrs[i].bo_vma = etnaviv_gem_vmap(&bo->obj->base); } return 0; @@ -367,6 +373,7 @@ static void submit_cleanup(struct kref *kref) dma_fence_put(submit->in_fence); if (submit->out_fence) dma_fence_put(submit->out_fence); + kfree(submit->pmrs); kfree(submit); } @@ -427,7 +434,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, stream = kvmalloc_array(1, args->stream_size, GFP_KERNEL); cmdbuf = etnaviv_cmdbuf_new(gpu->cmdbuf_suballoc, ALIGN(args->stream_size, 8) + 8, - args->nr_bos, args->nr_pmrs); + args->nr_bos); if (!bos || !relocs || !pmrs || !stream || !cmdbuf) { ret = -ENOMEM; goto err_submit_cmds; @@ -456,7 +463,6 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, ret = -EFAULT; goto err_submit_cmds; } - cmdbuf->nr_pmrs = args->nr_pmrs; ret = copy_from_user(stream, u64_to_user_ptr(args->stream), args->stream_size); @@ -475,7 +481,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, ww_acquire_init(&ticket, &reservation_ww_class); - submit = submit_create(dev, gpu, args->nr_bos); + submit = submit_create(dev, gpu, args->nr_bos, args->nr_pmrs); if (!submit) { ret = -ENOMEM; goto err_submit_ww_acquire; @@ -518,7 +524,7 @@ int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data, if (ret) goto err_submit_objects; - ret = submit_perfmon_validate(submit, cmdbuf, pmrs, args->nr_pmrs); + ret = submit_perfmon_validate(submit, args->exec_state, pmrs); if (ret) goto err_submit_objects; diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c index 2f09b746439e..6951ba560573 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -717,7 +717,7 @@ int etnaviv_gpu_init(struct etnaviv_gpu *gpu) } /* Create buffer: */ - gpu->buffer = etnaviv_cmdbuf_new(gpu->cmdbuf_suballoc, PAGE_SIZE, 0, 0); + gpu->buffer = etnaviv_cmdbuf_new(gpu->cmdbuf_suballoc, PAGE_SIZE, 0); if (!gpu->buffer) { ret = -ENOMEM; dev_err(gpu->dev, "could not create command buffer\n"); @@ -1317,11 +1317,11 @@ void etnaviv_gpu_pm_put(struct etnaviv_gpu *gpu) static void sync_point_perfmon_sample(struct etnaviv_gpu *gpu, struct etnaviv_event *event, unsigned int flags) { - const struct etnaviv_cmdbuf *cmdbuf = event->cmdbuf; + const struct etnaviv_gem_submit *submit = event->submit; unsigned int i; - for (i = 0; i < cmdbuf->nr_pmrs; i++) { - const struct etnaviv_perfmon_request *pmr = cmdbuf->pmrs + i; + for (i = 0; i < submit->nr_pmrs; i++) { + const struct etnaviv_perfmon_request *pmr = submit->pmrs + i; if (pmr->flags == flags) etnaviv_perfmon_process(gpu, pmr); @@ -1349,14 +1349,14 @@ static void sync_point_perfmon_sample_pre(struct etnaviv_gpu *gpu, static void sync_point_perfmon_sample_post(struct etnaviv_gpu *gpu, struct etnaviv_event *event) { - const struct etnaviv_cmdbuf *cmdbuf = event->cmdbuf; + const struct etnaviv_gem_submit *submit = event->submit; unsigned int i; u32 val; sync_point_perfmon_sample(gpu, event, ETNA_PM_PROCESS_POST); - for (i = 0; i < cmdbuf->nr_pmrs; i++) { - const struct etnaviv_perfmon_request *pmr = cmdbuf->pmrs + i; + for (i = 0; i < submit->nr_pmrs; i++) { + const struct etnaviv_perfmon_request *pmr = submit->pmrs + i; *pmr->bo_vma = pmr->sequence; } @@ -1392,7 +1392,7 @@ int etnaviv_gpu_submit(struct etnaviv_gpu *gpu, * - a sync point to re-configure gpu, process ETNA_PM_PROCESS_POST requests * and update the sequence number for userspace. */ - if (cmdbuf->nr_pmrs) + if (submit->nr_pmrs) nr_events = 3; ret = event_alloc(gpu, nr_events, event); @@ -1416,17 +1416,19 @@ int etnaviv_gpu_submit(struct etnaviv_gpu *gpu, submit->out_fence = dma_fence_get(fence); gpu->active_fence = submit->out_fence->seqno; - if (cmdbuf->nr_pmrs) { + if (submit->nr_pmrs) { gpu->event[event[1]].sync_point = &sync_point_perfmon_sample_pre; - gpu->event[event[1]].cmdbuf = cmdbuf; + kref_get(&submit->refcount); + gpu->event[event[1]].submit = submit; etnaviv_sync_point_queue(gpu, event[1]); } etnaviv_buffer_queue(gpu, event[0], cmdbuf); - if (cmdbuf->nr_pmrs) { + if (submit->nr_pmrs) { gpu->event[event[2]].sync_point = &sync_point_perfmon_sample_post; - gpu->event[event[2]].cmdbuf = cmdbuf; + kref_get(&submit->refcount); + gpu->event[event[2]].submit = submit; etnaviv_sync_point_queue(gpu, event[2]); } @@ -1465,6 +1467,7 @@ static void sync_point_worker(struct work_struct *work) u32 addr = gpu_read(gpu, VIVS_FE_DMA_ADDRESS); event->sync_point(gpu, event); + etnaviv_submit_put(event->submit); event_free(gpu, gpu->sync_point_event); /* restart FE last to avoid GPU and IRQ racing against this worker */ diff --git a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h index ccef6139cf70..eea823838b5f 100644 --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.h +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.h @@ -89,7 +89,7 @@ struct etnaviv_chip_identity { struct etnaviv_event { struct dma_fence *fence; - struct etnaviv_cmdbuf *cmdbuf; + struct etnaviv_gem_submit *submit; void (*sync_point)(struct etnaviv_gpu *gpu, struct etnaviv_event *event); };