From patchwork Thu Feb 21 18:42:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthew Wilcox (Oracle)" X-Patchwork-Id: 10825477 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 E341D139A for ; Fri, 22 Feb 2019 08:21:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D366731B2A for ; Fri, 22 Feb 2019 08:21:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D16E631B44; Fri, 22 Feb 2019 08:21:53 +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 6CFC931B3B for ; Fri, 22 Feb 2019 08:21:53 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8EB22893EB; Fri, 22 Feb 2019 08:21:23 +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 B008489127 for ; Thu, 21 Feb 2019 18:42:36 +0000 (UTC) Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1gwtIq-0000hb-Ab; Thu, 21 Feb 2019 18:42:36 +0000 From: Matthew Wilcox To: dri-devel@lists.freedesktop.org Subject: [PATCH 26/34] drm/qxl: Convert release_idr to XArray Date: Thu, 21 Feb 2019 10:42:09 -0800 Message-Id: <20190221184226.2149-50-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=gG7ixrYypbEcMghLyNc65UfU8G/goXZ01MhyVOCK0uw=; b=NpYF9LyZfySkvsQUtjR3HByAg qFCtwtx8IXjIy3GW/RhssMJ8iB6ZJabPFzR2cuE7NltZooCQ7qTumWcBbw/2WlVsJj93I72sG3evN w/xv1MKlsr3uYpg0conJG4s4GDdAZAbioDK9v0M2nntNdvv2jF21pAOTEbCzB45y2RJXKtUm24ezz IgfeuGVPOA38yIsEsECbp9RMsUxHs4V2UmwdT+jxb2uwhPGuwVa4iqQ0yXtPA56M9mjMuLMdS3Ksm kGiRlm9/eg4fVcmDeAjGFo8O7R6Cb0MYLQKk/I71jK+GFw8VNw9l8xjnPsE+IU/4qE65zOFAHWlXY HjgZUC7Xw==; 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/qxl/qxl_drv.h | 3 +- drivers/gpu/drm/qxl/qxl_kms.c | 3 +- drivers/gpu/drm/qxl/qxl_release.c | 54 +++++++++++++------------------ 3 files changed, 25 insertions(+), 35 deletions(-) diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h index 13a0254b59a1..3abd432a4b85 100644 --- a/drivers/gpu/drm/qxl/qxl_drv.h +++ b/drivers/gpu/drm/qxl/qxl_drv.h @@ -238,9 +238,8 @@ struct qxl_device { uint64_t va_slot_mask; spinlock_t release_lock; - struct idr release_idr; + struct xarray releases; uint32_t release_seqno; - spinlock_t release_idr_lock; struct mutex async_io_mutex; unsigned int last_sent_io_cmd; diff --git a/drivers/gpu/drm/qxl/qxl_kms.c b/drivers/gpu/drm/qxl/qxl_kms.c index 15238a413f9d..b2cc71c95142 100644 --- a/drivers/gpu/drm/qxl/qxl_kms.c +++ b/drivers/gpu/drm/qxl/qxl_kms.c @@ -247,8 +247,7 @@ int qxl_device_init(struct qxl_device *qdev, goto release_ring_free; } - idr_init(&qdev->release_idr); - spin_lock_init(&qdev->release_idr_lock); + xa_init_flags(&qdev->releases, XA_FLAGS_ALLOC1); spin_lock_init(&qdev->release_lock); idr_init(&qdev->surf_id_idr); diff --git a/drivers/gpu/drm/qxl/qxl_release.c b/drivers/gpu/drm/qxl/qxl_release.c index 30f85f0130cb..a1a42662ebf4 100644 --- a/drivers/gpu/drm/qxl/qxl_release.c +++ b/drivers/gpu/drm/qxl/qxl_release.c @@ -121,7 +121,7 @@ qxl_release_alloc(struct qxl_device *qdev, int type, struct qxl_release **ret) { struct qxl_release *release; - int handle; + int err; size_t size = sizeof(*release); release = kmalloc(size, GFP_KERNEL); @@ -135,21 +135,19 @@ qxl_release_alloc(struct qxl_device *qdev, int type, release->surface_release_id = 0; INIT_LIST_HEAD(&release->bos); - idr_preload(GFP_KERNEL); - spin_lock(&qdev->release_idr_lock); - handle = idr_alloc(&qdev->release_idr, release, 1, 0, GFP_NOWAIT); + xa_lock(&qdev->releases); + err = __xa_alloc(&qdev->releases, &release->id, release, xa_limit_31b, + GFP_KERNEL); release->base.seqno = ++qdev->release_seqno; - spin_unlock(&qdev->release_idr_lock); - idr_preload_end(); - if (handle < 0) { + xa_unlock(&qdev->releases); + if (err < 0) { kfree(release); *ret = NULL; - return handle; + return err; } *ret = release; - DRM_DEBUG_DRIVER("allocated release %d\n", handle); - release->id = handle; - return handle; + DRM_DEBUG_DRIVER("allocated release %d\n", release->id); + return release->id; } static void @@ -178,9 +176,7 @@ qxl_release_free(struct qxl_device *qdev, if (release->surface_release_id) qxl_surface_id_dealloc(qdev, release->surface_release_id); - spin_lock(&qdev->release_idr_lock); - idr_remove(&qdev->release_idr, release->id); - spin_unlock(&qdev->release_idr_lock); + xa_erase(&qdev->releases, release->id); if (release->base.ops) { WARN_ON(list_empty(&release->bos)); @@ -288,14 +284,14 @@ int qxl_alloc_surface_release_reserved(struct qxl_device *qdev, struct qxl_release **release) { if (surface_cmd_type == QXL_SURFACE_CMD_DESTROY && create_rel) { - int idr_ret; + int id; struct qxl_bo *bo; union qxl_release_info *info; /* stash the release after the create command */ - idr_ret = qxl_release_alloc(qdev, QXL_RELEASE_SURFACE_CMD, release); - if (idr_ret < 0) - return idr_ret; + id = qxl_release_alloc(qdev, QXL_RELEASE_SURFACE_CMD, release); + if (id < 0) + return id; bo = create_rel->release_bo; (*release)->release_bo = bo; @@ -304,7 +300,7 @@ int qxl_alloc_surface_release_reserved(struct qxl_device *qdev, qxl_release_list_add(*release, bo); info = qxl_release_map(qdev, *release); - info->id = idr_ret; + info->id = id; qxl_release_unmap(qdev, *release, info); return 0; } @@ -318,7 +314,7 @@ int qxl_alloc_release_reserved(struct qxl_device *qdev, unsigned long size, struct qxl_bo **rbo) { struct qxl_bo *bo; - int idr_ret; + int id; int ret = 0; union qxl_release_info *info; int cur_idx; @@ -334,11 +330,11 @@ int qxl_alloc_release_reserved(struct qxl_device *qdev, unsigned long size, return -EINVAL; } - idr_ret = qxl_release_alloc(qdev, type, release); - if (idr_ret < 0) { + id = qxl_release_alloc(qdev, type, release); + if (id < 0) { if (rbo) *rbo = NULL; - return idr_ret; + return id; } mutex_lock(&qdev->release_mutex); @@ -375,7 +371,7 @@ int qxl_alloc_release_reserved(struct qxl_device *qdev, unsigned long size, } info = qxl_release_map(qdev, *release); - info->id = idr_ret; + info->id = id; qxl_release_unmap(qdev, *release, info); return ret; @@ -386,13 +382,9 @@ struct qxl_release *qxl_release_from_id_locked(struct qxl_device *qdev, { struct qxl_release *release; - spin_lock(&qdev->release_idr_lock); - release = idr_find(&qdev->release_idr, id); - spin_unlock(&qdev->release_idr_lock); - if (!release) { - DRM_ERROR("failed to find id in release_idr\n"); - return NULL; - } + release = xa_load(&qdev->releases, id); + if (!release) + DRM_ERROR("failed to find id in releases\n"); return release; }