From patchwork Fri Aug 29 12:01:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 4810361 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 19B6A9F37E for ; Fri, 29 Aug 2014 12:01:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B586320127 for ; Fri, 29 Aug 2014 12:01:21 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 5B1B02011D for ; Fri, 29 Aug 2014 12:01:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DD2D76E6C1; Fri, 29 Aug 2014 05:01:18 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wg0-f44.google.com (mail-wg0-f44.google.com [74.125.82.44]) by gabe.freedesktop.org (Postfix) with ESMTP id 54EA46E6C1 for ; Fri, 29 Aug 2014 05:01:17 -0700 (PDT) Received: by mail-wg0-f44.google.com with SMTP id m15so2037969wgh.15 for ; Fri, 29 Aug 2014 05:01:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=t3CxVAQR443fdX7QTSsXJ4ctr0Upcgvp5EqegXtNAcA=; b=V3F0Any3cWT+3+5DZnfoSSvy0rYzYN4GyByIPXAeGs3wqy+KbIMQeGuZylbqfNpk5F YbrWxuJX8QDmHRV0P3zXeD+ovVSEDMgfHBMOoWrR6dyaBQwDiA4SOsIGV+Da5Uw97ghG MVmDep+8D2CJ2TZCNbKRjhbbtVu++lLfEgXyXYkWpmJjB2usEQIltlHUNjPufsQOeaK1 U0vzuuPVp6T1ikhvtM2LOedfiSOtOYWde61k/vYglHzN/W1UiQza/UmYyvsoBOsMGprf 7ybUNPMuFVarcm/qnDx8wD5zUBhzN7oeHBNHcu2GYV8fnwMYN5dwltvCASrSn8A1ACoS 7dhw== X-Received: by 10.180.39.140 with SMTP id p12mr3428906wik.40.1409313675500; Fri, 29 Aug 2014 05:01:15 -0700 (PDT) Received: from david-tp.localdomain (stgt-4d02e0c1.pool.mediaWays.net. [77.2.224.193]) by mx.google.com with ESMTPSA id cz3sm18089499wjb.23.2014.08.29.05.01.13 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Aug 2014 05:01:14 -0700 (PDT) From: David Herrmann To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/2] drm: make idr_mutex a spinlock Date: Fri, 29 Aug 2014 14:01:00 +0200 Message-Id: <1409313661-20696-1-git-send-email-dh.herrmann@gmail.com> X-Mailer: git-send-email 2.1.0 Cc: Daniel Vetter X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is no reason to use a heavy mutex for idr protection. Use a spinlock and make idr-allocation use idr_preload(). This patch also makes mode-object lookup irq-save, in case you ever wanna lookup modeset objects from interrupts. This is just a side-effect of avoiding a mutex. Signed-off-by: David Herrmann --- drivers/gpu/drm/drm_crtc.c | 34 ++++++++++++++++++++-------------- include/drm/drm_crtc.h | 4 ++-- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 61b6978..97eba56 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -283,8 +283,10 @@ static int drm_mode_object_get_reg(struct drm_device *dev, { int ret; - mutex_lock(&dev->mode_config.idr_mutex); - ret = idr_alloc(&dev->mode_config.crtc_idr, register_obj ? obj : NULL, 1, 0, GFP_KERNEL); + idr_preload(GFP_KERNEL); + spin_lock_irq(&dev->mode_config.idr_lock); + + ret = idr_alloc(&dev->mode_config.crtc_idr, register_obj ? obj : NULL, 1, 0, GFP_NOWAIT); if (ret >= 0) { /* * Set up the object linking under the protection of the idr @@ -293,7 +295,9 @@ static int drm_mode_object_get_reg(struct drm_device *dev, obj->id = ret; obj->type = obj_type; } - mutex_unlock(&dev->mode_config.idr_mutex); + + spin_unlock_irq(&dev->mode_config.idr_lock); + idr_preload_end(); return ret < 0 ? ret : 0; } @@ -322,9 +326,9 @@ int drm_mode_object_get(struct drm_device *dev, static void drm_mode_object_register(struct drm_device *dev, struct drm_mode_object *obj) { - mutex_lock(&dev->mode_config.idr_mutex); + spin_lock_irq(&dev->mode_config.idr_lock); idr_replace(&dev->mode_config.crtc_idr, obj, obj->id); - mutex_unlock(&dev->mode_config.idr_mutex); + spin_unlock_irq(&dev->mode_config.idr_lock); } /** @@ -339,17 +343,18 @@ static void drm_mode_object_register(struct drm_device *dev, void drm_mode_object_put(struct drm_device *dev, struct drm_mode_object *object) { - mutex_lock(&dev->mode_config.idr_mutex); + spin_lock_irq(&dev->mode_config.idr_lock); idr_remove(&dev->mode_config.crtc_idr, object->id); - mutex_unlock(&dev->mode_config.idr_mutex); + spin_unlock_irq(&dev->mode_config.idr_lock); } static struct drm_mode_object *_object_find(struct drm_device *dev, uint32_t id, uint32_t type) { struct drm_mode_object *obj = NULL; + unsigned long flags; - mutex_lock(&dev->mode_config.idr_mutex); + spin_lock_irqsave(&dev->mode_config.idr_lock, flags); obj = idr_find(&dev->mode_config.crtc_idr, id); if (obj && type != DRM_MODE_OBJECT_ANY && obj->type != type) obj = NULL; @@ -358,7 +363,7 @@ static struct drm_mode_object *_object_find(struct drm_device *dev, /* don't leak out unref'd fb's */ if (obj && (obj->type == DRM_MODE_OBJECT_FB)) obj = NULL; - mutex_unlock(&dev->mode_config.idr_mutex); + spin_unlock_irqrestore(&dev->mode_config.idr_lock, flags); return obj; } @@ -433,9 +438,9 @@ EXPORT_SYMBOL(drm_framebuffer_init); static void __drm_framebuffer_unregister(struct drm_device *dev, struct drm_framebuffer *fb) { - mutex_lock(&dev->mode_config.idr_mutex); + spin_lock_irq(&dev->mode_config.idr_lock); idr_remove(&dev->mode_config.crtc_idr, fb->base.id); - mutex_unlock(&dev->mode_config.idr_mutex); + spin_unlock_irq(&dev->mode_config.idr_lock); fb->base.id = 0; } @@ -465,14 +470,15 @@ static struct drm_framebuffer *__drm_framebuffer_lookup(struct drm_device *dev, { struct drm_mode_object *obj = NULL; struct drm_framebuffer *fb; + unsigned long flags; - mutex_lock(&dev->mode_config.idr_mutex); + spin_lock_irqsave(&dev->mode_config.idr_lock, flags); obj = idr_find(&dev->mode_config.crtc_idr, id); if (!obj || (obj->type != DRM_MODE_OBJECT_FB) || (obj->id != id)) fb = NULL; else fb = obj_to_fb(obj); - mutex_unlock(&dev->mode_config.idr_mutex); + spin_unlock_irqrestore(&dev->mode_config.idr_lock, flags); return fb; } @@ -5049,7 +5055,7 @@ void drm_mode_config_init(struct drm_device *dev) { mutex_init(&dev->mode_config.mutex); drm_modeset_lock_init(&dev->mode_config.connection_mutex); - mutex_init(&dev->mode_config.idr_mutex); + spin_lock_init(&dev->mode_config.idr_lock); mutex_init(&dev->mode_config.fb_lock); INIT_LIST_HEAD(&dev->mode_config.fb_list); INIT_LIST_HEAD(&dev->mode_config.crtc_list); diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index 77d9763..9c57b56 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -742,7 +742,7 @@ struct drm_mode_group { /** * drm_mode_config - Mode configuration control structure * @mutex: mutex protecting KMS related lists and structures - * @idr_mutex: mutex for KMS ID allocation and management + * @idr_lock: lock for KMS ID allocation and management * @crtc_idr: main KMS ID tracking object * @num_fb: number of fbs available * @fb_list: list of framebuffers available @@ -772,7 +772,7 @@ struct drm_mode_config { struct mutex mutex; /* protects configuration (mode lists etc.) */ struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */ struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */ - struct mutex idr_mutex; /* for IDR management */ + spinlock_t idr_lock; /* for IDR management */ struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */ /* this is limited to one for now */