Haskell Compilation Improvement

By: Linus Torvalds (torvalds.delete@this.linux-foundation.org), April 11, 2013 12:56 pm
Room: Moderated Discussions
Eric Bron (eric.bron.delete@this.zvisuel.privatefortest.com) on April 11, 2013 11:10 am wrote:
>
> with modern cores like Ivy Bridge it's generally very frustating to toy
> with explicit prefetch since there is simply 0% speedup (no slowdown either)

We've seen slowdowns in the kernel.

Sometimes serious slowdowns.

For example, some microarchitectures do TLB fills on prefetch (which you'd think makes sense since you often do page-crossing prefetches of pointers). But then they actually seem to have trouble with the NULL pointer and slow down because the TLB fill fails and it's not zero-cost at all due to some uarch stupidity, so you have to do a conditional jump to not prefetch the end of a list. And now you slow down because the branch predicts horribly badly for the common case of short lists, and your nice cache behavior where the prefetch didn't do anything actually suffers.

And it's very annoying, because the prefetches probably made sense when they were added, and may still work fine on some machines. And on others, they are actively detrimental.

Sure, you can play games with these things - like dynamically turn them into no-ops by having instruction rewriting (so that you don't have to have runtime conditionals etc). The people who advocate sw prefetching always have a ".. but but but you could.." excuse. They never seem to get the "and what are you giving me in return for all this wasted effort" argument. When most of the time it's zero upside down the line.

In the end, I think almost every single time we added a prefetch instruction, it came back to bite us five years later and it got removed again. And most of the prefetches we still have are probably of negative actual worth, but they just haven't gotten removed, because nobody has bothered to do with performance analysis.

And yes, as you say, some of them remain because they just don't hurt (the nice array based ones with tight loops have neither I$ issues nor the above kind of TLB load issues, but they also don't tend to have any wins, since hardware does it better anyway these days).

Some of the prefetches are for things like "we know we are going to write to this, but the first access is a read, and if we do a write-prefetch we can avoid the shared state transition". So it's not actually for prefetching data per se, it's a hint to the cache state machine. And that may actually make sense (unlike actual *prefetching* it is not timing-sensitive), although I'd much rather see the OoO engine notice it on its own.

Linus
< Previous Post in ThreadNext Post in Thread >
TopicPosted ByDate
Haskell Compilation ImprovementSymmetry04/09/13 10:41 AM
  Haskell Compilation ImprovementEric Bron04/09/13 11:56 AM
  Haskell Compilation ImprovementLinus Torvalds04/09/13 12:03 PM
    Haskell Compilation ImprovementEduardoS04/09/13 12:20 PM
      Haskell Compilation ImprovementLinus Torvalds04/09/13 12:31 PM
        Haskell Compilation ImprovementEduardoS04/09/13 12:49 PM
    Haskell Compilation Improvement04/11/13 01:36 AM
      Haskell Compilation ImprovementEric Bron04/11/13 03:58 AM
        Haskell Compilation ImprovementBrendan04/11/13 07:06 AM
          Haskell Compilation ImprovementSymmetry04/11/13 07:45 AM
            Haskell Compilation ImprovementBrendan04/11/13 11:31 AM
          Haskell Compilation ImprovementEric Bron04/11/13 08:57 AM
            Haskell Compilation ImprovementBrendan04/11/13 11:26 AM
              Haskell Compilation ImprovementEric Bron04/11/13 11:36 AM
                Haskell Compilation ImprovementBrendan04/11/13 05:00 PM
                  Haskell Compilation ImprovementDavid Kanter04/11/13 08:50 PM
                    Software prefetching in JVMsGabriele Svelto04/12/13 03:31 PM
                  Haskell Compilation ImprovementEric Bron04/12/13 09:12 AM
                    Haskell Compilation ImprovementBrendan04/12/13 11:40 AM
                      Haskell Compilation ImprovementEric Bron04/12/13 12:15 PM
                        Haskell Compilation ImprovementBrendan04/12/13 03:34 PM
                          Haskell Compilation ImprovementEric Bron04/12/13 10:44 PM
                            Haskell Compilation ImprovementBrendan04/13/13 02:20 AM
                              Haskell Compilation ImprovementEric Bron04/13/13 02:32 AM
                                Haskell Compilation ImprovementBrendan04/13/13 10:18 AM
                                  Haskell Compilation ImprovementEric Bron04/14/13 01:04 AM
                          Haskell Compilation ImprovementEric Bron04/15/13 08:34 AM
                            Haskell Compilation ImprovementBrendan04/16/13 03:26 PM
                              Prefetch compilation testsEric Bron04/21/13 12:52 AM
        Haskell Compilation Improvementanon04/11/13 07:14 AM
          Haskell Compilation ImprovementMichael S04/11/13 07:27 AM
            Haskell Compilation Improvementanon04/11/13 08:25 AM
              Haskell Compilation ImprovementMichael S04/11/13 08:37 AM
                Haskell Compilation Improvementbakaneko04/11/13 09:39 AM
                  Haskell Compilation ImprovementEric Bron04/11/13 10:08 AM
                    Haskell Compilation Improvementbakaneko04/11/13 10:36 AM
                    Haskell Compilation Improvementanon04/11/13 10:54 AM
                      Haskell Compilation ImprovementEric Bron04/11/13 11:10 AM
                        Haskell Compilation Improvementanon04/11/13 11:18 AM
                          Haskell Compilation ImprovementEric Bron04/11/13 11:27 AM
                            Haskell Compilation Improvementanon04/11/13 12:02 PM
                              Haskell Compilation ImprovementEric Bron04/11/13 12:09 PM
                                Haskell Compilation ImprovementEric Bron04/11/13 12:12 PM
                                Haskell Compilation Improvementanon04/11/13 12:14 PM
                                  Haskell Compilation ImprovementEric Bron04/11/13 12:30 PM
                                    Haskell Compilation Improvementanon04/11/13 11:30 PM
                                      Haskell Compilation ImprovementEric Bron04/12/13 09:25 AM
                                        Haskell Compilation Improvementanon04/12/13 07:12 PM
                                          Haskell Compilation ImprovementEric Bron04/12/13 10:51 PM
                                  Prefetch *hints*Konrad Schwarz04/12/13 08:24 AM
                        Haskell Compilation ImprovementLinus Torvalds04/11/13 12:56 PM
                          Inherent advantage of software prefetchJouni Osmala04/11/13 09:41 PM
                            Inherent advantage of software prefetchSeni04/13/13 03:40 AM
                            Another example: software scatter gather (NT)Megol04/14/13 02:39 AM
                          Haskell Compilation ImprovementMaynard Handley12/31/13 05:26 PM
                            Haskell Compilation ImprovementTREZA12/31/13 05:44 PM
                              Haskell Compilation ImprovementMaynard Handley12/31/13 07:49 PM
                                Haskell Compilation Improvementanon12/31/13 10:39 PM
                                  Haskell Compilation ImprovementMaynard Handley01/01/14 02:04 AM
                                  Haskell Compilation Improvementbakaneko01/01/14 05:31 AM
                                Haskell Compilation ImprovementGabriele Svelto01/02/14 07:57 AM
                                  Haskell Compilation ImprovementMichael S01/02/14 08:37 AM
                                    Haskell Compilation ImprovementGabriele Svelto01/02/14 10:09 AM
                                    Haskell Compilation ImprovementTREZA01/02/14 12:43 PM
                            Haskell Compilation ImprovementMaynard Handley12/31/13 06:07 PM
                            Future core architectures. (Was Haskell Compilation Improvement)Maynard Handley01/03/14 12:06 AM
                              Speculative multi-threadingDavid Kanter01/03/14 02:12 AM
                                Speculative multi-threadingMaynard Handley01/03/14 05:01 AM
                              Future core architectures. (Was Haskell Compilation Improvement)Seni01/03/14 01:09 PM
                              Future core architectures. (Was Haskell Compilation Improvement)Linus Torvalds01/03/14 01:27 PM
                            Haskell Compilation ImprovementKonrad Schwarz01/04/14 09:38 AM
              Haskell Compilation ImprovementEric Bron04/11/13 09:23 AM
          Haskell Compilation ImprovementEric Bron04/11/13 08:50 AM
            Haskell Compilation ImprovementEugene Nalimov04/11/13 09:20 AM
              Haskell Compilation ImprovementEric Bron04/11/13 09:28 AM
                Haskell Compilation ImprovementEduardoS04/11/13 07:30 PM
            Haskell Compilation Improvementanon04/11/13 10:19 AM
              Haskell Compilation ImprovementEric Bron04/11/13 10:30 AM
                Haskell Compilation Improvementanon04/11/13 10:50 AM
                  Haskell Compilation ImprovementEric Bron04/11/13 11:03 AM
                    Haskell Compilation Improvementanon04/11/13 11:16 AM
                      Haskell Compilation ImprovementEric Bron04/11/13 11:24 AM
                        Haskell Compilation Improvementanon04/11/13 12:09 PM
                          Haskell Compilation ImprovementEric Bron04/11/13 12:43 PM
                            Haskell Compilation Improvementanon04/11/13 11:27 PM
                              Haskell Compilation ImprovementEric Bron04/12/13 12:15 AM
                                Haskell Compilation Improvementanon04/12/13 07:14 PM
                                  Haskell Compilation ImprovementEric Bron04/12/13 11:01 PM
                      Haskell Compilation ImprovementLinus Torvalds04/11/13 01:05 PM
                        Haskell Compilation Improvementanon04/11/13 10:42 PM
                        Haskell Compilation ImprovementRobert David Graham04/12/13 02:12 PM
        Software prefetch architecturePaul A. Clayton04/11/13 08:54 AM
          Software prefetch architectureEric Bron04/11/13 09:06 AM
            Software prefetch architectureMegol04/15/13 11:03 AM
              Software prefetch architectureEric Bron04/15/13 11:30 AM
  low barMichael S04/09/13 04:38 PM
Reply to this Topic
Name:
Email:
Topic:
Body: No Text
How do you spell blue?