Keeping track of the CPU time for a thread
Mohammad A Haque
mhaque4 at masonlive.gmu.edu
Tue Jun 26 20:52:44 CEST 2012
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 <adam at os.inf.tu-dresden.de>
To: l4-hackers at os.inf.tu-dresden.de
Subject: Re: Keeping track of the CPU time for a thread
Message-ID: <20120624212925.GC1246 at os.inf.tu-dresden.de>
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 adam at os.inf.tu-dresden.de
Lackorzynski http://os.inf.tu-dresden.de/~adam/
More information about the l4-hackers
mailing list