• Nathan Lynch's avatar
    ARM: 8331/1: VDSO initialization, mapping, and synchronization · ecf99a43
    Nathan Lynch authored
    Initialize the VDSO page list at boot, install the VDSO mapping at
    exec time, and update the data page during timer ticks.  This code is
    not built if CONFIG_VDSO is not enabled.
    
    Account for the VDSO length when randomizing the offset from the
    stack.  The [vdso] and [vvar] pages are placed immediately following
    the sigpage with separate _install_special_mapping calls.
    
    We want to "penalize" systems lacking the arch timer as little
    as possible.  Previous versions of this code installed the VDSO
    unconditionally and unmodified, making it a measurably slower way for
    glibc to invoke the real syscalls on such systems.  E.g. calling
    gettimeofday via glibc goes from ~560ns to ~630ns on i.MX6Q.
    
    If we can indicate to glibc that the time-related APIs in the VDSO are
    not accelerated, glibc can continue to invoke the syscalls directly
    instead of dispatching through the VDSO only to fall back to the slow
    path.
    
    Thus, if the architected timer is unusable for whatever reason, patch
    the VDSO at boot time so that symbol lookups for gettimeofday and
    clock_gettime return NULL.  (This is similar to what powerpc does and
    borrows code from there.)  This allows glibc to perform the syscall
    directly instead of passing control to the VDSO, which minimizes the
    penalty.  In my measurements the time taken for a gettimeofday call
    via glibc goes from ~560ns to ~580ns (again on i.MX6Q), and this is
    solely due to adding a test and branch to glibc's gettimeofday syscall
    wrapper.
    
    An alternative to patching the VDSO at boot would be to not install
    the VDSO at all when the arch timer isn't usable.  Another alternative
    is to include a separate "dummy" vdso.so without gettimeofday and
    clock_gettime, which would be selected at boot time.  Either of these
    would get cumbersome if the VDSO were to gain support for an API such
    as getcpu which is unrelated to arch timer support.
    Signed-off-by: default avatarNathan Lynch <nathan_lynch@mentor.com>
    Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
    ecf99a43
vdso.c 8.4 KB