From patchwork Thu Aug 10 19:28:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Wilson X-Patchwork-Id: 9894549 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A88A560352 for ; Thu, 10 Aug 2017 19:28:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B0FF28B4F for ; Thu, 10 Aug 2017 19:28:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8FFAB28B57; Thu, 10 Aug 2017 19:28:48 +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=-4.2 required=2.0 tests=BAYES_00, 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 5453A28B4F for ; Thu, 10 Aug 2017 19:28:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7A5446E5DE; Thu, 10 Aug 2017 19:28:45 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from fireflyinternet.com (mail.fireflyinternet.com [109.228.58.192]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6FB776E5DE; Thu, 10 Aug 2017 19:28:43 +0000 (UTC) X-Default-Received-SPF: pass (skip=forwardok (res=PASS)) x-ip-name=78.156.65.138; Received: from haswell.alporthouse.com (unverified [78.156.65.138]) by fireflyinternet.com (Firefly Internet (M1)) with ESMTP id 8205630-1500050 for multiple; Thu, 10 Aug 2017 20:28:36 +0100 Received: by haswell.alporthouse.com (sSMTP sendmail emulation); Thu, 10 Aug 2017 20:28:35 +0100 From: Chris Wilson To: dri-devel@lists.freedesktop.org Subject: [PATCH] drm: RCU syncobj Date: Thu, 10 Aug 2017 20:28:30 +0100 Message-Id: <20170810192830.439-1-chris@chris-wilson.co.uk> X-Mailer: git-send-email 2.13.3 X-Originating-IP: 78.156.65.138 X-Country: code=GB country="United Kingdom" ip=78.156.65.138 Cc: intel-gfx@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 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-Virus-Scanned: ClamAV using ClamSMTP The first contention point we hit using syncobjs from concurrent threads is the spinlock guarding drm_syncobj_find(). We use an RCU-safe idr to store the syncobj, so if we employ RCU to free drm_syncobj and be careful in acquiring the reference (as we may now observe zombie synocbjs in the idr) we can do a lockless drm_syncobj_find(). Signed-off-by: Chris Wilson --- drivers/gpu/drm/drm_syncobj.c | 10 +++++----- include/drm/drm_syncobj.h | 2 ++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_syncobj.c b/drivers/gpu/drm/drm_syncobj.c index 38eca783a78c..cb5de50174ed 100644 --- a/drivers/gpu/drm/drm_syncobj.c +++ b/drivers/gpu/drm/drm_syncobj.c @@ -69,14 +69,14 @@ struct drm_syncobj *drm_syncobj_find(struct drm_file *file_private, { struct drm_syncobj *syncobj; - spin_lock(&file_private->syncobj_table_lock); + rcu_read_lock(); /* Check if we currently have a reference on the object */ syncobj = idr_find(&file_private->syncobj_idr, handle); - if (syncobj) - drm_syncobj_get(syncobj); + if (syncobj && !kref_get_unless_zero(&syncobj->refcount)) + syncobj = NULL; - spin_unlock(&file_private->syncobj_table_lock); + rcu_read_unlock(); return syncobj; } @@ -151,7 +151,7 @@ void drm_syncobj_free(struct kref *kref) syncobj_notify(syncobj, NULL); dma_fence_put(syncobj->fence); - kfree(syncobj); + kfree_rcu(syncobj, rcu); } EXPORT_SYMBOL(drm_syncobj_free); diff --git a/include/drm/drm_syncobj.h b/include/drm/drm_syncobj.h index b8f60d6793fb..88c949d2cb34 100644 --- a/include/drm/drm_syncobj.h +++ b/include/drm/drm_syncobj.h @@ -56,6 +56,8 @@ struct drm_syncobj { * a file backing for this syncobj. */ struct file *file; + + struct rcu_head rcu; }; void drm_syncobj_free(struct kref *kref);