linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-15  8:31 John Bradford
  2003-09-15  8:32 ` Nick Piggin
  0 siblings, 1 reply; 122+ messages in thread
From: John Bradford @ 2003-09-15  8:31 UTC (permalink / raw)
  To: alan, john; +Cc: davidsen, linux-kernel, zwane

> > That's a non-issue.  300 bytes matters a lot on some systems.  The
> > fact that there are drivers that are bloated is nothing to do with
> > it.
>
> Its kind of irrelevant when by saying "Athlon" you've added 128 byte
> alignment to all the cache friendly structure padding.

My intention is that we won't have done 128 byte alignments just by
'supporting' Athlons, only if we want to run fast on Athlons.  A
distribution kernel that is intended to boot on all CPUs needs
workarounds for Athlon bugs, but it doesn't need 128 byte alignment.

Obviously using such a kernel for anything other than getting a system
up and running to compile a better kernel is a Bad Thing, but the
distributions could supply separate Athlon, PIV, and 386 _optimised_
kernels.

> There are systems
> where memory matters, but spending a week chasing 300 bytes when you can
> knock out 50K is a waste of everyones time. Do the 40K problems first

The 'select a single CPU to support and/optimise for' -> 'select a
bitmap of CPUs to support' work is being done anyway though, so this
is more or less just one single IFDEF, which is more like a few
seconds work, rather than a week.

Also, a lot of the 40K problems are in drivers that embedded systems
simply don't use.

John.

^ permalink raw reply	[flat|nested] 122+ messages in thread
* RE: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-16  2:23 richard.brunner
  0 siblings, 0 replies; 122+ messages in thread
From: richard.brunner @ 2003-09-16  2:23 UTC (permalink / raw)
  To: davidsen, bunk; +Cc: john, zwane, linux-kernel

Bill,

FWIW, I think you are on the right track!

I may haggle over really "*slow* it in some way",
but I think that can be worked out. It just a nit
in the grand scheme.

Thanks!

] -Rich ...
] AMD Fellow
] richard.brunner at amd com 

> -----Original Message-----
> From: Bill Davidsen [mailto:davidsen@tmr.com] 
> Sent: Monday, September 15, 2003 5:27 PM
> To: Adrian Bunk
> Cc: John Bradford; zwane@linuxpower.ca; linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
> 
> 
> On Mon, 15 Sep 2003, Adrian Bunk wrote:
> 
> > On Mon, Sep 15, 2003 at 07:32:49AM +0100, John Bradford wrote:
> > >...
> > > It should be possible, and straightforward, to compile a 
> kernel which:
> > > 
> > > 1. Supports, (I.E. has workarounds for), any combination of CPUs.
> > >    E.G. a kernel which supports 386s, and Athlons _only_ would not
> > >    need the F00F bug workaround.  Currently '386' kernels 
> include it,
> > >    because '386' means 'support 386 and above processors'.
> > > 
> > > 2. Has compiler optimisations for one particular CPU.
> > >    E.G. the 386 and Athlon supporting kernel above could have
> > >    alignment optimised for either 386 or Athlon.
> > >...
> > 
> > That's the point where even I consider such a system to be 
> too complex.
> 
> How does it strike you to have these:
>  - compile support for any CPU which doesn't break the target
>    (including slow it in some serious way)
>  - drop support for any CPU except the target
> 
> It seems to me that this is what the vendors want (as general 
> as possible)
> and the size limited users want (small is beautiful).
> 
> Fitting the code to this model could be done gradually and 
> hopefully with
> some macros to prevent too much ugly ifdef code.
> 
> -- 
> bill davidsen <davidsen@tmr.com>
>   CTO, TMR Associates, Inc
> Doing interesting things with little computers since 1979.
> 
> -
> To unsubscribe from this list: send the line "unsubscribe 
> linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 


^ permalink raw reply	[flat|nested] 122+ messages in thread
* RE: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-15 20:20 Nakajima, Jun
  0 siblings, 0 replies; 122+ messages in thread
From: Nakajima, Jun @ 2003-09-15 20:20 UTC (permalink / raw)
  To: richard.brunner, davidsen; +Cc: alan, zwane, linux-kernel

> I'd prefer that some set of options "take away"
> rather than "add" features/work-arounds. In the case below,
> I'd prefer a "don't support Athlon Prefetch Errata".

So the best way would be "make it configurable, and set it on by
default."? I don't think forcing everyone to have workarounds for
particular errata is desirable, but I agree that preventing mistakes is
a good thing. 

Thanks,
Jun

> -----Original Message-----
> From: richard.brunner@amd.com [mailto:richard.brunner@amd.com]
> Sent: Monday, September 15, 2003 12:51 PM
> To: davidsen@tmr.com
> Cc: alan@lxorguk.ukuu.org.uk; zwane@linuxpower.ca; linux-
> kernel@vger.kernel.org
> Subject: RE: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
> 
> My concern is trying to prevent
> the flood of emails where someone thinks they built
> a "standard" kernel only to  discover that they forgot
> to select the various suboptions
> and it doesn't work on their processor. I'd like
> to simplfy what the majority of folks need to do
> to get a broadly working kernel.
> 
> I'd prefer that some set of options "take away"
> rather than "add" features/work-arounds. In the case below,
> I'd prefer a "don't support Athlon Prefetch Errata".
> 
> I think you can argue that some features are going to
> be common enough for the majority of users that they
> should be in the "take-away" category.
> 
> Others are uncommon enough that they fall into
> the "add" category.
> 
> If you stick with consistent nomenclature
> (e.g. add_feature_TBD & sub_default_feature_TBD)
> and put these options in one common config file,
> I think the embedded folks and the
> "optimize every last bit" folks get
> what they want.
> 
> ] -Rich ...
> ] AMD Fellow
> ] richard.brunner at amd com
> 
> > -----Original Message-----
> > From: Bill Davidsen [mailto:davidsen@tmr.com]
> > Sent: Monday, September 15, 2003 12:16 PM
> > To: Brunner, Richard
> > Cc: alan@lxorguk.ukuu.org.uk; zwane@linuxpower.ca;
> > linux-kernel@vger.kernel.org
> > Subject: RE: [PATCH] 2.6 workaround for Athlon/Opteron prefetch
errata
> >
> >
> > On Mon, 15 Sep 2003 richard.brunner@amd.com wrote:
> >
> > > I think Alan brought up a very good point. Even if you
> > > use a generic kernel that avoids prefetch use on Athlon
> > > (which I am opposed to), it doesn't solve the problem
> > > of user space programs detecting that the ISA supports
> > > prefetch and using prefetch instructions and hitting the
> > > errata on Athlon.
> > >
> > > The user space problem worries me more, because the expectation
> > > is that if CPUID says the program can use perfetch, it could
> > > and should regardless of what the kernel decided to do here.
> > >
> > > Andi's patch solves both the kernel space and the user space
> > > issues in a pretty small footprint.
> >
> > Clearly AMD would like to avoid having PIV and Athlon
> > optimized kernels,
> > and to default to adding unnecessary size to the PIV kernel to
support
> > errata in the Athlon. But fighting against having a config
> > which produces
> > a smaller and faster kernel for all non-Athlon users and all
> > embedded or
> > otherwise size limited users seems to be just a marketing
> > thing so P4 code
> > will seem to work correctly on Athlon.
> >
> > Vendors will build a kernel which runs as well as possible on
> > as many CPUs
> > as possible, but users who build their own kernel want to
> > build a kernel
> > for a particular config in most cases and should have the
> > option. There
> > should be a "support Athlon prefetch" option as well, which turns on
> > the fix only when it's needed, just as there is for P4
> > thermal throttling,
> > F.P. emulation, etc. Why shouldn't this be treated the same
> > way as other
> > features already in the config menu?
> >
> > --
> > bill davidsen <davidsen@tmr.com>
> >   CTO, TMR Associates, Inc
> > Doing interesting things with little computers since 1979.
> >
> >
> 
> -
> To unsubscribe from this list: send the line "unsubscribe
linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 122+ messages in thread
* RE: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-15 20:03 Nakajima, Jun
  0 siblings, 0 replies; 122+ messages in thread
From: Nakajima, Jun @ 2003-09-15 20:03 UTC (permalink / raw)
  To: Bill Davidsen, Alan Cox; +Cc: Zwane Mwaikambo, Linux Kernel Mailing List


> Of course if you have PIV kernel you don't need any of the Athlon code
at
> all, so the size and performance penalty is zero. And if you build for
a
> CPU which doesn't have prefetch you don't need any of that code at
all.

That's true. But I think sharing the same source/binary in some
reasonable fashion is much more beneficial to Linux and the users,
especially because we can improve the quality and performance more
efficiently. 

I think the way Andi implemented (see below, for example) is one of the
best solutions as far as I think of. 

extern inline void prefetchw(const void *x)
{
	alternative_input(ASM_NOP4,
			  "prefetchw (%1)",
			  X86_FEATURE_3DNOW,
			  "r" (x));
}

Thanks,
Jun

> -----Original Message-----
> From: Bill Davidsen [mailto:davidsen@tmr.com]
> Sent: Monday, September 15, 2003 11:51 AM
> To: Alan Cox
> Cc: Zwane Mwaikambo; Linux Kernel Mailing List
> Subject: Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
> 
> On Mon, 15 Sep 2003, Alan Cox wrote:
> 
> > On Llu, 2003-09-15 at 13:11, Bill Davidsen wrote:
> > > The code to disable prefetch on Athlon is 300 bytes and hurts your
> PIV?
> > > Really? I'll dig back through the code, but I recall it as adding
or
> > > deleting an entry in a table to enable prefetch. If it's affecting
PIV
> the
> > > code to use prefetch is seriously broken.
> >
> > Big time. Its over 300 bytes long because its embedded in each
inline
> > prefetch and it causes a branch misprediction almost every time.
Amazing
> > what you find when you actually measure stuff 8)
> >
> > So right now, its faster on PIV to delete the prefetch than use the
> > current hack, and adding the Athlon fix makes Athlon and PIV faster
and
> > total memory size lower.
> 
> Of course if you have PIV kernel you don't need any of the Athlon code
at
> all, so the size and performance penalty is zero. And if you build for
a
> CPU which doesn't have prefetch you don't need any of that code at
all.
> 
> --
> bill davidsen <davidsen@tmr.com>
>   CTO, TMR Associates, Inc
> Doing interesting things with little computers since 1979.
> 
> -
> To unsubscribe from this list: send the line "unsubscribe
linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 122+ messages in thread
* RE: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-15 19:51 richard.brunner
  2003-09-16  0:01 ` David Lang
                   ` (2 more replies)
  0 siblings, 3 replies; 122+ messages in thread
From: richard.brunner @ 2003-09-15 19:51 UTC (permalink / raw)
  To: davidsen; +Cc: alan, zwane, linux-kernel

My concern is trying to prevent 
the flood of emails where someone thinks they built 
a "standard" kernel only to  discover that they forgot 
to select the various suboptions
and it doesn't work on their processor. I'd like
to simplfy what the majority of folks need to do
to get a broadly working kernel.

I'd prefer that some set of options "take away"
rather than "add" features/work-arounds. In the case below,
I'd prefer a "don't support Athlon Prefetch Errata".

I think you can argue that some features are going to 
be common enough for the majority of users that they
should be in the "take-away" category.

Others are uncommon enough that they fall into
the "add" category.

If you stick with consistent nomenclature 
(e.g. add_feature_TBD & sub_default_feature_TBD) 
and put these options in one common config file, 
I think the embedded folks and the 
"optimize every last bit" folks get 
what they want.

] -Rich ...
] AMD Fellow
] richard.brunner at amd com 

> -----Original Message-----
> From: Bill Davidsen [mailto:davidsen@tmr.com] 
> Sent: Monday, September 15, 2003 12:16 PM
> To: Brunner, Richard
> Cc: alan@lxorguk.ukuu.org.uk; zwane@linuxpower.ca; 
> linux-kernel@vger.kernel.org
> Subject: RE: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
> 
> 
> On Mon, 15 Sep 2003 richard.brunner@amd.com wrote:
> 
> > I think Alan brought up a very good point. Even if you
> > use a generic kernel that avoids prefetch use on Athlon
> > (which I am opposed to), it doesn't solve the problem
> > of user space programs detecting that the ISA supports
> > prefetch and using prefetch instructions and hitting the
> > errata on Athlon.
> > 
> > The user space problem worries me more, because the expectation
> > is that if CPUID says the program can use perfetch, it could
> > and should regardless of what the kernel decided to do here.
> > 
> > Andi's patch solves both the kernel space and the user space
> > issues in a pretty small footprint.
> 
> Clearly AMD would like to avoid having PIV and Athlon 
> optimized kernels,
> and to default to adding unnecessary size to the PIV kernel to support
> errata in the Athlon. But fighting against having a config 
> which produces
> a smaller and faster kernel for all non-Athlon users and all 
> embedded or
> otherwise size limited users seems to be just a marketing 
> thing so P4 code
> will seem to work correctly on Athlon.
> 
> Vendors will build a kernel which runs as well as possible on 
> as many CPUs
> as possible, but users who build their own kernel want to 
> build a kernel
> for a particular config in most cases and should have the 
> option. There
> should be a "support Athlon prefetch" option as well, which turns on
> the fix only when it's needed, just as there is for P4 
> thermal throttling,
> F.P. emulation, etc. Why shouldn't this be treated the same 
> way as other
> features already in the config menu?
> 
> -- 
> bill davidsen <davidsen@tmr.com>
>   CTO, TMR Associates, Inc
> Doing interesting things with little computers since 1979.
> 
> 


^ permalink raw reply	[flat|nested] 122+ messages in thread
* Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-15 19:34 John Bradford
  2003-09-15 19:25 ` Bill Davidsen
  2003-09-15 22:28 ` Alan Cox
  0 siblings, 2 replies; 122+ messages in thread
From: John Bradford @ 2003-09-15 19:34 UTC (permalink / raw)
  To: davidsen, john; +Cc: alan, linux-kernel, zwane

> > > I still like the idea of a single config variable to remove all special
> > > case code for non-configured CPUs, call it NO_BLOAT or MINIMALIST_KERNEL
> > > or EMBEDDED_HELPER as you will. The embedded folks would then have a good
> > > handle to do the work and identify sections to be so identified.
> > 
> > Removing the code for non-configured CPUs should be the default.  It's
> > common sense - if you configure a kernel to support Athlons only, why
> > have PIV workarounds in there, unless you're actually debugging a
> > kernel problem?
>
> If we adopt a bit-per-CPUtype or similar approach maybe. But then you have
> to go back and test each code section to see if it applies to multiple
> types. I'm happy to have existing code stay, as long as there's a way to
> clean it up (or attempt to do so). I don't think making super clean is
> compatible with stability, and I'd rather see sections marked as
> architecture specific as the performance and embedded folks look for
> places to clean up the kernel.

Yes, you're right, from a stability point of view I was being a bit
impractical.  Any idea how many developers are actually regularly
testing code on 386s these days, by the way?

> I'm not on a crusade to get the tiny kernel, just to (a) provide a path
> for future work started by the config "feature removal" menu, and (b)
> avoid inserting a chunk of very specific code without ifdefs, now that
> developers have started thinking about putting the kernel on a diet. I
> don't suggest we do anything which will break existing code, just not
> introduce new bloat right now.

Yeah, breaking existing code can wait until 2.7 :-).  Putting the
hooks in for future code removal is all we need to do - until somebody
actually feels the need to trim something, it might as well stay.

John.

^ permalink raw reply	[flat|nested] 122+ messages in thread
* Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-15 19:19 John Bradford
  0 siblings, 0 replies; 122+ messages in thread
From: John Bradford @ 2003-09-15 19:19 UTC (permalink / raw)
  To: alan, davidsen; +Cc: john, linux-kernel, piggin, zwane

> > > In the model I'm proposing, the 386 kernel would be missing the Athlon
> > > workarounds.
> > 
> > This is unworkable unless you also have all the existing models where
> > you have fixes for later processors too. 
>
> I think John wants to have the default be that only code for the target
> CPU be included in the kernel when built for a given CPU.

Yes, that's what I meant.

> There's no
> reason why someone building for 386 would want code for other CPUs at all,
> vendors and people who want to run a single suboptimal kernel on multiple
> machines.
>
> My own suggestion is that the default could continue to be "include
> anything which doesn't break or drastically slow the target CPU," and then
> have a flag value to exclude fixups or enhancements for other CPUs. This
> allows existing code to be gradully marked for simplification by embedded
> users or those who just want to avoid overhead in their kernel.

Ah, OK, on reflection that's probably more realistic from a practical
viewpoint, (see my other post in this thread).

John.

^ permalink raw reply	[flat|nested] 122+ messages in thread
[parent not found: <200309150632.h8F6WnHb000589@81-2-122-30.bradfords.org.uk.suse.lists.linux.kernel>]
* RE: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-15 16:21 richard.brunner
  2003-09-15 19:15 ` Bill Davidsen
                   ` (2 more replies)
  0 siblings, 3 replies; 122+ messages in thread
From: richard.brunner @ 2003-09-15 16:21 UTC (permalink / raw)
  To: alan, davidsen; +Cc: zwane, linux-kernel

I think Alan brought up a very good point. Even if you
use a generic kernel that avoids prefetch use on Athlon
(which I am opposed to), it doesn't solve the problem
of user space programs detecting that the ISA supports
prefetch and using prefetch instructions and hitting the
errata on Athlon.

The user space problem worries me more, because the expectation
is that if CPUID says the program can use perfetch, it could
and should regardless of what the kernel decided to do here.

Andi's patch solves both the kernel space and the user space
issues in a pretty small footprint.


] -Rich ...
] AMD Fellow
] richard.brunner at amd com 

> -----Original Message-----
> From: Alan Cox [mailto:alan@lxorguk.ukuu.org.uk] 
> Sent: Monday, September 15, 2003 12:46 AM

> You also need it for userspace prefetch fault fixup for a 
> kernel without
> CONFIG_MK7 to run stuff perfectly on Athlon.
> 


^ permalink raw reply	[flat|nested] 122+ messages in thread
* Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-15 14:21 John Bradford
  0 siblings, 0 replies; 122+ messages in thread
From: John Bradford @ 2003-09-15 14:21 UTC (permalink / raw)
  To: alan, john; +Cc: davidsen, linux-kernel, piggin, zwane

> > In the model I'm proposing, the 386 kernel would be missing the Athlon
> > workarounds.
>
> This is unworkable unless you also have all the existing models where
> you have fixes for later processors too. 

I'm pretty sure we're talking about two different things - I don't
understand what you mean about all the exisiting models.  Are you
saying that with Adrian's patch we still can't simply include this
workaround [1] if and only if the user has included Athlon support,
rather than CPU<=Athlon?

[1] Obviously the point isn't just applicable to this work around, but
this is a new one going in.

John.

^ permalink raw reply	[flat|nested] 122+ messages in thread
* Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-15 12:43 John Bradford
  2003-09-15 18:21 ` Bill Davidsen
  0 siblings, 1 reply; 122+ messages in thread
