mbox series

[v6,00/19] Unify vDSOs across more architectures

Message ID 20190530141531.43462-1-vincenzo.frascino@arm.com (mailing list archive)
Headers show
Series Unify vDSOs across more architectures | expand

Message

Vincenzo Frascino May 30, 2019, 2:15 p.m. UTC
vDSO (virtual dynamic shared object) is a mechanism that the Linux
kernel provides as an alternative to system calls to reduce where
possible the costs in terms of cycles.
This is possible because certain syscalls like gettimeofday() do
not write any data and return one or more values that are stored
in the kernel, which makes relatively safe calling them directly
as a library function.

Even if the mechanism is pretty much standard, every architecture
in the last few years ended up implementing their own vDSO library
in the architectural code.

The purpose of this patch-set is to identify the commonalities in
between the architectures and try to consolidate the common code
paths, starting with gettimeofday().

This implementation contains the following design choices:
 * Every architecture defines the arch specific code in an header in
   "asm/vdso/".
 * The generic implementation includes the arch specific one and lives
   in "lib/vdso".
 * The arch specific code for gettimeofday lives in
   "<arch path>/vdso/gettimeofday.c" and includes the generic code only.
 * The generic implementation of update_vsyscall and update_vsyscall_tz
   lives in kernel/vdso and provide the bindings that can be implemented
   by each architecture.
 * Each architecture provides its implementation of the bindings in
   "asm/vdso/vsyscall.h".
 * This approach allows to consolidate the common code in a single place
   with the benefit of avoiding code duplication.

This implementation contains the portings to the common library for: arm64,
compat mode for arm64, arm, mips, x86_64, x32, compat mode for x86_64 and
i386.

The mips porting has been tested on qemu for mips32el. A configuration to
repeat the tests can be found at [4].

The x86_64 porting has been tested on an Intel Xeon 5120T based machine
running Ubuntu 18.04 and using the Ubuntu provided defconfig.

The i386 porting has been tested on qemu using the i386_defconfig
configuration.

Last but not least from this porting arm64, compat arm64, arm and mips gain
the support for:
 * CLOCK_BOOTTIME that can be useful in certain scenarios since it keeps
   track of the time during sleep as well.
 * CLOCK_TAI that is like CLOCK_REALTIME, but uses the International
   Atomic Time (TAI) reference instead of UTC to avoid jumping on leap
   second updates.
for both clock_gettime and clock_getres.

The porting has been validated using the vdsotest test-suite [1] extended
to cover all the clock ids [2].

A new test has been added to the linux kselftest in order to validate the
newly added library.

The porting has been benchmarked and the performance results are
provided as part of this cover letter.

To simplify the testing, a copy of the patchset on top of a recent linux
tree can be found at [3] and [4].

[1] https://github.com/nathanlynch/vdsotest
[2] https://github.com/fvincenzo/vdsotest
[3] git://linux-arm.org/linux-vf.git vdso/v6
[4] git://linux-arm.org/linux-vf.git vdso-mips/v6

Changes:
--------
v6:
  - Rebased on 5.2-rc2.
  - Added performance numbers.
  - Removed vdso_types.h.
  - Unified update_vsyscall and update_vsyscall_tz.
  - Reworked the kselftest included in this patchset.
  - Addressed review comments.
v5:
  - Rebased on 5.0-rc7.
  - Added x86_64, compat mode for x86_64 and i386 portings.
  - Extended vDSO kselftest.
  - Addressed review comments.
v4:
  - Rebased on 5.0-rc2.
  - Addressed review comments.
  - Disabled compat vdso on arm64 when the kernel is compiled with
    clang.
v3:
  - Ported the latest fixes and optimizations done on the x86
    architecture to the generic library.
  - Addressed review comments.
  - Improved the documentation of the interfaces.
  - Changed the HAVE_ARCH_TIMER config option to a more generic
    HAVE_HW_COUNTER.
v2:
  - Added -ffixed-x18 to arm64
  - Repleced occurrences of timeval and timespec
  - Modified datapage.h to be compliant with y2038 on all the architectures
  - Removed __u_vdso type

Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: Paul Burton <paul.burton@mips.com>
Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Mark Salyzyn <salyzyn@android.com>
Cc: Peter Collingbourne <pcc@google.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Dmitry Safonov <0x7f454c46@gmail.com>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Cc: Huw Davies <huw@codeweavers.com>
Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>

Performance Numbers: Linux 5.2.0-rc2 - Xeon Gold 5120T
======================================================

Unified vDSO:
-------------

clock-gettime-monotonic: syscall: 342 nsec/call
clock-gettime-monotonic:    libc: 25 nsec/call
clock-gettime-monotonic:    vdso: 24 nsec/call
clock-getres-monotonic: syscall: 296 nsec/call
clock-getres-monotonic:    libc: 296 nsec/call
clock-getres-monotonic:    vdso: 3 nsec/call
clock-gettime-monotonic-coarse: syscall: 294 nsec/call
clock-gettime-monotonic-coarse:    libc: 5 nsec/call
clock-gettime-monotonic-coarse:    vdso: 5 nsec/call
clock-getres-monotonic-coarse: syscall: 295 nsec/call
clock-getres-monotonic-coarse:    libc: 292 nsec/call
clock-getres-monotonic-coarse:    vdso: 5 nsec/call
clock-gettime-monotonic-raw: syscall: 343 nsec/call
clock-gettime-monotonic-raw:    libc: 25 nsec/call
clock-gettime-monotonic-raw:    vdso: 23 nsec/call
clock-getres-monotonic-raw: syscall: 290 nsec/call
clock-getres-monotonic-raw:    libc: 290 nsec/call
clock-getres-monotonic-raw:    vdso: 4 nsec/call
clock-gettime-tai: syscall: 332 nsec/call
clock-gettime-tai:    libc: 24 nsec/call
clock-gettime-tai:    vdso: 23 nsec/call
clock-getres-tai: syscall: 288 nsec/call
clock-getres-tai:    libc: 288 nsec/call
clock-getres-tai:    vdso: 3 nsec/call
clock-gettime-boottime: syscall: 342 nsec/call
clock-gettime-boottime:    libc: 24 nsec/call
clock-gettime-boottime:    vdso: 23 nsec/call
clock-getres-boottime: syscall: 284 nsec/call
clock-getres-boottime:    libc: 291 nsec/call
clock-getres-boottime:    vdso: 3 nsec/call
clock-gettime-realtime: syscall: 337 nsec/call
clock-gettime-realtime:    libc: 24 nsec/call
clock-gettime-realtime:    vdso: 23 nsec/call
clock-getres-realtime: syscall: 287 nsec/call
clock-getres-realtime:    libc: 284 nsec/call
clock-getres-realtime:    vdso: 3 nsec/call
clock-gettime-realtime-coarse: syscall: 307 nsec/call
clock-gettime-realtime-coarse:    libc: 4 nsec/call
clock-gettime-realtime-coarse:    vdso: 4 nsec/call
clock-getres-realtime-coarse: syscall: 294 nsec/call
clock-getres-realtime-coarse:    libc: 291 nsec/call
clock-getres-realtime-coarse:    vdso: 4 nsec/call
getcpu: syscall: 246 nsec/call
getcpu:    libc: 14 nsec/call
getcpu:    vdso: 11 nsec/call
gettimeofday: syscall: 293 nsec/call
gettimeofday:    libc: 26 nsec/call
gettimeofday:    vdso: 25 nsec/call

Stock Kernel:
-------------

