This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: CPU usage by threads


Yes, you just need one interrupt to do this.  This is OUTSIDE of any thread 
context.

When the interrupt fires, call CygThread::self () to determine which thread 
was running when the interrupt fired.  You'll need an array of structures 
that is something like this:

struct ThreadCounts
{
  CygThread *pThreadId; //Thisis what CygThread::self() will return
  u32 u32Count;
};

to keep track of the counts of each thread.

This is statistical sampling.  You're assuming that the more often you see a 
particular thread when the interrupt occurs, the more often that particular 
thread runs.  This is true 99.9% of the time.

In a SIDE NOTE, which most likely will NOT affect you, you may have what's 
called the "Thundering Herd" problem.  This is when your interrupt that you 
use to sample which thread is running coincides with when a thread starts 
running.  I have never seen an embedded system that is affected by this much 
since in most embedded systems it's interrupts that drive the system.  This 
problem WILL happen in systems like Unix, Windows, and other systems that do 
a lot of scheduling based off the clock though.  Again - this is just a side 
note and I mention it so you can research it if you feel like it.

-Rich

On Tuesday 05 November 2002 04:02 pm, Daniel Lidsten wrote:
> Hi again,
>
> I dont get exactly how you mean in the below text. Do you mean that i
> shall create a periodic alarm inside each thread and let it write the
> thread ID into an array or something and then have some other thread
> reading it and presenting it?
>
> Or can i use just ONE interrupt that do all this? If so then i need to
> know that the interrupt is run within the disrupted threads' context and
> not some special interrupt thread.
>
> I would approtiate it very much it you could clearify this for me.
>
> Regards, Daniel
>
> > Anyhow, if you just want to do cpu usage by task, I'd
> > recommend making a
> > periodic interrupt and then calling CygThread::self () to
> > figure out which
> > thread was running at the time, and just keep counts per
> > thread and do
> > division.  This will impact your system VERY little.  Have a
> > low priority
> > thread periodically print the values and you can get a pretty
> > good idea of
> > where you spend most of your time.   For best results, you
> > want an interrupt
> > with a system tick that cannot be divided into the system
> > tick.  I've heard
> > that one of the best profilers uses a 97 Hz clock with a
> > system clock of 100
> > Hz (eCos' default and most Unix's too).
> >
> > Our tool profiles the code, so it's probably overkill.  It
> > tells you where you
> > spend most of your time, what task you were in and the call
> > stack as well.
> >
> > Later,
> > -Rich
> >
> > > Regards, Daniel
> > >
> > > > -----Original Message-----
> > > > From: NavEcos [mailto:ecos@navosha.com]
> > > > Sent: den 24 oktober 2002 23:11
> > > > To: Daniel Lidsten
> > > > Subject: Re: [ECOS] CPU usage by threads
> > > >
> > > > On Thursday 24 October 2002 04:29 am, you wrote:
> > > > > Hi,
> > > > >
> > > > > I just took a peek at your site regarding the profiling
> > > >
> > > > tool it looks
> > > >
> > > > > very intresting. Do you have it for windows platform? How
> > > >
> > > > much does it
> > > >
> > > > > cost? Do you have any more information about it - some manual?
> > > >
> > > > Well, we're just tooling up.  That individual tool (don't have a
> > > > heart attack) is like $5K, but that's for a site license, as many
> > > > developers as you want
> > > > can use it for your project.  We are a small company, we
> >
> > need $.  You
> >
> > > > wouldn't be able to develop such a tool as cheaply.
> > > >
> > > > We're also bringing up a memory profiler as well, that
> >
> > will help you
> >
> > > > eliminate memory leaks.
> > > >
> > > > We have two other tools under development as well but they are
> > > > several weeks away from completion to no real point in mentioning
> > > > them yet.
> > > >
> > > > -Rich
> > > >
> > > > > Regards, Daniel Lidsten
> > > > >
> > > > > > -----Original Message-----
> > > > > > From: NavEcos [mailto:ecos@navosha.com]
> > > > > > Sent: den 24 oktober 2002 10:35
> > > > > > To: Daniel Lidsten
> > > > > > Subject: Re: [ECOS] CPU usage by threads
> > > > > >
> > > > > > On Thursday 24 October 2002 12:11 am, Daniel Lidsten wrote:
> > > > > > > Hi,
> > > > > > >
> > > > > > > I would like to know how much CPU time each thread in the
> > > > > >
> > > > > > system make
> > > > > >
> > > > > > > use of but i currently don't see any easy way of doing
> > > > > >
> > > > > > this? Does it
> > > > > >
> > > > > > > exists any such feature? If not, maybe it is possible to
> > > > > >
> > > > > > add some hook
> > > > > >
> > > > > > > functions that gets called by the kernel each time it
> > > > > >
> > > > > > performs a task
> > > > > >
> > > > > > > switch. These functions can then perform some logging,
> > > >
> > > > or just do
> > > >
> > > > > > > nothing at all if they are not used.
> > > > > > >
> > > > > > > Regards, Daniel Lidsten
> > > > > >
> > > > > > We provide a tool that will do this:
> > > > >
> > > > > http://ecos.dynu.com/~ecos3/prof.html
> > > > >
> > > > > But it's commercial.
> > > > >
> > > > > -Rich


--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]