From patchwork Thu Feb 21 18:41:37 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: 10825429 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 A4372139A for ; Fri, 22 Feb 2019 08:21:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 93FB631AFD for ; Fri, 22 Feb 2019 08:21:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8819131B24; Fri, 22 Feb 2019 08:21:11 +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 1DF9F31B0B for ; Fri, 22 Feb 2019 08:21:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ED353892A5; Fri, 22 Feb 2019 08:20:53 +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 4A5F58906D for ; Thu, 21 Feb 2019 18:42:31 +0000 (UTC) Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1gwtIk-0000ck-SH; Thu, 21 Feb 2019 18:42:30 +0000 From: Matthew Wilcox To: dri-devel@lists.freedesktop.org Subject: [PATCH 09/34] drm: Convert ctx_idr to XArray Date: Thu, 21 Feb 2019 10:41:37 -0800 Message-Id: <20190221184226.2149-18-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=fXECXSzq8HEYfs+e9MRQvlIFen4L/c51qg3wm/fUWAs=; b=ldXS9uaF27X2Pjk2bhvQfU65j AUaq0n/ViF9CpNwJm9Z3cgRReoOlAf6br6sJYA3fj3NeS4piVEvgi2UxM1eyuNGfdCFlPWSa0Uljt bz8GIA6oBuZOBwtUQuiKXnh0tOHj+79HK4Tq+LjHJIwPfiSdaYKQcE9O79rWa5PkfEoUxLN8Vm6qg wCZ+xMU1Qz/lnJtrwK7rOcHjiK8RhYrZg8T3TwHENYKkMo1JSBIcEVB78xmQ1m+g4z5WSw/GvpmL/ AZ9sQB4YcRiUklEoPtXvDErVumtwCpY0gDS1rOZEJcw4TmUepfmuoahaCTyaeMbfd3hF6xsZz2jwK Pla3D0RZg==; 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/drm_context.c | 42 +++++++++++++++-------------------- include/drm/drm_device.h | 2 +- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/drm_context.c b/drivers/gpu/drm/drm_context.c index 506663c69b0a..b498e311cf57 100644 --- a/drivers/gpu/drm/drm_context.c +++ b/drivers/gpu/drm/drm_context.c @@ -48,8 +48,7 @@ struct drm_ctx_list { * \param ctx_handle context handle. * * Clears the bit specified by \p ctx_handle in drm_device::ctx_bitmap and the entry - * in drm_device::ctx_idr, while holding the drm_device::struct_mutex - * lock. + * in drm_device::ctxts. */ void drm_legacy_ctxbitmap_free(struct drm_device * dev, int ctx_handle) { @@ -57,9 +56,7 @@ void drm_legacy_ctxbitmap_free(struct drm_device * dev, int ctx_handle) !drm_core_check_feature(dev, DRIVER_LEGACY)) return; - mutex_lock(&dev->struct_mutex); - idr_remove(&dev->ctx_idr, ctx_handle); - mutex_unlock(&dev->struct_mutex); + xa_erase(&dev->ctxts, ctx_handle); } /** @@ -68,18 +65,17 @@ void drm_legacy_ctxbitmap_free(struct drm_device * dev, int ctx_handle) * \param dev DRM device. * \return (non-negative) context handle on success or a negative number on failure. * - * Allocate a new idr from drm_device::ctx_idr while holding the - * drm_device::struct_mutex lock. + * Allocate a new id from drm_device::ctxts. */ static int drm_legacy_ctxbitmap_next(struct drm_device * dev) { - int ret; + int ret, id; - mutex_lock(&dev->struct_mutex); - ret = idr_alloc(&dev->ctx_idr, NULL, DRM_RESERVED_CONTEXTS, 0, - GFP_KERNEL); - mutex_unlock(&dev->struct_mutex); - return ret; + ret = xa_alloc(&dev->ctxts, &id, NULL, + XA_LIMIT(DRM_RESERVED_CONTEXTS, INT_MAX), GFP_KERNEL); + if (ret < 0) + return ret; + return id; } /** @@ -87,7 +83,7 @@ static int drm_legacy_ctxbitmap_next(struct drm_device * dev) * * \param dev DRM device. * - * Initialise the drm_device::ctx_idr + * Initialise the drm_device::ctxts */ void drm_legacy_ctxbitmap_init(struct drm_device * dev) { @@ -95,7 +91,7 @@ void drm_legacy_ctxbitmap_init(struct drm_device * dev) !drm_core_check_feature(dev, DRIVER_LEGACY)) return; - idr_init(&dev->ctx_idr); + xa_init_flags(&dev->ctxts, XA_FLAGS_ALLOC); } /** @@ -103,8 +99,8 @@ void drm_legacy_ctxbitmap_init(struct drm_device * dev) * * \param dev DRM device. * - * Free all idr members using drm_ctx_sarea_free helper function - * while holding the drm_device::struct_mutex lock. + * Free all memory used by the ctxts data structure. Does not free the + * pointers in that data structures. */ void drm_legacy_ctxbitmap_cleanup(struct drm_device * dev) { @@ -112,9 +108,7 @@ void drm_legacy_ctxbitmap_cleanup(struct drm_device * dev) !drm_core_check_feature(dev, DRIVER_LEGACY)) return; - mutex_lock(&dev->struct_mutex); - idr_destroy(&dev->ctx_idr); - mutex_unlock(&dev->struct_mutex); + xa_destroy(&dev->ctxts); } /** @@ -166,7 +160,7 @@ void drm_legacy_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file) * \param arg user argument pointing to a drm_ctx_priv_map structure. * \return zero on success or a negative number on failure. * - * Gets the map from drm_device::ctx_idr with the handle specified and + * Gets the map from drm_device::ctxts with the handle specified and * returns its handle. */ int drm_legacy_getsareactx(struct drm_device *dev, void *data, @@ -182,7 +176,7 @@ int drm_legacy_getsareactx(struct drm_device *dev, void *data, mutex_lock(&dev->struct_mutex); - map = idr_find(&dev->ctx_idr, request->ctx_id); + map = xa_load(&dev->ctxts, request->ctx_id); if (!map) { mutex_unlock(&dev->struct_mutex); return -EINVAL; @@ -215,7 +209,7 @@ int drm_legacy_getsareactx(struct drm_device *dev, void *data, * \return zero on success or a negative number on failure. * * Searches the mapping specified in \p arg and update the entry in - * drm_device::ctx_idr with it. + * drm_device::ctxts with it. */ int drm_legacy_setsareactx(struct drm_device *dev, void *data, struct drm_file *file_priv) @@ -243,7 +237,7 @@ int drm_legacy_setsareactx(struct drm_device *dev, void *data, if (!map) goto bad; - if (IS_ERR(idr_replace(&dev->ctx_idr, map, request->ctx_id))) + if (xa_is_err(xa_store(&dev->ctxts, request->ctx_id, map, GFP_KERNEL))) goto bad; mutex_unlock(&dev->struct_mutex); diff --git a/include/drm/drm_device.h b/include/drm/drm_device.h index 52e271b97de8..b3b025b76f3e 100644 --- a/include/drm/drm_device.h +++ b/include/drm/drm_device.h @@ -115,7 +115,7 @@ struct drm_device { struct list_head ctxlist; /**< Linked list of context handles */ struct mutex ctxlist_mutex; /**< For ctxlist */ - struct idr ctx_idr; + struct xarray ctxts; struct list_head vmalist; /**< List of vmas (for debugging) */