clock-gettime-monotonic: syscall: 338 nsec/call
clock-gettime-monotonic:    libc: 24 nsec/call
clock-gettime-monotonic:    vdso: 23 nsec/call
clock-getres-monotonic: syscall: 291 nsec/call
clock-getres-monotonic:    libc: 304 nsec/call
clock-getres-monotonic:    vdso: not tested
Note: vDSO version of clock_getres not found
clock-gettime-monotonic-coarse: syscall: 297 nsec/call
clock-gettime-monotonic-coarse:    libc: 5 nsec/call
clock-gettime-monotonic-coarse:    vdso: 4 nsec/call
clock-getres-monotonic-coarse: syscall: 281 nsec/call
clock-getres-monotonic-coarse:    libc: 286 nsec/call
clock-getres-monotonic-coarse:    vdso: not tested
Note: vDSO version of clock_getres not found
clock-gettime-monotonic-raw: syscall: 336 nsec/call
clock-gettime-monotonic-raw:    libc: 340 nsec/call
clock-gettime-monotonic-raw:    vdso: 346 nsec/call
clock-getres-monotonic-raw: syscall: 297 nsec/call
clock-getres-monotonic-raw:    libc: 301 nsec/call
clock-getres-monotonic-raw:    vdso: not tested
Note: vDSO version of clock_getres not found
clock-gettime-tai: syscall: 351 nsec/call
clock-gettime-tai:    libc: 24 nsec/call
clock-gettime-tai:    vdso: 23 nsec/call
clock-getres-tai: syscall: 298 nsec/call
clock-getres-tai:    libc: 290 nsec/call
clock-getres-tai:    vdso: not tested
Note: vDSO version of clock_getres not found
clock-gettime-boottime: syscall: 342 nsec/call
clock-gettime-boottime:    libc: 347 nsec/call
clock-gettime-boottime:    vdso: 355 nsec/call
clock-getres-boottime: syscall: 296 nsec/call
clock-getres-boottime:    libc: 295 nsec/call
clock-getres-boottime:    vdso: not tested
Note: vDSO version of clock_getres not found
clock-gettime-realtime: syscall: 346 nsec/call
clock-gettime-realtime:    libc: 24 nsec/call
clock-gettime-realtime:    vdso: 22 nsec/call
clock-getres-realtime: syscall: 295 nsec/call
clock-getres-realtime:    libc: 291 nsec/call
clock-getres-realtime:    vdso: not tested
Note: vDSO version of clock_getres not found
clock-gettime-realtime-coarse: syscall: 292 nsec/call
clock-gettime-realtime-coarse:    libc: 5 nsec/call
clock-gettime-realtime-coarse:    vdso: 4 nsec/call
clock-getres-realtime-coarse: syscall: 300 nsec/call
clock-getres-realtime-coarse:    libc: 301 nsec/call
clock-getres-realtime-coarse:    vdso: not tested
Note: vDSO version of clock_getres not found
getcpu: syscall: 252 nsec/call
getcpu:    libc: 14 nsec/call
getcpu:    vdso: 11 nsec/call
gettimeofday: syscall: 293 nsec/call
gettimeofday:    libc: 24 nsec/call
gettimeofday:    vdso: 25 nsec/call


Peter Collingbourne (1):
  arm64: Build vDSO with -ffixed-x18

Vincenzo Frascino (18):
  kernel: Standardize vdso_datapage
  kernel: Define gettimeofday vdso common code
  kernel: Unify update_vsyscall implementation
  arm64: Substitute gettimeofday with C implementation
  arm64: compat: Add missing syscall numbers
  arm64: compat: Expose signal related structures
  arm64: compat: Generate asm offsets for signals
  lib: vdso: Add compat support
  arm64: compat: Add vDSO
  arm64: Refactor vDSO code
  arm64: compat: vDSO setup for compat layer
  arm64: elf: vDSO code page discovery
  arm64: compat: Get sigreturn trampolines from vDSO
  arm64: Add vDSO compat support
  arm: Add support for generic vDSO
  mips: Add support for generic vDSO
  x86: Add support for generic vDSO
  kselftest: Extend vDSO selftest

 arch/arm/Kconfig                              |   3 +
 arch/arm/include/asm/vdso/gettimeofday.h      |  96 +++++
 arch/arm/include/asm/vdso/vsyscall.h          |  71 ++++
 arch/arm/include/asm/vdso_datapage.h          |  29 +-
 arch/arm/kernel/vdso.c                        |  87 +----
 arch/arm/vdso/Makefile                        |  13 +-
 arch/arm/vdso/note.c                          |  15 +
 arch/arm/vdso/vdso.lds.S                      |   2 +
 arch/arm/vdso/vgettimeofday.c                 | 268 +------------
 arch/arm64/Kconfig                            |   3 +
 arch/arm64/Makefile                           |  23 +-
 arch/arm64/include/asm/elf.h                  |  14 +
 arch/arm64/include/asm/signal32.h             |  46 +++
 arch/arm64/include/asm/unistd.h               |   5 +
 arch/arm64/include/asm/vdso.h                 |   3 +
 arch/arm64/include/asm/vdso/compat_barrier.h  |  51 +++
 .../include/asm/vdso/compat_gettimeofday.h    | 108 ++++++
 arch/arm64/include/asm/vdso/gettimeofday.h    |  84 +++++
 arch/arm64/include/asm/vdso/vsyscall.h        |  53 +++
 arch/arm64/include/asm/vdso_datapage.h        |  48 ---
 arch/arm64/kernel/Makefile                    |   6 +-
 arch/arm64/kernel/asm-offsets.c               |  39 +-
 arch/arm64/kernel/signal32.c                  |  72 ++--
 arch/arm64/kernel/vdso.c                      | 356 ++++++++++++------
 arch/arm64/kernel/vdso/Makefile               |  34 +-
 arch/arm64/kernel/vdso/gettimeofday.S         | 334 ----------------
 arch/arm64/kernel/vdso/vgettimeofday.c        |  28 ++
 arch/arm64/kernel/vdso32/.gitignore           |   2 +
 arch/arm64/kernel/vdso32/Makefile             | 184 +++++++++
 arch/arm64/kernel/vdso32/note.c               |  15 +
 arch/arm64/kernel/vdso32/sigreturn.S          |  62 +++
 arch/arm64/kernel/vdso32/vdso.S               |  19 +
 arch/arm64/kernel/vdso32/vdso.lds.S           |  82 ++++
 arch/arm64/kernel/vdso32/vgettimeofday.c      |  59 +++
 arch/mips/Kconfig                             |   2 +
 arch/mips/include/asm/vdso.h                  |  78 +---
 arch/mips/include/asm/vdso/gettimeofday.h     | 175 +++++++++
 arch/mips/{ => include/asm}/vdso/vdso.h       |   6 +-
 arch/mips/include/asm/vdso/vsyscall.h         |  43 +++
 arch/mips/kernel/vdso.c                       |  37 +-
 arch/mips/vdso/Makefile                       |  25 +-
 arch/mips/vdso/elf.S                          |   2 +-
 arch/mips/vdso/gettimeofday.c                 | 273 --------------
 arch/mips/vdso/sigreturn.S                    |   2 +-
 arch/mips/vdso/vdso.lds.S                     |   4 +
 arch/mips/vdso/vgettimeofday.c                |  57 +++
 arch/x86/Kconfig                              |   3 +
 arch/x86/entry/vdso/Makefile                  |   9 +
 arch/x86/entry/vdso/vclock_gettime.c          | 251 +++---------
 arch/x86/entry/vdso/vdso.lds.S                |   2 +
 arch/x86/entry/vdso/vdso32/vdso32.lds.S       |   2 +
 arch/x86/entry/vdso/vdsox32.lds.S             |   1 +
 arch/x86/entry/vsyscall/Makefile              |   2 -
 arch/x86/entry/vsyscall/vsyscall_gtod.c       |  83 ----
 arch/x86/include/asm/mshyperv-tsc.h           |  76 ++++
 arch/x86/include/asm/mshyperv.h               |  70 +---
 arch/x86/include/asm/pvclock.h                |   2 +-
 arch/x86/include/asm/vdso/gettimeofday.h      | 203 ++++++++++
 arch/x86/include/asm/vdso/vsyscall.h          |  44 +++
 arch/x86/include/asm/vgtod.h                  |  75 +---
 arch/x86/include/asm/vvar.h                   |   7 +-
 arch/x86/kernel/pvclock.c                     |   1 +
 include/asm-generic/vdso/vsyscall.h           |  56 +++
 include/linux/hrtimer.h                       |  15 +-
 include/linux/hrtimer_defs.h                  |  25 ++
 include/linux/timekeeper_internal.h           |   9 +
 include/vdso/datapage.h                       |  91 +++++
 include/vdso/helpers.h                        |  56 +++
 include/vdso/vsyscall.h                       |  11 +
 kernel/Makefile                               |   1 +
 kernel/vdso/Makefile                          |   2 +
 kernel/vdso/vsyscall.c                        | 139 +++++++
 lib/Kconfig                                   |   5 +
 lib/vdso/Kconfig                              |  36 ++
 lib/vdso/Makefile                             |  22 ++
 lib/vdso/gettimeofday.c                       | 229 +++++++++++
 tools/testing/selftests/vDSO/Makefile         |   2 +
 tools/testing/selftests/vDSO/vdso_full_test.c | 261 +++++++++++++
 78 files changed, 3042 insertions(+), 1767 deletions(-)
 create mode 100644 arch/arm/include/asm/vdso/gettimeofday.h
 create mode 100644 arch/arm/include/asm/vdso/vsyscall.h
 create mode 100644 arch/arm/vdso/note.c
 create mode 100644 arch/arm64/include/asm/vdso/compat_barrier.h
 create mode 100644 arch/arm64/include/asm/vdso/compat_gettimeofday.h
 create mode 100644 arch/arm64/include/asm/vdso/gettimeofday.h
 create mode 100644 arch/arm64/include/asm/vdso/vsyscall.h
 delete mode 100644 arch/arm64/include/asm/vdso_datapage.h
 delete mode 100644 arch/arm64/kernel/vdso/gettimeofday.S
 create mode 100644 arch/arm64/kernel/vdso/vgettimeofday.c
 create mode 100644 arch/arm64/kernel/vdso32/.gitignore
 create mode 100644 arch/arm64/kernel/vdso32/Makefile
 create mode 100644 arch/arm64/kernel/vdso32/note.c
 create mode 100644 arch/arm64/kernel/vdso32/sigreturn.S
 create mode 100644 arch/arm64/kernel/vdso32/vdso.S
 create mode 100644 arch/arm64/kernel/vdso32/vdso.lds.S
 create mode 100644 arch/arm64/kernel/vdso32/vgettimeofday.c
 create mode 100644 arch/mips/include/asm/vdso/gettimeofday.h
 rename arch/mips/{ => include/asm}/vdso/vdso.h (90%)
 create mode 100644 arch/mips/include/asm/vdso/vsyscall.h
 delete mode 100644 arch/mips/vdso/gettimeofday.c
 create mode 100644 arch/mips/vdso/vgettimeofday.c
 delete mode 100644 arch/x86/entry/vsyscall/vsyscall_gtod.c
 create mode 100644 arch/x86/include/asm/mshyperv-tsc.h
 create mode 100644 arch/x86/include/asm/vdso/gettimeofday.h
 create mode 100644 arch/x86/include/asm/vdso/vsyscall.h
 create mode 100644 include/asm-generic/vdso/vsyscall.h
 create mode 100644 include/linux/hrtimer_defs.h
 create mode 100644 include/vdso/datapage.h
 create mode 100644 include/vdso/helpers.h
 create mode 100644 include/vdso/vsyscall.h
 create mode 100644 kernel/vdso/Makefile
 create mode 100644 kernel/vdso/vsyscall.c
 create mode 100644 lib/vdso/Kconfig
 create mode 100644 lib/vdso/Makefile
 create mode 100644 lib/vdso/gettimeofday.c
 create mode 100644 tools/testing/selftests/vDSO/vdso_full_test.c

