From patchwork Thu Sep 26 14:10:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qiang Yu X-Patchwork-Id: 11162815 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 824D71599 for ; Thu, 26 Sep 2019 14:12:54 +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 689EF222C6 for ; Thu, 26 Sep 2019 14:12:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 689EF222C6 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 9CB2A6ED44; Thu, 26 Sep 2019 14:12:53 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by gabe.freedesktop.org (Postfix) with ESMTPS id E4A346ED44; Thu, 26 Sep 2019 14:12:52 +0000 (UTC) Received: by mail-pf1-x442.google.com with SMTP id 205so1942458pfw.2; Thu, 26 Sep 2019 07:12:52 -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=qJoGqRdp8WoKFAnF+e7AVTcfRr0hQl7O756Jqf++qm4=; b=gIH2SCVvJuLuFhLqjnmmqKJZqtOrOBDA5LFNt43uTehT+IRx+Da7d9Vv8RaIeHSybP tuZ0zNKGHe5NtFhdPSWYblLkMsUJENxPMzPxIgUgGHiBmVPB07Ogh007If+xJaXMWrA7 zvMG8QYWZEzzxLD3dgZl0A+EAflqN0spY3imTr0ZwV+mxD8EZBrSEWlNf43fU8IHJ1HM 6eJlbMV6Q5A1TuDpabvuwhHq7pIrFo4q2HoEl40GiDIR0Y+u7fhoEjbRMLO4+BsUBnBr 5yAve40tp1ieLMYA+oYCyUtiRcoy3HFYW3n6RRpvVJrnmTdedXOBz4Wpa6ip3oiuCBfB vzmw== X-Gm-Message-State: APjAAAXfmwcbS6eIhKSvucuczVXqBMOs9QVa57RMI81mFMuVemLxAjnM NqSFo1umZiUd5QzCqGbaJdMG6F5Y+OA= X-Google-Smtp-Source: APXvYqzNQxBQskNqQVQjyaqjYR4+Kng5cBJP/RuovrpdH9h8RekdOErKEWVYFBiKViaQAnSXQNPkog== X-Received: by 2002:a17:90a:284c:: with SMTP id p12mr3849090pjf.87.1569507172421; Thu, 26 Sep 2019 07:12:52 -0700 (PDT) Received: from localhost.localdomain (ah.ptr230.ptrcloud.net. [153.122.161.8]) by smtp.gmail.com with ESMTPSA id w188sm2176740pgw.26.2019.09.26.07.12.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Sep 2019 07:12:52 -0700 (PDT) From: Qiang Yu To: dri-devel@lists.freedesktop.org Subject: [PATCH 5/6] drm/lima: use drm_gem_(un)lock_reservations Date: Thu, 26 Sep 2019 22:10:44 +0800 Message-Id: <20190926141046.30758-7-yuq825@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190926141046.30758-1-yuq825@gmail.com> References: <20190926141046.30758-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=qJoGqRdp8WoKFAnF+e7AVTcfRr0hQl7O756Jqf++qm4=; b=ekEMtXGF/3fMhzAs/wkdX6nMg5t2LhMo9kU81/OfuoIkdTJaQVxC8s5zhs38NuGzbz wN4TgOP8j3icMqDfYG9OxOB2k1AExWyrOeuLhg0xkVwRpQLHqpRkQ40/Xt7Pm6VfZ4Qm MNp0Y6b+3yAf4tPYna+zI3OoHpwFdDZ0MafRceeEvQEkQVyqcsczDacGpEVkTvJ8/Ehf Z+dSTpHVFZwVvAMSX2jhiHk8MdqayzsLCO7Km0I/Zr8RwkQ4drGSqMhQwFUjV4oXGWVq Hke+yGZri40r91n/gmKsq5Sx/qW4PD0t6C4QnLmhKkyuTljqKTF4vkEZNZ1OFJCeNTuG D5tw== 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, Maxime Ripard , David Airlie , Qiang Yu , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Signed-off-by: Qiang Yu --- drivers/gpu/drm/lima/lima_gem.c | 64 ++++----------------------------- 1 file changed, 6 insertions(+), 58 deletions(-) diff --git a/drivers/gpu/drm/lima/lima_gem.c b/drivers/gpu/drm/lima/lima_gem.c index eb70e4429588..3cc1870862c3 100644 --- a/drivers/gpu/drm/lima/lima_gem.c +++ b/drivers/gpu/drm/lima/lima_gem.c @@ -166,61 +166,6 @@ static int lima_gem_sync_bo(struct lima_sched_task *task, struct lima_bo *bo, return drm_gem_fence_array_add_implicit(&task->deps, &bo->base.base, write); } -static int lima_gem_lock_bos(struct lima_bo **bos, u32 nr_bos, - struct ww_acquire_ctx *ctx) -{ - int i, ret = 0, contended, slow_locked = -1; - - ww_acquire_init(ctx, &reservation_ww_class); - -retry: - for (i = 0; i < nr_bos; i++) { - if (i == slow_locked) { - slow_locked = -1; - continue; - } - - ret = ww_mutex_lock_interruptible(&lima_bo_resv(bos[i])->lock, ctx); - if (ret < 0) { - contended = i; - goto err; - } - } - - ww_acquire_done(ctx); - return 0; - -err: - for (i--; i >= 0; i--) - ww_mutex_unlock(&lima_bo_resv(bos[i])->lock); - - if (slow_locked >= 0) - ww_mutex_unlock(&lima_bo_resv(bos[slow_locked])->lock); - - if (ret == -EDEADLK) { - /* we lost out in a seqno race, lock and retry.. */ - ret = ww_mutex_lock_slow_interruptible( - &lima_bo_resv(bos[contended])->lock, ctx); - if (!ret) { - slow_locked = contended; - goto retry; - } - } - ww_acquire_fini(ctx); - - return ret; -} - -static void lima_gem_unlock_bos(struct lima_bo **bos, u32 nr_bos, - struct ww_acquire_ctx *ctx) -{ - int i; - - for (i = 0; i < nr_bos; i++) - ww_mutex_unlock(&lima_bo_resv(bos[i])->lock); - ww_acquire_fini(ctx); -} - static int lima_gem_add_deps(struct drm_file *file, struct lima_submit *submit) { int i, err; @@ -280,7 +225,8 @@ int lima_gem_submit(struct drm_file *file, struct lima_submit *submit) } } - err = lima_gem_lock_bos(bos, submit->nr_bos, &ctx); + err = drm_gem_lock_reservations((struct drm_gem_object **)bos, + submit->nr_bos, &ctx); if (err) goto err_out2; @@ -313,7 +259,8 @@ int lima_gem_submit(struct drm_file *file, struct lima_submit *submit) dma_resv_add_shared_fence(lima_bo_resv(bos[i]), fence); } - lima_gem_unlock_bos(bos, submit->nr_bos, &ctx); + drm_gem_unlock_reservations((struct drm_gem_object **)bos, + submit->nr_bos, &ctx); for (i = 0; i < submit->nr_bos; i++) drm_gem_object_put_unlocked(&bos[i]->base.base); @@ -330,7 +277,8 @@ int lima_gem_submit(struct drm_file *file, struct lima_submit *submit) err_out4: lima_sched_task_fini(submit->task); err_out3: - lima_gem_unlock_bos(bos, submit->nr_bos, &ctx); + drm_gem_unlock_reservations((struct drm_gem_object **)bos, + submit->nr_bos, &ctx); err_out2: for (i = 0; i < submit->nr_bos; i++) lima_vm_bo_del(vm, bos[i]);