From: John Bradford @ 2003-09-15 12:43 UTC (permalink / raw)
  To: alan, davidsen; +Cc: john, linux-kernel, zwane

> I still like the idea of a single config variable to remove all special
> case code for non-configured CPUs, call it NO_BLOAT or MINIMALIST_KERNEL
> or EMBEDDED_HELPER as you will. The embedded folks would then have a good
> handle to do the work and identify sections to be so identified.

Removing the code for non-configured CPUs should be the default.  It's
common sense - if you configure a kernel to support Athlons only, why
have PIV workarounds in there, unless you're actually debugging a
kernel problem?

John.

^ permalink raw reply	[flat|nested] 122+ messages in thread
* Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-15 12:28 Mikael Pettersson
  2003-09-15 18:13 ` Bill Davidsen
  2003-09-16 11:54 ` Jamie Lokier
  0 siblings, 2 replies; 122+ messages in thread
From: Mikael Pettersson @ 2003-09-15 12:28 UTC (permalink / raw)
  To: alan, davidsen; +Cc: linux-kernel, zwane

On Mon, 15 Sep 2003 08:11:12 -0400 (EDT), Bill Davidsen <davidsen@tmr.com> wrote:
> On Mon, 15 Sep 2003, Alan Cox wrote:
> > That disable you talk about is bloat. It also trashes the performance of
> > PIV boxes. In fact I checked out of interest - the disable hack
> > currently being used is adding *over* 300 bytes to my kernel as its
> > inlined repeatedly. So its larger, and it ruins performance for all
> > processors.
> 
> The code to disable prefetch on Athlon is 300 bytes and hurts your PIV?
> Really? I'll dig back through the code, but I recall it as adding or
> deleting an entry in a table to enable prefetch. If it's affecting PIV the
> code to use prefetch is seriously broken.

