From patchwork Mon Oct 30 22:29:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 117510 Delivered-To: patches@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3120395qgn; Mon, 30 Oct 2017 15:29:33 -0700 (PDT) X-Received: by 10.101.64.198 with SMTP id u6mr9044088pgp.44.1509402573331; Mon, 30 Oct 2017 15:29:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509402573; cv=none; d=google.com; s=arc-20160816; b=OlRT6RK9xURBSmg405jjWax6KUlXyXs1E+GUlSrvZiOyQxRtQHIkaVhRtWMGIUJsj/ I+3+5vu7hNcpCgDXAO2+9hoIi0MMc5YlHhMS085f1jWnIfC2vcUXbTq2yPF6FDHdyCmF O3+1uXdnfU8JFsm68KIYg5HO25C7f+VMtr4KD1RzQF8VvXXpxj2s5o6MyadQL+e4GSoo RRXz/YGY9PQkrBDaQzpDUsoXMhpbumppN+wz2KqpOUeYF/eRRgu5jnPdx19SU/nvBf98 ZLM6zu9Zxjz0SsnsJOAQpT77A5QjwngMZZ0JcH/er3PxHv9nsL2qNe+3dhv2v7Cw2+Tr LW5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=PhUB2YYEL41LMm6SJUh2B2XgySMfg6h/YjnKgXK8054=; b=P9ng0NbL3SsmxhYhO+uXAfH/sh220PKKcZUp+d1e6QXO1dwIZTsjaiBI53RQPwQfop 17bf7HKM/r2wYBJ0H1OYNL2XCFqN0BNb09aLFbi6RjERfGyK5YXBX5JDphtn4ELsTzpe ZACL3G0qMMW1bZDcfle8iB064LLdoXOrE1wKnqDuejqlXY+L6j28XXxpVb+4wJoO0kBc ioPzjcpGKPmmRXoVy9g1eDWmDELLF6bQoWqFhe+GrVfClcK1WZpUuOvbdwkVL/DH/aat VYyh2r1jvAJMuYUIAt2UwFtdHdJHacvhWwI/CfC2i9WdLhe5W6wG7qWRreVPRmEdsb4e XXNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qn2UwZyj; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id n89sor1657pfh.19.2017.10.30.15.29.33 for (Google Transport Security); Mon, 30 Oct 2017 15:29:33 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qn2UwZyj; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PhUB2YYEL41LMm6SJUh2B2XgySMfg6h/YjnKgXK8054=; b=Qn2UwZyj7vylF+V9bGnE8W9RMAv3cpWN73De4tSZrcLb/JTAX+psX+KfD+kPhEqo1I Ywb3FSMUBnkAs3NN+rhFqtOGJPimd0FSpLkM2jeOsrtMMqUXhsfRxMmXh4qaTR5cn2z3 4RCGEwvv8+jpMVH3COR0EySlfFJvxRIBzp4Wk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PhUB2YYEL41LMm6SJUh2B2XgySMfg6h/YjnKgXK8054=; b=lY05179k8O5I/U10Id29RHVnA28ibKRINs8piYfAIAub5BLHSaipqoqs9bnZKScE83 R6myaAxwvtcPrfypqpGhVGbk/sPLiD3f8jZn4aDzAg+HMRfd90z92K3rFTSrfQONTBB5 wWpn6t8yN9ktYoNC4iXldhwvesW/Vvwkp2ltDODR+LSwLlwZ42HReyFt6uHo3fde9wL4 dT8JFw3k3hEflY8dQ8HylFGiOId5UVrefWlo903obvncKoi6TB2lxJuD4Pds55kyuiUq VgWUhQCBUhSt7WC6Hol+vK0CVagprjJ4ex6zDsHykpiyvNibjuo+EfN7+vtH76xH96ts lj7Q== X-Gm-Message-State: AMCzsaXevEzrGO6i/+X0QHq9iXRigXD0cAtqZZMNJbQbgpZ/6mxTOafX HmVSiPkuz5+7EBGjPae7aqXDcWXR X-Google-Smtp-Source: ABhQp+Qz6h7drtYgmRY5HALyQETSiAqIrsO4olLVglVMn3yjQenudU4+p+ysNT7URo0czoE/J8RQGA== X-Received: by 10.98.147.197 with SMTP id r66mr10273781pfk.20.1509402572900; Mon, 30 Oct 2017 15:29:32 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id g13sm27479320pfm.130.2017.10.30.15.29.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 30 Oct 2017 15:29:31 -0700 (PDT) From: John Stultz To: lkml Cc: Arnd Bergmann , Thomas Gleixner , Ingo Molnar , Miroslav Lichvar , Richard Cochran , Prarit Bhargava , Stephen Boyd , John Stultz Subject: [PATCH 6/7] time: Move time_t conversion helpers to time32.h Date: Mon, 30 Oct 2017 15:29:13 -0700 Message-Id: <1509402554-18437-7-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509402554-18437-1-git-send-email-john.stultz@linaro.org> References: <1509402554-18437-1-git-send-email-john.stultz@linaro.org> From: Arnd Bergmann On 64-bit architectures, the timespec64 based helpers in linux/time.h are defined as macros pointing to their timespec based counterparts. This made sense when they were first introduced, but as we are migrating away from timespec in general, it's much less intuitive now. This changes the macros to work in the exact opposite way: we always provide the timespec64 based helpers and define the old interfaces as macros for them. Now we can move those macros into linux/time32.h, which already contains the respective helpers for 32-bit architectures. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Miroslav Lichvar Cc: Richard Cochran Cc: Prarit Bhargava Cc: Stephen Boyd Signed-off-by: Arnd Bergmann Signed-off-by: John Stultz --- include/linux/time32.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/time64.h | 50 +------------------------------------------------- kernel/time/time.c | 5 +++-- 3 files changed, 49 insertions(+), 51 deletions(-) -- 2.7.4 diff --git a/include/linux/time32.h b/include/linux/time32.h index 9b9c43f..65b1de2 100644 --- a/include/linux/time32.h +++ b/include/linux/time32.h @@ -13,6 +13,49 @@ #define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1) +#if __BITS_PER_LONG == 64 + +/* timespec64 is defined as timespec here */ +static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64) +{ + return ts64; +} + +static inline struct timespec64 timespec_to_timespec64(const struct timespec ts) +{ + return ts; +} + +# define timespec_equal timespec64_equal +# define timespec_compare timespec64_compare +# define set_normalized_timespec set_normalized_timespec64 +# define timespec_add timespec64_add +# define timespec_sub timespec64_sub +# define timespec_valid timespec64_valid +# define timespec_valid_strict timespec64_valid_strict +# define timespec_to_ns timespec64_to_ns +# define ns_to_timespec ns_to_timespec64 +# define timespec_add_ns timespec64_add_ns + +#else +static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64) +{ + struct timespec ret; + + ret.tv_sec = (time_t)ts64.tv_sec; + ret.tv_nsec = ts64.tv_nsec; + return ret; +} + +static inline struct timespec64 timespec_to_timespec64(const struct timespec ts) +{ + struct timespec64 ret; + + ret.tv_sec = ts.tv_sec; + ret.tv_nsec = ts.tv_nsec; + return ret; +} + static inline int timespec_equal(const struct timespec *a, const struct timespec *b) { @@ -116,6 +159,8 @@ static __always_inline void timespec_add_ns(struct timespec *a, u64 ns) a->tv_nsec = ns; } +#endif + /** * time_to_tm - converts the calendar time to local broken-down time * diff --git a/include/linux/time64.h b/include/linux/time64.h index 402b595c7..ec1888c 100644 --- a/include/linux/time64.h +++ b/include/linux/time64.h @@ -7,11 +7,8 @@ typedef __s64 time64_t; typedef __u64 timeu64_t; -/* - * This wants to go into uapi/linux/time.h once we agreed about the - * userspace interfaces. - */ #if __BITS_PER_LONG == 64 +/* this trick allows us to optimize out timespec64_to_timespec */ # define timespec64 timespec #define itimerspec64 itimerspec #else @@ -41,49 +38,6 @@ struct itimerspec64 { #define KTIME_MAX ((s64)~((u64)1 << 63)) #define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC) -#if __BITS_PER_LONG == 64 - -static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64) -{ - return ts64; -} - -static inline struct timespec64 timespec_to_timespec64(const struct timespec ts) -{ - return ts; -} - -# define timespec64_equal timespec_equal -# define timespec64_compare timespec_compare -# define set_normalized_timespec64 set_normalized_timespec -# define timespec64_add timespec_add -# define timespec64_sub timespec_sub -# define timespec64_valid timespec_valid -# define timespec64_valid_strict timespec_valid_strict -# define timespec64_to_ns timespec_to_ns -# define ns_to_timespec64 ns_to_timespec -# define timespec64_add_ns timespec_add_ns - -#else - -static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64) -{ - struct timespec ret; - - ret.tv_sec = (time_t)ts64.tv_sec; - ret.tv_nsec = ts64.tv_nsec; - return ret; -} - -static inline struct timespec64 timespec_to_timespec64(const struct timespec ts) -{ - struct timespec64 ret; - - ret.tv_sec = ts.tv_sec; - ret.tv_nsec = ts.tv_nsec; - return ret; -} - static inline int timespec64_equal(const struct timespec64 *a, const struct timespec64 *b) { @@ -185,8 +139,6 @@ static __always_inline void timespec64_add_ns(struct timespec64 *a, u64 ns) a->tv_nsec = ns; } -#endif - /* * timespec64_add_safe assumes both values are positive and checks for * overflow. It will return TIME64_MAX in case of overflow. diff --git a/kernel/time/time.c b/kernel/time/time.c index 947fb61..fe60ebd 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -407,6 +407,7 @@ time64_t mktime64(const unsigned int year0, const unsigned int mon0, } EXPORT_SYMBOL(mktime64); +#if __BITS_PER_LONG == 32 /** * set_normalized_timespec - set timespec sec and nsec parts and normalize * @@ -467,6 +468,7 @@ struct timespec ns_to_timespec(const s64 nsec) return ts; } EXPORT_SYMBOL(ns_to_timespec); +#endif /** * ns_to_timeval - Convert nanoseconds to timeval @@ -486,7 +488,6 @@ struct timeval ns_to_timeval(const s64 nsec) } EXPORT_SYMBOL(ns_to_timeval); -#if BITS_PER_LONG == 32 /** * set_normalized_timespec - set timespec sec and nsec parts and normalize * @@ -547,7 +548,7 @@ struct timespec64 ns_to_timespec64(const s64 nsec) return ts; } EXPORT_SYMBOL(ns_to_timespec64); -#endif + /** * msecs_to_jiffies: - convert milliseconds to jiffies * @m: time in milliseconds