From patchwork Sun Sep 2 05:45:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 11138 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id DFBD323E41 for ; Sun, 2 Sep 2012 05:48:42 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 4E000A18D0F for ; Sun, 2 Sep 2012 05:47:59 +0000 (UTC) Received: by mail-iy0-f180.google.com with SMTP id j25so6289543iaf.11 for ; Sat, 01 Sep 2012 22:48:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=4SYjV1EUiZMqyTog29p2y0j+GPNQ6NZapISXtqMEVbs=; b=a0n3n6L6b0NEv6xxph5ELSq0mV4N+xDhsLiAV/eY/NwQ/UyrCGl0qFjYqhPt0YDi/d f0aEVjt5qQFq3CxPOWNr5xyeFElJFfCvv1bjqS5bQ8ka3nAFSw6zTodNucI4WMdqqud+ 0Xgv56KwUAzzBXUSZEbr24AOxtSm1cuCJbWiGvdVNFcEH6YsHtX/YIVdrZOtvS+2L0vY eFXRovxMW7oDIChf6O6X/1PPLWmALlvbWu77EE23aDb6JFL/e8OCUJdccwmWrawpFS6T sHgM1nfDX6PtJrpeekjQMyAjXH+p4zOhQg8HpKWIEgnHk3vBBQVKjBA84OD6ijU/+Hs+ 896A== Received: by 10.42.109.194 with SMTP id m2mr12381261icp.48.1346564922222; Sat, 01 Sep 2012 22:48:42 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.184.232 with SMTP id ex8csp80996igc; Sat, 1 Sep 2012 22:48:41 -0700 (PDT) Received: by 10.68.224.71 with SMTP id ra7mr28470420pbc.154.1346564921595; Sat, 01 Sep 2012 22:48:41 -0700 (PDT) Received: from mail-pb0-f50.google.com (mail-pb0-f50.google.com [209.85.160.50]) by mx.google.com with ESMTPS id iv6si3327515pbc.58.2012.09.01.22.48.41 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 01 Sep 2012 22:48:41 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) client-ip=209.85.160.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.160.50 is neither permitted nor denied by best guess record for domain of anton.vorontsov@linaro.org) smtp.mail=anton.vorontsov@linaro.org Received: by mail-pb0-f50.google.com with SMTP id md12so7233407pbc.37 for ; Sat, 01 Sep 2012 22:48:41 -0700 (PDT) Received: by 10.68.231.130 with SMTP id tg2mr28721797pbc.70.1346564921333; Sat, 01 Sep 2012 22:48:41 -0700 (PDT) Received: from localhost (ip-64-134-230-8.public.wayport.net. [64.134.230.8]) by mx.google.com with ESMTPS id qw6sm7093006pbc.26.2012.09.01.22.48.38 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 01 Sep 2012 22:48:41 -0700 (PDT) From: Anton Vorontsov To: Thomas Gleixner Cc: Pekka Enberg , Leonid Moiseichuk , Bartlomiej Zolnierkiewicz , Colin Cross , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Davide Libenzi , Andrew Morton , Ingo Molnar , John Stultz , 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 Message-Id: <1346564722-14408-2-git-send-email-anton.vorontsov@linaro.org> X-Mailer: git-send-email 1.7.11.5 In-Reply-To: <20120902054335.GA12741@lizard> References: <20120902054335.GA12741@lizard> X-Gm-Message-State: ALoCoQk6I6fXwBOSC2Lt69tLlbUq0jUI2KiqxwwB2A7auTutIUb3dFL+DNanRiPzxGrm653RYVND 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 --- 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);