From: Nicholas Nethercote Date: Sun, 19 Jun 2005 18:49:19 +0000 (+0000) Subject: Move VG_(sanity_check_general) out of m_main.c into scheduler.c. X-Git-Tag: svn/VALGRIND_3_0_0~363 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e2605727845d4d8e062eaacc1fd16ef9b91f8170;p=thirdparty%2Fvalgrind.git Move VG_(sanity_check_general) out of m_main.c into scheduler.c. Removes the dependence of m_scheduler/ on m_main.c; reduces the dependence of m_signals.c on m_main.c. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3955 --- diff --git a/coregrind/m_main.c b/coregrind/m_main.c index 78b829f04a..bb43b62ff4 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -129,22 +129,10 @@ static Char **vg_argv; /*=== Counters, for profiling purposes only ===*/ /*====================================================================*/ -/* Counts pertaining to internal sanity checking. */ -static UInt sanity_fast_count = 0; -static UInt sanity_slow_count = 0; - static void print_all_stats ( void ) { - // Translation stats VG_(print_tt_tc_stats)(); - - // Scheduler stats VG_(print_scheduler_stats)(); - - VG_(message)(Vg_DebugMsg, - " sanity: %d cheap, %d expensive checks.", - sanity_fast_count, sanity_slow_count ); - VG_(print_ExeContext_stats)(); // Memory stats @@ -155,7 +143,6 @@ static void print_all_stats ( void ) VG_(sanity_check_malloc_all)(); VG_(print_all_arena_stats)(); VG_(message)(Vg_DebugMsg, ""); - //VG_(print_shadow_stats)(); } } @@ -2309,96 +2296,6 @@ static void init_thread1state ( Addr client_ip, } -/*====================================================================*/ -/*=== Sanity check machinery (permanently engaged) ===*/ -/*====================================================================*/ - -/* A fast sanity check -- suitable for calling circa once per - millisecond. */ - -void VG_(sanity_check_general) ( Bool force_expensive ) -{ - ThreadId tid; - - VGP_PUSHCC(VgpCoreCheapSanity); - - if (VG_(clo_sanity_level) < 1) return; - - /* --- First do all the tests that we can do quickly. ---*/ - - sanity_fast_count++; - - /* Check stuff pertaining to the memory check system. */ - - /* Check that nobody has spuriously claimed that the first or - last 16 pages of memory have become accessible [...] */ - if (VG_(needs).sanity_checks) { - VGP_PUSHCC(VgpToolCheapSanity); - vg_assert(VG_TDICT_CALL(tool_cheap_sanity_check)); - VGP_POPCC(VgpToolCheapSanity); - } - - /* --- Now some more expensive checks. ---*/ - - /* Once every 25 times, check some more expensive stuff. */ - if ( force_expensive - || VG_(clo_sanity_level) > 1 - || (VG_(clo_sanity_level) == 1 && (sanity_fast_count % 25) == 0)) { - - VGP_PUSHCC(VgpCoreExpensiveSanity); - sanity_slow_count++; - -# if 0 - { void zzzmemscan(void); zzzmemscan(); } -# endif - - if ((sanity_fast_count % 250) == 0) - VG_(sanity_check_tt_tc)("VG_(sanity_check_general)"); - - if (VG_(needs).sanity_checks) { - VGP_PUSHCC(VgpToolExpensiveSanity); - vg_assert(VG_TDICT_CALL(tool_expensive_sanity_check)); - VGP_POPCC(VgpToolExpensiveSanity); - } - - /* Check that Segments and /proc/self/maps match up */ - //vg_assert(VG_(sanity_check_memory)()); - - /* Look for stack overruns. Visit all threads. */ - for(tid = 1; tid < VG_N_THREADS; tid++) { - SSizeT remains; - - if (VG_(threads)[tid].status == VgTs_Empty || - VG_(threads)[tid].status == VgTs_Zombie) - continue; - - remains = VGA_(stack_unused)(tid); - if (remains < VKI_PAGE_SIZE) - VG_(message)(Vg_DebugMsg, - "WARNING: Thread %d is within %d bytes " - "of running out of stack!", - tid, remains); - } - - /* - if ((sanity_fast_count % 500) == 0) VG_(mallocSanityCheckAll)(); - */ - VGP_POPCC(VgpCoreExpensiveSanity); - } - - if (VG_(clo_sanity_level) > 1) { - VGP_PUSHCC(VgpCoreExpensiveSanity); - /* Check sanity of the low-level memory manager. Note that bugs - in the client's code can cause this to fail, so we don't do - this check unless specially asked for. And because it's - potentially very expensive. */ - VG_(sanity_check_malloc_all)(); - VGP_POPCC(VgpCoreExpensiveSanity); - } - VGP_POPCC(VgpCoreCheapSanity); -} - - /*====================================================================*/ /*=== main() ===*/ /*====================================================================*/ diff --git a/coregrind/m_scheduler/scheduler.c b/coregrind/m_scheduler/scheduler.c index d6d2d42f3c..a5c6c2d62a 100644 --- a/coregrind/m_scheduler/scheduler.c +++ b/coregrind/m_scheduler/scheduler.c @@ -71,7 +71,6 @@ #include "pub_core_libcproc.h" #include "pub_core_libcsignal.h" #include "pub_core_machine.h" -#include "pub_core_main.h" #include "pub_core_mallocfree.h" #include "pub_core_options.h" #include "pub_core_profile.h" @@ -116,6 +115,9 @@ static void mostly_clear_thread_record ( ThreadId tid ); static UInt n_scheduling_events_MINOR = 0; static UInt n_scheduling_events_MAJOR = 0; +/* Sanity checking counts. */ +static UInt sanity_fast_count = 0; +static UInt sanity_slow_count = 0; void VG_(print_scheduler_stats)(void) { @@ -124,6 +126,9 @@ void VG_(print_scheduler_stats)(void) VG_(message)(Vg_DebugMsg, "scheduler: %d/%d major/minor sched events.", n_scheduling_events_MAJOR, n_scheduling_events_MINOR); + VG_(message)(Vg_DebugMsg, + " sanity: %d cheap, %d expensive checks.", + sanity_fast_count, sanity_slow_count ); } /* CPU semaphore, so that threads can run exclusively */ @@ -1031,7 +1036,7 @@ void do_client_request ( ThreadId tid ) /* --------------------------------------------------------------------- - Sanity checking. + Sanity checking (permanently engaged) ------------------------------------------------------------------ */ /* Internal consistency checks on the sched structures. */ @@ -1055,6 +1060,87 @@ void scheduler_sanity ( ThreadId tid ) } } +void VG_(sanity_check_general) ( Bool force_expensive ) +{ + ThreadId tid; + + VGP_PUSHCC(VgpCoreCheapSanity); + + if (VG_(clo_sanity_level) < 1) return; + + /* --- First do all the tests that we can do quickly. ---*/ + + sanity_fast_count++; + + /* Check stuff pertaining to the memory check system. */ + + /* Check that nobody has spuriously claimed that the first or + last 16 pages of memory have become accessible [...] */ + if (VG_(needs).sanity_checks) { + VGP_PUSHCC(VgpToolCheapSanity); + vg_assert(VG_TDICT_CALL(tool_cheap_sanity_check)); + VGP_POPCC(VgpToolCheapSanity); + } + + /* --- Now some more expensive checks. ---*/ + + /* Once every 25 times, check some more expensive stuff. */ + if ( force_expensive + || VG_(clo_sanity_level) > 1 + || (VG_(clo_sanity_level) == 1 && (sanity_fast_count % 25) == 0)) { + + VGP_PUSHCC(VgpCoreExpensiveSanity); + sanity_slow_count++; + +# if 0 + { void zzzmemscan(void); zzzmemscan(); } +# endif + + if ((sanity_fast_count % 250) == 0) + VG_(sanity_check_tt_tc)("VG_(sanity_check_general)"); + + if (VG_(needs).sanity_checks) { + VGP_PUSHCC(VgpToolExpensiveSanity); + vg_assert(VG_TDICT_CALL(tool_expensive_sanity_check)); + VGP_POPCC(VgpToolExpensiveSanity); + } + + /* Check that Segments and /proc/self/maps match up */ + //vg_assert(VG_(sanity_check_memory)()); + + /* Look for stack overruns. Visit all threads. */ + for(tid = 1; tid < VG_N_THREADS; tid++) { + SSizeT remains; + + if (VG_(threads)[tid].status == VgTs_Empty || + VG_(threads)[tid].status == VgTs_Zombie) + continue; + + remains = VGA_(stack_unused)(tid); + if (remains < VKI_PAGE_SIZE) + VG_(message)(Vg_DebugMsg, + "WARNING: Thread %d is within %d bytes " + "of running out of stack!", + tid, remains); + } + + /* + if ((sanity_fast_count % 500) == 0) VG_(mallocSanityCheckAll)(); + */ + VGP_POPCC(VgpCoreExpensiveSanity); + } + + if (VG_(clo_sanity_level) > 1) { + VGP_PUSHCC(VgpCoreExpensiveSanity); + /* Check sanity of the low-level memory manager. Note that bugs + in the client's code can cause this to fail, so we don't do + this check unless specially asked for. And because it's + potentially very expensive. */ + VG_(sanity_check_malloc_all)(); + VGP_POPCC(VgpCoreExpensiveSanity); + } + VGP_POPCC(VgpCoreCheapSanity); +} /*--------------------------------------------------------------------*/ /*--- end ---*/ diff --git a/coregrind/pub_core_aspacemgr.h b/coregrind/pub_core_aspacemgr.h index 4c39c29857..f2c221686c 100644 --- a/coregrind/pub_core_aspacemgr.h +++ b/coregrind/pub_core_aspacemgr.h @@ -149,8 +149,6 @@ extern const HChar *VG_(prot_str)(UInt prot); extern Addr VG_(get_memory_from_mmap_for_client) (Addr base, SizeT len, UInt prot, UInt flags); -//extern void VG_(print_shadow_stats)(); - /* Parses /proc/self/maps, calling `record_mapping' for each entry. */ extern void VG_(parse_procselfmaps) ( diff --git a/coregrind/pub_core_main.h b/coregrind/pub_core_main.h index 541650d234..0e1f59b424 100644 --- a/coregrind/pub_core_main.h +++ b/coregrind/pub_core_main.h @@ -38,9 +38,6 @@ // things. //-------------------------------------------------------------------- -/* Sanity checks which may be done at any time. The scheduler decides when. */ -extern void VG_(sanity_check_general) ( Bool force_expensive ); - /* client executable file descriptor */ extern Int VG_(clexecfd); diff --git a/coregrind/pub_core_scheduler.h b/coregrind/pub_core_scheduler.h index 79403572dd..e48849217b 100644 --- a/coregrind/pub_core_scheduler.h +++ b/coregrind/pub_core_scheduler.h @@ -86,6 +86,9 @@ extern void VG_(resume_scheduler) ( ThreadId tid ); /* If true, a fault is Valgrind-internal (ie, a bug) */ extern Bool VG_(my_fault); +/* Sanity checks which may be done at any time. The scheduler decides when. */ +extern void VG_(sanity_check_general) ( Bool force_expensive ); + #endif // __PUB_CORE_SCHEDULER_H /*--------------------------------------------------------------------*/