Example of memory ordering causing excitement in the real world

By: Linus Torvalds (torvalds.delete@this.linux-foundation.org), July 12, 2015 12:38 pm
Room: Moderated Discussions
Maynard Handley (name99.delete@this.name99.org) on July 12, 2015 12:32 pm wrote:
>
> Linus, this seems like a reasonable argument BUT there are at least two ISAs that have been
> designed since 20 years ago: ARMv8 and RISC-V.

So I'm going to dismiss RISC-V as "academic", and I think they ended up with the weak ordering because it's "pretty". I think it's a very easy trap to fall into, especially if one of the major goals of your architecture is mainly academia ("research and education").

I think weak memory ordering is easier to just explain to people conceptually. Never mind that it may be harder to use. It's pretty simple to say "loads and stores are not ordered", and then (because that leads to problems) introduce the notion of acquire and release on top of that in terms of locking primitive rules.

In contrast, the x86 model of "all loads are acquires and all stores are releases" sounds odd. It doesn't sound symmetric or clean, even if that particular wording is probably the most symmetric and clean wording you can find for it.

As to ARMv8, I obviously think it was a mistake. But it's a very natural one to make when you come from the ARM background. I don't think ARMv8 is really a "new" model, it's just ARM with completely different encoding, and an updated baseline from ARM.

I wonder if we could make the x86 model more palatable to academic people by pointing out how broken the traditional memory barriers are (really, acquire/release is so much better than the "read/write/full" memory barrier crap, and even academics understand that), and then really describe x86 just in terms of being the most beautiful model because everything is acquire/release.

IOW, do some kind of mental judo on people who seem to like weak memory ordering just because of the symmetry and the "simplicity" of the model. ;)

> I can offer one possible example. You leave the compiler out your discussion, but it is often the case that
> you have to indicate to the compiler (not just the HW) about memory re-ordering. So it's reasonable at that
> point to say "since this information has to be in the program, anyway, if you want correctness in the face of
> modern compilers, so why not propagate it down to the hardware, and we can perhaps usefully use it there?"
> Now how can it usefully be used even if you are performing speculative load-hoisting?
> I don't know; but then I am no expert (hardly even much of an amateur) in this area.

So I realize that people use that as an argument, and I think it's a very sad and bad argument.

Because it's basically saying "well, hardware does shit things too, so let's make compilers do even more crap things, and then use that as an argument for hardware doing crap in the first place".

A mentally damaged sloth on drugs can see that the above is a circular argument and a logical fallacy.

But apparently those mentally damaged dug-infused sloths are smarter than many people in the tech world. I see your argument much too often, and it makes me sad and angry.

I've been involved in the whole "atomic access" discussion for the C standard (happily only as a distant person, not intimately) and it's insane. The standards language people are trying to introduce for "mo_consume" (which is basically "acquire, but not on ARM and Powerpc") is a mess. It's sad, and it's all because the C language standards people are trying to bend over backwards for the crap memory ordering of bad CPU's.

It should be just "acquire", but since that's expensive on ARM and PowerPC, people really want to use regular loads, and depend on the data dependency consistency that everybody but alpha has. And it turns out that just describing the data dependency consistency is horrible and crazy, and I can currently guarantee that

(a) no compiler writer will ever get it right or understand it

(b) no actual user will ever really understand it anyway, and will then use it without understanding the rules.

simply because the C standards language as currently proposed is fragile and unreadable.

Do you really think that is a good situation?

And the argument people use for this? It's that the language should cater to shit CPU semantics. And then the next step is exactly the one you're using: that since the compiler already breaks things, why should the hardware then work any better?

I seriously believe that the C standards committee is doing the wrong thing. They've done it for a long time. Re-ordering memory accesses by the compiler is not valid. Doing speculative writes to memory locations is not valid. It really should be that simple. Sure, the compiler can reorder things that it can prove are not semantically visible, but that's the only reordering the compiler should do.

