From: Clemens Ladisch <clemens@ladisch.de>
To: Lucas De Marchi <lucas.de.marchi@gmail.com>,
lkml <linux-kernel@vger.kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Steven Rostedt <rostedt@goodmis.org>
Subject: Re: timerfd waking up before timer really expires
Date: Wed, 04 Mar 2015 09:06:11 +0100 [thread overview]
Message-ID: <54F6BCF3.4010404@ladisch.de> (raw)
In-Reply-To: <CAKi4VAJ=bz4eeBnk9nmT4+7Q6=F4ccJF6nVNcz7xiE-Ao=JCWw@mail.gmail.com>
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
next prev parent reply other threads:[~2015-03-04 8:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-03 19:59 timerfd waking up before timer really expires Lucas De Marchi
2015-03-04 8:06 ` Clemens Ladisch [this message]
2015-03-04 15:19 ` Lucas De Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54F6BCF3.4010404@ladisch.de \
--to=clemens@ladisch.de \
--cc=linux-kernel@vger.kernel.org \
--cc=lucas.de.marchi@gmail.com \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.