Comments

Arnd Bergmann May 31, 2019, 8:46 a.m. UTC | #1
On Thu, May 30, 2019 at 4:15 PM Vincenzo Frascino
<vincenzo.frascino@arm.com> wrote:
>
> vDSO (virtual dynamic shared object) is a mechanism that the Linux
> kernel provides as an alternative to system calls to reduce where
> possible the costs in terms of cycles.
> This is possible because certain syscalls like gettimeofday() do
> not write any data and return one or more values that are stored
> in the kernel, which makes relatively safe calling them directly
> as a library function.

Hi Vincento,

I've very happy with how this turned out overall, and as far as I can
tell you have addressed all my previous comments. I had another
look through the series and only noticed a few very minor issues.

I hope Thomas can have another look soon, he probably also finds
a few things, and then it should be ready for inclusion in linux-next
and the coming merge window.

One open question I touched in my review is whether we want to
have a vdso version of clock_getres() in all architectures or not.
I'd prefer to leave it out because there is very little advantage to
it over the system call (the results don't change at runtime and
can easily be cached by libc if performance ever matters), and
it takes up a small amount of memory for the implementation.

We shouldn't just need it for consistency because all callers
would require implementing a fallback to the system call
anyway, to deal with old kernels.

If anyone comes up with a good reason why it should be added
after all, let me know and I'll stop mentioning it.

      Arnd
Vincenzo Frascino June 4, 2019, 12:04 p.m. UTC | #2
Hi Arnd,

thank you for your review.

On 31/05/2019 09:46, Arnd Bergmann wrote:
> On Thu, May 30, 2019 at 4:15 PM Vincenzo Frascino
> <vincenzo.frascino@arm.com> wrote:
>>
>> vDSO (virtual dynamic shared object) is a mechanism that the Linux
>> kernel provides as an alternative to system calls to reduce where
>> possible the costs in terms of cycles.
>> This is possible because certain syscalls like gettimeofday() do
>> not write any data and return one or more values that are stored
>> in the kernel, which makes relatively safe calling them directly
>> as a library function.
> 
> Hi Vincento,
> 
> I've very happy with how this turned out overall, and as far as I can
> tell you have addressed all my previous comments. I had another
> look through the series and only noticed a few very minor issues.
> 

Thanks! I agree with what you pointed out in the single patches, I will wait for
Thomas to review them as well and then will address all the comments in v7.

...

> 
> One open question I touched in my review is whether we want to
> have a vdso version of clock_getres() in all architectures or not.
> I'd prefer to leave it out because there is very little advantage to
> it over the system call (the results don't change at runtime and
> can easily be cached by libc if performance ever matters), and
> it takes up a small amount of memory for the implementation.
> 

I thought about it and I ended up with what proposed in this patchset mainly for
symmetry across all the architectures since in the end they use the same common
code.

It seems also that there is some performance impact (i.e.):

clock-getres-monotonic:    libc(system call): 296 nsec/call
clock-getres-monotonic:    libc(vdso): 5 nsec/call


I agree with you though when you say that caching it in the libc is a
possibility to overcome the performance impact.

> We shouldn't just need it for consistency because all callers
> would require implementing a fallback to the system call
> anyway, to deal with old kernels.
> 

A way to address this issue would be to use versioning, which seems supported in
the vdso library (i.e. arch/x86/entry/vdso/vdso32/vdso32.lds.S).

For example for x86 (vdso32) we would have something like:

VERSION
{
	LINUX_5.3 (being optimistic here :) ) {
	global:
                __vdso_clock_getres;
                __vdso_clock_gettime64;
        };
        LINUX_2.6 {
        global:
                __vdso_clock_gettime;
                __vdso_gettimeofday;
                __vdso_time;
        };

        LINUX_2.5 {
        global:
                __kernel_vsyscall;
                __kernel_sigreturn;
                __kernel_rt_sigreturn;
        local: *;
        };
}

What do you think? Would this be a viable solution?

