Paul Irofti:

> > This iteration of the diff adds bounds checking for tk_user and moves
> > the usertc.c stub to every arch in libc as recommanded by deraadt@.
> > It also fixes a gettimeofday issue reported by cheloha@ and tb@.
> 
> Forgot to add armv7 tk_nclock entries. Noticed by benno@, thanks!

One blemish I see is that tk_user is a magic number.

For example, sparc64 will have two timecounters: tick and stick.
They will be assigned magic numbers 1 and 2...

    struct timecounter tick_timecounter = {
            tick_get_timecount, NULL, ~0u, 0, "tick", 0, NULL, 1
    };
    struct timecounter stick_timecounter = {
            stick_get_timecount, NULL, ~0u, 0, "stick", 1000, NULL, 2
    };

... and sparc64 usertc.c will need the corresponding magic array order:

    static uint64_t (*get_tc[])(void) =
    {
            rdtick,
            rdstick,
    };

I don't know if we want to go through the effort to make this
prettier.  We would need an MD header, say, <machine/timetc.h>
that gets picked up by <sys/timetc.h>, with something like

    #define TC_TICK         1
    #define TC_STICK        2

The symbolic values could then be used in the kernel timecounter
definitions...

    struct timecounter tick_timecounter = {
            tick_get_timecount, NULL, ~0u, 0, "tick", 0, NULL, TC_TICK
    };
    struct timecounter stick_timecounter = {
            stick_get_timecount, NULL, ~0u, 0, "stick", 1000, NULL, TC_STICK
    };

... and in libc usertc.c:

    static uint64_t (*get_tc[])(void) =
    {
            [TC_TICK] = rdtick,
            [TC_STICK] = rdstick,
    };
    ...
    *tc = (*get_tc[tk_user])();

The cost would be yet another header file per arch.
Thoughts?

-- 
Christian "naddy" Weisgerber                          na...@mips.inka.de

Reply via email to