From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23983 invoked by alias); 6 Mar 2013 22:26:58 -0000 Received: (qmail 23970 invoked by uid 22791); 6 Mar 2013 22:26:57 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=AWL,BAYES_00,KHOP_THREADED X-Spam-Check-By: sourceware.org Received: from tetra.codeconfidence.com (HELO tetra.codeconfidence.com) (94.229.66.225) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 06 Mar 2013 22:26:50 +0000 Received: from cog.dallaway.org.uk (cpc1-cmbg10-0-0-cust34.5-4.cable.virginmedia.com [81.102.132.35]) by tetra.codeconfidence.com (Postfix) with ESMTP id 61885234C027; Wed, 6 Mar 2013 22:26:47 +0000 (GMT) Received: from cog.dallaway.org.uk (cog.dallaway.org.uk [127.0.0.1]) by cog.dallaway.org.uk (8.13.8/8.13.8) with ESMTP id r26MQkWA004259; Wed, 6 Mar 2013 22:26:46 GMT Message-ID: <5137C2A6.7090800@dallaway.org.uk> Date: Wed, 06 Mar 2013 22:26:00 -0000 From: John Dallaway User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.11) Gecko/20121120 Thunderbird/10.0.11 MIME-Version: 1.0 To: Greg Dyer CC: eCos Discussion References: <8A9A59002BD6CE4CBC872499112816E9011DACF5@msvr4.axys.tri.lan> In-Reply-To: <8A9A59002BD6CE4CBC872499112816E9011DACF5@msvr4.axys.tri.lan> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Subject: [ECOS] Re: Monitoring stack usage X-SW-Source: 2013-03/txt/msg00007.txt.bz2 Hi Greg On 06/03/13 16:29, Greg Dyer wrote: > I am running an embedded environment using multiple threads in eCos, a > main thread and a logging thread. I've been testing stack usages vs > different stack sizes in the logging thread because I had suspected that > a stack overflow could be occurring in the logging thread causing it to > lock up. I enabled CYGFUN_KERNEL_THREADS_STACK_MEASUREMENT and started > printing the values from cyg_thread_measure_stack_usage as well as the > value from threadInfo.stack_used. [ snip ] > Is there a reason that my stack usage could be growing so high in my > second test? The compiled code is identical, only some a few parameters > are changed in my running code. I was expecting to see my stack usage > possibly go above the 4k mark but not continue to grow with my stack > size. Is there a better way I can monitor stack usage to detect an > overflow so I can appropriately set a better stack size? Of course, you are correct. Stack usage should not grow with stack size. To help interpret what you are observing, it is important to understand how stack usage measurement is implemented in eCos. Enabling CYGFUN_KERNEL_THREADS_STACK_MEASUREMENT will cause a bit pattern to be written across the entire stack during thread initialisation. This bit pattern is then overwritten progressively as more of the stack is used. Calls to cyg_thread_measure_stack_usage() will calculate the usage by searching for the lowest address on the stack that no-longer contains the bit pattern. If bad code is causing even a single byte to be written to an unused part of the stack then cyg_thread_measure_stack_usage() will find that byte and report unexpectedly large stack usage. By the way, do make sure that CYGPKG_INFRA_DEBUG and CYGDBG_USE_ASSERTS are enabled while you track down this issue. Enabling these items will also enable stack overflow checking (CYGFUN_KERNEL_THREADS_STACK_CHECKING). I hope this helps... John Dallaway eCos maintainer http://www.dallaway.org.uk/john -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss