mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paul Mackerras <paulus@samba.org>
To: "Dong Feng" <middle.fengdong@gmail.com>
Cc: ak@suse.de, "Christoph Lameter" <clameter@sgi.com>,
	linux-kernel@vger.kernel.org
Subject: Re: Why Semaphore Hardware-Dependent?
Date: Mon, 28 Aug 2006 10:18:35 +1000	[thread overview]
Message-ID: <17650.13915.413019.784343@cargo.ozlabs.ibm.com> (raw)
In-Reply-To: <a2ebde260608271222x2b51693fnaa600965fcfaa6d2@mail.gmail.com>

Dong Feng writes:

> Why can't we have a hardware-independent semaphore definition while we
> have already had hardware-dependent spinlock, rwlock, and rcu lock? It
> seems the semaphore definitions classified into two major categories.
> The main deference is whether there is a member variable _sleeper_.
> Does this (optional) member indicate any hardware family gene?

It indicates the presence of instructions that let you implement a
flexible atomic update, that is, either load-locked and
store-conditional instructions, or a compare-and-exchange instruction.

The original x86 implementation had the `count' and `sleepers' fields
in the semaphore structure.  For PowerPC, I redesigned the semaphores
to have only the `count' field, which I was able to do because PowerPC
has `load with reservation' and `store conditional' instructions,
which one can use to construct code to do atomic updates where the
resulting value can be just about any function of the initial value.

For semaphores, I made a __sem_update_count function which atomically
updates the count field to (MAX(count, 0) + inc).  That implementation
was subsequently picked up by other architectures with equivalent
instructions (alpha, mips, s390, sparc64, etc.).  Have a look at
arch/powerpc/kernel/semaphore.c for the details.

I believe the reason for not doing something like this on x86 was the
fact that we still support i386 processors, which don't have the
cmpxchg instruction.  That's fair enough, but I would be opposed to
making semaphores bigger and slower on PowerPC because of that.  Hence
the two different styles of implementation.

Paul.

  parent reply	other threads:[~2006-08-28  0:18 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-27 19:22 Dong Feng
2006-08-27 20:52 ` Andi Kleen
2006-08-27 21:05   ` Christoph Lameter
2006-08-27 21:39     ` Andi Kleen
2006-08-27 22:14       ` Christoph Lameter
2006-08-28  0:18 ` Paul Mackerras [this message]
2006-08-28  5:14   ` Chris Wedgwood
2006-08-28  5:21     ` Christoph Lameter
2006-08-28  5:56     ` Jan Engelhardt
2006-08-28 12:35     ` linux-os (Dick Johnson)
2006-08-28  7:23   ` Andi Kleen
2006-08-29  1:00     ` Paul Mackerras
2006-08-28  7:30 ` Arjan van de Ven
2006-08-29  1:18   ` Nick Piggin
2006-08-29  6:07     ` Andi Kleen
2006-09-13 17:54       ` Nick Piggin
2006-08-29 10:05   ` David Howells
2006-08-29 10:56     ` Andi Kleen
2006-08-29 17:40       ` Andrew Morton
2006-08-29 19:10       ` Benjamin LaHaise
2006-08-29 15:56     ` Christoph Lameter
2006-08-29 16:20       ` Ralf Baechle
2006-08-29 16:25       ` David Howells
2006-08-29 16:28         ` Christoph Lameter
2006-08-29 16:53         ` Ralf Baechle
2006-08-29 16:58           ` Geert Uytterhoeven
2006-08-29 16:57         ` David Howells
2006-08-29 17:22       ` Andi Kleen
2006-08-29 17:36         ` Christoph Lameter
2006-08-29 18:18           ` Andi Kleen
2006-08-29 18:41             ` Christoph Lameter
2006-08-29 18:30           ` David Howells
2006-08-29 18:33             ` Andi Kleen
2006-08-29 18:56             ` David Howells
2006-09-13 18:04     ` Nick Piggin
2006-09-13 18:07       ` Christoph Lameter
2006-09-13 18:13         ` Nick Piggin
2006-09-13 18:16           ` Christoph Lameter
2006-09-13 18:50     ` David Howells
2006-09-13 19:25       ` Nick Piggin
2006-09-14 11:41       ` David Howells
2006-09-14 15:27         ` Nick Piggin
2006-09-14 15:38           ` Nick Piggin
2006-09-15  8:59         ` David Howells

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=17650.13915.413019.784343@cargo.ozlabs.ibm.com \
    --to=paulus@samba.org \
    --cc=ak@suse.de \
    --cc=clameter@sgi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=middle.fengdong@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

all inboxes | Powered by JetHome®