From patchwork Wed Feb 20 19:41:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hilman X-Patchwork-Id: 2168961 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 1D27BDF230 for ; Wed, 20 Feb 2013 19:45:16 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U8FZ9-0006Qb-52; Wed, 20 Feb 2013 19:42:55 +0000 Received: from mail-pa0-f51.google.com ([209.85.220.51]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1U8FYB-00069n-7P for linux-arm-kernel@lists.infradead.org; Wed, 20 Feb 2013 19:41:56 +0000 Received: by mail-pa0-f51.google.com with SMTP id hz1so4236341pad.10 for ; Wed, 20 Feb 2013 11:41:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=7kHXSOB4FXnsGyJp8GVzSH/GELI3qitgtisEZh0yf8w=; b=HrzADZB+/isUYeOHj6y+UMp9Yi//szN2S9KSnXVWJwP0YvEoxLjIazY5+O4lCGLXIx AtQtNLHAYS1x8Jzq9CXbcLRa2f7al0zc7ra6vha6YF9RitKbB5eFNSfnKHk1WbmpT2/k BeNG2LyRQhp6HCBCyCe2QSQ0ZYpDfIB2eZ41P0qLcQFmOED9KcrZo1nO2rgVn6zkDmYY iLzAD+6tcaA11wVh1vXn/BSc1q6gOPGQmqgYl8Ozg8FzxgDNcuPRx5cZ5U/Du+WNnNFu D0IO76pnv6aDT6nWvWWALfja3RV0McAE4wX+AmZWkX4oicR2nfi+s0vghtv1FZOWL4ml 5tRQ== X-Received: by 10.68.208.70 with SMTP id mc6mr50723598pbc.27.1361389314342; Wed, 20 Feb 2013 11:41:54 -0800 (PST) Received: from localhost (c-24-19-7-36.hsd1.wa.comcast.net. [24.19.7.36]) by mx.google.com with ESMTPS id rl3sm22571748pbb.28.2013.02.20.11.41.52 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 20 Feb 2013 11:41:53 -0800 (PST) From: Kevin Hilman To: Frederic Weisbecker Subject: [RFC/PATCH 4/5] cputime: use do_div() for nsec resolution conversion helpers Date: Wed, 20 Feb 2013 11:41:41 -0800 Message-Id: <1361389302-11968-5-git-send-email-khilman@linaro.org> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1361389302-11968-1-git-send-email-khilman@linaro.org> References: <1361389302-11968-1-git-send-email-khilman@linaro.org> X-Gm-Message-State: ALoCoQnhhJUEGnkIJ2puMNX+lYkIDMM4BppfF+fvVkhzzXJ1zvZ2/zFYzo/2u2Zny1T0kGd8Vpob X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130220_144155_393907_BC778EB7 X-CRM114-Status: UNSURE ( 9.48 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.220.51 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Mats Liljegren , linaro-dev@lists.linaro.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org For the nsec resolution conversions to be useful on non 64-bit architectures, do_div() needs to be used for the 64-bit divisions. Signed-off-by: Kevin Hilman --- include/asm-generic/cputime_nsecs.h | 51 +++++++++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/include/asm-generic/cputime_nsecs.h b/include/asm-generic/cputime_nsecs.h index b6485ca..daa6075 100644 --- a/include/asm-generic/cputime_nsecs.h +++ b/include/asm-generic/cputime_nsecs.h @@ -24,13 +24,17 @@ typedef u64 __nocast cputime64_t; /* * Convert cputime <-> jiffies (HZ) */ -#define cputime_to_jiffies(__ct) \ - ((__force u64)(__ct) / (NSEC_PER_SEC / HZ)) +static inline u64 cputime_to_jiffies(const cputime_t ct) +{ + cputime_t __ct = ct; + + do_div(__ct, NSEC_PER_SEC / HZ); + return __ct; +} #define cputime_to_scaled(__ct) (__ct) #define jiffies_to_cputime(__jif) \ (__force cputime_t)((__jif) * (NSEC_PER_SEC / HZ)) -#define cputime64_to_jiffies64(__ct) \ - ((__force u64)(__ct) / (NSEC_PER_SEC / HZ)) +#define cputime64_to_jiffies64(__ct) cputime_to_jiffies(__ct) #define jiffies64_to_cputime64(__jif) \ (__force cputime64_t)((__jif) * (NSEC_PER_SEC / HZ)) @@ -44,8 +48,13 @@ typedef u64 __nocast cputime64_t; /* * Convert cputime <-> microseconds */ -#define cputime_to_usecs(__ct) \ - ((__force u64)(__ct) / NSEC_PER_USEC) +static inline u64 cputime_to_usecs(const cputime_t ct) +{ + cputime_t __ct = ct; + + do_div(__ct, NSEC_PER_USEC); + return __ct; +} #define usecs_to_cputime(__usecs) \ (__force cputime_t)((__usecs) * NSEC_PER_USEC) #define usecs_to_cputime64(__usecs) \ @@ -54,8 +63,13 @@ typedef u64 __nocast cputime64_t; /* * Convert cputime <-> seconds */ -#define cputime_to_secs(__ct) \ - ((__force u64)(__ct) / NSEC_PER_SEC) +static inline u64 cputime_to_secs(const cputime_t ct) +{ + cputime_t __ct = ct; + + do_div(__ct, NSEC_PER_SEC); + return __ct; +} #define secs_to_cputime(__secs) \ (__force cputime_t)((__secs) * NSEC_PER_SEC) @@ -69,8 +83,10 @@ static inline cputime_t timespec_to_cputime(const struct timespec *val) } static inline void cputime_to_timespec(const cputime_t ct, struct timespec *val) { - val->tv_sec = (__force u64) ct / NSEC_PER_SEC; - val->tv_nsec = (__force u64) ct % NSEC_PER_SEC; + cputime_t __ct = ct; + + val->tv_nsec = do_div(__ct, NSEC_PER_SEC); + val->tv_sec = __ct; } /* @@ -83,15 +99,22 @@ static inline cputime_t timeval_to_cputime(struct timeval *val) } static inline void cputime_to_timeval(const cputime_t ct, struct timeval *val) { - val->tv_sec = (__force u64) ct / NSEC_PER_SEC; - val->tv_usec = ((__force u64) ct % NSEC_PER_SEC) / NSEC_PER_USEC; + cputime_t __ct = ct; + + val->tv_usec = do_div(__ct, NSEC_PER_SEC) / NSEC_PER_USEC; + val->tv_sec = __ct; } /* * Convert cputime <-> clock (USER_HZ) */ -#define cputime_to_clock_t(__ct) \ - ((__force u64)(__ct) / (NSEC_PER_SEC / USER_HZ)) +static inline u64 cputime_to_clock_t(const cputime_t ct) +{ + cputime_t __ct = ct; + + do_div(__ct, (NSEC_PER_SEC / USER_HZ)); + return __ct; +} #define clock_t_to_cputime(__x) \ (__force cputime_t)((__x) * (NSEC_PER_SEC / USER_HZ))