]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: parallelize reloc sym
authorJeremy Faller <jeremy@golang.org>
Tue, 25 Feb 2020 02:08:12 +0000 (21:08 -0500)
committerJeremy Faller <jeremy@golang.org>
Mon, 9 Mar 2020 14:24:52 +0000 (14:24 +0000)
I tried a couple of different architectures (goroutine per symbol, 8
goroutines handling symbols from channels, and this architecture), and
this was the best. Another possible approach could be to divide up the
space of relocations, forgo the channels, and just pass slices to the
relocation routines, which would possibly be faster.

Reloc                     13.9ms ± 5%      9.0ms ±10%       -35.09%  (p=0.000 n=8+9)

Change-Id: I5111220e855313fae4b89d64277759c4dc33b697
Reviewed-on: https://go-review.googlesource.com/c/go/+/220842
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/link/internal/ld/data.go

index 629cd5cd27df015716c8a9f48c67c9e41354f032..25dda36293a3c2b4e448758115481e6dda7fde18 100644 (file)
@@ -571,19 +571,31 @@ func relocsym(target *Target, err *ErrorReporter, lookup LookupFn, syms *ArchSym
 }
 
 func (ctxt *Link) reloc() {
+       var wg sync.WaitGroup
        target := &ctxt.Target
        reporter := &ctxt.ErrorReporter
        lookup := ctxt.Syms.ROLookup
        syms := &ctxt.ArchSyms
-       for _, s := range ctxt.Textp {
-               relocsym(target, reporter, lookup, syms, s)
-       }
-       for _, s := range datap {
-               relocsym(target, reporter, lookup, syms, s)
-       }
-       for _, s := range dwarfp {
-               relocsym(target, reporter, lookup, syms, s)
-       }
+       wg.Add(3)
+       go func() {
+               for _, s := range ctxt.Textp {
+                       relocsym(target, reporter, lookup, syms, s)
+               }
+               wg.Done()
+       }()
+       go func() {
+               for _, s := range datap {
+                       relocsym(target, reporter, lookup, syms, s)
+               }
+               wg.Done()
+       }()
+       go func() {
+               for _, s := range dwarfp {
+                       relocsym(target, reporter, lookup, syms, s)
+               }
+               wg.Done()
+       }()
+       wg.Wait()
 }
 
 func windynrelocsym(ctxt *Link, rel, s *sym.Symbol) {