OpenBSD Journal

Timecounters available to userland in -current

Contributed by Janne Johansson on from the we're gonna party like its 199NaN dept.

In this commit, Paul Irofti (pirofti@) added support for reading timecounters in userland without making a syscall.

Up to now, this will have required a syscall every time in order to read out real values from a timecounter device on OpenBSD, but from now on, a special ELF segment will possibly hold a page where libc can read out a pointer to the current timecounter value, and hence read it without context switching, making it faster:

test1$ cat gtod.c
#include <sys/time.h>

int main() {
        struct timeval tp;
        int i;

        for(i = 0; i < 100000000; i++)
                gettimeofday(&tp, NULL);

        return 0;
test1$ make gtod
cc -O2 -pipe    -o gtod gtod.c 
test1$ R=3; for X in `jot ${R}`; do time ./gtod; done
    1m35.24s real     0m59.24s user     0m34.98s system
    1m32.00s real     0m54.17s user     0m31.26s system
    1m31.25s real     0m56.64s user     0m33.40s system
test1$ doas sysupgrade
test1$ R=3; for X in `jot ${R}`; do time ./gtod; done
    0m03.12s real     0m03.09s user     0m00.00s system
    0m03.00s real     0m02.97s user     0m00.01s system
    0m05.80s real     0m05.77s user     0m00.00s system

Among other programs, Office suites and browsers tend to hit the gettimeofday() very frequently, and this should lessen the CPU usage of those programs, and make things feel a bit snappier. Ted Unangst wrote about this in this post on running ktrace on a browser, and in this post about mplayer consuming lots of CPU while decoding MP3s.

This should be in snapshots any second now, so please do your part and help test snapshots so this can be a well tested feature for 6.8.

(Comments are closed)



Copyright © - Daniel Hartmeier. All rights reserved. Articles and comments are copyright their respective authors, submission implies license to publish on this web site. Contents of the archive prior to as well as images and HTML templates were copied from the fabulous original with Jose's and Jim's kind permission. This journal runs as CGI with httpd(8) on OpenBSD, the source code is BSD licensed. undeadly \Un*dead"ly\, a. Not subject to death; immortal. [Obs.]