timekeeping: cleanups
Subsystems (4)
cover timekeeping: cleanups
Here are some older cleanups that for one reason or another never made it into the mainline kernel so far:
- the arch/sh series was posted a couple of times by both Baolin and me, with no reply from the sh maintainers
- the vfs patch initially got some opposition when the new interfaces were not documented right, but that is done now.
- The remaining three patches simply remove functions that have been obsoleted a while ago and have lost their last callers now.
I'm adding these into my y2038 tree now, so they make it into linux-next, planning to send a pull request to Thomas for the tip tree afterwards.
Arnd
Arnd Bergmann (8):
sh: dreamcast: rtc: push down rtc class ops into driver
sh: sh03: rtc: push down rtc class ops into driver
sh: remove unused rtc_sh_get/set_time infrastructure
sh: remove board_time_init() callback
timekeeping: remove unused {read,update}_persistent_clock
timekeeping: remove timespec_add/timespec_del
vfs: replace current_kernel_time64 with ktime equivalent
timekeeping: remove obsolete time accessors
Documentation/sh/new-machine.txt | 8 -- arch/sh/boards/mach-dreamcast/Makefile | 4 +- arch/sh/boards/mach-dreamcast/rtc.c | 39 +++++++--- arch/sh/boards/mach-dreamcast/setup.c | 1 - arch/sh/boards/mach-sh03/Makefile | 3 +- arch/sh/boards/mach-sh03/rtc.c | 51 ++++++++----- arch/sh/boards/mach-sh03/setup.c | 9 --- arch/sh/boards/of-generic.c | 8 -- arch/sh/configs/dreamcast_defconfig | 2 + arch/sh/configs/sh03_defconfig | 2 + arch/sh/include/asm/rtc.h | 3 - arch/sh/include/mach-dreamcast/mach/sysasic.h | 1 - arch/sh/kernel/time.c | 74 +------------------ fs/inode.c | 4 +- include/linux/time32.h | 25 ------- include/linux/timekeeping.h | 14 ---- include/linux/timekeeping32.h | 15 ---- kernel/time/ntp.c | 10 +-- kernel/time/time.c | 36 --------- kernel/time/timekeeping.c | 12 +-- 20 files changed, 73 insertions(+), 248 deletions(-)
Signature · 1 line
2.18.0
PATCH 1/8 sh: dreamcast: rtc: push down rtc class ops into driver
The dreamcast RTC support has an extra level of indirection to provide either the old read_persistent_clock/update_persistent_clock interface or the rtc-generic device for hctosys/systohc.
Both do the same thing here, so we can do away with the abstraction and simply enable the RTC core code to take care of it.
--- arch/sh/boards/mach-dreamcast/Makefile | 4 +- arch/sh/boards/mach-dreamcast/rtc.c | 39 +++++++++++++------ arch/sh/boards/mach-dreamcast/setup.c | 1 - arch/sh/configs/dreamcast_defconfig | 2 + arch/sh/include/mach-dreamcast/mach/sysasic.h | 1 - 5 files changed, 31 insertions(+), 16 deletions(-)
arch/sh/boards/mach-dreamcast/Makefile +2 -2
@@ -2,5 +2,5 @@ # Makefile for the Sega Dreamcast specific parts of the kernel # -obj-y := setup.o irq.o rtc.o - +obj-y := setup.o irq.o +obj-$(CONFIG_RTC_DRV_GENERIC) += rtc.o
arch/sh/boards/mach-dreamcast/rtc.c +27 -12
@@ -11,8 +11,9 @@*/ #include <linux/time.h> -#include <asm/rtc.h> -#include <asm/io.h> +#include <linux/rtc.h> +#include <linux/io.h> +#include <linux/platform_device.h> /* The AICA RTC has an Epoch of 1/1/1950, so we must subtract 20 years (in seconds) to get the standard Unix Epoch when getting the time, and add
@@ -30,9 +31,10 @@* * Grabs the current RTC seconds counter and adjusts it to the Unix Epoch. */ -static void aica_rtc_gettimeofday (struct timespec *ts) +static int aica_rtc_gettimeofday (struct device *dev,struct rtc_time *tm) {unsigned long val1, val2; +time64_t t; do { val1 = ((__raw_readl(AICA_RTC_SECS_H) & 0xffff) << 16) |
@@ -42,10 +44,12 @@ static void aica_rtc_gettimeofday(struct timespec *ts) (__raw_readl (AICA_RTC_SECS_L ) &0xffff ); }while (val1 != val2); - ts->tv_sec = val1 -TWENTY_YEARS ; +/* normalize to 1970..2106 time range */ + t = (u32)(val1 -TWENTY_YEARS ); -/* Can't get nanoseconds with just a seconds counter. */ - ts->tv_nsec =0 ; +rtc_time64_to_tm (t, tm); + +return 0 ; }/**
@@ -54,10 +58,11 @@ static void aica_rtc_gettimeofday(struct timespec *ts)* * Adjusts the given @tv to the AICA Epoch and sets the RTC seconds counter. */ -static int aica_rtc_settimeofday (const time_t secs) +static int aica_rtc_settimeofday (struct device *dev,struct rtc_time *tm) {unsigned long val1, val2; -unsigned long adj = secs +TWENTY_YEARS ; +time64_t secs =rtc_tm_to_time64 (tm); +u32 adj = secs +TWENTY_YEARS ; do { __raw_writel((adj & 0xffff0000) >> 16, AICA_RTC_SECS_H);
@@ -73,9 +78,19 @@ static int aica_rtc_settimeofday(const time_t secs)return 0 ; } -void aica_time_init (void ) +static const struct rtc_class_ops rtc_generic_ops = { + .read_time = aica_rtc_gettimeofday, + .set_time = aica_rtc_settimeofday, +}; + +static int __init aica_time_init (void ) { - rtc_sh_get_time = aica_rtc_gettimeofday; - rtc_sh_set_time = aica_rtc_settimeofday; -} +struct platform_device *pdev; + + pdev =platform_device_register_data (NULL ,"rtc-generic" ,-1 , + &rtc_generic_ops, +sizeof (rtc_generic_ops)); +return PTR_ERR_OR_ZERO (pdev); +} +arch_initcall (aica_time_init);
arch/sh/boards/mach-dreamcast/setup.c +0 -1
@@ -30,7 +30,6 @@static void __init dreamcast_setup (char **cmdline_p) { - board_time_init = aica_time_init; } static struct sh_machine_vector mv_dreamcast __initmv = {
arch/sh/configs/dreamcast_defconfig +2 -0
@@ -70,3 +70,5 @@ CONFIG_PROC_KCORE=y CONFIG_TMPFS=y CONFIG_HUGETLBFS=y # CONFIG_CRYPTO_ANSI_CPRNG is not set +CONFIG_RTC_CLASS=y +CONFIG_RTC_DRV_GENERIC=y
arch/sh/include/mach-dreamcast/mach/sysasic.h +0 -1
@@ -42,7 +42,6 @@/* arch/sh/boards/mach-dreamcast/irq.c */ extern int systemasic_irq_demux (int );extern void systemasic_irq_init (void ); -extern void aica_time_init (void );#endif /* __ASM_SH_DREAMCAST_SYSASIC_H */
Signature · 1 line
2.18.0
Re: [PATCH 1/8] sh: dreamcast: rtc: push down rtc class ops into driver
Quoted 3 lines · Arnd Bergmann
The dreamcast RTC support has an extra level of indirection to provide either the old read_persistent_clock/update_persistent_clock interface or the rtc-generic device for hctosys/systohc.
s/dreamcast/sh/ in the above sentence? Also repeated in the other patches.
Re: [PATCH 1/8] sh: dreamcast: rtc: push down rtc class ops into driver
Quoted 8 lines · Christoph Hellwig
Quoted 3 lines · Arnd Bergmann
The dreamcast RTC support has an extra level of indirection to provide either the old read_persistent_clock/update_persistent_clock interface or the rtc-generic device for hctosys/systohc.
s/dreamcast/sh/ in the above sentence? Also repeated in the other patches.
Right, I guess this is at least ambiguous. What I was trying to express here is that I'm taking the indirection out for dreamcast specifically.
In the other patches, I obviously copied it wrong. Fixed now in my branch, thanks for the review!
Arnd
PATCH 2/8 sh: sh03: rtc: push down rtc class ops into driver
In reply to Arnd BergmannThe dreamcast RTC support has an extra level of indirection to provide either the old read_persistent_clock/update_persistent_clock interface or the rtc-generic device for hctosys/systohc.
By removing the indirection and always using the RTC_CLASS interface, we can avoid the lossy double conversion between rtc_time and timespec, so we end up supporting the entire range of 'year' values, and clarifying the rtc_set_time callback.
I did not change the behavior of sh03_rtc_settimeofday(), which keeps just updating the seconds/minutes by calling set_rtc_mmss(), this could be improved if anyone cares. Also, the file should ideally be moved into drivers/rtc and not use rtc-generic.
--- arch/sh/boards/mach-sh03/Makefile | 3 +- arch/sh/boards/mach-sh03/rtc.c | 51 +++++++++++++++++++------------ arch/sh/boards/mach-sh03/setup.c | 9 ------ arch/sh/configs/sh03_defconfig | 2 ++ 4 files changed, 35 insertions(+), 30 deletions(-)
arch/sh/boards/mach-sh03/Makefile +2 -1
@@ -2,4 +2,5 @@ # Makefile for the Interface (CTP/PCI-SH03) specific parts of the kernel # -obj-y := setup.o rtc.o +obj-y := setup.o +obj-$(CONFIG_RTC_DRV_GENERIC) += rtc.o
arch/sh/boards/mach-sh03/rtc.c +31 -20
93 lines not on this page · raw message
arch/sh/boards/mach-sh03/setup.c +0 -9
@@ -22,14 +22,6 @@ static void __init init_sh03_IRQ(void)plat_irq_setup_pins (IRQ_MODE_IRQ ); } -/* arch/sh/boards/sh03/rtc.c */ -void sh03_time_init (void ); - -static void __init sh03_setup (char **cmdline_p) -{ - board_time_init = sh03_time_init; -} -static struct resource cf_ide_resources[] = { [0 ] = { .start =0x1f0 ,
@@ -101,6 +93,5 @@ device_initcall(sh03_devices_setup); static struct sh_machine_vector mv_sh03 __initmv = { .mv_name ="Interface (CTP/PCI-SH03)" , - .mv_setup = sh03_setup, .mv_init_irq = init_sh03_IRQ, };
arch/sh/configs/sh03_defconfig +2 -0
@@ -130,3 +130,5 @@ CONFIG_CRYPTO_SHA1=y CONFIG_CRYPTO_DEFLATE=y # CONFIG_CRYPTO_ANSI_CPRNG is not set CONFIG_CRC_CCITT=y +CONFIG_RTC_CLASS=y +CONFIG_RTC_DRV_GENERIC=y
Signature · 1 line
2.18.0
PATCH 3/8 sh: remove unused rtc_sh_get/set_time infrastructure
In reply to Arnd BergmannAll platforms are now converted to RTC drivers, so this has become obsolete. The board_time_init() callback still has one caller, but could otherwise also get killed.
This removes one more usage of the deprecated timespec structure, which overflows in y2038.
--- arch/sh/include/asm/rtc.h | 2 -- arch/sh/kernel/time.c | 69 --------------------------------------- 2 files changed, 71 deletions(-)
arch/sh/include/asm/rtc.h +0 -2
@@ -4,8 +4,6 @@void time_init (void );extern void (*board_time_init)(void ); -extern void (*rtc_sh_get_time)(struct timespec *); -extern int (*rtc_sh_set_time)(const time_t );#define RTC_CAP_4_DIGIT_YEAR (1 << 0)
arch/sh/kernel/time.c +0 -69
75 lines not on this page · raw message
Signature · 1 line
2.18.0
PATCH 4/8 sh: remove board_time_init() callback
In reply to Arnd BergmannThe only remaining user of board_time_init() is the of-generic machine, and that just calls the global timer_init() function. Calling that one has no effect on non-DT platforms, so we can simply call it unconditionally in place of board_time_init().
--- Documentation/sh/new-machine.txt | 8 -------- arch/sh/boards/of-generic.c | 8 -------- arch/sh/include/asm/rtc.h | 1 - arch/sh/kernel/time.c | 5 +---- 4 files changed, 1 insertion(+), 21 deletions(-)
Documentation/sh/new-machine.txt +0 -8
@@ -116,7 +116,6 @@ might look something like: * arch/sh/boards/vapor/setup.c - Setup code for imaginary board */ #include <linux/init.h> -#include <asm/rtc.h> /* for board_time_init() */ const char *get_system_type(void) {
@@ -132,13 +131,6 @@ int __init platform_setup(void) * this board. */ - /* - * Presume all FooTech boards have the same broken timer, - * and also presume that we've defined foo_timer_init to - * do something useful. - */ - board_time_init = foo_timer_init; - /* Start-up imaginary PCI ... */ /* And whatever else ... */
arch/sh/boards/of-generic.c +0 -8
@@ -117,18 +117,10 @@ static void __init sh_of_mem_reserve(void)early_init_fdt_scan_reserved_mem (); } -static void __init sh_of_time_init (void ) -{ -pr_info ("SH generic board support: scanning for clocksource devices\n" ); -timer_probe (); -} -static void __init sh_of_setup (char **cmdline_p) {struct device_node *root; - board_time_init = sh_of_time_init; - sh_mv.mv_name ="Unknown SH model" ; root =of_find_node_by_path ("/" );if (root) {
arch/sh/include/asm/rtc.h +0 -1
@@ -3,7 +3,6 @@#define _ASM_RTC_Hvoid time_init (void ); -extern void (*board_time_init)(void );#define RTC_CAP_4_DIGIT_YEAR (1 << 0)
arch/sh/kernel/time.c +1 -4
@@ -22,8 +22,6 @@#include <asm/clock.h> #include <asm/rtc.h> -void (*board_time_init)(void ); -static void __init sh_late_time_init (void ) {/*
@@ -41,8 +39,7 @@ static void __init sh_late_time_init(void)void __init time_init (void ) { -if (board_time_init) -board_time_init (); +timer_probe ();clk_init ();
Signature · 1 line
2.18.0
PATCH 5/8 timekeeping: remove unused {read,update}_persistent_clock
In reply to Arnd BergmannAfter arch/sh has removed the last reference to these functions, we can remove them completely and just rely on the 64-bit time_t based versions. This cleans up a rather ugly use of __weak functions.
--- include/linux/timekeeping32.h | 6 ------ kernel/time/ntp.c | 10 +--------- kernel/time/timekeeping.c | 12 ++---------- 3 files changed, 3 insertions(+), 25 deletions(-)
include/linux/timekeeping32.h +0 -6
@@ -52,10 +52,4 @@ static inline void getboottime(struct timespec *ts) *ts = timespec64_to_timespec(ts64); } -/* -* Persistent clock related interfaces -*/ -extern void read_persistent_clock (struct timespec *ts); -extern int update_persistent_clock (struct timespec now); -#endif
kernel/time/ntp.c +1 -9
@@ -555,17 +555,9 @@ static void sync_rtc_clock(void) }#ifdef CONFIG_GENERIC_CMOS_UPDATE -int __weak update_persistent_clock (struct timespec now) -{ -return -ENODEV ; -} -int __weak update_persistent_clock64 (struct timespec64 now64) { -struct timespec now; - - now =timespec64_to_timespec (now64); -return update_persistent_clock (now); +return -ENODEV ; }#endif
kernel/time/timekeeping.c +2 -10
@@ -1467,7 +1467,7 @@ u64 timekeeping_max_deferment(void) }/** -* read_persistent_clock - Return time from the persistent clock. +* read_persistent_clock64 - Return time from the persistent clock. * * Weak dummy function for arches that do not yet support it. * Reads the time from the battery backed persistent clock.
@@ -1475,20 +1475,12 @@ u64 timekeeping_max_deferment(void)* * XXX - Do be sure to remove it once all arches implement it. */ -void __weak read_persistent_clock (struct timespec *ts) +void __weak read_persistent_clock64 (struct timespec64 *ts) { ts->tv_sec =0 ; ts->tv_nsec =0 ; } -void __weak read_persistent_clock64 (struct timespec64 *ts64) -{ -struct timespec ts; - -read_persistent_clock (&ts); - *ts64 =timespec_to_timespec64 (ts); -} -/** * read_persistent_wall_and_boot_offset - Read persistent clock, and also offset * from the boot.
Signature · 1 line
2.18.0
Re: [PATCH 5/8] timekeeping: remove unused {read,update}_persistent_clock
Quoted 6 lines · Arnd Bergmann
After
arch/shhas removed the last reference to these functions, we can remove them completely and just rely on the 64-bittime_tbased versions. This cleans up a rather ugly use of__weakfunctions.
Quoted 6 lines
Signed-off-by Arnd Bergmann <[email protected]>--- include/linux/timekeeping32.h | 6 ------ kernel/time/ntp.c | 10 +--------- kernel/time/timekeeping.c | 12 ++---------- 3 files changed, 3 insertions(+), 25 deletions(-)
thanks
-john
PATCH 6/8 timekeeping: remove timespec_add/timespec_del
In reply to Arnd BergmannThe last users were removed a while ago since everyone moved to ktime_t, so we can remove the two unused interfaces for old timespec structures.
With those two gone, set_normalized_timespec() is also unused, so remove that as well.
--- include/linux/time32.h | 25 ------------------------- kernel/time/time.c | 36 ------------------------------------ 2 files changed, 61 deletions(-)
include/linux/time32.h +0 -25
@@ -96,31 +96,6 @@ static inline int timespec_compare(const struct timespec *lhs, const struct timereturn 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: */
kernel/time/time.c +0 -36
@@ -386,42 +386,6 @@ time64_t mktime64(const unsigned int year0, const unsigned int mon0, }EXPORT_SYMBOL (mktime64); -/** -* set_normalized_timespec - set timespec sec and nsec parts and normalize -* -* @ts: pointer to timespec variable to be set -* @sec: seconds to set -* @nsec: nanoseconds to set -* -* Set seconds and nanoseconds field of a timespec variable and -* normalize to the timespec storage format -* -* Note: The tv_nsec part is always in the range of -* 0 <= tv_nsec < NSEC_PER_SEC -* For negative values only the tv_sec field is negative ! -*/ -void set_normalized_timespec (struct timespec *ts,time_t sec,s64 nsec) -{ -while (nsec >=NSEC_PER_SEC ) { -/* -* The following asm() prevents the compiler from -* optimising this loop into a modulo operation. See -* also __iter_div_u64_rem() in include/linux/time.h -*/ - asm("" :"+rm" (nsec)); - nsec -=NSEC_PER_SEC ; - ++sec; - } -while (nsec <0 ) { - asm("" :"+rm" (nsec)); - nsec +=NSEC_PER_SEC ; - --sec; - } - ts->tv_sec = sec; - ts->tv_nsec = nsec; -} -EXPORT_SYMBOL (set_normalized_timespec); -/** * ns_to_timespec - Convert nanoseconds to timespec * @nsec: the nanoseconds value to be converted
Signature · 1 line
2.18.0
Re: [PATCH 6/8] timekeeping: remove timespec_add/timespec_del
Quoted 4 lines · Arnd Bergmann
The last users were removed a while ago since everyone moved to
ktime_t, so we can remove the two unused interfaces for old timespec structures.
Quoted 8 lines
With those two gone,
set_normalized_timespec()is also unused, so remove that as well.Signed-off-by Arnd Bergmann <[email protected]>--- include/linux/time32.h | 25 ------------------------- kernel/time/time.c | 36 ------------------------------------ 2 files changed, 61 deletions(-)
PATCH 7/8 vfs: replace current_kernel_time64 with ktime equivalent
In reply to Arnd Bergmanncurrent_time is the last remaining caller of current_kernel_time64(), which is a wrapper around ktime_get_coarse_real_ts64(). This calls the latter directly for consistency with the rest of the kernel that is moving to the ktime_get_ family of time accessors, as now documented in Documentation/core-api/timekeeping.rst.
An open questions is whether we may want to actually call the more accurate ktime_get_real_ts64() for file systems that save high-resolution timestamps in their on-disk format. This would add a small overhead to each update of the inode stamps but lead to inode timestamps to actually have a usable resolution better than one jiffy (1 to 10 milliseconds normally). Experiments on a variety of hardware platforms show a typical time of around 100 CPU cycles to read the cycle counter and calculate the accurate time from that. On old platforms without a cycle counter, this can be signiciantly higher, up to several microseconds to access a hardware clock, but those have become very rare by now.
I traced the original addition of the current_kernel_time() call to set the nanosecond fields back to linux-2.5.48, where Andi Kleen added a patch with subject "nanosecond stat timefields". Andi explains that the motivation was to introduce as little overhead as possible back then. At this time, reading the clock hardware was also more expensive when most architectures did not have a cycle counter.
One side effect of having more accurate inode timestamp would be having to write out the inode every time that mtime/ctime/atime get touched on most systems, whereas many file systems today only write it when the timestamps have changed, i.e. at most once per jiffy unless something else changes as well. That change would certainly be noticed in some workloads, which is enough reason to not do it without a good reason, regardless of the cost of reading the time.
One thing we could still consider however would be to round the timestamps from current_time() to multiples of NSEC_PER_JIFFY, e.g. full milliseconds rather than having six or seven meaningless but confusing digits at the end of the timestamp.
--- fs/inode.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
fs/inode.c +3 -1
@@ -2146,7 +2146,9 @@ EXPORT_SYMBOL(timespec64_trunc);*/ struct timespec64 current_time (struct inode *inode) { -struct timespec64 now =current_kernel_time64 (); +struct timespec64 now; + +ktime_get_coarse_real_ts64 (&now);if (unlikely (!inode->i_sb)) {WARN (1 ,"current_time() called with uninitialized super_block in the inode" );
Signature · 1 line
2.18.0
PATCH 8/8 timekeeping: remove obsolete time accessors
In reply to Arnd BergmannThere are no more remaining users of these deprecated wrappers, so let's remove them before new users have a chance to make it in.
See Documentation/core-api/timekeeping.rst for replacements when porting old drivers that contain calls to this function.
--- include/linux/timekeeping.h | 14 -------------- include/linux/timekeeping32.h | 9 --------- 2 files changed, 23 deletions(-)
include/linux/timekeeping.h +0 -14
@@ -262,18 +262,4 @@ void read_persistent_wall_and_boot_offset(struct timespec64 *wall_clock, struct timespec64 *boot_offset);extern int update_persistent_clock64 (struct timespec64 now); -/* -* deprecated aliases, don't use in new code -*/ -#define getnstimeofday64 (ts) ktime_get_real_ts64(ts) - -static inline struct timespec64 current_kernel_time64 (void ) -{ -struct timespec64 ts; - -ktime_get_coarse_real_ts64 (&ts); - -return ts; -} -#endif
include/linux/timekeeping32.h +0 -9
@@ -6,15 +6,6 @@* over time so we can remove the file here. */ -static inline void do_gettimeofday (struct timeval *tv) -{ -struct timespec64 now; - -ktime_get_real_ts64 (&now); - tv->tv_sec = now.tv_sec; - tv->tv_usec = now.tv_nsec/1000 ; -} -static inline unsigned long get_seconds (void ) {return ktime_get_real_seconds ();
Signature · 1 line
2.18.0
Re: [PATCH 8/8] timekeeping: remove obsolete time accessors
Quoted 4 lines · Arnd Bergmann
There are no more remaining users of these deprecated wrappers, so let's remove them before new users have a chance to make it in.
Quoted 8 lines
See
Documentation/core-api/timekeeping.rstfor replacements when porting old drivers that contain calls to this function.Signed-off-by Arnd Bergmann <[email protected]>--- include/linux/timekeeping.h | 14 -------------- include/linux/timekeeping32.h | 9 --------- 2 files changed, 23 deletions(-)