From patchwork Sun Sep 2 05:45:19 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Vorontsov X-Patchwork-Id: 11137 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 266B023E41 for ; Sun, 2 Sep 2012 05:48:19 +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 73CF6A18D0F for ; Sun, 2 Sep 2012 05:47:35 +0000 (UTC) Received: by iafj25 with SMTP id j25so6289543iaf.11 for ; Sat, 01 Sep 2012 22:48:18 -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=pKUgNACF946jNqfAVYk9sxTcDXH40+qyyhkq7lyh9gk=; b=CvUax5mbCMT25TYibBU7NSgqKGUXA0alncak7icvC+xtWqYGs9S5bSrkEQUev7J7h1 aeuwRUSjjSwuikvsmQlonxW2THddXS4j5vpQZTw02hN2jxKXpB34nvS2Ci1oickx3wMy U3S3I4TP2TA5/Xv+MRwYh2+FuWCLYZvL0DIr1FMWQGXt72RA/nbeLd/7QO0T5/y/RHEh 8YDgx24Th8inRb1czUd9OUw7Wvfz5G3Hj9p2i4iMpv8VA4PwkL1fkkD+RJJOBwM3duwa 7SY3wqJhCx1bCSwmSX5kAyWxoyBU7rmZcJnOePImL03exEfslf8YaKvmL2iYB210t76E vAkw== Received: by 10.50.45.162 with SMTP id o2mr7549486igm.0.1346564898181; Sat, 01 Sep 2012 22:48:18 -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 ex8csp80989igc; Sat, 1 Sep 2012 22:48:17 -0700 (PDT) Received: by 10.68.231.168 with SMTP id th8mr29142131pbc.14.1346564897539; Sat, 01 Sep 2012 22:48:17 -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.17 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 01 Sep 2012 22:48:17 -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 pbcmd12 with SMTP id md12so7233407pbc.37 for ; Sat, 01 Sep 2012 22:48:17 -0700 (PDT) Received: by 10.68.197.194 with SMTP id iw2mr22959038pbc.121.1346564897083; Sat, 01 Sep 2012 22:48:17 -0700 (PDT) Received: from localhost (ip-64-134-230-8.public.wayport.net. [64.134.230.8]) by mx.google.com with ESMTPS id pj10sm7086669pbb.46.2012.09.01.22.48.14 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 01 Sep 2012 22:48:16 -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 1/4] kernel/time: Add new helpers to convert ktime to/from jiffies Date: Sat, 1 Sep 2012 22:45:19 -0700 Message-Id: <1346564722-14408-1-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: ALoCoQmMCgxWPTXAlsorBPXXKvxUMXkGpjc9h6ljtskJYMYHqim236D75Ka8VGzCay7/WahvonRv Two new functions: jiffies_to_ktime() and ktime_to_jiffies(), we'll use them for timerfd deferred timers handling. We fully reuse the logic from timespec implementations, so the functions are pretty straightforward. The only tricky part is in headers: we have to include jiffies.h after we defined ktime_t, this is because ktime.h needs some declarations from jiffies.h (e.g. TICK_NSEC). Signed-off-by: Anton Vorontsov --- include/linux/jiffies.h | 3 +++ include/linux/ktime.h | 3 ++- kernel/time.c | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h index 265e2c3..4451241 100644 --- a/include/linux/jiffies.h +++ b/include/linux/jiffies.h @@ -6,6 +6,7 @@ #include #include #include +#include #include /* for HZ */ /* @@ -303,6 +304,8 @@ extern void jiffies_to_timespec(const unsigned long jiffies, extern unsigned long timeval_to_jiffies(const struct timeval *value); extern void jiffies_to_timeval(const unsigned long jiffies, struct timeval *value); +extern unsigned long ktime_to_jiffies(ktime_t *value); +extern void jiffies_to_ktime(const unsigned long jiffies, ktime_t *value); extern clock_t jiffies_to_clock_t(unsigned long x); extern unsigned long clock_t_to_jiffies(unsigned long x); extern u64 jiffies_64_to_clock_t(u64 x); diff --git a/include/linux/ktime.h b/include/linux/ktime.h index 603bec2..9551856 100644 --- a/include/linux/ktime.h +++ b/include/linux/ktime.h @@ -22,7 +22,6 @@ #define _LINUX_KTIME_H #include -#include /* * ktime_t: @@ -58,6 +57,8 @@ union ktime { typedef union ktime ktime_t; /* Kill this */ +#include + #define KTIME_MAX ((s64)~((u64)1 << 63)) #if (BITS_PER_LONG == 64) # define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC) diff --git a/kernel/time.c b/kernel/time.c index ba744cf..82c06c5 100644 --- a/kernel/time.c +++ b/kernel/time.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -566,6 +567,28 @@ void jiffies_to_timeval(const unsigned long jiffies, struct timeval *value) } EXPORT_SYMBOL(jiffies_to_timeval); +unsigned long ktime_to_jiffies(ktime_t *value) +{ + struct timespec ts = ktime_to_timespec(*value); + + /* + * nsecs_to_jiffies(ktime_to_ns(*ktime)) is unsafe as nsecs_to_jiffies + * doesn't handle MAX_JIFFY_OFFSET. So we reuse the logic from the + * timespec to jiffies conversion function. + */ + return timespec_to_jiffies(&ts); +} +EXPORT_SYMBOL(ktime_to_jiffies); + +void jiffies_to_ktime(const unsigned long jiffies, ktime_t *value) +{ + struct timespec ts; + + jiffies_to_timespec(jiffies, &ts); + *value = timespec_to_ktime(ts); +} +EXPORT_SYMBOL(jiffies_to_ktime); + /* * Convert jiffies/jiffies_64 to clock_t and back. */