vdso support for s390
cover vdso support for s390
Greetings,
the two patches in this series add a vdso to s390 for three system calls:
1) gettimeofday
2) clock_getres for CLOCK_REALTIME and CLOCK_MONOTONIC
3) clock_gettime for CLOCK_REALTIME and CLOCK_MONOTONIC
The vdso code for gettimeofday is about 4-5 times faster than the system call. Similar results for clock_gettime.
The first of the two patches changes the arch_setup_additional_pages function. The second argument is unused and can be removed. For the s390 vdso I want to know if the elf executable is dynamically linked or not. Only if an interpreter is used the vdso is mapped. This adds a second argument to arch_setup_additional_pages again but with a different semantic.
Signature · 4 lines
blue skies, Martin. "Reality continues to ruin my life." - Calvin.
PATCH 1/2 arch_setup_additional_pages arguments
From: Martin Schwidefsky <[email protected]>
arch_setup_additional_pages currently gets two arguments, the binary format descripton and an indication if the process uses an executable stack or not. The second argument is not used by anybody, it could be removed without replacement.
What actually does make sense is to pass an indication if the process uses the elf interpreter or not. The glibc code will not use anything from the vdso if the process does not use the dynamic linker, so for statically linked binaries the architecture backend can choose not to map the vdso.
---
arch/powerpc/include/asm/elf.h | 2 +- arch/powerpc/kernel/vdso.c | 3 +-- arch/sh/include/asm/elf.h | 2 +- arch/sh/kernel/vsyscall/vsyscall.c | 3 +-- arch/x86/vdso/vdso32-setup.c | 2 +- arch/x86/vdso/vma.c | 2 +- fs/binfmt_elf.c | 2 +- include/asm-x86/elf.h | 2 +- 8 files changed, 8 insertions(+), 10 deletions(-)
arch/powerpc/include/asm/elf.h +1 -1
@@ -267,7 +267,7 @@ extern int ucache_bsize;#define ARCH_HAS_SETUP_ADDITIONAL_PAGES struct linux_binprm ;extern int arch_setup_additional_pages (struct linux_binprm *bprm, -int executable_stack); +int uses_interp);#define VDSO_AUX_ENT (a,b) NEW_AUX_ENT(a,b);#endif /* __KERNEL__ */
arch/powerpc/kernel/vdso.c +1 -2
@@ -184,8 +184,7 @@ static void dump_vdso_pages(struct vm_ar* This is called from binfmt_elf, we create the special vma for the * vDSO and insert it into the mm struct tree */ -int arch_setup_additional_pages (struct linux_binprm *bprm, -int executable_stack) +int arch_setup_additional_pages (struct linux_binprm *bprm,int uses_interp) {struct mm_struct *mm = current->mm;struct page **vdso_pagelist;
arch/sh/include/asm/elf.h +1 -1
@@ -202,7 +202,7 @@ extern int dump_task_fpu (struct task_st#define ARCH_HAS_SETUP_ADDITIONAL_PAGES struct linux_binprm ;extern int arch_setup_additional_pages (struct linux_binprm *bprm, -int executable_stack); +int uses_interp);extern unsigned int vdso_enabled;extern void __kernel_vsyscall;
arch/sh/kernel/vsyscall/vsyscall.c +1 -2
@@ -59,8 +59,7 @@ int __init vsyscall_init(void) }/* Setup a VMA at program startup for the vsyscall page */ -int arch_setup_additional_pages (struct linux_binprm *bprm, -int executable_stack) +int arch_setup_additional_pages (struct linux_binprm *bprm,int uses_interp) {struct mm_struct *mm = current->mm;unsigned long addr;
arch/x86/vdso/vdso32-setup.c +1 -1
@@ -310,7 +310,7 @@ int __init sysenter_setup(void) }/* Setup a VMA at program startup for the vsyscall page */ -int arch_setup_additional_pages (struct linux_binprm *bprm,int exstack) +int arch_setup_additional_pages (struct linux_binprm *bprm,int uses_interp) {struct mm_struct *mm = current->mm;unsigned long addr;
arch/x86/vdso/vma.c +1 -1
@@ -98,7 +98,7 @@ static unsigned long vdso_addr(unsigned/* Setup a VMA at program startup for the vsyscall page. Not called for compat tasks */ -int arch_setup_additional_pages (struct linux_binprm *bprm,int exstack) +int arch_setup_additional_pages (struct linux_binprm *bprm,int uses_interp) {struct mm_struct *mm = current->mm;unsigned long addr;
fs/binfmt_elf.c +1 -1
@@ -949,7 +949,7 @@ static int load_elf_binary(struct linux_set_binfmt (&elf_format);#ifdef ARCH_HAS_SETUP_ADDITIONAL_PAGES - retval =arch_setup_additional_pages (bprm, executable_stack); + retval =arch_setup_additional_pages (bprm, !!elf_interpreter);if (retval <0 ) {send_sig (SIGKILL , current,0 ); goto out;
include/asm-x86/elf.h +1 -1
@@ -325,7 +325,7 @@ struct linux_binprm;#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1extern int arch_setup_additional_pages (struct linux_binprm *bprm, -int executable_stack); +int uses_interp);extern int syscall32_setup_pages (struct linux_binprm *,int exstack);#define compat_arch_setup_additional_pages syscall32_setup_pages
Signature · 4 lines
blue skies, Martin. "Reality continues to ruin my life." - Calvin.
PATCH 2/2 introduce vdso on s390
In reply to Martin SchwidefskyFrom: Martin Schwidefsky <[email protected]>
Add a vdso to speed up gettimeofday and clock_getres/clock_gettime for CLOCK_REALTIME/CLOCK_MONOTONIC.
---
arch/s390/Kconfig | 3 arch/s390/include/asm/auxvec.h | 2 arch/s390/include/asm/elf.h | 16 ++ arch/s390/include/asm/mmu.h | 1 arch/s390/include/asm/page.h | 2 arch/s390/include/asm/vdso.h | 39 +++++ arch/s390/kernel/Makefile | 9 - arch/s390/kernel/asm-offsets.c | 15 ++ arch/s390/kernel/time.c | 31 ++++ arch/s390/kernel/vdso.c | 232 +++++++++++++++++++++++++++++++ arch/s390/kernel/vdso32/Makefile | 55 +++++++ arch/s390/kernel/vdso32/clock_getres.S | 39 +++++ arch/s390/kernel/vdso32/clock_gettime.S | 128 +++++++++++++++++ arch/s390/kernel/vdso32/gettimeofday.S | 82 ++++++++++ arch/s390/kernel/vdso32/note.S | 12 + arch/s390/kernel/vdso32/vdso32.lds.S | 138 ++++++++++++++++++ arch/s390/kernel/vdso32/vdso32_wrapper.S | 13 + arch/s390/kernel/vdso64/Makefile | 55 +++++++ arch/s390/kernel/vdso64/clock_getres.S | 39 +++++ arch/s390/kernel/vdso64/clock_gettime.S | 89 +++++++++++ arch/s390/kernel/vdso64/gettimeofday.S | 56 +++++++ arch/s390/kernel/vdso64/note.S | 12 + arch/s390/kernel/vdso64/vdso64.lds.S | 138 ++++++++++++++++++ arch/s390/kernel/vdso64/vdso64_wrapper.S | 13 + 24 files changed, 1217 insertions(+), 2 deletions(-)
arch/s390/include/asm/auxvec.h +2 -0
@@ -1,4 +1,6 @@#ifndef __ASMS390_AUXVEC_H#define __ASMS390_AUXVEC_H +#define AT_SYSINFO_EHDR 33 +#endif
arch/s390/include/asm/elf.h +16 -0
@@ -120,6 +120,10 @@ typedef s390_compat_regs compat_elf_greg#include <asm/system.h> /* for save_access_regs */ #include <asm/mmu_context.h> +#include <asm/vdso.h> + +extern unsigned int vdso_enabled; +/* * This is used to ensure we don't load something for the wrong architecture. */
@@ -193,4 +197,16 @@ do { \ current->mm->context.noexec ==0 ; \ }) +#define ARCH_DLINFO \ +do { \ + if (vdso_enabled) \ + NEW_AUX_ENT(AT_SYSINFO_EHDR, \ + (unsigned long)current->mm->context.vdso_base); \ +} while (0) + +struct linux_binprm ; + +#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1 +int arch_setup_additional_pages (struct linux_binprm *,int ); +#endif
arch/s390/include/asm/mmu.h +1 -0
@@ -6,6 +6,7 @@ typedef struct {struct list_head pgtable_list;unsigned long asce_bits;unsigned long asce_limit; +unsigned long vdso_base;int noexec;int has_pgste;/* The mmu context has extended page tables */ int alloc_pgste;/* cloned contexts will have extended page tables */
arch/s390/include/asm/page.h +2 -0
@@ -152,4 +152,6 @@ void arch_alloc_page(struct page *page,#include <asm-generic/memory_model.h> #include <asm-generic/page.h> +#define __HAVE_ARCH_GATE_AREA 1 +#endif /* _S390_PAGE_H */
arch/s390/include/asm/vdso.h new file +39 -0
@@ -0,0 +1,39 @@ +#ifndef __S390_VDSO_H__ +#define __S390_VDSO_H__ + +#ifdef __KERNEL__ + +/* Default link addresses for the vDSOs */ +#define VDSO32_LBASE 0 +#define VDSO64_LBASE 0 + +#define VDSO_VERSION_STRING LINUX_2.6.26 + +#ifndef __ASSEMBLY__ + +/* +* Note about this structure: +* +* NEVER USE THIS IN USERSPACE CODE DIRECTLY. The layout of this +* structure is supposed to be known only to the function in the vdso +* itself and may change without notice. +*/ + +struct vdso_data { +__u64 tb_update_count;/* Timebase atomicity ctr 0x00 */ +__u64 xtime_tod_stamp;/* TOD clock for xtime 0x08 */ +__u64 xtime_clock_sec;/* Kernel time 0x10 */ +__u64 xtime_clock_nsec;/* 0x18 */ +__u64 wtom_clock_sec;/* Wall to monotonic clock 0x20 */ +__u64 wtom_clock_nsec;/* 0x28 */ +__u32 tz_minuteswest;/* Minutes west of Greenwich 0x30 */ +__u32 tz_dsttime;/* Type of dst correction 0x34 */ +}; + +extern struct vdso_data *vdso_data; + +#endif /* __ASSEMBLY__ */ + +#endif /* __KERNEL__ */ + +#endif /* __S390_VDSO_H__ */
arch/s390/Kconfig +3 -0
@@ -43,6 +43,9 @@ config GENERIC_HWEIGHT config GENERIC_TIME def_bool y +config GENERIC_TIME_VSYSCALL + def_bool y + config GENERIC_CLOCKEVENTS def_bool y
arch/s390/kernel/asm-offsets.c +15 -0
@@ -6,6 +6,7 @@#include <linux/sched.h> #include <linux/kbuild.h> +#include <asm/vdso.h> int main (void ) {
@@ -38,5 +39,19 @@ int main(void)DEFINE (__SF_BACKCHAIN, offsetof(struct stack_frame , back_chain));DEFINE (__SF_GPRS, offsetof(struct stack_frame , gprs));DEFINE (__SF_EMPTY, offsetof(struct stack_frame , empty1)); +BLANK (); +/* timeval/timezone offsets for use by vdso */ +DEFINE (__VDSO_UPD_COUNT, offsetof(struct vdso_data , tb_update_count)); +DEFINE (__VDSO_XTIME_STAMP, offsetof(struct vdso_data , xtime_tod_stamp)); +DEFINE (__VDSO_XTIME_SEC, offsetof(struct vdso_data , xtime_clock_sec)); +DEFINE (__VDSO_XTIME_NSEC, offsetof(struct vdso_data , xtime_clock_nsec)); +DEFINE (__VDSO_WTOM_SEC, offsetof(struct vdso_data , wtom_clock_sec)); +DEFINE (__VDSO_WTOM_NSEC, offsetof(struct vdso_data , wtom_clock_nsec)); +DEFINE (__VDSO_TIMEZONE, offsetof(struct vdso_data , tz_minuteswest)); +/* constants used by the vdso */ +DEFINE (CLOCK_REALTIME ,CLOCK_REALTIME ); +DEFINE (CLOCK_MONOTONIC ,CLOCK_MONOTONIC ); +DEFINE (CLOCK_REALTIME_RES ,MONOTONIC_RES_NSEC ); +return 0 ; }
arch/s390/kernel/Makefile +7 -2
@@ -13,8 +13,9 @@ CFLAGS_smp.o := -Wno-nonnull CFLAGS_ptrace.o += -DUTS_MACHINE='"$(UTS_MACHINE)"' obj-y := bitmap.o traps.o time.o process.o base.o early.o \ - setup.o sys_s390.o ptrace.o signal.o cpcmd.o ebcdic.o \ - s390_ext.o debug.o irq.o ipl.o dis.o diag.o mem_detect.o + setup.o sys_s390.o ptrace.o signal.o cpcmd.o ebcdic.o \ + s390_ext.o debug.o irq.o ipl.o dis.o diag.o mem_detect.o \ + vdso.o obj-y += $(if $(CONFIG_64BIT),entry64.o,entry.o) obj-y += $(if $(CONFIG_64BIT),reipl64.o,reipl.o)
@@ -39,3 +40,7 @@ S390_KEXEC_OBJS := machine_kexec.o crash S390_KEXEC_OBJS += $(if $(CONFIG_64BIT),relocate_kernel64.o,relocate_kernel.o) obj-$(CONFIG_KEXEC) += $(S390_KEXEC_OBJS) +# vdso +obj-$(CONFIG_64BIT) += vdso64/ +obj-$(CONFIG_32BIT) += vdso32/ +obj-$(CONFIG_COMPAT) += vdso32/
arch/s390/kernel/time.c +31 -0
@@ -36,6 +36,7 @@#include <asm/delay.h> #include <asm/s390_ext.h> #include <asm/div64.h> +#include <asm/vdso.h> #include <asm/irq.h> #include <asm/irq_regs.h> #include <asm/timer.h>
@@ -223,6 +224,36 @@ static struct clocksource clocksource_to }; +void update_vsyscall (struct timespec *wall_time,struct clocksource *clock) +{ +if (clock != &clocksource_tod) +return ; + +/* Make userspace gettimeofday spin until we're done. */ + ++vdso_data->tb_update_count; +smp_mb (); + vdso_data->xtime_tod_stamp = clock->cycle_last; + vdso_data->xtime_clock_sec = xtime.tv_sec; + vdso_data->xtime_clock_nsec = xtime.tv_nsec; + vdso_data->wtom_clock_sec = wall_to_monotonic.tv_sec; + vdso_data->wtom_clock_nsec = wall_to_monotonic.tv_nsec; +smp_wmb (); + ++(vdso_data->tb_update_count); +} + +extern struct timezone sys_tz; + +void update_vsyscall_tz (void ) +{ +/* Make userspace gettimeofday spin until we're done. */ + ++vdso_data->tb_update_count; +smp_mb (); + vdso_data->tz_minuteswest = sys_tz.tz_minuteswest; + vdso_data->tz_dsttime = sys_tz.tz_dsttime; +smp_mb (); + ++vdso_data->tb_update_count; +} +/* * Initialize the TOD clock and the CPU timer of * the boot cpu.
arch/s390/kernel/vdso32/clock_getres.S new file +39 -0
@@ -0,0 +1,39 @@ +/* + * Userland implementation of clock_getres() for 32 bits processes in a + * s390 kernel for use in the vDSO + * + * Copyright IBM Corp. 2008 + * Author(s): Martin Schwidefsky ([email protected]) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License (version 2 only) + * as published by the Free Software Foundation. + */ +#include <asm/vdso.h> +#include <asm/asm-offsets.h> +#include <asm/unistd.h> + + .text + .align 4 + .globl __kernel_clock_getres + .type __kernel_clock_getres,@function +__kernel_clock_getres: + .cfi_startproc + chi %r2,CLOCK_REALTIME + je 0f + chi %r2,CLOCK_MONOTONIC + jne 3f +0: ltr %r3,%r3 + jz 2f /* res == NULL */ + basr %r1,0 +1: l %r0,4f-1b(%r1) + xc 0(4,%r3),0(%r3) /* set tp->tv_sec to zero */ + st %r0,4(%r3) /* store tp->tv_usec */ +2: lhi %r2,0 + br %r14 +3: lhi %r1,__NR_clock_getres /* fallback to svc */ + svc 0 + br %r14 +4: .long CLOCK_REALTIME_RES + .cfi_endproc + .size __kernel_clock_getres,.-__kernel_clock_getres
arch/s390/kernel/vdso32/clock_gettime.S new file +128 -0
128 lines not on this page · raw message
arch/s390/kernel/vdso32/gettimeofday.S new file +82 -0
82 lines not on this page · raw message
arch/s390/kernel/vdso32/Makefile new file +55 -0
55 lines not on this page · raw message
arch/s390/kernel/vdso32/note.S new file +12 -0
@@ -0,0 +1,12 @@ +/* + * This supplies .note.* sections to go into the PT_NOTE inside the vDSO text. + * Here we can supply some information useful to userland. + */ + +#include <linux/uts.h> +#include <linux/version.h> +#include <linux/elfnote.h> + +ELFNOTE_START(Linux, 0, "a") + .long LINUX_VERSION_CODE +ELFNOTE_END
arch/s390/kernel/vdso32/vdso32.lds.S new file +138 -0
138 lines not on this page · raw message
arch/s390/kernel/vdso32/vdso32_wrapper.S new file +13 -0
@@ -0,0 +1,13 @@ +#include <linux/init.h> +#include <asm/page.h> + + .section ".data.page_aligned" + + .globl vdso32_start, vdso32_end + .balign PAGE_SIZE +vdso32_start: + .incbin "arch/s390/kernel/vdso32/vdso32.so" + .balign PAGE_SIZE +vdso32_end: + + .previous
arch/s390/kernel/vdso64/clock_getres.S new file +39 -0
@@ -0,0 +1,39 @@ +/* + * Userland implementation of clock_getres() for 64 bits processes in a + * s390 kernel for use in the vDSO + * + * Copyright IBM Corp. 2008 + * Author(s): Martin Schwidefsky ([email protected]) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License (version 2 only) + * as published by the Free Software Foundation. + */ +#include <asm/vdso.h> +#include <asm/asm-offsets.h> +#include <asm/unistd.h> + + .text + .align 4 + .globl __kernel_clock_getres + .type __kernel_clock_getres,@function +__kernel_clock_getres: + .cfi_startproc + cghi %r2,CLOCK_REALTIME + je 0f + cghi %r2,CLOCK_MONOTONIC + jne 2f +0: ltgr %r3,%r3 + jz 1f /* res == NULL */ + larl %r1,3f + lg %r0,0(%r1) + xc 0(8,%r3),0(%r3) /* set tp->tv_sec to zero */ + stg %r0,8(%r3) /* store tp->tv_usec */ +1: lghi %r2,0 + br %r14 +2: lghi %r1,__NR_clock_getres /* fallback to svc */ + svc 0 + br %r14 +3: .quad CLOCK_REALTIME_RES + .cfi_endproc + .size __kernel_clock_getres,.-__kernel_clock_getres
arch/s390/kernel/vdso64/clock_gettime.S new file +89 -0
89 lines not on this page · raw message
arch/s390/kernel/vdso64/gettimeofday.S new file +56 -0
56 lines not on this page · raw message
arch/s390/kernel/vdso64/Makefile new file +55 -0
55 lines not on this page · raw message
arch/s390/kernel/vdso64/note.S new file +12 -0
@@ -0,0 +1,12 @@ +/* + * This supplies .note.* sections to go into the PT_NOTE inside the vDSO text. + * Here we can supply some information useful to userland. + */ + +#include <linux/uts.h> +#include <linux/version.h> +#include <linux/elfnote.h> + +ELFNOTE_START(Linux, 0, "a") + .long LINUX_VERSION_CODE +ELFNOTE_END
arch/s390/kernel/vdso64/vdso64.lds.S new file +138 -0
138 lines not on this page · raw message
arch/s390/kernel/vdso64/vdso64_wrapper.S new file +13 -0
@@ -0,0 +1,13 @@ +#include <linux/init.h> +#include <asm/page.h> + + .section ".data.page_aligned" + + .globl vdso64_start, vdso64_end + .balign PAGE_SIZE +vdso64_start: + .incbin "arch/s390/kernel/vdso64/vdso64.so" + .balign PAGE_SIZE +vdso64_end: + + .previous
arch/s390/kernel/vdso.c new file +232 -0
232 lines not on this page · raw message
Signature · 4 lines
blue skies, Martin. "Reality continues to ruin my life." - Calvin.
Re: [patch 2/2] introduce vdso on s390
Quoted 4 lines · Martin Schwidefsky
arch/s390/kernel/time.c +4
-0+void update_vsyscall (struct timespec *wall_time,struct clocksource *clock) +{ +if (clock != &clocksource_tod) +return ;
arch/s390/kernel/time.c static struct clocksource clocksource_to · line 240
Quoted 10 lines
arch/s390/kernel/time.c +10
-0+ +/* Make userspace gettimeofday spin until we're done. */ + ++vdso_data->tb_update_count; +smp_mb (); + vdso_data->xtime_tod_stamp = clock->cycle_last; + vdso_data->xtime_clock_sec = xtime.tv_sec; + vdso_data->xtime_clock_nsec = xtime.tv_nsec; + vdso_data->wtom_clock_sec = wall_to_monotonic.tv_sec; + vdso_data->wtom_clock_nsec = wall_to_monotonic.tv_nsec; +smp_wmb ();
Different barriers?
arch/s390/kernel/time.c static struct clocksource clocksource_to · line 241
Quoted 1 line
arch/s390/kernel/time.c +1
-0+ ++(vdso_data->tb_update_count);
Why ++(...)?
Bastian
Signature · 2 lines
Either one of us, by himself, is expendable. Both of us are not. -- Kirk, "The Devil in the Dark", stardate 3196.1
Re: [patch 2/2] introduce vdso on s390
Quoted 17 lines · Bastian Blank
Quoted 4 lines · Martin Schwidefsky
arch/s390/kernel/time.c +4
-0+void update_vsyscall (struct timespec *wall_time,struct clocksource *clock) +{ +if (clock != &clocksource_tod) +return ;arch/s390/kernel/time.c static struct clocksource clocksource_to · line 240
Quoted 10 lines
arch/s390/kernel/time.c +10
-0+ +/* Make userspace gettimeofday spin until we're done. */ + ++vdso_data->tb_update_count; +smp_mb (); + vdso_data->xtime_tod_stamp = clock->cycle_last; + vdso_data->xtime_clock_sec = xtime.tv_sec; + vdso_data->xtime_clock_nsec = xtime.tv_nsec; + vdso_data->wtom_clock_sec = wall_to_monotonic.tv_sec; + vdso_data->wtom_clock_nsec = wall_to_monotonic.tv_nsec; +smp_wmb ();Different barriers?
Doesn't matter. They are all the same anyway on s390. But I changed it to smp_wmb instead.
Quoted 3 lines
arch/s390/kernel/time.c static struct clocksource clocksource_to · line 241
Quoted 1 line
arch/s390/kernel/time.c +1
-0+ ++(vdso_data->tb_update_count);Why ++(...)?
Removed the braces.