From patchwork Thu Oct 19 11:14:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 116361 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp365789qgn; Thu, 19 Oct 2017 04:15:19 -0700 (PDT) X-Google-Smtp-Source: ABhQp+Q4cuJ0ecubrOGaEo3TyGX1PqPBWVE5BstZFH9Yk+xvsziPS5ZolEDg3c8tmgOASQK3CW06 X-Received: by 10.101.78.5 with SMTP id r5mr1062363pgt.94.1508411719539; Thu, 19 Oct 2017 04:15:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508411719; cv=none; d=google.com; s=arc-20160816; b=kGmQy6mLe800n/HzLnuNzsQ8V8X63AappwTqtJV6x38lBKW3gtK4+5/msGpPpXMvV1 G7zO45JOElb0GH7gvmHkNDjBCw/MxpKIv1jc2RhNBIPunB8NflFJVnl9JhcyOxjkU0Y+ ge6v9Uwo8Ng5g/yRNl7m9xnvJWiDOBuVV3cNnCTr6vQ0EQz5jDFjaaKnZhHPxal9QIwI 5Ss6WfYyOiyqoOvbSxwdT8GeDILfhoo3yiHFG7hTPHHYgujSPj9hmwiUXX6qe7HoUxmA +vyzg22czWSv9Sn48GvC19R1KmNPXhfkI18QnkuZMuqx0QebC07Wjw03bJ2A87skOToI sZog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=EgGjStpDYmTsPcXLLW7BGUq6AsaPfyJCtSYJ/JwCQLo=; b=O4BbxEYsQjTEmy4IJ2gRWBtt7P5R8yJI6PMw7z8fzAd+I5E3K7CgaAw5LD0LRMt6h9 HYps/uJQTGCTODMXuh187a1h0zhbxB0ECpxUkEM8795QoKeaaz47d8fE1uT3qMDc/YKH l8DHwbprAMOxFKvnvuHM6wcqXu6mbtP7z72GloLMs7cCkOyXf/33Vvg58s9DLzuVUsSe Lgm3h+Z+CxOVHko7ShfUJLeQGqvR+u/I8r9icnJIJh94wglyQW0BaLVSk6yyJkXBJLFa ZecYSK1mckbpKhLNPWhwbCWlmkk8iFqbAcBrXArt4BGN5Kg7RM82QndsT/wErG+HE7aA /AdQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m3si2657345pgs.564.2017.10.19.04.15.19; Thu, 19 Oct 2017 04:15:19 -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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752757AbdJSLPR (ORCPT + 27 others); Thu, 19 Oct 2017 07:15:17 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:51451 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752108AbdJSLPP (ORCPT ); Thu, 19 Oct 2017 07:15:15 -0400 Received: from wuerfel.lan ([46.223.139.202]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.145]) with ESMTPA (Nemesis) id 0MC1E8-1dwNLc06Ou-008psj; Thu, 19 Oct 2017 13:15:04 +0200 From: Arnd Bergmann To: Thomas Gleixner , y2038@lists.linaro.org Cc: Deepa Dinamani , John Stultz , Stephen Boyd , linux-kernel@vger.kernel.org, Arnd Bergmann Subject: [PATCH 1/7] timekeeping: consolidate timekeeping_inject_offset code Date: Thu, 19 Oct 2017 13:14:44 +0200 Message-Id: <20171019111450.3702205-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:ZWp54L5OWkFsKmFEa6LEtMmlMv9IxxbcCTPof5WffK82M+3Vrg2 6cbAVJ/BamxeJWKZqgBbkYE0bBtgT0KrRB9J4Gtom/P4i4MFRtPCD2JvTm/oFQINZGcH/IV YTvTJ6J7/xo4LfUzFgCscpoQ413jG1Dnsa59O/3J/VWHlhWxjlUoJL97A70dmM3XMMA4xnD Jt1cKQ36XIBRICwSse4LA== X-UI-Out-Filterresults: notjunk:1; V01:K0:cfsc9rt9364=:X0WAJ0eBID0x4BKiynatmj pGASX+8dyLWAcwLk1JEK0RyfcJzme4RvIKZIR5fSJ/JhEhZIF4enLB47CMjScZlcsGTQi0ygM LxE/W6TShUjOH3b8i6hG+CjlR0BM+F7HjmgfRmW63c7r5+qgTGXgr52Qb6PUaWwYoulaeqiSF DA0q3uaezUFiA7+tOBUMfcRqICje9B32jQOH35g6ztRDcb+kWZyc3+YOL/vvJxc7eYPJSDp6P J6PmLDSa3pvq3HXKeDsJ4zdBNrOMbfOxbt+bChPrL0Po00DppHwI5mT+z7tQ3iT6Vq+6MTbI5 NVgUfl0/DG5eLCSNAakxVke/68PR2tyzxkV7Huw9jfspg6ifWU67OAgNGAO+zmdKgop4UVoyB bdOWLXabueJNm9tWjy/I49H4zCLgemHv1GH8w2O+pkZESM/xlBVikz0KXYSITPogalPQutC9H TzDJPhNrgbpFmmpIys8ZC4RkOfBcUBbQme1JKVfMiTTuuqXUhlXuYXIjiUTsUPnEbX0Igy4nB XzsnsAPajUYcKYpL2WAgGD8b/5HipI5YR7ET35is+r72rnddef+iPvhCqGxMA6FHksj8oYHKn TLkPFJrcg6KTHKXoYSzsBWodNspcESVLSy2vRha6pw0LCFfH19U7i+iEzp7mkORus7neQICUy sgF7WD3/bR1oHQ/yzbun0FPdjt5zwXctO0+cvKBPQypH15c5xnbkQp65yDOUN2imM3fvMPDiO EtJnrt018NHfYYrNEqxbcEJjMuq7rkLRjnWxSQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The code to check the adjtimex() or clock_adjtime() arguments is spread out across multiple files for presumably only historic reasons. As a preparatation for a rework to get rid of the use of 'struct timeval' and 'struct timespec' in there, this moves all the portions into kernel/time/timekeeping.c and marks them as 'static'. The warp_clock() function here is not as closely related as the others, but I feel it still makes sense to move it here in order to consolidate all callers of timekeeping_inject_offset(). Signed-off-by: Arnd Bergmann --- include/linux/time.h | 26 ---------- kernel/time/ntp.c | 61 ---------------------- kernel/time/ntp_internal.h | 1 - kernel/time/time.c | 36 +------------ kernel/time/timekeeping.c | 123 ++++++++++++++++++++++++++++++++++++++++++++- kernel/time/timekeeping.h | 2 +- 6 files changed, 123 insertions(+), 126 deletions(-) -- 2.9.0 diff --git a/include/linux/time.h b/include/linux/time.h index 9bc1f945777c..c0fbad08448f 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -134,32 +134,6 @@ static inline bool timeval_valid(const struct timeval *tv) extern struct timespec timespec_trunc(struct timespec t, unsigned gran); -/* - * Validates if a timespec/timeval used to inject a time offset is valid. - * Offsets can be postive or negative. The value of the timeval/timespec - * is the sum of its fields, but *NOTE*: the field tv_usec/tv_nsec must - * always be non-negative. - */ -static inline bool timeval_inject_offset_valid(const struct timeval *tv) -{ - /* We don't check the tv_sec as it can be positive or negative */ - - /* Can't have more microseconds then a second */ - if (tv->tv_usec < 0 || tv->tv_usec >= USEC_PER_SEC) - return false; - return true; -} - -static inline bool timespec_inject_offset_valid(const struct timespec *ts) -{ - /* We don't check the tv_sec as it can be positive or negative */ - - /* Can't have more nanoseconds then a second */ - if (ts->tv_nsec < 0 || ts->tv_nsec >= NSEC_PER_SEC) - return false; - return true; -} - /* Some architectures do not supply their own clocksource. * This is mainly the case in architectures that get their * inter-tick times by reading the counter on their interval diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c index edf19cc53140..a5e702669d84 100644 --- a/kernel/time/ntp.c +++ b/kernel/time/ntp.c @@ -653,67 +653,6 @@ static inline void process_adjtimex_modes(struct timex *txc, } - -/** - * ntp_validate_timex - Ensures the timex is ok for use in do_adjtimex - */ -int ntp_validate_timex(struct timex *txc) -{ - if (txc->modes & ADJ_ADJTIME) { - /* singleshot must not be used with any other mode bits */ - if (!(txc->modes & ADJ_OFFSET_SINGLESHOT)) - return -EINVAL; - if (!(txc->modes & ADJ_OFFSET_READONLY) && - !capable(CAP_SYS_TIME)) - return -EPERM; - } else { - /* In order to modify anything, you gotta be super-user! */ - if (txc->modes && !capable(CAP_SYS_TIME)) - return -EPERM; - /* - * if the quartz is off by more than 10% then - * something is VERY wrong! - */ - if (txc->modes & ADJ_TICK && - (txc->tick < 900000/USER_HZ || - txc->tick > 1100000/USER_HZ)) - return -EINVAL; - } - - if (txc->modes & ADJ_SETOFFSET) { - /* In order to inject time, you gotta be super-user! */ - if (!capable(CAP_SYS_TIME)) - return -EPERM; - - if (txc->modes & ADJ_NANO) { - struct timespec ts; - - ts.tv_sec = txc->time.tv_sec; - ts.tv_nsec = txc->time.tv_usec; - if (!timespec_inject_offset_valid(&ts)) - return -EINVAL; - - } else { - if (!timeval_inject_offset_valid(&txc->time)) - return -EINVAL; - } - } - - /* - * Check for potential multiplication overflows that can - * only happen on 64-bit systems: - */ - if ((txc->modes & ADJ_FREQUENCY) && (BITS_PER_LONG == 64)) { - if (LLONG_MIN / PPM_SCALE > txc->freq) - return -EINVAL; - if (LLONG_MAX / PPM_SCALE < txc->freq) - return -EINVAL; - } - - return 0; -} - - /* * adjtimex mainly allows reading (and writing, if superuser) of * kernel time-keeping variables. used by xntpd. diff --git a/kernel/time/ntp_internal.h b/kernel/time/ntp_internal.h index d8a7c11fa71a..74b52cd48209 100644 --- a/kernel/time/ntp_internal.h +++ b/kernel/time/ntp_internal.h @@ -7,7 +7,6 @@ extern void ntp_clear(void); extern u64 ntp_tick_length(void); extern ktime_t ntp_get_next_leap(void); extern int second_overflow(time64_t secs); -extern int ntp_validate_timex(struct timex *); extern int __do_adjtimex(struct timex *, struct timespec64 *, s32 *); extern void __hardpps(const struct timespec64 *, const struct timespec64 *); #endif /* _LINUX_NTP_INTERNAL_H */ diff --git a/kernel/time/time.c b/kernel/time/time.c index 44a8c1402133..04684e294f00 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -158,40 +158,6 @@ SYSCALL_DEFINE2(gettimeofday, struct timeval __user *, tv, } /* - * Indicates if there is an offset between the system clock and the hardware - * clock/persistent clock/rtc. - */ -int persistent_clock_is_local; - -/* - * Adjust the time obtained from the CMOS to be UTC time instead of - * local time. - * - * This is ugly, but preferable to the alternatives. Otherwise we - * would either need to write a program to do it in /etc/rc (and risk - * confusion if the program gets run more than once; it would also be - * hard to make the program warp the clock precisely n hours) or - * compile in the timezone information into the kernel. Bad, bad.... - * - * - TYT, 1992-01-01 - * - * The best thing to do is to keep the CMOS clock in universal time (UTC) - * as real UNIX machines always do it. This avoids all headaches about - * daylight saving times and warping kernel clocks. - */ -static inline void warp_clock(void) -{ - if (sys_tz.tz_minuteswest != 0) { - struct timespec adjust; - - persistent_clock_is_local = 1; - adjust.tv_sec = sys_tz.tz_minuteswest * 60; - adjust.tv_nsec = 0; - timekeeping_inject_offset(&adjust); - } -} - -/* * In case for some reason the CMOS clock has not already been running * in UTC, but in some local time: The first time we set the timezone, * we will warp the clock so that it is ticking UTC time instead of @@ -224,7 +190,7 @@ int do_sys_settimeofday64(const struct timespec64 *tv, const struct timezone *tz if (firsttime) { firsttime = 0; if (!tv) - warp_clock(); + timekeeping_warp_clock(); } } if (tv) diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 8af77006e937..679dbfbea419 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1300,13 +1300,39 @@ int do_settimeofday64(const struct timespec64 *ts) } EXPORT_SYMBOL(do_settimeofday64); +/* + * Validates if a timespec/timeval used to inject a time offset is valid. + * Offsets can be postive or negative. The value of the timeval/timespec + * is the sum of its fields, but *NOTE*: the field tv_usec/tv_nsec must + * always be non-negative. + */ +static inline bool timeval_inject_offset_valid(const struct timeval *tv) +{ + /* We don't check the tv_sec as it can be positive or negative */ + + /* Can't have more microseconds then a second */ + if (tv->tv_usec < 0 || tv->tv_usec >= USEC_PER_SEC) + return false; + return true; +} + +static inline bool timespec_inject_offset_valid(const struct timespec *ts) +{ + /* We don't check the tv_sec as it can be positive or negative */ + + /* Can't have more nanoseconds then a second */ + if (ts->tv_nsec < 0 || ts->tv_nsec >= NSEC_PER_SEC) + return false; + return true; +} + /** * timekeeping_inject_offset - Adds or subtracts from the current time. * @tv: pointer to the timespec variable containing the offset * * Adds or subtracts an offset value from the current time. */ -int timekeeping_inject_offset(struct timespec *ts) +static int timekeeping_inject_offset(struct timespec *ts) { struct timekeeper *tk = &tk_core.timekeeper; unsigned long flags; @@ -1345,7 +1371,40 @@ int timekeeping_inject_offset(struct timespec *ts) return ret; } -EXPORT_SYMBOL(timekeeping_inject_offset); + +/* + * Indicates if there is an offset between the system clock and the hardware + * clock/persistent clock/rtc. + */ +int persistent_clock_is_local; + +/* + * Adjust the time obtained from the CMOS to be UTC time instead of + * local time. + * + * This is ugly, but preferable to the alternatives. Otherwise we + * would either need to write a program to do it in /etc/rc (and risk + * confusion if the program gets run more than once; it would also be + * hard to make the program warp the clock precisely n hours) or + * compile in the timezone information into the kernel. Bad, bad.... + * + * - TYT, 1992-01-01 + * + * The best thing to do is to keep the CMOS clock in universal time (UTC) + * as real UNIX machines always do it. This avoids all headaches about + * daylight saving times and warping kernel clocks. + */ +void timekeeping_warp_clock(void) +{ + if (sys_tz.tz_minuteswest != 0) { + struct timespec adjust; + + persistent_clock_is_local = 1; + adjust.tv_sec = sys_tz.tz_minuteswest * 60; + adjust.tv_nsec = 0; + timekeeping_inject_offset(&adjust); + } +} /** * __timekeeping_set_tai_offset - Sets the TAI offset from UTC and monotonic @@ -2290,6 +2349,66 @@ ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq, ktime_t *offs_real, } /** + * ntp_validate_timex - Ensures the timex is ok for use in do_adjtimex + */ +static int ntp_validate_timex(struct timex *txc) +{ + if (txc->modes & ADJ_ADJTIME) { + /* singleshot must not be used with any other mode bits */ + if (!(txc->modes & ADJ_OFFSET_SINGLESHOT)) + return -EINVAL; + if (!(txc->modes & ADJ_OFFSET_READONLY) && + !capable(CAP_SYS_TIME)) + return -EPERM; + } else { + /* In order to modify anything, you gotta be super-user! */ + if (txc->modes && !capable(CAP_SYS_TIME)) + return -EPERM; + /* + * if the quartz is off by more than 10% then + * something is VERY wrong! + */ + if (txc->modes & ADJ_TICK && + (txc->tick < 900000/USER_HZ || + txc->tick > 1100000/USER_HZ)) + return -EINVAL; + } + + if (txc->modes & ADJ_SETOFFSET) { + /* In order to inject time, you gotta be super-user! */ + if (!capable(CAP_SYS_TIME)) + return -EPERM; + + if (txc->modes & ADJ_NANO) { + struct timespec ts; + + ts.tv_sec = txc->time.tv_sec; + ts.tv_nsec = txc->time.tv_usec; + if (!timespec_inject_offset_valid(&ts)) + return -EINVAL; + + } else { + if (!timeval_inject_offset_valid(&txc->time)) + return -EINVAL; + } + } + + /* + * Check for potential multiplication overflows that can + * only happen on 64-bit systems: + */ + if ((txc->modes & ADJ_FREQUENCY) && (BITS_PER_LONG == 64)) { + if (LLONG_MIN / PPM_SCALE > txc->freq) + return -EINVAL; + if (LLONG_MAX / PPM_SCALE < txc->freq) + return -EINVAL; + } + + return 0; +} + + +/** * do_adjtimex() - Accessor function to NTP __do_adjtimex function */ int do_adjtimex(struct timex *txc) diff --git a/kernel/time/timekeeping.h b/kernel/time/timekeeping.h index d0914676d4c5..44aec7893cdd 100644 --- a/kernel/time/timekeeping.h +++ b/kernel/time/timekeeping.h @@ -10,7 +10,7 @@ extern ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq, extern int timekeeping_valid_for_hres(void); extern u64 timekeeping_max_deferment(void); -extern int timekeeping_inject_offset(struct timespec *ts); +extern void timekeeping_warp_clock(void); extern int timekeeping_suspend(void); extern void timekeeping_resume(void); From patchwork Thu Oct 19 11:14:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 116367 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp367775qgn; Thu, 19 Oct 2017 04:17:29 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SSk1Alx4hQYQMN8B/HE1MFlhtEkCJPLhGBb2/yCXcCSnSKABQBb4UV000uuSCFprpHh4av X-Received: by 10.101.70.15 with SMTP id v15mr1082398pgq.446.1508411849546; Thu, 19 Oct 2017 04:17:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508411849; cv=none; d=google.com; s=arc-20160816; b=Dv8c8DQCQUx8rXSjOc0LUCxNGNb5TELPI2Ff2wfb4hENXJYfQsjRE2I6bh5+w6IQzl 70FbYvvB77KQicID+qYvos1vXKnw5Qdy0lMgpk0Pgw4IcbBLvDWcQkLFCgYgrR3k0XVY Hc89t7GY9GZFKbTS+Pe+28T+OQzv8u/UFyX60TYDMRC4yFMGkEf1uUd+4gIkFCqDOLqf AyRC22WV3U50DB2liTuMx21nE/ebgIOdVg9s/GszplNLZE1Hxi9y8HX43CBQlHJTOknk M3vX4DUig7+dqpzriI+c9EApbGviF/wQw7EVJK/IKZFNArEnzkiYJfsyI6gjMz5KxfLM XrOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=25onzy553y6NlG983n71p+yJTZdQigBBWtDVMPo06ZI=; b=VtC82ki6kG4TDdFTG4atLs/zvXGH5BKDNqlMlWHD0I4XMZMEQVdYBp+O94oNryW9sZ 5mcUlPtEj4DVFLmcjZVS3f7oHkH5KH5eH/zi6wKxnvzzFEWKxGiK0M/WeYcjHa5dKkhX Q+inF61dXAd81tW9CqEmfknmlARlSFvPmuBpAbn9NxJTK9M89ExggzPYwZG7boG9bdpa HgelvMcA1OFTrcDzDMMwQ+ONQNdboiJlpXVaPrmkEEtYb/AJdYEC1l5EFvN6Z6sSu5iF ZN7dQU54DcYlbm1hD3rnyEiEaTE1YtKeg4L4tgZDVMPaqBu8JSWhXBAXCv9nUqh5Rq4S d8Dg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a8si6455089plm.56.2017.10.19.04.17.29; Thu, 19 Oct 2017 04:17:29 -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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752892AbdJSLR0 (ORCPT + 27 others); Thu, 19 Oct 2017 07:17:26 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:56510 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752665AbdJSLPP (ORCPT ); Thu, 19 Oct 2017 07:15:15 -0400 Received: from wuerfel.lan ([46.223.139.202]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.145]) with ESMTPA (Nemesis) id 0M6VWV-1dHJJr1WYd-00ySAw; Thu, 19 Oct 2017 13:15:04 +0200 From: Arnd Bergmann To: Thomas Gleixner , y2038@lists.linaro.org Cc: Deepa Dinamani , John Stultz , Stephen Boyd , linux-kernel@vger.kernel.org, Arnd Bergmann Subject: [PATCH 2/7] timekeeping: use timespec64 in timekeeping_inject_offset Date: Thu, 19 Oct 2017 13:14:45 +0200 Message-Id: <20171019111450.3702205-2-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171019111450.3702205-1-arnd@arndb.de> References: <20171019111450.3702205-1-arnd@arndb.de> X-Provags-ID: V03:K0:etNaBGhm7jK0EbzSXBfBcWKIq2MuBMddr01Vp/kBb8qczcStqmF CLkASm8w5iR1MaHTeBNIti7YFJfUdniXmqND4RKsoGOnJmoRw+JUy4gov5BIk4yF4r6Gghe LKqIQhir60oA7eZB7lmj9NCDPONxV8OcqdC+hWgIOXrhnpTEOLAQbeAyfbA3H6LVsBTKVlp VZZKCqg15OKrFT9eekHhQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:Cmoel+Y/j2A=:DS2kCNI/HjDl8To7mYpK/k X32Iuvf00y85sn+vTNSXte9TZT48sJLEVqvRBvJ1kQ0FowsBu9ni0kBhCRF315+psGHzRFQS1 h/nnNcPDQVdNhbdrrC1G/nC504mKRvUxgvVx7McNJUf0ypMmBsMvY8kdI6VCc5o+Una0Z+k/+ r1lcvYTPPbGhwwnWKM5fEussIS5VlFLNFL9l8knHqBktWJKoQm4vBTM/YO0/EzxDXaAsaPFB6 W0K07RuO9MQJr2mRM/JPEV9aTKy1o/POO1kmMvERRTPASzemakhTzDQpsBYj7wHNLdI8/xDre 5LbRprC3Ifejx0EWXC+G/Lo7O78msbh3A/qSpjH6sPWW5tH/CLnSJCuw1jN/JhYOXfUTIWCsX szTyJ25dJ/QWHHC4eiyODbi0yp70888H5vvUc97W0M3u6y9qdaKucN1MQUyA1D+JpOwvYDZzl dUU/9QoplXF5RTdLwpmsnf3JYwQTT9Gc3pGrLokwzeTRTWbTi0hdZuWQdus2NRlsU7wmQU0Sx 1wCCfYqFpoge16IJIxgkXronDq6y9CFhhBgH2pPUvey4aodYn2C/JZU+n1g9Mp8BodWolbu5a fdQ4uYpbtiRPMn7WSeVthtumQwbjRNLCYVP5BFOuApL0Lp0u4DwX2pq60nXRM3BbG8xQfNTUV vwizSC6QKOiY/9e5udtP5xYfKL0r6zhU87XkbiTD+bU7u59GExacj2OCGRwNpjplAJ1zY3KnP MrlwWfGt47knbemtYGHH70MzvCKAziE/VaLyiA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As part of changing all the timekeeping code to use 64-bit time_t consistently, this removes the uses of timeval and timespec as much as possible from do_adjtimex() and timekeeping_inject_offset(). The timeval_inject_offset_valid() and timespec_inject_offset_valid() just complicate this, so I'm folding them into the respective callers. This leaves the actual 'struct timex' definition, which is part of the user-space ABI and should be dealt with separately when we have agreed on the ABI change. Signed-off-by: Arnd Bergmann --- kernel/time/timekeeping.c | 72 ++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 47 deletions(-) -- 2.9.0 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c index 679dbfbea419..66f6fe5ea97a 100644 --- a/kernel/time/timekeeping.c +++ b/kernel/time/timekeeping.c @@ -1300,65 +1300,37 @@ int do_settimeofday64(const struct timespec64 *ts) } EXPORT_SYMBOL(do_settimeofday64); -/* - * Validates if a timespec/timeval used to inject a time offset is valid. - * Offsets can be postive or negative. The value of the timeval/timespec - * is the sum of its fields, but *NOTE*: the field tv_usec/tv_nsec must - * always be non-negative. - */ -static inline bool timeval_inject_offset_valid(const struct timeval *tv) -{ - /* We don't check the tv_sec as it can be positive or negative */ - - /* Can't have more microseconds then a second */ - if (tv->tv_usec < 0 || tv->tv_usec >= USEC_PER_SEC) - return false; - return true; -} - -static inline bool timespec_inject_offset_valid(const struct timespec *ts) -{ - /* We don't check the tv_sec as it can be positive or negative */ - - /* Can't have more nanoseconds then a second */ - if (ts->tv_nsec < 0 || ts->tv_nsec >= NSEC_PER_SEC) - return false; - return true; -} - /** * timekeeping_inject_offset - Adds or subtracts from the current time. * @tv: pointer to the timespec variable containing the offset * * Adds or subtracts an offset value from the current time. */ -static int timekeeping_inject_offset(struct timespec *ts) +static int timekeeping_inject_offset(struct timespec64 *ts) { struct timekeeper *tk = &tk_core.timekeeper; unsigned long flags; - struct timespec64 ts64, tmp; + struct timespec64 tmp; int ret = 0; - if (!timespec_inject_offset_valid(ts)) + if (ts->tv_nsec < 0 || ts->tv_nsec >= NSEC_PER_SEC) return -EINVAL; - ts64 = timespec_to_timespec64(*ts); - raw_spin_lock_irqsave(&timekeeper_lock, flags); write_seqcount_begin(&tk_core.seq); timekeeping_forward_now(tk); /* Make sure the proposed value is valid */ - tmp = timespec64_add(tk_xtime(tk), ts64); - if (timespec64_compare(&tk->wall_to_monotonic, &ts64) > 0 || + tmp = timespec64_add(tk_xtime(tk), *ts); + if (timespec64_compare(&tk->wall_to_monotonic, ts) > 0 || !timespec64_valid_strict(&tmp)) { ret = -EINVAL; goto error; } - tk_xtime_add(tk, &ts64); - tk_set_wall_to_mono(tk, timespec64_sub(tk->wall_to_monotonic, ts64)); + tk_xtime_add(tk, ts); + tk_set_wall_to_mono(tk, timespec64_sub(tk->wall_to_monotonic, *ts)); error: /* even if we error out, we forwarded the time, so call update */ timekeeping_update(tk, TK_CLEAR_NTP | TK_MIRROR | TK_CLOCK_WAS_SET); @@ -1397,7 +1369,7 @@ int persistent_clock_is_local; void timekeeping_warp_clock(void) { if (sys_tz.tz_minuteswest != 0) { - struct timespec adjust; + struct timespec64 adjust; persistent_clock_is_local = 1; adjust.tv_sec = sys_tz.tz_minuteswest * 60; @@ -2349,9 +2321,9 @@ ktime_t ktime_get_update_offsets_now(unsigned int *cwsseq, ktime_t *offs_real, } /** - * ntp_validate_timex - Ensures the timex is ok for use in do_adjtimex + * timekeeping_validate_timex - Ensures the timex is ok for use in do_adjtimex */ -static int ntp_validate_timex(struct timex *txc) +static int timekeeping_validate_timex(struct timex *txc) { if (txc->modes & ADJ_ADJTIME) { /* singleshot must not be used with any other mode bits */ @@ -2379,16 +2351,22 @@ static int ntp_validate_timex(struct timex *txc) if (!capable(CAP_SYS_TIME)) return -EPERM; - if (txc->modes & ADJ_NANO) { - struct timespec ts; + /* + * Validate if a timespec/timeval used to inject a time + * offset is valid. Offsets can be postive or negative, so + * we don't check tv_sec. The value of the timeval/timespec + * is the sum of its fields,but *NOTE*: + * The field tv_usec/tv_nsec must always be non-negative and + * we can't have more nanoseconds/microseconds than a second. + */ + if (txc->time.tv_usec < 0) + return -EINVAL; - ts.tv_sec = txc->time.tv_sec; - ts.tv_nsec = txc->time.tv_usec; - if (!timespec_inject_offset_valid(&ts)) + if (txc->modes & ADJ_NANO) { + if (txc->time.tv_usec >= NSEC_PER_SEC) return -EINVAL; - } else { - if (!timeval_inject_offset_valid(&txc->time)) + if (txc->time.tv_usec >= USEC_PER_SEC) return -EINVAL; } } @@ -2420,12 +2398,12 @@ int do_adjtimex(struct timex *txc) int ret; /* Validate the data before disabling interrupts */ - ret = ntp_validate_timex(txc); + ret = timekeeping_validate_timex(txc); if (ret) return ret; if (txc->modes & ADJ_SETOFFSET) { - struct timespec delta; + struct timespec64 delta; delta.tv_sec = txc->time.tv_sec; delta.tv_nsec = txc->time.tv_usec; if (!(txc->modes & ADJ_NANO)) From patchwork Thu Oct 19 11:14:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 116362 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp365822qgn; Thu, 19 Oct 2017 04:15:21 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RiGLfAhBxEvtuAb0ImAe3J6yafonY/k2OQs6Ynd9rTV/WqJh4Bt/2Hh7gW7JHOef6UYsIH X-Received: by 10.98.36.135 with SMTP id k7mr1175680pfk.63.1508411721276; Thu, 19 Oct 2017 04:15:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508411721; cv=none; d=google.com; s=arc-20160816; b=z4o8bQbKcUW1MIjNCvWl9TpKSEO63VIBV2z+ISHkTyMo6xRvhuVuPb4a1O7uN3mn3H LPDQJUES8M7bjA3Db5fqn+o+J/eNFTzrtnSksrPR02AsWyRfKUk+yMqLWpKuVT1JgSsw CE+R/l+hS0rvJmrAHWcGoi9Nd0rMm5p7molgU3Mssp/I2k27gJoEM44/tLHwsuEcpkP1 zPcaXkfdPD/6YGMb01zFlK7oJw3BoNWcMrARsgkv308uRuKjfU5ZZ2a5oEbq0+iTyNSg f0qapaHDJUs5K41Q92GwWGR9ms8qjVvsSJ0VZzuZPI7W2exmd+2YImA8zmgrp9SFQ+HV S4rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=AsSy0Xygrvna68+Inq63g9D34WXdFS21hJWzi610Rv8=; b=XcGd/dF/MFZywACMXVmDRErNxdB+HQlJs0dORa50NnAgSl4+l3m6SAQeICAERrrJG5 uf6bMILETHqkwdx6simevyN4EjniR1h3xCdGoJ7dCuFKK3DUoDynl85i1e7m2LE/1GMT 4VLb7hilyPy3ULuRLPCJlIO/xc0tDFwphjxdu/ZpfUtTsC/XNJcsvRVxdOyXj1eVBPmL qRu+wsw7w905I89r25AkRWg5OrC82pBwgi8+/XHUHt5q2EkrUxgr1Y1rjAbGkp6RGdIO xtAmk4s8Xw/e/SFEuf+FQl1vOJgJ4esiTWWB0aIuDRhZRGCIOIu3WFmicDG4S2fDbqbE fGMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m3si2657345pgs.564.2017.10.19.04.15.20; Thu, 19 Oct 2017 04:15:21 -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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752785AbdJSLPS (ORCPT + 27 others); Thu, 19 Oct 2017 07:15:18 -0400 Received: from mout.kundenserver.de ([217.72.192.73]:55573 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752462AbdJSLPP (ORCPT ); Thu, 19 Oct 2017 07:15:15 -0400 Received: from wuerfel.lan ([46.223.139.202]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.145]) with ESMTPA (Nemesis) id 0MYvOV-1dk5YR2z2J-00VkBq; Thu, 19 Oct 2017 13:15:04 +0200 From: Arnd Bergmann To: Thomas Gleixner , y2038@lists.linaro.org Cc: Deepa Dinamani , John Stultz , Stephen Boyd , linux-kernel@vger.kernel.org, Arnd Bergmann Subject: [PATCH 3/7] time: remove unused functions Date: Thu, 19 Oct 2017 13:14:46 +0200 Message-Id: <20171019111450.3702205-3-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171019111450.3702205-1-arnd@arndb.de> References: <20171019111450.3702205-1-arnd@arndb.de> X-Provags-ID: V03:K0:AmvLWk+bOiolk6+Idvd+bwr7w12IAsdVMbDGgwbjTBO4oNCJVaj 8apFE92AHXnJRT6/GxJWCY03nDIfWkZonbCvcbMXs5prNHFEUJuFQH9ytiLcLjPSAZlZW2R 9tGA3RIzxWpnv27b9ELLse1eyeMahIY2E2gKLoD/ydseKlCtKGaDz0Gf/rKAZlUJhF7PoZk USJEQOWAfnq1yVnamSEFg== X-UI-Out-Filterresults: notjunk:1; V01:K0:Gl6I8tFFY8Q=:guvzrRiutNKqFvAVsGT+a+ 4+PChk5dGlOn0p7WRdyoQ1ICWGfq/F2OWITekCn6RcxixL35XBXPzhbQY8afEL/Kwt+3dWKHf n1gjrm6rhNTCof+AB5+RcBB/2PPWc3DPiC0na/pYlCq37jVaP/dfJfx6ODxlXGK1FI601XZK5 pQQVOp5FuHAwqFkO/ZXNTEXCMgbWpycqbl02vMwhrc5idWdre/YEFq0P/DbMMOLD5GsxVHEmi Tt1Lb9JDa6ZBLo5z5NLykUeTnQhfqHJnrPTGE+I61kAjUPKMO1QNyFyaH1WkRF9YGcFT2kUBT 9zQq9BNmvjffe3J2pQXAYFUZOcR3X7MR73iawMLVtmEnvGs9IWTCpMyP8sWU0M2HdFeKA9OkB rQaixVD8Ga7WacKMxgmNCdmPjDcvgr7NoxWLDtb5aL0eGt01fWa7ddvAnQqEVhf+y4LpGfOvX jxUBTFY9rDKQLo7EtjRNT43AMwaCZufpGdhhic6qr9B4UrNCZbTWhR06ggewOKne2FfDA6gp+ w9jDLykILOtVAi3gwSGa43WQwlwabs4ijVAA/dRtIGnzBqUWEBR2vfbot6P7EoNVQ6fp1QHlg DHPibDpztZeIJ8et70mY77xiBqNk2WBh1EMV6f+evQRyunR6MyRhxs49SZs1qwaauNXYXKrra 3oEKiWlFhU6XiBaiCrgnyIERzTpg9vTARVZ8OfXS8806NrjWM6zT0UfvMcyQ8x5t5goqqqUJZ u9Cgwgk4tzRFv7wvqmicwZuXCGGVgUF0UVJh0g== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The (slow but) ongoing work on conversion from timespec to timespec64 has led some timespec based helper functions to become unused. No new code should use them, so we can remove the functions entirely. I'm planning to obsolete additional interfaces next and remove more of these. Signed-off-by: Arnd Bergmann --- include/linux/time.h | 18 ------------------ include/linux/time64.h | 28 ---------------------------- kernel/time/time.c | 18 ------------------ 3 files changed, 64 deletions(-) -- 2.9.0 diff --git a/include/linux/time.h b/include/linux/time.h index c0fbad08448f..0e8a80918484 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -39,15 +39,6 @@ static inline int timespec_compare(const struct timespec *lhs, const struct time return lhs->tv_nsec - rhs->tv_nsec; } -static inline int timeval_compare(const struct timeval *lhs, const struct timeval *rhs) -{ - if (lhs->tv_sec < rhs->tv_sec) - return -1; - if (lhs->tv_sec > rhs->tv_sec) - return 1; - return lhs->tv_usec - rhs->tv_usec; -} - extern time64_t mktime64(const unsigned int year, const unsigned int mon, const unsigned int day, const unsigned int hour, const unsigned int min, const unsigned int sec); @@ -65,15 +56,6 @@ static inline unsigned long mktime(const unsigned int year, extern void set_normalized_timespec(struct timespec *ts, time_t sec, s64 nsec); -/* - * timespec_add_safe assumes both values are positive and checks - * for overflow. It will return TIME_T_MAX if the reutrn would be - * smaller then either of the arguments. - */ -extern struct timespec timespec_add_safe(const struct timespec lhs, - const struct timespec rhs); - - static inline struct timespec timespec_add(struct timespec lhs, struct timespec rhs) { diff --git a/include/linux/time64.h b/include/linux/time64.h index 980c71b3001a..402b595c76d2 100644 --- a/include/linux/time64.h +++ b/include/linux/time64.h @@ -53,16 +53,6 @@ static inline struct timespec64 timespec_to_timespec64(const struct timespec ts) return ts; } -static inline struct itimerspec itimerspec64_to_itimerspec(struct itimerspec64 *its64) -{ - return *its64; -} - -static inline struct itimerspec64 itimerspec_to_itimerspec64(struct itimerspec *its) -{ - return *its; -} - # define timespec64_equal timespec_equal # define timespec64_compare timespec_compare # define set_normalized_timespec64 set_normalized_timespec @@ -94,24 +84,6 @@ static inline struct timespec64 timespec_to_timespec64(const struct timespec ts) return ret; } -static inline struct itimerspec itimerspec64_to_itimerspec(struct itimerspec64 *its64) -{ - struct itimerspec ret; - - ret.it_interval = timespec64_to_timespec(its64->it_interval); - ret.it_value = timespec64_to_timespec(its64->it_value); - return ret; -} - -static inline struct itimerspec64 itimerspec_to_itimerspec64(struct itimerspec *its) -{ - struct itimerspec64 ret; - - ret.it_interval = timespec_to_timespec64(its->it_interval); - ret.it_value = timespec_to_timespec64(its->it_value); - return ret; -} - static inline int timespec64_equal(const struct timespec64 *a, const struct timespec64 *b) { diff --git a/kernel/time/time.c b/kernel/time/time.c index 04684e294f00..947fb614c78f 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -819,24 +819,6 @@ unsigned long nsecs_to_jiffies(u64 n) EXPORT_SYMBOL_GPL(nsecs_to_jiffies); /* - * Add two timespec values and do a safety check for overflow. - * It's assumed that both values are valid (>= 0) - */ -struct timespec timespec_add_safe(const struct timespec lhs, - const struct timespec rhs) -{ - struct timespec res; - - set_normalized_timespec(&res, lhs.tv_sec + rhs.tv_sec, - lhs.tv_nsec + rhs.tv_nsec); - - if (res.tv_sec < lhs.tv_sec || res.tv_sec < rhs.tv_sec) - res.tv_sec = TIME_T_MAX; - - return res; -} - -/* * Add two timespec64 values and do a safety check for overflow. * It's assumed that both values are valid (>= 0). * And, each timespec64 is in normalized form. From patchwork Thu Oct 19 11:14:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 116363 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp366108qgn; Thu, 19 Oct 2017 04:15:41 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QYrKTmVSknirb6KjPfFmI4l9NnYfNaJ8Sm0irW+MouFePRtuPtINOV+HGbZLalqMk3anIg X-Received: by 10.84.142.129 with SMTP id 1mr1228007plx.427.1508411741338; Thu, 19 Oct 2017 04:15:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508411741; cv=none; d=google.com; s=arc-20160816; b=qtIiOTztEPPzVmn3rlnrvKDgj7wSzPlyglicOKDOxb/8Cp4FYMLXbx2YPyBvK8qc+P Yrw7S50GyJE+mpCtY0FZ0GnMTzT1XpEdVfzBeDYMrHxrSF6npSy2URLiLABI5zqmNLWv omLIi2QWmS1hfvWlqtgw1Dpx7OuhEl4vAO+FLLonmYOtadCKz6Ek4ZvyCjgsefRjzZ8e mhP+bj7R1toKThKBIie7rSU33f0qa1NrDP4s3jIugWp9mbPcUcD4ArPfgQC4f8rMW5iQ F2giuAZpy/7X6HV2/DnNF/5CCbpRuS8bDXtwEkD/+ZjMUtPttEe/RTBdy1eOmKv1/dof ejfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=cMfQwBQEjNKFjx7x71CRy8biAwPmYPZRFs9j12C4J88=; b=XETTlG8By3QndKoIySGKkWhjAE+wo5r45BjN3AlbhkndnOwHiVJggH/1/H4CmgIIwB qREbI7ylHOtyZGc5kkWRHqX6HLCP8T7z+8h5eqFMW8j1k7Mn7OZ5wR7w8M4eZHF+IN0W E5s5oG2SpeGTF7PHqPsh6gVsc12fFSzoIX/P+VbLluu+sc5C2VdEPlV+G/PLY022YnTJ V1/pkbbsW+Q409Fi5gRNOVqdEUG0py3Jjfpmyxq/X6HgvstEw9nfs9h571Kw1Pb4zUfu 4QIz+mNs8v/lw5AhPxD87CLH9MGD2wgTj/RZQ+QxHvflYHK9MirSFQsH+m7esEMT2EV9 fcsw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j21si9149400pfe.34.2017.10.19.04.15.40; Thu, 19 Oct 2017 04:15:41 -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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752813AbdJSLPj (ORCPT + 27 others); Thu, 19 Oct 2017 07:15:39 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:60729 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752673AbdJSLPQ (ORCPT ); Thu, 19 Oct 2017 07:15:16 -0400 Received: from wuerfel.lan ([46.223.139.202]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.145]) with ESMTPA (Nemesis) id 0MfZE3-1dqe4Q0EXb-00P7QM; Thu, 19 Oct 2017 13:15:05 +0200 From: Arnd Bergmann To: Thomas Gleixner , y2038@lists.linaro.org Cc: Deepa Dinamani , John Stultz , Stephen Boyd , linux-kernel@vger.kernel.org, Arnd Bergmann Subject: [PATCH 4/7] time: move time_t based interfaces to time32.h Date: Thu, 19 Oct 2017 13:14:47 +0200 Message-Id: <20171019111450.3702205-4-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171019111450.3702205-1-arnd@arndb.de> References: <20171019111450.3702205-1-arnd@arndb.de> X-Provags-ID: V03:K0:zwWjmTn4TnGOlWPZ51DOgnI1g2uTmYOGtKGurjKVCBQjIHuGOp9 JAlLTvOUrQyEkpi53nGfuRAAxuulYH4rGiUgL6POKoaws0up55R56i4Y7cQ+VeVu5LdfR/m 5oMcvWUgpxQq4NtElKQLdvsn3YsV5fVVvTxOs8b3oeJOJJEIgzm52GjHn8rg9u9FThSO2N5 DuGNI7YUL8VsGqT7e6DGg== X-UI-Out-Filterresults: notjunk:1; V01:K0:ELTG6XIk3oM=:QAQEa1tAtkpL3zi1s7Or86 z/sdsx72LUydLZ91TtS6EZja/3S3rhZoWQn3599TD1XcKnOS4sX25SuE5yOtg8dXYyBw5ySS5 0ZfKGKJ88gZh8CnI2pH3hjwybBhQsVAPCpUOH8tb+Pf+qrFAtBHLOu5NUi+YFrTppM4Qtf0lm TaZdohjezxsLrRmqmINyZ6JBkhrf0U9CZ+q6cxdfALU3n86PpaNuH0KMNPpSQWyPf/6t1wd7Q J495Z5hUuVSiW1XCJc28Wnj802alyf5hGvpHXNrwzteFA7CJsSRM7bTTlvL/1jdPN2d4URzK2 RRBYJFHP7NOtcqTS8th58q7hbUeufJy9U/x6wC/NouWqh7dOxp7IS4nI6MSnDjkwMyKQCVtfY gPfnZc2LUnTMAA8XXlGW5avzWFkvzYr85TYgF8EE95D1kqR0ramTBzXOofi/hrdbm8+hXVq10 Z3mgcKhgdE+coHJM99hc72DdbgnSmiyr4rbiVdA/3NRR6m/4LLQHnY4fCAuYAjAaGqPR0zW5p fJhlxGsYncANYth3pWWwCTiFXgf5MBQJXYl/ApsZQ2+RiheicLxx54JXcld6yANi29HohyCCc WGG6eSrl6KNf/02owfoyCkwhlj0M6f7hEd1NOW8EQEDokcxzenxaP/vMzjz1D43DQ85UgofEP fKsGH2wDhgFr9hgtuh9zIPyaN/JJ2DDebQ9o4CGel0VoY1DqN/TFHKinbppdB/4AxCvbUvpmX W/rgQpVLyqWJjbUz8qkEjl2MHG9W4K0mSRTXIA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Interfaces based on 'struct timespec' or 'struct timeval' should no longer be used for new code, which can use either ktime_t or 'struct timespec64' instead. To make this a little clearer, this moves the various helpers into a new time32.h header. For the moment, this gets included by the normal time.h, but we may be able to separate it entirely when most users of time32.h are gone. Individual helpers in the new file can get removed once they become unused in the future. Since the contents of time32.h look a lot like what's in time64.h, I'm reordering them during the move to make them more similar, and to allow a follow-up patch to redirect the 'timespec' based functions to thei 'timespec64' based counterparts on 64-bit architectures later. Signed-off-by: Arnd Bergmann --- include/linux/time.h | 163 +-------------------------------------------- include/linux/time32.h | 174 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+), 162 deletions(-) create mode 100644 include/linux/time32.h -- 2.9.0 diff --git a/include/linux/time.h b/include/linux/time.h index 0e8a80918484..c375f54a678d 100644 --- a/include/linux/time.h +++ b/include/linux/time.h @@ -17,105 +17,10 @@ int get_itimerspec64(struct itimerspec64 *it, int put_itimerspec64(const struct itimerspec64 *it, struct itimerspec __user *uit); -#define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1) - -static inline int timespec_equal(const struct timespec *a, - const struct timespec *b) -{ - return (a->tv_sec == b->tv_sec) && (a->tv_nsec == b->tv_nsec); -} - -/* - * lhs < rhs: return <0 - * lhs == rhs: return 0 - * lhs > rhs: return >0 - */ -static inline int timespec_compare(const struct timespec *lhs, const struct timespec *rhs) -{ - if (lhs->tv_sec < rhs->tv_sec) - return -1; - if (lhs->tv_sec > rhs->tv_sec) - return 1; - return lhs->tv_nsec - rhs->tv_nsec; -} - extern time64_t mktime64(const unsigned int year, const unsigned int mon, const unsigned int day, const unsigned int hour, const unsigned int min, const unsigned int sec); -/** - * Deprecated. Use mktime64(). - */ -static inline unsigned long mktime(const unsigned int year, - const unsigned int mon, const unsigned int day, - const unsigned int hour, const unsigned int min, - const unsigned int sec) -{ - return mktime64(year, mon, day, hour, min, sec); -} - -extern void set_normalized_timespec(struct timespec *ts, time_t sec, s64 nsec); - -static inline struct timespec timespec_add(struct timespec lhs, - struct timespec rhs) -{ - struct timespec ts_delta; - set_normalized_timespec(&ts_delta, lhs.tv_sec + rhs.tv_sec, - lhs.tv_nsec + rhs.tv_nsec); - return ts_delta; -} - -/* - * sub = lhs - rhs, in normalized form - */ -static inline struct timespec timespec_sub(struct timespec lhs, - struct timespec rhs) -{ - struct timespec ts_delta; - set_normalized_timespec(&ts_delta, lhs.tv_sec - rhs.tv_sec, - lhs.tv_nsec - rhs.tv_nsec); - return ts_delta; -} - -/* - * Returns true if the timespec is norm, false if denorm: - */ -static inline bool timespec_valid(const struct timespec *ts) -{ - /* Dates before 1970 are bogus */ - if (ts->tv_sec < 0) - return false; - /* Can't have more nanoseconds then a second */ - if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC) - return false; - return true; -} - -static inline bool timespec_valid_strict(const struct timespec *ts) -{ - if (!timespec_valid(ts)) - return false; - /* Disallow values that could overflow ktime_t */ - if ((unsigned long long)ts->tv_sec >= KTIME_SEC_MAX) - return false; - return true; -} - -static inline bool timeval_valid(const struct timeval *tv) -{ - /* Dates before 1970 are bogus */ - if (tv->tv_sec < 0) - return false; - - /* Can't have more microseconds then a second */ - if (tv->tv_usec < 0 || tv->tv_usec >= USEC_PER_SEC) - return false; - - return true; -} - -extern struct timespec timespec_trunc(struct timespec t, unsigned gran); - /* Some architectures do not supply their own clocksource. * This is mainly the case in architectures that get their * inter-tick times by reading the counter on their interval @@ -164,73 +69,7 @@ struct tm { void time64_to_tm(time64_t totalsecs, int offset, struct tm *result); -/** - * time_to_tm - converts the calendar time to local broken-down time - * - * @totalsecs the number of seconds elapsed since 00:00:00 on January 1, 1970, - * Coordinated Universal Time (UTC). - * @offset offset seconds adding to totalsecs. - * @result pointer to struct tm variable to receive broken-down time - */ -static inline void time_to_tm(time_t totalsecs, int offset, struct tm *result) -{ - time64_to_tm(totalsecs, offset, result); -} - -/** - * timespec_to_ns - Convert timespec to nanoseconds - * @ts: pointer to the timespec variable to be converted - * - * Returns the scalar nanosecond representation of the timespec - * parameter. - */ -static inline s64 timespec_to_ns(const struct timespec *ts) -{ - return ((s64) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec; -} - -/** - * timeval_to_ns - Convert timeval to nanoseconds - * @ts: pointer to the timeval variable to be converted - * - * Returns the scalar nanosecond representation of the timeval - * parameter. - */ -static inline s64 timeval_to_ns(const struct timeval *tv) -{ - return ((s64) tv->tv_sec * NSEC_PER_SEC) + - tv->tv_usec * NSEC_PER_USEC; -} - -/** - * ns_to_timespec - Convert nanoseconds to timespec - * @nsec: the nanoseconds value to be converted - * - * Returns the timespec representation of the nsec parameter. - */ -extern struct timespec ns_to_timespec(const s64 nsec); - -/** - * ns_to_timeval - Convert nanoseconds to timeval - * @nsec: the nanoseconds value to be converted - * - * Returns the timeval representation of the nsec parameter. - */ -extern struct timeval ns_to_timeval(const s64 nsec); - -/** - * timespec_add_ns - Adds nanoseconds to a timespec - * @a: pointer to timespec to be incremented - * @ns: unsigned nanoseconds value to be added - * - * This must always be inlined because its used from the x86-64 vdso, - * which cannot call other kernel functions. - */ -static __always_inline void timespec_add_ns(struct timespec *a, u64 ns) -{ - a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns); - a->tv_nsec = ns; -} +# include static inline bool itimerspec64_valid(const struct itimerspec64 *its) { diff --git a/include/linux/time32.h b/include/linux/time32.h new file mode 100644 index 000000000000..6a00a309d095 --- /dev/null +++ b/include/linux/time32.h @@ -0,0 +1,174 @@ +#ifndef _LINUX_TIME32_H +#define _LINUX_TIME32_H +/* + * These are all interfaces based on the old time_t definition + * that overflows in 2038 on 32-bit architectures. New code + * should use the replacements based on time64_t and timespec64. + * + * Any interfaces in here that become unused as we migrate + * code to time64_t should get removed. + */ + +#include + +#define TIME_T_MAX (time_t)((1UL << ((sizeof(time_t) << 3) - 1)) - 1) + +static inline int timespec_equal(const struct timespec *a, + const struct timespec *b) +{ + return (a->tv_sec == b->tv_sec) && (a->tv_nsec == b->tv_nsec); +} + +/* + * lhs < rhs: return <0 + * lhs == rhs: return 0 + * lhs > rhs: return >0 + */ +static inline int timespec_compare(const struct timespec *lhs, const struct timespec *rhs) +{ + if (lhs->tv_sec < rhs->tv_sec) + return -1; + if (lhs->tv_sec > rhs->tv_sec) + return 1; + return lhs->tv_nsec - rhs->tv_nsec; +} + +extern void set_normalized_timespec(struct timespec *ts, time_t sec, s64 nsec); + +static inline struct timespec timespec_add(struct timespec lhs, + struct timespec rhs) +{ + struct timespec ts_delta; + set_normalized_timespec(&ts_delta, lhs.tv_sec + rhs.tv_sec, + lhs.tv_nsec + rhs.tv_nsec); + return ts_delta; +} + +/* + * sub = lhs - rhs, in normalized form + */ +static inline struct timespec timespec_sub(struct timespec lhs, + struct timespec rhs) +{ + struct timespec ts_delta; + set_normalized_timespec(&ts_delta, lhs.tv_sec - rhs.tv_sec, + lhs.tv_nsec - rhs.tv_nsec); + return ts_delta; +} + +/* + * Returns true if the timespec is norm, false if denorm: + */ +static inline bool timespec_valid(const struct timespec *ts) +{ + /* Dates before 1970 are bogus */ + if (ts->tv_sec < 0) + return false; + /* Can't have more nanoseconds then a second */ + if ((unsigned long)ts->tv_nsec >= NSEC_PER_SEC) + return false; + return true; +} + +static inline bool timespec_valid_strict(const struct timespec *ts) +{ + if (!timespec_valid(ts)) + return false; + /* Disallow values that could overflow ktime_t */ + if ((unsigned long long)ts->tv_sec >= KTIME_SEC_MAX) + return false; + return true; +} + +/** + * timespec_to_ns - Convert timespec to nanoseconds + * @ts: pointer to the timespec variable to be converted + * + * Returns the scalar nanosecond representation of the timespec + * parameter. + */ +static inline s64 timespec_to_ns(const struct timespec *ts) +{ + return ((s64) ts->tv_sec * NSEC_PER_SEC) + ts->tv_nsec; +} + +/** + * ns_to_timespec - Convert nanoseconds to timespec + * @nsec: the nanoseconds value to be converted + * + * Returns the timespec representation of the nsec parameter. + */ +extern struct timespec ns_to_timespec(const s64 nsec); + +/** + * timespec_add_ns - Adds nanoseconds to a timespec + * @a: pointer to timespec to be incremented + * @ns: unsigned nanoseconds value to be added + * + * This must always be inlined because its used from the x86-64 vdso, + * which cannot call other kernel functions. + */ +static __always_inline void timespec_add_ns(struct timespec *a, u64 ns) +{ + a->tv_sec += __iter_div_u64_rem(a->tv_nsec + ns, NSEC_PER_SEC, &ns); + a->tv_nsec = ns; +} + +/** + * time_to_tm - converts the calendar time to local broken-down time + * + * @totalsecs the number of seconds elapsed since 00:00:00 on January 1, 1970, + * Coordinated Universal Time (UTC). + * @offset offset seconds adding to totalsecs. + * @result pointer to struct tm variable to receive broken-down time + */ +static inline void time_to_tm(time_t totalsecs, int offset, struct tm *result) +{ + time64_to_tm(totalsecs, offset, result); +} + +static inline unsigned long mktime(const unsigned int year, + const unsigned int mon, const unsigned int day, + const unsigned int hour, const unsigned int min, + const unsigned int sec) +{ + return mktime64(year, mon, day, hour, min, sec); +} + +static inline bool timeval_valid(const struct timeval *tv) +{ + /* Dates before 1970 are bogus */ + if (tv->tv_sec < 0) + return false; + + /* Can't have more microseconds then a second */ + if (tv->tv_usec < 0 || tv->tv_usec >= USEC_PER_SEC) + return false; + + return true; +} + +extern struct timespec timespec_trunc(struct timespec t, unsigned gran); + +/** + * timeval_to_ns - Convert timeval to nanoseconds + * @ts: pointer to the timeval variable to be converted + * + * Returns the scalar nanosecond representation of the timeval + * parameter. + */ +static inline s64 timeval_to_ns(const struct timeval *tv) +{ + return ((s64) tv->tv_sec * NSEC_PER_SEC) + + tv->tv_usec * NSEC_PER_USEC; +} + +/** + * ns_to_timeval - Convert nanoseconds to timeval + * @nsec: the nanoseconds value to be converted + * + * Returns the timeval representation of the nsec parameter. + */ +extern struct timeval ns_to_timeval(const s64 nsec); + +#endif From patchwork Thu Oct 19 11:14:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 116364 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp366160qgn; Thu, 19 Oct 2017 04:15:44 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TNNixiQMHc08gJj0DZLuekBO077pT2cEWTTcARajRDfmGss2piqLY4JlNoewqBtgNHN6Gd X-Received: by 10.159.195.11 with SMTP id bd11mr1264681plb.58.1508411744366; Thu, 19 Oct 2017 04:15:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508411744; cv=none; d=google.com; s=arc-20160816; b=HBMda8EQEiy1GexDc19W3nw/OigrZDbV2XEAYnS8/h6JWb5wxSymy23qUZEoevfVVM wvUkYOmdG5OTwvRT7BzBAUb2L4xjv8FaawK3tTrHLpxDVQtTkHtRpvO1/cLKO12SL3WD UJVD7H2WETUiMcpQKmJzhc92NEaTKKLwXZZHG1Rcde9HmVC7EVBPvtt1E7rtJ96F8lPx KvEEb0uhNUPqsIP3EzqHR++N1T+9Nbmd7qf3DqLhM2YBn/uj4O8MOQm7Rh6YjbQ4BZ9W Gz7D1vYDPvYWZA8tbfIJWP4Q+9hh/cdEq/FvIpf5XeTCHkTj6FKBN94hZC9ofTIZsWt+ 5G/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=7UlgRd3zPDwAxwTxFTXAe1vI+DoXYEtLVcq12ztxzgQ=; b=PuLEEun1M+dJ0I3sVmPQ6ctSq7V03lyJxCsmcg0VS5bD2J27nmY6jUZndRWiCRwUTd dQVq1Q4b2/4KZus+bpgoJG4c2SqJAa90lhpQnRvYgrtNblwVS/4vfFtxh5B8EIrKfT32 kupJCzOkq2xzMewK5GhavLDvisJPpX01RHMSzL6IpnGRm4nAIdnk2x6S0eFVzkELM1ru 2JOD2gxqWUrJi6e/pq84WftLDzFksUaafmlvHuZmYRdDT8BGKMbjd/WhcwXnTs/mUF6S UsTtlxOWEO8Tc7o+CD4RoNQMwstxZTdFLTOxm4CbPzLGWy22ZnOSLjEn7SW6v224XVXM 7q3g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j21si9149400pfe.34.2017.10.19.04.15.44; Thu, 19 Oct 2017 04:15:44 -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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752847AbdJSLPm (ORCPT + 27 others); Thu, 19 Oct 2017 07:15:42 -0400 Received: from mout.kundenserver.de ([217.72.192.74]:54641 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752667AbdJSLPQ (ORCPT ); Thu, 19 Oct 2017 07:15:16 -0400 Received: from wuerfel.lan ([46.223.139.202]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.145]) with ESMTPA (Nemesis) id 0MV56z-1diQrM1ezV-00YVbk; Thu, 19 Oct 2017 13:15:05 +0200 From: Arnd Bergmann To: Thomas Gleixner , y2038@lists.linaro.org Cc: Deepa Dinamani , John Stultz , Stephen Boyd , linux-kernel@vger.kernel.org, Arnd Bergmann Subject: [PATCH 5/7] time: move time_t conversion helpers to time32.h Date: Thu, 19 Oct 2017 13:14:48 +0200 Message-Id: <20171019111450.3702205-5-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171019111450.3702205-1-arnd@arndb.de> References: <20171019111450.3702205-1-arnd@arndb.de> X-Provags-ID: V03:K0:kT1rwXjXXeXb5KgWjih/Tv41wDvemSaLa6fTOhKmzF4CR7+BegY mDJ4SPHNSVdCTtGa+cgfIuVLQXbqEoMsE5jkADBdwiOAhaz0QRRlgz0+/ulXmgJP3JfFm1s n9gtNlpOFAsNRar2QBFWXlGKLWH7VuDuIdKzxGvtcfm3zkp61FevZreT2vWp6I7aLI2E1Qv AlExqPBcyNAbttWdiWk2Q== X-UI-Out-Filterresults: notjunk:1; V01:K0:+T3tjKJ/whE=:nK9eCGWZxPrStqKjm3BKV2 ku6xlzPPShwyn2Rd8Dlen5HWInFy6FZEc7uISxiFrZzmwozse+d7r/zcu/5ZglziAteJHgY5w g8IZBXM27A6wBB9ffU1bCSUOLFa/+d2OOH63euabx+oB5KDBrZEBgZNJSwzcInTCVp/aIKR1N qzxy1mmG0NddPpddFEjIsk0B6iFP8whnuAC2FDUnM8n+InxPCQ288l9vszBnYHpzcNEupOxh4 VylQBFPOKP4Ovog70ViHEusrhmfaoZEQnFtqQQcRGApN+IGG5+gjJzl2T9ZpxImLai/0F0OU4 i63M9apUak89itJ9Cty/O38X0aJUQYrDKfWWgYG9oq8w8YJsvePu3Fj0axKbbM+mCUpBFR8/q DaTC/MT1rDKbk0CTiUbpHeJHA1zAAJC4x3AvnXUCorx8N5Qix6V00rO0r/g7qDkAquv5S3rGv UXwGWJdzpw8hk15LekQLONW426coh22go2jAvPqER2cXrO6qbKeiHkd7S7i9Q6KtyKk9YvGel Z2KAlwo0Cq4AhVWEQuLaDJGy5Bn4rUGjlhrnmbdgSoTsAM9Aq3nwFa2XxrIS1DN3C7X6DlTg/ EGewSSLbq9Rx2278Y4Bh+ShDThvAYj49nNmbr0AlVHROp8dSVBWlBclzV9lXgP2nFHgyrMsKa zfvv6md7jiBTsydJ5WYeglNk6LXKMUSF8AGndV/k+sIIU56spEce/ApasdRRq+Vx7GuLtL5MO +sh3of+wALgVYBzv01Ev4lLorRinveX/Pyr8lQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Arnd Bergmann --- include/linux/time32.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/time64.h | 50 +------------------------------------------------- kernel/time/time.c | 5 +++-- 3 files changed, 49 insertions(+), 51 deletions(-) -- 2.9.0 diff --git a/include/linux/time32.h b/include/linux/time32.h index 6a00a309d095..305f81dd5429 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) { @@ -114,6 +157,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 402b595c76d2..ec1888cf5378 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 947fb614c78f..fe60ebd301cf 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 From patchwork Thu Oct 19 11:14:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 116365 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp366553qgn; Thu, 19 Oct 2017 04:16:08 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SzcEe/VjRDNjtvQdV6iwOm8ZNOoaXdfPqM8AO3Ty2HVun9exh+Pi5ddQV4Ay3kWWcwYjL1 X-Received: by 10.99.115.79 with SMTP id d15mr1045247pgn.343.1508411768468; Thu, 19 Oct 2017 04:16:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508411768; cv=none; d=google.com; s=arc-20160816; b=wCMIloCIGC7+Vzve+LYQwtKQ6ZTHuGZ/axI0T+LWmUPPfqLWtsIdstWOQ8WlNnKcbh piYFl9LCSnlX64C5Vyxho0hIFNgG2u6OcB8987I921+laYv8a9o5hFFLi7PXBk7aES24 qON7JquXJS2Mf/FW2IIp6bVo1zWfEf6y8kJSbPf73gWBBA+wJtjlw6Z4hINUevI1Hy6B daXoYLL5zXkpp6fi4c10kLYilBd+lCCGEmxM6kJiqtIsbjCshX7SPc0y8dbaSiUNsEiQ dsvQCuNOGX6lSniKhGmYXnq0YlIBZRhWd7uzyO4dwVOJb5LkbfVUGk2UbLpUe7vfbiyv TrZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=3aJ+z96OK247rU9zFo25foUPgT/3iD4I25pJOjTM700=; b=n80OcHrK1UosFXzqp849XwpZWc8PZa3KNQqJthFxw/j+kCXd0AKDAhLU1WO1rvWK0R 4F1DlJDTUod1XN0zLfsiLatoQ7/xUduwPpnRbwbd10uPoeadUnxB/KBwVRpFxNZxccoq z22QiESeBx6c1A6flbn5FmYH0kVrpuvaxVMVoFEU8C1SQMA2H5nplv+w46GGg6pXKwAu TOaUG0/rSLqpMuqw3gDKrN1smjpRA3BA6IPunE7Icj0DaB/0X/6v+xqv6c3b/lCbuZw9 h/7oN5rBt6egFS8Vzo8+OUGrrdSqFlT0YJMB9RiotypfHZELTjzb6+9A32y/wyJsnxxK HhYw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v63si8364594pgv.8.2017.10.19.04.16.08; Thu, 19 Oct 2017 04:16:08 -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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752829AbdJSLPl (ORCPT + 27 others); Thu, 19 Oct 2017 07:15:41 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:60344 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752670AbdJSLPQ (ORCPT ); Thu, 19 Oct 2017 07:15:16 -0400 Received: from wuerfel.lan ([46.223.139.202]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.145]) with ESMTPA (Nemesis) id 0MPGl6-1e9YdN360G-004Q2v; Thu, 19 Oct 2017 13:15:05 +0200 From: Arnd Bergmann To: Thomas Gleixner , y2038@lists.linaro.org Cc: Deepa Dinamani , John Stultz , Stephen Boyd , linux-kernel@vger.kernel.org, Arnd Bergmann Subject: [PATCH 6/7] time: move old timekeeping interfaces to timekeeping32.h Date: Thu, 19 Oct 2017 13:14:49 +0200 Message-Id: <20171019111450.3702205-6-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171019111450.3702205-1-arnd@arndb.de> References: <20171019111450.3702205-1-arnd@arndb.de> X-Provags-ID: V03:K0:YhrK+s8YhUz+uEhGbtYywjvGkhH3OMbycTSCP2+7p0o37kxR+eN Zqse/FWftFRi2mQ67vY5bw2yXoegNtexzefUwM5HQVnimNKHDVjuUR10fi+6EtdbeO3GnJD InxJYzEhd++by6zfPk33NMsbeds180o7zAvdXFV9TY1GmWwyXl8aoMJ306HhucL8/XKDcuV 9fVOV+pCc9Nji8SPCXPAA== X-UI-Out-Filterresults: notjunk:1; V01:K0:38FiVUI6FxQ=:4zv2KbQI+y851Y19XZ/DJm nPzYhCgKXLlAXEAA7hspfkmda83kuIz92Xq4ZgHp+TfTytfpZ0XOEZTpzHIyMKWwV/z2Srsnu x27f1EG14mEgPl0Y2Xmrh1QWQu8j1CUM/YdZ7EMltKV6QozxGc/Hf6nEO//gDMj+AylRo2lVW KbFo23Nz5FpixlK0PAtHBQsxFwqH9gzwn/VxMSSKOc72zwmevpBvZXs74vmmtXjCbDPmmq+bf mw7f+KgrPj3JhlWw8jVxoeAI7phdspHFBNeA4lFZKkbT6C4qGvLYZ+twkvnGcLZiD7QMbmLUy HPSQBUUn+MwUAlc2Rfd2sihb85LVNwwL4iU//+9HRhgtew3kPcF6vWUsnt8PYQMistRYTFWB0 /vfFeaz8AdEQGiz9edoPnide4SWh0Dwo24KgohGNMFlrpqAN+AzWQ566S71pypMRme60lJiOC GprGJkNiz4pIHy92inGkIK4tcVmrMEySGXbhJIxhAWXbtRKN9ZoMDrBtB1l8XSKIxFd0Kl964 TkhXGhgULS9xyncK0Mei2Eo0g9vbMz0hxHWVqn3/WKEAOQlj79Iopx4eJg0D5INP83dQgvruX ha6mEKSHHyG2W/7qPZfa7RR19AaHUHCujeVvyspfIIAnI5VYkMECRvZ7YTBJYqvQNCE16QUyi ME3z1JJxINb+LllU0/0e1LcnmjOXwbpF5Gs7GStcqGkg0Q+7XzGoTozie+RKFNv6X8MxSsRCN ai/UC3T2Gcq7+wuu/GTCdSDtjIZ4oybhEJc8VA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The interfaces based on 'struct timespec' and 'unsigned long' seconds are no longer recommended for new code, and we are trying to migrate to ktime_t based interfaces and other y2038-safe variants. This moves all the legacy interfaces from linux/timekeeping.h into a new timekeeping32.h to better document this. Signed-off-by: Arnd Bergmann --- include/linux/ktime.h | 1 + include/linux/timekeeping.h | 137 +------------------------------------- include/linux/timekeeping32.h | 151 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+), 135 deletions(-) create mode 100644 include/linux/timekeeping32.h -- 2.9.0 diff --git a/include/linux/ktime.h b/include/linux/ktime.h index 0c8bd45c8206..5b9fddbaac41 100644 --- a/include/linux/ktime.h +++ b/include/linux/ktime.h @@ -270,5 +270,6 @@ static inline ktime_t ms_to_ktime(u64 ms) } # include +# include #endif diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h index eb98cbdbb323..2263698edeaf 100644 --- a/include/linux/timekeeping.h +++ b/include/linux/timekeeping.h @@ -15,27 +15,16 @@ extern void xtime_update(unsigned long ticks); /* * Get and set timeofday */ -extern void do_gettimeofday(struct timeval *tv); extern int do_settimeofday64(const struct timespec64 *ts); extern int do_sys_settimeofday64(const struct timespec64 *tv, const struct timezone *tz); /* * Kernel time accessors */ -unsigned long get_seconds(void); struct timespec64 current_kernel_time64(void); -/* does not take xtime_lock */ -struct timespec __current_kernel_time(void); - -static inline struct timespec current_kernel_time(void) -{ - struct timespec64 now = current_kernel_time64(); - - return timespec64_to_timespec(now); -} /* - * timespec based interfaces + * timespec64 based interfaces */ struct timespec64 get_monotonic_coarse64(void); extern void getrawmonotonic64(struct timespec64 *ts); @@ -47,116 +36,6 @@ extern int __getnstimeofday64(struct timespec64 *tv); extern void getnstimeofday64(struct timespec64 *tv); extern void getboottime64(struct timespec64 *ts); -#if BITS_PER_LONG == 64 -/** - * Deprecated. Use do_settimeofday64(). - */ -static inline int do_settimeofday(const struct timespec *ts) -{ - return do_settimeofday64(ts); -} - -static inline int __getnstimeofday(struct timespec *ts) -{ - return __getnstimeofday64(ts); -} - -static inline void getnstimeofday(struct timespec *ts) -{ - getnstimeofday64(ts); -} - -static inline void ktime_get_ts(struct timespec *ts) -{ - ktime_get_ts64(ts); -} - -static inline void ktime_get_real_ts(struct timespec *ts) -{ - getnstimeofday64(ts); -} - -static inline void getrawmonotonic(struct timespec *ts) -{ - getrawmonotonic64(ts); -} - -static inline struct timespec get_monotonic_coarse(void) -{ - return get_monotonic_coarse64(); -} - -static inline void getboottime(struct timespec *ts) -{ - return getboottime64(ts); -} -#else -/** - * Deprecated. Use do_settimeofday64(). - */ -static inline int do_settimeofday(const struct timespec *ts) -{ - struct timespec64 ts64; - - ts64 = timespec_to_timespec64(*ts); - return do_settimeofday64(&ts64); -} - -static inline int __getnstimeofday(struct timespec *ts) -{ - struct timespec64 ts64; - int ret = __getnstimeofday64(&ts64); - - *ts = timespec64_to_timespec(ts64); - return ret; -} - -static inline void getnstimeofday(struct timespec *ts) -{ - struct timespec64 ts64; - - getnstimeofday64(&ts64); - *ts = timespec64_to_timespec(ts64); -} - -static inline void ktime_get_ts(struct timespec *ts) -{ - struct timespec64 ts64; - - ktime_get_ts64(&ts64); - *ts = timespec64_to_timespec(ts64); -} - -static inline void ktime_get_real_ts(struct timespec *ts) -{ - struct timespec64 ts64; - - getnstimeofday64(&ts64); - *ts = timespec64_to_timespec(ts64); -} - -static inline void getrawmonotonic(struct timespec *ts) -{ - struct timespec64 ts64; - - getrawmonotonic64(&ts64); - *ts = timespec64_to_timespec(ts64); -} - -static inline struct timespec get_monotonic_coarse(void) -{ - return timespec64_to_timespec(get_monotonic_coarse64()); -} - -static inline void getboottime(struct timespec *ts) -{ - struct timespec64 ts64; - - getboottime64(&ts64); - *ts = timespec64_to_timespec(ts64); -} -#endif - #define ktime_get_real_ts64(ts) getnstimeofday64(ts) /* @@ -242,23 +121,13 @@ extern u64 ktime_get_boot_fast_ns(void); extern u64 ktime_get_real_fast_ns(void); /* - * Timespec interfaces utilizing the ktime based ones + * timespec64 interfaces utilizing the ktime based ones */ -static inline void get_monotonic_boottime(struct timespec *ts) -{ - *ts = ktime_to_timespec(ktime_get_boottime()); -} - static inline void get_monotonic_boottime64(struct timespec64 *ts) { *ts = ktime_to_timespec64(ktime_get_boottime()); } -static inline void timekeeping_clocktai(struct timespec *ts) -{ - *ts = ktime_to_timespec(ktime_get_clocktai()); -} - static inline void timekeeping_clocktai64(struct timespec64 *ts) { *ts = ktime_to_timespec64(ktime_get_clocktai()); @@ -341,10 +210,8 @@ extern void ktime_get_snapshot(struct system_time_snapshot *systime_snapshot); */ extern int persistent_clock_is_local; -extern void read_persistent_clock(struct timespec *ts); extern void read_persistent_clock64(struct timespec64 *ts); extern void read_boot_clock64(struct timespec64 *ts); -extern int update_persistent_clock(struct timespec now); extern int update_persistent_clock64(struct timespec64 now); diff --git a/include/linux/timekeeping32.h b/include/linux/timekeeping32.h new file mode 100644 index 000000000000..af4114d5dc17 --- /dev/null +++ b/include/linux/timekeeping32.h @@ -0,0 +1,151 @@ +#ifndef _LINUX_TIMEKEEPING32_H +#define _LINUX_TIMEKEEPING32_H +/* + * These interfaces are all based on the old timespec type + * and should get replaced with the timespec64 based versions + * over time so we can remove the file here. + */ + +extern void do_gettimeofday(struct timeval *tv); +unsigned long get_seconds(void); + +/* does not take xtime_lock */ +struct timespec __current_kernel_time(void); + +static inline struct timespec current_kernel_time(void) +{ + struct timespec64 now = current_kernel_time64(); + + return timespec64_to_timespec(now); +} + +#if BITS_PER_LONG == 64 +/** + * Deprecated. Use do_settimeofday64(). + */ +static inline int do_settimeofday(const struct timespec *ts) +{ + return do_settimeofday64(ts); +} + +static inline int __getnstimeofday(struct timespec *ts) +{ + return __getnstimeofday64(ts); +} + +static inline void getnstimeofday(struct timespec *ts) +{ + getnstimeofday64(ts); +} + +static inline void ktime_get_ts(struct timespec *ts) +{ + ktime_get_ts64(ts); +} + +static inline void ktime_get_real_ts(struct timespec *ts) +{ + getnstimeofday64(ts); +} + +static inline void getrawmonotonic(struct timespec *ts) +{ + getrawmonotonic64(ts); +} + +static inline struct timespec get_monotonic_coarse(void) +{ + return get_monotonic_coarse64(); +} + +static inline void getboottime(struct timespec *ts) +{ + return getboottime64(ts); +} +#else +/** + * Deprecated. Use do_settimeofday64(). + */ +static inline int do_settimeofday(const struct timespec *ts) +{ + struct timespec64 ts64; + + ts64 = timespec_to_timespec64(*ts); + return do_settimeofday64(&ts64); +} + +static inline int __getnstimeofday(struct timespec *ts) +{ + struct timespec64 ts64; + int ret = __getnstimeofday64(&ts64); + + *ts = timespec64_to_timespec(ts64); + return ret; +} + +static inline void getnstimeofday(struct timespec *ts) +{ + struct timespec64 ts64; + + getnstimeofday64(&ts64); + *ts = timespec64_to_timespec(ts64); +} + +static inline void ktime_get_ts(struct timespec *ts) +{ + struct timespec64 ts64; + + ktime_get_ts64(&ts64); + *ts = timespec64_to_timespec(ts64); +} + +static inline void ktime_get_real_ts(struct timespec *ts) +{ + struct timespec64 ts64; + + getnstimeofday64(&ts64); + *ts = timespec64_to_timespec(ts64); +} + +static inline void getrawmonotonic(struct timespec *ts) +{ + struct timespec64 ts64; + + getrawmonotonic64(&ts64); + *ts = timespec64_to_timespec(ts64); +} + +static inline struct timespec get_monotonic_coarse(void) +{ + return timespec64_to_timespec(get_monotonic_coarse64()); +} + +static inline void getboottime(struct timespec *ts) +{ + struct timespec64 ts64; + + getboottime64(&ts64); + *ts = timespec64_to_timespec(ts64); +} +#endif + +/* + * Timespec interfaces utilizing the ktime based ones + */ +static inline void get_monotonic_boottime(struct timespec *ts) +{ + *ts = ktime_to_timespec(ktime_get_boottime()); +} + +static inline void timekeeping_clocktai(struct timespec *ts) +{ + *ts = ktime_to_timespec(ktime_get_clocktai()); +} + +/* + * Persistent clock related interfaces + */ +extern void read_persistent_clock(struct timespec *ts); +extern int update_persistent_clock(struct timespec now); + +#endif From patchwork Thu Oct 19 11:14:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 116366 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp367280qgn; Thu, 19 Oct 2017 04:17:00 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QQP4LtixzmlrG+UDl7FaS8Srdrzw2dGtW5fVVYwvCvs+ojvaBExN5A0IScATMya5OQ5j8T X-Received: by 10.98.200.138 with SMTP id i10mr1195643pfk.222.1508411820108; Thu, 19 Oct 2017 04:17:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508411820; cv=none; d=google.com; s=arc-20160816; b=TY8rV3IkeHDd7grFxunZ20boHW6NTPLH7aF0W8z60Pp5zEIywOknC9pdEGZYu392LM ra2o3glFOCFwZ0+O2cWUQfe6Dr2p5W54h5NKs4mAAlF5WdUp69EeL/Z0RjkBCTC89cB7 cXwlRWe6bBjhdn5yrqmJxAvsm6GaW+GkL1IZWeYTMg+GFXK/HA3SpbzJPb2tDDDBJ697 VyXuh78eQWgmy7lN6hhjxo1C/Odw6hr3USKMWvlZaVzwX5bGiG0yKgLL40XHocD4udoC ljjgft3ZyqYb4P7rZB8vXBdcH/EBUAnyo3AnliTOdpDFd6wxYTL7n1r7AzUtdW/ZId8f D+tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=1/IOOkOEWUBWUNMmHxV3XifOBsNCTYLIZJUMwbhjrCM=; b=mcbRMBVVQ5Zzfsnuc2ihgqfdM897XvDF6r7Nb6wLqkBHXziEIe9dHlPd7XmRMs70na 6z/zosj9Yr0MVkw176Bea2hMj4Mvbkn5UnoO1PG9KQY3A8xEKEgsYBW6BEgjyCzzLnC3 sR1yiunxGgbZMK7BO2J5HikoB99JVUu/etmwChUIlvF/GyKp+9Fc6a/UAVA5p7spDwMt 0GrtS0MgYBiGiJDldRK5KHRajzZh6P0JFrLM9+aCrSNUbMM5yGE5pkLrCwOHjzcZuk36 xR7axe3ezU5L6XtSAVeQJ4opY4dlEpkYml1xMcOrTBquM6CJULPdWyS6VKebVq531fU1 kCJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t12si2139490plm.122.2017.10.19.04.16.59; Thu, 19 Oct 2017 04:17:00 -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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752794AbdJSLPi (ORCPT + 27 others); Thu, 19 Oct 2017 07:15:38 -0400 Received: from mout.kundenserver.de ([217.72.192.75]:58342 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752674AbdJSLPQ (ORCPT ); Thu, 19 Oct 2017 07:15:16 -0400 Received: from wuerfel.lan ([46.223.139.202]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.145]) with ESMTPA (Nemesis) id 0LtWRI-1d6cD00NMq-010wTB; Thu, 19 Oct 2017 13:15:06 +0200 From: Arnd Bergmann To: Thomas Gleixner , y2038@lists.linaro.org Cc: Deepa Dinamani , John Stultz , Stephen Boyd , linux-kernel@vger.kernel.org, Arnd Bergmann Subject: [PATCH 7/7] time: remove timespec64 hack Date: Thu, 19 Oct 2017 13:14:50 +0200 Message-Id: <20171019111450.3702205-7-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171019111450.3702205-1-arnd@arndb.de> References: <20171019111450.3702205-1-arnd@arndb.de> X-Provags-ID: V03:K0:5EY9rbrnP1hu1GWdqezLZ0SK0qbu8caFKXlQI5fy/66AoZaNdH4 6Cjf33RLKiSRLz06y7enrT04937VsJJAEY6DS9/ieBNm+CPexzJUz+1YNvjGdVwBhYBY0CN Q2OLay4g7RB13QJcF/Mj2S2MBbXsNp4vH0yP8I9LikOcUFxDvqzwORUTqApmYebED9OtWer /8FG8aZJpQ7mluE1Xh3ng== X-UI-Out-Filterresults: notjunk:1; V01:K0:G+/utopfuAk=:Gs/6RLpNeQry+mh/k6VxHr zB3uBg2Ol28Fv4HDgeLrLw9+lQC2DXbbCVhPLareUfuhmmDB8nZyf+8mDofA3JekoekCKxZVF frKfKCsONnF8inWYb57uQcm+TW/peMBjEerMYeP6f9XMGemvyKP6XP27MlkvUqycKlnVbBuWv u6Sf3Uxu01n/I9rQFHY7eHZrqZizZzAQefNjkYY5vBtiozjgUviS5rftmLQJAnmLA90Us2dKP /nbITXAr8a9eXeSZwUxyIgOmMYwPbqOfHu9/2d0ndEmVPANLIGAK2uV+xzlh+QIy5hTwjHCYT 70V+JD/jk03Rtiu3YxeXSXEjczLb6i/vMiWrvWDXqjxVyePXAQXGSbBQ04roYWmQroRlTDrJ3 J9WIgKx71HF52OrseFU+NG78tDmxfZ+wyJf3Nh5ElTyeOjS3f2GTBkcqLZFFeYRo+r20LJQJE KRB/XFEKACGqjW3Bm5j6b9fP1EzEEH+GGWeIC9wxIW0kwK+x9sHtQ5av5EbfB7EXJQCdDT6H5 5ZRvQNjekbGmG3/l8m7yTfBxA6MF4XEBIiuWZlPh/ILS6+adnAKcltuioSrdyaqZ09iccWDFk 5+aau1rkqlZy9vS3j0qYYfOaDj1dRTUFDtWfafD8Vzg4bwq9310edO38CFKSxJyBr+iT7SPsf 7PbrG2wLVelTzXCSpwM9I+j3m8Vk7vMY44kzpvuYVTCbUdEaIjY20FlIca5PKkGydZ0NE+p0d r8zY6+5nCGkw9DYJ14wj9j1wJkQ90v9yJBhxPQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This may be a somewhat controversial change, changing 64-bit architectures to use the same 'struct timespec64' definition that 32-bit architectures have, and removing a micro-optimization that tries to minimize the difference between timespec and timespec64. Starting with gcc-5, the compiler can completely optimize away the timespec_to_timespec64 and timespec64_to_timespec functions on 64-bit architectures. With older compilers, we introduce a couple of extra copies of local variables, but those are easily avoided by using the timespec64 based interfaces consistently, as we do in most of the important code paths already. The main upside of removing the hack is that printing the tv_sec field of a timespec64 structure can now use the %lld format string on all architectures without a cast to time64_t. Without this patch, the field is a 'long' type and would have to be printed using %ld on 64-bit architectures. Signed-off-by: Arnd Bergmann --- include/linux/time32.h | 18 +++-------------- include/linux/time64.h | 7 ------- include/linux/timekeeping32.h | 45 ------------------------------------------- kernel/time/time.c | 2 -- 4 files changed, 3 insertions(+), 69 deletions(-) -- 2.9.0 diff --git a/include/linux/time32.h b/include/linux/time32.h index 305f81dd5429..bd53e66bab1f 100644 --- a/include/linux/time32.h +++ b/include/linux/time32.h @@ -18,25 +18,14 @@ /* timespec64 is defined as timespec here */ static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64) { - return ts64; + return *(const struct timespec *)&ts64; } static inline struct timespec64 timespec_to_timespec64(const struct timespec ts) { - return ts; + return *(const struct timespec64 *)&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) { @@ -55,6 +44,7 @@ static inline struct timespec64 timespec_to_timespec64(const struct timespec ts) ret.tv_nsec = ts.tv_nsec; return ret; } +#endif static inline int timespec_equal(const struct timespec *a, const struct timespec *b) @@ -157,8 +147,6 @@ 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 ec1888cf5378..b6b5650d8fab 100644 --- a/include/linux/time64.h +++ b/include/linux/time64.h @@ -7,11 +7,6 @@ typedef __s64 time64_t; typedef __u64 timeu64_t; -#if __BITS_PER_LONG == 64 -/* this trick allows us to optimize out timespec64_to_timespec */ -# define timespec64 timespec -#define itimerspec64 itimerspec -#else struct timespec64 { time64_t tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ @@ -22,8 +17,6 @@ struct itimerspec64 { struct timespec64 it_value; }; -#endif - /* Parameters used to convert the timespec values: */ #define MSEC_PER_SEC 1000L #define USEC_PER_MSEC 1000L diff --git a/include/linux/timekeeping32.h b/include/linux/timekeeping32.h index af4114d5dc17..f707ddb4dad7 100644 --- a/include/linux/timekeeping32.h +++ b/include/linux/timekeeping32.h @@ -19,50 +19,6 @@ static inline struct timespec current_kernel_time(void) return timespec64_to_timespec(now); } -#if BITS_PER_LONG == 64 -/** - * Deprecated. Use do_settimeofday64(). - */ -static inline int do_settimeofday(const struct timespec *ts) -{ - return do_settimeofday64(ts); -} - -static inline int __getnstimeofday(struct timespec *ts) -{ - return __getnstimeofday64(ts); -} - -static inline void getnstimeofday(struct timespec *ts) -{ - getnstimeofday64(ts); -} - -static inline void ktime_get_ts(struct timespec *ts) -{ - ktime_get_ts64(ts); -} - -static inline void ktime_get_real_ts(struct timespec *ts) -{ - getnstimeofday64(ts); -} - -static inline void getrawmonotonic(struct timespec *ts) -{ - getrawmonotonic64(ts); -} - -static inline struct timespec get_monotonic_coarse(void) -{ - return get_monotonic_coarse64(); -} - -static inline void getboottime(struct timespec *ts) -{ - return getboottime64(ts); -} -#else /** * Deprecated. Use do_settimeofday64(). */ @@ -127,7 +83,6 @@ static inline void getboottime(struct timespec *ts) getboottime64(&ts64); *ts = timespec64_to_timespec(ts64); } -#endif /* * Timespec interfaces utilizing the ktime based ones diff --git a/kernel/time/time.c b/kernel/time/time.c index fe60ebd301cf..4ad81b020c3e 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -407,7 +407,6 @@ 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 * @@ -468,7 +467,6 @@ struct timespec ns_to_timespec(const s64 nsec) return ts; } EXPORT_SYMBOL(ns_to_timespec); -#endif /** * ns_to_timeval - Convert nanoseconds to timeval