> If anyone comes up with a good reason why it should be added
> after all, let me know and I'll stop mentioning it.
> 
>       Arnd
>
Arnd Bergmann June 4, 2019, 12:12 p.m. UTC | #3
On Tue, Jun 4, 2019 at 2:05 PM Vincenzo Frascino
<vincenzo.frascino@arm.com> wrote:
> On 31/05/2019 09:46, Arnd Bergmann wrote:
> > On Thu, May 30, 2019 at 4:15 PM Vincenzo Frascino
> > <vincenzo.frascino@arm.com> wrote:
> > One open question I touched in my review is whether we want to
> > have a vdso version of clock_getres() in all architectures or not.
> > I'd prefer to leave it out because there is very little advantage to
> > it over the system call (the results don't change at runtime and
> > can easily be cached by libc if performance ever matters), and
> > it takes up a small amount of memory for the implementation.
> >
>
> I thought about it and I ended up with what proposed in this patchset mainly for
> symmetry across all the architectures since in the end they use the same common
> code.
>
> It seems also that there is some performance impact (i.e.):
>
> clock-getres-monotonic:    libc(system call): 296 nsec/call
> clock-getres-monotonic:    libc(vdso): 5 nsec/call
>
>
> I agree with you though when you say that caching it in the libc is a
> possibility to overcome the performance impact.

It's clear that the vdso version is much faster, my point was that
I could not think of any use case that cared about it being fast.

If there is a good reason for it, I also don't mind adding a
clock_getres_time64() vdso version everywhere.

> > We shouldn't just need it for consistency because all callers
> > would require implementing a fallback to the system call
> > anyway, to deal with old kernels.
> >
>
> A way to address this issue would be to use versioning, which seems supported in
> the vdso library (i.e. arch/x86/entry/vdso/vdso32/vdso32.lds.S).
>
> For example for x86 (vdso32) we would have something like:
>
> VERSION
> {
>         LINUX_5.3 (being optimistic here :) ) {
>         global:
>                 __vdso_clock_getres;
>                 __vdso_clock_gettime64;
>         };
>         LINUX_2.6 {
>         global:
>                 __vdso_clock_gettime;
>                 __vdso_gettimeofday;
>                 __vdso_time;
>         };
>
>         LINUX_2.5 {
>         global:
>                 __kernel_vsyscall;
>                 __kernel_sigreturn;
>                 __kernel_rt_sigreturn;
>         local: *;
>         };
> }
>
> What do you think? Would this be a viable solution?

I actually never understood the point of symbol versioning
in the vdso. What does that gain us? Note that there are
no conflicting symbol names between the versions, and
that nothing enforces the kernel headers to match the
symbol version used when linking.

      Arnd
Vincenzo Frascino June 5, 2019, 2:32 p.m. UTC | #4
On 6/4/19 1:12 PM, Arnd Bergmann wrote:
> On Tue, Jun 4, 2019 at 2:05 PM Vincenzo Frascino
> <vincenzo.frascino@arm.com> wrote:
>> On 31/05/2019 09:46, Arnd Bergmann wrote:
>>> On Thu, May 30, 2019 at 4:15 PM Vincenzo Frascino
>>> <vincenzo.frascino@arm.com> wrote:
>>> One open question I touched in my review is whether we want to
>>> have a vdso version of clock_getres() in all architectures or not.
>>> I'd prefer to leave it out because there is very little advantage to
>>> it over the system call (the results don't change at runtime and
>>> can easily be cached by libc if performance ever matters), and
>>> it takes up a small amount of memory for the implementation.
>>>
>>
>> I thought about it and I ended up with what proposed in this patchset mainly for
>> symmetry across all the architectures since in the end they use the same common
>> code.
>>
>> It seems also that there is some performance impact (i.e.):
>>
>> clock-getres-monotonic:    libc(system call): 296 nsec/call
>> clock-getres-monotonic:    libc(vdso): 5 nsec/call
>>
>>
>> I agree with you though when you say that caching it in the libc is a
>> possibility to overcome the performance impact.
> 
> It's clear that the vdso version is much faster, my point was that
> I could not think of any use case that cared about it being fast.
> 

I do not know of any use case that cares, my point was that since we need to
implement it in the generic library for some architectures, for symmetry we can
extend it to all the architectures that support the generic vdso library.

> If there is a good reason for it, I also don't mind adding a
> clock_getres_time64() vdso version everywhere.

Totally agree on this.

> 
>>> We shouldn't just need it for consistency because all callers
>>> would require implementing a fallback to the system call
>>> anyway, to deal with old kernels.
>>>
>>
>> A way to address this issue would be to use versioning, which seems supported in
>> the vdso library (i.e. arch/x86/entry/vdso/vdso32/vdso32.lds.S).
>>
>> For example for x86 (vdso32) we would have something like:
>>
>> VERSION
>> {
>>         LINUX_5.3 (being optimistic here :) ) {
>>         global:
>>                 __vdso_clock_getres;
>>                 __vdso_clock_gettime64;
>>         };
>>         LINUX_2.6 {
>>         global:
>>                 __vdso_clock_gettime;
>>                 __vdso_gettimeofday;
>>                 __vdso_time;
>>         };
>>
>>         LINUX_2.5 {
>>         global:
>>                 __kernel_vsyscall;
>>                 __kernel_sigreturn;
>>                 __kernel_rt_sigreturn;
>>         local: *;
>>         };
>> }
>>
>> What do you think? Would this be a viable solution?
> 
> I actually never understood the point of symbol versioning
> in the vdso. What does that gain us? Note that there are
> no conflicting symbol names between the versions, and
> that nothing enforces the kernel headers to match the
> symbol version used when linking.
>

My understanding, based on [1] and [2] is that the version defines the minimum
kernel version from when a specific symbols is exposed and whenever this symbol
is requested from the vDSO the correct version needs to be specified.
Every "new" library, dealing with an "old" kernel, compliant with the exposed
ABI should implement the vDSO calls in this way and provide a fallback if the
vDSO function is not present (i.e. [3]).

[1] Documentation/ABI/stable/vdso
[2] tools/testing/selftests/vDSO/parse_vdso.c
[3]
https://github.com/lattera/glibc/blob/master/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c


>       Arnd
>
Thomas Gleixner June 14, 2019, 12:16 p.m. UTC | #5
On Tue, 4 Jun 2019, Vincenzo Frascino wrote:
> On 31/05/2019 09:46, Arnd Bergmann wrote:
> > One open question I touched in my review is whether we want to
> > have a vdso version of clock_getres() in all architectures or not.
> > I'd prefer to leave it out because there is very little advantage to
> > it over the system call (the results don't change at runtime and
> > can easily be cached by libc if performance ever matters), and
> > it takes up a small amount of memory for the implementation.
> > 
> 
> I thought about it and I ended up with what proposed in this patchset mainly for
> symmetry across all the architectures since in the end they use the same common
> code.
> 
> It seems also that there is some performance impact (i.e.):
> 
> clock-getres-monotonic:    libc(system call): 296 nsec/call
> clock-getres-monotonic:    libc(vdso): 5 nsec/call

clock_getres() is usually not a hot path operation.

> I agree with you though when you say that caching it in the libc is a
> possibility to overcome the performance impact.
> 
> > We shouldn't just need it for consistency because all callers
> > would require implementing a fallback to the system call
> > anyway, to deal with old kernels.

libc has the fallback already. Let's aim for 1:1 replacement of the
architecture code first and then add the extra bits in separate patches.

Thanks,

	tglx
Vincenzo Frascino June 14, 2019, 12:19 p.m. UTC | #6
On 6/14/19 1:16 PM, Thomas Gleixner wrote:
> On Tue, 4 Jun 2019, Vincenzo Frascino wrote:
>> On 31/05/2019 09:46, Arnd Bergmann wrote:
>>> One open question I touched in my review is whether we want to
>>> have a vdso version of clock_getres() in all architectures or not.
>>> I'd prefer to leave it out because there is very little advantage to
>>> it over the system call (the results don't change at runtime and
>>> can easily be cached by libc if performance ever matters), and
>>> it takes up a small amount of memory for the implementation.
>>>
>>
>> I thought about it and I ended up with what proposed in this patchset mainly for
>> symmetry across all the architectures since in the end they use the same common
>> code.
>>
>> It seems also that there is some performance impact (i.e.):
>>
>> clock-getres-monotonic:    libc(system call): 296 nsec/call
>> clock-getres-monotonic:    libc(vdso): 5 nsec/call
> 
> clock_getres() is usually not a hot path operation.
> 
>> I agree with you though when you say that caching it in the libc is a
>> possibility to overcome the performance impact.
>>
>>> We shouldn't just need it for consistency because all callers
>>> would require implementing a fallback to the system call
>>> anyway, to deal with old kernels.
> 
> libc has the fallback already. Let's aim for 1:1 replacement of the
> architecture code first and then add the extra bits in separate patches.
>

Ok, thanks Thomas, I will split the patches accordingly.

> Thanks,
> 
> 	tglx
>
Shijith Thotton June 20, 2019, 6:17 a.m. UTC | #7
Hi Vincenzo,

