mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Anton Vorontsov <anton.vorontsov@linaro.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: "Pekka Enberg" <penberg@kernel.org>,
	"Leonid Moiseichuk" <leonid.moiseichuk@nokia.com>,
	"Bartlomiej Zolnierkiewicz" <b.zolnierkie@samsung.com>,
	"Colin Cross" <ccross@android.com>,
	"Arve Hjønnevåg" <arve@android.com>,
	"Davide Libenzi" <davidel@xmailserver.org>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	"Ingo Molnar" <mingo@elte.hu>,
	"John Stultz" <john.stultz@linaro.org>,
	linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org,
	linaro-kernel@lists.linaro.org, patches@linaro.org,
	kernel-team@android.com
Subject: [PATCH 2/4] timerfd: Move repeated logic into timefd_rearm()
Date: Sat,  1 Sep 2012 22:45:20 -0700	[thread overview]
Message-ID: <1346564722-14408-2-git-send-email-anton.vorontsov@linaro.org> (raw)
In-Reply-To: <20120902054335.GA12741@lizard>

This patch introduces timerfd_rearm(), this small helper is used to
forward and restart the hrtimer.

This small refactoring would be also useful if/when we'll add other
backend for timerfd (like deferrable timers), so we won't need to
duplicate the code more.

Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
---
 fs/timerfd.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/fs/timerfd.c b/fs/timerfd.c
index dffeb37..ecfb3f3 100644
--- a/fs/timerfd.c
+++ b/fs/timerfd.c
@@ -178,6 +178,14 @@ static unsigned int timerfd_poll(struct file *file, poll_table *wait)
 	return events;
 }
 
+static u64 timerfd_rearm(struct timerfd_ctx *ctx)
+{
+	u64 orun = hrtimer_forward_now(&ctx->tmr, ctx->tintv) - 1;
+
+	hrtimer_restart(&ctx->tmr);
+	return orun;
+}
+
 static ssize_t timerfd_read(struct file *file, char __user *buf, size_t count,
 			    loff_t *ppos)
 {
@@ -214,9 +222,7 @@ static ssize_t timerfd_read(struct file *file, char __user *buf, size_t count,
 			 * callback to avoid DoS attacks specifying a very
 			 * short timer period.
 			 */
-			ticks += hrtimer_forward_now(&ctx->tmr,
-						     ctx->tintv) - 1;
-			hrtimer_restart(&ctx->tmr);
+			ticks += timerfd_rearm(ctx);
 		}
 		ctx->expired = 0;
 		ctx->ticks = 0;
@@ -355,9 +361,7 @@ SYSCALL_DEFINE2(timerfd_gettime, int, ufd, struct itimerspec __user *, otmr)
 	spin_lock_irq(&ctx->wqh.lock);
 	if (ctx->expired && ctx->tintv.tv64) {
 		ctx->expired = 0;
-		ctx->ticks +=
-			hrtimer_forward_now(&ctx->tmr, ctx->tintv) - 1;
-		hrtimer_restart(&ctx->tmr);
+		ctx->ticks += timerfd_rearm(ctx);
 	}
 	kotmr.it_value = ktime_to_timespec(timerfd_get_remaining(ctx));
 	kotmr.it_interval = ktime_to_timespec(ctx->tintv);
-- 
1.7.11.5


  parent reply	other threads:[~2012-09-02  5:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-02  5:43 [PATCH/RFC 0/4] Deferrable timers support for timerfd API Anton Vorontsov
2012-09-02  5:45 ` [PATCH 1/4] kernel/time: Add new helpers to convert ktime to/from jiffies Anton Vorontsov
2012-09-02  5:45 ` Anton Vorontsov [this message]
2012-09-02  5:45 ` [PATCH 3/4] timerfd: Factor out timer-type unspecific timerfd_expire() Anton Vorontsov
2012-09-02  5:45 ` [PATCH 4/4] timerfd: Add support for deferrable timers Anton Vorontsov
2012-09-17  5:53 ` [PATCH/RFC 0/4] Deferrable timers support for timerfd API Anton Vorontsov

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=1346564722-14408-2-git-send-email-anton.vorontsov@linaro.org \
    --to=anton.vorontsov@linaro.org \
    --cc=akpm@linux-foundation.org \
    --cc=arve@android.com \
    --cc=b.zolnierkie@samsung.com \
    --cc=ccross@android.com \
    --cc=davidel@xmailserver.org \
    --cc=john.stultz@linaro.org \
    --cc=kernel-team@android.com \
    --cc=leonid.moiseichuk@nokia.com \
    --cc=linaro-kernel@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=patches@linaro.org \
    --cc=penberg@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®