From patchwork Tue Jan 15 12:33:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maarten Lankhorst X-Patchwork-Id: 14043 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id E4B1023F81 for ; Tue, 15 Jan 2013 12:34:29 +0000 (UTC) Received: from mail-vb0-f41.google.com (mail-vb0-f41.google.com [209.85.212.41]) by fiordland.canonical.com (Postfix) with ESMTP id 8B1AFA18807 for ; Tue, 15 Jan 2013 12:34:29 +0000 (UTC) Received: by mail-vb0-f41.google.com with SMTP id l22so34669vbn.14 for ; Tue, 15 Jan 2013 04:34:29 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:dkim-signature:x-received:from:to:date:message-id :x-mailer:in-reply-to:references:cc:subject:x-beenthere :x-mailman-version:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:sender:errors-to:x-gm-message-state; bh=zqEoKnc8wDC+iIErzwlvbFSvQofTN86mHxsDH+aBMaA=; b=mOS/aH58ocSNPbMBeVapfYMIGU0GlelfHgW0kr84yz3GPPZ/KHkQHRc94Cdby3aXCI FWLVqYbOjSF7DxQth4cP5ypHxXouTICGcVnf2kkRMWY7eYoW3XDsCIStAhFGSCweRaaT 0aJL31dGKV49qzRm69kBv1qHUkOnCXDArVOMaS6sgTybjw0MI0CvRSuQVrMIvmIaa6Ct P36HhYz7q3zkF/B8WJlqO9GFdu4Aaydu8WY1TUm02ewY6Z+6LcdrLhEHkIvrHQEXta5F Ey6WyaHXEohlNOXCK1UtiJCFYCCzwGwISS3r+KwZoGSmGyihcTvqa7reo/ivy5vav89m npkA== X-Received: by 10.52.70.205 with SMTP id o13mr91658342vdu.75.1358253268934; Tue, 15 Jan 2013 04:34:28 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.145.101 with SMTP id st5csp109683veb; Tue, 15 Jan 2013 04:34:28 -0800 (PST) X-Received: by 10.204.9.11 with SMTP id j11mr40062454bkj.53.1358253265633; Tue, 15 Jan 2013 04:34:25 -0800 (PST) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id hy12si26900968bkc.73.2013.01.15.04.34.24; Tue, 15 Jan 2013 04:34:25 -0800 (PST) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@gmail.com Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1Tv5ig-0003HM-IF; Tue, 15 Jan 2013 12:34:22 +0000 Received: from mail-wg0-f49.google.com ([74.125.82.49]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1Tv5ie-0003HH-RS for linaro-mm-sig@lists.linaro.org; Tue, 15 Jan 2013 12:34:20 +0000 Received: by mail-wg0-f49.google.com with SMTP id 15so23523wgd.28 for ; Tue, 15 Jan 2013 04:34:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=6UPALgFVWF1i+eXUbzFnpL0JvzszccuxSdfJlpsTAl4=; b=hcCGHM9YbqQNqla+AIBa4xHFstdumjUouRQGzl6ORNxO9UqEpUS4wv3IGY5ggYcXTF gJiQAtXQqDfZ065iHFUnQgEf6sinsEjm/aOdgH/JMWYwi3IU6MrDbCsaVvV2VvoseSJw w1zpBpJsxs9UmxyBjgVEXBd3aapg4lflw46DOzKefHWhbA6M+wnF8zFTXITfrMiR/NNd A4blFcf5aUlCqBkRoIVX7dBhDk3xM66SZobTUpXmZhd5UsbH0Fnn9RwH+Xq8OwG22X1j +ASr195SxLpoDN36UyT94xpKHV6fXUjOaJU0Av7V5Cdold4qD65U/ARTcZJqqE87OVLe Cnug== X-Received: by 10.194.76.237 with SMTP id n13mr141742455wjw.57.1358253260713; Tue, 15 Jan 2013 04:34:20 -0800 (PST) Received: from localhost (5ED48CEF.cm-7-5c.dynamic.ziggo.nl. [94.212.140.239]) by mx.google.com with ESMTPS id ew4sm3583241wid.11.2013.01.15.04.34.18 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 15 Jan 2013 04:34:20 -0800 (PST) Received: by localhost (sSMTP sendmail emulation); Tue, 15 Jan 2013 13:34:17 +0100 From: Maarten Lankhorst To: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org Date: Tue, 15 Jan 2013 13:33:58 +0100 Message-Id: <1358253244-11453-2-git-send-email-maarten.lankhorst@canonical.com> X-Mailer: git-send-email 1.8.0.3 In-Reply-To: <1358253244-11453-1-git-send-email-maarten.lankhorst@canonical.com> References: <1358253244-11453-1-git-send-email-maarten.lankhorst@canonical.com> Cc: Maarten Lankhorst Subject: [Linaro-mm-sig] [PATCH 1/7] arch: add __mutex_fastpath_lock_retval_arg to generic/sh/x86/powerpc/ia64 X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQlawk3gD6RtmobDhjEJxjtg51DVB7GUMFNJHrT7Sq+w5mJ7cDgQpmRDdPapE0MyQj/LL/6Z Needed for reservation slowpath. --- arch/ia64/include/asm/mutex.h | 20 ++++++++++++++++++++ arch/powerpc/include/asm/mutex.h | 20 ++++++++++++++++++++ arch/sh/include/asm/mutex-llsc.h | 20 ++++++++++++++++++++ arch/x86/include/asm/mutex_32.h | 20 ++++++++++++++++++++ arch/x86/include/asm/mutex_64.h | 20 ++++++++++++++++++++ include/asm-generic/mutex-dec.h | 20 ++++++++++++++++++++ include/asm-generic/mutex-null.h | 1 + include/asm-generic/mutex-xchg.h | 21 +++++++++++++++++++++ 8 files changed, 142 insertions(+) diff --git a/arch/ia64/include/asm/mutex.h b/arch/ia64/include/asm/mutex.h index bed73a6..2510058 100644 --- a/arch/ia64/include/asm/mutex.h +++ b/arch/ia64/include/asm/mutex.h @@ -44,6 +44,26 @@ __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *)) } /** + * __mutex_fastpath_lock_retval_arg - try to take the lock by moving the count + * from 1 to a 0 value + * @count: pointer of type atomic_t + * @arg: argument to pass along if fastpath fails. + * @fail_fn: function to call if the original value was not 1 + * + * Change the count from 1 to a value lower than 1, and call if + * it wasn't 1 originally. This function returns 0 if the fastpath succeeds, + * or anything the slow path function returns. + */ +static inline int __mutex_fastpath_lock_retval_arg(atomic_t *count, + void *arg, int (*fail_fn)(atomic_t *, void*)) +{ + if (unlikely(ia64_fetchadd4_acq(count, -1) != 1)) + return fail_fn(count, arg); + else + return 0; +} + +/** * __mutex_fastpath_unlock - try to promote the count from 0 to 1 * @count: pointer of type atomic_t * @fail_fn: function to call if the original value was not 0 diff --git a/arch/powerpc/include/asm/mutex.h b/arch/powerpc/include/asm/mutex.h index 5399f7e..df4bcff 100644 --- a/arch/powerpc/include/asm/mutex.h +++ b/arch/powerpc/include/asm/mutex.h @@ -97,6 +97,26 @@ __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *)) } /** + * __mutex_fastpath_lock_retval_arg - try to take the lock by moving the count + * from 1 to a 0 value + * @count: pointer of type atomic_t + * @arg: argument to pass along if fastpath fails. + * @fail_fn: function to call if the original value was not 1 + * + * Change the count from 1 to a value lower than 1, and call if + * it wasn't 1 originally. This function returns 0 if the fastpath succeeds, + * or anything the slow path function returns. + */ +static inline int __mutex_fastpath_lock_retval_arg(atomic_t *count, + void *arg, int (*fail_fn)(atomic_t *, void*)) +{ + if (unlikely(__mutex_dec_return_lock(count) < 0)) + return fail_fn(count, arg); + else + return 0; +} + +/** * __mutex_fastpath_unlock - try to promote the count from 0 to 1 * @count: pointer of type atomic_t * @fail_fn: function to call if the original value was not 0 diff --git a/arch/sh/include/asm/mutex-llsc.h b/arch/sh/include/asm/mutex-llsc.h index 090358a..b68dd6d 100644 --- a/arch/sh/include/asm/mutex-llsc.h +++ b/arch/sh/include/asm/mutex-llsc.h @@ -56,6 +56,26 @@ __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *)) return __res; } +static inline int __mutex_fastpath_lock_retval_arg(atomic_t *count, + void *arg, int (*fail_fn)(atomic_t *, void *)) +{ + int __done, __res; + + __asm__ __volatile__ ( + "movli.l @%2, %0 \n" + "add #-1, %0 \n" + "movco.l %0, @%2 \n" + "movt %1 \n" + : "=&z" (__res), "=&r" (__done) + : "r" (&(count)->counter) + : "t"); + + if (unlikely(!__done || __res != 0)) + __res = fail_fn(count, arg); + + return __res; +} + static inline void __mutex_fastpath_unlock(atomic_t *count, void (*fail_fn)(atomic_t *)) { diff --git a/arch/x86/include/asm/mutex_32.h b/arch/x86/include/asm/mutex_32.h index 03f90c8..34f77f9 100644 --- a/arch/x86/include/asm/mutex_32.h +++ b/arch/x86/include/asm/mutex_32.h @@ -58,6 +58,26 @@ static inline int __mutex_fastpath_lock_retval(atomic_t *count, } /** + * __mutex_fastpath_lock_retval_arg - try to take the lock by moving the count + * from 1 to a 0 value + * @count: pointer of type atomic_t + * @arg: argument to pass along if fastpath fails. + * @fail_fn: function to call if the original value was not 1 + * + * Change the count from 1 to a value lower than 1, and call if + * it wasn't 1 originally. This function returns 0 if the fastpath succeeds, + * or anything the slow path function returns. + */ +static inline int __mutex_fastpath_lock_retval_arg(atomic_t *count, + void *arg, int (*fail_fn)(atomic_t *, void*)) +{ + if (unlikely(atomic_dec_return(count) < 0)) + return fail_fn(count, arg); + else + return 0; +} + +/** * __mutex_fastpath_unlock - try to promote the mutex from 0 to 1 * @count: pointer of type atomic_t * @fail_fn: function to call if the original value was not 0 diff --git a/arch/x86/include/asm/mutex_64.h b/arch/x86/include/asm/mutex_64.h index 68a87b0..148249e 100644 --- a/arch/x86/include/asm/mutex_64.h +++ b/arch/x86/include/asm/mutex_64.h @@ -53,6 +53,26 @@ static inline int __mutex_fastpath_lock_retval(atomic_t *count, } /** + * __mutex_fastpath_lock_retval_arg - try to take the lock by moving the count + * from 1 to a 0 value + * @count: pointer of type atomic_t + * @arg: argument to pass along if fastpath fails. + * @fail_fn: function to call if the original value was not 1 + * + * Change the count from 1 to a value lower than 1, and call if + * it wasn't 1 originally. This function returns 0 if the fastpath succeeds, + * or anything the slow path function returns. + */ +static inline int __mutex_fastpath_lock_retval_arg(atomic_t *count, + void *arg, int (*fail_fn)(atomic_t *, void*)) +{ + if (unlikely(atomic_dec_return(count) < 0)) + return fail_fn(count, arg); + else + return 0; +} + +/** * __mutex_fastpath_unlock - increment and call function if nonpositive * @v: pointer of type atomic_t * @fail_fn: function to call if the result is nonpositive diff --git a/include/asm-generic/mutex-dec.h b/include/asm-generic/mutex-dec.h index f104af7..f5d027e 100644 --- a/include/asm-generic/mutex-dec.h +++ b/include/asm-generic/mutex-dec.h @@ -43,6 +43,26 @@ __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *)) } /** + * __mutex_fastpath_lock_retval_arg - try to take the lock by moving the count + * from 1 to a 0 value + * @count: pointer of type atomic_t + * @arg: argument to pass along if fastpath fails. + * @fail_fn: function to call if the original value was not 1 + * + * Change the count from 1 to a value lower than 1, and call if + * it wasn't 1 originally. This function returns 0 if the fastpath succeeds, + * or anything the slow path function returns. + */ +static inline int +__mutex_fastpath_lock_retval_arg(atomic_t *count, void *arg, + int (*fail_fn)(atomic_t *, void*)) +{ + if (unlikely(atomic_dec_return(count) < 0)) + return fail_fn(count, arg); + return 0; +} + +/** * __mutex_fastpath_unlock - try to promote the count from 0 to 1 * @count: pointer of type atomic_t * @fail_fn: function to call if the original value was not 0 diff --git a/include/asm-generic/mutex-null.h b/include/asm-generic/mutex-null.h index e1bbbc7..991e9c3 100644 --- a/include/asm-generic/mutex-null.h +++ b/include/asm-generic/mutex-null.h @@ -12,6 +12,7 @@ #define __mutex_fastpath_lock(count, fail_fn) fail_fn(count) #define __mutex_fastpath_lock_retval(count, fail_fn) fail_fn(count) +#define __mutex_fastpath_lock_retval_arg(count, arg, fail_fn) fail_fn(count, arg) #define __mutex_fastpath_unlock(count, fail_fn) fail_fn(count) #define __mutex_fastpath_trylock(count, fail_fn) fail_fn(count) #define __mutex_slowpath_needs_to_unlock() 1 diff --git a/include/asm-generic/mutex-xchg.h b/include/asm-generic/mutex-xchg.h index c04e0db..d9cc971 100644 --- a/include/asm-generic/mutex-xchg.h +++ b/include/asm-generic/mutex-xchg.h @@ -55,6 +55,27 @@ __mutex_fastpath_lock_retval(atomic_t *count, int (*fail_fn)(atomic_t *)) } /** + * __mutex_fastpath_lock_retval_arg - try to take the lock by moving the count + * from 1 to a 0 value + * @count: pointer of type atomic_t + * @arg: argument to pass along if fastpath fails. + * @fail_fn: function to call if the original value was not 1 + * + * Change the count from 1 to a value lower than 1, and call if + * it wasn't 1 originally. This function returns 0 if the fastpath succeeds, + * or anything the slow path function returns. + */ +static inline int +__mutex_fastpath_lock_retval_arg(atomic_t *count, void *arg, + int (*fail_fn)(atomic_t *, void*)) +{ + if (unlikely(atomic_xchg(count, 0) != 1)) + if (likely(atomic_xchg(count, -1) != 1)) + return fail_fn(count, arg); + return 0; +} + +/** * __mutex_fastpath_unlock - try to promote the mutex from 0 to 1 * @count: pointer of type atomic_t * @fail_fn: function to call if the original value was not 0