]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Move VG_(sanity_check_general) out of m_main.c into scheduler.c.
authorNicholas Nethercote <njn@valgrind.org>
Sun, 19 Jun 2005 18:49:19 +0000 (18:49 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Sun, 19 Jun 2005 18:49:19 +0000 (18:49 +0000)
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

coregrind/m_main.c
coregrind/m_scheduler/scheduler.c
coregrind/pub_core_aspacemgr.h
coregrind/pub_core_main.h
coregrind/pub_core_scheduler.h

index 78b829f04a133ac4ae39075f4bd5e01b5b931dcb..bb43b62ff44cea9fa717b599df65c8ed5124c68c 100644 (file)
@@ -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()                                                       ===*/
 /*====================================================================*/
index d6d2d42f3c42c1d996969a4c3032ea2a9ebe47d7..a5c6c2d62a49e70b3f8dc177b3f52d130cff5c65 100644 (file)
@@ -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                                                          ---*/
index 4c39c29857efd1c18c3898cea7b9d963c0a19929..f2c221686c6d17f6e8df12aaad841442fc0f4cd9 100644 (file)
@@ -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) (
index 541650d234340be01b85ca99754741d3a2e4e2da..0e1f59b4243e40a69bf5f5e1bcb48e4c4a9883b9 100644 (file)
@@ -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);
 
index 79403572dda44548c64e85987aadd5d96f5e4d15..e48849217b610a674b05224d48ddecc4691f17f4 100644 (file)
@@ -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
 
 /*--------------------------------------------------------------------*/