On 5/30/19 7:15 AM, Vincenzo Frascino wrote:
> vDSO (virtual dynamic shared object) is a mechanism that the Linux
> kernel provides as an alternative to system calls to reduce where
> possible the costs in terms of cycles.
> This is possible because certain syscalls like gettimeofday() do
> not write any data and return one or more values that are stored
> in the kernel, which makes relatively safe calling them directly
> as a library function.
> 
> Even if the mechanism is pretty much standard, every architecture
> in the last few years ended up implementing their own vDSO library
> in the architectural code.
> 
> The purpose of this patch-set is to identify the commonalities in
> between the architectures and try to consolidate the common code
> paths, starting with gettimeofday().
> 
> This implementation contains the following design choices:
>   * Every architecture defines the arch specific code in an header in
>     "asm/vdso/".
>   * The generic implementation includes the arch specific one and lives
>     in "lib/vdso".
>   * The arch specific code for gettimeofday lives in
>     "<arch path>/vdso/gettimeofday.c" and includes the generic code only.
>   * The generic implementation of update_vsyscall and update_vsyscall_tz
>     lives in kernel/vdso and provide the bindings that can be implemented
>     by each architecture.
>   * Each architecture provides its implementation of the bindings in
>     "asm/vdso/vsyscall.h".
>   * This approach allows to consolidate the common code in a single place
>     with the benefit of avoiding code duplication.
> 
> This implementation contains the portings to the common library for: arm64,
> compat mode for arm64, arm, mips, x86_64, x32, compat mode for x86_64 and
> i386.
> 
> The mips porting has been tested on qemu for mips32el. A configuration to
> repeat the tests can be found at [4].
> 
> The x86_64 porting has been tested on an Intel Xeon 5120T based machine
> running Ubuntu 18.04 and using the Ubuntu provided defconfig.
> 
> The i386 porting has been tested on qemu using the i386_defconfig
> configuration.
> 
> Last but not least from this porting arm64, compat arm64, arm and mips gain
> the support for:
>   * CLOCK_BOOTTIME that can be useful in certain scenarios since it keeps
>     track of the time during sleep as well.
>   * CLOCK_TAI that is like CLOCK_REALTIME, but uses the International
>     Atomic Time (TAI) reference instead of UTC to avoid jumping on leap
>     second updates.
> for both clock_gettime and clock_getres.
> 
> The porting has been validated using the vdsotest test-suite [1] extended
> to cover all the clock ids [2].
> 
> A new test has been added to the linux kselftest in order to validate the
> newly added library.
> 
> The porting has been benchmarked and the performance results are
> provided as part of this cover letter.
> 
> To simplify the testing, a copy of the patchset on top of a recent linux
> tree can be found at [3] and [4].
> 
> [1] https://github.com/nathanlynch/vdsotest
> [2] https://github.com/fvincenzo/vdsotest
> [3] git://linux-arm.org/linux-vf.git vdso/v6
> [4] git://linux-arm.org/linux-vf.git vdso-mips/v6
> 
> Changes:
> --------
> v6:
>    - Rebased on 5.2-rc2.
>    - Added performance numbers.
>    - Removed vdso_types.h.
>    - Unified update_vsyscall and update_vsyscall_tz.
>    - Reworked the kselftest included in this patchset.
>    - Addressed review comments.
> v5:
>    - Rebased on 5.0-rc7.
>    - Added x86_64, compat mode for x86_64 and i386 portings.
>    - Extended vDSO kselftest.
>    - Addressed review comments.
> v4:
>    - Rebased on 5.0-rc2.
>    - Addressed review comments.
>    - Disabled compat vdso on arm64 when the kernel is compiled with
>      clang.
> v3:
>    - Ported the latest fixes and optimizations done on the x86
>      architecture to the generic library.
>    - Addressed review comments.
>    - Improved the documentation of the interfaces.
>    - Changed the HAVE_ARCH_TIMER config option to a more generic
>      HAVE_HW_COUNTER.
> v2:
>    - Added -ffixed-x18 to arm64
>    - Repleced occurrences of timeval and timespec
>    - Modified datapage.h to be compliant with y2038 on all the architectures
>    - Removed __u_vdso type
> 
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Russell King <linux@armlinux.org.uk>
> Cc: Ralf Baechle <ralf@linux-mips.org>
> Cc: Paul Burton <paul.burton@mips.com>
> Cc: Daniel Lezcano <daniel.lezcano@linaro.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Mark Salyzyn <salyzyn@android.com>
> Cc: Peter Collingbourne <pcc@google.com>
> Cc: Shuah Khan <shuah@kernel.org>
> Cc: Dmitry Safonov <0x7f454c46@gmail.com>
> Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
> Cc: Huw Davies <huw@codeweavers.com>
> Signed-off-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
> 
> Performance Numbers: Linux 5.2.0-rc2 - Xeon Gold 5120T
> ======================================================
> 
> Unified vDSO:
> -------------
> 
> clock-gettime-monotonic: syscall: 342 nsec/call
> clock-gettime-monotonic:    libc: 25 nsec/call
> clock-gettime-monotonic:    vdso: 24 nsec/call
> clock-getres-monotonic: syscall: 296 nsec/call
> clock-getres-monotonic:    libc: 296 nsec/call
> clock-getres-monotonic:    vdso: 3 nsec/call
> clock-gettime-monotonic-coarse: syscall: 294 nsec/call
> clock-gettime-monotonic-coarse:    libc: 5 nsec/call
> clock-gettime-monotonic-coarse:    vdso: 5 nsec/call
> clock-getres-monotonic-coarse: syscall: 295 nsec/call
> clock-getres-monotonic-coarse:    libc: 292 nsec/call
> clock-getres-monotonic-coarse:    vdso: 5 nsec/call
> clock-gettime-monotonic-raw: syscall: 343 nsec/call
> clock-gettime-monotonic-raw:    libc: 25 nsec/call
> clock-gettime-monotonic-raw:    vdso: 23 nsec/call
> clock-getres-monotonic-raw: syscall: 290 nsec/call
> clock-getres-monotonic-raw:    libc: 290 nsec/call
> clock-getres-monotonic-raw:    vdso: 4 nsec/call
> clock-gettime-tai: syscall: 332 nsec/call
> clock-gettime-tai:    libc: 24 nsec/call
> clock-gettime-tai:    vdso: 23 nsec/call
> clock-getres-tai: syscall: 288 nsec/call
> clock-getres-tai:    libc: 288 nsec/call
> clock-getres-tai:    vdso: 3 nsec/call
> clock-gettime-boottime: syscall: 342 nsec/call
> clock-gettime-boottime:    libc: 24 nsec/call
> clock-gettime-boottime:    vdso: 23 nsec/call
> clock-getres-boottime: syscall: 284 nsec/call
> clock-getres-boottime:    libc: 291 nsec/call
> clock-getres-boottime:    vdso: 3 nsec/call
> clock-gettime-realtime: syscall: 337 nsec/call
> clock-gettime-realtime:    libc: 24 nsec/call
> clock-gettime-realtime:    vdso: 23 nsec/call
> clock-getres-realtime: syscall: 287 nsec/call
> clock-getres-realtime:    libc: 284 nsec/call
> clock-getres-realtime:    vdso: 3 nsec/call
> clock-gettime-realtime-coarse: syscall: 307 nsec/call
> clock-gettime-realtime-coarse:    libc: 4 nsec/call
> clock-gettime-realtime-coarse:    vdso: 4 nsec/call
> clock-getres-realtime-coarse: syscall: 294 nsec/call
> clock-getres-realtime-coarse:    libc: 291 nsec/call
> clock-getres-realtime-coarse:    vdso: 4 nsec/call
> getcpu: syscall: 246 nsec/call
> getcpu:    libc: 14 nsec/call
> getcpu:    vdso: 11 nsec/call
> gettimeofday: syscall: 293 nsec/call
> gettimeofday:    libc: 26 nsec/call
> gettimeofday:    vdso: 25 nsec/call
> 
> Stock Kernel:
> -------------
> 
> clock-gettime-monotonic: syscall: 338 nsec/call
> clock-gettime-monotonic:    libc: 24 nsec/call
> clock-gettime-monotonic:    vdso: 23 nsec/call
> clock-getres-monotonic: syscall: 291 nsec/call
> clock-getres-monotonic:    libc: 304 nsec/call
> clock-getres-monotonic:    vdso: not tested
> Note: vDSO version of clock_getres not found
> clock-gettime-monotonic-coarse: syscall: 297 nsec/call
> clock-gettime-monotonic-coarse:    libc: 5 nsec/call
> clock-gettime-monotonic-coarse:    vdso: 4 nsec/call
> clock-getres-monotonic-coarse: syscall: 281 nsec/call
> clock-getres-monotonic-coarse:    libc: 286 nsec/call
> clock-getres-monotonic-coarse:    vdso: not tested
> Note: vDSO version of clock_getres not found
> clock-gettime-monotonic-raw: syscall: 336 nsec/call
> clock-gettime-monotonic-raw:    libc: 340 nsec/call
> clock-gettime-monotonic-raw:    vdso: 346 nsec/call
> clock-getres-monotonic-raw: syscall: 297 nsec/call
> clock-getres-monotonic-raw:    libc: 301 nsec/call
> clock-getres-monotonic-raw:    vdso: not tested
> Note: vDSO version of clock_getres not found
> clock-gettime-tai: syscall: 351 nsec/call
> clock-gettime-tai:    libc: 24 nsec/call
> clock-gettime-tai:    vdso: 23 nsec/call
> clock-getres-tai: syscall: 298 nsec/call
> clock-getres-tai:    libc: 290 nsec/call
> clock-getres-tai:    vdso: not tested
> Note: vDSO version of clock_getres not found
> clock-gettime-boottime: syscall: 342 nsec/call
> clock-gettime-boottime:    libc: 347 nsec/call
> clock-gettime-boottime:    vdso: 355 nsec/call
> clock-getres-boottime: syscall: 296 nsec/call
> clock-getres-boottime:    libc: 295 nsec/call
> clock-getres-boottime:    vdso: not tested
> Note: vDSO version of clock_getres not found
> clock-gettime-realtime: syscall: 346 nsec/call
> clock-gettime-realtime:    libc: 24 nsec/call
> clock-gettime-realtime:    vdso: 22 nsec/call
> clock-getres-realtime: syscall: 295 nsec/call
> clock-getres-realtime:    libc: 291 nsec/call
> clock-getres-realtime:    vdso: not tested
> Note: vDSO version of clock_getres not found
> clock-gettime-realtime-coarse: syscall: 292 nsec/call
> clock-gettime-realtime-coarse:    libc: 5 nsec/call
> clock-gettime-realtime-coarse:    vdso: 4 nsec/call
> clock-getres-realtime-coarse: syscall: 300 nsec/call
> clock-getres-realtime-coarse:    libc: 301 nsec/call
> clock-getres-realtime-coarse:    vdso: not tested
> Note: vDSO version of clock_getres not found
> getcpu: syscall: 252 nsec/call
> getcpu:    libc: 14 nsec/call
> getcpu:    vdso: 11 nsec/call
> gettimeofday: syscall: 293 nsec/call
> gettimeofday:    libc: 24 nsec/call
> gettimeofday:    vdso: 25 nsec/call
> 
> 
> Peter Collingbourne (1):
>    arm64: Build vDSO with -ffixed-x18
> 
> Vincenzo Frascino (18):
>    kernel: Standardize vdso_datapage
>    kernel: Define gettimeofday vdso common code
>    kernel: Unify update_vsyscall implementation
>    arm64: Substitute gettimeofday with C implementation
>    arm64: compat: Add missing syscall numbers
>    arm64: compat: Expose signal related structures
>    arm64: compat: Generate asm offsets for signals
>    lib: vdso: Add compat support
>    arm64: compat: Add vDSO
>    arm64: Refactor vDSO code
>    arm64: compat: vDSO setup for compat layer
>    arm64: elf: vDSO code page discovery
>    arm64: compat: Get sigreturn trampolines from vDSO
>    arm64: Add vDSO compat support
>    arm: Add support for generic vDSO
>    mips: Add support for generic vDSO
>    x86: Add support for generic vDSO
>    kselftest: Extend vDSO selftest
> 
>   arch/arm/Kconfig                              |   3 +
>   arch/arm/include/asm/vdso/gettimeofday.h      |  96 +++++
>   arch/arm/include/asm/vdso/vsyscall.h          |  71 ++++
>   arch/arm/include/asm/vdso_datapage.h          |  29 +-
>   arch/arm/kernel/vdso.c                        |  87 +----
>   arch/arm/vdso/Makefile                        |  13 +-
>   arch/arm/vdso/note.c                          |  15 +
>   arch/arm/vdso/vdso.lds.S                      |   2 +
>   arch/arm/vdso/vgettimeofday.c                 | 268 +------------
>   arch/arm64/Kconfig                            |   3 +
>   arch/arm64/Makefile                           |  23 +-
>   arch/arm64/include/asm/elf.h                  |  14 +
>   arch/arm64/include/asm/signal32.h             |  46 +++
>   arch/arm64/include/asm/unistd.h               |   5 +
>   arch/arm64/include/asm/vdso.h                 |   3 +
>   arch/arm64/include/asm/vdso/compat_barrier.h  |  51 +++
>   .../include/asm/vdso/compat_gettimeofday.h    | 108 ++++++
>   arch/arm64/include/asm/vdso/gettimeofday.h    |  84 +++++
>   arch/arm64/include/asm/vdso/vsyscall.h        |  53 +++
>   arch/arm64/include/asm/vdso_datapage.h        |  48 ---
>   arch/arm64/kernel/Makefile                    |   6 +-
>   arch/arm64/kernel/asm-offsets.c               |  39 +-
>   arch/arm64/kernel/signal32.c                  |  72 ++--
>   arch/arm64/kernel/vdso.c                      | 356 ++++++++++++------
>   arch/arm64/kernel/vdso/Makefile               |  34 +-
>   arch/arm64/kernel/vdso/gettimeofday.S         | 334 ----------------
>   arch/arm64/kernel/vdso/vgettimeofday.c        |  28 ++
>   arch/arm64/kernel/vdso32/.gitignore           |   2 +
>   arch/arm64/kernel/vdso32/Makefile             | 184 +++++++++
>   arch/arm64/kernel/vdso32/note.c               |  15 +
>   arch/arm64/kernel/vdso32/sigreturn.S          |  62 +++
>   arch/arm64/kernel/vdso32/vdso.S               |  19 +
>   arch/arm64/kernel/vdso32/vdso.lds.S           |  82 ++++
>   arch/arm64/kernel/vdso32/vgettimeofday.c      |  59 +++
>   arch/mips/Kconfig                             |   2 +
>   arch/mips/include/asm/vdso.h                  |  78 +---
>   arch/mips/include/asm/vdso/gettimeofday.h     | 175 +++++++++
>   arch/mips/{ => include/asm}/vdso/vdso.h       |   6 +-
>   arch/mips/include/asm/vdso/vsyscall.h         |  43 +++
>   arch/mips/kernel/vdso.c                       |  37 +-
>   arch/mips/vdso/Makefile                       |  25 +-
>   arch/mips/vdso/elf.S                          |   2 +-
>   arch/mips/vdso/gettimeofday.c                 | 273 --------------
>   arch/mips/vdso/sigreturn.S                    |   2 +-
>   arch/mips/vdso/vdso.lds.S                     |   4 +
>   arch/mips/vdso/vgettimeofday.c                |  57 +++
>   arch/x86/Kconfig                              |   3 +
>   arch/x86/entry/vdso/Makefile                  |   9 +
>   arch/x86/entry/vdso/vclock_gettime.c          | 251 +++---------
>   arch/x86/entry/vdso/vdso.lds.S                |   2 +
>   arch/x86/entry/vdso/vdso32/vdso32.lds.S       |   2 +
>   arch/x86/entry/vdso/vdsox32.lds.S             |   1 +
>   arch/x86/entry/vsyscall/Makefile              |   2 -
>   arch/x86/entry/vsyscall/vsyscall_gtod.c       |  83 ----
>   arch/x86/include/asm/mshyperv-tsc.h           |  76 ++++
>   arch/x86/include/asm/mshyperv.h               |  70 +---
>   arch/x86/include/asm/pvclock.h                |   2 +-
>   arch/x86/include/asm/vdso/gettimeofday.h      | 203 ++++++++++
>   arch/x86/include/asm/vdso/vsyscall.h          |  44 +++
>   arch/x86/include/asm/vgtod.h                  |  75 +---
>   arch/x86/include/asm/vvar.h                   |   7 +-
>   arch/x86/kernel/pvclock.c                     |   1 +
>   include/asm-generic/vdso/vsyscall.h           |  56 +++
>   include/linux/hrtimer.h                       |  15 +-
>   include/linux/hrtimer_defs.h                  |  25 ++
>   include/linux/timekeeper_internal.h           |   9 +
>   include/vdso/datapage.h                       |  91 +++++
>   include/vdso/helpers.h                        |  56 +++
>   include/vdso/vsyscall.h                       |  11 +
>   kernel/Makefile                               |   1 +
>   kernel/vdso/Makefile                          |   2 +
>   kernel/vdso/vsyscall.c                        | 139 +++++++
>   lib/Kconfig                                   |   5 +
>   lib/vdso/Kconfig                              |  36 ++
>   lib/vdso/Makefile                             |  22 ++
>   lib/vdso/gettimeofday.c                       | 229 +++++++++++
>   tools/testing/selftests/vDSO/Makefile         |   2 +
>   tools/testing/selftests/vDSO/vdso_full_test.c | 261 +++++++++++++
>   78 files changed, 3042 insertions(+), 1767 deletions(-)
>   create mode 100644 arch/arm/include/asm/vdso/gettimeofday.h
>   create mode 100644 arch/arm/include/asm/vdso/vsyscall.h
>   create mode 100644 arch/arm/vdso/note.c
>   create mode 100644 arch/arm64/include/asm/vdso/compat_barrier.h
>   create mode 100644 arch/arm64/include/asm/vdso/compat_gettimeofday.h
>   create mode 100644 arch/arm64/include/asm/vdso/gettimeofday.h
>   create mode 100644 arch/arm64/include/asm/vdso/vsyscall.h
>   delete mode 100644 arch/arm64/include/asm/vdso_datapage.h
>   delete mode 100644 arch/arm64/kernel/vdso/gettimeofday.S
>   create mode 100644 arch/arm64/kernel/vdso/vgettimeofday.c
>   create mode 100644 arch/arm64/kernel/vdso32/.gitignore
>   create mode 100644 arch/arm64/kernel/vdso32/Makefile
>   create mode 100644 arch/arm64/kernel/vdso32/note.c
>   create mode 100644 arch/arm64/kernel/vdso32/sigreturn.S
>   create mode 100644 arch/arm64/kernel/vdso32/vdso.S
>   create mode 100644 arch/arm64/kernel/vdso32/vdso.lds.S
>   create mode 100644 arch/arm64/kernel/vdso32/vgettimeofday.c
>   create mode 100644 arch/mips/include/asm/vdso/gettimeofday.h
>   rename arch/mips/{ => include/asm}/vdso/vdso.h (90%)
>   create mode 100644 arch/mips/include/asm/vdso/vsyscall.h
>   delete mode 100644 arch/mips/vdso/gettimeofday.c
>   create mode 100644 arch/mips/vdso/vgettimeofday.c
>   delete mode 100644 arch/x86/entry/vsyscall/vsyscall_gtod.c
>   create mode 100644 arch/x86/include/asm/mshyperv-tsc.h
>   create mode 100644 arch/x86/include/asm/vdso/gettimeofday.h
>   create mode 100644 arch/x86/include/asm/vdso/vsyscall.h
>   create mode 100644 include/asm-generic/vdso/vsyscall.h
>   create mode 100644 include/linux/hrtimer_defs.h
>   create mode 100644 include/vdso/datapage.h
>   create mode 100644 include/vdso/helpers.h
>   create mode 100644 include/vdso/vsyscall.h
>   create mode 100644 kernel/vdso/Makefile
>   create mode 100644 kernel/vdso/vsyscall.c
>   create mode 100644 lib/vdso/Kconfig
>   create mode 100644 lib/vdso/Makefile
>   create mode 100644 lib/vdso/gettimeofday.c
>   create mode 100644 tools/testing/selftests/vDSO/vdso_full_test.c
> 

