Re: [PATCH] RTC: Add mmap method to rtc character driver

Jim Gettys
2006-07-26T17:25:18Z

On Wed, 2006-07-26 at 17:16 +0200, Andi Kleen wrote:
> Neil Horman <nhorman@tuxdriver.com> writes:
>
> > At OLS last week, During Dave Jones Userspace Sucks presentation, Jim
> > Geddys and some of the Xorg guys noted that they would be able to stop using gettimeofday
> > so frequently, if they had some other way to get a millisecond resolution timer
> > in userspace,

I agree with Andi here.

>
> No, no, it's wrong. They should use gettimeofday and the kernel's job
> is to make it fast enough that they can.

Exactly. On modern machines, doing a procedure call to get the time (as
opposed to a system trap) is, I suspect, very tolerable. And who knows,
maybe a smart compiler inlines the procedure so it optimizes to just a
few instructions.

If behind the scenes there is a mapped page that is used to convey this
information efficiently, that's fine.

But I don't think it should be the application programmer's
responsibility to know of hackish solutions of mmapping particular
devices on particular OS hardware or software platforms. That's a
symptom of the disease, rather than a clean solution.

>
> Or rather they likely shouldn't use gettimeofday, but clock_gettime()
> with CLOCK_MONOTONIC instead to be independent of someone setting the
> clock back.

Turns out we already have code to handle the turn back case, but
monotonically increasing time is generally appreciated ;-).

>
> Memory mapped counters are generally not flexible enough and there
> are lots of reasons why the kernel might need to do special things
> for time keeping. Don't expose them.

Yup. I agree entirely.

>
> -Andi
--
Jim Gettys
One Laptop Per Child