Bill, look in include/asm-i386/processor.h:

extern inline void prefetch(const void *x)
{
        if (cpu_data[0].x86_vendor == X86_VENDOR_AMD)
                return;         /* Some athlons fault if the address is bad */
        alternative_input(ASM_NOP4,
                          "prefetchnta (%1)",
                          X86_FEATURE_XMM,
                          "r" (x));
}

A dynamic test at each occurrence. That's truly horrible.
(And I'll hack it out of _my_ kernels ASAP. Can't imagine
I missed that one.)

/Mikael

^ permalink raw reply	[flat|nested] 122+ messages in thread
* Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-15 11:46 John Bradford
  2003-09-15 12:38 ` Nick Piggin
  0 siblings, 1 reply; 122+ messages in thread
From: John Bradford @ 2003-09-15 11:46 UTC (permalink / raw)
  To: john, piggin; +Cc: alan, davidsen, linux-kernel, zwane

> >>>>>>>That's a non-issue.  300 bytes matters a lot on some systems.  The
> >>>>>>>fact that there are drivers that are bloated is nothing to do with
> >>>>>>>it.
> >>>>>>>
> >>>>>>Its kind of irrelevant when by saying "Athlon" you've added 128 byte
> >>>>>>alignment to all the cache friendly structure padding.
> >>>>>>
> >>>>>My intention is that we won't have done 128 byte alignments just by
> >>>>>'supporting' Athlons, only if we want to run fast on Athlons.  A
> >>>>>distribution kernel that is intended to boot on all CPUs needs
> >>>>>workarounds for Athlon bugs, but it doesn't need 128 byte alignment.
> >>>>>
> >>>>>Obviously using such a kernel for anything other than getting a system
> >>>>>up and running to compile a better kernel is a Bad Thing, but the
> >>>>>distributions could supply separate Athlon, PIV, and 386 _optimised_
> >>>>>kernels.
> >>>>>
> >>>>Why bother with that complexity? Just use 128 byte lines. This allows
> >>>>a decent generic kernel. The people who have space requirements would
> >>>>only compile what they need anyway.
> >>>>
> >>>So, basically, if you compile a kernel for a 386, but think that maybe
> >>>one day you might need to run it on an Athlon for debugging purposes,
> >>>you use 128 byte padding, because it's not too bad on the 386?  Seems
> >>>pretty wasteful to me when the obvious, simple, elegant solution is to
> >>>allow independent selection of workaround inclusion and optimisation.
> >>>Especially since half of the work has already been done.
> >>>
> >>I missed the "simple, elegant" part. Conceptually elegant maybe.
> >>
> >>If you mean to use the optimise option only to set cache line size, then
> >>that might be a bit saner.
> >>
> >>As far as the case study goes though: if you were worried about being
> >>wasteful, why wouldn't you compile just for the 386 and debug from that?
> >
> >In the model I'm proposing, the 386 kernel would be missing the Athlon
> >workarounds.
>
> No, debug the kernel while its running on the 386.

What if the 386 is a wristwatch, or similar embedded device?

> And what of my other
> concerns?

Since nobody seemed to agree with me, I was sparing the list the
bandwidth, but...

> 1. It doesn't appear to be simple and elegant.

Well, it's obviously not as simple as just using 128 byte padding all
the time, but the basic idea of, 'choose required work-arounds, and
optimisations independently of each other', is fairly simple, (in
concept), and elegant, (as it lets you compile the most finely tuned
binary).

Maybe we are not thinking along the same lines.

Up to now, selecting a CPU to compile for basically means, "Use
compiler optimisations for this CPU, and don't care about
compatibility with anything before it".  Adrian's patch to change this
to an arbitrary bitmap selection of CPUs to support seems like a good
idea to me for two reasons, firstly with increasing numbers of
work-arounds, it's silly to include them all in a kernel for a 386.
Secondly, ever since we included support for optimising for the 686,
the idea that a kernels compiled for progressively more recent CPUs
would be faster than each other on the same hardware has been false -
a kernel compiled for a Pentium is slower on a 686 than a kernel
compiled for a 486 is.

So, if we move from selecting a range of CPUs to support, I.E. 386 ->
whatever, to selecting individual CPUs, E.G. 386, PIV, and Athlon,
there is no question about which workarounds we should include.  By
the way, I am talking about including them at compile time, not
checking at run time whether they are needed - maybe I wasn't clear
about that.  I don't see the point in checking at runtime - any kernel
that supports multiple CPUs is not optimial anyway, so why bother
trying to optimise it at all?  I know there is another way of looking
at it, that distributions will want a kernel that runs on anything,
(well, these days, probably a 486 or higher CPU), that is not
particularly sub-optimial on any CPU, so that users can just install
it, and have it work.  In that case, I totally agree with you that 128
byte padding is the most sensible way to go, but that is a
distribution thing.  Anybody who compiles their own kernel is probably
going to want to compile it for the processor it's destined to run on,
rather than make a generic kernel, unless they are making a boot disk
for emergencies, in which case performance is not usually an issue.
So, the question of which workarounds to include is simple, but what
to do about optimisation?  In the current model, where you are
selecting a range of CPUs to support, (E.G. 386->Pentium), the
question is answered by saying, OK, we'll optimise for the most recent
processor in that range.  With an arbitrary selection, E.G. PIV and
Athlon, which do you pad for?  Whichever is least harmful to
performance on the others?  This is what I meant by simple and elegant
- you just present independent choice to the user in the
configurator.

> 2. It would drive developers nuts if it was used for anything other than
>    a couple of critical functions (cache size would be one).

OK, well by using the 'optimisation' setting simply for setting cache
size alone, you'd still get a nice tunable kernel.  Much better than
just setting it to an arbitrary value.

> 3. Are there valid situations where you would need it? This isn't a
>    rhetorical question. Your example would be fine if somebody really
>    needed to do that.

Personally, I compile specific kernels for all of my boxes separately.
No box runs any kind of generic kernel in normal use, so I'd like to
see as many unnecessary workarounds removed from the code as possible
at compile time, and appropriate compiler optimisations for only the
specific CPU the kernel is destined for.  That maximises kernel
performance on that mahcine.  On the other hand, if I'm working on an
embedded project with a 386 or a 486, I'm usually running the same
environment on a more powerful box as well, for testing purposes, so I
need workarounds for the, (E.G. Athlon), CPU in the development box,
but I don't want performance optimisations for that faster CPU,
especially if they have a negative effect on the embedded CPU.

John.

^ permalink raw reply	[flat|nested] 122+ messages in thread
* Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-15 10:54 John Bradford
  2003-09-15 10:52 ` Nick Piggin
  2003-09-15 13:45 ` Alan Cox
  0 siblings, 2 replies; 122+ messages in thread
From: John Bradford @ 2003-09-15 10:54 UTC (permalink / raw)
  To: john, piggin; +Cc: alan, davidsen, linux-kernel, zwane

> >>>>>That's a non-issue.  300 bytes matters a lot on some systems.  The
> >>>>>fact that there are drivers that are bloated is nothing to do with
> >>>>>it.
> >>>>>
> >>>>>
> >>>>Its kind of irrelevant when by saying "Athlon" you've added 128 byte
> >>>>alignment to all the cache friendly structure padding.
> >>>>
> >>>>
> >>>My intention is that we won't have done 128 byte alignments just by
> >>>'supporting' Athlons, only if we want to run fast on Athlons.  A
> >>>distribution kernel that is intended to boot on all CPUs needs
> >>>workarounds for Athlon bugs, but it doesn't need 128 byte alignment.
> >>>
> >>>Obviously using such a kernel for anything other than getting a system
> >>>up and running to compile a better kernel is a Bad Thing, but the
> >>>distributions could supply separate Athlon, PIV, and 386 _optimised_
> >>>kernels.
> >>>
> >>>
> >>Why bother with that complexity? Just use 128 byte lines. This allows
> >>a decent generic kernel. The people who have space requirements would
> >>only compile what they need anyway.
> >>
> >
> >So, basically, if you compile a kernel for a 386, but think that maybe
> >one day you might need to run it on an Athlon for debugging purposes,
> >you use 128 byte padding, because it's not too bad on the 386?  Seems
> >pretty wasteful to me when the obvious, simple, elegant solution is to
> >allow independent selection of workaround inclusion and optimisation.
> >Especially since half of the work has already been done.
> >
>
> I missed the "simple, elegant" part. Conceptually elegant maybe.
>
> If you mean to use the optimise option only to set cache line size, then
> that might be a bit saner.
>
> As far as the case study goes though: if you were worried about being
> wasteful, why wouldn't you compile just for the 386 and debug from that?

In the model I'm proposing, the 386 kernel would be missing the Athlon
workarounds.

John.

^ permalink raw reply	[flat|nested] 122+ messages in thread
* Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-15  9:39 John Bradford
  2003-09-15  9:58 ` Nick Piggin
  0 siblings, 1 reply; 122+ messages in thread
From: John Bradford @ 2003-09-15  9:39 UTC (permalink / raw)
  To: john, piggin; +Cc: alan, davidsen, linux-kernel, zwane

> >>>That's a non-issue.  300 bytes matters a lot on some systems.  The
> >>>fact that there are drivers that are bloated is nothing to do with
> >>>it.
> >>>
> >>Its kind of irrelevant when by saying "Athlon" you've added 128 byte
> >>alignment to all the cache friendly structure padding.
> >>
> >
> >My intention is that we won't have done 128 byte alignments just by
> >'supporting' Athlons, only if we want to run fast on Athlons.  A
> >distribution kernel that is intended to boot on all CPUs needs
> >workarounds for Athlon bugs, but it doesn't need 128 byte alignment.
> >
> >Obviously using such a kernel for anything other than getting a system
> >up and running to compile a better kernel is a Bad Thing, but the
> >distributions could supply separate Athlon, PIV, and 386 _optimised_
> >kernels.
> >
>
> Why bother with that complexity? Just use 128 byte lines. This allows
> a decent generic kernel. The people who have space requirements would
> only compile what they need anyway.

So, basically, if you compile a kernel for a 386, but think that maybe
one day you might need to run it on an Athlon for debugging purposes,
you use 128 byte padding, because it's not too bad on the 386?  Seems
pretty wasteful to me when the obvious, simple, elegant solution is to
allow independent selection of workaround inclusion and optimisation.
Especially since half of the work has already been done.

