From patchwork Fri Jun 12 08:10:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 49813 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5CF5620C81 for ; Fri, 12 Jun 2015 08:12:07 +0000 (UTC) Received: by wgla2 with SMTP id a2sf7532772wgl.1 for ; Fri, 12 Jun 2015 01:12:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:in-reply-to:references :sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=S+HsZoFnmtv8kTuFArE7qfEpHS3z85qYeeC0ih4YS+M=; b=Y940ytqz3yM7DU9WLkaYkfDc9t5OZ+NKLgsCCUDD5sSmXauYcRzfWTx+8odiACueOe cVYyHW0ogSe1PEvRQNBmVCP03fMH2OG48Zvk3yZo4BGPHJipOa2IEFymR8u05CDAoQvN KfRV1ePedXFV9DehKr8rbFfNJlC1vkG/hMxVOhGNVYM0mCk7a0z/xU1oc3U82iuiQJJU G9GhaPvgkZT3bQ+NtEAXrpatnD99sChg2bckZI9lcVLfw4P1N2/g3yFw+lrLIq3zscVw LlNmT4+mni7JD6V/goUExp1Yh+ke8cG8C837TQUTpj6y2wIT7MhT2UIKCbKldLYcdoHq LTuw== X-Gm-Message-State: ALoCoQm6xzMaPpESqNI5KOLVNTZBkFRpSu8HWNgArh3ghrtiLeewJsnIXBT6LoV3YNE5vdl854DH X-Received: by 10.112.142.67 with SMTP id ru3mr13087539lbb.1.1434096726482; Fri, 12 Jun 2015 01:12:06 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.169 with SMTP id r9ls503284laj.86.gmail; Fri, 12 Jun 2015 01:12:06 -0700 (PDT) X-Received: by 10.112.72.132 with SMTP id d4mr13882809lbv.1.1434096726305; Fri, 12 Jun 2015 01:12:06 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id t1si2778711lbk.72.2015.06.12.01.12.06 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Jun 2015 01:12:06 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by labko7 with SMTP id ko7so17003829lab.2 for ; Fri, 12 Jun 2015 01:12:06 -0700 (PDT) X-Received: by 10.152.1.40 with SMTP id 8mr14201409laj.56.1434096726144; Fri, 12 Jun 2015 01:12:06 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp367915lbb; Fri, 12 Jun 2015 01:12:04 -0700 (PDT) X-Received: by 10.69.25.41 with SMTP id in9mr21153073pbd.80.1434096724235; Fri, 12 Jun 2015 01:12:04 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e2si4370895pat.2.2015.06.12.01.12.03; Fri, 12 Jun 2015 01:12:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754925AbbFLIL5 (ORCPT + 29 others); Fri, 12 Jun 2015 04:11:57 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:36070 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752786AbbFLILs (ORCPT ); Fri, 12 Jun 2015 04:11:48 -0400 Received: by pabqy3 with SMTP id qy3so18467194pab.3 for ; Fri, 12 Jun 2015 01:11:47 -0700 (PDT) X-Received: by 10.66.222.130 with SMTP id qm2mr21226498pac.39.1434096707889; Fri, 12 Jun 2015 01:11:47 -0700 (PDT) Received: from baolinwangubtpc.spreadtrum.com ([175.111.195.49]) by mx.google.com with ESMTPSA id sl9sm2792137pac.41.2015.06.12.01.11.42 (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Jun 2015 01:11:47 -0700 (PDT) From: Baolin Wang To: benh@kernel.crashing.org Cc: arnd@arndb.de, peterz@infradead.org, paulus@samba.org, mpe@ellerman.id.au, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, linux390@de.ibm.com, rth@twiddle.net, riel@redhat.com, cl@linux.com, tj@kernel.org, fweisbec@gmail.com, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, baolin.wang@linaro.org, y2038@lists.linaro.org Subject: [PATCH v5 22/24] cputime: Introduce cputime_to_timespec64()/timespec64_to_cputime() Date: Fri, 12 Jun 2015 16:10:32 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: baolin.wang@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The cputime_to_timespec() and timespec_to_cputime() functions are not year 2038 safe on 32bit systems due to the struct timepsec will overflow in 2038 year. Introduce cputime_to_timespec64() and timespec64_to_cputime() functions which use struct timespec64, as well as for arch/s390 and arch/powerpc architecture. The cputime_to_timespec() and timespec_to_cputime() functions are moved to include/linux/cputime.h file as 'static inline' for removing conveniently in future. Signed-off-by: Baolin Wang --- arch/powerpc/include/asm/cputime.h | 6 +++--- arch/s390/include/asm/cputime.h | 8 ++++---- include/asm-generic/cputime_jiffies.h | 10 +++++----- include/asm-generic/cputime_nsecs.h | 6 +++--- include/linux/cputime.h | 16 ++++++++++++++++ 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/arch/powerpc/include/asm/cputime.h b/arch/powerpc/include/asm/cputime.h index e245255..5dda5c0 100644 --- a/arch/powerpc/include/asm/cputime.h +++ b/arch/powerpc/include/asm/cputime.h @@ -154,9 +154,9 @@ static inline cputime_t secs_to_cputime(const unsigned long sec) } /* - * Convert cputime <-> timespec + * Convert cputime <-> timespec64 */ -static inline void cputime_to_timespec(const cputime_t ct, struct timespec *p) +static inline void cputime_to_timespec64(const cputime_t ct, struct timespec64 *p) { u64 x = (__force u64) ct; unsigned int frac; @@ -168,7 +168,7 @@ static inline void cputime_to_timespec(const cputime_t ct, struct timespec *p) p->tv_nsec = x; } -static inline cputime_t timespec_to_cputime(const struct timespec *p) +static inline cputime_t timespec64_to_cputime(const struct timespec64 *p) { u64 ct; diff --git a/arch/s390/include/asm/cputime.h b/arch/s390/include/asm/cputime.h index 221b454..3319b51 100644 --- a/arch/s390/include/asm/cputime.h +++ b/arch/s390/include/asm/cputime.h @@ -81,16 +81,16 @@ static inline cputime_t secs_to_cputime(const unsigned int s) } /* - * Convert cputime to timespec and back. + * Convert cputime to timespec64 and back. */ -static inline cputime_t timespec_to_cputime(const struct timespec *value) +static inline cputime_t timespec64_to_cputime(const struct timespec64 *value) { unsigned long long ret = value->tv_sec * CPUTIME_PER_SEC; return (__force cputime_t)(ret + __div(value->tv_nsec * CPUTIME_PER_USEC, NSEC_PER_USEC)); } -static inline void cputime_to_timespec(const cputime_t cputime, - struct timespec *value) +static inline void cputime_to_timespec64(const cputime_t cputime, + struct timespec64 *value) { unsigned long long __cputime = (__force unsigned long long) cputime; value->tv_nsec = (__cputime % CPUTIME_PER_SEC) * NSEC_PER_USEC / CPUTIME_PER_USEC; diff --git a/include/asm-generic/cputime_jiffies.h b/include/asm-generic/cputime_jiffies.h index fe386fc..54e034c 100644 --- a/include/asm-generic/cputime_jiffies.h +++ b/include/asm-generic/cputime_jiffies.h @@ -44,12 +44,12 @@ typedef u64 __nocast cputime64_t; #define secs_to_cputime(sec) jiffies_to_cputime((sec) * HZ) /* - * Convert cputime to timespec and back. + * Convert cputime to timespec64 and back. */ -#define timespec_to_cputime(__val) \ - jiffies_to_cputime(timespec_to_jiffies(__val)) -#define cputime_to_timespec(__ct,__val) \ - jiffies_to_timespec(cputime_to_jiffies(__ct),__val) +#define timespec64_to_cputime(__val) \ + jiffies_to_cputime(timespec64_to_jiffies(__val)) +#define cputime_to_timespec64(__ct,__val) \ + jiffies_to_timespec64(cputime_to_jiffies(__ct),__val) /* * Convert cputime to timeval and back. diff --git a/include/asm-generic/cputime_nsecs.h b/include/asm-generic/cputime_nsecs.h index 0419485..c0cafc0 100644 --- a/include/asm-generic/cputime_nsecs.h +++ b/include/asm-generic/cputime_nsecs.h @@ -71,14 +71,14 @@ typedef u64 __nocast cputime64_t; (__force cputime_t)((__secs) * NSEC_PER_SEC) /* - * Convert cputime <-> timespec (nsec) + * Convert cputime <-> timespec64 (nsec) */ -static inline cputime_t timespec_to_cputime(const struct timespec *val) +static inline cputime_t timespec64_to_cputime(const struct timespec64 *val) { u64 ret = val->tv_sec * NSEC_PER_SEC + val->tv_nsec; return (__force cputime_t) ret; } -static inline void cputime_to_timespec(const cputime_t ct, struct timespec *val) +static inline void cputime_to_timespec64(const cputime_t ct, struct timespec64 *val) { u32 rem; diff --git a/include/linux/cputime.h b/include/linux/cputime.h index f2eb2ee..cd638a0 100644 --- a/include/linux/cputime.h +++ b/include/linux/cputime.h @@ -13,4 +13,20 @@ usecs_to_cputime((__nsecs) / NSEC_PER_USEC) #endif +static inline cputime_t timespec_to_cputime(const struct timespec *ts) +{ + struct timespec64 ts64 = timespec_to_timespec64(*ts); + + return timespec64_to_cputime(&ts64); +} + +static inline void cputime_to_timespec(const cputime_t cputime, + struct timespec *value) +{ + struct timespec64 ts64; + + cputime_to_timespec64(cputime, &ts64); + *value = timespec64_to_timespec(ts64); +} + #endif /* __LINUX_CPUTIME_H */