Re: [PATCH v2 06/28] kernel: Define gettimeofday vdso common code

Vincenzo Frascino
2018-12-11T13:40:19Z

Hi Arnd,

thank you for reviewing my patches.

On 29/11/2018 20:42, Arnd Bergmann wrote:
> On Thu, Nov 29, 2018 at 6:06 PM Vincenzo Frascino
> <vincenzo.frascino@arm.com> wrote:
>
>> +/*
>> + * The definitions below are required to overcome the limitations
>> + * of time_t on 32 bit architectures, which overflows in 2038.
>> + * The new code should use the replacements based on time64_t and
>> + * timespec64.
>> + *
>> + * The abstraction below will be updated once the migration to
>> + * time64_t is complete.
>> + */
>> +#ifdef CONFIG_GENERIC_VDSO_32
>> +#define __vdso_timespec old_timespec32
>> +#define __vdso_timeval old_timeval32
>> +#else
>> +#ifdef ENABLE_COMPAT_VDSO
>> +#define __vdso_timespec old_timespec32
>> +#define __vdso_timeval old_timeval32
>> +#else
>> +#define __vdso_timespec __kernel_timespec
>> +#define __vdso_timeval __kernel_old_timeval
>> +#endif /* CONFIG_COMPAT_VDSO */
>> +#endif /* CONFIG_GENERIC_VDSO_32 */
>>
>
> Have you considered doing this in the reverse way, by including
> the common parts from multiple implementations (32 and 64
> bit), instead of compiling the same source file multiple
> times with different macros set? I think that would make it
> easier to understand.
>

The common code is never compiled as standalone. It includes arch specific code
(for the fallbacks) and it is included in the arch specific vdso library (for
both 32 and 64 bit where it makes sense). Hence it is built once or twice.

If I understand correctly your question, seems inline with what I am doing.

>> +
>> +#ifdef CONFIG_HAVE_ARCH_TIMER
>> +static __always_inline notrace int __do_realtime_or_tai(
>> + const struct vdso_data *vd,
>> + struct __vdso_timespec *ts,
>> + bool is_tai)
>> +{
>> + u32 seq, cs_mono_mult, cs_shift;
>> + u64 ns, sec;
>> + u64 cycle_last, cs_mono_mask;
>> +
>> + if (vd->use_syscall)
>> + return -1;
>> +repeat:
>
> Maybe instead of the #ifdef, do it like
>
> if (!IS_ENABLED(CONFIG_HAVE_ARCH_TIMER) ||
> vd->use_syscall)
> return -1;
>

Ok, thanks. I will change this in v3.

>> +static notrace int __cvdso_clock_gettime(clockid_t clock,
>> + struct __vdso_timespec *ts)
>> +{
>> + const struct vdso_data *vd = __arch_get_vdso_data();
>> +
>> + if (!__arch_valid_arg(ts))
>> + return -EFAULT;
>> +
>> + switch (clock) {
>> + case CLOCK_REALTIME:
>> + if (do_realtime(vd, ts))
>> + goto fallback;
>> + break;
>> + case CLOCK_TAI:
>> + if (do_tai(vd, ts))
>> + goto fallback;
>> + break;
>> + case CLOCK_MONOTONIC:
>> + if (do_monotonic(vd, ts))
>> + goto fallback;
>> + break;
>> + case CLOCK_MONOTONIC_RAW:
>> + if (do_monotonic_raw(vd, ts))
>> + goto fallback;
>> + break;
>
> Please sync this up with the latest x86 version in
> arch/x86/entry/vdso/vclock_gettime.c, that version has
> seen a lot of improvements recently, so I'd recommend
> using a copy of that file as the base, and then
> modifying it as needed to make it work on the other
> architectures.
>

Thomas commented on my patches and from v3 I am going to port the recent
improvements to the vdso common code.

> Arnd
>

--
Regards,
Vincenzo