From: Philippe Waroquiers Date: Thu, 21 Aug 2014 20:01:50 +0000 (+0000) Subject: Follow up to r14313: disable stack cache earlier X-Git-Tag: svn/VALGRIND_3_10_0~156 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5f580688562dd202c5bea97797144d6fea11d66a;p=thirdparty%2Fvalgrind.git Follow up to r14313: disable stack cache earlier glibc is recycling memory for detached threads before a thread termination => disable the stack cache earlier (i.e. once a 'non main thread' is seen) git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14329 --- diff --git a/coregrind/m_scheduler/scheduler.c b/coregrind/m_scheduler/scheduler.c index 3a85e524e1..3c2bdcf3ee 100644 --- a/coregrind/m_scheduler/scheduler.c +++ b/coregrind/m_scheduler/scheduler.c @@ -1211,6 +1211,30 @@ VgSchedReturnCode VG_(scheduler) ( ThreadId tid ) } } + if (SimHintiS(SimHint_no_nptl_pthread_stackcache, VG_(clo_sim_hints)) + && tid != 1) { + /* We disable the stack cache the first time we see a thread other + than the main thread appearing. At this moment, we are sure the pthread + lib loading is done/variable was initialised by pthread lib/... */ + if (VG_(client__stack_cache_actsize__addr)) { + if (*VG_(client__stack_cache_actsize__addr) == 0) { + VG_(debugLog)(1,"sched", + "pthread stack cache size disable done" + " via kludge\n"); + *VG_(client__stack_cache_actsize__addr) = 1000 * 1000 * 1000; + /* Set a value big enough to be above the hardcoded maximum stack + cache size in glibc, small enough to allow a pthread stack size + to be added without risk of overflow. */ + } + } else { + VG_(debugLog)(0,"sched", + "WARNING: pthread stack cache cannot be disabled!\n"); + VG_(clo_sim_hints) &= !SimHint2S(SimHint_no_nptl_pthread_stackcache); + /* Remove SimHint_no_nptl_pthread_stackcache from VG_(clo_sim_hints) + to avoid having a msg for all following threads. */ + } + } + /* set the proper running signal mask */ block_signals(); @@ -1580,30 +1604,6 @@ VgSchedReturnCode VG_(scheduler) ( ThreadId tid ) if (VG_(clo_trace_sched)) print_sched_event(tid, "exiting VG_(scheduler)"); - if (SimHintiS(SimHint_no_nptl_pthread_stackcache, VG_(clo_sim_hints))) { - if (VG_(client__stack_cache_actsize__addr)) { - if (*VG_(client__stack_cache_actsize__addr) == 0) { - /* We disable the stack cache just before the first - thread exits. At this moment, we are sure the pthread lib - loading is done/variable was initialised by - pthread lib/... */ - VG_(debugLog)(1,"sched", - "pthread stack cache size disabling done" - " via kludge\n"); - *VG_(client__stack_cache_actsize__addr) = 1000 * 1000 * 1000; - /* Set a value big enough to be above the hardcoded maximum stack - cache size in glibc, small enough to allow a pthread stack size - to be added without risk of overflow. */ - } - } else { - VG_(debugLog)(0,"sched", - "WARNING: pthread stack cache cannot be disabled!\n"); - VG_(clo_sim_hints) &= !SimHint2S(SimHint_no_nptl_pthread_stackcache); - /* Remove SimHint_no_nptl_pthread_stackcache from VG_(clo_sim_hints) - to avoid having a msg for at all thread terminations. */ - } - } - vg_assert(VG_(is_exiting)(tid)); return tst->exitreason;