]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Last optimisation for the day: change VG_(stats__n_xindirs) in such a
authorJulian Seward <jseward@acm.org>
Sat, 21 Apr 2012 23:05:57 +0000 (23:05 +0000)
committerJulian Seward <jseward@acm.org>
Sat, 21 Apr 2012 23:05:57 +0000 (23:05 +0000)
way that the fast-path through VG_(disp_cp_xindir) only has to
increment a 32 bit counter, saving memory bandwidth on 32 bit
platforms compared to a 64-bit inc.  The overall numbers of XIndirs
can still be 64 bit though.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12527

coregrind/m_dispatch/dispatch-amd64-linux.S
coregrind/m_dispatch/dispatch-x86-linux.S
coregrind/m_scheduler/scheduler.c

index 73daec523d256889d2b6b85a50d8cba1af0be6d2..2586d41d2bce6212f206431d3575a6510f90044c 100644 (file)
@@ -206,8 +206,8 @@ VG_(disp_cp_xindir):
        /* Where are we going? */
        movq    OFFSET_amd64_RIP(%rbp), %rax
 
-        /* RM ME -- stats only */
-        addq    $1, vgPlain_stats__n_xindirs
+        /* stats only */
+        addl    $1, VG_(stats__n_xindirs_32)
         
        /* try a fast lookup in the translation cache */
        movabsq $VG_(tt_fast), %rcx
@@ -224,8 +224,8 @@ VG_(disp_cp_xindir):
        ud2     /* persuade insn decoders not to speculate past here */
 
 fast_lookup_failed:
-        /* RM ME -- stats only */
-        addq    $1, vgPlain_stats__n_xindir_misses
+        /* stats only */
+        addl    $1, VG_(stats__n_xindir_misses_32)
 
        movq    $VG_TRC_INNER_FASTMISS, %rax
         movq    $0, %rdx
index f34d8bfca445409bb101e5845afff1ec78cefe66..bb2cb3cb418c91a24da6367ce6544b58f0e7656a 100644 (file)
@@ -199,9 +199,8 @@ VG_(disp_cp_xindir):
        /* Where are we going? */
        movl    OFFSET_x86_EIP(%ebp), %eax
 
-        /* RM ME -- stats only */
-        addl    $1, vgPlain_stats__n_xindirs
-        adcl    $0, vgPlain_stats__n_xindirs+4
+        /* stats only */
+        addl    $1, VG_(stats__n_xindirs_32)
         
         /* try a fast lookup in the translation cache */
         movl    %eax, %ebx                      /* next guest addr */
@@ -216,9 +215,8 @@ VG_(disp_cp_xindir):
        ud2     /* persuade insn decoders not to speculate past here */
 
 fast_lookup_failed:
-        /* RM ME -- stats only */
-        addl    $1, vgPlain_stats__n_xindir_misses
-        adcl    $0, vgPlain_stats__n_xindir_misses+4
+        /* stats only */
+        addl    $1, VG_(stats__n_xindir_misses_32)
 
        movl    $VG_TRC_INNER_FASTMISS, %eax
         movl    $0, %edx
index 66d4f83720a594dcee61a1de1b788af46bbbc1d0..20a20baefc50d9dd4f5d7e5a1ea6b83a9503d810 100644 (file)
@@ -128,8 +128,16 @@ static void mostly_clear_thread_record ( ThreadId tid );
 static ULong n_scheduling_events_MINOR = 0;
 static ULong n_scheduling_events_MAJOR = 0;
 
-ULong VG_(stats__n_xindirs) = 0;
-ULong VG_(stats__n_xindir_misses) = 0;
+/* Stats: number of XIndirs, and number that missed in the fast
+   cache. */
+static ULong stats__n_xindirs = 0;
+static ULong stats__n_xindir_misses = 0;
+
+/* And 32-bit temp bins for the above, so that 32-bit platforms don't
+   have to do 64 bit incs on the hot path through
+   VG_(cp_disp_xindir). */
+/*global*/ UInt VG_(stats__n_xindirs_32) = 0;
+/*global*/ UInt VG_(stats__n_xindir_misses_32) = 0;
 
 /* Sanity checking counts. */
 static UInt sanity_fast_count = 0;
@@ -141,9 +149,9 @@ void VG_(print_scheduler_stats)(void)
       "scheduler: %'llu event checks.\n", bbs_done );
    VG_(message)(Vg_DebugMsg,
                 "scheduler: %'llu indir transfers, %'llu misses (1 in %llu)\n",
-                VG_(stats__n_xindirs), VG_(stats__n_xindir_misses),
-                VG_(stats__n_xindirs) / (VG_(stats__n_xindir_misses) 
-                                         ? VG_(stats__n_xindir_misses) : 1));
+                stats__n_xindirs, stats__n_xindir_misses,
+                stats__n_xindirs / (stats__n_xindir_misses 
+                                    ? stats__n_xindir_misses : 1));
    VG_(message)(Vg_DebugMsg,
       "scheduler: %'llu/%'llu major/minor sched events.\n",
       n_scheduling_events_MAJOR, n_scheduling_events_MINOR);
@@ -816,6 +824,10 @@ void run_thread_for_a_while ( /*OUT*/HWord* two_words,
    do_pre_run_checks( (ThreadState*)tst );
    /* end Paranoia */
 
+   /* Futz with the XIndir stats counters. */
+   vg_assert(VG_(stats__n_xindirs_32) == 0);
+   vg_assert(VG_(stats__n_xindir_misses_32) == 0);
+
    /* Clear return area. */
    two_words[0] = two_words[1] = 0;
 
@@ -852,7 +864,6 @@ void run_thread_for_a_while ( /*OUT*/HWord* two_words,
    /* We have either a no-redir or a redir translation. */
    vg_assert(host_code_addr != 0); /* implausible */
 
-
    /* there should be no undealt-with signals */
    //vg_assert(VG_(threads)[tid].siginfo.si_signo == 0);
 
@@ -902,6 +913,15 @@ void run_thread_for_a_while ( /*OUT*/HWord* two_words,
       block_signals();
    } 
 
+   /* Merge the 32-bit XIndir/miss counters into the 64 bit versions,
+      and zero out the 32-bit ones in preparation for the next run of
+      generated code. */
+   stats__n_xindirs += (ULong)VG_(stats__n_xindirs_32);
+   VG_(stats__n_xindirs_32) = 0;
+   stats__n_xindir_misses += (ULong)VG_(stats__n_xindir_misses_32);
+   VG_(stats__n_xindir_misses_32) = 0;
+
+   /* Inspect the event counter. */
    vg_assert((Int)tst->arch.vex.host_EvC_COUNTER >= -1);
    vg_assert(tst->arch.vex.host_EvC_FAILADDR
              == (HWord)VG_(fnptr_to_fnentry)( &VG_(disp_cp_evcheck_fail)) );