John.

^ permalink raw reply	[flat|nested] 122+ messages in thread
* Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-15  6:32 John Bradford
  2003-09-15  7:40 ` Alan Cox
                   ` (2 more replies)
  0 siblings, 3 replies; 122+ messages in thread
From: John Bradford @ 2003-09-15  6:32 UTC (permalink / raw)
  To: davidsen, zwane; +Cc: linux-kernel

> > We just got a start on making Linux smaller to encourage embedded use, I
> > don't see adding 300+ bytes of wasted code so people can run
> > misconfigured kernels.
> > 
> > I rather have to patch this in for my Athlon kernels than have people
> > who aren't cutting corners trying to avoid building matching kernels
> > have to live with the overhead.
>
> Overhead? Really you could save more memory by cleaning up a lot of 
> drivers. Andi already said it before, there are better places to be 
> looking at.

That's a non-issue.  300 bytes matters a lot on some systems.  The
fact that there are drivers that are bloated is nothing to do with
it.

> Also 'patching' for Athlon kernels doesn't cut it for people who need to 
> distribute kernels which run on various hardware (such as distros). This 
> alone is benefit enough to justify this supposed 'bloat'.

No it's not.  Most distributions heavily patch the kernel anyway.

It should be possible, and straightforward, to compile a kernel which:

1. Supports, (I.E. has workarounds for), any combination of CPUs.
   E.G. a kernel which supports 386s, and Athlons _only_ would not
   need the F00F bug workaround.  Currently '386' kernels include it,
   because '386' means 'support 386 and above processors'.

2. Has compiler optimisations for one particular CPU.
   E.G. the 386 and Athlon supporting kernel above could have
   alignment optimised for either 386 or Athlon.

This makes it trivial to:

* Make a kernel for a distribution's initial install
  Select all CPUs as supported, and optimise for 686.

* Make an optimised kernel for any system
  Select only the target CPU as supported, and optimise for it

* Make a generic kernel for PIV, and Athlon
  Select PIV and Athlon only as supported.  Optimise for either, or
  optimise for 386, (yes, even though it is not supported), for a
  small kernel, on the basis that it will maximise cache usage, and be
  fairly optimal on both systems.

John.

^ permalink raw reply	[flat|nested] 122+ messages in thread
* Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-12 21:24 John Bradford
  0 siblings, 0 replies; 122+ messages in thread
From: John Bradford @ 2003-09-12 21:24 UTC (permalink / raw)
  To: ak, bunk
  Cc: akpm, azarah, ebiederm, jgarzik, linux-kernel, richard.brunner, torvalds

> From linux-kernel-owner+john=40bradfords.org.uk@vger.kernel.org  Fri Sep 12 21:59:55 2003
> Envelope-To: john@bradfords.org.uk
> Date: 	Fri, 12 Sep 2003 22:00:23 +0200
> From: Adrian Bunk <bunk@fs.tum.de>
> To: Andi Kleen <ak@suse.de>
> Cc: Martin Schlemmer <azarah@gentoo.org>, jgarzik@pobox.com,
>    ebiederm@xmission.com, akpm@osdl.org, richard.brunner@amd.com,
>    linux-kernel@vger.kernel.org, torvalds@osdl.org
> Subject: Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
> References: <3F60837D.7000209@pobox.com> <20030911162634.64438c7d.ak@suse.de> <3F6087FC.7090508@pobox.com> <m1vfrxlxol.fsf@ebiederm.dsl.xmission.com> <20030912195606.24e73086.ak@suse.de> <3F62098F.9030300@pobox.com> <20030912182216.GK27368@fs.tum.de> <20030912202851.3529e7e7.ak@suse.de> <1063393505.3371.207.camel@workshop.saharacpt.lan> <20030912213016.47a4e5de.ak@suse.de>
> Mime-Version: 1.0
> Content-Type: text/plain; charset=us-ascii
> Content-Disposition: inline
> In-Reply-To: <20030912213016.47a4e5de.ak@suse.de>
> User-Agent: Mutt/1.4.1i
> Sender: linux-kernel-owner@vger.kernel.org
> Precedence: bulk
> X-Mailing-List: 	linux-kernel@vger.kernel.org
>
> On Fri, Sep 12, 2003 at 09:30:16PM +0200, Andi Kleen wrote:
> >...
> > I think it's useful to keep kernels booting everywhere, it makes it a lot easier
> > to test a single kernel on multiple systems.
>
> Different people have different needs:
>
> Sometimes you want kernels booting everywhere, e.g. a distribution might
> want to support all CPUs from an 386 to an Opteron with one kernel for
> their boot floppies.
>
> For a system administrator with only Pentium 3 and Pentum 4 machines
> support for 386 and Opteron isn't of much worth.
>
> In some embedded systems people are happy about every kB their kernel is 
> smaller.

As I understand it:

* For maximum optimisation, compile for your specific CPU.
* To get compatibility for everything except a 386 CPU, with almost
  optimum performance, compile for 486.
* To get full compatibility, with possibly significantly less than
  optimum performance, compile for 386.
* Only optimise for Pentium if the kernel is intended to be run on a
  Pentium CPU, as the resulting code is less optimal for many other
  processors than code optimised for a 486.

