|
From: <sv...@va...> - 2010-09-08 08:30:40
|
Author: sewardj
Date: 2010-09-08 09:30:31 +0100 (Wed, 08 Sep 2010)
New Revision: 11343
Log:
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.
Modified:
trunk/coregrind/m_aspacemgr/aspacemgr-common.c
trunk/coregrind/m_scheduler/scheduler.c
trunk/coregrind/pub_core_aspacemgr.h
Modified: trunk/coregrind/m_aspacemgr/aspacemgr-common.c
===================================================================
--- trunk/coregrind/m_aspacemgr/aspacemgr-common.c 2010-09-07 16:32:53 UTC (rev 11342)
+++ trunk/coregrind/m_aspacemgr/aspacemgr-common.c 2010-09-08 08:30:31 UTC (rev 11343)
@@ -432,15 +432,18 @@
/* 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);
}
Modified: trunk/coregrind/m_scheduler/scheduler.c
===================================================================
--- trunk/coregrind/m_scheduler/scheduler.c 2010-09-07 16:32:53 UTC (rev 11342)
+++ trunk/coregrind/m_scheduler/scheduler.c 2010-09-08 08:30:31 UTC (rev 11343)
@@ -1753,9 +1753,11 @@
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",
Modified: trunk/coregrind/pub_core_aspacemgr.h
===================================================================
--- trunk/coregrind/pub_core_aspacemgr.h 2010-09-07 16:32:53 UTC (rev 11342)
+++ trunk/coregrind/pub_core_aspacemgr.h 2010-09-08 08:30:31 UTC (rev 11343)
@@ -396,11 +396,11 @@
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. */
+/* 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 );
-extern Int VG_(am_get_VgStack_unused_szB)( VgStack* stack );
-
// DDD: this is ugly
#if defined(VGO_darwin)
typedef
|