And yes, the C model of "strict aliasing" is broken shit. And yes, it actually does break real code. Most of the time the damage is limited by just the fact that re-ordering by the compiler is usually limited by other things (like function calls), and by the fact that a lot of real-world code isn't actually compiled with insane optimizations.

Rant over. But the short answer is that yes, I've been involved at the compiler side too, and I've ranted on that side too.

Linus
< Previous Post in ThreadNext Post in Thread >
TopicPosted ByDate
Cyclone Macro-op fusionMaynard Handley2015/07/05 05:01 PM
  Cyclone Macro-op fusionGabriele Svelto2015/07/06 01:11 AM
    Cyclone Macro-op fusionMaynard Handley2015/07/06 09:25 AM
      Cyclone Macro-op fusionWilco2015/07/06 10:17 AM
        Cyclone Macro-op fusionMaynard Handley2015/07/06 11:07 AM
          Cyclone Macro-op fusionMaynard Handley2015/07/06 11:55 AM
            Cyclone Macro-op fusionGabriele Svelto2015/07/07 01:49 AM
      Power8 branch conversionSHK2015/07/06 11:41 AM
        Power8 branch conversionMaynard Handley2015/07/06 12:01 PM
          Power8 branch conversionMaynard Handley2015/07/06 12:09 PM
        Benefit of dynamic hammock predicationPaul A. Clayton2015/07/06 02:02 PM
          Benefit of dynamic hammock predicationMaynard Handley2015/07/06 02:34 PM
            Benefit of dynamic hammock predicationEduardoS2015/07/06 06:56 PM
            Benefit of dynamic hammock predicationPatrick Chase2015/07/06 09:30 PM
          Benefit of dynamic hammock predicationLinus Torvalds2015/07/06 02:59 PM
            Benefit of dynamic hammock predicationWilco2015/07/06 03:35 PM
              Benefit of dynamic hammock predicationLinus Torvalds2015/07/06 04:25 PM
                Benefit of dynamic hammock predicationanon2015/07/06 08:02 PM
            Benefit of dynamic hammock predicationPatrick Chase2015/07/06 09:31 PM
              Benefit of dynamic hammock predicationanon2015/07/06 10:02 PM
              Benefit of dynamic hammock predicationMichael S2015/07/07 12:07 AM
              Benefit of dynamic hammock predicationLinus Torvalds2015/07/07 08:23 AM
                Benefit of dynamic hammock predicationPatrick Chase2015/07/07 09:49 AM
                  Benefit of dynamic hammock predicationSHK2015/07/07 10:34 AM
                  Benefit of dynamic hammock predicationMaynard Handley2015/07/07 11:00 AM
                    Benefit of dynamic hammock predicationExophase2015/07/07 12:26 PM
                      Benefit of dynamic hammock predicationWilco2015/07/07 03:54 PM
                      Benefit of dynamic hammock predicationMaynard Handley2015/07/07 04:25 PM
                    Benefit of dynamic hammock predicationPatrick Chase2015/07/07 01:32 PM
                    Benefit of dynamic hammock predicationMichael S2015/07/08 12:57 AM
                  Benefit of dynamic hammock predicationSylvain Collange2015/07/08 05:30 AM
                    Benefit of dynamic hammock predicationMaynard Handley2015/07/08 08:46 AM
                      Benefit of dynamic hammock predicationSylvain Collange2015/07/08 09:32 AM
                        Benefit of dynamic hammock predicationMaynard Handley2015/07/08 09:57 AM
                        Sadly, skewed associativity has not been broadly adoptedPaul A. Clayton2015/07/08 01:00 PM
                        Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)Maynard Handley2015/07/08 07:23 PM
                          Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)David Kanter2015/07/09 06:20 AM
                            Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)Maynard Handley2015/07/09 09:04 AM
                              Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)Tim McCaffrey2015/07/09 09:41 AM
                                Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)Patrick Chase2015/07/09 12:08 PM
                                  Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)Sylvain Collange2015/07/10 01:03 AM
                              Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)David Kanter2015/07/09 03:15 PM
                                Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)Maynard Handley2015/07/09 04:21 PM
                            Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)Patrick Chase2015/07/09 11:44 AM
                          Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)Patrick Chase2015/07/09 08:43 AM
                          Prediction quality of A8 and Intel (was Benefit of dynamic hammock predication)someone2015/07/10 04:43 AM
            Benefit of dynamic hammock predicationKonrad Schwarz2015/07/07 06:54 AM
            Benefit of dynamic hammock predicationdmcq2015/07/07 01:38 PM
              Benefit of dynamic hammock predicationLinus Torvalds2015/07/08 07:23 AM
                Benefit of dynamic hammock predicationdmcq2015/07/08 09:11 AM
                  Benefit of dynamic hammock predicationLinus Torvalds2015/07/08 12:38 PM
                    Example of memory ordering causing excitement in the real worldMark Roulo2015/07/08 03:54 PM
                      Example of memory ordering causing excitement in the real worlddmcq2015/07/09 03:37 AM
                        Example of memory ordering causing excitement in the real worldMark Roulo2015/07/09 07:24 AM
                          Example of memory ordering causing excitement in the real worlddmcq2015/07/09 09:09 AM
                          Example of memory ordering causing excitement in the real worldMaynard Handley2015/07/09 09:12 AM
                            Example of memory ordering causing excitement in the real worldLinus Torvalds2015/07/09 11:14 AM
                              Example of memory ordering causing excitement in the real worlddmcq2015/07/09 03:24 PM
                                Example of memory ordering causing excitement in the real worldSimon Farnsworth2015/07/10 12:07 PM
                                  Example of memory ordering causing excitement in the real worlddmcq2015/07/10 02:49 PM
                                    Example of memory ordering causing excitement in the real worldSimon Farnsworth2015/07/12 12:02 PM
                                      Example of memory ordering causing excitement in the real worlddmcq2015/07/13 04:03 AM
                                        Example of memory ordering causing excitement in the real worldMichael S2015/07/13 04:19 AM
                                        Example of memory ordering causing excitement in the real worldSimon Farnsworth2015/07/14 12:21 PM
                                          Example of memory ordering causing excitement in the real worlddmcq2015/07/14 01:54 PM
                                            Example of memory ordering causing excitement in the real worldSimon Farnsworth2015/07/15 12:13 PM
                                              Example of memory ordering causing excitement in the real worlddmcq2015/07/15 02:43 PM
                                                Example of memory ordering causing excitement in the real worldSimon Farnsworth2015/07/16 11:41 AM
                                                  Example of memory ordering causing excitement in the real worldWilco2015/07/17 12:57 PM
                                                    Example of memory ordering causing excitement in the real worldLinus Torvalds2015/07/17 03:29 PM
                                                      Example of memory ordering causing excitement in the real worlddmcq2015/07/18 03:07 AM
                                          Example of memory ordering causing excitement in the real worldJouni Osmala2015/07/16 02:52 AM
                                            Example of memory ordering causing excitement in the real worldSimon Farnsworth2015/07/16 12:05 PM
                                              Example of memory ordering causing excitement in the real worldJouni Osmala2015/07/17 12:18 AM
                                                ISA support for bound checkingMichael S2015/07/17 03:51 AM
                                                  ISA support for bound checkingEtienne2015/07/17 05:39 AM
                                                  MPX on SkylakeMark Roulo2015/07/17 07:19 AM
                                                    MPX on SkylakeMichael S2015/07/17 07:44 AM
                                                      MPX on SkylakeMark Roulo2015/07/17 08:03 AM
                                  Example of memory ordering causing excitement in the real worldanon2015/07/12 02:42 AM
                                    Example of memory ordering causing excitement in the real worlddmcq2015/07/12 09:27 AM
                                    Example of memory ordering causing excitement in the real worldLinus Torvalds2015/07/12 10:24 AM
                                      Example of memory ordering causing excitement in the real worldEduardoS2015/07/12 10:53 AM
                                        Example of memory ordering causing excitement in the real worldLinus Torvalds2015/07/12 12:07 PM
                                          Example of memory ordering causing excitement in the real worldanon2015/07/12 06:52 PM
                                            Example of memory ordering causing excitement in the real worldLinus Torvalds2015/07/13 10:05 AM
                                              Example of memory ordering causing excitement in the real worlddmcq2015/07/13 11:20 AM
                                                Example of memory ordering causing excitement in the real worldLinus Torvalds2015/07/13 12:46 PM
                                                  Example of memory ordering causing excitement in the real worldMaynard Handley2015/07/13 01:10 PM
                                                    Example of memory ordering causing excitement in the real worldanon2015/07/13 07:51 PM
                                                    Simple cores justifying weak ordering?Paul A. Clayton2015/07/14 08:01 AM
                                                      David's Paul A. Clayton2015/07/14 08:37 AM
                                                      David's 2015-07-12 10:34 post confirmed some of that (NT)Paul A. Clayton2015/07/14 08:39 AM
                                                    Example of memory ordering causing excitement in the real worldEtienne2015/07/17 12:15 AM
                                                  Example of memory ordering causing excitement in the real worlddmcq2015/07/13 01:14 PM
                                                  Reality is even worseTerry Gray2015/07/13 05:05 PM
                                                    Reality is even worseKonrad Schwarz2015/07/20 11:13 PM
                                                  A simple CAS/MCAS semantics2015/07/15 11:54 AM
                                                    A simple CAS/MCAS semanticsLinus Torvalds2015/07/15 12:55 PM
                                                    A simple CAS/MCAS semanticsEduardoS2015/07/15 01:31 PM
                                                Example of memory ordering causing excitement in the real worldsylt2015/07/13 01:19 PM
                                                  Example of memory ordering causing excitement in the real worlddmcq2015/07/13 02:24 PM
                                                    Example of memory ordering causing excitement in the real worldEduardoS2015/07/13 03:48 PM
                                                      Example of memory ordering causing excitement in the real worldMaynard Handley2015/07/13 06:18 PM
                                                        Example of memory ordering causing excitement in the real worldEduardoS2015/07/13 06:57 PM
                                                      Example of memory ordering causing excitement in the real worldanon2015/07/13 08:01 PM
                                                    What high level languages do you have in mind?Mark Roulo2015/07/13 04:00 PM
                                                      What high level languages do you have in mind?dmcq2015/07/14 05:54 AM
                                                  Example of memory ordering causing excitement in the real worldWilco2015/07/13 03:36 PM
                                                    Example of memory ordering causing excitement in the real worldEduardoS2015/07/13 03:56 PM
                                                      Example of memory ordering causing excitement in the real worldanon2015/07/13 05:43 PM
                                                        Example of memory ordering causing excitement in the real worldEduardoS2015/07/13 07:11 PM
                                                          Example of memory ordering causing excitement in the real worldanon2015/07/13 08:07 PM
                                      Example of memory ordering causing excitement in the real worldMaynard Handley2015/07/12 11:32 AM
                                        Example of memory ordering causing excitement in the real worldEduardoS2015/07/12 12:35 PM
                                        Example of memory ordering causing excitement in the real worldLinus Torvalds2015/07/12 12:38 PM
                                          Example of memory ordering causing excitement in the real worldEduardoS2015/07/12 05:47 PM
                                            Example of memory ordering causing excitement in the real worldNoSpammer2015/07/13 11:34 AM
                                              Example of memory ordering causing excitement in the real worldWilco2015/07/13 03:50 PM
                                                Example of memory ordering causing excitement in the real worldNoSpammer2015/07/14 01:02 PM
                                                  Example of memory ordering causing excitement in the real worldanon2015/07/14 08:37 PM
                                                    Example of memory ordering causing excitement in the real worldMichael S2015/07/15 12:19 AM
                                                      Example of memory ordering causing excitement in the real worldanon2015/07/15 01:26 AM
                                                        Example of memory ordering causing excitement in the real worldNoSpammer2015/07/15 06:05 AM
                                                          Example of memory ordering causing excitement in the real worlddmcq2015/07/15 07:04 AM
                                                            Example of memory ordering causing excitement in the real worldMichael S2015/07/15 07:29 AM
                                                              Example of memory ordering causing excitement in the real worlddmcq2015/07/15 09:09 AM
                                                              Can string ops use microarchitectural state?Paul A. Clayton2015/07/16 08:33 AM
                                                                Can string ops use microarchitectural state?rwessel2015/07/16 12:00 PM
                                                                  Can string ops use microarchitectural state?Paul A. Clayton2015/07/16 05:16 PM
                                                                    Can string ops use microarchitectural state?rwessel2015/07/16 08:34 PM
                                                                      Can string ops use microarchitectural state?Michael S2015/07/17 04:39 AM
                                                                        Can string ops use microarchitectural state?rwessel2015/07/17 08:02 AM
                                                                Consider interrupt followed by task preemptionMichael S2015/07/16 03:31 PM
                                                                  Consider interrupt followed by task preemptionPaul A. Clayton2015/07/16 05:23 PM
                                                            Example of memory ordering causing excitement in the real worldNoSpammer2015/07/15 11:50 AM
                                                              Example of memory ordering causing excitement in the real worldLinus Torvalds2015/07/15 01:27 PM
                                                                Example of memory ordering causing excitement in the real worldNoSpammer2015/07/15 02:14 PM
                                                                  Example of memory ordering causing excitement in the real worldLinus Torvalds2015/07/15 04:42 PM
                                                      Example of memory ordering causing excitement in the real worldNoSpammer2015/07/15 01:44 AM
                                                    Example of memory ordering causing excitement in the real worldLinus Torvalds2015/07/15 01:17 PM
                                                      Example of memory ordering causing excitement in the real worldWilco2015/07/15 01:43 PM
                                                        Example of memory ordering causing excitement in the real worldanon2015/07/15 04:45 PM
                                                        Example of memory ordering causing excitement in the real worldLinus Torvalds2015/07/15 05:35 PM
                                                          Example of memory ordering causing excitement in the real worlddmcq2015/07/16 01:46 AM
                                                            Example of memory ordering causing excitement in the real worlddmcq2015/07/16 01:49 AM
                                        Example of memory ordering causing excitement in the real worldKonrad Schwarz2015/07/21 06:15 AM
                                      Example of memory ordering causing excitement in the real worldanon2015/07/12 06:42 PM
                                        Example of memory ordering causing excitement in the real worldanon2015/07/12 08:48 PM
                                        Example of memory ordering causing excitement in the real worldDavid Kanter2015/07/12 09:34 PM
                                          Example of memory ordering causing excitement in the real worldMichael S2015/07/13 12:51 AM
                                            Example of memory ordering causing excitement in the real worldDavid Kanter2015/07/13 07:31 AM
                                          Example of memory ordering causing excitement in the real worldanon2015/07/13 05:05 AM
                                            Example of memory ordering causing excitement in the real worldGabriele Svelto2015/07/17 04:40 AM
                                          Example of memory ordering causing excitement in the real worlddmcq2015/07/13 07:09 AM
                                        Example of memory ordering causing excitement in the real worldanon2015/07/13 06:46 AM
                                          Example of memory ordering causing excitement in the real worldanon2015/07/14 03:12 AM
                                        Example of memory ordering causing excitement in the real worlddmcq2015/07/15 02:51 AM
                                          Example of memory ordering causing excitement in the real worldanon2015/07/15 03:38 AM
                                            Example of memory ordering causing excitement in the real worlddmcq2015/07/15 05:21 AM
                                      Store queues in POWER/PowerPC processorsGabriele Svelto2015/07/16 12:55 AM
                                        Not sure about that conclusionDavid Kanter2015/07/16 06:34 AM
                                          The POWER4 had the same structureGabriele Svelto2015/07/17 04:20 AM
                                        Committing stores in program orderPaul A. Clayton2015/07/16 12:35 PM
                                          Committing stores in program orderMaynard Handley2015/07/17 11:52 AM
                                      Example of memory ordering causing excitement in the real worldKonrad Schwarz2015/07/20 03:44 AM
                                        Example of memory ordering causing excitement in the real worldanon2015/07/20 06:29 AM
                                          Example of memory ordering causing excitement in the real worldKonrad Schwarz2015/07/20 11:08 PM
                                            Example of memory ordering causing excitement in the real worlddmcq2015/07/21 12:27 AM
                                            Example of memory ordering causing excitement in the real worldMichael S2015/07/21 02:11 AM
                                              Example of memory ordering causing excitement in the real worldKonrad Schwarz2015/07/21 04:24 AM
                                            Example of memory ordering causing excitement in the real worldanon2015/07/21 05:22 AM
                                              Example of memory ordering causing excitement in the real worldKonrad Schwarz2015/07/21 06:36 AM
                                                Example of memory ordering causing excitement in the real worldanon2015/07/21 07:25 AM
                                              Example of memory ordering causing excitement in the real worldanon2015/07/21 07:17 AM
                                                Example of memory ordering causing excitement in the real worldanon2015/07/21 08:50 AM
                                                Example of memory ordering causing excitement in the real worldGabriele Svelto2015/07/21 11:46 AM
                                                Example of memory ordering causing excitement in the real worldKonrad Schwarz2015/07/21 11:35 PM
                                                  Example of memory ordering causing excitement in the real worldKonrad Schwarz2015/07/22 12:37 AM
                                                  Example of memory ordering causing excitement in the real worldanon2015/07/23 02:17 AM
                                                    Example of memory ordering causing excitement in the real worldKonrad Schwarz2015/07/23 03:59 AM
                                                      Example of memory ordering causing excitement in the real worldMichael S2015/07/23 06:31 AM
                                                        Example of memory ordering causing excitement in the real worldKonrad Schwarz2015/07/23 02:38 PM
                                                          Example of memory ordering causing excitement in the real worldKonrad Schwarz2015/07/23 10:44 PM
                                                            Example of memory ordering causing excitement in the real worlddmcq2015/07/24 12:08 AM
                                    Example of memory ordering causing excitement in the real worlddmcq2015/07/13 06:27 AM
                          Example of memory ordering causing excitement in the real worldKonrad Schwarz2015/07/16 04:11 AM
                      Example of memory ordering causing excitement in the real worldAnonymousse2015/07/16 04:07 AM
          Benefit of dynamic hammock predicationsomeotherdude2015/07/06 04:12 PM
            Benefit of dynamic hammock predicationMichael S2015/07/07 12:19 AM
          Benefit of dynamic hammock predicationPatrick Chase2015/07/06 09:20 PM
            SIMD predication is also helpful, of course (NT)Paul A. Clayton2015/07/07 06:45 AM
        Power8 branch conversionGabriele Svelto2015/07/07 01:50 AM
          isel works for storesPaul A. Clayton2015/07/07 06:43 AM
            isel works for storesPatrick Chase2015/07/07 10:08 AM
            isel DOES NOT work for storessomeotherdude2015/07/07 03:01 PM
              isel DOES NOT work for storesWilco2015/07/07 03:40 PM
              Yes it doesPatrick Chase2015/07/07 10:14 PM
                Yes it doesvvid2015/07/08 08:51 AM
            You don't need isel eitherGabriele Svelto2015/07/08 01:01 AM
              You don't need isel eitherPaul A. Clayton2015/07/08 03:46 AM
                You don't need isel eitherGabriele Svelto2015/07/08 04:22 AM
Reply to this Topic
Name:
Email:
Topic:
Body: No Text
How do you spell green?