mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maarten Lankhorst <maarten.lankhorst@canonical.com>
To: Maarten Lankhorst <m.b.lankhorst@gmail.com>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org
Subject: Re: [PATCH 1/7] arch: add __mutex_fastpath_lock_retval_arg to generic/sh/x86/powerpc/ia64
Date: Tue, 15 Jan 2013 14:49:52 +0100	[thread overview]
Message-ID: <50F55E80.3060106@canonical.com> (raw)
In-Reply-To: <1358253244-11453-2-git-send-email-maarten.lankhorst@canonical.com>

Again, missing entry :(

Op 15-01-13 13:33, Maarten Lankhorst schreef:
> Needed for reservation slowpath.

I was hoping to convert the 'mutexes' in ttm to proper mutexes, so I extended the
core mutex code slightly to add support for reservations. This requires however
passing an argument to __mutex_fastpath_lock_retval, so I added this for all archs
based on their existing __mutex_fastpath_lock_retval implementation.

I'm guessing this would have to be split up in the final version, but for now it's
easier to edit as a single patch.

> ---
>  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 <fail_fn> 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 <fail_fn> 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 <fail_fn> 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 <fail_fn> 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 <fail_fn> 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 <fail_fn> 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


  reply	other threads:[~2013-01-15 13:49 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-15 12:33 [PATCH 0/7] cross-device reservation for dma-buf support Maarten Lankhorst
2013-01-15 12:33 ` [PATCH 1/7] arch: add __mutex_fastpath_lock_retval_arg to generic/sh/x86/powerpc/ia64 Maarten Lankhorst
2013-01-15 13:49   ` Maarten Lankhorst [this message]
2013-01-15 12:33 ` [PATCH 2/7] mutex: add support for reservation style locks Maarten Lankhorst
2013-01-15 13:43   ` Maarten Lankhorst
2013-01-30  1:07   ` Rob Clark
2013-01-30 11:08     ` Daniel Vetter
2013-01-30 11:52       ` Rob Clark
2013-01-31 13:38         ` Rob Clark
2013-01-30 11:16     ` Maarten Lankhorst
2013-01-15 12:34 ` [PATCH 3/7] sched: allow try_to_wake_up to be used internally outside of core.c Maarten Lankhorst
2013-01-15 12:34 ` [PATCH 4/7] fence: dma-buf cross-device synchronization (v11) Maarten Lankhorst
2013-01-22 15:13   ` [Linaro-mm-sig] " Francesco Lavra
2013-01-23 14:56     ` Maarten Lankhorst
2013-01-23 17:14       ` Francesco Lavra
2013-01-31  9:32   ` Inki Dae
2013-01-31  9:53     ` Maarten Lankhorst
2013-01-31  9:57     ` Daniel Vetter
2013-01-31 14:38       ` Inki Dae
2013-01-31 14:49         ` Daniel Vetter
2013-01-15 12:34 ` [PATCH 5/7] seqno-fence: Hardware dma-buf implementation of fencing (v4) Maarten Lankhorst
2013-01-16  6:28   ` [Linaro-mm-sig] " Inki Dae
2013-01-16 10:36     ` Maarten Lankhorst
2013-01-16 12:00       ` Inki Dae
2013-01-24 14:52       ` Inki Dae
2013-01-15 12:34 ` [PATCH 6/7] reservation: cross-device reservation support Maarten Lankhorst
2013-01-22 16:47   ` [Linaro-mm-sig] " Francesco Lavra
2013-01-22 17:04     ` Maarten Lankhorst
2013-02-04  7:06   ` Inki Dae
2013-02-04  9:57     ` Maarten Lankhorst
2013-02-04 14:51       ` Daniel Vetter
2013-01-15 12:34 ` [PATCH 7/7] reservation: Add lockdep annotation and selftests Maarten Lankhorst

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50F55E80.3060106@canonical.com \
    --to=maarten.lankhorst@canonical.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linaro-mm-sig@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=m.b.lankhorst@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome