From patchwork Thu Sep 19 15:48:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 2912081 Return-Path: X-Original-To: patchwork-linux-btrfs@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 AC2999F1F1 for ; Thu, 19 Sep 2013 15:48:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 915CE2042B for ; Thu, 19 Sep 2013 15:48:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8B2C820424 for ; Thu, 19 Sep 2013 15:48:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752662Ab3ISPsN (ORCPT ); Thu, 19 Sep 2013 11:48:13 -0400 Received: from dkim2.fusionio.com ([66.114.96.54]:45514 "EHLO dkim2.fusionio.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751562Ab3ISPsL (ORCPT ); Thu, 19 Sep 2013 11:48:11 -0400 Received: from mx2.fusionio.com (unknown [10.101.1.160]) by dkim2.fusionio.com (Postfix) with ESMTP id EA8389A0404 for ; Thu, 19 Sep 2013 09:48:10 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fusionio.com; s=default; t=1379605691; bh=FqwxyL4sb0aAkY7rLlCzOI3EU8swtmWpQ+rIckpiaFM=; h=From:To:CC:Subject:Date; b=LaIiRVs3QMSN40WJQudUyST/r6D+78HXWUeCyNhMpGxbF8zUT/pENFGaHIAJa4h+W zUzebAkg/Dr8yCPc2IOqEnN7hio08cZ79ESBw26jUs+skHgAVii4FZ+I/mIaCGuPCw XOTfLhxrzZlAfmoMnFsiLrJDsUsspUoa0SQNi95s= X-ASG-Debug-ID: 1379605690-0421b50220406c50001-6jHSXT Received: from CAS1.int.fusionio.com (cas1.int.fusionio.com [10.101.1.40]) by mx2.fusionio.com with ESMTP id NSdDBD1itsdmRoPU (version=TLSv1 cipher=AES128-SHA bits=128 verify=NO); Thu, 19 Sep 2013 09:48:10 -0600 (MDT) X-Barracuda-Envelope-From: JBacik@fusionio.com Received: from localhost (10.101.1.160) by mail.fusionio.com (10.101.1.40) with Microsoft SMTP Server (TLS) id 14.3.158.1; Thu, 19 Sep 2013 09:48:09 -0600 From: Josef Bacik To: CC: , , , , Subject: [PATCH 1/2] rwsem: add rwsem_is_contended V2 Date: Thu, 19 Sep 2013 11:48:07 -0400 X-ASG-Orig-Subj: [PATCH 1/2] rwsem: add rwsem_is_contended V2 Message-ID: <1379605688-987-1-git-send-email-jbacik@fusionio.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.101.1.160] X-Barracuda-Connect: cas1.int.fusionio.com[10.101.1.40] X-Barracuda-Start-Time: 1379605690 X-Barracuda-Encrypted: AES128-SHA X-Barracuda-URL: http://10.101.1.181:8000/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at fusionio.com X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=9.0 tests=BSF_SC0_MISMATCH_TO X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.2.140754 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 BSF_SC0_MISMATCH_TO Envelope rcpt doesn't match header Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham 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 Btrfs needs a simple way to know if it needs to let go of it's read lock on a rwsem. Introduce rwsem_is_contended to check to see if there are any waiters on this rwsem currently. This is just a hueristic, it is meant to be light and not 100% accurate and called by somebody already holding on to the rwsem in either read or write. Thanks, Signed-off-by: Josef Bacik --- V1->V2: took everybodys suggestions and simplified it to just one function in rwsem.h so it works for both the spinlock case and non-spinlock case. include/linux/rwsem.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/linux/rwsem.h b/include/linux/rwsem.h index 0616ffe..c340493 100644 --- a/include/linux/rwsem.h +++ b/include/linux/rwsem.h @@ -75,6 +75,19 @@ do { \ } while (0) /* + * This is the same regardless of which rwsem implementation that is being used. + * It is just a heuristic meant to be called by somebody alreadying holding the + * rwsem to see if somebody from the opposite type is wanting access to the + * lock. + */ +static inline int rwsem_is_contended(struct rw_semaphore *sem) +{ + if (!list_empty(&sem->wait_list)) + return 1; + return 0; +} + +/* * lock for reading */ extern void down_read(struct rw_semaphore *sem);