Keeping track of the CPU time for a thread

Adam Lackorzynski adam at os.inf.tu-dresden.de
Wed Jun 27 23:18:46 CEST 2012


On Tue Jun 26, 2012 at 18:52:44 +0000, Mohammad A Haque wrote:
> 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?

Your examples works for me (in a slightly modified version):
  int num_run = 1000000;
  int number = 15;
  int fact;

  while (1) {
    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(l4re_env()->main_thread);
    printf("Consumed time: %llu\n", *(l4_cpu_time_t *)&l4_utcb_mr()->mr[0]);
  }

The consumed time increases as the program runs.
The granularity is 1ms, except you enable "fine-grained cpu time" in the Fiasco
kernel, then it is more exact.



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