All of lore.kernel.org
 help / color / mirror / Atom feed
From: Helge Deller <deller@gmx.de>
To: Thomas Gleixner <tglx@linutronix.de>,
	linux-parisc@vger.kernel.org,
	James Bottomley <James.Bottomley@HansenPartnership.com>,
	John David Anglin <dave.anglin@bell.net>
Cc: Linux Kernel Development <linux-kernel@vger.kernel.org>
Subject: Re: timerfd_settime/timerfd_gettime issue ?
Date: Mon, 4 Jan 2016 23:27:57 +0100	[thread overview]
Message-ID: <20160104222757.GA969@p100.box> (raw)
In-Reply-To: <alpine.DEB.2.11.1512301052520.28591@nanos>

Hi Thomas,

* Thomas Gleixner <tglx@linutronix.de>:
> On Tue, 29 Dec 2015, Helge Deller wrote:
> > No, the patch below doesn't help.
> > 
> > I still see:
> > [  644.916000] timerfd_settime: interval (sec=0, nsec=100000000) it_value (sec=0, nsec=100000000) 
> > [  645.024000] timerfd_gettime: interval (sec=0, nsec=100000000) it_value (sec=0, nsec=103029949) 
> > 
> 
> Right. It can't help. Sorry for the distraction.
> 
> Looking deeper I found the issue. It's caused by CONFIG_TIME_LOW_RES. See the
> comment in hrtimer_start_range_ns(). We round the expiry time to the next
> jiffies period to avoid short timeouts. Assuming you are running with HZ=250
> this is exactly 4ms. So that's where your extra time comes from.

Yes, that seems right.

> Not sure what to do about that.

The patch below seems to solve the issue for me. But I'm not sure if
there might be any side-effects. What do you think? Does the patch
seems correct? It just adjusts to values returned to userspace (and thus
hides the internal roundings).

Thanks,
Helge

diff --git a/fs/timerfd.c b/fs/timerfd.c
index b94fa6c..9b6cc73 100644
--- a/fs/timerfd.c
+++ b/fs/timerfd.c
@@ -152,8 +152,16 @@ static ktime_t timerfd_get_remaining(struct timerfd_ctx *ctx)
 
 	if (isalarm(ctx))
 		remaining = alarm_expires_remaining(&ctx->t.alarm);
-	else
+	else {
 		remaining = hrtimer_expires_remaining(&ctx->t.tmr);
+#ifdef CONFIG_TIME_LOW_RES
+		/* Expiry time was rounded up in hrtimer_start_range_ns()
+		 * to the next jiffies period to avoid short timeouts.
+		 * Subtract it here again to avoid userspace seeing higher
+		 * values than expected. */
+		remaining.tv64 -= hrtimer_resolution;
+#endif
+	}
 
 	return remaining.tv64 < 0 ? ktime_set(0, 0): remaining;
 }

  reply	other threads:[~2016-01-04 22:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-26 12:26 timerfd_settime/timerfd_gettime issue ? Helge Deller
2015-12-29  9:44 ` Thomas Gleixner
2015-12-29 20:13   ` Helge Deller
2015-12-30  9:57     ` Thomas Gleixner
2016-01-04 22:27       ` Helge Deller [this message]
2016-01-10 20:57         ` [PATCH parisc,frv,m68k] timerfd: Fix timeout values with CONFIG_TIME_LOW_RES=y Helge Deller
2016-01-10 20:57           ` Helge Deller

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=20160104222757.GA969@p100.box \
    --to=deller@gmx.de \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=dave.anglin@bell.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-parisc@vger.kernel.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.