public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: John Dallaway <john@dallaway.org.uk>
To: Greg Dyer <gdyer@axys.com>
Cc: eCos Discussion <ecos-discuss@ecos.sourceware.org>
Subject: [ECOS] Re: Monitoring stack usage
Date: Wed, 06 Mar 2013 22:26:00 -0000	[thread overview]
Message-ID: <5137C2A6.7090800@dallaway.org.uk> (raw)
In-Reply-To: <8A9A59002BD6CE4CBC872499112816E9011DACF5@msvr4.axys.tri.lan>

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

      reply	other threads:[~2013-03-06 22:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-06 16:29 [ECOS] " Greg Dyer
2013-03-06 22:26 ` John Dallaway [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5137C2A6.7090800@dallaway.org.uk \
    --to=john@dallaway.org.uk \
    --cc=ecos-discuss@ecos.sourceware.org \
    --cc=gdyer@axys.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).