linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] i386 rw_semaphores fix
Date: 11 Apr 2001 11:05:31 -0700	[thread overview]
Message-ID: <9b26db$3t2$1@cesium.transmeta.com> (raw)
In-Reply-To: <20010411021318.A21221@khan.acc.umu.se> <Pine.LNX.4.31.0104101750320.15069-100000@penguin.transmeta.com>

Followup to:  <Pine.LNX.4.31.0104101750320.15069-100000@penguin.transmeta.com>
By author:    Linus Torvalds <torvalds@transmeta.com>
In newsgroup: linux.dev.kernel
> 
> Note that the "fixup" approach is not necessarily very painful at all,
> from a performance standpoint (either on 386 or on newer CPU's). It's not
> really that hard to just replace the instruction in the "undefined
> instruction"  handler by having strict rules about how to use the "xadd"
> instruction.
> 
> For example, you would not actually fix up the xadd to be a function call
> to something that emulates "xadd" itself on a 386. You would fix up the
> whole sequence of "inline down_write()" with a simple call to an
> out-of-line "i386_down_write()" function.
> 
> Note that down_write() on an old 386 is likely to be complicated enough
> that you want to do it out-of-line anyway, so the code-path you take
> (afetr the first time you've trapped on that particular location) would be
> the one you would take for an optimized 386 kernel anyway. And similarly,
> the restrictions you place on non-386-code to make it fixable are simple
> enough that it probably shouldn't make a difference for performance on
> modern chips.
> 

This reminds me a lot of how FPU emulation was done on 16-bit x86
CPUs, which didn't have the #EM trap on FPU instructions.  Each FPU
instruction would actually be assembled as CD + <FPU insn>, except
that the first byte of the FPU insn had its top bits modified.  Of
course the CD is the first byte of the INT instruction, so it would
dispatch to a very small set of interrupt vectors based on the first
byte of the FPU instruction; in case there really was an FPU it would
patch in <FPU insn>+NOP, otherwise it would patch in CALL <FPU
emulation routine> if you were running in a small-code model, or just
emulate it in a large-code model (since the far CALL wouldn't fit.)

This is a very nice way to deal with this, since your performance
impact is virtually nil in either case, since you're only taking the
trap once per call site.  A little bit of icache footprint, that's
all.

Now, if you're compiling for 486+ anyway, you would of course not add
the extra padding, and skip the trap handler.

	-hpa
-- 
<hpa@transmeta.com> at work, <hpa@zytor.com> in private!
"Unix gives you enough rope to shoot yourself in the foot."
http://www.zytor.com/~hpa/puzzle.txt

  parent reply	other threads:[~2001-04-11 18:06 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <3AD0FD0F.9B0C47FD@uow.edu.au>
2001-04-09  3:08 ` rw_semaphores Linus Torvalds
2001-04-09  4:18   ` rw_semaphores Linus Torvalds
2001-04-09 13:55     ` rw_semaphores Ben LaHaise
2001-04-10  2:41 ` rw_semaphores Tachino Nobuhiro
2001-04-10  5:43   ` rw_semaphores Linus Torvalds
2001-04-10  7:47     ` rw_semaphores David Howells
2001-04-10 18:02       ` [PATCH] i386 rw_semaphores fix David Howells
2001-04-10 19:42         ` Linus Torvalds
2001-04-10 19:56           ` x86 cpu configuration (was: Re: [PATCH] i386 rw_semaphores fix) Jeff Garzik
2001-04-10 21:58             ` Alan Cox
2001-04-10 20:05           ` [PATCH] i386 rw_semaphores fix Andi Kleen
2001-04-10 20:16             ` Linus Torvalds
2001-04-10 22:00             ` Alan Cox
2001-04-11  0:00               ` Andi Kleen
2001-04-11  0:13                 ` David Weinehall
2001-04-11  0:20                   ` Andi Kleen
2001-04-11  0:56                     ` David Weinehall
2001-04-11  1:04                       ` Andi Kleen
2001-04-11 12:32                     ` Alan Cox
2001-04-11  0:55                   ` Linus Torvalds
2001-04-11  1:07                     ` Andi Kleen
2001-04-11  1:12                       ` Linus Torvalds
2001-04-11  1:23                         ` Andi Kleen
2001-04-11 12:36                           ` Alan Cox
2001-04-11 18:05                     ` H. Peter Anvin [this message]
2001-04-11 12:28                 ` Alan Cox
2001-04-11 18:06                   ` H. Peter Anvin
2001-04-11 22:06                     ` Alan Cox
2001-04-11 22:42                       ` H. Peter Anvin
2001-04-11 22:55                         ` Alan Cox
2001-04-10 21:57           ` Alan Cox
2001-04-11  0:40             ` Tim Wright
2001-04-11  7:38           ` David Howells
2001-04-11 12:24             ` Maciej W. Rozycki
2001-04-11 12:57           ` [PATCH] 2nd try: " David Howells
2001-04-11 16:37             ` [PATCH] 3rd " David Howells
2001-04-11 21:41               ` [PATCH] 4th " David Howells
2001-04-12 18:16                 ` Andrew Morton
2001-04-11 23:00               ` [PATCH] 3rd " Anton Blanchard
2001-04-12 15:06                 ` [PATCH] i386 rw_semaphores, general abstraction patch David Howells
2001-04-11 16:56         ` [PATCH] i386 rw_semaphores fix Andrew Morton
2001-04-11 17:36           ` David Howells
2001-04-11 18:41             ` Linus Torvalds
2001-04-11 21:27           ` David Howells
2001-04-16 14:39       ` rw_semaphores yodaiken
2001-04-16 14:56         ` rw_semaphores Alan Cox
2001-04-16 17:05         ` rw_semaphores Linus Torvalds
2001-04-16 17:34           ` rw_semaphores yodaiken
2001-04-16 17:26         ` rw_semaphores Andrew Morton
2001-04-10  6:33   ` rw_semaphores Tachino Nobuhiro

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='9b26db$3t2$1@cesium.transmeta.com' \
    --to=hpa@zytor.com \
    --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;
as well as URLs for NNTP newsgroup(s).