Amended and retested for 32 bit "borrow ops" series
Subsystems (4)
[email protected]
maintainerHi All,
Apologies for sending a broken version for 32 bit.
This is an amended version which has been tested for 32 bit with/without glibc "borrowing" and 64 bit with/without glibc borrowing.
It also includes a proper 32 bit futex implementation.
I have combined all patches and bumped the version to no 4.
The total performance difference as measured with dd on a ubd device which is mostly cached in-memory is ~ 1.3 times for 64 bit and 2.4 times for 32 bit.
Other benchmarks (find, boot time, etc) benefit as well, but the benefit is not so drastic.
All tests performed on a Ryzen 5 1600X host.
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
[email protected]
maintainerPATCH v4 1/7 um: allow the use of glibc functions instead of builtins
From: Anton Ivanov <[email protected]>
The UML kernel runs as a normal userspace process and can use most of glibc string.h functionality instead of built-ins. At present, when using built-ins, it is also limited to their unoptimized versions, because it does not have the runtime code patching present on x86 via apply_alternatives()
Allowing the use of glibc for memcpy, memmove, etc provides 1-5% boost on common file io as measured by cat and dd. The size of the linux executable is also reduced by ~10KBytes.
It is possible to turn this on/off via the kernel configuration.
--- arch/um/Kconfig | 10 ++++++ arch/um/include/asm/string.h | 70 ++++++++++++++++++++++++++++++++++++ arch/um/os-Linux/user_syms.c | 28 ++++++++++++++- arch/x86/um/Makefile | 6 ++-- 4 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 arch/um/include/asm/string.h
arch/um/Kconfig +10 -0
@@ -189,6 +189,16 @@ config UML_TIME_TRAVEL_SUPPORT It is safe to say Y, but you probably don't need this. +config UML_USE_BUILT_IN_STRINGS + bool + default N + prompt "Use kernel memcpy, memmove, etc" + help + UML can use the kernel built in memcpy, memmove, etc functions + or use the glibc equivalents instead. + The glibc equivalents are slightly faster and will result in a + slightly smaller executable when linking UML dynamically. + endmenu source "arch/um/drivers/Kconfig"
arch/um/include/asm/string.h new file +70 -0
70 lines not on this page · raw message
arch/um/os-Linux/user_syms.c +27 -1
@@ -9,6 +9,7 @@* add an EXPORT for the glibc one. */ +#ifdef CONFIG_UML_USE_BUILT_IN_STRINGS #undef strlen#undef strstr#undef memcpy
@@ -17,6 +18,7 @@extern size_t strlen (const char *);extern void *memmove (void *,const void *,size_t );extern void *memset (void *,int ,size_t ); +#endif extern int printf (const char *, ...);/* If it's not defined, the export is included in lib/string.c.*/
@@ -24,14 +26,38 @@ extern int printf(const char *, ...);EXPORT_SYMBOL (strstr);#endif -#ifndef __x86_64__ +#if !defined(__x86_64__) && defined(CONFIG_UML_USE_BUILT_IN_STRINGS )extern void *memcpy (void *,const void *,size_t );EXPORT_SYMBOL (memcpy);#endif + +#ifndef CONFIG_UML_USE_BUILT_IN_STRINGS +/* These all come from glibc */ +EXPORT_SYMBOL (memcpy);EXPORT_SYMBOL (memmove);EXPORT_SYMBOL (memset);EXPORT_SYMBOL (printf); +EXPORT_SYMBOL (strcpy); +EXPORT_SYMBOL (strncpy); +EXPORT_SYMBOL (strcat); +EXPORT_SYMBOL (strncat); +EXPORT_SYMBOL (strcmp); +EXPORT_SYMBOL (strncmp); +EXPORT_SYMBOL (strchr); +EXPORT_SYMBOL (strlen); +EXPORT_SYMBOL (memchr); +EXPORT_SYMBOL (strnlen); +EXPORT_SYMBOL (strncasecmp); +EXPORT_SYMBOL (strcasecmp); +EXPORT_SYMBOL (strchrnul); +EXPORT_SYMBOL (strcspn); +EXPORT_SYMBOL (strpbrk); +EXPORT_SYMBOL (strsep); +EXPORT_SYMBOL (memcmp); +EXPORT_SYMBOL (bcmp); + +#endif /* Here, instead, I can provide a fake prototype. Yes, someone cares: genksyms. * However, the modules will use the CRC defined *here*, no matter if it is
arch/x86/um/Makefile +4 -2
@@ -20,14 +20,16 @@ ifeq ($(CONFIG_X86_32),y) obj-y += checksum_32.o syscalls_32.o obj-$(CONFIG_ELF_CORE) += elfcore.o -subarch-y = ../lib/string_32.o ../lib/atomic64_32.o ../lib/atomic64_cx8_32.o +subarch-y = ../lib/atomic64_32.o ../lib/atomic64_cx8_32.o subarch-y += ../kernel/sys_ia32.o +subarch-$(CONFIG_UML_USE_BUILT_IN_STRINGS) += ../lib/string_32.o else obj-y += syscalls_64.o vdso/ -subarch-y = ../lib/csum-partial_64.o ../lib/memcpy_64.o ../entry/thunk_64.o +subarch-y = ../lib/csum-partial_64.o ../entry/thunk_64.o +subarch-$(CONFIG_UML_USE_BUILT_IN_STRINGS) += ../lib/memcpy_64.o endif
Signature · 7 lines
2.20.1 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Re: [PATCH v4 1/7] um: allow the use of glibc functions instead of builtins
Quoted 8 lines · On Fri, 2020-12-11 at 17:45 +0000, [email protected] wrote:
From: Anton Ivanov <[email protected]>
The UML kernel runs as a normal userspace process and can use most of glibc
string.hfunctionality instead of built-ins. At present, when using built-ins, it is also limited to their unoptimized versions, because it does not have the runtime code patching present on x86 viaapply_alternatives()
Quoted 7 lines
Allowing the use of glibc for memcpy, memmove, etc provides 1-5% boost on common file io as measured by cat and dd. The size of the linux executable is also reduced by ~10KBytes.
It is possible to turn this on/off via the kernel configuration.
Signed-off-by Anton Ivanov <[email protected]>
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
[email protected]
maintainerPATCH v4 2/7 um: enable the use of optimized xor routines in UML
In reply to [email protected]From: Anton Ivanov <[email protected]>
This patch enable the use of optimized xor routines from the x86 tree as well as supply the necessary macros for them to be used in UML.
The macros supply several "fake" flags and definitions to allow using the x86 files "as is".
This patchset implements only the flags needed for the optimized strings.h, xor.h and checksum.h implementations instead of trying to copy the entire x86 flags environment.
--- arch/um/include/asm/cpufeature.h | 17 +++++++++++++ arch/um/include/asm/cpufeatures.h | 15 ++++++++++++ arch/um/include/asm/fpu/api.h | 14 +++++++++++ arch/um/include/asm/processor-generic.h | 3 +++ arch/um/include/asm/xor-x86.h | 1 + arch/um/include/asm/xor.h | 17 ++++++++++++- arch/um/include/asm/xor_32.h | 1 + arch/um/include/asm/xor_64.h | 1 + arch/um/include/asm/xor_avx.h | 1 + arch/um/include/shared/os.h | 1 + arch/um/kernel/um_arch.c | 17 +++++++++++-- arch/um/os-Linux/start_up.c | 32 +++++++++++++++++++++++++ 12 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 arch/um/include/asm/cpufeature.h create mode 100644 arch/um/include/asm/cpufeatures.h create mode 100644 arch/um/include/asm/fpu/api.h create mode 120000 arch/um/include/asm/xor-x86.h create mode 120000 arch/um/include/asm/xor_32.h create mode 120000 arch/um/include/asm/xor_64.h create mode 120000 arch/um/include/asm/xor_avx.h
arch/um/include/asm/cpufeature.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_UM_CPUFEATURE_H +#define _ASM_UM_CPUFEATURE_H + +#include <asm/asm.h> +#include <linux/bitops.h> +#include <asm/processor-generic.h> +#include <asm/cpufeatures.h> + + +const char *host_cpu_feature_names[] = {"mmx" ,"xmm" ,"avx" ,"osxsave" ,"rep_good" ,"erms" ,"xmm2" }; +#define MAX_UM_CPU_FEATURES ARRAY_SIZE(host_cpu_feature_names) + + +#define boot_cpu_has (bit) (boot_cpu_data.host_features & bit) + +#endif /* _ASM_UM_CPUFEATURE_H */
arch/um/include/asm/cpufeatures.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_UM_CPUFEATURES_H +#define _ASM_UM_CPUFEATURES_H + +/* Fake x86 Features of actual interest to UML */ + +#define X86_FEATURE_MMX (1 << 0) +#define X86_FEATURE_XMM (1 << 1) +#define X86_FEATURE_AVX (1 << 2) +#define X86_FEATURE_OSXSAVE (1 << 3) +#define X86_FEATURE_REP_GOOD (1 << 4) +#define X86_FEATURE_ERMS (1 << 5) +#define X86_FEATURE_XMM2 (1 << 6) + +#endif /* _ASM_UM_CPUFEATURES_H */
arch/um/include/asm/fpu/api.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _ASM_UM_FPU_API_H +#define _ASM_UM_FPU_API_H + +/* Copyright (c) 2020 Cambridge Greys Ltd +* Copyright (c) 2020 Red Hat Inc. +* A set of "dummy" defines to allow the direct inclusion +* of x86 optimized copy, xor, etc routines into the +* UML code tree. */ + +#define kernel_fpu_begin () (void)0 +#define kernel_fpu_end () (void)0 + +#endif
arch/um/include/asm/processor-generic.h +3 -0
@@ -90,6 +90,9 @@ extern void start_thread(struct pt_regs *regs, unsigned long entry,struct cpuinfo_um {unsigned long loops_per_jiffy;int ipi_pipe[2 ]; +/* There is only a small set of x86 features we are interested +* in for now */ +unsigned long host_features; };extern struct cpuinfo_um boot_cpu_data;
arch/um/include/asm/xor-x86.h new file +1 -0
@@ -0,0 +1 @@ +../../../x86/include/asm/xor.h
arch/um/include/asm/xor.h +16 -1
@@ -1,7 +1,22 @@/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm-generic/xor.h> +#ifndef _ASM_UM_XOR_H +#define _ASM_UM_XOR_H + +#ifdef CONFIG_64BIT +#undef CONFIG_X86_32 +#else +#define CONFIG_X86_32 1 +#endif + +#include <asm/cpufeature.h> +#include <asm/xor-x86.h> #include <linux/time-internal.h> +#ifdef CONFIG_UML_TIME_TRAVEL_SUPPORT +#undef XOR_SELECT_TEMPLATE/* pick an arbitrary one - measuring isn't possible with inf-cpu */ #define XOR_SELECT_TEMPLATE (x) \ (time_travel_mode == TT_MODE_INFCPU ? &xor_block_8regs : NULL) +#endif + +#endif
arch/um/include/asm/xor_32.h new file +1 -0
@@ -0,0 +1 @@ +../../../x86/include/asm/xor_32.h
arch/um/include/asm/xor_64.h new file +1 -0
@@ -0,0 +1 @@ +../../../x86/include/asm/xor_64.h
arch/um/include/asm/xor_avx.h new file +1 -0
@@ -0,0 +1 @@ +../../../x86/include/asm/xor_avx.h
arch/um/include/shared/os.h +1 -0
@@ -187,6 +187,7 @@ int os_poll(unsigned int n, const int *fds);extern void os_early_checks (void );extern void os_check_bugs (void );extern void check_host_supports_tls (int *supports_tls,int *tls_min); +extern unsigned long check_host_cpu_features (const char **feature_names,int n);/* mem.c */ extern int create_mem_file (unsigned long long len);
arch/um/kernel/um_arch.c +15 -2
@@ -15,6 +15,7 @@#include <linux/kmsg_dump.h> #include <asm/processor.h> +#include <asm/cpufeature.h> #include <asm/sections.h> #include <asm/setup.h> #include <as-layout.h>
@@ -48,9 +49,12 @@ static void __init add_arg(char *arg)*/ struct cpuinfo_um boot_cpu_data = { .loops_per_jiffy =0 , - .ipi_pipe = {-1 ,-1 } + .ipi_pipe = {-1 ,-1 }, + .host_features =0 }; +EXPORT_SYMBOL (boot_cpu_data); + union thread_union cpu0_irqstack__section (".data..init_irqstack" ) = { .thread_info = INIT_THREAD_INFO(init_task) };
@@ -67,9 +71,15 @@ static int show_cpuinfo(struct seq_file *m, void *v)seq_printf (m,"model name\t: UML\n" );seq_printf (m,"mode\t\t: skas\n" );seq_printf (m,"host\t\t: %s\n" , host_info); -seq_printf (m,"bogomips\t: %lu.%02lu\n\n" , +seq_printf (m,"bogomips\t: %lu.%02lu\n" , loops_per_jiffy/(500000 /HZ ), (loops_per_jiffy/(5000 /HZ )) %100 ); +seq_printf (m,"flags\t\t:" ); +for (index =0 ; index <MAX_UM_CPU_FEATURES ; index++) { +if (boot_cpu_data.host_features & (1 << index)) +seq_printf (m," %s" , host_cpu_feature_names[index]); + } +seq_printf (m,"\n\n" );return 0 ; }
@@ -275,6 +285,9 @@ int __init linux_main(int argc, char **argv)/* OS sanity checks that need to happen before the kernel runs */ os_early_checks (); + boot_cpu_data.host_features = +check_host_cpu_features (host_cpu_feature_names,MAX_UM_CPU_FEATURES ); + brk_start = (unsigned long )sbrk (0 );/*
arch/um/os-Linux/start_up.c +32 -0
@@ -321,6 +321,38 @@ static void __init check_coredump_limit(void)os_info ("%llu\n" , (unsigned long long )lim.rlim_max); } +unsigned long __init check_host_cpu_features (const char **feature_names,int n) +{ +FILE *cpuinfo; +char *line =NULL ; +size_t len =0 ; +int i; +bool done_parsing = false; +unsigned long result =0 ; + + cpuinfo =fopen ("/proc/cpuinfo" ,"r" ); +if (cpuinfo ==NULL ) { +os_info ("Failed to get host CPU features\n" ); + }else { +while ((getline (&line, &len, cpuinfo)) !=-1 ) { +if (strstr (line,"flags" )) { +for (i =0 ; i < n; i++) { +if (strstr (line, feature_names[i])) { + result |= (1 << i); + } + } + done_parsing = true; + } +free (line); + line =NULL ; +if (done_parsing) +break ; + } +fclose (cpuinfo); + } +return result; +} +void __init os_early_checks (void ) {int pid;
Signature · 7 lines
2.20.1 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRe: [PATCH v4 2/7] um: enable the use of optimized xor routines in UML
Quoted 5 lines
+++
b/arch/um/include/asm/fpu/api.harch/um/include/asm/fpu/api.h new file +2
-0@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _ASM_UM_FPU_API_H
arch/um/include/asm/fpu/api.h line 12
Quoted 10 lines
arch/um/include/asm/fpu/api.h new file +10
-0+#define _ASM_UM_FPU_API_H + +/* Copyright (c) 2020 Cambridge Greys Ltd +* Copyright (c) 2020 Red Hat Inc. +* A set of "dummy" defines to allow the direct inclusion +* of x86 optimized copy, xor, etc routines into the +* UML code tree. */ + +#define kernel_fpu_begin () (void)0 +#define kernel_fpu_end () (void)0
I think I would prefer those to be static inlines, but YMMV.
johannes
arch/um/include/asm/xor-x86.h line 1
Quoted 7 lines
arch/um/include/asm/xor-x86.h new file +1
-0@@ -0,0 +1 @@ +../../../x86/include/asm/xor.h
Do these really need to be symlinks? Last I looked, it seemed that arch/x86/include/asm/ is actually in the include path?
Quoted 6 lines
arch/um/include/asm/xor.h +1
-1@@ -1,7 +1,22 @@/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm-generic/xor.h> +#ifndef _ASM_UM_XOR_H
arch/um/include/asm/xor.h line 12
Quoted 10 lines
arch/um/include/asm/xor.h +10
-0+#define _ASM_UM_XOR_H + +#ifdef CONFIG_64BIT +#undef CONFIG_X86_32 +#else +#define CONFIG_X86_32 1 +#endif + +#include <asm/cpufeature.h> +#include <asm/xor-x86.h>
and thus this could just be
#include_next <asm/xor.h>
without the symlink?
arch/um/include/asm/xor_32.h
Quoted 5 lines
arch/um/include/asm/xor_32.h new file +0
-0
And the others don't exist in um anyway, so probably aren't needed?
But maybe I'm confused about the include path, I didn't double-check now.
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Anton Ivanov
maintainerRe: [PATCH v4 2/7] um: enable the use of optimized xor routines in UML
Quoted 18 lines · Johannes Berg
Quoted 4 lines
+++
b/arch/um/include/asm/fpu/api.harch/um/include/asm/fpu/api.h new file +2
-0@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _ASM_UM_FPU_API_Harch/um/include/asm/fpu/api.h line 12
Quoted 10 lines
arch/um/include/asm/fpu/api.h new file +10
-0+#define _ASM_UM_FPU_API_H + +/* Copyright (c) 2020 Cambridge Greys Ltd +* Copyright (c) 2020 Red Hat Inc. +* A set of "dummy" defines to allow the direct inclusion +* of x86 optimized copy, xor, etc routines into the +* UML code tree. */ + +#define kernel_fpu_begin () (void)0 +#define kernel_fpu_end () (void)0I think I would prefer those to be static inlines, but YMMV.
johannes
Quoted 9 lines
arch/um/include/asm/xor-x86.h line 1
Quoted 7 lines
arch/um/include/asm/xor-x86.h new file +1
-0@@ -0,0 +1 @@ +../../../x86/include/asm/xor.hDo these really need to be symlinks? Last I looked, it seemed that
arch/x86/include/asm/is actually in the include path?
It is included, but it is included quite far down the list.
We pick up a few things out of there, but if we leave them "as is" they all default to their least optimized versions. The results clearly demonstrate that too - 30% difference on 64 bit and > 100% on 32 bit.
This is because we do not perform alternatives substitution. Our "alternatives" processing function in the UML startup is a noop.
My idea was to override that to the extent possible and get whatever mileage is possible without that.
I can give it a try to see how it looks if I use the x86 feature table and other bits which are picked up from there, but working with that is like pulling teeth without anaesthetic.
On the positive side this means that we can copy the alternatives code on x86.
I can give it another go. I tried early on and it was a bit painful.
A.
Quoted 43 lines
Quoted 7 lines
arch/um/include/asm/xor.h +1
-1@@ -1,7 +1,22 @@/* SPDX-License-Identifier: GPL-2.0 */ -#include <asm-generic/xor.h> +#ifndef _ASM_UM_XOR_Harch/um/include/asm/xor.h line 12
Quoted 10 lines
arch/um/include/asm/xor.h +10
-0+#define _ASM_UM_XOR_H + +#ifdef CONFIG_64BIT +#undef CONFIG_X86_32 +#else +#define CONFIG_X86_32 1 +#endif + +#include <asm/cpufeature.h> +#include <asm/xor-x86.h> and thus this could just be
#include_next <
asm/xor.h>without the symlink?
arch/um/include/asm/xor_32.h
Quoted 5 lines
arch/um/include/asm/xor_32.h new file +0
-0And the others don't exist in um anyway, so probably aren't needed?
But maybe I'm confused about the include path, I didn't double-check now.
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Signature · 9 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/ _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRe: [PATCH v4 2/7] um: enable the use of optimized xor routines in UML
Quoted 9 lines · Anton Ivanov
Quoted 7 lines
arch/um/include/asm/xor-x86.h line 1
Quoted 5 lines
arch/um/include/asm/xor-x86.h new file +1
-0@@ -0,0 +1 @@ +../../../x86/include/asm/xor.hDo these really need to be symlinks? Last I looked, it seemed that
arch/x86/include/asm/is actually in the include path?It is included, but it is included quite far down the list.
I see. So you're saying basically we'll get asm-generic/xor.h before the x86 version, and then we're getting the worst possible implementation, right?
Quoted 3 lines
We pick up a few things out of there, but if we leave them "as is" they all default to their least optimized versions. The results clearly demonstrate that too - 30% difference on 64 bit and > 100% on 32 bit.
Right.
Quoted 2 lines
This is because we do not perform alternatives substitution. Our "alternatives" processing function in the UML startup is a noop.
Oh, so we *do* get x86, but compatibility with ancient CPUs?
Quoted 2 lines
My idea was to override that to the extent possible and get whatever mileage is possible without that.
Makes sense.
Quoted 8 lines
I can give it a try to see how it looks if I use the x86 feature table and other bits which are picked up from there, but working with that is like pulling teeth without anaesthetic.
On the positive side this means that we can copy the alternatives code on x86.
I can give it another go. I tried early on and it was a bit painful.
Yeah, no, not sure ...
Maybe just doing something like
#include "../../../x86/include/asm/xor.h"
would be acceptable? It seems a bit better to me in the sense of being more obvious than the symlinks... but dunno.
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Anton Ivanov
maintainerRe: [PATCH v4 2/7] um: enable the use of optimized xor routines in UML
Quoted 11 lines · Johannes Berg
Quoted 7 lines · Anton Ivanov
Quoted 6 lines
arch/um/include/asm/xor-x86.h line 1
Quoted 4 lines
arch/um/include/asm/xor-x86.h new file +1
-0@@ -0,0 +1 @@ +../../../x86/include/asm/xor.hDo these really need to be symlinks? Last I looked, it seemed that
arch/x86/include/asm/is actually in the include path?It is included, but it is included quite far down the list.
I see. So you're saying basically we'll get
asm-generic/xor.hbefore the x86 version, and then we're getting the worst possible implementation, right?
A x86 implementation which is at "worst case scenario defaults" and has not undergone an alternative replacement for the actual CPU features can be as bad as the generic. In fact, in some cases generic may even be better :(
Quoted 8 lines
Quoted 3 lines
We pick up a few things out of there, but if we leave them "as is" they all default to their least optimized versions. The results clearly demonstrate that too - 30% difference on 64 bit and > 100% on 32 bit.
Right.
Quoted 2 lines
This is because we do not perform alternatives substitution. Our "alternatives" processing function in the UML startup is a noop.
Oh, so we *do* get x86, but compatibility with ancient CPUs?
Not just ancient CPUs. Ancient BUGGY cpus. It is usually the worst case scenario implementation.
Quoted 13 lines
Quoted 3 lines
My idea was to override that to the extent possible and get whatever mileage is possible without that.
Makes sense.
Quoted 8 lines
I can give it a try to see how it looks if I use the x86 feature table and other bits which are picked up from there, but working with that is like pulling teeth without anaesthetic.
On the positive side this means that we can copy the alternatives code on x86.
I can give it another go. I tried early on and it was a bit painful.
Quoted 8 lines
Yeah, no, not sure ...
Maybe just doing something like
#include "
../../../x86/include/asm/xor.h"would be acceptable? It seems a bit better to me in the sense of being more obvious than the symlinks... but dunno.
That (and everything else) relies on the CPU Features available macros. I "cheated" on those and created our own using just one ulong - the 5-6 bits which are relevant to us. That is the original idea behind pulling things in and symlinking - to make sure they pick OUR defs, not the whole array of features out of the x86 tree.
We also need to noop or redefine a few things like fpu_exit, fpu_enter, etc.
However, based on the discussion we have had so far, I should revisit this and do it ONLY where it is needed, not in all cases.
I will give it another go on Monday.
Looking at the results, it's definitely worth it. For me it is a question of how to do it, not "should we do it". 30% difference is in the realm of "definitely worth it".
Quoted 4 lines
johannes
Signature · 9 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/ _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Anton Ivanov
maintainerRe: [PATCH v4 2/7] um: enable the use of optimized xor routines in UML
In reply to Johannes BergQuoted 12 lines · Johannes Berg
Quoted 7 lines · Anton Ivanov
Quoted 6 lines
arch/um/include/asm/xor-x86.h line 1
Quoted 4 lines
arch/um/include/asm/xor-x86.h new file +1
-0@@ -0,0 +1 @@ +../../../x86/include/asm/xor.hDo these really need to be symlinks? Last I looked, it seemed that
arch/x86/include/asm/is actually in the include path?It is included, but it is included quite far down the list.
I see. So you're saying basically we'll get
asm-generic/xor.hbefore the x86 version, and then we're getting the worst possible implementation, right?
Quoted 8 lines
Quoted 3 lines
We pick up a few things out of there, but if we leave them "as is" they all default to their least optimized versions. The results clearly demonstrate that too - 30% difference on 64 bit and > 100% on 32 bit.
Right.
Quoted 2 lines
This is because we do not perform alternatives substitution. Our "alternatives" processing function in the UML startup is a noop.
Oh, so we *do* get x86, but compatibility with ancient CPUs?
I had a look at the alternatives processing in x86 once again. The exact definition of what we get to use is: "ancient, buggy CPUs in SMP mode".
So in addition to using one of the worst case scenario implementations, we also do not do patching of SMP verbiage to UP where appropriate which is done on x86.
I just had a go at trying to reuse the aforementioned alternatives processing "as is" from the x86 tree.
This is pretty much a no-go from the start. We can't use it. It relies on "owning" int handlers and generating int instructions in places. If I understand it correctly, it will interfere with gdb by doing its own INT 3 work. Key parts of it are also "if-defed away" from us at present.
IMHO - it will have to be rewritten mostly from scratch for UML.
I will have a look if we can reuse the cpu feature and bug definitions instead of using our own. This will allow us to reuse the bits which relate to crypto - xor, etc as those are cases/ifdefs instead of alternatives.
A.
Quoted 30 lines
Quoted 3 lines
My idea was to override that to the extent possible and get whatever mileage is possible without that.
Makes sense.
Quoted 8 lines
I can give it a try to see how it looks if I use the x86 feature table and other bits which are picked up from there, but working with that is like pulling teeth without anaesthetic.
On the positive side this means that we can copy the alternatives code on x86.
I can give it another go. I tried early on and it was a bit painful.
Yeah, no, not sure ...
Maybe just doing something like
#include "
../../../x86/include/asm/xor.h"would be acceptable? It seems a bit better to me in the sense of being more obvious than the symlinks... but dunno.
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Signature · 9 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/ _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRe: [PATCH v4 2/7] um: enable the use of optimized xor routines in UML
Quoted 4 lines · Anton Ivanov
I had a look at the alternatives processing in x86 once again. The exact definition of what we get to use is: "ancient, buggy CPUs in SMP mode".
fun.
Quoted 3 lines
So in addition to using one of the worst case scenario implementations, we also do not do patching of SMP verbiage to UP where appropriate which is done on x86.
right.
Quoted 9 lines
I just had a go at trying to reuse the aforementioned alternatives processing "as is" from the x86 tree.
This is pretty much a no-go from the start. We can't use it. It relies on "owning" int handlers and generating int instructions in places. If I understand it correctly, it will interfere with gdb by doing its own INT 3 work. Key parts of it are also "if-defed away" from us at present.
Quoted 6 lines
IMHO - it will have to be rewritten mostly from scratch for UML.
I will have a look if we can reuse the cpu feature and bug definitions instead of using our own. This will allow us to reuse the bits which relate to crypto - xor, etc as those are cases/ifdefs instead of alternatives.
I agree.
But I feel like something I said sent you on this path, and that never was my intent. I don't mind using the x86 header files in a fashion similar to what you did, I just didn't like the symlinks because it seems those would be awkward if somebody ever wants to port UML to some other architecture ...
Maybe just put there header files with
#include "../../x86/include/asm/xor.h"
or something like that just to avoid the symlinks?
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Anton Ivanov
maintainerRe: [PATCH v4 2/7] um: enable the use of optimized xor routines in UML
Quoted 34 lines · Johannes Berg
Quoted 3 lines · Anton Ivanov
I had a look at the alternatives processing in x86 once again. The exact definition of what we get to use is: "ancient, buggy CPUs in SMP mode".
fun.
Quoted 3 lines
So in addition to using one of the worst case scenario implementations, we also do not do patching of SMP verbiage to UP where appropriate which is done on x86.
right.
Quoted 9 lines
I just had a go at trying to reuse the aforementioned alternatives processing "as is" from the x86 tree.
This is pretty much a no-go from the start. We can't use it. It relies on "owning" int handlers and generating int instructions in places. If I understand it correctly, it will interfere with gdb by doing its own INT 3 work. Key parts of it are also "if-defed away" from us at present.
Quoted 6 lines
IMHO - it will have to be rewritten mostly from scratch for UML.
I will have a look if we can reuse the cpu feature and bug definitions instead of using our own. This will allow us to reuse the bits which relate to crypto - xor, etc as those are cases/ifdefs instead of alternatives.
I agree.
But I feel like something I said sent you on this path, and that never was my intent. I don't mind using the x86 header files in a fashion similar to what you did, I just didn't like the symlinks because it seems those would be awkward if somebody ever wants to port UML to some other architecture ...
Quoted 5 lines
Maybe just put there header files with
#include "
../../x86/include/asm/xor.h"or something like that just to avoid the symlinks?
I agree with you - that is how we should use them.
We still need to have "features" code and boot time CPU detection.
I am trying to figure out if it is worth it to borrow some of that instead of my original hack which reused the names with a different back-end. That is another can of worms because some of that code is actually generated at compile time by x86 so I need to figure out how to pull that into our build system.
Quoted 3 lines
johannes
Signature · 9 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/ _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
[email protected]
maintainerPATCH v4 3/7 um: "borrow" atomics from x86 architecture
In reply to [email protected]From: Anton Ivanov <[email protected]>
This moves UML on 64 bit from generic atomics to their x86 equivalents.
Generic atomics bracket most operations by interrupts off/interrupts on. This is quite expensive on UML - it translates to changing the signal mask and rerunning the signal loop every time.
--- arch/um/include/asm/atomic-x86.h | 1 + arch/um/include/asm/atomic.h | 7 +++++++ arch/um/include/asm/atomic64_64.h | 1 + 3 files changed, 9 insertions(+) create mode 120000 arch/um/include/asm/atomic-x86.h create mode 100644 arch/um/include/asm/atomic.h create mode 120000 arch/um/include/asm/atomic64_64.h
arch/um/include/asm/atomic-x86.h new file +1 -0
@@ -0,0 +1 @@ +../../../x86/include/asm/atomic.h
arch/um/include/asm/atomic.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_ATOMIC_XOR_H +#define _ASM_ATOMIC_XOR_H + +#include <asm/atomic-x86.h> + +#endif
arch/um/include/asm/atomic64_64.h new file +1 -0
@@ -0,0 +1 @@ +../../../x86/include/asm/atomic64_64.h
Signature · 7 lines
2.20.1 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRe: [PATCH v4 3/7] um: "borrow" atomics from x86 architecture
arch/um/include/asm/atomic.h line 2
Quoted 5 lines · On Fri, 2020-12-11 at 17:45 +0000, [email protected] wrote:
+++
b/arch/um/include/asm/atomic.harch/um/include/asm/atomic.h new file +2
-0@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_ATOMIC_XOR_H
XOR?
And also here - are the symlinks really needed?
Not that I mind them too much, but it's a bit strange ... and would be a lot harder to port to other arches, if anyone should be inclined, if there are hard symlinks to x86.
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Anton Ivanov
maintainerRe: [PATCH v4 3/7] um: "borrow" atomics from x86 architecture
Quoted 7 lines · Johannes Berg
arch/um/include/asm/atomic.h line 2
Quoted 4 lines · On Fri, 2020-12-11 at 17:45 +0000, [email protected] wrote:
+++
b/arch/um/include/asm/atomic.harch/um/include/asm/atomic.h new file +2
-0@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_ATOMIC_XOR_HXOR?
Brainfart
Will fix it in v5.
Quoted 10 lines
And also here - are the symlinks really needed?
Not that I mind them too much, but it's a bit strange ... and would be a lot harder to port to other arches, if anyone should be inclined, if there are hard symlinks to x86.
johannes
Signature · 9 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/ _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
[email protected]
maintainerPATCH v4 4/7 um: add a UML specific futex implementation
In reply to [email protected]From: Anton Ivanov <[email protected]>
The generic asm futex implementation emulates atomic access to memory by doing a get_user followed by put_user. These translate to two mapping operations on UML with paging enabled in the meantime. This, in turn may end up changing interrupts, invoking the signal loop, etc.
This replaces the generic implementation by a mapping followed by an operation on the mapped segment.
--- arch/um/include/asm/Kbuild | 1 - arch/um/include/asm/futex.h | 14 ++++ arch/um/kernel/skas/uaccess.c | 130 ++++++++++++++++++++++++++++++++++ 3 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 arch/um/include/asm/futex.h
arch/um/include/asm/Kbuild +0 -1
@@ -8,7 +8,6 @@ generic-y += emergency-restart.h generic-y += exec.h generic-y += extable.h generic-y += ftrace.h -generic-y += futex.h generic-y += hw_irq.h generic-y += irq_regs.h generic-y += irq_work.h
arch/um/include/asm/futex.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_FUTEX_H +#define _ASM_GENERIC_FUTEX_H + +#include <linux/futex.h> +#include <linux/uaccess.h> +#include <asm/errno.h> + + +extern int arch_futex_atomic_op_inuser (int op,u32 oparg,int *oval,u32 __user *uaddr); +extern int futex_atomic_cmpxchg_inatomic (u32 *uval,u32 __user *uaddr, +u32 oldval,u32 newval); + +#endif
arch/um/kernel/skas/uaccess.c +130 -0
139 lines not on this page · raw message
Signature · 7 lines
2.20.1 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRe: [PATCH v4 4/7] um: add a UML specific futex implementation
Quoted 5 lines · On Fri, 2020-12-11 at 17:45 +0000, [email protected] wrote:
+++
b/arch/um/include/asm/futex.harch/um/include/asm/futex.h new file +2
-0@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_FUTEX_H
arch/um/include/asm/futex.h line 12
Quoted 10 lines
arch/um/include/asm/futex.h new file +10
-0+#define _ASM_GENERIC_FUTEX_H + +#include <linux/futex.h> +#include <linux/uaccess.h> +#include <asm/errno.h> + + +extern int arch_futex_atomic_op_inuser (int op,u32 oparg,int *oval,u32 __user *uaddr); +extern int futex_atomic_cmpxchg_inatomic (u32 *uval,u32 __user *uaddr, +u32 oldval,u32 newval);
"extern" for functions in header files is kinda pointless, and usually not used.
(indentation also seems off a bit)
arch/um/kernel/skas/uaccess.c long __strnlen_user(const void __user *str, long len) · line 256
Quoted 4 lines
arch/um/kernel/skas/uaccess.c +4
-0+/** +* arch_futex_atomic_op_inuser() - Atomic arithmetic operation with constant +* argument and comparison of the previous +* futex value with another constant.
Is there much value in (copying?) the documentation? It wouldn't get included anywhere, I'd think.
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
[email protected]
maintainerPATCH v4 5/7 um: "borrow" cmpxchg from x86 tree in UML
In reply to [email protected]From: Anton Ivanov <[email protected]>
UML was falling back to asm-generic cmpxchg which emulates atomic behaviour by turning irqs on/off. On UML this means turning on/off signals for each cmpxchg which is expensive.
--- arch/um/include/asm/cmpxchg-x86.h | 1 + arch/um/include/asm/cmpxchg.h | 7 +++++++ arch/um/include/asm/cmpxchg_32.h | 1 + arch/um/include/asm/cmpxchg_64.h | 1 + 4 files changed, 10 insertions(+) create mode 120000 arch/um/include/asm/cmpxchg-x86.h create mode 100644 arch/um/include/asm/cmpxchg.h create mode 120000 arch/um/include/asm/cmpxchg_32.h create mode 120000 arch/um/include/asm/cmpxchg_64.h
arch/um/include/asm/cmpxchg-x86.h new file +1 -0
@@ -0,0 +1 @@ +../../../x86/include/asm/cmpxchg.h
arch/um/include/asm/cmpxchg.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_UM_CMPXCHG_H +#define _ASM_UM_CMPXCHG_H + +#include <asm/cmpxchg-x86.h> + +#endif
arch/um/include/asm/cmpxchg_32.h new file +1 -0
@@ -0,0 +1 @@ +../../../x86/include/asm/cmpxchg_32.h
arch/um/include/asm/cmpxchg_64.h new file +1 -0
@@ -0,0 +1 @@ +../../../x86/include/asm/cmpxchg_64.h
Signature · 7 lines
2.20.1 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
[email protected]
maintainerPATCH v4 6/7 um: swithch futex ops to cmpxchg
In reply to [email protected]From: Anton Ivanov <[email protected]>
As a result of switching from emulated to true atomic cmpxchg we can use cmpxchg in the corresponding um futex op.
--- arch/um/kernel/skas/uaccess.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
arch/um/kernel/skas/uaccess.c +1 -3
@@ -343,7 +343,6 @@ EXPORT_SYMBOL(arch_futex_atomic_op_inuser);* -EAGAIN - Atomic operation was unable to complete due to contention * -ENOSYS - Function not implemented (only if !HAVE_FUTEX_CMPXCHG) */ -int futex_atomic_cmpxchg_inatomic (u32 *uval,u32 __user *uaddr,u32 oldval,u32 newval) {
@@ -366,8 +365,7 @@ int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr, val = *uaddr; -if (val == oldval) - *uaddr = newval; + ret =cmpxchg (uaddr, oldval, newval); *uval = val;pagefault_enable ();
Signature · 7 lines
2.20.1 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
Johannes Berg
maintainerRe: [PATCH v4 6/7] um: swithch futex ops to cmpxchg
Typo in the subject :)
Quoted 2 lines
As a result of switching from emulated to true atomic cmpxchg we can use cmpxchg in the corresponding um futex op.
But this seems odd - maybe just reorder the patches so the futex code can directly have this squashed in?
johannes
_______________________________________________
linux-um mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-um
Anton Ivanov
maintainerRe: [PATCH v4 6/7] um: swithch futex ops to cmpxchg
Quoted 6 lines · Johannes Berg
Typo in the subject :)
Quoted 2 lines
As a result of switching from emulated to true atomic cmpxchg we can use cmpxchg in the corresponding um futex op.
But this seems odd - maybe just reorder the patches so the futex code can directly have this squashed in?
You do not want to do that if you are still using the generic cmpxchg. That is quite cumbersome. If we reorder the cmpxchg before the futex, then it can be folded in.
I will do it in v5
A.
Quoted 5 lines
johannes
Signature · 9 lines
Anton R. Ivanov Cambridgegreys Limited. Registered in England. Company Number 10273661 https://www.cambridgegreys.com/ _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um
[email protected]
maintainerPATCH v4 7/7 um: borrow bitops from the x86 tree
In reply to [email protected]From: Anton Ivanov <[email protected]>
Using x86 bitops instead of the asm-generic allows to squeeze a couple of percents improvement on fs IO in UML. It should improve other areas as well.
--- arch/um/include/asm/bitops-x86.h | 1 + arch/um/include/asm/bitops.h | 7 +++++++ 2 files changed, 8 insertions(+) create mode 120000 arch/um/include/asm/bitops-x86.h create mode 100644 arch/um/include/asm/bitops.h
arch/um/include/asm/bitops-x86.h new file +1 -0
@@ -0,0 +1 @@ +../../../x86/include/asm/bitops.h
arch/um/include/asm/bitops.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_UM_BITOPS_H +#define _ASM_UM_BITOPS_H + +#include <asm/bitops-x86.h> + +#endif
Signature · 7 lines
2.20.1 _______________________________________________ linux-um mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-um