All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yoann Padioleau <padator@wanadoo.fr>
To: kernel-janitors@vger.kernel.org
Subject: Re: [KJ] the rules for replacing DECLARE_MUTEX with DEFINE_MUTEX?
Date: Fri, 08 Jun 2007 08:36:25 +0000	[thread overview]
Message-ID: <87d506267q.fsf@wanadoo.fr> (raw)
In-Reply-To: <Pine.LNX.4.64.0706070838130.18229@localhost.localdomain>

"Robert P. J. Day" <rpjday@mindspring.com> writes:

>   i know that there's been a fair amount of work done lately in terms
> of replacing regular semaphores with the newer "mutex", and i just
> want to clarify under what circumstances that can be done.
>
>   first, a mutex is strictly a binary semaphore so it can't possibly
> be used in place of a general counting semaphore. (well, duh.)
>
>   in addition, mutexes can generally be used only in a limited
> locality, where the process that locks the mutex must be the same one
> that unlocks it, so even strictly binary semaphores might not be
> convertable to mutexes.

Why that ? The mutexes don't have a waiting queue like semaphores ? 

>
>   as i read it, the obvious places where actual mutexes could be used
> would be places like, say, drivers/spi/spi.c:
>
> ...
> static DECLARE_MUTEX(board_lock);
> ...
>     down(&board_lock);
>     list_add_tail(&bi->list, &board_list);
>     up(&board_lock);
> ...
>
>   first, the fact that the mutex itself is static means it's going to
> be used only within this file context.  

But it could be used by multiple instances of the same driver ? 

> and that restricted locality
> where it's actually used is what i interpret as a good hint that that
> semaphore could be replaced by a mutex.
>
>   is that a good summary of the rules?  am i missing anything
> critical?

Could you give counter examples: situations where we must not use 
a mutex, especially situations where it's a binary semaphore
but it still can't be converted to a mutex.

>
> rday
>
> p.s.  no, i have no interest in submitting patches for this, i just
> wanted to make sure i understood the general rules.

Just for curiosity, why you have no instest in such patches ? Because
you prefer to clarify the kernel than optimize it ? 


> -- 
> ====================================
> Robert P. J. Day
> Linux Consulting, Training and Annoying Kernel Pedantry
> Waterloo, Ontario, CANADA
>
> http://fsdev.net/wiki/index.php?title=Main_Page
> ====================================
> _______________________________________________
> Kernel-janitors mailing list
> Kernel-janitors@lists.linux-foundation.org
> https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors

_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/kernel-janitors

  reply	other threads:[~2007-06-08  8:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-07 12:45 [KJ] the rules for replacing DECLARE_MUTEX with DEFINE_MUTEX? Robert P. J. Day
2007-06-08  8:36 ` Yoann Padioleau [this message]
2007-06-08  9:01 ` Robert P. J. Day

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=87d506267q.fsf@wanadoo.fr \
    --to=padator@wanadoo.fr \
    --cc=kernel-janitors@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.