From patchwork Wed Mar 20 23:34:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hilman X-Patchwork-Id: 2310581 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 33D94DF24C for ; Wed, 20 Mar 2013 23:39:08 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UISXF-0001GL-TG; Wed, 20 Mar 2013 23:35:09 +0000 Received: from mail-da0-x232.google.com ([2607:f8b0:400e:c00::232]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UISWk-00019t-Jm for linux-arm-kernel@lists.infradead.org; Wed, 20 Mar 2013 23:34:40 +0000 Received: by mail-da0-f50.google.com with SMTP id t1so1271960dae.37 for ; Wed, 20 Mar 2013 16:34:33 -0700 (PDT) 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=BIQuEn9aL64rrwQf98tyAPPXHPMjwg4+ib94lW6cUPg=; b=UIO92Ljxavj1dJNq8ZlTHE8e3sUBI4eco9T58B+saQcQIBp+SZ/8ZWIMETGnyOykoX /OWqvNZqevlVQRa8mc5D1y1ZNO2/mv5W+UuKOA8/QVML5BRfXIC0hdkr87tbRDJmvYmZ Eo1E+JjDqbYD12Hksz1/5dPS23I9H+I26fhapLzMTzKcfxvkiP6U3bjPhQLu3QRolY5k /298UKvqFLjgpaWojvQo4TOqbHTSRtymVs2gj7FoNnYxPSgspA+cCO+IQEnd8nvUx0NY hAFyo2ZRqb1jTyEMgKKijT/V5MIr8U+0KygpBzI9notB8s+joYIE7oZyU3GXZBmVUZmY bNvA== X-Received: by 10.66.88.105 with SMTP id bf9mr11887731pab.175.1363822473734; Wed, 20 Mar 2013 16:34:33 -0700 (PDT) Received: from localhost (c-24-19-7-36.hsd1.wa.comcast.net. [24.19.7.36]) by mx.google.com with ESMTPS id kb3sm3673996pbc.21.2013.03.20.16.34.32 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Wed, 20 Mar 2013 16:34:32 -0700 (PDT) From: Kevin Hilman To: Frederic Weisbecker , Russell King , linux-kernel@vger.kernel.org Subject: [PATCH 1/3] cputime_nsecs: use math64.h for nsec resolution conversion helpers Date: Wed, 20 Mar 2013 16:34:25 -0700 Message-Id: <1363822467-6275-2-git-send-email-khilman@linaro.org> X-Mailer: git-send-email 1.8.2 In-Reply-To: <1363822467-6275-1-git-send-email-khilman@linaro.org> References: <1363822467-6275-1-git-send-email-khilman@linaro.org> X-Gm-Message-State: ALoCoQnKGiZqxhVmnMrUOyu/UYpgqJ0D1ChkBZGUA9s9Wh60xjHgtyKNRNc25l/IgiBAXx84Fn8y X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130320_193438_820913_89137B13 X-CRM114-Status: GOOD ( 10.43 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Paul McKenney , linaro-kernel@lists.linaro.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org For the nsec resolution conversions to be useable on non 64-bit architectures, the helpers in need to be used so the right arch-specific 64-bit math helpers can be used (e.g. do_div()) Cc: Frederic Weisbecker Signed-off-by: Kevin Hilman --- include/asm-generic/cputime_nsecs.h | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/include/asm-generic/cputime_nsecs.h b/include/asm-generic/cputime_nsecs.h index a8ece9a..2c9e62c 100644 --- a/include/asm-generic/cputime_nsecs.h +++ b/include/asm-generic/cputime_nsecs.h @@ -16,21 +16,27 @@ #ifndef _ASM_GENERIC_CPUTIME_NSECS_H #define _ASM_GENERIC_CPUTIME_NSECS_H +#include + typedef u64 __nocast cputime_t; typedef u64 __nocast cputime64_t; #define cputime_one_jiffy jiffies_to_cputime(1) +#define cputime_div(__ct, divisor) div_u64((__force u64)__ct, divisor) +#define cputime_div_rem(__ct, divisor, remainder) \ + div_u64_rem((__force u64)__ct, divisor, remainder); + /* * Convert cputime <-> jiffies (HZ) */ #define cputime_to_jiffies(__ct) \ - ((__force u64)(__ct) / (NSEC_PER_SEC / HZ)) + cputime_div(__ct, NSEC_PER_SEC / HZ) #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)) + cputime_div(__ct, NSEC_PER_SEC / HZ) #define jiffies64_to_cputime64(__jif) \ (__force cputime64_t)((__jif) * (NSEC_PER_SEC / HZ)) @@ -45,7 +51,7 @@ typedef u64 __nocast cputime64_t; * Convert cputime <-> microseconds */ #define cputime_to_usecs(__ct) \ - ((__force u64)(__ct) / NSEC_PER_USEC) + cputime_div(__ct, NSEC_PER_USEC) #define usecs_to_cputime(__usecs) \ (__force cputime_t)((__usecs) * NSEC_PER_USEC) #define usecs_to_cputime64(__usecs) \ @@ -55,7 +61,7 @@ typedef u64 __nocast cputime64_t; * Convert cputime <-> seconds */ #define cputime_to_secs(__ct) \ - ((__force u64)(__ct) / NSEC_PER_SEC) + cputime_div(__ct, NSEC_PER_SEC) #define secs_to_cputime(__secs) \ (__force cputime_t)((__secs) * NSEC_PER_SEC) @@ -69,8 +75,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; + u32 rem; + + val->tv_sec = cputime_div_rem(ct, NSEC_PER_SEC, &rem); + val->tv_nsec = rem; } /* @@ -83,15 +91,17 @@ static inline cputime_t timeval_to_cputime(const 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; + u32 rem; + + val->tv_sec = cputime_div_rem(ct, NSEC_PER_SEC, &rem); + val->tv_usec = rem / NSEC_PER_USEC; } /* * Convert cputime <-> clock (USER_HZ) */ #define cputime_to_clock_t(__ct) \ - ((__force u64)(__ct) / (NSEC_PER_SEC / USER_HZ)) + cputime_div(__ct, (NSEC_PER_SEC / USER_HZ)) #define clock_t_to_cputime(__x) \ (__force cputime_t)((__x) * (NSEC_PER_SEC / USER_HZ))