summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsewardj <sewardj@a5019735-40e9-0310-863c-91ae7b9d1cf9>2010-09-08 08:30:31 +0000
committersewardj <sewardj@a5019735-40e9-0310-863c-91ae7b9d1cf9>2010-09-08 08:30:31 +0000
commit46dbd3f0192e6ffda8df706c62aca901902c5922 (patch)
tree3fd1d0ab5f86d8fe2ded325ce7dce355d19db826
parente05b3a455d461d0933b524535ab5c5c8185d9f9a (diff)
Don't scan the entire Valgrind stack to check for impending
stack-overflow situations. This causes an immense number of L2 misses which are completely pointless, and the recent increase of the Valgrind per-thread stack size from 64k to 1M greatly aggravates the situation. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11343 a5019735-40e9-0310-863c-91ae7b9d1cf9
-rw-r--r--coregrind/m_aspacemgr/aspacemgr-common.c9
-rw-r--r--coregrind/m_scheduler/scheduler.c6
-rw-r--r--coregrind/pub_core_aspacemgr.h8
3 files changed, 14 insertions, 9 deletions
diff --git a/coregrind/m_aspacemgr/aspacemgr-common.c b/coregrind/m_aspacemgr/aspacemgr-common.c
index a1dbda9e..b7a51d6e 100644
--- a/coregrind/m_aspacemgr/aspacemgr-common.c
+++ b/coregrind/m_aspacemgr/aspacemgr-common.c
@@ -432,15 +432,18 @@ VgStack* VG_(am_alloc_VgStack)( /*OUT*/Addr* initial_sp )
/* Figure out how many bytes of the stack's active area have not
been used. Used for estimating if we are close to overflowing it. */
-Int VG_(am_get_VgStack_unused_szB)( VgStack* stack )
+SizeT VG_(am_get_VgStack_unused_szB)( VgStack* stack, SizeT limit )
{
- Int i;
+ SizeT i;
UInt* p;
p = (UInt*)&stack->bytes[VG_STACK_GUARD_SZB];
- for (i = 0; i < VG_STACK_ACTIVE_SZB/sizeof(UInt); i++)
+ for (i = 0; i < VG_STACK_ACTIVE_SZB/sizeof(UInt); i++) {
if (p[i] != 0xDEADBEEF)
break;
+ if (i * sizeof(UInt) >= limit)
+ break;
+ }
return i * sizeof(UInt);
}
diff --git a/coregrind/m_scheduler/scheduler.c b/coregrind/m_scheduler/scheduler.c
index 97234031..f8f29507 100644
--- a/coregrind/m_scheduler/scheduler.c
+++ b/coregrind/m_scheduler/scheduler.c
@@ -1753,9 +1753,11 @@ void VG_(sanity_check_general) ( Bool force_expensive )
stack
= (VgStack*)
VG_(get_ThreadState)(tid)->os_state.valgrind_stack_base;
+ SizeT limit
+ = 4096; // Let's say. Checking more causes lots of L2 misses.
remains
- = VG_(am_get_VgStack_unused_szB)(stack);
- if (remains < VKI_PAGE_SIZE)
+ = VG_(am_get_VgStack_unused_szB)(stack, limit);
+ if (remains < limit)
VG_(message)(Vg_DebugMsg,
"WARNING: Thread %d is within %ld bytes "
"of running out of stack!\n",
diff --git a/coregrind/pub_core_aspacemgr.h b/coregrind/pub_core_aspacemgr.h
index 2e623293..484303e8 100644
--- a/coregrind/pub_core_aspacemgr.h
+++ b/coregrind/pub_core_aspacemgr.h
@@ -396,10 +396,10 @@ typedef
extern VgStack* VG_(am_alloc_VgStack)( /*OUT*/Addr* initial_sp );
-/* Figure out how many bytes of the stack's active area have not
- been used. Used for estimating if we are close to overflowing it. */
-
-extern Int VG_(am_get_VgStack_unused_szB)( VgStack* stack );
+/* Figure out how many bytes of the stack's active area have not been
+ used. Used for estimating if we are close to overflowing it. If
+ the free area is larger than 'limit', just return 'limit'. */
+extern SizeT VG_(am_get_VgStack_unused_szB)( VgStack* stack, SizeT limit );
// DDD: this is ugly
#if defined(VGO_darwin)