[Prev][Next][Index][Thread]
Re: Clock implementation in oskit
> freebsd/3.x/src/lib/libc/gen/clock.c does provide code for clock but
> it needs getrusage which a similar thorough search suggests we don't
> have.
>
> If all you want to do is get your program linked, you could hack one
> up pretty quickly. Choices include a version that returns the same
> number all the time, a version which returns a number that increases
> by 1 each time.
Here is my 2 cents on a quick hack job to get something that is both
functional and remotely approximating the original purpose of clock().
I'm going by the man page for clock() under linux, which states it's an
_approximation_ of the number of seconds of CPU time the program has been
using.
If you are using pthreads, you could insert a line in the scheduler that
increments some state variable each thread has every time the scheduler
switches to a particular thread. Since the man page on clock says that
arbitary start values are possible, you don't have to do any
initialisation on this variable. Then, to get the number of seconds used
so far, divide by the frequency of pthread switching. Or something like
that.
If it isn't multithreaded, you should be able to register a function to
the timer interrupt routines to increment your own variable very so often
to keep track. Hopefully OSkit has a big BLOCKED variable or something so
you don't increment the count when your program is blocked on IO.
Hope this helps. And it's not the cleanest way to do it methinks.
"Do you live in the Australian Antarctic Territory and if so are
you sane?" ICQ 45031529 to ICQ 614819.
______________________________________________________________
| Voon-Li Chung | Star Trek Fan, PhD Student, Inline- |
| vlchung@cs.uwa.edu.au | Hockey Player. TheatreSports Player |
| Web Page: http://www.cs.uwa.edu.au/~vlchung |
--------------------------------------------------------------
References: