The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Bob Miller <rem@osdl.org>
To: "Juan M. de la Torre" <jmtorre@gmx.net>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Questions on semaphores
Date: Wed, 4 Sep 2002 15:21:35 -0700	[thread overview]
Message-ID: <20020904152135.A2047@doc.pdx.osdl.net> (raw)
In-Reply-To: <20020904212931.GA2014@apocalipsis>; from jmtorre@gmx.net on Wed, Sep 04, 2002 at 11:29:31PM +0200

On Wed, Sep 04, 2002 at 11:29:31PM +0200, Juan M. de la Torre wrote:
> 
>  Hi people, I have two question regarding the i386 semaphore implementation
>  in kernel 2.4.19. 
>  
>  Please dont blame me if they are too obvius; i'm a newbie in kernel hacking
>  :)
> 
>  The functions __down, __down_interruptible and __down_trylock (defined
>  in arch/i386/kernel/semaphore.c) use the global spinlock
>  'semaphore_lock' to access some fields of the semaphore they are
>  working on:
>  
>  1) Is there any reason to do this?

It was easy to do.

>  2) Wouldn't it be more scalable to use a per-semaphore lock instead a
>     global spinlock?
> 

Yes it would be more scalable, but not as much as you would think.
The __down, __down_interruptible and __down_trylock code only gets
invoked when the semaphore is contended  for.

>  The function __down_trylock try to get the spinlock using
>  spin_lock_irqsave, instead of using spin_lock_irq:
> 
>  1) why? :)
> 

The __down_trylock() code can be called with another lock held.  The
spin_lock_irqsave()/spin_lock_irqrestore() interface is used to restore
the irq value for the lock that may already be held.

>  Thanks in advance,
>  Juanma
> 
The code in the 2.5 tree was changed a while back to use the spinlock in
the wait_queue_head_t to replace the global semaphore spin lock.  So, this
has been "FIXED" in 2.5.

-- 
Bob Miller					Email: rem@osdl.org
Open Source Development Lab			Phone: 503.626.2455 Ext. 17

      reply	other threads:[~2002-09-04 22:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-09-04 21:29 Questions on semaphores Juan M. de la Torre
2002-09-04 22:21 ` Bob Miller [this message]

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=20020904152135.A2047@doc.pdx.osdl.net \
    --to=rem@osdl.org \
    --cc=jmtorre@gmx.net \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox