From patchwork Thu Feb 21 18:42:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 10825471 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1FD5E139A for ; Fri, 22 Feb 2019 08:21:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11FE131B38 for ; Fri, 22 Feb 2019 08:21:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 06AC831B3D; Fri, 22 Feb 2019 08:21:50 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 A01D131B38 for ; Fri, 22 Feb 2019 08:21:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A993E8937C; Fri, 22 Feb 2019 08:21:09 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4C62C8916A for ; Thu, 21 Feb 2019 18:42:38 +0000 (UTC) Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1gwtIr-0000ix-TD; Thu, 21 Feb 2019 18:42:37 +0000 From: Matthew Wilcox To: dri-devel@lists.freedesktop.org Subject: [PATCH 31/34] drm/vgem: Convert fence_idr to XArray Date: Thu, 21 Feb 2019 10:42:19 -0800 Message-Id: <20190221184226.2149-60-willy@infradead.org> X-Mailer: git-send-email 2.14.5 In-Reply-To: <20190221184226.2149-1-willy@infradead.org> References: <20190221184226.2149-1-willy@infradead.org> X-Mailman-Approved-At: Fri, 22 Feb 2019 08:20:52 +0000 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ls/ScIVlKGn10OhslP2j5l71OzMhRbhBTtD52ThURTI=; b=dHG14rOPfT16/tcvjw6osyxxo BZ/qDhsFTRQD9h/UlLxov5585Mm9gZNVYocOUlsMda3aLtcNl9RQJcunopU0R9+ls1HGJnF1JBCEW vzLlPBtaLEkiD6e7ibhboqxtG2WCV7KIcF/HSdX81D+VciTvdRHfPUk04DMy9xXTDdQoOsBzrPbYg 5lS4lscdq7ph2jzpSqyXrJHed5Uv9PL4kTeGVKdywT2Dxr35tKZLRkiLHo+uW9XCTdHRtFnz4KdeH vOcuqWr/L9ldQse/nnnu7+ytvN7AJ8SrLdEjOjSyVD2RElPOzdlZR8TX4zAh6bnc4WrTwDwdMWnSY hsl18n/ug==; 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: Matthew Wilcox MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Matthew Wilcox --- drivers/gpu/drm/vgem/vgem_drv.h | 3 +-- drivers/gpu/drm/vgem/vgem_fence.c | 43 +++++++++++++------------------ 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/vgem/vgem_drv.h b/drivers/gpu/drm/vgem/vgem_drv.h index 5c8f6d619ff3..56c8872b0967 100644 --- a/drivers/gpu/drm/vgem/vgem_drv.h +++ b/drivers/gpu/drm/vgem/vgem_drv.h @@ -36,8 +36,7 @@ #include struct vgem_file { - struct idr fence_idr; - struct mutex fence_mutex; + struct xarray fences; }; #define to_vgem_bo(x) container_of(x, struct drm_vgem_gem_object, base) diff --git a/drivers/gpu/drm/vgem/vgem_fence.c b/drivers/gpu/drm/vgem/vgem_fence.c index c1c420afe2dd..aa410ebcddf2 100644 --- a/drivers/gpu/drm/vgem/vgem_fence.c +++ b/drivers/gpu/drm/vgem/vgem_fence.c @@ -184,15 +184,10 @@ int vgem_fence_attach_ioctl(struct drm_device *dev, reservation_object_add_shared_fence(resv, fence); reservation_object_unlock(resv); - /* Record the fence in our idr for later signaling */ + /* Record the fence in our array for later signaling */ if (ret == 0) { - mutex_lock(&vfile->fence_mutex); - ret = idr_alloc(&vfile->fence_idr, fence, 1, 0, GFP_KERNEL); - mutex_unlock(&vfile->fence_mutex); - if (ret > 0) { - arg->out_fence = ret; - ret = 0; - } + ret = xa_alloc(&vfile->fences, &arg->out_fence, fence, + xa_limit_31b, GFP_KERNEL); } err_fence: if (ret) { @@ -232,13 +227,13 @@ int vgem_fence_signal_ioctl(struct drm_device *dev, if (arg->flags) return -EINVAL; - mutex_lock(&vfile->fence_mutex); - fence = idr_replace(&vfile->fence_idr, NULL, arg->fence); - mutex_unlock(&vfile->fence_mutex); - if (!fence) + fence = xa_store(&vfile->fences, arg->fence, NULL, 0); + if (!fence) { + xa_erase(&vfile->fences, arg->fence); + return -ENOENT; + } + if (xa_is_err(fence)) return -ENOENT; - if (IS_ERR(fence)) - return PTR_ERR(fence); if (dma_fence_is_signaled(fence)) ret = -ETIMEDOUT; @@ -250,21 +245,19 @@ int vgem_fence_signal_ioctl(struct drm_device *dev, int vgem_fence_open(struct vgem_file *vfile) { - mutex_init(&vfile->fence_mutex); - idr_init(&vfile->fence_idr); + xa_init_flags(&vfile->fences, XA_FLAGS_ALLOC1); return 0; } -static int __vgem_fence_idr_fini(int id, void *p, void *data) -{ - dma_fence_signal(p); - dma_fence_put(p); - return 0; -} - void vgem_fence_close(struct vgem_file *vfile) { - idr_for_each(&vfile->fence_idr, __vgem_fence_idr_fini, vfile); - idr_destroy(&vfile->fence_idr); + struct dma_fence *fence; + unsigned long index; + + xa_for_each(&vfile->fences, index, fence) { + dma_fence_signal(fence); + dma_fence_put(fence); + } + xa_destroy(&vfile->fences); }