From patchwork Thu Mar 24 09:41:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tejun Heo X-Patchwork-Id: 658391 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id p2O9gSb9001504 for ; Thu, 24 Mar 2011 09:42:28 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755790Ab1CXJl6 (ORCPT ); Thu, 24 Mar 2011 05:41:58 -0400 Received: from mail-fx0-f46.google.com ([209.85.161.46]:56629 "EHLO mail-fx0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755743Ab1CXJl4 (ORCPT ); Thu, 24 Mar 2011 05:41:56 -0400 Received: by fxm17 with SMTP id 17so8215956fxm.19 for ; Thu, 24 Mar 2011 02:41:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:date:from:to:cc:subject:message-id :references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=XCYPhrptixOhmpdkJUCIpBNOh/CQW9/fuf5PYAnwshk=; b=hc2LxxM9T03BSv86E/ksKY4+T5iuEyIqoM6jy1IjtDIczPZKHoUHxe2rr038PIz2f0 uIT/AT/p8uS8NEeFqjp71bRflujA411hQWuC+1KIv78LXheiBpM5ChIbUr97ND+6b+3d amxLLtx+2KgoOzH8lmwyhIpr7GefvK7qaXwDg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=SXefWbrMuULKAa6WfQQTDcJc4LDmaX4eSuQpO6ytXg+F7WnRjbpkWvRZEzHERmC8aY nku5kfsJjbkn5P0M446JueGVpoECz2cbTr51mSZ/jvg5i6buyLtdv0oD/6Y1WhGH4TQV zDjNqk7TInygR7mVA2Z5xu0vt5cIgqqQXlKbs= Received: by 10.223.106.76 with SMTP id w12mr9431330fao.104.1300959715075; Thu, 24 Mar 2011 02:41:55 -0700 (PDT) Received: from htj.dyndns.org ([130.75.117.88]) by mx.google.com with ESMTPS id b18sm3596690fak.32.2011.03.24.02.41.53 (version=SSLv3 cipher=OTHER); Thu, 24 Mar 2011 02:41:54 -0700 (PDT) Date: Thu, 24 Mar 2011 10:41:51 +0100 From: Tejun Heo To: Peter Zijlstra , Ingo Molnar , Linus Torvalds , Andrew Morton , Chris Mason Cc: linux-kernel@vger.kernel.org, linux-btrfs@vger.kernel.org Subject: [PATCH 2/2] mutex: Apply adaptive spinning on mutex_trylock() Message-ID: <20110324094151.GE12038@htj.dyndns.org> References: <20110323153727.GB12003@htj.dyndns.org> <20110324094119.GD12038@htj.dyndns.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20110324094119.GD12038@htj.dyndns.org> User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Thu, 24 Mar 2011 09:42:28 +0000 (UTC) Index: work/kernel/mutex.c =================================================================== --- work.orig/kernel/mutex.c +++ work/kernel/mutex.c @@ -443,6 +443,15 @@ static inline int __mutex_trylock_slowpa unsigned long flags; int prev; + preempt_disable(); + + if (mutex_spin(lock)) { + mutex_set_owner(lock); + mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_); + preempt_enable(); + return 1; + } + spin_lock_mutex(&lock->wait_lock, flags); prev = atomic_xchg(&lock->count, -1); @@ -456,6 +465,7 @@ static inline int __mutex_trylock_slowpa atomic_set(&lock->count, 0); spin_unlock_mutex(&lock->wait_lock, flags); + preempt_enable(); return prev == 1; }