From patchwork Thu Feb 21 19:21:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Hilman X-Patchwork-Id: 2172841 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id D2BC23FCA4 for ; Thu, 21 Feb 2013 19:24:29 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U8bi3-0002zP-KK; Thu, 21 Feb 2013 19:21:35 +0000 Received: from mail-da0-f48.google.com ([209.85.210.48]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1U8bhn-0002wI-Ej for linux-arm-kernel@lists.infradead.org; Thu, 21 Feb 2013 19:21:20 +0000 Received: by mail-da0-f48.google.com with SMTP id w4so765814dam.7 for ; Thu, 21 Feb 2013 11:21:17 -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:references:date:in-reply-to :message-id:user-agent:mime-version:content-type:x-gm-message-state; bh=KJADW/fhIHjp1G7q8vSBkIFk+4DErBN9Kjx+gA/TxmA=; b=SldtF4fo9Z313LbQAOiE+6qdBL73YoH+kxgTyi7qSN0/3HouWJX8dOojxgFhFK3lFl igBVkvmX6aG9iIHOHt9Or99HM/j98GJfoeAIX2yN8JNP4tjkY2KrZ5r9cmYAvZzH8h19 wDgj4nlDPiC3ii7Ub2KbaHvYVDaFvKGDd0FAvqoJwSuU82U0aJCwOES83Zt3rc3GM17u RjOfKx5JCjrZGWklIWWtQc/hf/0jmB3O9srQ9FVMKh8iSX97ty9qGkc6mWiaq4VJwqkf puekQVi+/cV43PfRz7S7mFgIS5VoCyccEWDq/ToLm59t2Y0dtJQW+kYeoA3wHfKxtw1Y fzpw== X-Received: by 10.68.230.193 with SMTP id ta1mr55735329pbc.103.1361474477085; Thu, 21 Feb 2013 11:21:17 -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 s9sm40937pav.7.2013.02.21.11.21.14 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 21 Feb 2013 11:21:15 -0800 (PST) From: Kevin Hilman To: Namhyung Kim Subject: Re: [RFC/PATCH 4/5] cputime: use do_div() for nsec resolution conversion helpers References: <1361389302-11968-1-git-send-email-khilman@linaro.org> <1361389302-11968-5-git-send-email-khilman@linaro.org> <20130221175857.GB14256@danjae.linux.parc55> Date: Thu, 21 Feb 2013 11:21:13 -0800 In-Reply-To: <20130221175857.GB14256@danjae.linux.parc55> (Namhyung Kim's message of "Thu, 21 Feb 2013 09:58:57 -0800") Message-ID: <87621lo4ly.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux) MIME-Version: 1.0 X-Gm-Message-State: ALoCoQlkWeZRWTp0tr3EQ/2Nx8vX9ciQXrPPKjjauHXM/cCJSPuo7wZ9M7oofWzDR3DEveEZ9rl+ X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130221_142120_100963_DBCA22E8 X-CRM114-Status: GOOD ( 16.97 ) 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.210.48 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Frederic Weisbecker , 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: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Namhyung Kim writes: > Hi Kevin, > > On Wed, Feb 20, 2013 at 11:41:41AM -0800, Kevin Hilman wrote: >> 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; > > Why it removed the "(__force u64)" conversion part? Shouldn't it be: > > u64 __ct = (__force u64) ct; > > ? You're right, that was an oversight. Updated patch below. Frederic, if you merge this, please take the one below with the __force attributes added back. I've updated my branch to include the fixed version. Kevin From a8a0a8b8b12512a7f862ade459cd88d2b48e2bf3 Mon Sep 17 00:00:00 2001 From: Kevin Hilman Date: Thu, 14 Feb 2013 11:27:36 -0800 Subject: [PATCH 4/5] cputime: use do_div() for nsec resolution conversion helpers For the nsec resolution conversions to be useful on non 64-bit architectures, do_div() needs to be used for the 64-bit divisions. Special thanks to Namhyung Kim for pointing out omissions of the __force attribute in an earlier version. Cc: Namhyung Kim 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..d4944c9 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) +{ + u64 __ct = (__force u64) 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) +{ + u64 __ct = (__force u64) 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) +{ + u64 __ct = (__force u64) 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; + u64 __ct = (__force u64) 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; + u64 __ct = (__force u64) 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) +{ + u64 __ct = (__force u64) 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))