RE: Re: Keeping track of the CPU time for a thread

Mohammad A Haque <[email protected]>
Newsgroups gmane.comp.micro-kernel.l4.devel
Message-ID <B0ACF77358361C4C88655820705FC092449FEDF8@SN2PRD0106MB179.prod.exchangelabs.com>
Thank you for your reply.

Just to test the functionality, I tried a very simple thread. It computes a factorial for some number of iterations.

void entry_point(void * param) {
    int num_run = 1000000;
    int number = 15;
    int fact;

    thread_t self = env()->self();
    for(int i=0;i<num_run;i++) {
      fact = 1;
      for(int j = 2; j<= number; j++) {
        fact = fact * j;
      }
    }
    printf("Factorial of %d is : %d\n", number, fact);
    l4_thread_stats_time(self.cap());
    printf("Consumed time: %llu\n",l4_utcb_mr()->mr[0]);
  }

What I found is - the consumed time does not depend on the number of iterations (num_run) - I tried from 1 to a very large number. It does vary with the number. Am I missing something?

Thanks again.


----------------------------------------------------------------------
Date: Sun, 24 Jun 2012 23:29:25 +0200
From: Adam Lackorzynski <[email protected]>
To: [email protected]
Subject: Re: Keeping track of the CPU time for a thread
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-1

Hi,

On Thu Jun 21, 2012 at 17:44:25 +0000, Mohammad A Haque wrote:
> I want to measure how much CPU time a thread has consumed. When the
> CPU time consumption exceeds a certain limit (specific to that
> thread), I want to raise an interrupt. Please suggest me how can I do
> it efficiently?

The L4::Thread interface has the stats_time function to get the consumed
time of a thread (FINE_GRAINED_CPUTIME in the kernel might be of
interest here). Triggering an interrupt goes with its trigger function.
Then it's just about plugging this together.



Adam
--
Adam                 [email protected]
  Lackorzynski         http://os.inf.tu-dresden.de/~adam/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.