Recently, there have been efforts to make a universally compatible
kernel, with optimisations for all CPUs that don't significantly
adversely affect any other CPUs.  The logic behind this seems to be
that users can then use their distribution's kernel on any CPU, and
get reasonable performance.

Nothing wrong with that in principle, but there are also a lot of
users who are happy to compile one kernel for one machine, and want it
as optimised as possible.  This often includes embedded systems
developers, but certainly isn't limited to them.

John.

^ permalink raw reply	[flat|nested] 122+ messages in thread
* RE: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-11 17:17 richard.brunner
  2003-09-13 16:54 ` Pavel Machek
  0 siblings, 1 reply; 122+ messages in thread
From: richard.brunner @ 2003-09-11 17:17 UTC (permalink / raw)
  To: ak, davej; +Cc: torvalds, linux-kernel, akpm

> -----Original Message-----
> From: Andi Kleen [mailto:ak@suse.de] 
> Sent: Thursday, September 11, 2003 7:29 AM
> 
> On Thu, 11 Sep 2003 15:14:51 +0100
> Dave Jones <davej@redhat.com> wrote:
> 
> > On Thu, Sep 11, 2003 at 04:01:08PM +0200, Andi Kleen wrote:
> > 
> >  > > What's wrong with the current status quo that just says 
> >  > > "Athlon prefetch is broken"?
> >  > It doesn't fix user space for once.
> > 
> > And for another, it cripples the earlier athlons which 
> > don't have this
> > errata. Andi's fix at least makes prefetch work again on 
> > those boxes.
> > It's also arguable that prefetch() helps the older K7's 
> > more than the
> > affected ones.
> 
> All Athlons have this Errata. I can trigger it on an old
> 900Mhz pre XP Athlon too. You just have to use 3dnow prefetch
> instead of SSE prefetch.
> 
> BTW the older Athlons currently don't use prefetch because 
> the alternative
> patcher does not handle 3dnow style prefetch.
> 

Avoiding prefetch for all Athlons and earlier Opterons/Athlon64
even in the kernel can really tank performance. And as Andi says
it still doesn't solve user mode from hitting the errata.
 
] -Rich ...
] AMD Fellow


^ permalink raw reply	[flat|nested] 122+ messages in thread
* RE: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-11 17:14 richard.brunner
  0 siblings, 0 replies; 122+ messages in thread
From: richard.brunner @ 2003-09-11 17:14 UTC (permalink / raw)
  To: jamie, ak; +Cc: linux-kernel, akpm, torvalds

Potentially, any address can be a candidate. If you assume a sequential
access pattern for data, addresses toward the back of the cache-line
(but not the last few bytes) are less likely to hit the errata
because hopefully the page that the cacheline is in is 
already "faulted in". But that is no guarantee.


] -Rich ...
] AMD Fellow
] richard.brunner at amd com 

> -----Original Message-----
> From: Jamie Lokier [mailto:jamie@shareable.org] 
> Sent: Thursday, September 11, 2003 9:59 AM
> To: Andi Kleen
> Cc: Brunner, Richard; linux-kernel@vger.kernel.org; 
> akpm@osdl.org; torvalds@osdl.org
> Subject: Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
> 
> 
> Andi Kleen wrote:
> > +static int is_prefetch(struct pt_regs *regs, unsigned long addr)
> 
> Do I understand that certain values of "addr" can't be due to the
> erratum?
> 
> In which case, could you skip most of the is_prefetch() instruction
> decoder with a test like this?:
> 
> 	if ((addr & 3) == 0)
> 		return 0;
> 
> I'm not sure from the description of the erratum what, exactly, are
> the possible addresses which can appear in the fault information.
> 
> -- Jamie
> 


^ permalink raw reply	[flat|nested] 122+ messages in thread
* RE: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-11 17:09 richard.brunner
  0 siblings, 0 replies; 122+ messages in thread
From: richard.brunner @ 2003-09-11 17:09 UTC (permalink / raw)
  To: jamie; +Cc: linux-kernel

If the program is doing lots of page faults to SEGV signals 
intentionally, each of those transitions (exception to-> kernel ->
process -> signal-back to user) is already pretty expensive.
I would think that the slight overhead that is_prefetch() 
adds in this case is pretty low in comparision because 
the transitions themselves are very expensive in cycles. 
Most of the time, is_prefetch should be able to tell if 
it is a prefetch from just reading the first byte 
(one memory access).

We can measure this for such programs if need be, but, I would bet
we won't see any difference.

Having said that, I'm agnostic to whether is_prefetch() 
gets compiled out for non-AMD processors. I defer to 
all the kernel experts here if that is feasible or not.


] -Rich ...
] AMD Fellow
] richard.brunner at amd com 

> -----Original Message-----
> From: Jamie Lokier [mailto:jamie@shareable.org] 
> Sent: Thursday, September 11, 2003 9:55 AM
> To: Brunner, Richard
> Cc: linux-kernel@vger.kernel.org
> Subject: Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
> 
> 
> richard.brunner@amd.com wrote:
> > Don't worry! I am pretty certain the patch won't impact the 
> > performance of the 2.6 kernel on processors from other vendors ;-)
> 
> is_prefetch() will slow down programs which depend on lots of SEGV
> signals: those garbage collectors which use mprotect and SIGSEGV to
> track dirty pages.
> 
> I wonder how much it will slow them down.
> 
> -- Jamie
> 


^ permalink raw reply	[flat|nested] 122+ messages in thread
* RE: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-11  4:55 richard.brunner
  2003-09-11 16:55 ` Jamie Lokier
  2003-09-12 14:14 ` Martin Schlemmer
  0 siblings, 2 replies; 122+ messages in thread
From: richard.brunner @ 2003-09-11  4:55 UTC (permalink / raw)
  To: linux-kernel

Jun,

I have to agree with what Andi says. It is in a slow path,
and we want to guard against user programs that could hit it.
Making it conditional doesn't buy a lot and would cause lots of
re-validation of the patch that we would like
to avoid so we can get this in to the 2.6 kernel ASAP. 
Don't worry! I am pretty certain the patch won't impact the 
performance of the 2.6 kernel on processors from other vendors ;-)

                       Thanks!
                                          ]-Rich ...
                                          ]AMD Fellow
> From: Nakajima, Jun [mailto:jun.nakajima@intel.com] 
>
> > I would hate to break this again just to save a few hundred bytes in 
> > this function. Also the overhead is very low so it is also not 
> > interesting to make it conditional for speed reasons.
> 
> For maintenance and testing purposes, I think it's still 
> better to make it conditional. If the errata are fixed, you 
> might want to kill the condition depending on the stepping, 
> for example. During the transition time, you need to support 
> both the steppings until old ones go away (then remove the 
> workaround).
> 
> Thanks,
> Jun


^ permalink raw reply	[flat|nested] 122+ messages in thread
[parent not found: <uqD5.3BI.3@gated-at.bofh.it>]
* RE: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
@ 2003-09-11  3:43 Nakajima, Jun
  2003-09-11  4:03 ` Valdis.Kletnieks
  0 siblings, 1 reply; 122+ messages in thread
From: Nakajima, Jun @ 2003-09-11  3:43 UTC (permalink / raw)
  To: Andi Kleen, Andrew Morton
  Cc: richard.brunner, linux-kernel, torvalds, Mallick, Asit K

> I would hate to break this again just to save a few hundred bytes in
> this function. Also the overhead is very low so it is also not
> interesting to make it conditional for speed reasons.

For maintenance and testing purposes, I think it's still better to make
it conditional. If the errata are fixed, you might want to kill the
condition depending on the stepping, for example. During the transition
time, you need to support both the steppings until old ones go away
(then remove the workaround).

Thanks,
Jun

> -----Original Message-----
> From: Andi Kleen [mailto:ak@suse.de]
> Sent: Wednesday, September 10, 2003 6:47 PM
> To: Andrew Morton
> Cc: Andi Kleen; richard.brunner@amd.com; linux-kernel@vger.kernel.org;
> torvalds@osdl.org
> Subject: Re: [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata
> 
> On Wed, Sep 10, 2003 at 06:44:14PM -0700, Andrew Morton wrote:
> > Andi Kleen <ak@suse.de> wrote:
> > >
> > >  +static int is_prefetch(struct pt_regs *regs, unsigned long addr)
> >
> > Can we make this code go away if the configured CPU is, say, Intel?
> > (I couldn't find a sane CONFIG_ setting to use for this).
> 
> It could be done but ... we are moving more and more to generic
kernels
> (e.g. see the alternative patch code which is enabled unconditionally)
> So that when you have a kernel it will boot on near all modern CPUs.
> Currently Athlon and P4 kernels run on each other for example.
> 
> I would hate to break this again just to save a few hundred bytes in
> this function. Also the overhead is very low so it is also not
> interesting to make it conditional for speed reasons.
> 
> >
> > It might be vaguely interesting to add a user-visible counter for
this
> > event? If someone somehow comes up with an application which hits
the
> fault
> > frequently they will take a big performance hit.
> 
> In that case they can just profile the kernel. is_prefetch should
> show it then.
> 
> Of course someone can still add the counter if they want, I'm not
> opposed to it.
> 
> -Andi
> 
> -
> To unsubscribe from this list: send the line "unsubscribe
linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply	[flat|nested] 122+ messages in thread
* Update on AMD Athlon/Opteron/Athlon64 Prefetch Errata
@ 2003-09-11  0:56 richard.brunner
  2003-09-11  1:27 ` [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata Andi Kleen
  0 siblings, 1 reply; 122+ messages in thread
From: richard.brunner @ 2003-09-11  0:56 UTC (permalink / raw)
  To: linux-kernel

Dear LKML,

Continuing my yearly tradition of posting just one long
novel to LKML every year, here is the literary update on the
Prefetch Errata that the early 2.6 Kernels hit on AMD Athlon
Processors.

This previously published errata can occur infrequently and
is present in all AMD Athlon processors and earlier AMD
Opteron/Athlon64 processors.  See [1] and [2].

The full details are below, but the key point is that under
certain circumstances, prefetch instructions can get memory
management faults for addresses which would fault if they
were accessed by a load or store instruction.  We plan to
revise our published errata with the new information below.

The errata requires a kernel workaround, but the good news
is that it is:

  - Harmless in most cases where it could occur. Most of the
    time the prefetch will be targeting memory that is
    accessible under the current privilege mode. So the page
    will simply be "faulted in" slightly earlier than
    needed.

  - Rare and Infrequent. AMD Athlon processors have been
    available for years running numerous Operating Systems
    and only recently have we hit this errata outside of
    code specifically designed to target the errata --
    requiring tens of thousands of iterations to cause it.

  - It can be worked around. Andi Kleen has a 2.6 and a 2.4
    Kernel patches that we have tested at AMD on a large
    number of AMD Athlon processors and AMD Opteron/Athlon64
    processors (both legacy x86 and x86-64 long mode).  It
    works just fine. (Andi will be posting them soon when he 
    wakes up ;-)

  - AMD is fixing this in future revisions of AMD
    Opteron/Athlon64 processors.

  - Andi's kernel patches will not be needed on future
    AMD processors but it is forward compatible and so
    won't break on them either.
 


The Details
===========
Software prefetch instructions are defined to ignore page
faults. Under highly specific and detailed internal
circumstances, the following conditions may cause the
PREFETCH instruction to report a page fault.

+ The target address of the PREFETCH would cause a page
  fault if the address was accessed by an actual memory load
  or store instruction under the current privilege mode.

+ The instruction is a PREFETCH or PREFETCHNTA/0/1/2
  followed in execution-order by an actual or speculative
  byte-sized load to the same address.

  In this case, the page fault exception error code bits for
  the faulting PREFETCH would be identical to that for a
  byte-sized load to the same address.

+ The instruction is a PREFETCHW followed in execution-order
  by an actual or speculative byte-sized store to the same
  address.
  
  In this case, the page fault exception error code bits for
  the faulting PREFETCHW would be identical to that for a
  byte-sized store to the same address.

Note that some misaligned accesses can be broken up by the
processor into multiple accesses where at least one of the
accesses is a byte-sized access.

If the target address of the subsequent memory load or store
is aligned and not byte-sized, this errata does not occur
and no work-around is needed.

So the net effect is that an unexpected page fault may occur
infrequently on a PREFETCH instruction.


Kernel Work-around
=================
The kernel can work around the errata by modifying the Page
Fault Handler in the following way.  This is what Andi
Kleen's patches do.  Because the actual errata is infrequent
it does not produce an excessive number of page faults that
affect system performance.
   
+ Continue to allow the page fault handler to satisfy the
  page fault.  If the faulting instruction is permitted
  access to the page, return to it as usual.

+ If the faulting instruction is not permitted access to the
  page, scan the instruction stream bytes at the faulting
  Instruction Pointer to determine if the instruction is a
  PREFETCH. 

+ If it is not a PREFETCH instruction, generate the
  appropriate memory access control violation as
  appropriate.

+ If the faulting instruction is a PREFETCH instruction,
  simply return back to it; the internal hardware conditions
  that caused the PREFETCH to fault should be removed and
  operation should continue normally.


General Work-around
===================
If the page-fault handler for a kernel can be patched as
described above, no further action by software is
required. The following general work-arounds should only be
considered for kernels where the page-fault handler can not
be patched and a PREFETCH instruction could end up targeting
an address in an "inaccessible" page. (An "inaccessible"
page is one for which memory accesses are not allowed under
the current privilege mode.)

Because the actual errata is infrequent, it does not produce
an excessive number of page faults that affect system
performance.  Therefore a page fault from a PREFETCH
instruction for an address within an "accessible" page does
not require any general work-around.  (An "accessible" page
is one for which memory accesses are allowed under the
current privilege mode once the page is resident in memory)

Software can minimize the occurrence of the errata by
issuing only one PREFETCH instruction per cache-line (a
naturally-aligned 64-byte quantity on AMD Athlon and AMD
Opteron/Athlon64) and ensuring one of the following:

+ In many cases, if a particular target address of a
  prefetch is known to encounter this errata, simply change
  the prefetch to target the next byte.

+ Avoid prefetching inaccessible memory locations, when
  possible.

+ In the general case, ensure that the address used by the
  PREFETCH is offset into the middle of an aligned quadword
  near the end of the cache-line. For example, if the
  address desired to be prefetched is "ADDR", use an offset
  of 0x33 to compute the address used by the actual PREFETCH
  instruction as: "(ADDR & ~0x3f) + 0x33"




Footnotes
=========
[1] AMD Athlon(tm) Processor Model 6 Revision Guide 24332F June 2003.
    
www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/24332.pdf


[2] Revision Guide for AMD Opteron(tm) Processors 25759 Rev. 3.07 Aug 2003

www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/25759.PDF


] -Rich ...
] AMD Fellow


^ permalink raw reply	[flat|nested] 122+ messages in thread

end of thread, other threads:[~2003-09-18 17:43 UTC | newest]

Thread overview: 122+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-15  8:31 [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata John Bradford
2003-09-15  8:32 ` Nick Piggin
2003-09-15 20:51   ` Adrian Bunk
  -- strict thread matches above, loose matches on Subject: below --
2003-09-16  2:23 richard.brunner
2003-09-15 20:20 Nakajima, Jun
2003-09-15 20:03 Nakajima, Jun
2003-09-15 19:51 richard.brunner
2003-09-16  0:01 ` David Lang
2003-09-16  0:20 ` Bill Davidsen
2003-09-16 11:50 ` Jamie Lokier
2003-09-16 13:46   ` Bill Davidsen
2003-09-16 17:21     ` Jamie Lokier
2003-09-15 19:34 John Bradford
2003-09-15 19:25 ` Bill Davidsen
2003-09-15 22:28 ` Alan Cox
2003-09-15 19:19 John Bradford
     [not found] <200309150632.h8F6WnHb000589@81-2-122-30.bradfords.org.uk.suse.lists.linux.kernel>
     [not found] ` <1063611650.2674.1.camel@dhcp23.swansea.linux.org.uk.suse.lists.linux.kernel>
2003-09-15 18:29   ` Andi Kleen
2003-09-15 16:21 richard.brunner
2003-09-15 19:15 ` Bill Davidsen
2003-09-16 11:46 ` Jamie Lokier
2003-09-16 13:30   ` Dave Jones
2003-09-16 13:52     ` Bill Davidsen
2003-09-16 15:25       ` Timothy Miller
2003-09-16 16:53         ` Bill Davidsen
2003-09-16 17:22         ` Jamie Lokier
2003-09-16 17:23       ` Jamie Lokier
2003-09-18  7:43 ` Pavel Machek
2003-09-18 14:05   ` Dave Jones
2003-09-18 15:56     ` Jamie Lokier
2003-09-18 17:34   ` Bill Davidsen
2003-09-15 14:21 John Bradford
2003-09-15 12:43 John Bradford
2003-09-15 18:21 ` Bill Davidsen
2003-09-15 12:28 Mikael Pettersson
2003-09-15 18:13 ` Bill Davidsen
2003-09-16 11:54 ` Jamie Lokier
2003-09-15 11:46 John Bradford
2003-09-15 12:38 ` Nick Piggin
2003-09-15 13:46   ` Chris Meadors
2003-09-15 14:00     ` Nick Piggin
2003-09-16 15:06   ` Bill Davidsen
2003-09-16 15:24     ` Nick Piggin
2003-09-15 10:54 John Bradford
2003-09-15 10:52 ` Nick Piggin
2003-09-15 13:45 ` Alan Cox
2003-09-15 18:44   ` Bill Davidsen
2003-09-15  9:39 John Bradford
2003-09-15  9:58 ` Nick Piggin
2003-09-15  6:32 John Bradford
2003-09-15  7:40 ` Alan Cox
2003-09-15 12:02   ` Bill Davidsen
2003-09-15 11:48 ` Bill Davidsen
2003-09-15 20:55 ` Adrian Bunk
2003-09-16  0:26   ` Bill Davidsen
2003-09-12 21:24 John Bradford
2003-09-11 17:17 richard.brunner
2003-09-13 16:54 ` Pavel Machek
2003-09-11 17:14 richard.brunner
2003-09-11 17:09 richard.brunner
2003-09-11  4:55 richard.brunner
2003-09-11 16:55 ` Jamie Lokier
2003-09-12 14:14 ` Martin Schlemmer
     [not found] <uqD5.3BI.3@gated-at.bofh.it>
2003-09-11  4:14 ` Andi Kleen
2003-09-11  4:58   ` dada1
2003-09-11  5:11     ` Andi Kleen
2003-09-11  5:58       ` dada1
2003-09-11  3:43 Nakajima, Jun
2003-09-11  4:03 ` Valdis.Kletnieks
2003-09-11  0:56 Update on AMD Athlon/Opteron/Athlon64 Prefetch Errata richard.brunner
2003-09-11  1:27 ` [PATCH] 2.6 workaround for Athlon/Opteron prefetch errata Andi Kleen
2003-09-11  1:44   ` Andrew Morton
2003-09-11  1:47     ` Andi Kleen
2003-09-11 14:15       ` Jeff Garzik
2003-09-11 14:26         ` Andi Kleen
2003-09-11 14:34           ` Jeff Garzik
2003-09-11 14:58             ` Andi Kleen
2003-09-11 15:06               ` Jeff Garzik
2003-09-11 20:08               ` bill davidsen
2003-09-11 19:56             ` bill davidsen
2003-09-11 20:44               ` Alan Cox
2003-09-11 21:29                 ` Mike Fedyk
2003-09-11 21:38                 ` bill davidsen
2003-09-12 17:32             ` Eric W. Biederman
2003-09-12 17:56               ` Andi Kleen
2003-09-12 17:59                 ` Jeff Garzik
2003-09-12 18:22                   ` Adrian Bunk
2003-09-12 18:28                     ` Andi Kleen
2003-09-12 18:39                       ` Jeff Garzik
2003-09-12 18:45                       ` Jeff Garzik
2003-09-12 18:48                       ` Adrian Bunk
2003-09-12 19:07                         ` Andi Kleen
2003-09-12 19:05                       ` Martin Schlemmer
2003-09-12 19:30                         ` Andi Kleen
2003-09-12 19:58                           ` Martin Schlemmer
2003-09-12 20:00                           ` Adrian Bunk
2003-09-15  0:15                           ` bill davidsen
2003-09-14 23:51                       ` bill davidsen
2003-09-14 23:49                     ` bill davidsen
2003-09-14 23:47                 ` bill davidsen
2003-09-15  1:02                   ` Zwane Mwaikambo
2003-09-15  2:08                     ` Nick Piggin
2003-09-15  3:55                     ` Bill Davidsen
2003-09-15  7:45                       ` Alan Cox
2003-09-15 12:11                         ` Bill Davidsen
2003-09-15 13:48                           ` Alan Cox
2003-09-15 18:50                             ` Bill Davidsen
2003-09-12 18:03               ` Mike Fedyk
2003-09-11 13:54   ` Linus Torvalds
2003-09-11 14:01     ` Andi Kleen
2003-09-11 14:14       ` Dave Jones
2003-09-11 14:29         ` Andi Kleen
2003-09-11 14:14     ` Alan Cox
2003-09-11 14:24       ` Andi Kleen
2003-09-11 14:28         ` Dave Jones
2003-09-11 14:32           ` Andi Kleen
2003-09-11 20:14         ` bill davidsen
2003-09-11 16:58   ` Jamie Lokier
2003-09-11 17:05     ` Andi Kleen
2003-09-11 17:32       ` Jamie Lokier
2003-09-11 17:39         ` Andi Kleen
2003-09-11 17:48           ` Jamie Lokier
2003-09-11 18:18             ` Andi Kleen
2003-09-11 18:59               ` Jamie Lokier

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).