Message ID | 1520620971-9567-4-git-send-email-john.stultz@linaro.org |
---|---|
State | New |
Headers | show |
Series | Timekeeping queue for 4.17 | expand |
> +extern struct __kernel_old_timeval ns_to_kernel_old_timeval(const s64 nsec); Generally there's no need to mark arguments with arithmethic types as const, as they are never modified in the calling scope. > + * legacy timeval structure, only embedded in structures that > + * traditionally used 'timeval' to pass time intervals (not absolute > + * times). Do not add new users. If user space fails to compile > + * here, this is probably because it is not y2038 safe and needs to > + * be changed to use another interface. > + */ > +struct __kernel_old_timeval { > + __kernel_long_t tv_sec; /* seconds */ > + __kernel_long_t tv_usec; /* seconds */ s/seconds/microseconds > +struct __kernel_old_timeval ns_to_kernel_old_timeval(const s64 nsec) > +{ > + struct timespec64 ts = ns_to_timespec64(nsec); > + struct __kernel_old_timeval tv; > + > + tv.tv_sec = ts.tv_sec; > + tv.tv_usec = (suseconds_t) ts.tv_nsec / 1000; Is ts.tv_nsec guaranteed to never have bits set in the high 32 bits? In any case, the space before the type cast is a bit confusing to me, I think it should be written as: tv.tv_usec = (suseconds_t)ts.tv_nsec / 1000; To better show was the higher precedence of the cast is going to result in. Thanks, Ingo
On Sat, Mar 10, 2018 at 9:11 AM, Ingo Molnar <mingo@kernel.org> wrote: > >> +extern struct __kernel_old_timeval ns_to_kernel_old_timeval(const s64 nsec); > > Generally there's no need to mark arguments with arithmethic types as const, as > they are never modified in the calling scope. Sure. Here I just copied from the neighboring line, but that's an obvious change. >> + * legacy timeval structure, only embedded in structures that >> + * traditionally used 'timeval' to pass time intervals (not absolute >> + * times). Do not add new users. If user space fails to compile >> + * here, this is probably because it is not y2038 safe and needs to >> + * be changed to use another interface. >> + */ >> +struct __kernel_old_timeval { >> + __kernel_long_t tv_sec; /* seconds */ >> + __kernel_long_t tv_usec; /* seconds */ > > s/seconds/microseconds Right. >> +struct __kernel_old_timeval ns_to_kernel_old_timeval(const s64 nsec) >> +{ >> + struct timespec64 ts = ns_to_timespec64(nsec); >> + struct __kernel_old_timeval tv; >> + >> + tv.tv_sec = ts.tv_sec; >> + tv.tv_usec = (suseconds_t) ts.tv_nsec / 1000; > > Is ts.tv_nsec guaranteed to never have bits set in the high 32 bits? Yes, ns_to_timespec64() produces a valid timespec64 structure. > In any case, the space before the type cast is a bit confusing to me, I think it > should be written as: > > tv.tv_usec = (suseconds_t)ts.tv_nsec / 1000; > > To better show was the higher precedence of the cast is going to result in. Sure. Thanks for taking a look, I'll send an updated version. Arnd
diff --git a/include/linux/time32.h b/include/linux/time32.h index 65b1de2..3febcaf 100644 --- a/include/linux/time32.h +++ b/include/linux/time32.h @@ -217,5 +217,6 @@ static inline s64 timeval_to_ns(const struct timeval *tv) * Returns the timeval representation of the nsec parameter. */ extern struct timeval ns_to_timeval(const s64 nsec); +extern struct __kernel_old_timeval ns_to_kernel_old_timeval(const s64 nsec); #endif diff --git a/include/uapi/linux/time.h b/include/uapi/linux/time.h index 53f8dd8..888da62 100644 --- a/include/uapi/linux/time.h +++ b/include/uapi/linux/time.h @@ -43,6 +43,18 @@ struct itimerval { }; /* + * legacy timeval structure, only embedded in structures that + * traditionally used 'timeval' to pass time intervals (not absolute + * times). Do not add new users. If user space fails to compile + * here, this is probably because it is not y2038 safe and needs to + * be changed to use another interface. + */ +struct __kernel_old_timeval { + __kernel_long_t tv_sec; /* seconds */ + __kernel_long_t tv_usec; /* seconds */ +}; + +/* * The IDs of the various system clocks (for POSIX.1b interval timers): */ #define CLOCK_REALTIME 0 diff --git a/kernel/time/time.c b/kernel/time/time.c index bd4e6c7..cbb3c71 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -488,6 +488,18 @@ struct timeval ns_to_timeval(const s64 nsec) } EXPORT_SYMBOL(ns_to_timeval); +struct __kernel_old_timeval ns_to_kernel_old_timeval(const s64 nsec) +{ + struct timespec64 ts = ns_to_timespec64(nsec); + struct __kernel_old_timeval tv; + + tv.tv_sec = ts.tv_sec; + tv.tv_usec = (suseconds_t) ts.tv_nsec / 1000; + + return tv; +} +EXPORT_SYMBOL(ns_to_kernel_old_timeval); + /** * set_normalized_timespec - set timespec sec and nsec parts and normalize *