powerpc: switch VDSO to C implementation.
Subsystems (3)
v3 cover powerpc: switch VDSO to C implementation.
This is a third tentative to switch powerpc VDSO to generic C implementation.
This version should work on PPC64 (untested). VDSO32 for PPC64 is impossible to build and has been de-activated, because the powerpc ASM header files for C are not prepared to build 32 bits code with CONFIG_PPC64.
powerpc is a bit special for VDSO as well as system calls in the way that it requires setting CR SO bit which cannot be done in C. Therefore, entry/exit and fallback need to be performed in ASM.
On a powerpc8xx, with current powerpc/32 ASM VDSO:
gettimeofday: vdso: 737 nsec/call clock-getres-realtime: vdso: 475 nsec/call clock-gettime-realtime: vdso: 892 nsec/call
The first patch adds VDSO generic C support without any changes to common code. Performance is as follows:
gettimeofday: vdso: 1379 nsec/call clock-getres-realtime-coarse: vdso: 984 nsec/call clock-gettime-realtime-coarse: vdso: 868 nsec/call clock-getres-realtime: vdso: 922 nsec/call clock-gettime-realtime: vdso: 1511 nsec/call clock-getres-monotonic-raw: vdso: 968 nsec/call clock-gettime-monotonic-raw: vdso: 1576 nsec/call
Then a few changes in the common code have allowed performance improvement. At the end of the series we have:
gettimeofday: vdso: 899 nsec/call clock-getres-realtime-coarse: vdso: 546 nsec/call clock-gettime-realtime-coarse: vdso: 615 nsec/call clock-getres-realtime: vdso: 545 nsec/call clock-gettime-realtime: vdso: 1064 nsec/call clock-getres-monotonic-raw: vdso: 546 nsec/call clock-gettime-monotonic-raw: vdso: 1125 nsec/call
Christophe Leroy (12):
powerpc/64: Don't provide time functions in compat VDSO32 powerpc/vdso: Switch VDSO to generic C implementation.
lib: vdso: mark __cvdso_clock_getres() as static
lib: vdso: inline do_hres() and do_coarse()
lib: vdso: Avoid duplication in __cvdso_clock_getres()
lib: vdso: __iter_div_u64_rem() is suboptimal for 32 bit time powerpc/vdso: simplify __get_datapage()
lib: vdso: allow arches to provide vdso data pointer powerpc/vdso: provide inline alternative to __get_datapage() powerpc/vdso: provide vdso data pointer from the ASM caller.
lib: vdso: split clock verification out of __arch_get_hw_counter() powerpc/vdso: provide __arch_is_hw_counter_valid()
arch/powerpc/Kconfig | 2 + arch/powerpc/include/asm/vdso/gettimeofday.h | 104 +++++++++++ arch/powerpc/include/asm/vdso/vsyscall.h | 25 +++ arch/powerpc/include/asm/vdso_datapage.h | 52 +++--- arch/powerpc/kernel/asm-offsets.c | 46 +---- arch/powerpc/kernel/time.c | 90 ---------- arch/powerpc/kernel/vdso.c | 58 ++---- arch/powerpc/kernel/vdso32/Makefile | 30 +++- arch/powerpc/kernel/vdso32/datapage.S | 10 +- arch/powerpc/kernel/vdso32/gettimeofday.S | 258 ++++----------------------- arch/powerpc/kernel/vdso32/vdso32.lds.S | 9 +- arch/powerpc/kernel/vdso32/vgettimeofday.c | 29 +++ arch/powerpc/kernel/vdso64/Makefile | 23 ++- arch/powerpc/kernel/vdso64/datapage.S | 13 +- arch/powerpc/kernel/vdso64/gettimeofday.S | 257 ++++---------------------- arch/powerpc/kernel/vdso64/vdso64.lds.S | 7 +- arch/powerpc/kernel/vdso64/vgettimeofday.c | 29 +++ lib/vdso/gettimeofday.c | 130 +++++++++++--- 18 files changed, 457 insertions(+), 715 deletions(-) create mode 100644 arch/powerpc/include/asm/vdso/gettimeofday.h create mode 100644 arch/powerpc/include/asm/vdso/vsyscall.h create mode 100644 arch/powerpc/kernel/vdso32/vgettimeofday.c create mode 100644 arch/powerpc/kernel/vdso64/vgettimeofday.c
Signature · 1 line
2.13.3
RFC PATCH v3 1/12 powerpc/64: Don't provide time functions in compat VDSO32
In order to allow use of generic C VDSO, remove time functions from the 32 bits VDSO on PPC64.
This (temporary) removal is needed because powerpc kernel C headers are not prepared for building 32 bits code on PPC64.
--- arch/powerpc/kernel/vdso32/Makefile | 3 ++- arch/powerpc/kernel/vdso32/vdso32.lds.S | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
arch/powerpc/kernel/vdso32/Makefile +2 -1
@@ -3,7 +3,8 @@ # List of files in the vdso, has to be asm only for now obj-vdso32-$(CONFIG_PPC64) = getcpu.o -obj-vdso32 = sigtramp.o gettimeofday.o datapage.o cacheflush.o note.o \ +obj-vdso32-$(CONFIG_PPC32) = gettimeofday.o +obj-vdso32 = sigtramp.o datapage.o cacheflush.o note.o \ $(obj-vdso32-y) # Build rules
arch/powerpc/kernel/vdso32/vdso32.lds.S +1 -1
@@ -144,7 +144,7 @@ VERSION __kernel_datapage_offset; __kernel_get_syscall_map; -#ifndef CONFIG_PPC_BOOK3S_601 +#if defined(CONFIG_PPC32) && !defined(CONFIG_PPC_BOOK3S_601) __kernel_gettimeofday; __kernel_clock_gettime; __kernel_clock_getres;
Signature · 1 line
2.13.3
RFC PATCH v3 4/12 lib: vdso: inline do_hres() and do_coarse()
In reply to Christophe Leroydo_hres() is called from several places, so GCC doesn't inline it at first.
do_hres() takes a struct __kernel_timespec * parameter for passing the result. In the 32 bits case, this parameter corresponds to a local var in the caller. In order to provide a pointer to this structure, the caller has to put it in its stack and do_hres() has to write the result in the stack. This is suboptimal, especially on RISC processor like powerpc.
By making GCC inline the function, the struct __kernel_timespec remains a local var using registers, avoiding the need to write and read stack.
The improvement is significant on powerpc:
Before:
gettimeofday: vdso: 1379 nsec/call clock-gettime-realtime-coarse: vdso: 868 nsec/call clock-gettime-realtime: vdso: 1511 nsec/call clock-gettime-monotonic-raw: vdso: 1576 nsec/call
After:
gettimeofday: vdso: 1078 nsec/call clock-gettime-realtime-coarse: vdso: 807 nsec/call clock-gettime-realtime: vdso: 1256 nsec/call clock-gettime-monotonic-raw: vdso: 1316 nsec/call
At the same time, change the return type of do_coarse() to int, this increase readability of the if/elseif/elseif/else section in __cvdso_clock_gettime_common()
--- lib/vdso/gettimeofday.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-)
lib/vdso/gettimeofday.c +16 -13
@@ -38,8 +38,8 @@ u64 vdso_calc_delta(u64 cycles, u64 last, u64 mask, u32 mult) }#endif -static int do_hres (const struct vdso_data *vd,clockid_t clk, -struct __kernel_timespec *ts) +static __always_inline int do_hres(const struct vdso_data *vd, clockid_t clk, +struct __kernel_timespec *ts) {const struct vdso_timestamp *vdso_ts = &vd->basetime[clk];u64 cycles, last, sec, ns;
@@ -68,8 +68,8 @@ static int do_hres(const struct vdso_data *vd, clockid_t clk,return 0 ; } -static void do_coarse (const struct vdso_data *vd,clockid_t clk, -struct __kernel_timespec *ts) +static __always_inline int do_coarse(const struct vdso_data *vd, clockid_t clk, +struct __kernel_timespec *ts) {const struct vdso_timestamp *vdso_ts = &vd->basetime[clk];u32 seq;
@@ -79,6 +79,8 @@ static void do_coarse(const struct vdso_data *vd, clockid_t clk, ts->tv_sec = vdso_ts->sec; ts->tv_nsec = vdso_ts->nsec; }while (unlikely (vdso_read_retry (vd, seq))); + +return 0 ; } static __maybe_unused int
@@ -96,15 +98,16 @@ __cvdso_clock_gettime_common(clockid_t clock, struct __kernel_timespec *ts)* clocks are handled in the VDSO directly. */ msk =1U << clock; -if (likely (msk &VDSO_HRES )) { -return do_hres (&vd[CS_HRES_COARSE ], clock, ts); - }else if (msk &VDSO_COARSE ) { -do_coarse (&vd[CS_HRES_COARSE ], clock, ts); -return 0 ; - }else if (msk &VDSO_RAW ) { -return do_hres (&vd[CS_RAW ], clock, ts); - } -return -1 ; +if (likely (msk &VDSO_HRES )) + vd +=CS_HRES_COARSE ; +else if (msk &VDSO_COARSE ) +return do_coarse (&vd[CS_HRES_COARSE ], clock, ts); +else if (msk &VDSO_RAW ) + vd +=CS_RAW ; +else +return -1 ; + +return do_hres (vd, clock, ts); } static __maybe_unused int
Signature · 1 line
2.13.3
RFC PATCH v3 5/12 lib: vdso: Avoid duplication in __cvdso_clock_getres()
In reply to Christophe LeroyVDSO_HRES and VDSO_RAW clocks are handled the same way.
Don't duplicate code.
Before the patch:
clock-getres-monotonic-raw: vdso: 737 nsec/call clock-getres-monotonic-coarse: vdso: 753 nsec/call clock-getres-monotonic: vdso: 691 nsec/call
After the patch:
clock-getres-monotonic-raw: vdso: 715 nsec/call clock-getres-monotonic-coarse: vdso: 715 nsec/call clock-getres-monotonic: vdso: 714 nsec/call
--- lib/vdso/gettimeofday.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
lib/vdso/gettimeofday.c +2 -9
@@ -184,7 +184,6 @@ static __maybe_unusedint __cvdso_clock_getres_common (clockid_t clock,struct __kernel_timespec *res) {const struct vdso_data *vd =__arch_get_vdso_data (); -u64 hrtimer_res;u32 msk;u64 ns;
@@ -192,27 +191,21 @@ int __cvdso_clock_getres_common(clockid_t clock, struct __kernel_timespec *res)if (unlikely ((u32 ) clock >=MAX_CLOCKS ))return -1 ; - hrtimer_res =READ_ONCE (vd[CS_HRES_COARSE ].hrtimer_res);/* * Convert the clockid to a bitmask and use it to check which * clocks are handled in the VDSO directly. */ msk =1U << clock; -if (msk &VDSO_HRES ) { +if (msk & (VDSO_HRES |VDSO_RAW )) {/* * Preserves the behaviour of posix_get_hrtimer_res(). */ - ns = hrtimer_res; + ns =READ_ONCE (vd[CS_HRES_COARSE ].hrtimer_res); }else if (msk &VDSO_COARSE ) {/* * Preserves the behaviour of posix_get_coarse_res(). */ ns =LOW_RES_NSEC ; - }else if (msk &VDSO_RAW ) { -/* -* Preserves the behaviour of posix_get_hrtimer_res(). -*/ - ns = hrtimer_res; }else {return -1 ; }
Signature · 1 line
2.13.3
RFC PATCH v3 7/12 powerpc/vdso: simplify __get_datapage()
In reply to Christophe LeroyThe VDSO datapage and the text pages are always located immediately next to each other, so it can be hardcoded without an indirection through __kernel_datapage_offset
In order to ease things, move the data page in front like other arches, that way there is no need to know the size of the library to locate the data page.
Before:
clock-getres-realtime-coarse: vdso: 714 nsec/call clock-gettime-realtime-coarse: vdso: 792 nsec/call clock-gettime-realtime: vdso: 1243 nsec/call
After:
clock-getres-realtime-coarse: vdso: 699 nsec/call clock-gettime-realtime-coarse: vdso: 784 nsec/call clock-gettime-realtime: vdso: 1231 nsec/call
--- arch/powerpc/kernel/vdso.c | 53 +++++---------------------------- arch/powerpc/kernel/vdso32/datapage.S | 10 +++---- arch/powerpc/kernel/vdso32/vdso32.lds.S | 7 ++--- arch/powerpc/kernel/vdso64/datapage.S | 10 +++---- arch/powerpc/kernel/vdso64/vdso64.lds.S | 7 ++--- 5 files changed, 19 insertions(+), 68 deletions(-)
arch/powerpc/kernel/vdso.c +7 -46
@@ -191,7 +191,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)* install_special_mapping or the perf counter mmap tracking code * will fail to recognise it as a vDSO (since arch_vma_name fails). */ - current->mm->context.vdso_base = vdso_base; + current->mm->context.vdso_base = vdso_base +PAGE_SIZE ;/* * our vma flags don't have VM_WRITE so by default, the process isn't
@@ -488,42 +488,6 @@ static __init void vdso_setup_trampolines(struct lib32_elfinfo *v32, vdso32_rt_sigtramp =find_function32 (v32,"__kernel_sigtramp_rt32" ); } -static __init int vdso_fixup_datapage (struct lib32_elfinfo *v32, -struct lib64_elfinfo *v64) -{ -#ifdef CONFIG_VDSO32 -Elf32_Sym *sym32; -#endif -#ifdef CONFIG_PPC64 -Elf64_Sym *sym64; - - sym64 =find_symbol64 (v64,"__kernel_datapage_offset" ); -if (sym64 ==NULL ) { -printk (KERN_ERR "vDSO64: Can't find symbol " -"__kernel_datapage_offset !\n" ); -return -1 ; - } - *((int *)(vdso64_kbase + sym64->st_value -VDSO64_LBASE )) = - (vdso64_pages <<PAGE_SHIFT ) - - (sym64->st_value -VDSO64_LBASE ); -#endif /* CONFIG_PPC64 */ - -#ifdef CONFIG_VDSO32 - sym32 =find_symbol32 (v32,"__kernel_datapage_offset" ); -if (sym32 ==NULL ) { -printk (KERN_ERR "vDSO32: Can't find symbol " -"__kernel_datapage_offset !\n" ); -return -1 ; - } - *((int *)(vdso32_kbase + (sym32->st_value -VDSO32_LBASE ))) = - (vdso32_pages <<PAGE_SHIFT ) - - (sym32->st_value -VDSO32_LBASE ); -#endif - -return 0 ; -} - -static __init int vdso_fixup_features (struct lib32_elfinfo *v32,struct lib64_elfinfo *v64) {
@@ -624,9 +588,6 @@ static __init int vdso_setup(void)if (vdso_do_find_sections (&v32, &v64))return -1 ; -if (vdso_fixup_datapage (&v32, &v64)) -return -1 ; -if (vdso_fixup_features (&v32, &v64))return -1 ;
@@ -771,26 +732,26 @@ static int __init vdso_init(void) vdso32_pagelist =kcalloc (vdso32_pages +2 ,sizeof (struct page *),GFP_KERNEL );BUG_ON (vdso32_pagelist ==NULL ); + vdso32_pagelist[0 ] =virt_to_page (vdso_data);for (i =0 ; i < vdso32_pages; i++) {struct page *pg =virt_to_page (vdso32_kbase + i*PAGE_SIZE );get_page (pg); - vdso32_pagelist[i] = pg; + vdso32_pagelist[i +1 ] = pg; } - vdso32_pagelist[i++] =virt_to_page (vdso_data); - vdso32_pagelist[i] =NULL ; + vdso32_pagelist[i +1 ] =NULL ;#endif #ifdef CONFIG_PPC64 vdso64_pagelist =kcalloc (vdso64_pages +2 ,sizeof (struct page *),GFP_KERNEL );BUG_ON (vdso64_pagelist ==NULL ); + vdso64_pagelist[0 ] =virt_to_page (vdso_data);for (i =0 ; i < vdso64_pages; i++) {struct page *pg =virt_to_page (vdso64_kbase + i*PAGE_SIZE );get_page (pg); - vdso64_pagelist[i] = pg; + vdso64_pagelist[i +1 ] = pg; } - vdso64_pagelist[i++] =virt_to_page (vdso_data); - vdso64_pagelist[i] =NULL ; + vdso64_pagelist[i +1 ] =NULL ;#endif /* CONFIG_PPC64 */ get_page (virt_to_page (vdso_data));
arch/powerpc/kernel/vdso32/datapage.S +4 -6
@@ -12,9 +12,6 @@ #include <asm/vdso.h> .text - .global __kernel_datapage_offset; -__kernel_datapage_offset: - .long 0 V_FUNCTION_BEGIN(__get_datapage) .cfi_startproc
@@ -31,10 +28,11 @@ V_FUNCTION_BEGIN(__get_datapage) data_page_branch: mflr r3 mtlr r0 - addi r3, r3, __kernel_datapage_offset-data_page_branch - lwz r0,0(r3) +#if CONFIG_PPC_PAGE_SHIFT > 14 + addis r3, r3, (_vdso_datapage - data_page_branch)@ha +#endif + addi r3, r3, (_vdso_datapage - data_page_branch)@l .cfi_restore lr - add r3,r0,r3 blr .cfi_endproc V_FUNCTION_END(__get_datapage)
arch/powerpc/kernel/vdso32/vdso32.lds.S +2 -5
@@ -4,6 +4,7 @@ * library */ #include <asm/vdso.h> +#include <asm/page.h> #ifdef __LITTLE_ENDIAN__ OUTPUT_FORMAT("elf32-powerpcle", "elf32-powerpcle", "elf32-powerpcle")
@@ -15,6 +16,7 @@ ENTRY(_start) SECTIONS { + PROVIDE(_vdso_datapage = . - PAGE_SIZE); . = VDSO32_LBASE + SIZEOF_HEADERS; .hash : { *(.hash) } :text
@@ -138,11 +140,6 @@ VERSION { VDSO_VERSION_STRING { global: - /* - * Has to be there for the kernel to find - */ - __kernel_datapage_offset; - __kernel_get_syscall_map; #if defined(CONFIG_PPC32) && !defined(CONFIG_PPC_BOOK3S_601) __kernel_gettimeofday;
arch/powerpc/kernel/vdso64/datapage.S +4 -6
@@ -12,9 +12,6 @@ #include <asm/vdso.h> .text -.global __kernel_datapage_offset; -__kernel_datapage_offset: - .long 0 _GLOBAL(__get_datapage) .cfi_startproc
@@ -31,10 +28,11 @@ _GLOBAL(__get_datapage) data_page_branch: mflr r3 mtlr r0 - addi r3, r3, __kernel_datapage_offset-data_page_branch - lwz r0,0(r3) +#if CONFIG_PPC_PAGE_SHIFT > 14 + addis r3, r3, (_vdso_datapage - data_page_branch)@ha +#endif + addi r3, r3, (_vdso_datapage - data_page_branch)@l .cfi_restore lr - add r3,r0,r3 blr .cfi_endproc
arch/powerpc/kernel/vdso64/vdso64.lds.S +2 -5
@@ -4,6 +4,7 @@ * library */ #include <asm/vdso.h> +#include <asm/page.h> #ifdef __LITTLE_ENDIAN__ OUTPUT_FORMAT("elf64-powerpcle", "elf64-powerpcle", "elf64-powerpcle")
@@ -15,6 +16,7 @@ ENTRY(_start) SECTIONS { + PROVIDE(_vdso_datapage = . - PAGE_SIZE); . = VDSO64_LBASE + SIZEOF_HEADERS; .hash : { *(.hash) } :text
@@ -138,11 +140,6 @@ VERSION { VDSO_VERSION_STRING { global: - /* - * Has to be there for the kernel to find - */ - __kernel_datapage_offset; - __kernel_get_syscall_map; __kernel_gettimeofday; __kernel_clock_gettime;
Signature · 1 line
2.13.3
RFC PATCH v3 12/12 powerpc/vdso: provide __arch_is_hw_counter_valid()
In reply to Christophe LeroyTo avoid a double verification of the hw_counter validity, provide __arch_is_hw_counter_valid()
Before:
clock-gettime-realtime: vdso: 1078 nsec/call
After:
clock-gettime-realtime: vdso: 1064 nsec/call
The * shows the test of the clock type.
The > shows the additional test on the counter,
that goes away with this patch
Before:
5e0: 81 25 00 04 lwz r9,4(r5) *5e4: 2f 89 00 00 cmpwi cr7,r9,0 *5e8: 40 9e 01 3c bne cr7,724 <__c_kernel_clock_gettime+0x17c> 5ec: 94 21 ff e0 stwu r1,-32(r1) 5f0: 93 61 00 0c stw r27,12(r1) 5f4: 93 81 00 10 stw r28,16(r1) 5f8: 93 a1 00 14 stw r29,20(r1) 5fc: 93 c1 00 18 stw r30,24(r1) 600: 93 e1 00 1c stw r31,28(r1) 604: 7d 8d 42 e6 mftbu r12 608: 7f ac 42 e6 mftb r29 60c: 7c cd 42 e6 mftbu r6 610: 7f 8c 30 40 cmplw cr7,r12,r6 614: 40 9e ff f0 bne cr7,604 <__c_kernel_clock_gettime+0x5c> >618: 2f 8c 00 00 cmpwi cr7,r12,0 61c: 83 6b 00 28 lwz r27,40(r11) 620: 83 8b 00 2c lwz r28,44(r11) 624: 81 45 00 08 lwz r10,8(r5) 628: 80 e5 00 0c lwz r7,12(r5) >62c: 41 9c 00 b4 blt cr7,6e0 <__c_kernel_clock_gettime+0x138> 630: 81 05 00 18 lwz r8,24(r5) 634: 83 c5 00 1c lwz r30,28(r5) 638: 80 cb 00 24 lwz r6,36(r11) 63c: 83 e5 00 00 lwz r31,0(r5) 640: 7f 9f 00 40 cmplw cr7,r31,r0 644: 40 9e 00 84 bne cr7,6c8 <__c_kernel_clock_gettime+0x120>
After:
5e0: 81 25 00 04 lwz r9,4(r5) *5e4: 2f 89 00 00 cmpwi cr7,r9,0 *5e8: 40 9e 01 88 bne cr7,770 <__c_kernel_clock_gettime+0x1c8> 5ec: 94 21 ff e0 stwu r1,-32(r1) 5f0: 93 61 00 0c stw r27,12(r1) 5f4: 93 81 00 10 stw r28,16(r1) 5f8: 93 a1 00 14 stw r29,20(r1) 5fc: 93 c1 00 18 stw r30,24(r1) 600: 93 e1 00 1c stw r31,28(r1) 604: 7f cd 42 e6 mftbu r30 608: 7f ac 42 e6 mftb r29 60c: 7c cd 42 e6 mftbu r6 610: 7f 9e 30 40 cmplw cr7,r30,r6 614: 40 9e ff f0 bne cr7,604 <__c_kernel_clock_gettime+0x5c> 618: 83 6b 00 28 lwz r27,40(r11) 61c: 83 8b 00 2c lwz r28,44(r11) 620: 81 45 00 08 lwz r10,8(r5) 624: 80 e5 00 0c lwz r7,12(r5) 628: 81 05 00 18 lwz r8,24(r5) 62c: 83 e5 00 1c lwz r31,28(r5) 630: 80 cb 00 24 lwz r6,36(r11) 634: 81 85 00 00 lwz r12,0(r5) 638: 7f 8c 00 40 cmplw cr7,r12,r0 63c: 40 9e 00 84 bne cr7,6c0 <__c_kernel_clock_gettime+0x118>
--- arch/powerpc/include/asm/vdso/gettimeofday.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/vdso/gettimeofday.h +6 -3
@@ -69,15 +69,18 @@ int clock_getres32_fallback(clockid_t _clkid, struct old_timespec32 *_ts) }#endif -static __always_inline u64 __arch_get_hw_counter(s32 clock_mode) +static __always_inline bool __arch_is_hw_counter_valid(s32 clock_mode) {/* * clock_mode == 0 implies that vDSO are enabled otherwise * fallback on syscall. */ -if (clock_mode !=0 ) -return U64_MAX ; +return clock_mode ==0 ? true : false; +} +#define __arch_is_hw_counter_valid __arch_is_hw_counter_valid +static __always_inline u64 __arch_get_hw_counter(s32 clock_mode) +{return get_tb (); }
Signature · 1 line
2.13.3
RFC PATCH v3 9/12 powerpc/vdso: provide inline alternative to __get_datapage()
In reply to Christophe Leroy__get_datapage() is only a few instructions to retrieve the address of the page where the kernel stores data to the VDSO.
By inlining this function into its users, a bl/blr pair and a mflr/mtlr pair is avoided, plus a few reg moves.
The improvement is noticeable (about 55 nsec/call on an 8xx)
With current __get_datapage() function:
gettimeofday: vdso: 731 nsec/call clock-gettime-realtime-coarse: vdso: 668 nsec/call clock-gettime-monotonic-coarse: vdso: 745 nsec/call
Using the __get_datapage macro provided by this patch:
gettimeofday: vdso: 677 nsec/call clock-gettime-realtime-coarse: vdso: 613 nsec/call clock-gettime-monotonic-coarse: vdso: 690 nsec/call
--- arch/powerpc/include/asm/vdso_datapage.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
arch/powerpc/include/asm/vdso_datapage.h +11 -0
@@ -105,6 +105,17 @@ struct vdso_arch_data { extern struct vdso_arch_data *vdso_data; +#else /* __ASSEMBLY__ */ + +.macro get_datapage ptr, offset=0 + bcl 20, 31, .+4 + mflr \ptr +#if CONFIG_PPC_PAGE_SHIFT > 14 + addis \ptr, \ptr, (_vdso_datapage + \offset - (.-4))@ha +#endif + addi \ptr, \ptr, (_vdso_datapage + \offset - (.-4))@l +.endm + #endif /* __ASSEMBLY__ */ #endif /* __KERNEL__ */
Signature · 1 line
2.13.3
RFC PATCH v3 11/12 lib: vdso: split clock verification out of __arch_get_hw_counter()
In reply to Christophe Leroy__arch_get_hw_counter() returns the current value of the counter if the counter is valid or a negative number if the counter is not valid.
This is suboptimal because the validity is checked twice: once before reading the counter and once after reading the counter.
Optionaly split the verification out of __arch_get_hw_counter() by providing an optional __arch_is_hw_counter_valid() function.
--- lib/vdso/gettimeofday.c | 7 +++++++ 1 file changed, 7 insertions(+)
lib/vdso/gettimeofday.c +7 -0
@@ -67,11 +67,18 @@ static __always_inline int do_hres(const struct vdso_data *vd, clockid_t clk, do { seq = vdso_read_begin(vd); +#ifdef __arch_is_hw_counter_valid + if (unlikely(!__arch_is_hw_counter_valid(vd->clock_mode))) + return -1; +#endif + cycles = __arch_get_hw_counter(vd->clock_mode); ns = vdso_ts->nsec; last = vd->cycle_last; +#ifndef __arch_is_hw_counter_valid if (unlikely((s64)cycles < 0)) return -1; +#endif ns += vdso_calc_delta(cycles, last, vd->mask, vd->mult); nsec = ns >> vd->shift;
Signature · 1 line
2.13.3
RFC PATCH v3 3/12 lib: vdso: mark __cvdso_clock_getres() as static
In reply to Christophe LeroyWhen __cvdso_clock_getres() became __cvdso_clock_getres_common() and a new __cvdso_clock_getres() was added, static qualifier was forgotten.
This change allows the compiler to inline __cvdso_clock_getres_common(), and the performance improvement is significant:
Before:
clock-getres-realtime-coarse: vdso: 984 nsec/call clock-getres-realtime: vdso: 922 nsec/call clock-getres-monotonic-raw: vdso: 968 nsec/call
After:
clock-getres-realtime-coarse: vdso: 753 nsec/call clock-getres-realtime: vdso: 691 nsec/call clock-getres-monotonic-raw: vdso: 737 nsec/call
--- lib/vdso/gettimeofday.c | 1 + 1 file changed, 1 insertion(+)
lib/vdso/gettimeofday.c +1 -0
@@ -221,6 +221,7 @@ int __cvdso_clock_getres_common(clockid_t clock, struct __kernel_timespec *res)return 0 ; } +static __maybe_unused int __cvdso_clock_getres (clockid_t clock,struct __kernel_timespec *res) {int ret =__cvdso_clock_getres_common (clock, res);
Signature · 7 lines
2.13.3 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
RFC PATCH v3 10/12 powerpc/vdso: provide vdso data pointer from the ASM caller.
In reply to Christophe Leroy__arch_get_vdso_data() clobbers the link register, requiring the caller to save it.
As the ASM calling function already has to set a stack frame and saves the link register before calling the C vdso function, retriving the vdso data pointer there is lighter.
The improvement is significant:
Before:
gettimeofday: vdso: 1027 nsec/call clock-getres-realtime-coarse: vdso: 699 nsec/call clock-gettime-realtime-coarse: vdso: 784 nsec/call clock-gettime-realtime: vdso: 1231 nsec/call
After:
gettimeofday: vdso: 908 nsec/call clock-getres-realtime-coarse: vdso: 545 nsec/call clock-gettime-realtime-coarse: vdso: 617 nsec/call clock-gettime-realtime: vdso: 1078 nsec/call
--- arch/powerpc/include/asm/vdso/gettimeofday.h | 12 ++---------- arch/powerpc/kernel/vdso32/gettimeofday.S | 3 +++ arch/powerpc/kernel/vdso32/vgettimeofday.c | 19 +++++++++++-------- arch/powerpc/kernel/vdso64/gettimeofday.S | 3 +++ arch/powerpc/kernel/vdso64/vgettimeofday.c | 19 +++++++++++-------- 5 files changed, 30 insertions(+), 26 deletions(-)
arch/powerpc/include/asm/vdso/gettimeofday.h +2 -10
@@ -6,13 +6,14 @@#include <asm/time.h> #include <asm/unistd.h> -#include <asm/vdso_datapage.h> #include <uapi/linux/time.h> #define VDSO_HAS_CLOCK_GETRES 1#define VDSO_HAS_TIME 1 +#define VDSO_GETS_VD_PTR_FROM_ARCH 1 + static __always_inline int do_syscall_2(const unsigned long _r0, const unsigned long _r3,const unsigned long _r4) {
@@ -80,15 +81,6 @@ static __always_inline u64 __arch_get_hw_counter(s32 clock_mode)return get_tb (); } -void *__get_datapage (void ); - -static __always_inline const struct vdso_data *__arch_get_vdso_data(void) -{ -struct vdso_arch_data *vdso_data =__get_datapage (); - -return vdso_data->data; -} -/* * powerpc specific delta calculation. *
arch/powerpc/kernel/vdso32/gettimeofday.S +3 -0
@@ -9,6 +9,7 @@ #include <asm/processor.h> #include <asm/ppc_asm.h> #include <asm/vdso.h> +#include <asm/vdso_datapage.h> #include <asm/asm-offsets.h> #include <asm/unistd.h>
@@ -18,6 +19,7 @@ stwu r1, -16(r1) mflr r0 stw r0, 20(r1) + get_datapage r5, VDSO_DATA_OFFSET bl \funct lwz r0, 20(r1) cmpwi r3, 0
@@ -79,6 +81,7 @@ V_FUNCTION_BEGIN(__kernel_time) stwu r1, -16(r1) mflr r0 stw r0, 20(r1) + get_datapage r4, VDSO_DATA_OFFSET bl __c_kernel_time lwz r0, 20(r1) crclr cr0*4+so
arch/powerpc/kernel/vdso32/vgettimeofday.c +11 -8
@@ -5,22 +5,25 @@#include <linux/time.h> #include <linux/types.h> -int __c_kernel_clock_gettime (clockid_t clock,struct old_timespec32 *ts) +int __c_kernel_clock_gettime (clockid_t clock,struct old_timespec32 *ts, +const struct vdso_data *vd) { -return __cvdso_clock_gettime32 (clock, ts); +return __cvdso_clock_gettime32 (vd, clock, ts); } -int __c_kernel_gettimeofday (struct __kernel_old_timeval *tv,struct timezone *tz) +int __c_kernel_gettimeofday (struct __kernel_old_timeval *tv,struct timezone *tz, +const struct vdso_data *vd) { -return __cvdso_gettimeofday (tv, tz); +return __cvdso_gettimeofday (vd, tv, tz); } -int __c_kernel_clock_getres (clockid_t clock_id,struct old_timespec32 *res) +int __c_kernel_clock_getres (clockid_t clock_id,struct old_timespec32 *res, +const struct vdso_data *vd) { -return __cvdso_clock_getres_time32 (clock_id, res); +return __cvdso_clock_getres_time32 (vd, clock_id, res); } -time_t __c_kernel_time (time_t *time) +time_t __c_kernel_time (time_t *time,const struct vdso_data *vd) { -return __cvdso_time (time); +return __cvdso_time (vd, time); }
arch/powerpc/kernel/vdso64/gettimeofday.S +3 -0
@@ -9,6 +9,7 @@ #include <asm/processor.h> #include <asm/ppc_asm.h> #include <asm/vdso.h> +#include <asm/vdso_datapage.h> #include <asm/asm-offsets.h> #include <asm/unistd.h>
@@ -18,6 +19,7 @@ mflr r0 std r0, 16(r1) stdu r1, -128(r1) + get_datapage r5, VDSO_DATA_OFFSET bl \funct addi r1, r1, 128 ld r0, 16(r1)
@@ -79,6 +81,7 @@ V_FUNCTION_BEGIN(__kernel_time) mflr r0 std r0, 16(r1) stdu r1, -128(r1) + get_datapage r4, VDSO_DATA_OFFSET bl __c_kernel_time addi r1, r1, 128 ld r0, 16(r1)
arch/powerpc/kernel/vdso64/vgettimeofday.c +11 -8
@@ -5,22 +5,25 @@#include <linux/time.h> #include <linux/types.h> -int __c_kernel_clock_gettime (clockid_t clock,struct __kernel_timespec *ts) +int __c_kernel_clock_gettime (clockid_t clock,struct __kernel_timespec *ts, +const struct vdso_data *vd) { -return __cvdso_clock_gettime (clock, ts); +return __cvdso_clock_gettime (vd, clock, ts); } -int __c_kernel_gettimeofday (struct __kernel_old_timeval *tv,struct timezone *tz) +int __c_kernel_gettimeofday (struct __kernel_old_timeval *tv,struct timezone *tz, +const struct vdso_data *vd) { -return __cvdso_gettimeofday (tv, tz); +return __cvdso_gettimeofday (vd, tv, tz); } -int __c_kernel_clock_getres (clockid_t clock_id,struct __kernel_timespec *res) +int __c_kernel_clock_getres (clockid_t clock_id,struct __kernel_timespec *res, +const struct vdso_data *vd) { -return __cvdso_clock_getres (clock_id, res); +return __cvdso_clock_getres (vd, clock_id, res); } -time_t __c_kernel_time (time_t *time) +time_t __c_kernel_time (time_t *time,const struct vdso_data *vd) { -return __cvdso_time (time); +return __cvdso_time (vd, time); }
Signature · 1 line
2.13.3
RFC PATCH v3 8/12 lib: vdso: allow arches to provide vdso data pointer
In reply to Christophe LeroyOn powerpc, __arch_get_vdso_data() clobbers the link register, requiring the caller to save it.
As the parent function already has to set a stack frame and saves the link register before calling the C vdso function, retriving the vdso data pointer there is lighter.
Give arches the opportunity to hand the vdso data pointer to C vdso functions.
--- lib/vdso/gettimeofday.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
lib/vdso/gettimeofday.c +56 -0
@@ -104,9 +104,15 @@ static __always_inline int do_coarse(const struct vdso_data *vd, clockid_t clk, } static __maybe_unused int +#ifdef VDSO_GETS_VD_PTR_FROM_ARCH +__cvdso_clock_gettime_common(const struct vdso_data *vd, clockid_t clock, + struct __kernel_timespec *ts) +{ +#else __cvdso_clock_gettime_common(clockid_t clock, struct __kernel_timespec *ts) { const struct vdso_data *vd = __arch_get_vdso_data(); +#endif u32 msk;/* Check for negative values or invalid clocks */
@@ -131,9 +137,16 @@ __cvdso_clock_gettime_common(clockid_t clock, struct __kernel_timespec *ts) } static __maybe_unused int +#ifdef VDSO_GETS_VD_PTR_FROM_ARCH +__cvdso_clock_gettime(const struct vdso_data *vd, clockid_t clock, + struct __kernel_timespec *ts) +{ + int ret = __cvdso_clock_gettime_common(vd, clock, ts); +#else __cvdso_clock_gettime(clockid_t clock, struct __kernel_timespec *ts) { int ret = __cvdso_clock_gettime_common(clock, ts); +#endif if (unlikely (ret))return clock_gettime_fallback (clock, ts);
@@ -141,12 +154,21 @@ __cvdso_clock_gettime(clockid_t clock, struct __kernel_timespec *ts) } static __maybe_unused int +#ifdef VDSO_GETS_VD_PTR_FROM_ARCH +__cvdso_clock_gettime32(const struct vdso_data *vd, clockid_t clock, + struct old_timespec32 *res) +#else __cvdso_clock_gettime32(clockid_t clock, struct old_timespec32 *res) +#endif {struct __kernel_timespec ts;int ret; +#ifdef VDSO_GETS_VD_PTR_FROM_ARCH + ret =__cvdso_clock_gettime_common (vd, clock, &ts); +#else ret =__cvdso_clock_gettime_common (clock, &ts); +#endif #ifdef VDSO_HAS_32BIT_FALLBACK if (unlikely (ret))
@@ -164,9 +186,15 @@ __cvdso_clock_gettime32(clockid_t clock, struct old_timespec32 *res) } static __maybe_unused int +#ifdef VDSO_GETS_VD_PTR_FROM_ARCH +__cvdso_gettimeofday(const struct vdso_data *vd, struct __kernel_old_timeval *tv, + struct timezone *tz) +{ +#else __cvdso_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz) { const struct vdso_data *vd = __arch_get_vdso_data(); +#endif if (likely (tv !=NULL )) {struct __kernel_timespec ts;
@@ -187,9 +215,15 @@ __cvdso_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz) } #ifdef VDSO_HAS_TIME +#ifdef VDSO_GETS_VD_PTR_FROM_ARCH +static __maybe_unused __kernel_old_time_t +__cvdso_time(const struct vdso_data *vd, __kernel_old_time_t *time) +{ +#else static __maybe_unused __kernel_old_time_t __cvdso_time(__kernel_old_time_t *time) { const struct vdso_data *vd = __arch_get_vdso_data(); +#endif __kernel_old_time_t t = READ_ONCE(vd[CS_HRES_COARSE].basetime[CLOCK_REALTIME].sec); if (time)
@@ -201,9 +235,15 @@ static __maybe_unused __kernel_old_time_t __cvdso_time(__kernel_old_time_t *time #ifdef VDSO_HAS_CLOCK_GETRES static __maybe_unused +#ifdef VDSO_GETS_VD_PTR_FROM_ARCH +int __cvdso_clock_getres_common(const struct vdso_data *vd, clockid_t clock, + struct __kernel_timespec *res) +{ +#else int __cvdso_clock_getres_common(clockid_t clock, struct __kernel_timespec *res) { const struct vdso_data *vd = __arch_get_vdso_data(); +#endif u32 msk; u64 ns;
@@ -238,9 +278,16 @@ int __cvdso_clock_getres_common(clockid_t clock, struct __kernel_timespec *res) } static __maybe_unused +#ifdef VDSO_GETS_VD_PTR_FROM_ARCH +int __cvdso_clock_getres (const struct vdso_data *vd,clockid_t clock, +struct __kernel_timespec *res) +{ +int ret =__cvdso_clock_getres_common (vd, clock, res); +#else int __cvdso_clock_getres (clockid_t clock,struct __kernel_timespec *res) {int ret =__cvdso_clock_getres_common (clock, res); +#endif if (unlikely (ret))return clock_getres_fallback (clock, res);
@@ -248,12 +295,21 @@ int __cvdso_clock_getres(clockid_t clock, struct __kernel_timespec *res) } static __maybe_unused int +#ifdef VDSO_GETS_VD_PTR_FROM_ARCH +__cvdso_clock_getres_time32(const struct vdso_data *vd, clockid_t clock, + struct old_timespec32 *res) +#else __cvdso_clock_getres_time32(clockid_t clock, struct old_timespec32 *res) +#endif {struct __kernel_timespec ts;int ret; +#ifdef VDSO_GETS_VD_PTR_FROM_ARCH + ret =__cvdso_clock_getres_common (vd, clock, &ts); +#else ret =__cvdso_clock_getres_common (clock, &ts); +#endif #ifdef VDSO_HAS_32BIT_FALLBACK if (unlikely (ret))
Signature · 1 line
2.13.3
RFC PATCH v3 2/12 powerpc/vdso: Switch VDSO to generic C implementation.
In reply to Christophe LeroyThis is a minimalistic conversion to VDSO generic C implementation.
On powerpc 8xx, performance is degraded by 40-45% for gettime and by 50% for getres.
Optimisations will follow in next patches, some in the core VDSO functions, some in the powerpc arch.
powerpc is a bit special for VDSO as well as system calls in the way that it requires setting CR SO bit which cannot be done in C. Therefore, entry/exit needs to be performed in ASM.
On a powerpc885 at 132MHz:
With current powerpc/32 ASM VDSO:
gettimeofday: vdso: 737 nsec/call clock-getres-realtime-coarse: vdso: 3081 nsec/call clock-gettime-realtime-coarse: vdso: 2861 nsec/call clock-getres-realtime: vdso: 475 nsec/call clock-gettime-realtime: vdso: 892 nsec/call clock-getres-boottime: vdso: 2621 nsec/call clock-gettime-boottime: vdso: 3857 nsec/call clock-getres-tai: vdso: 2620 nsec/call clock-gettime-tai: vdso: 3854 nsec/call clock-getres-monotonic-raw: vdso: 2621 nsec/call clock-gettime-monotonic-raw: vdso: 3499 nsec/call clock-getres-monotonic-coarse: vdso: 3083 nsec/call clock-gettime-monotonic-coarse: vdso: 3082 nsec/call clock-getres-monotonic: vdso: 475 nsec/call clock-gettime-monotonic: vdso: 1014 nsec/call
Once switched to C implementation:
gettimeofday: vdso: 1379 nsec/call getcpu: vdso: not tested clock-getres-realtime-coarse: vdso: 984 nsec/call clock-gettime-realtime-coarse: vdso: 868 nsec/call clock-getres-realtime: vdso: 922 nsec/call clock-gettime-realtime: vdso: 1511 nsec/call clock-getres-boottime: vdso: 922 nsec/call clock-gettime-boottime: vdso: 1510 nsec/call clock-getres-tai: vdso: 923 nsec/call clock-gettime-tai: vdso: 1511 nsec/call clock-getres-monotonic-raw: vdso: 968 nsec/call clock-gettime-monotonic-raw: vdso: 1576 nsec/call clock-getres-monotonic-coarse: vdso: 984 nsec/call clock-gettime-monotonic-coarse: vdso: 868 nsec/call clock-getres-monotonic: vdso: 922 nsec/call clock-gettime-monotonic: vdso: 1510 nsec/call
--- arch/powerpc/Kconfig | 2 + arch/powerpc/include/asm/vdso/gettimeofday.h | 109 ++++++++++++ arch/powerpc/include/asm/vdso/vsyscall.h | 25 +++ arch/powerpc/include/asm/vdso_datapage.h | 41 ++--- arch/powerpc/kernel/asm-offsets.c | 46 +---- arch/powerpc/kernel/time.c | 90 ---------- arch/powerpc/kernel/vdso.c | 5 +- arch/powerpc/kernel/vdso32/Makefile | 27 ++- arch/powerpc/kernel/vdso32/gettimeofday.S | 255 +++------------------------ arch/powerpc/kernel/vdso32/vgettimeofday.c | 26 +++ arch/powerpc/kernel/vdso64/Makefile | 23 ++- arch/powerpc/kernel/vdso64/datapage.S | 3 +- arch/powerpc/kernel/vdso64/gettimeofday.S | 254 +++----------------------- arch/powerpc/kernel/vdso64/vgettimeofday.c | 26 +++ 14 files changed, 312 insertions(+), 620 deletions(-) create mode 100644 arch/powerpc/include/asm/vdso/gettimeofday.h create mode 100644 arch/powerpc/include/asm/vdso/vsyscall.h create mode 100644 arch/powerpc/kernel/vdso32/vgettimeofday.c create mode 100644 arch/powerpc/kernel/vdso64/vgettimeofday.c
arch/powerpc/Kconfig +2 -0
@@ -169,6 +169,7 @@ config PPC select GENERIC_STRNCPY_FROM_USER select GENERIC_STRNLEN_USER select GENERIC_TIME_VSYSCALL + select GENERIC_GETTIMEOFDAY select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_HUGE_VMAP if PPC_BOOK3S_64 && PPC_RADIX_MMU select HAVE_ARCH_JUMP_LABEL
@@ -198,6 +199,7 @@ config PPC select HAVE_FUNCTION_GRAPH_TRACER select HAVE_FUNCTION_TRACER select HAVE_GCC_PLUGINS if GCC_VERSION >= 50200 # plugin support on gcc <= 5.1 is buggy on PPC + select HAVE_GENERIC_VDSO select HAVE_HW_BREAKPOINT if PERF_EVENTS && (PPC_BOOK3S || PPC_8xx) select HAVE_IDE select HAVE_IOREMAP_PROT
arch/powerpc/include/asm/vdso/gettimeofday.h new file +109 -0
109 lines not on this page · raw message
arch/powerpc/include/asm/vdso/vsyscall.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __ASM_VDSO_VSYSCALL_H +#define __ASM_VDSO_VSYSCALL_H + +#ifndef __ASSEMBLY__ + +#include <linux/timekeeper_internal.h> +#include <asm/vdso_datapage.h> + +/* +* Update the vDSO data page to keep in sync with kernel timekeeping. +*/ +static __always_inline +struct vdso_data *__arch_get_k_vdso_data(void) +{ +return vdso_data->data; +} +#define __arch_get_k_vdso_data __arch_get_k_vdso_data + +/* The asm-generic header needs to be included after the definitions above */ +#include <asm-generic/vdso/vsyscall.h> + +#endif /* !__ASSEMBLY__ */ + +#endif /* __ASM_VDSO_VSYSCALL_H */
arch/powerpc/include/asm/vdso_datapage.h +14 -27
84 lines not on this page · raw message
arch/powerpc/kernel/asm-offsets.c +9 -37
53 lines not on this page · raw message
arch/powerpc/kernel/time.c +0 -90
102 lines not on this page · raw message
arch/powerpc/kernel/vdso.c +3 -2
@@ -17,6 +17,7 @@#include <linux/elf.h> #include <linux/security.h> #include <linux/memblock.h> +#include <vdso/datapage.h> #include <asm/pgtable.h> #include <asm/processor.h>
@@ -71,10 +72,10 @@ static int vdso_ready;* with it, it will become dynamically allocated */ static union { -struct vdso_data data; +struct vdso_arch_data data;u8 page[PAGE_SIZE ]; } vdso_data_store __page_aligned_data; -struct vdso_data *vdso_data = &vdso_data_store.data; +struct vdso_arch_data *vdso_data = &vdso_data_store.data;/* Format of the patch table */ struct vdso_patch_def
arch/powerpc/kernel/vdso32/Makefile +24 -3
@@ -2,11 +2,23 @@ # List of files in the vdso, has to be asm only for now +ARCH_REL_TYPE_ABS := R_PPC_JUMP_SLOT|R_PPC_GLOB_DAT|R_PPC_ADDR32|R_PPC_ADDR24|R_PPC_ADDR16|R_PPC_ADDR16_LO|R_PPC_ADDR16_HI|R_PPC_ADDR16_HA|R_PPC_ADDR14|R_PPC_ADDR14_BRTAKEN|R_PPC_ADDR14_BRNTAKEN +include $(srctree)/lib/vdso/Makefile + obj-vdso32-$(CONFIG_PPC64) = getcpu.o obj-vdso32-$(CONFIG_PPC32) = gettimeofday.o obj-vdso32 = sigtramp.o datapage.o cacheflush.o note.o \ $(obj-vdso32-y) +ifneq ($(c-gettimeofday-y),) + CFLAGS_vgettimeofday.o += -include $(c-gettimeofday-y) + CFLAGS_vgettimeofday.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) + CFLAGS_vgettimeofday.o += $(call cc-option, -fno-stack-protector) + CFLAGS_vgettimeofday.o += -DDISABLE_BRANCH_PROFILING + CFLAGS_vgettimeofday.o += -ffreestanding + CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) +endif + # Build rules ifdef CROSS32_COMPILE
@@ -26,6 +38,7 @@ obj-vdso32 := $(addprefix $(obj)/, $(obj-vdso32)) GCOV_PROFILE := n KCOV_INSTRUMENT := n UBSAN_SANITIZE := n +KASAN_SANITIZE := n ccflags-y := -shared -fno-common -fno-builtin -nostdlib \ -Wl,-soname=linux-vdso32.so.1 -Wl,--hash-style=both
@@ -39,8 +52,12 @@ CPPFLAGS_vdso32.lds += -P -C -Upowerpc $(obj)/vdso32_wrapper.o : $(obj)/vdso32.so # link rule for the .so file, .lds has to be first +ifdef CONFIG_PPC32 +$(obj)/vdso32.so.dbg: $(src)/vdso32.lds $(obj-vdso32) $(obj)/vgettimeofday.o FORCE +else $(obj)/vdso32.so.dbg: $(src)/vdso32.lds $(obj-vdso32) FORCE - $(call if_changed,vdso32ld) +endif + $(call if_changed,vdso32ld_and_check) # strip rule for the .so file $(obj)/%.so: OBJCOPYFLAGS := -S
@@ -50,12 +67,16 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE # assembly rules for the .S files $(obj-vdso32): %.o: %.S FORCE $(call if_changed_dep,vdso32as) +$(obj)/vgettimeofday.o: %.o: %.c FORCE + $(call if_changed_dep,vdso32cc) # actual build commands -quiet_cmd_vdso32ld = VDSO32L $@ - cmd_vdso32ld = $(VDSOCC) $(c_flags) $(CC32FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^) +quiet_cmd_vdso32ld_and_check = VDSO32L $@ + cmd_vdso32ld_and_check = $(VDSOCC) $(c_flags) $(CC32FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^) ; $(cmd_vdso_check) quiet_cmd_vdso32as = VDSO32A $@ cmd_vdso32as = $(VDSOCC) $(a_flags) $(CC32FLAGS) -c -o $@ $< +quiet_cmd_vdso32cc = VDSO32A $@ + cmd_vdso32cc = $(VDSOCC) $(c_flags) $(CC32FLAGS) -c -o $@ $< # install commands for the unstripped file quiet_cmd_vdso_install = INSTALL $@
arch/powerpc/kernel/vdso32/gettimeofday.S +27 -228
287 lines not on this page · raw message
arch/powerpc/kernel/vdso32/vgettimeofday.c new file +26 -0
@@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Powerpc userspace implementations of gettimeofday() and similar. +*/ +#include <linux/time.h> +#include <linux/types.h> + +int __c_kernel_clock_gettime (clockid_t clock,struct old_timespec32 *ts) +{ +return __cvdso_clock_gettime32 (clock, ts); +} + +int __c_kernel_gettimeofday (struct __kernel_old_timeval *tv,struct timezone *tz) +{ +return __cvdso_gettimeofday (tv, tz); +} + +int __c_kernel_clock_getres (clockid_t clock_id,struct old_timespec32 *res) +{ +return __cvdso_clock_getres_time32 (clock_id, res); +} + +time_t __c_kernel_time (time_t *time) +{ +return __cvdso_time (time); +}
arch/powerpc/kernel/vdso64/Makefile +19 -4
@@ -1,8 +1,20 @@ # SPDX-License-Identifier: GPL-2.0 # List of files in the vdso, has to be asm only for now +ARCH_REL_TYPE_ABS := R_PPC_JUMP_SLOT|R_PPC_GLOB_DAT|R_PPC_ADDR32|R_PPC_ADDR24|R_PPC_ADDR16|R_PPC_ADDR16_LO|R_PPC_ADDR16_HI|R_PPC_ADDR16_HA|R_PPC_ADDR14|R_PPC_ADDR14_BRTAKEN|R_PPC_ADDR14_BRNTAKEN +include $(srctree)/lib/vdso/Makefile + obj-vdso64 = sigtramp.o gettimeofday.o datapage.o cacheflush.o note.o getcpu.o +ifneq ($(c-gettimeofday-y),) + CFLAGS_vgettimeofday.o += -include $(c-gettimeofday-y) + CFLAGS_vgettimeofday.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) + CFLAGS_vgettimeofday.o += $(call cc-option, -fno-stack-protector) + CFLAGS_vgettimeofday.o += -DDISABLE_BRANCH_PROFILING + CFLAGS_vgettimeofday.o += -ffreestanding + CFLAGS_REMOVE_vgettimeofday.o = $(CC_FLAGS_FTRACE) +endif + # Build rules targets := $(obj-vdso64) vdso64.so vdso64.so.dbg
@@ -11,6 +23,7 @@ obj-vdso64 := $(addprefix $(obj)/, $(obj-vdso64)) GCOV_PROFILE := n KCOV_INSTRUMENT := n UBSAN_SANITIZE := n +KASAN_SANITIZE := n ccflags-y := -shared -fno-common -fno-builtin -nostdlib \ -Wl,-soname=linux-vdso64.so.1 -Wl,--hash-style=both
@@ -20,12 +33,14 @@ obj-y += vdso64_wrapper.o extra-y += vdso64.lds CPPFLAGS_vdso64.lds += -P -C -U$(ARCH) +$(obj)/vgettimeofday.o: %.o: %.c FORCE + # Force dependency (incbin is bad) $(obj)/vdso64_wrapper.o : $(obj)/vdso64.so # link rule for the .so file, .lds has to be first -$(obj)/vdso64.so.dbg: $(src)/vdso64.lds $(obj-vdso64) FORCE - $(call if_changed,vdso64ld) +$(obj)/vdso64.so.dbg: $(src)/vdso64.lds $(obj-vdso64) $(obj)/vgettimeofday.o FORCE + $(call if_changed,vdso64ld_and_check) # strip rule for the .so file $(obj)/%.so: OBJCOPYFLAGS := -S
@@ -33,8 +48,8 @@ $(obj)/%.so: $(obj)/%.so.dbg FORCE $(call if_changed,objcopy) # actual build commands -quiet_cmd_vdso64ld = VDSO64L $@ - cmd_vdso64ld = $(CC) $(c_flags) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^) +quiet_cmd_vdso64ld_and_check = VDSO64L $@ + cmd_vdso64ld_and_check = $(CC) $(c_flags) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^) ; $(cmd_vdso_check) # install commands for the unstripped file quiet_cmd_vdso_install = INSTALL $@
arch/powerpc/kernel/vdso64/datapage.S +1 -2
@@ -16,7 +16,7 @@ __kernel_datapage_offset: .long 0 -V_FUNCTION_BEGIN(__get_datapage) +_GLOBAL(__get_datapage) .cfi_startproc /* We don't want that exposed or overridable as we want other objects * to be able to bl directly to here
@@ -37,7 +37,6 @@ data_page_branch: add r3,r0,r3 blr .cfi_endproc -V_FUNCTION_END(__get_datapage) /* * void *__kernel_get_syscall_map(unsigned int *syscall_count) ;
arch/powerpc/kernel/vdso64/gettimeofday.S +27 -227
285 lines not on this page · raw message
arch/powerpc/kernel/vdso64/vgettimeofday.c new file +26 -0
@@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Powerpc userspace implementations of gettimeofday() and similar. +*/ +#include <linux/time.h> +#include <linux/types.h> + +int __c_kernel_clock_gettime (clockid_t clock,struct __kernel_timespec *ts) +{ +return __cvdso_clock_gettime (clock, ts); +} + +int __c_kernel_gettimeofday (struct __kernel_old_timeval *tv,struct timezone *tz) +{ +return __cvdso_gettimeofday (tv, tz); +} + +int __c_kernel_clock_getres (clockid_t clock_id,struct __kernel_timespec *res) +{ +return __cvdso_clock_getres (clock_id, res); +} + +time_t __c_kernel_time (time_t *time) +{ +return __cvdso_time (time); +}
Signature · 1 line
2.13.3
RFC PATCH v3 6/12 lib: vdso: __iter_div_u64_rem() is suboptimal for 32 bit time
In reply to Christophe LeroyUsing __iter_div_ulong_rem() is suboptimal on 32 bits. Nanoseconds are only 32 bits, and VDSO data is updated every 10ms so nsec will never overflow 32 bits.
Add an equivalent of __iter_div_u64_rem() but based on unsigned long to better fit with 32 bits arches.
Before:
gettimeofday: vdso: 1078 nsec/call clock-gettime-monotonic-raw: vdso: 1317 nsec/call clock-gettime-monotonic: vdso: 1255 nsec/call
After:
gettimeofday: vdso: 1032 nsec/call clock-gettime-monotonic-raw: vdso: 1312 nsec/call clock-gettime-monotonic: vdso: 1243 nsec/call
--- lib/vdso/gettimeofday.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-)
lib/vdso/gettimeofday.c +23 -3
@@ -38,12 +38,32 @@ u64 vdso_calc_delta(u64 cycles, u64 last, u64 mask, u32 mult) }#endif +static __always_inline u32 +__iter_div_ulong_rem (unsigned long dividend,u32 divisor,unsigned long *remainder) +{ +u32 ret =0 ; + +while (dividend >= divisor) { +/* The following asm() prevents the compiler from +optimising this loop into a modulo operation. */ + asm("" :"+rm" (dividend)); + + dividend -= divisor; + ret++; + } + + *remainder = dividend; + +return ret; +} + static __always_inline int do_hres(const struct vdso_data *vd, clockid_t clk,struct __kernel_timespec *ts) {const struct vdso_timestamp *vdso_ts = &vd->basetime[clk];u64 cycles, last, sec, ns;u32 seq; +unsigned long nsec; do { seq = vdso_read_begin(vd);
@@ -54,7 +74,7 @@ static __always_inline int do_hres(const struct vdso_data *vd, clockid_t clk,return -1 ; ns +=vdso_calc_delta (cycles, last, vd->mask, vd->mult); - ns >>= vd->shift; + nsec = ns >> vd->shift; sec = vdso_ts->sec; }while (unlikely (vdso_read_retry (vd, seq)));
@@ -62,8 +82,8 @@ static __always_inline int do_hres(const struct vdso_data *vd, clockid_t clk,* Do this outside the loop: a race inside the loop could result * in __iter_div_u64_rem() being extremely slow. */ - ts->tv_sec = sec +__iter_div_u64_rem (ns,NSEC_PER_SEC , &ns); - ts->tv_nsec = ns; + ts->tv_sec = sec +__iter_div_ulong_rem (nsec,NSEC_PER_SEC , &nsec); + ts->tv_nsec = nsec;return 0 ; }
Signature · 1 line
2.13.3
Re: [RFC PATCH v3 06/12] lib: vdso: __iter_div_u64_rem() is suboptimal for 32 bit time
Quoted 3 lines · Christophe Leroy
Using
__iter_div_ulong_rem()is suboptimal on 32 bits. Nanoseconds are only 32 bits, and VDSO data is updated every 10ms so nsec will never overflow 32 bits.
That's theory and perhaps true for bare metal, but there is no guarantee on VIRT that the CPU which has the timekeeping duty assigned is not scheduled out for longer than 4 seconds.
Thanks,
tglx
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [RFC PATCH v3 08/12] lib: vdso: allow arches to provide vdso data pointer
In reply to Christophe Leroylib/vdso/gettimeofday.c static __always_inline int do_coarse(const struct vdso_data *vd, clockid_t clk, · line 116
Quoted 12 lines · Christophe Leroy
static
__maybe_unusedintlib/vdso/gettimeofday.c +6
-0+#ifdef VDSO_GETS_VD_PTR_FROM_ARCH +__cvdso_clock_gettime_common(const struct vdso_data *vd, clockid_t clock, + struct __kernel_timespec *ts) +{ +#else __cvdso_clock_gettime_common(clockid_t clock, struct __kernel_timespec *ts) { const struct vdso_data *vd = __arch_get_vdso_data(); +#endif u32 msk;
If we do that, then there is no point in propagating this to the inner functions. It's perfectly fine to have this distinction at the outermost level.
As a related question, I noticed that you keep all that ASM voodoo in the PPC specific code which provides the actual entry points. Is that ASM code really still necessary? All current users of the generic VDSO just do something like:
int __vdso_clock_gettime(clockid_t clock, struct __kernel_timespec *ts)
{
return __cvdso_clock_gettime(clock, ts);
}in the architecture code. Is there a reason why this can't work on PPC?
Thanks,
tglx
Re: [RFC PATCH v3 08/12] lib: vdso: allow arches to provide vdso data pointer
Le 15/01/2020 à 00:06, Thomas Gleixner a écrit :
Quoted 17 lines
lib/vdso/gettimeofday.c static __always_inline int do_coarse(const struct vdso_data *vd, clockid_t clk, · line 116
Quoted 12 lines · Christophe Leroy
static
__maybe_unusedintlib/vdso/gettimeofday.c +6
-0+#ifdef VDSO_GETS_VD_PTR_FROM_ARCH +__cvdso_clock_gettime_common(const struct vdso_data *vd, clockid_t clock, + struct __kernel_timespec *ts) +{ +#else __cvdso_clock_gettime_common(clockid_t clock, struct __kernel_timespec *ts) { const struct vdso_data *vd = __arch_get_vdso_data(); +#endif u32 msk;If we do that, then there is no point in propagating this to the inner functions. It's perfectly fine to have this distinction at the outermost level.
In v2, I did it at the arch level (see https://patchwork.ozlabs.org/patch/1214983/). Andy was concerned about it being suboptimal for arches which (unlike powerpc) have PC related data addressing mode.
Wouldn't it be the same issue if doing it at the outermost level of generic VDSO ?
Quoted 6 lines
As a related question, I noticed that you keep all that ASM voodoo in the PPC specific code which provides the actual entry points. Is that ASM code really still necessary? All current users of the generic VDSO just do something like:
Quoted 6 lines
int
__vdso_clock_gettime(clockid_t clock, struct __kernel_timespec *ts){ return __cvdso_clock_gettime(clock, ts); }in the architecture code. Is there a reason why this can't work on PPC?
The problem with powerpc is that VDSO functions have to (just like system calls) set the SO bit in CR register in case of error, or clear it if no error. There is no way to do that from the C function, because there is no way to tell GCC to not play up with CR register on function return.
Refer discussion at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92769
Christophe
Re: [RFC PATCH v3 08/12] lib: vdso: allow arches to provide vdso data pointer
Thomas, Andy,
Le 15/01/2020 à 07:15, Christophe Leroy a écrit :
Quoted 21 lines
Le 15/01/2020 à 00:06, Thomas Gleixner a écrit :
Quoted 17 lines
Quoted 7 lines · Christophe Leroy
static
__maybe_unusedint(quoted diff) +2
-0+#ifdef VDSO_GETS_VD_PTR_FROM_ARCH +__cvdso_clock_gettime_common(const struct vdso_data *vd, clockid_tclock,
+ struct__kernel_timespec*ts)(quoted diff) +2
-0+{ +#elseQuoted 5 lines
__cvdso_clock_gettime_common(clockid_t clock, struct __kernel_timespec *ts){
const structvdso_data*vd =__arch_get_vdso_data(); +#endif
u32 msk;If we do that, then there is no point in propagating this to the inner functions. It's perfectly fine to have this distinction at the outermost level.
Quoted 3 lines
In v2, I did it at the arch level (see https://patchwork.ozlabs.org/patch/1214983/). Andy was concerned about it being suboptimal for arches which (unlike powerpc) have PC related data addressing mode.
Wouldn't it be the same issue if doing it at the outermost level of generic VDSO ?
Any opinion on this ?
From your point of view, what should I do:
A/ __arch_get_vdso_data() handled entirely at arch level and arches handing over the vdso data pointer to generic C VDSO functions all the time (as in my v2 series) ? B/ Data pointer being handed over all the way up for arches wanting to do so, no changes at all for others (as in my v3 series) ?
C/ __arch_get_vdso_data() being called at the outermost generic level for arches not interested in handling data pointer from the caller (as suggested by Thomas) ?
Andy, with A/ you were concerned about arches being able to do PC related accesses. Would it be an issue for C/ as well ? If not, I guess C/ would be cleaner than B/ allthought not as clean as A which doesn't add any #ifdefery at all.
Thanks
Christophe
Re: [RFC PATCH v3 08/12] lib: vdso: allow arches to provide vdso data pointer
Quoted 5 lines · Christophe Leroy
Le 15/01/2020 à 07:15, Christophe Leroy a écrit :
From your point of view, what should I do:
A/__arch_get_vdso_data()handled entirely at arch level and arches handing over the vdso data pointer to generic C VDSO functions all the time (as in my v2 series) ?
No. That's again moving the same code to all architectures.
Quoted 2 lines
B/ Data pointer being handed over all the way up for arches wanting to do so, no changes at all for others (as in my v3 series) ?
Too much ifdeffery
Quoted 8 lines
C/
__arch_get_vdso_data()being called at the outermost generic level for arches not interested in handling data pointer from the caller (as suggested by Thomas) ?Andy, with A/ you were concerned about arches being able to do PC related accesses. Would it be an issue for C/ as well ? If not, I guess C/ would be cleaner than B/ allthought not as clean as A which doesn't add any #ifdefery at all.
You can avoid ifdeffery with C if you do:
static __maybe_unused int __cvdso_data_clock_gettime(clockid_t clock, struct __kernel_timespec *ts,
const struct vdso_data *vd)
{
.....
}static __maybe_unused int__cvdso_clock_gettime(clockid_t clock, struct __kernel_timespec *ts)
{
const struct vdso_data *vd = __arch_get_vdso_data();
return __cvdso_data_clock_gettime(clock, ts, vd);
}and then use __cvdso_data_clock_gettime on PPC and let the other archs unmodified.
Thanks,
tglx
Andy Lutomirski
maintainerRe: [RFC PATCH v3 08/12] lib: vdso: allow arches to provide vdso data pointer
Quoted 10 lines · Thomas Gleixner
static
__maybe_unusedint __cvdso_data_clock_gettime(clockid_t clock, struct__kernel_timespec*ts,
const structvdso_data*vd){ ..... }static
__maybe_unusedint__cvdso_clock_gettime(clockid_t clock, struct __kernel_timespec *ts)
Quoted 10 lines
{ const struct vdso_data *vd = __arch_get_vdso_data(); return __cvdso_data_clock_gettime(clock, ts, vd); }and then use
__cvdso_data_clock_gettimeon PPC and let the other archs unmodified.
FWIW, I did some experiments on x86 with gcc 9.2. gcc 9.2 uses rip-relative accesses if I simplify the config enough and otherwise materializes the pointer. Presumably it decides that the code size reduction is worth it if there are a lot of accesses.
I suspect that tglx's suggestion will be fine or at worst will add negligible overhead on x86_64.