Ran vdsotest-bench on ThunderX2 (arm64) with and without unified 
patchset. The numbers are as below:

Unified vDSO:
-------------
clock-gettime-monotonic: syscall: 346 nsec/call
clock-gettime-monotonic:    libc: 38 nsec/call
clock-gettime-monotonic:    vdso: 36 nsec/call
clock-getres-monotonic: syscall: 262 nsec/call
clock-getres-monotonic:    libc: 6 nsec/call
clock-getres-monotonic:    vdso: 5 nsec/call
clock-gettime-monotonic-coarse: syscall: 296 nsec/call
clock-gettime-monotonic-coarse:    libc: 39 nsec/call
clock-gettime-monotonic-coarse:    vdso: 38 nsec/call
clock-getres-monotonic-coarse: syscall: 260 nsec/call
clock-getres-monotonic-coarse:    libc: 8 nsec/call
clock-getres-monotonic-coarse:    vdso: 5 nsec/call
clock-gettime-monotonic-raw: syscall: 345 nsec/call
clock-gettime-monotonic-raw:    libc: 35 nsec/call
clock-gettime-monotonic-raw:    vdso: 34 nsec/call
clock-getres-monotonic-raw: syscall: 261 nsec/call
clock-getres-monotonic-raw:    libc: 7 nsec/call
clock-getres-monotonic-raw:    vdso: 5 nsec/call
clock-gettime-tai: syscall: 357 nsec/call
clock-gettime-tai:    libc: 38 nsec/call
clock-gettime-tai:    vdso: 36 nsec/call
clock-getres-tai: syscall: 257 nsec/call
clock-getres-tai:    libc: 7 nsec/call
clock-getres-tai:    vdso: 5 nsec/call
clock-gettime-boottime: syscall: 356 nsec/call
clock-gettime-boottime:    libc: 38 nsec/call
clock-gettime-boottime:    vdso: 36 nsec/call
clock-getres-boottime: syscall: 257 nsec/call
clock-getres-boottime:    libc: 6 nsec/call
clock-getres-boottime:    vdso: 5 nsec/call
clock-gettime-realtime: syscall: 345 nsec/call
clock-gettime-realtime:    libc: 38 nsec/call
clock-gettime-realtime:    vdso: 36 nsec/call
clock-getres-realtime: syscall: 257 nsec/call
clock-getres-realtime:    libc: 7 nsec/call
clock-getres-realtime:    vdso: 5 nsec/call
clock-gettime-realtime-coarse: syscall: 295 nsec/call
clock-gettime-realtime-coarse:    libc: 39 nsec/call
clock-gettime-realtime-coarse:    vdso: 38 nsec/call
clock-getres-realtime-coarse: syscall: 260 nsec/call
clock-getres-realtime-coarse:    libc: 8 nsec/call
clock-getres-realtime-coarse:    vdso: 5 nsec/call
getcpu: syscall: 244 nsec/call
getcpu:    libc: 247 nsec/call
getcpu:    vdso: not tested
Note: vDSO version of getcpu not found
gettimeofday: syscall: 383 nsec/call
gettimeofday:    libc: 39 nsec/call
gettimeofday:    vdso: 35 nsec/call

