[MLton] getrusage and times?

Wesley W. Terpstra wesley@terpstra.ca
Thu, 14 Jul 2005 17:46:20 +0200


MLton seems to really like calling:

getrusage(RUSAGE_SELF, {ru_utime={0, 1999}, ru_stime={0, 3999}, ...}) = 0
times({tms_utime=0, tms_stime=0, tms_cutime=0, tms_cstime=0}) = 432034594
getrusage(RUSAGE_SELF, {ru_utime={0, 1999}, ru_stime={0, 3999}, ...}) = 0
times({tms_utime=0, tms_stime=0, tms_cutime=0, tms_cstime=0}) = 432034594
getrusage(RUSAGE_SELF, {ru_utime={0, 1999}, ru_stime={0, 3999}, ...}) = 0
times({tms_utime=0, tms_stime=0, tms_cutime=0, tms_cstime=0}) = 432034594
getrusage(RUSAGE_SELF, {ru_utime={0, 1999}, ru_stime={0, 3999}, ...}) = 0
times({tms_utime=0, tms_stime=0, tms_cutime=0, tms_cstime=0}) = 432034594

I was stracing a test server program using my version of MLton state 
threads and was seeing that all over the place. One thing I noticed, 
the "nasty_hack" really is nasty, since it seems everytime an _export'd
method gets called, yet another pair of times() and getrusage() are run.

However, even after moving 'identity' into a .c file for the time being,
this still happens fairly often:

epoll_wait(3, {{EPOLLIN, {u32=4, u64=4}}}, 1000, -1) = 1
gettimeofday({1121353504, 431760}, NULL) = 0
fcntl64(4, F_GETFL)                     = 0x2 (flags O_RDWR)
fcntl64(4, F_SETFL, O_RDWR|O_NONBLOCK)  = 0
accept(4, {sa_family=AF_INET, sin_port=htons(1635), sin_addr=inet_addr("127.0.0.1")}, [16]) = 5
fcntl64(4, F_SETFL, O_RDWR)             = 0
epoll_ctl(3, EPOLL_CTL_ADD, 5, {EPOLLIN|EPOLLOUT|EPOLLERR|EPOLLHUP|EPOLLET, {u32=5, u64=5}}) = 0
fcntl64(4, F_GETFL)                     = 0x2 (flags O_RDWR)
fcntl64(4, F_SETFL, O_RDWR|O_NONBLOCK)  = 0
accept(4, 0xb7e4e5ac, [110])            = -1 EAGAIN (Resource temporarily unavailable)
fcntl64(4, F_SETFL, O_RDWR)             = 0
getrusage(RUSAGE_SELF, {ru_utime={0, 1999}, ru_stime={0, 3999}, ...}) = 0
times({tms_utime=0, tms_stime=0, tms_cutime=0, tms_cstime=0}) = 432034594
getrusage(RUSAGE_SELF, {ru_utime={0, 1999}, ru_stime={0, 3999}, ...}) = 0
times({tms_utime=0, tms_stime=0, tms_cutime=0, tms_cstime=0}) = 432034594
getrusage(RUSAGE_SELF, {ru_utime={0, 1999}, ru_stime={0, 3999}, ...}) = 0
times({tms_utime=0, tms_stime=0, tms_cutime=0, tms_cstime=0}) = 432034594
getrusage(RUSAGE_SELF, {ru_utime={0, 1999}, ru_stime={0, 3999}, ...}) = 0
times({tms_utime=0, tms_stime=0, tms_cutime=0, tms_cstime=0}) = 432034594
send(5, "hello and welcome!\n", 19, MSG_DONTWAIT) = 19
epoll_wait(3, {{EPOLLOUT, {u32=5, u64=5}}}, 1000, -1) = 1

Since I am trying to scale this simulator as far as possible, eliminating
unnecessary switches to kernel land is quite important. Every system call
in there is as it should be, except for the 'fcntl64's and getrusage/times.

The fcntl64s around accept are understandable and seem acceptable since it
only does it for accept and not recv/send. (MSG_DONTWAIT <-- good call)

What I don't like are the getrusage/times. What are they needed for?
Besides that, why does it need to be checked 4 times in a row?
Finally, where the hell is it being called from?! :-)

I tried tracing this upwards from fixedGetrusage, but the only places I can
find it used are on the profiling path in gc.c and in MLton.Rusage which
doesn't seem to be referenced anywhere in the basis except the timers.
I can't even find how _export calls them. gdb was no help.

-- 
Wesley W. Terpstra