[commit: ghc] wip/better-machine-readable-stats: [rts] Count yieldThread() calls in spin-locks, and show them in stats. (7e4b859)

git at git.haskell.org git at git.haskell.org
Thu Jan 11 02:03:58 UTC 2018


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/better-machine-readable-stats
Link       : http://ghc.haskell.org/trac/ghc/changeset/7e4b859edfd1abf742d5742436a13b9dba4b3270/ghc

>---------------------------------------------------------------

commit 7e4b859edfd1abf742d5742436a13b9dba4b3270
Author: Douglas Wilson <douglas.wilson at gmail.com>
Date:   Thu Jan 11 14:00:34 2018 +1300

    [rts] Count yieldThread() calls in spin-locks, and show them in stats.
    
    Summary:
    The stats output for spin-locks is somewhat different. old:
    
    gc_alloc_block_sync: 0
    whitehole_gc_spin: 0
    gen[0].sync: 0
    gen[1].sync: 0
    
    new:
                             Spins    Yields
    gc_alloc_block_sync          0         0
    whitehole_gc                 0         0
    gen[0].sync                  0         0
    gen[1].sync                  0         0
    
    Test Plan: ./validate
    
    Reviewers: bgamari, erikd, simonmar
    
    Subscribers: rwbarton, thomie, carter
    
    GHC Trac Issues: #3553, #9221
    
    Differential Revision: https://phabricator.haskell.org/D4301


>---------------------------------------------------------------

7e4b859edfd1abf742d5742436a13b9dba4b3270
 includes/rts/SpinLock.h |  5 ++++-
 rts/Stats.c             | 28 ++++++++++++++++++++++++----
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/includes/rts/SpinLock.h b/includes/rts/SpinLock.h
index 6530a3a..1dca02f 100644
--- a/includes/rts/SpinLock.h
+++ b/includes/rts/SpinLock.h
@@ -27,7 +27,8 @@
 typedef struct SpinLock_
 {
     StgWord   lock;
-    StgWord64 spin; // DEBUG version counts how much it spins
+    StgWord64 spin;  // incremented every time we spin in ACQUIRE_SPIN_LOCK
+    StgWord64 yield; // incremented every time we yield in ACQUIRE_SPIN_LOCK
 } SpinLock;
 #else
 typedef StgWord SpinLock;
@@ -49,6 +50,7 @@ INLINE_HEADER void ACQUIRE_SPIN_LOCK(SpinLock * p)
             p->spin++;
             busy_wait_nop();
         }
+        p->yield++;
         yieldThread();
     } while (1);
 }
@@ -66,6 +68,7 @@ INLINE_HEADER void initSpinLock(SpinLock * p)
     write_barrier();
     p->lock = 1;
     p->spin = 0;
+    p->yield = 0;
 }
 
 #else
diff --git a/rts/Stats.c b/rts/Stats.c
index 26bdac0..07cad3f 100644
--- a/rts/Stats.c
+++ b/rts/Stats.c
@@ -767,13 +767,33 @@ stat_exit (void)
 #if defined(THREADED_RTS) && defined(PROF_SPIN)
             {
                 uint32_t g;
+                const int32_t col_width[] = {-20, 10, 10};
+                statsPrintf("%*s" "%*s" "%*s" "\n"
+                            , col_width[0], ""
+                            , col_width[1], "Spins"
+                            , col_width[2], "Yields");
+                statsPrintf("%*s" "%*" FMT_Word64 "%*" FMT_Word64 "\n"
+                            , col_width[0], "gc_alloc_block_sync"
+                            , col_width[1], gc_alloc_block_sync.spin
+                            , col_width[2], gc_alloc_block_sync.yield);
+                statsPrintf("%*s" "%*" FMT_Word64 "%*" FMT_Word64 "\n"
+                            , col_width[0], "whitehole_gc"
+                            , col_width[1], whitehole_gc_spin
+                            , col_width[2], (StgWord64)0);
 
-                statsPrintf("gc_alloc_block_sync: %"FMT_Word64"\n", gc_alloc_block_sync.spin);
-                statsPrintf("whitehole_gc_spin: %"FMT_Word64"\n"
-                            , whitehole_gc_spin);
                 for (g = 0; g < RtsFlags.GcFlags.generations; g++) {
-                    statsPrintf("gen[%d].sync: %"FMT_Word64"\n", g, generations[g].sync.spin);
+                    int prefix_length = 0;
+                    statsPrintf("gen[%" FMT_Word32 "%n", g, &prefix_length);
+                    int suffix_length = col_width[0] + prefix_length;
+                    suffix_length =
+                      suffix_length > 0 ? col_width[0] : suffix_length;
+
+                    statsPrintf("%*s" "%*" FMT_Word64 "%*" FMT_Word64 "\n"
+                                , suffix_length, "].sync"
+                                , col_width[1], generations[g].sync.spin
+                                , col_width[2], generations[g].sync.yield);
                 }
+
             }
 #endif
         }



More information about the ghc-commits mailing list