public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nick Piggin <nickpiggin@yahoo.com.au>
To: Ingo Molnar <mingo@elte.hu>
Cc: lkml <linux-kernel@vger.kernel.org>,
	Linus Torvalds <torvalds@osdl.org>, Andrew Morton <akpm@osdl.org>,
	Arjan van de Ven <arjan@infradead.org>,
	Nicolas Pitre <nico@cam.org>,
	Jes Sorensen <jes@trained-monkey.org>,
	Al Viro <viro@ftp.linux.org.uk>, Oleg Nesterov <oleg@tv-sign.ru>,
	David Howells <dhowells@redhat.com>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Christoph Hellwig <hch@infradead.org>, Andi Kleen <ak@suse.de>,
	Russell King <rmk+lkml@arm.linux.org.uk>
Subject: Re: [patch 08/19] mutex subsystem, core
Date: Wed, 04 Jan 2006 00:15:24 +1100	[thread overview]
Message-ID: <43BA78EC.7050603@yahoo.com.au> (raw)
In-Reply-To: <20060103100807.GH23289@elte.hu>

Ingo Molnar wrote:

> +
> +/*
> + * Spinlock based trylock, we take the spinlock and check whether we
> + * can get the lock:
> + */
> +static inline int __mutex_trylock_nonatomic(atomic_t *lock_count)
> +{
> +	struct mutex *lock = container_of(lock_count, struct mutex, count);
> +	int prev;
> +
> +	spin_lock_mutex(&lock->wait_lock);
> +
> +	prev = atomic_xchg(&lock->count, -1);
> +	if (likely(prev == 1))
> +		debug_mutex_set_owner(lock, current_thread_info() __RET_IP__);
> +	/* Set it back to 0 if there are no waiters: */
> +	if (likely(list_empty(&lock->wait_list)))
> +		atomic_set(&lock->count, 0);
> +
> +	spin_unlock_mutex(&lock->wait_lock);
> +
> +	return prev == 1;
> +}
> +
> +/***
> + * mutex_trylock - try acquire the mutex, without waiting
> + * @lock: the mutex to be acquired
> + *
> + * Try to acquire the mutex atomically. Returns 1 if the mutex
> + * has been acquired successfully, and 0 on contention.
> + *
> + * NOTE: this function follows the spin_trylock() convention, so
> + * it is negated to the down_trylock() return values! Be careful
> + * about this when converting semaphore users to mutexes.
> + *
> + * This function must not be used in interrupt context. The
> + * mutex must be released by the same task that acquired it.
> + */
> +int fastcall mutex_trylock(struct mutex *lock)
> +{
> +	return __mutex_fastpath_trylock(&lock->count,
> +					__mutex_trylock_nonatomic);
> +}
> +

[snip]

> +
> +#define spin_lock_mutex(lock)			spin_lock(lock)
> +#define spin_unlock_mutex(lock)			spin_unlock(lock)

Is this an interrupt deadlock, or do you not allow interrupt contexts
to even trylock a mutex?

If the former, I would simply use atomic_cmpxchg unconditionally for
the trylock and not use a spinlock fallback function at all.

Alternately, you may 'trylock' the spinlock, but it just seems like
extra code for not much reason (when you can use atomic_cmpxchg).

-- 
SUSE Labs, Novell Inc.

Send instant messages to your online friends http://au.messenger.yahoo.com 

  reply	other threads:[~2006-01-03 13:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-03 10:08 [patch 08/19] mutex subsystem, core Ingo Molnar
2006-01-03 13:15 ` Nick Piggin [this message]
2006-01-03 15:05   ` Ingo Molnar
2006-01-03 15:38     ` Linus Torvalds
2006-01-03 15:42       ` Ingo Molnar
2006-01-03 18:00 ` Oleg Nesterov
2006-01-03 16:49   ` Ingo Molnar
  -- strict thread matches above, loose matches on Subject: below --
2006-01-03 16:46 Ingo Molnar
2006-01-03 15:58 Kai Geek
2006-01-02 16:34 Ingo Molnar

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=43BA78EC.7050603@yahoo.com.au \
    --to=nickpiggin@yahoo.com.au \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=arjan@infradead.org \
    --cc=dhowells@redhat.com \
    --cc=hch@infradead.org \
    --cc=jes@trained-monkey.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=nico@cam.org \
    --cc=oleg@tv-sign.ru \
    --cc=rmk+lkml@arm.linux.org.uk \
    --cc=torvalds@osdl.org \
    --cc=viro@ftp.linux.org.uk \
    /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