Stock Kernel:
-------------
clock-gettime-monotonic: syscall: 344 nsec/call
clock-gettime-monotonic:    libc: 74 nsec/call
clock-gettime-monotonic:    vdso: 73 nsec/call
clock-getres-monotonic: syscall: 258 nsec/call
clock-getres-monotonic:    libc: 6 nsec/call
clock-getres-monotonic:    vdso: 4 nsec/call
clock-gettime-monotonic-coarse: syscall: 300 nsec/call
clock-gettime-monotonic-coarse:    libc: 36 nsec/call
clock-gettime-monotonic-coarse:    vdso: 34 nsec/call
clock-getres-monotonic-coarse: syscall: 261 nsec/call
clock-getres-monotonic-coarse:    libc: 6 nsec/call
clock-getres-monotonic-coarse:    vdso: 4 nsec/call
clock-gettime-monotonic-raw: syscall: 346 nsec/call
clock-gettime-monotonic-raw:    libc: 74 nsec/call
clock-gettime-monotonic-raw:    vdso: 72 nsec/call
clock-getres-monotonic-raw: syscall: 254 nsec/call
clock-getres-monotonic-raw:    libc: 6 nsec/call
clock-getres-monotonic-raw:    vdso: 4 nsec/call
clock-gettime-tai: syscall: 345 nsec/call
clock-gettime-tai:    libc: 361 nsec/call
clock-gettime-tai:    vdso: 359 nsec/call
clock-getres-tai: syscall: 259 nsec/call
clock-getres-tai:    libc: 262 nsec/call
clock-getres-tai:    vdso: 258 nsec/call
clock-gettime-boottime: syscall: 353 nsec/call
clock-gettime-boottime:    libc: 365 nsec/call
clock-gettime-boottime:    vdso: 362 nsec/call
clock-getres-boottime: syscall: 260 nsec/call
clock-getres-boottime:    libc: 267 nsec/call
clock-getres-boottime:    vdso: 259 nsec/call
clock-gettime-realtime: syscall: 344 nsec/call
clock-gettime-realtime:    libc: 73 nsec/call
clock-gettime-realtime:    vdso: 72 nsec/call
clock-getres-realtime: syscall: 255 nsec/call
clock-getres-realtime:    libc: 7 nsec/call
clock-getres-realtime:    vdso: 4 nsec/call
clock-gettime-realtime-coarse: syscall: 296 nsec/call
clock-gettime-realtime-coarse:    libc: 35 nsec/call
clock-gettime-realtime-coarse:    vdso: 33 nsec/call
clock-getres-realtime-coarse: syscall: 258 nsec/call
clock-getres-realtime-coarse:    libc: 6 nsec/call
clock-getres-realtime-coarse:    vdso: 4 nsec/call
getcpu: syscall: 237 nsec/call
getcpu:    libc: 242 nsec/call
getcpu:    vdso: not tested
Note: vDSO version of getcpu not found
gettimeofday: syscall: 378 nsec/call
gettimeofday:    libc: 73 nsec/call
gettimeofday:    vdso: 70 nsec/call

Observed good improvement for some APIs with the patch.

Tested-by: Shijith Thotton <sthotton@marvell.com>

Thanks,
Shijith
Vincenzo Frascino June 20, 2019, 8:55 a.m. UTC | #8
Hi Shijith,

...

> Observed good improvement for some APIs with the patch.
> 

Looks good. Thanks for testing the set, I will add your tag to my patches.

> Tested-by: Shijith Thotton <sthotton@marvell.com>
> 
> Thanks,
> Shijith
>
Andre Przywara June 20, 2019, 4:27 p.m. UTC | #9
On Thu, 30 May 2019 15:15:12 +0100
Vincenzo Frascino <vincenzo.frascino@arm.com> wrote:

Hi,

> vDSO (virtual dynamic shared object) is a mechanism that the Linux
> kernel provides as an alternative to system calls to reduce where
> possible the costs in terms of cycles.
> [ ... ]
> The porting has been benchmarked and the performance results are
> provided as part of this cover letter.

I can't reveal the absolute numbers here, but vdsotest-bench gives me
quite some performance gain on my board here ("time needed on v6" divided
by "time needed on 5.2-rc1", so smaller percentages are better):
clock-gettime-monotonic:	23 %
clock-gettime-monotonic-raw:	30 %
clock-gettime-tai:		 5 %
clock-getres-tai:		 5 %
clock-gettime-boottime:		 5 %
clock-getres-boottime:		 5 %
clock-gettime-realtime:		25 %
gettimeofday:			26 % 
The other numbers stayed the same or differed by just 1 ns, which seems to
be within the margin of error, as repeated runs on the same kernel suggest.
The 5% numbers are of course those were we went from a syscall-only to the
newly added arm64 VDSO implementation, but even the other calls improved
by a factor of 3 or more.

Sounds like a strong indicator that this is a good thing to have.

Not sure if "running some benchmark a couple of times on a single machine"
qualifies for this, but I guess it means:

Tested-by: Andre Przywara <andre.przywara@arm.com>

Cheers,
Andre.
Vincenzo Frascino June 21, 2019, 9:11 a.m. UTC | #10
On 20/06/2019 17:27, Andre Przywara wrote:
> On Thu, 30 May 2019 15:15:12 +0100
> Vincenzo Frascino <vincenzo.frascino@arm.com> wrote:
> 
> Hi,
> 
>> vDSO (virtual dynamic shared object) is a mechanism that the Linux
>> kernel provides as an alternative to system calls to reduce where
>> possible the costs in terms of cycles.
>> [ ... ]
>> The porting has been benchmarked and the performance results are
>> provided as part of this cover letter.
> 
> I can't reveal the absolute numbers here, but vdsotest-bench gives me
> quite some performance gain on my board here ("time needed on v6" divided
> by "time needed on 5.2-rc1", so smaller percentages are better):
> clock-gettime-monotonic:	23 %
> clock-gettime-monotonic-raw:	30 %
> clock-gettime-tai:		 5 %
> clock-getres-tai:		 5 %
> clock-gettime-boottime:		 5 %
> clock-getres-boottime:		 5 %
> clock-gettime-realtime:		25 %
> gettimeofday:			26 % 
> The other numbers stayed the same or differed by just 1 ns, which seems to
> be within the margin of error, as repeated runs on the same kernel suggest.
> The 5% numbers are of course those were we went from a syscall-only to the
> newly added arm64 VDSO implementation, but even the other calls improved
> by a factor of 3 or more.
> 
> Sounds like a strong indicator that this is a good thing to have.
> 
> Not sure if "running some benchmark a couple of times on a single machine"
> qualifies for this, but I guess it means:
> 
> Tested-by: Andre Przywara <andre.przywara@arm.com>
>

Thanks Andre, it sounds great! I will add your tag as well to my patches.

> Cheers,
> Andre.
>