[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <54F6BCF3.4010404@ladisch.de>
Date: Wed, 04 Mar 2015 09:06:11 +0100
From: Clemens Ladisch <clemens@...isch.de>
To: Lucas De Marchi <lucas.de.marchi@...il.com>,
lkml <linux-kernel@...r.kernel.org>
CC: Thomas Gleixner <tglx@...utronix.de>,
Steven Rostedt <rostedt@...dmis.org>
Subject: Re: timerfd waking up before timer really expires
Lucas De Marchi wrote:
> I was debugging my application and noticed that a timerfd event was being
> triggered *before* the timer expires.
>
> I reduced the scope of the program to test a single timerfd and measure the
> difference in the result of clock_gettime() between two reads.
>
> loop_time_fd = setup_timerfd(interval, 0);
> do {
> read(loop_time_fd, &events, sizeof(events));
> ... = now_usec();
> } while (1);
>
> For whatever interval I configure and 10000 iterations, what I'm seeing in the
> elapsed vector are values like
>
> interval +- 70usec
Let us assume that the timer itself is perfectly accurate, and that all
wakeups of your program are immediately when the timerfd becomes ready,
except for one iteration, where there is a scheduling delay. Then the
measured interval before this delayed wakeup is longer, while the
measured interval after this wakeup is shorter by the same amount.
To detect early wakeups, you must not check whether the interval between
two consecutive wakeups is too short, but whether the interval between
a wakeup and the time when the timerfd was actually started is shorter
than N × the timer interval.
Regards,
Clemens
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists