From patchwork Thu Feb 21 18:41:21 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: 10825489 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 0EA461390 for ; Fri, 22 Feb 2019 08:22:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 005F231AF8 for ; Fri, 22 Feb 2019 08:22:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8FB531B41; Fri, 22 Feb 2019 08:22:01 +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 8828431AF8 for ; Fri, 22 Feb 2019 08:22:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 721678940E; Fri, 22 Feb 2019 08:21:24 +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 712D688FCF for ; Thu, 21 Feb 2019 18:42:28 +0000 (UTC) Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1gwtIi-0000a7-1v; Thu, 21 Feb 2019 18:42:28 +0000 From: Matthew Wilcox To: dri-devel@lists.freedesktop.org Subject: [PATCH 01/34] drm: Convert drm_minors_idr to XArray Date: Thu, 21 Feb 2019 10:41:21 -0800 Message-Id: <20190221184226.2149-2-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=qh0BQsghtpUzPdovPsN8ba7PahoohHOyXJmNfDPbQ2c=; b=kkxQduaLNCNvKutnDiIod9pEG wxVBtinF8+CH/xDQ9uL9khGcI6W0o1D1Q47nkK2RAr/YwbngxDb3PyJ1hoNzMMEY+XpQJoDL/2eQ6 0xnCMcydpqvOjk2cZlcNQC26X5bvnk5jVXgQqp/XkausfbpdVIiOQWX8nYDc9C1H/t7RwDONFNDez PK87bLuhH0BwyuRQfhkjzQk3q0IzbtK4gAT/5zZoiYcsJikafuyjtvzX4NmsfG9c8SQ0AegECVL+7 kJuqNziAvLPI339l6nTddwaI5HzgTVjgjuHzwwoMVaBOUCn+K91VofNPl9pJPv4IPZ1iG+UU0PA00 eqlqvPSuA==; 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 Divide all the indices by 64 to save memory. Signed-off-by: Matthew Wilcox --- drivers/gpu/drm/drm_drv.c | 49 ++++++++++++++------------------------- 1 file changed, 17 insertions(+), 32 deletions(-) diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 12e5e2be7890..17ed29f49060 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -64,8 +64,7 @@ MODULE_PARM_DESC(debug, "Enable debug output, where each bit enables a debug cat "\t\tBit 8 (0x100) will enable DP messages (displayport code)"); module_param_named(debug, drm_debug, int, 0600); -static DEFINE_SPINLOCK(drm_minor_lock); -static struct idr drm_minors_idr; +static DEFINE_XARRAY_FLAGS(drm_minors, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ); /* * If the drm core fails to init for whatever reason, @@ -109,7 +108,6 @@ static struct drm_minor **drm_minor_get_slot(struct drm_device *dev, static int drm_minor_alloc(struct drm_device *dev, unsigned int type) { struct drm_minor *minor; - unsigned long flags; int r; minor = kzalloc(sizeof(*minor), GFP_KERNEL); @@ -118,22 +116,12 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type) minor->type = type; minor->dev = dev; + minor->index = 64 * type; - idr_preload(GFP_KERNEL); - spin_lock_irqsave(&drm_minor_lock, flags); - r = idr_alloc(&drm_minors_idr, - NULL, - 64 * type, - 64 * (type + 1), - GFP_NOWAIT); - spin_unlock_irqrestore(&drm_minor_lock, flags); - idr_preload_end(); - + r = xa_insert_irq(&drm_minors, minor->index / 64, NULL, GFP_KERNEL); if (r < 0) goto err_free; - minor->index = r; - minor->kdev = drm_sysfs_minor_alloc(minor); if (IS_ERR(minor->kdev)) { r = PTR_ERR(minor->kdev); @@ -144,9 +132,7 @@ static int drm_minor_alloc(struct drm_device *dev, unsigned int type) return 0; err_index: - spin_lock_irqsave(&drm_minor_lock, flags); - idr_remove(&drm_minors_idr, minor->index); - spin_unlock_irqrestore(&drm_minor_lock, flags); + xa_erase_irq(&drm_minors, minor->index / 64); err_free: kfree(minor); return r; @@ -164,9 +150,9 @@ static void drm_minor_free(struct drm_device *dev, unsigned int type) put_device(minor->kdev); - spin_lock_irqsave(&drm_minor_lock, flags); - idr_remove(&drm_minors_idr, minor->index); - spin_unlock_irqrestore(&drm_minor_lock, flags); + xa_lock_irqsave(&drm_minors, flags); + __xa_erase(&drm_minors, minor->index / 64); + xa_unlock_irqrestore(&drm_minors, flags); kfree(minor); *slot = NULL; @@ -195,9 +181,9 @@ static int drm_minor_register(struct drm_device *dev, unsigned int type) goto err_debugfs; /* replace NULL with @minor so lookups will succeed from now on */ - spin_lock_irqsave(&drm_minor_lock, flags); - idr_replace(&drm_minors_idr, minor, minor->index); - spin_unlock_irqrestore(&drm_minor_lock, flags); + xa_lock_irqsave(&drm_minors, flags); + __xa_store(&drm_minors, minor->index / 64, minor, 0); + xa_unlock_irqrestore(&drm_minors, flags); DRM_DEBUG("new minor registered %d\n", minor->index); return 0; @@ -217,9 +203,9 @@ static void drm_minor_unregister(struct drm_device *dev, unsigned int type) return; /* replace @minor with NULL so lookups will fail from now on */ - spin_lock_irqsave(&drm_minor_lock, flags); - idr_replace(&drm_minors_idr, NULL, minor->index); - spin_unlock_irqrestore(&drm_minor_lock, flags); + xa_lock_irqsave(&drm_minors, flags); + __xa_store(&drm_minors, minor->index / 64, NULL, 0); + xa_unlock_irqrestore(&drm_minors, flags); device_del(minor->kdev); dev_set_drvdata(minor->kdev, NULL); /* safety belt */ @@ -240,11 +226,11 @@ struct drm_minor *drm_minor_acquire(unsigned int minor_id) struct drm_minor *minor; unsigned long flags; - spin_lock_irqsave(&drm_minor_lock, flags); - minor = idr_find(&drm_minors_idr, minor_id); + xa_lock_irqsave(&drm_minors, flags); + minor = xa_load(&drm_minors, minor_id / 64); if (minor) drm_dev_get(minor->dev); - spin_unlock_irqrestore(&drm_minor_lock, flags); + xa_unlock_irqrestore(&drm_minors, flags); if (!minor) { return ERR_PTR(-ENODEV); @@ -958,7 +944,7 @@ static void drm_core_exit(void) unregister_chrdev(DRM_MAJOR, "drm"); debugfs_remove(drm_debugfs_root); drm_sysfs_destroy(); - idr_destroy(&drm_minors_idr); + WARN_ON(!xa_empty(&drm_minors)); drm_connector_ida_destroy(); } @@ -967,7 +953,6 @@ static int __init drm_core_init(void) int ret; drm_connector_ida_init(); - idr_init(&drm_minors_idr); ret = drm_sysfs_init(); if (ret < 0) {