From patchwork Mon Oct 7 01:54:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qiang Yu X-Patchwork-Id: 11176707 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 23DB914DB for ; Mon, 7 Oct 2019 01:57:47 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0C7EE2080F for ; Mon, 7 Oct 2019 01:57:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C7EE2080F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5E33A6E445; Mon, 7 Oct 2019 01:57:46 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by gabe.freedesktop.org (Postfix) with ESMTPS id C51316E445; Mon, 7 Oct 2019 01:57:44 +0000 (UTC) Received: by mail-pf1-x441.google.com with SMTP id y5so7622445pfo.4; Sun, 06 Oct 2019 18:57:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XL5wDDHpLg0AjY9UChpDr+XHgx4J/KtT9T3yS63gmTQ=; b=iDAxB6cu5NRjSLWru23yApRIRJzcsiyUGNtt3wR/UIDvbQQjgwW9uJdofO+J2lj1+Z 9p4QAIYA1luN+bnzq8Em/Axq+XB9LDGhVzYw8pHELootKF5iNJPYrHCSlgeXx/aK3zd0 56B1+moOF+AxtEgFJOGJIikjT/7Ih154qZNopMEFU2y84wSD8jRjKgLnMsnFSqZb3Bb4 obv1MQLfrk11Ai5zwPtA373wvctLqU/JuulbbRjR48HGkwWwK/Y+SBjTflQcnLzPBuyi UIKag0SNClfKqL1xU8hAGUe+IpYA0hNTeIQbbzxnzUz3dujcvDm0hgr1qGQ57GotGsO2 HhhA== X-Gm-Message-State: APjAAAUP8oyx6SQO4Ax4cfv08hpuNGZyPJMIG3bZ0dSdzhVxQyjB8RMm o8Dja+hpIj8Y1a5jf/8QKnMazX01cJ8Xig== X-Google-Smtp-Source: APXvYqx0ORSLN0C5Cojs1VodDFIckMfLrio2u4U6JrP6E7S55nfi8Yl5gMjLpD70b/UHVKtJBdQb6w== X-Received: by 2002:a63:5344:: with SMTP id t4mr8233730pgl.394.1570413464113; Sun, 06 Oct 2019 18:57:44 -0700 (PDT) Received: from yuq-Aspire-4738G.lan (ah.ptr230.ptrcloud.net. [153.122.161.8]) by smtp.gmail.com with ESMTPSA id b123sm18328536pgc.72.2019.10.06.18.57.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Oct 2019 18:57:43 -0700 (PDT) From: Qiang Yu To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 3/6] drm/lima: use drm_gem_objects_lookup Date: Mon, 7 Oct 2019 09:54:27 +0800 Message-Id: <20191007015430.20829-4-yuq825@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191007015430.20829-1-yuq825@gmail.com> References: <20191007015430.20829-1-yuq825@gmail.com> X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XL5wDDHpLg0AjY9UChpDr+XHgx4J/KtT9T3yS63gmTQ=; b=fzLvSXctdpU94ApSz/K5WWSZ06vnm6Bial9JL4SkDZFvz8TDi3snq9YPnBTcX5h/p9 PIxZsdWmrVpYUXxvA8H2bng5QTkEkz0vlViZD81/Niak8YIL2cTWvxWmY/ODEQmTqGN1 uMXl6weQX0y1xyDbmuB+bkh5/8lzvQcWrTJEXy9YVja3tsjkJRwSJLeywKU7loTXjmaN f6XeLwn6ICW2QrSrgneiPnmN6FK6fKTX6j4ATwUl3tOFo/1c1YWg8oiZVjLPrGli6tEL Rgaw9/xK1YJzH66PAa9gJVwqIDyDOV8HJ1PoKBQN20UQ8JBZum0CMqxvxpEK6uE4DD5r 7pgg== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lima@lists.freedesktop.org, David Airlie , Maxime Ripard , Qiang Yu , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use DRM GEM helper function drm_gem_objects_lookup() for GEM object lookup at once instead of one by one with drm_gem_object_lookup(). v2: improve commit comment. Signed-off-by: Qiang Yu --- drivers/gpu/drm/lima/lima_drv.c | 5 ++- drivers/gpu/drm/lima/lima_gem.c | 73 +++++++++++++++++++-------------- 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/lima/lima_drv.c b/drivers/gpu/drm/lima/lima_drv.c index 75ec703d22e0..cc850a522fac 100644 --- a/drivers/gpu/drm/lima/lima_drv.c +++ b/drivers/gpu/drm/lima/lima_drv.c @@ -108,7 +108,7 @@ static int lima_ioctl_gem_submit(struct drm_device *dev, void *data, struct drm_ if (args->frame_size != pipe->frame_size) return -EINVAL; - bos = kvcalloc(args->nr_bos, sizeof(*submit.bos) + sizeof(*submit.lbos), GFP_KERNEL); + bos = kvcalloc(args->nr_bos, sizeof(*submit.bos), GFP_KERNEL); if (!bos) return -ENOMEM; @@ -142,7 +142,6 @@ static int lima_ioctl_gem_submit(struct drm_device *dev, void *data, struct drm_ submit.pipe = args->pipe; submit.bos = bos; - submit.lbos = (void *)bos + size; submit.nr_bos = args->nr_bos; submit.task = task; submit.ctx = ctx; @@ -159,6 +158,8 @@ static int lima_ioctl_gem_submit(struct drm_device *dev, void *data, struct drm_ kmem_cache_free(pipe->task_slab, task); out0: kvfree(bos); + if (submit.lbos) + kvfree(submit.lbos); return err; } diff --git a/drivers/gpu/drm/lima/lima_gem.c b/drivers/gpu/drm/lima/lima_gem.c index ff3d9acc24fc..f5aeaa1f61c8 100644 --- a/drivers/gpu/drm/lima/lima_gem.c +++ b/drivers/gpu/drm/lima/lima_gem.c @@ -130,6 +130,25 @@ int lima_gem_mmap(struct file *filp, struct vm_area_struct *vma) return 0; } +static int lima_gem_lookup_bos(struct drm_file *file, struct lima_submit *submit) +{ + int i, ret; + u32 *handles; + + handles = kvmalloc_array(submit->nr_bos, sizeof(u32), GFP_KERNEL); + if (!handles) + return -ENOMEM; + + for (i = 0; i < submit->nr_bos; i++) + handles[i] = submit->bos[i].handle; + + ret = drm_gem_objects_lookup(file, handles, submit->nr_bos, + (struct drm_gem_object ***)&submit->lbos); + + kvfree(handles); + return ret; +} + static int lima_gem_sync_bo(struct lima_sched_task *task, struct lima_bo *bo, bool write, bool explicit) { @@ -236,7 +255,7 @@ int lima_gem_submit(struct drm_file *file, struct lima_submit *submit) struct lima_vm *vm = priv->vm; struct drm_syncobj *out_sync = NULL; struct dma_fence *fence; - struct lima_bo **bos = submit->lbos; + struct lima_bo **bos; if (submit->out_sync) { out_sync = drm_syncobj_find(file, submit->out_sync); @@ -244,43 +263,37 @@ int lima_gem_submit(struct drm_file *file, struct lima_submit *submit) return -ENOENT; } - for (i = 0; i < submit->nr_bos; i++) { - struct drm_gem_object *obj; - struct lima_bo *bo; - - obj = drm_gem_object_lookup(file, submit->bos[i].handle); - if (!obj) { - err = -ENOENT; - goto err_out0; - } + err = lima_gem_lookup_bos(file, submit); + if (err) + goto err_out0; - bo = to_lima_bo(obj); + bos = submit->lbos; - /* increase refcnt of gpu va map to prevent unmapped when executing, - * will be decreased when task done - */ - err = lima_vm_bo_add(vm, bo, false); + /* increase refcnt of gpu va map to prevent unmapped when executing, + * will be decreased when task done + */ + for (i = 0; i < submit->nr_bos; i++) { + err = lima_vm_bo_add(vm, bos[i], false); if (err) { - drm_gem_object_put_unlocked(obj); - goto err_out0; + for (i--; i >= 0; i--) + lima_vm_bo_del(vm, bos[i]); + goto err_out1; } - - bos[i] = bo; } err = lima_gem_lock_bos(bos, submit->nr_bos, &ctx); if (err) - goto err_out0; + goto err_out2; err = lima_sched_task_init( submit->task, submit->ctx->context + submit->pipe, bos, submit->nr_bos, vm); if (err) - goto err_out1; + goto err_out3; err = lima_gem_add_deps(file, submit); if (err) - goto err_out2; + goto err_out4; for (i = 0; i < submit->nr_bos; i++) { err = lima_gem_sync_bo( @@ -288,7 +301,7 @@ int lima_gem_submit(struct drm_file *file, struct lima_submit *submit) submit->bos[i].flags & LIMA_SUBMIT_BO_WRITE, submit->flags & LIMA_SUBMIT_FLAG_EXPLICIT_FENCE); if (err) - goto err_out2; + goto err_out4; } fence = lima_sched_context_queue_task( @@ -315,17 +328,17 @@ int lima_gem_submit(struct drm_file *file, struct lima_submit *submit) return 0; -err_out2: +err_out4: lima_sched_task_fini(submit->task); -err_out1: +err_out3: lima_gem_unlock_bos(bos, submit->nr_bos, &ctx); -err_out0: - for (i = 0; i < submit->nr_bos; i++) { - if (!bos[i]) - break; +err_out2: + for (i = 0; i < submit->nr_bos; i++) lima_vm_bo_del(vm, bos[i]); +err_out1: + for (i = 0; i < submit->nr_bos; i++) drm_gem_object_put_unlocked(&bos[i]->gem); - } +err_out0: if (out_sync) drm_syncobj_put(out_sync); return err;