License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 15:07:57 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2008-10-22 22:26:29 -07:00
|
|
|
#ifndef _ASM_X86_PERCPU_H
|
|
|
|
#define _ASM_X86_PERCPU_H
|
2008-01-30 13:32:53 +01:00
|
|
|
|
2009-01-13 20:41:35 +09:00
|
|
|
#ifdef CONFIG_X86_64
|
2009-01-13 20:41:35 +09:00
|
|
|
#define __percpu_seg gs
|
2023-10-17 18:27:34 +02:00
|
|
|
#define __percpu_rel (%rip)
|
2009-01-13 20:41:35 +09:00
|
|
|
#else
|
2009-01-13 20:41:35 +09:00
|
|
|
#define __percpu_seg fs
|
2023-10-17 18:27:34 +02:00
|
|
|
#define __percpu_rel
|
2007-10-11 11:20:03 +02:00
|
|
|
#endif
|
2008-01-30 13:32:53 +01:00
|
|
|
|
|
|
|
#ifdef __ASSEMBLY__
|
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
2023-10-17 18:27:34 +02:00
|
|
|
#define __percpu %__percpu_seg:
|
|
|
|
#else
|
|
|
|
#define __percpu
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PER_CPU_VAR(var) __percpu(var)__percpu_rel
|
2008-01-30 13:32:53 +01:00
|
|
|
|
2009-02-08 09:58:39 -05:00
|
|
|
#ifdef CONFIG_X86_64_SMP
|
|
|
|
#define INIT_PER_CPU_VAR(var) init_per_cpu__##var
|
|
|
|
#else
|
2009-10-29 22:34:15 +09:00
|
|
|
#define INIT_PER_CPU_VAR(var) var
|
2009-02-08 09:58:39 -05:00
|
|
|
#endif
|
|
|
|
|
2008-01-30 13:32:53 +01:00
|
|
|
#else /* ...!ASSEMBLY */
|
|
|
|
|
2023-12-04 22:02:29 +01:00
|
|
|
#include <linux/build_bug.h>
|
2009-01-13 20:41:35 +09:00
|
|
|
#include <linux/stringify.h>
|
2023-12-15 17:02:03 -05:00
|
|
|
#include <asm/asm.h>
|
2008-01-30 13:32:53 +01:00
|
|
|
|
2009-01-13 20:41:35 +09:00
|
|
|
#ifdef CONFIG_SMP
|
2023-10-04 16:49:43 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_CC_HAS_NAMED_AS
|
|
|
|
|
2023-12-04 22:02:31 +01:00
|
|
|
#ifdef __CHECKER__
|
|
|
|
#define __seg_gs __attribute__((address_space(__seg_gs)))
|
|
|
|
#define __seg_fs __attribute__((address_space(__seg_fs)))
|
|
|
|
#endif
|
|
|
|
|
2023-10-04 16:49:43 +02:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
#define __percpu_seg_override __seg_gs
|
|
|
|
#else
|
|
|
|
#define __percpu_seg_override __seg_fs
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define __percpu_prefix ""
|
|
|
|
|
|
|
|
#else /* CONFIG_CC_HAS_NAMED_AS */
|
|
|
|
|
|
|
|
#define __percpu_seg_override
|
2011-03-26 20:57:18 -05:00
|
|
|
#define __percpu_prefix "%%"__stringify(__percpu_seg)":"
|
2023-10-04 16:49:43 +02:00
|
|
|
|
|
|
|
#endif /* CONFIG_CC_HAS_NAMED_AS */
|
|
|
|
|
|
|
|
#define __force_percpu_prefix "%%"__stringify(__percpu_seg)":"
|
2012-05-11 15:35:27 +08:00
|
|
|
#define __my_cpu_offset this_cpu_read(this_cpu_off)
|
2010-09-09 18:17:26 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Compared to the generic __my_cpu_offset version, the following
|
|
|
|
* saves one instruction and avoids clobbering a temp register.
|
x86/percpu: Unify arch_raw_cpu_ptr() defines
When building a 32-bit vDSO for a 64-bit kernel, games are played with
CONFIG_X86_64. {this,raw}_cpu_read_8() macros are conditionally defined
on CONFIG_X86_64 and when CONFIG_X86_64 is undefined in fake_32bit_build.h
various build failures in generic percpu header files can happen. To make
things worse, the build of 32-bit vDSO for a 64-bit kernel grew dependency
on arch_raw_cpu_ptr() macro and the build fails if arch_raw_cpu_ptr()
macro is not defined.
To mitigate these issues, x86 carefully defines arch_raw_cpu_ptr() to
avoid any dependency on raw_cpu_read_8() and thus CONFIG_X86_64. W/o
segment register support, the definition uses size-agnostic MOV asm
mnemonic and hopes that _ptr argument won't ever be 64-bit size on
32-bit targets (although newer GCCs warn for this situation with
"unsupported size for integer register"), and w/ segment register
support the definition uses size-agnostic __raw_cpu_read() macro.
Fortunately, raw_cpu_read() is not used in 32-bit vDSO for a 64-bit kernel.
However, we can't simply omit the definition of arch_raw_cpu_read(),
since the build will fail when building vdso/vdso32/vclock_gettime.o.
The patch defines arch_raw_cpu_ptr to BUILD_BUG() when BUILD_VDSO32_64
macro is defined. This way, we are sure that arch_raw_cpu_ptr() won't
actually be used in 32-bit VDSO for a 64-bit kernel, but it is still
defined to prevent build failure.
Finally, we can unify arch_raw_cpu_ptr() between builds w/ and w/o
x86 segment register support, substituting two tricky macro definitions
with a straightforward implementation.
There is no size difference and no difference in number of this_cpu_off
accesses between patched and unpatched kernel when the kernel is built
either w/ and w/o segment register support.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20240322102730.209141-1-ubizjak@gmail.com
2024-03-22 11:27:14 +01:00
|
|
|
*
|
|
|
|
* arch_raw_cpu_ptr should not be used in 32-bit VDSO for a 64-bit
|
|
|
|
* kernel, because games are played with CONFIG_X86_64 there and
|
|
|
|
* sizeof(this_cpu_off) becames 4.
|
2010-09-09 18:17:26 +02:00
|
|
|
*/
|
x86/percpu: Unify arch_raw_cpu_ptr() defines
When building a 32-bit vDSO for a 64-bit kernel, games are played with
CONFIG_X86_64. {this,raw}_cpu_read_8() macros are conditionally defined
on CONFIG_X86_64 and when CONFIG_X86_64 is undefined in fake_32bit_build.h
various build failures in generic percpu header files can happen. To make
things worse, the build of 32-bit vDSO for a 64-bit kernel grew dependency
on arch_raw_cpu_ptr() macro and the build fails if arch_raw_cpu_ptr()
macro is not defined.
To mitigate these issues, x86 carefully defines arch_raw_cpu_ptr() to
avoid any dependency on raw_cpu_read_8() and thus CONFIG_X86_64. W/o
segment register support, the definition uses size-agnostic MOV asm
mnemonic and hopes that _ptr argument won't ever be 64-bit size on
32-bit targets (although newer GCCs warn for this situation with
"unsupported size for integer register"), and w/ segment register
support the definition uses size-agnostic __raw_cpu_read() macro.
Fortunately, raw_cpu_read() is not used in 32-bit vDSO for a 64-bit kernel.
However, we can't simply omit the definition of arch_raw_cpu_read(),
since the build will fail when building vdso/vdso32/vclock_gettime.o.
The patch defines arch_raw_cpu_ptr to BUILD_BUG() when BUILD_VDSO32_64
macro is defined. This way, we are sure that arch_raw_cpu_ptr() won't
actually be used in 32-bit VDSO for a 64-bit kernel, but it is still
defined to prevent build failure.
Finally, we can unify arch_raw_cpu_ptr() between builds w/ and w/o
x86 segment register support, substituting two tricky macro definitions
with a straightforward implementation.
There is no size difference and no difference in number of this_cpu_off
accesses between patched and unpatched kernel when the kernel is built
either w/ and w/o segment register support.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20240322102730.209141-1-ubizjak@gmail.com
2024-03-22 11:27:14 +01:00
|
|
|
#ifndef BUILD_VDSO32_64
|
|
|
|
#define arch_raw_cpu_ptr(_ptr) \
|
2023-10-04 16:49:43 +02:00
|
|
|
({ \
|
2024-04-04 11:42:03 +02:00
|
|
|
unsigned long tcp_ptr__ = raw_cpu_read_long(this_cpu_off); \
|
2024-04-02 19:50:38 +02:00
|
|
|
tcp_ptr__ += (__force unsigned long)(_ptr); \
|
x86/percpu: Unify arch_raw_cpu_ptr() defines
When building a 32-bit vDSO for a 64-bit kernel, games are played with
CONFIG_X86_64. {this,raw}_cpu_read_8() macros are conditionally defined
on CONFIG_X86_64 and when CONFIG_X86_64 is undefined in fake_32bit_build.h
various build failures in generic percpu header files can happen. To make
things worse, the build of 32-bit vDSO for a 64-bit kernel grew dependency
on arch_raw_cpu_ptr() macro and the build fails if arch_raw_cpu_ptr()
macro is not defined.
To mitigate these issues, x86 carefully defines arch_raw_cpu_ptr() to
avoid any dependency on raw_cpu_read_8() and thus CONFIG_X86_64. W/o
segment register support, the definition uses size-agnostic MOV asm
mnemonic and hopes that _ptr argument won't ever be 64-bit size on
32-bit targets (although newer GCCs warn for this situation with
"unsupported size for integer register"), and w/ segment register
support the definition uses size-agnostic __raw_cpu_read() macro.
Fortunately, raw_cpu_read() is not used in 32-bit vDSO for a 64-bit kernel.
However, we can't simply omit the definition of arch_raw_cpu_read(),
since the build will fail when building vdso/vdso32/vclock_gettime.o.
The patch defines arch_raw_cpu_ptr to BUILD_BUG() when BUILD_VDSO32_64
macro is defined. This way, we are sure that arch_raw_cpu_ptr() won't
actually be used in 32-bit VDSO for a 64-bit kernel, but it is still
defined to prevent build failure.
Finally, we can unify arch_raw_cpu_ptr() between builds w/ and w/o
x86 segment register support, substituting two tricky macro definitions
with a straightforward implementation.
There is no size difference and no difference in number of this_cpu_off
accesses between patched and unpatched kernel when the kernel is built
either w/ and w/o segment register support.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20240322102730.209141-1-ubizjak@gmail.com
2024-03-22 11:27:14 +01:00
|
|
|
(typeof(*(_ptr)) __kernel __force *)tcp_ptr__; \
|
2010-09-09 18:17:26 +02:00
|
|
|
})
|
x86/percpu: Unify arch_raw_cpu_ptr() defines
When building a 32-bit vDSO for a 64-bit kernel, games are played with
CONFIG_X86_64. {this,raw}_cpu_read_8() macros are conditionally defined
on CONFIG_X86_64 and when CONFIG_X86_64 is undefined in fake_32bit_build.h
various build failures in generic percpu header files can happen. To make
things worse, the build of 32-bit vDSO for a 64-bit kernel grew dependency
on arch_raw_cpu_ptr() macro and the build fails if arch_raw_cpu_ptr()
macro is not defined.
To mitigate these issues, x86 carefully defines arch_raw_cpu_ptr() to
avoid any dependency on raw_cpu_read_8() and thus CONFIG_X86_64. W/o
segment register support, the definition uses size-agnostic MOV asm
mnemonic and hopes that _ptr argument won't ever be 64-bit size on
32-bit targets (although newer GCCs warn for this situation with
"unsupported size for integer register"), and w/ segment register
support the definition uses size-agnostic __raw_cpu_read() macro.
Fortunately, raw_cpu_read() is not used in 32-bit vDSO for a 64-bit kernel.
However, we can't simply omit the definition of arch_raw_cpu_read(),
since the build will fail when building vdso/vdso32/vclock_gettime.o.
The patch defines arch_raw_cpu_ptr to BUILD_BUG() when BUILD_VDSO32_64
macro is defined. This way, we are sure that arch_raw_cpu_ptr() won't
actually be used in 32-bit VDSO for a 64-bit kernel, but it is still
defined to prevent build failure.
Finally, we can unify arch_raw_cpu_ptr() between builds w/ and w/o
x86 segment register support, substituting two tricky macro definitions
with a straightforward implementation.
There is no size difference and no difference in number of this_cpu_off
accesses between patched and unpatched kernel when the kernel is built
either w/ and w/o segment register support.
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20240322102730.209141-1-ubizjak@gmail.com
2024-03-22 11:27:14 +01:00
|
|
|
#else
|
|
|
|
#define arch_raw_cpu_ptr(_ptr) ({ BUILD_BUG(); (typeof(_ptr))0; })
|
|
|
|
#endif
|
2023-10-15 22:24:40 +02:00
|
|
|
|
2023-11-05 22:34:35 +01:00
|
|
|
#define PER_CPU_VAR(var) %__percpu_seg:(var)__percpu_rel
|
|
|
|
|
2023-10-04 16:49:43 +02:00
|
|
|
#else /* CONFIG_SMP */
|
|
|
|
#define __percpu_seg_override
|
2011-03-26 20:57:18 -05:00
|
|
|
#define __percpu_prefix ""
|
2023-10-04 16:49:43 +02:00
|
|
|
#define __force_percpu_prefix ""
|
2023-11-05 22:34:35 +01:00
|
|
|
|
|
|
|
#define PER_CPU_VAR(var) (var)__percpu_rel
|
|
|
|
|
2023-10-04 16:49:43 +02:00
|
|
|
#endif /* CONFIG_SMP */
|
2008-01-30 13:32:53 +01:00
|
|
|
|
2023-10-04 16:49:43 +02:00
|
|
|
#define __my_cpu_type(var) typeof(var) __percpu_seg_override
|
2024-04-04 11:42:02 +02:00
|
|
|
#define __my_cpu_ptr(ptr) (__my_cpu_type(*(ptr))*)(__force uintptr_t)(ptr)
|
2024-04-02 19:50:38 +02:00
|
|
|
#define __my_cpu_var(var) (*__my_cpu_ptr(&(var)))
|
2014-11-04 08:50:48 +00:00
|
|
|
#define __percpu_arg(x) __percpu_prefix "%" #x
|
2023-10-04 16:49:43 +02:00
|
|
|
#define __force_percpu_arg(x) __force_percpu_prefix "%" #x
|
2011-03-26 20:57:18 -05:00
|
|
|
|
2009-02-08 09:58:39 -05:00
|
|
|
/*
|
|
|
|
* Initialized pointers to per-cpu variables needed for the boot
|
|
|
|
* processor need to use these macros to get the proper address
|
|
|
|
* offset from __per_cpu_load on SMP.
|
|
|
|
*
|
|
|
|
* There also must be an entry in vmlinux_64.lds.S
|
|
|
|
*/
|
|
|
|
#define DECLARE_INIT_PER_CPU(var) \
|
2009-10-29 22:34:15 +09:00
|
|
|
extern typeof(var) init_per_cpu_var(var)
|
2009-02-08 09:58:39 -05:00
|
|
|
|
|
|
|
#ifdef CONFIG_X86_64_SMP
|
|
|
|
#define init_per_cpu_var(var) init_per_cpu__##var
|
|
|
|
#else
|
2009-10-29 22:34:15 +09:00
|
|
|
#define init_per_cpu_var(var) var
|
2009-02-08 09:58:39 -05:00
|
|
|
#endif
|
|
|
|
|
2008-01-30 13:32:53 +01:00
|
|
|
/* For arch-specific code, we can use direct single-insn ops (they
|
|
|
|
* don't give an lvalue though). */
|
|
|
|
|
2020-07-20 13:49:15 -07:00
|
|
|
#define __pcpu_type_1 u8
|
|
|
|
#define __pcpu_type_2 u16
|
|
|
|
#define __pcpu_type_4 u32
|
|
|
|
#define __pcpu_type_8 u64
|
|
|
|
|
|
|
|
#define __pcpu_cast_1(val) ((u8)(((unsigned long) val) & 0xff))
|
|
|
|
#define __pcpu_cast_2(val) ((u16)(((unsigned long) val) & 0xffff))
|
|
|
|
#define __pcpu_cast_4(val) ((u32)(((unsigned long) val) & 0xffffffff))
|
|
|
|
#define __pcpu_cast_8(val) ((u64)(val))
|
|
|
|
|
|
|
|
#define __pcpu_op1_1(op, dst) op "b " dst
|
|
|
|
#define __pcpu_op1_2(op, dst) op "w " dst
|
|
|
|
#define __pcpu_op1_4(op, dst) op "l " dst
|
|
|
|
#define __pcpu_op1_8(op, dst) op "q " dst
|
|
|
|
|
|
|
|
#define __pcpu_op2_1(op, src, dst) op "b " src ", " dst
|
|
|
|
#define __pcpu_op2_2(op, src, dst) op "w " src ", " dst
|
|
|
|
#define __pcpu_op2_4(op, src, dst) op "l " src ", " dst
|
|
|
|
#define __pcpu_op2_8(op, src, dst) op "q " src ", " dst
|
|
|
|
|
|
|
|
#define __pcpu_reg_1(mod, x) mod "q" (x)
|
|
|
|
#define __pcpu_reg_2(mod, x) mod "r" (x)
|
|
|
|
#define __pcpu_reg_4(mod, x) mod "r" (x)
|
|
|
|
#define __pcpu_reg_8(mod, x) mod "r" (x)
|
|
|
|
|
|
|
|
#define __pcpu_reg_imm_1(x) "qi" (x)
|
|
|
|
#define __pcpu_reg_imm_2(x) "ri" (x)
|
|
|
|
#define __pcpu_reg_imm_4(x) "ri" (x)
|
|
|
|
#define __pcpu_reg_imm_8(x) "re" (x)
|
|
|
|
|
2020-07-20 13:49:16 -07:00
|
|
|
#define percpu_to_op(size, qual, op, _var, _val) \
|
|
|
|
do { \
|
|
|
|
__pcpu_type_##size pto_val__ = __pcpu_cast_##size(_val); \
|
|
|
|
if (0) { \
|
|
|
|
typeof(_var) pto_tmp__; \
|
|
|
|
pto_tmp__ = (_val); \
|
|
|
|
(void)pto_tmp__; \
|
|
|
|
} \
|
|
|
|
asm qual(__pcpu_op2_##size(op, "%[val]", __percpu_arg([var])) \
|
2023-10-04 16:49:43 +02:00
|
|
|
: [var] "+m" (__my_cpu_var(_var)) \
|
2020-07-20 13:49:16 -07:00
|
|
|
: [val] __pcpu_reg_imm_##size(pto_val__)); \
|
2008-03-23 01:03:06 -07:00
|
|
|
} while (0)
|
|
|
|
|
2020-07-20 13:49:18 -07:00
|
|
|
#define percpu_unary_op(size, qual, op, _var) \
|
|
|
|
({ \
|
|
|
|
asm qual (__pcpu_op1_##size(op, __percpu_arg([var])) \
|
2023-10-04 16:49:43 +02:00
|
|
|
: [var] "+m" (__my_cpu_var(_var))); \
|
2020-07-20 13:49:18 -07:00
|
|
|
})
|
|
|
|
|
2010-01-05 15:34:50 +09:00
|
|
|
/*
|
|
|
|
* Generate a percpu add to memory instruction and optimize code
|
2010-04-19 11:51:16 -07:00
|
|
|
* if one is added or subtracted.
|
2010-01-05 15:34:50 +09:00
|
|
|
*/
|
2020-07-20 13:49:18 -07:00
|
|
|
#define percpu_add_op(size, qual, var, val) \
|
2010-01-05 15:34:50 +09:00
|
|
|
do { \
|
|
|
|
const int pao_ID__ = (__builtin_constant_p(val) && \
|
percpu: fix this_cpu_sub() subtrahend casting for unsigneds
this_cpu_sub() is implemented as negation and addition.
This patch casts the adjustment to the counter type before negation to
sign extend the adjustment. This helps in cases where the counter type
is wider than an unsigned adjustment. An alternative to this patch is
to declare such operations unsupported, but it seemed useful to avoid
surprises.
This patch specifically helps the following example:
unsigned int delta = 1
preempt_disable()
this_cpu_write(long_counter, 0)
this_cpu_sub(long_counter, delta)
preempt_enable()
Before this change long_counter on a 64 bit machine ends with value
0xffffffff, rather than 0xffffffffffffffff. This is because
this_cpu_sub(pcp, delta) boils down to this_cpu_add(pcp, -delta),
which is basically:
long_counter = 0 + 0xffffffff
Also apply the same cast to:
__this_cpu_sub()
__this_cpu_sub_return()
this_cpu_sub_return()
All percpu_test.ko passes, especially the following cases which
previously failed:
l -= ui_one;
__this_cpu_sub(long_counter, ui_one);
CHECK(l, long_counter, -1);
l -= ui_one;
this_cpu_sub(long_counter, ui_one);
CHECK(l, long_counter, -1);
CHECK(l, long_counter, 0xffffffffffffffff);
ul -= ui_one;
__this_cpu_sub(ulong_counter, ui_one);
CHECK(ul, ulong_counter, -1);
CHECK(ul, ulong_counter, 0xffffffffffffffff);
ul = this_cpu_sub_return(ulong_counter, ui_one);
CHECK(ul, ulong_counter, 2);
ul = __this_cpu_sub_return(ulong_counter, ui_one);
CHECK(ul, ulong_counter, 1);
Signed-off-by: Greg Thelen <gthelen@google.com>
Acked-by: Tejun Heo <tj@kernel.org>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-10-30 13:56:20 -07:00
|
|
|
((val) == 1 || (val) == -1)) ? \
|
|
|
|
(int)(val) : 0; \
|
2010-01-05 15:34:50 +09:00
|
|
|
if (0) { \
|
2020-07-20 13:49:18 -07:00
|
|
|
typeof(var) pao_tmp__; \
|
2010-01-05 15:34:50 +09:00
|
|
|
pao_tmp__ = (val); \
|
2010-06-10 13:10:36 +02:00
|
|
|
(void)pao_tmp__; \
|
2010-01-05 15:34:50 +09:00
|
|
|
} \
|
2020-07-20 13:49:18 -07:00
|
|
|
if (pao_ID__ == 1) \
|
|
|
|
percpu_unary_op(size, qual, "inc", var); \
|
|
|
|
else if (pao_ID__ == -1) \
|
|
|
|
percpu_unary_op(size, qual, "dec", var); \
|
|
|
|
else \
|
|
|
|
percpu_to_op(size, qual, "add", var, val); \
|
2010-01-05 15:34:50 +09:00
|
|
|
} while (0)
|
|
|
|
|
2020-07-20 13:49:17 -07:00
|
|
|
#define percpu_from_op(size, qual, op, _var) \
|
|
|
|
({ \
|
|
|
|
__pcpu_type_##size pfo_val__; \
|
|
|
|
asm qual (__pcpu_op2_##size(op, __percpu_arg([var]), "%[val]") \
|
|
|
|
: [val] __pcpu_reg_##size("=", pfo_val__) \
|
2023-10-04 16:49:43 +02:00
|
|
|
: [var] "m" (__my_cpu_var(_var))); \
|
2020-07-20 13:49:17 -07:00
|
|
|
(typeof(_var))(unsigned long) pfo_val__; \
|
2014-11-04 08:50:48 +00:00
|
|
|
})
|
|
|
|
|
2020-07-20 13:49:23 -07:00
|
|
|
#define percpu_stable_op(size, op, _var) \
|
|
|
|
({ \
|
|
|
|
__pcpu_type_##size pfo_val__; \
|
2023-10-16 22:07:30 +02:00
|
|
|
asm(__pcpu_op2_##size(op, __force_percpu_arg(a[var]), "%[val]") \
|
2020-07-20 13:49:23 -07:00
|
|
|
: [val] __pcpu_reg_##size("=", pfo_val__) \
|
2023-10-16 22:07:30 +02:00
|
|
|
: [var] "i" (&(_var))); \
|
2020-07-20 13:49:23 -07:00
|
|
|
(typeof(_var))(unsigned long) pfo_val__; \
|
2008-03-23 01:03:06 -07:00
|
|
|
})
|
2008-01-30 13:32:53 +01:00
|
|
|
|
2010-12-17 15:47:04 +01:00
|
|
|
/*
|
|
|
|
* Add return operation
|
|
|
|
*/
|
2020-07-20 13:49:20 -07:00
|
|
|
#define percpu_add_return_op(size, qual, _var, _val) \
|
2010-12-17 15:47:04 +01:00
|
|
|
({ \
|
2020-07-20 13:49:20 -07:00
|
|
|
__pcpu_type_##size paro_tmp__ = __pcpu_cast_##size(_val); \
|
|
|
|
asm qual (__pcpu_op2_##size("xadd", "%[tmp]", \
|
|
|
|
__percpu_arg([var])) \
|
|
|
|
: [tmp] __pcpu_reg_##size("+", paro_tmp__), \
|
2023-10-04 16:49:43 +02:00
|
|
|
[var] "+m" (__my_cpu_var(_var)) \
|
2020-07-20 13:49:20 -07:00
|
|
|
: : "memory"); \
|
|
|
|
(typeof(_var))(unsigned long) (paro_tmp__ + _val); \
|
2010-12-17 15:47:04 +01:00
|
|
|
})
|
|
|
|
|
2024-03-20 09:30:41 +01:00
|
|
|
/*
|
|
|
|
* raw_cpu_xchg() can use a load-store since
|
|
|
|
* it is not required to be IRQ-safe.
|
|
|
|
*/
|
|
|
|
#define raw_percpu_xchg_op(_var, _nval) \
|
|
|
|
({ \
|
|
|
|
typeof(_var) pxo_old__ = raw_cpu_read(_var); \
|
|
|
|
raw_cpu_write(_var, _nval); \
|
|
|
|
pxo_old__; \
|
|
|
|
})
|
|
|
|
|
2010-12-14 10:28:44 -06:00
|
|
|
/*
|
2024-03-20 09:30:40 +01:00
|
|
|
* this_cpu_xchg() is implemented using cmpxchg without a lock prefix.
|
|
|
|
* xchg is expensive due to the implied lock prefix. The processor
|
|
|
|
* cannot prefetch cachelines if xchg is used.
|
2010-12-14 10:28:44 -06:00
|
|
|
*/
|
2024-03-20 09:30:40 +01:00
|
|
|
#define this_percpu_xchg_op(_var, _nval) \
|
2010-12-14 10:28:44 -06:00
|
|
|
({ \
|
2024-03-20 09:30:40 +01:00
|
|
|
typeof(_var) pxo_old__ = this_cpu_read(_var); \
|
|
|
|
do { } while (!this_cpu_try_cmpxchg(_var, &pxo_old__, _nval)); \
|
|
|
|
pxo_old__; \
|
2010-12-14 10:28:44 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cmpxchg has no such implied lock semantics as a result it is much
|
|
|
|
* more efficient for cpu local operations.
|
|
|
|
*/
|
2020-07-20 13:49:22 -07:00
|
|
|
#define percpu_cmpxchg_op(size, qual, _var, _oval, _nval) \
|
2010-12-14 10:28:44 -06:00
|
|
|
({ \
|
2020-07-20 13:49:22 -07:00
|
|
|
__pcpu_type_##size pco_old__ = __pcpu_cast_##size(_oval); \
|
|
|
|
__pcpu_type_##size pco_new__ = __pcpu_cast_##size(_nval); \
|
|
|
|
asm qual (__pcpu_op2_##size("cmpxchg", "%[nval]", \
|
|
|
|
__percpu_arg([var])) \
|
|
|
|
: [oval] "+a" (pco_old__), \
|
2023-10-04 16:49:43 +02:00
|
|
|
[var] "+m" (__my_cpu_var(_var)) \
|
2020-07-20 13:49:22 -07:00
|
|
|
: [nval] __pcpu_reg_##size(, pco_new__) \
|
|
|
|
: "memory"); \
|
|
|
|
(typeof(_var))(unsigned long) pco_old__; \
|
2010-12-14 10:28:44 -06:00
|
|
|
})
|
|
|
|
|
2023-08-30 17:13:56 +02:00
|
|
|
#define percpu_try_cmpxchg_op(size, qual, _var, _ovalp, _nval) \
|
|
|
|
({ \
|
|
|
|
bool success; \
|
|
|
|
__pcpu_type_##size *pco_oval__ = (__pcpu_type_##size *)(_ovalp); \
|
|
|
|
__pcpu_type_##size pco_old__ = *pco_oval__; \
|
|
|
|
__pcpu_type_##size pco_new__ = __pcpu_cast_##size(_nval); \
|
|
|
|
asm qual (__pcpu_op2_##size("cmpxchg", "%[nval]", \
|
|
|
|
__percpu_arg([var])) \
|
|
|
|
CC_SET(z) \
|
|
|
|
: CC_OUT(z) (success), \
|
|
|
|
[oval] "+a" (pco_old__), \
|
2023-10-04 16:49:43 +02:00
|
|
|
[var] "+m" (__my_cpu_var(_var)) \
|
2023-08-30 17:13:56 +02:00
|
|
|
: [nval] __pcpu_reg_##size(, pco_new__) \
|
|
|
|
: "memory"); \
|
|
|
|
if (unlikely(!success)) \
|
|
|
|
*pco_oval__ = pco_old__; \
|
|
|
|
likely(success); \
|
|
|
|
})
|
|
|
|
|
2023-05-31 15:08:39 +02:00
|
|
|
#if defined(CONFIG_X86_32) && !defined(CONFIG_UML)
|
|
|
|
#define percpu_cmpxchg64_op(size, qual, _var, _oval, _nval) \
|
|
|
|
({ \
|
|
|
|
union { \
|
|
|
|
u64 var; \
|
|
|
|
struct { \
|
|
|
|
u32 low, high; \
|
|
|
|
}; \
|
|
|
|
} old__, new__; \
|
|
|
|
\
|
|
|
|
old__.var = _oval; \
|
|
|
|
new__.var = _nval; \
|
|
|
|
\
|
x86/percpu: Do not clobber %rsi in percpu_{try_,}cmpxchg{64,128}_op
The fallback alternative uses %rsi register to manually load pointer
to the percpu variable before the call to the emulation function.
This is unoptimal, because the load is hidden from the compiler.
Move the load of %rsi outside inline asm, so the compiler can
reuse the value. The code in slub.o improves from:
55ac: 49 8b 3c 24 mov (%r12),%rdi
55b0: 48 8d 4a 40 lea 0x40(%rdx),%rcx
55b4: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
55b8: 4c 89 f8 mov %r15,%rax
55bb: 48 8d 37 lea (%rdi),%rsi
55be: e8 00 00 00 00 callq 55c3 <...>
55bf: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
55c3: 75 a3 jne 5568 <...>
55c5: ...
0000000000000000 <.altinstr_replacement>:
5: 65 48 0f c7 0f cmpxchg16b %gs:(%rdi)
to:
55ac: 49 8b 34 24 mov (%r12),%rsi
55b0: 48 8d 4a 40 lea 0x40(%rdx),%rcx
55b4: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
55b8: 4c 89 f8 mov %r15,%rax
55bb: e8 00 00 00 00 callq 55c0 <...>
55bc: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
55c0: 75 a6 jne 5568 <...>
55c2: ...
Where the alternative replacement instruction now uses %rsi:
0000000000000000 <.altinstr_replacement>:
5: 65 48 0f c7 0e cmpxchg16b %gs:(%rsi)
The instruction (effectively a reg-reg move) at 55bb: in the original
assembly is removed. Also, both the CALL and replacement CMPXCHG16B
are 5 bytes long, removing the need for NOPs in the asm code.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20230918151452.62344-1-ubizjak@gmail.com
2023-09-18 17:14:10 +02:00
|
|
|
asm qual (ALTERNATIVE("call this_cpu_cmpxchg8b_emu", \
|
2023-05-31 15:08:39 +02:00
|
|
|
"cmpxchg8b " __percpu_arg([var]), X86_FEATURE_CX8) \
|
2023-10-04 16:49:43 +02:00
|
|
|
: [var] "+m" (__my_cpu_var(_var)), \
|
2023-05-31 15:08:39 +02:00
|
|
|
"+a" (old__.low), \
|
|
|
|
"+d" (old__.high) \
|
|
|
|
: "b" (new__.low), \
|
x86/percpu: Do not clobber %rsi in percpu_{try_,}cmpxchg{64,128}_op
The fallback alternative uses %rsi register to manually load pointer
to the percpu variable before the call to the emulation function.
This is unoptimal, because the load is hidden from the compiler.
Move the load of %rsi outside inline asm, so the compiler can
reuse the value. The code in slub.o improves from:
55ac: 49 8b 3c 24 mov (%r12),%rdi
55b0: 48 8d 4a 40 lea 0x40(%rdx),%rcx
55b4: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
55b8: 4c 89 f8 mov %r15,%rax
55bb: 48 8d 37 lea (%rdi),%rsi
55be: e8 00 00 00 00 callq 55c3 <...>
55bf: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
55c3: 75 a3 jne 5568 <...>
55c5: ...
0000000000000000 <.altinstr_replacement>:
5: 65 48 0f c7 0f cmpxchg16b %gs:(%rdi)
to:
55ac: 49 8b 34 24 mov (%r12),%rsi
55b0: 48 8d 4a 40 lea 0x40(%rdx),%rcx
55b4: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
55b8: 4c 89 f8 mov %r15,%rax
55bb: e8 00 00 00 00 callq 55c0 <...>
55bc: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
55c0: 75 a6 jne 5568 <...>
55c2: ...
Where the alternative replacement instruction now uses %rsi:
0000000000000000 <.altinstr_replacement>:
5: 65 48 0f c7 0e cmpxchg16b %gs:(%rsi)
The instruction (effectively a reg-reg move) at 55bb: in the original
assembly is removed. Also, both the CALL and replacement CMPXCHG16B
are 5 bytes long, removing the need for NOPs in the asm code.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20230918151452.62344-1-ubizjak@gmail.com
2023-09-18 17:14:10 +02:00
|
|
|
"c" (new__.high), \
|
|
|
|
"S" (&(_var)) \
|
|
|
|
: "memory"); \
|
2023-05-31 15:08:39 +02:00
|
|
|
\
|
|
|
|
old__.var; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define raw_cpu_cmpxchg64(pcp, oval, nval) percpu_cmpxchg64_op(8, , pcp, oval, nval)
|
|
|
|
#define this_cpu_cmpxchg64(pcp, oval, nval) percpu_cmpxchg64_op(8, volatile, pcp, oval, nval)
|
x86/percpu: Define {raw,this}_cpu_try_cmpxchg{64,128}
Define target-specific {raw,this}_cpu_try_cmpxchg64() and
{raw,this}_cpu_try_cmpxchg128() macros. These definitions override
the generic fallback definitions and enable target-specific
optimized implementations.
Several places in mm/slub.o improve from e.g.:
53bc: 48 8d 4f 40 lea 0x40(%rdi),%rcx
53c0: 48 89 fa mov %rdi,%rdx
53c3: 49 8b 5c 05 00 mov 0x0(%r13,%rax,1),%rbx
53c8: 4c 89 e8 mov %r13,%rax
53cb: 49 8d 30 lea (%r8),%rsi
53ce: e8 00 00 00 00 call 53d3 <...>
53cf: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
53d3: 48 31 d7 xor %rdx,%rdi
53d6: 4c 31 e8 xor %r13,%rax
53d9: 48 09 c7 or %rax,%rdi
53dc: 75 ae jne 538c <...>
to:
53bc: 48 8d 4a 40 lea 0x40(%rdx),%rcx
53c0: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
53c4: 4c 89 f8 mov %r15,%rax
53c7: 48 8d 37 lea (%rdi),%rsi
53ca: e8 00 00 00 00 call 53cf <...>
53cb: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
53cf: 75 bb jne 538c <...>
reducing the size of mm/slub.o by 80 bytes:
text data bss dec hex filename
39758 5337 4208 49303 c097 slub-new.o
39838 5337 4208 49383 c0e7 slub-old.o
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230906185941.53527-1-ubizjak@gmail.com
2023-09-06 20:58:44 +02:00
|
|
|
|
|
|
|
#define percpu_try_cmpxchg64_op(size, qual, _var, _ovalp, _nval) \
|
|
|
|
({ \
|
|
|
|
bool success; \
|
|
|
|
u64 *_oval = (u64 *)(_ovalp); \
|
|
|
|
union { \
|
|
|
|
u64 var; \
|
|
|
|
struct { \
|
|
|
|
u32 low, high; \
|
|
|
|
}; \
|
|
|
|
} old__, new__; \
|
|
|
|
\
|
|
|
|
old__.var = *_oval; \
|
|
|
|
new__.var = _nval; \
|
|
|
|
\
|
x86/percpu: Do not clobber %rsi in percpu_{try_,}cmpxchg{64,128}_op
The fallback alternative uses %rsi register to manually load pointer
to the percpu variable before the call to the emulation function.
This is unoptimal, because the load is hidden from the compiler.
Move the load of %rsi outside inline asm, so the compiler can
reuse the value. The code in slub.o improves from:
55ac: 49 8b 3c 24 mov (%r12),%rdi
55b0: 48 8d 4a 40 lea 0x40(%rdx),%rcx
55b4: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
55b8: 4c 89 f8 mov %r15,%rax
55bb: 48 8d 37 lea (%rdi),%rsi
55be: e8 00 00 00 00 callq 55c3 <...>
55bf: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
55c3: 75 a3 jne 5568 <...>
55c5: ...
0000000000000000 <.altinstr_replacement>:
5: 65 48 0f c7 0f cmpxchg16b %gs:(%rdi)
to:
55ac: 49 8b 34 24 mov (%r12),%rsi
55b0: 48 8d 4a 40 lea 0x40(%rdx),%rcx
55b4: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
55b8: 4c 89 f8 mov %r15,%rax
55bb: e8 00 00 00 00 callq 55c0 <...>
55bc: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
55c0: 75 a6 jne 5568 <...>
55c2: ...
Where the alternative replacement instruction now uses %rsi:
0000000000000000 <.altinstr_replacement>:
5: 65 48 0f c7 0e cmpxchg16b %gs:(%rsi)
The instruction (effectively a reg-reg move) at 55bb: in the original
assembly is removed. Also, both the CALL and replacement CMPXCHG16B
are 5 bytes long, removing the need for NOPs in the asm code.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20230918151452.62344-1-ubizjak@gmail.com
2023-09-18 17:14:10 +02:00
|
|
|
asm qual (ALTERNATIVE("call this_cpu_cmpxchg8b_emu", \
|
x86/percpu: Define {raw,this}_cpu_try_cmpxchg{64,128}
Define target-specific {raw,this}_cpu_try_cmpxchg64() and
{raw,this}_cpu_try_cmpxchg128() macros. These definitions override
the generic fallback definitions and enable target-specific
optimized implementations.
Several places in mm/slub.o improve from e.g.:
53bc: 48 8d 4f 40 lea 0x40(%rdi),%rcx
53c0: 48 89 fa mov %rdi,%rdx
53c3: 49 8b 5c 05 00 mov 0x0(%r13,%rax,1),%rbx
53c8: 4c 89 e8 mov %r13,%rax
53cb: 49 8d 30 lea (%r8),%rsi
53ce: e8 00 00 00 00 call 53d3 <...>
53cf: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
53d3: 48 31 d7 xor %rdx,%rdi
53d6: 4c 31 e8 xor %r13,%rax
53d9: 48 09 c7 or %rax,%rdi
53dc: 75 ae jne 538c <...>
to:
53bc: 48 8d 4a 40 lea 0x40(%rdx),%rcx
53c0: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
53c4: 4c 89 f8 mov %r15,%rax
53c7: 48 8d 37 lea (%rdi),%rsi
53ca: e8 00 00 00 00 call 53cf <...>
53cb: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
53cf: 75 bb jne 538c <...>
reducing the size of mm/slub.o by 80 bytes:
text data bss dec hex filename
39758 5337 4208 49303 c097 slub-new.o
39838 5337 4208 49383 c0e7 slub-old.o
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230906185941.53527-1-ubizjak@gmail.com
2023-09-06 20:58:44 +02:00
|
|
|
"cmpxchg8b " __percpu_arg([var]), X86_FEATURE_CX8) \
|
|
|
|
CC_SET(z) \
|
|
|
|
: CC_OUT(z) (success), \
|
2023-10-04 16:49:43 +02:00
|
|
|
[var] "+m" (__my_cpu_var(_var)), \
|
x86/percpu: Define {raw,this}_cpu_try_cmpxchg{64,128}
Define target-specific {raw,this}_cpu_try_cmpxchg64() and
{raw,this}_cpu_try_cmpxchg128() macros. These definitions override
the generic fallback definitions and enable target-specific
optimized implementations.
Several places in mm/slub.o improve from e.g.:
53bc: 48 8d 4f 40 lea 0x40(%rdi),%rcx
53c0: 48 89 fa mov %rdi,%rdx
53c3: 49 8b 5c 05 00 mov 0x0(%r13,%rax,1),%rbx
53c8: 4c 89 e8 mov %r13,%rax
53cb: 49 8d 30 lea (%r8),%rsi
53ce: e8 00 00 00 00 call 53d3 <...>
53cf: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
53d3: 48 31 d7 xor %rdx,%rdi
53d6: 4c 31 e8 xor %r13,%rax
53d9: 48 09 c7 or %rax,%rdi
53dc: 75 ae jne 538c <...>
to:
53bc: 48 8d 4a 40 lea 0x40(%rdx),%rcx
53c0: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
53c4: 4c 89 f8 mov %r15,%rax
53c7: 48 8d 37 lea (%rdi),%rsi
53ca: e8 00 00 00 00 call 53cf <...>
53cb: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
53cf: 75 bb jne 538c <...>
reducing the size of mm/slub.o by 80 bytes:
text data bss dec hex filename
39758 5337 4208 49303 c097 slub-new.o
39838 5337 4208 49383 c0e7 slub-old.o
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230906185941.53527-1-ubizjak@gmail.com
2023-09-06 20:58:44 +02:00
|
|
|
"+a" (old__.low), \
|
|
|
|
"+d" (old__.high) \
|
|
|
|
: "b" (new__.low), \
|
x86/percpu: Do not clobber %rsi in percpu_{try_,}cmpxchg{64,128}_op
The fallback alternative uses %rsi register to manually load pointer
to the percpu variable before the call to the emulation function.
This is unoptimal, because the load is hidden from the compiler.
Move the load of %rsi outside inline asm, so the compiler can
reuse the value. The code in slub.o improves from:
55ac: 49 8b 3c 24 mov (%r12),%rdi
55b0: 48 8d 4a 40 lea 0x40(%rdx),%rcx
55b4: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
55b8: 4c 89 f8 mov %r15,%rax
55bb: 48 8d 37 lea (%rdi),%rsi
55be: e8 00 00 00 00 callq 55c3 <...>
55bf: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
55c3: 75 a3 jne 5568 <...>
55c5: ...
0000000000000000 <.altinstr_replacement>:
5: 65 48 0f c7 0f cmpxchg16b %gs:(%rdi)
to:
55ac: 49 8b 34 24 mov (%r12),%rsi
55b0: 48 8d 4a 40 lea 0x40(%rdx),%rcx
55b4: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
55b8: 4c 89 f8 mov %r15,%rax
55bb: e8 00 00 00 00 callq 55c0 <...>
55bc: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
55c0: 75 a6 jne 5568 <...>
55c2: ...
Where the alternative replacement instruction now uses %rsi:
0000000000000000 <.altinstr_replacement>:
5: 65 48 0f c7 0e cmpxchg16b %gs:(%rsi)
The instruction (effectively a reg-reg move) at 55bb: in the original
assembly is removed. Also, both the CALL and replacement CMPXCHG16B
are 5 bytes long, removing the need for NOPs in the asm code.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20230918151452.62344-1-ubizjak@gmail.com
2023-09-18 17:14:10 +02:00
|
|
|
"c" (new__.high), \
|
|
|
|
"S" (&(_var)) \
|
|
|
|
: "memory"); \
|
x86/percpu: Define {raw,this}_cpu_try_cmpxchg{64,128}
Define target-specific {raw,this}_cpu_try_cmpxchg64() and
{raw,this}_cpu_try_cmpxchg128() macros. These definitions override
the generic fallback definitions and enable target-specific
optimized implementations.
Several places in mm/slub.o improve from e.g.:
53bc: 48 8d 4f 40 lea 0x40(%rdi),%rcx
53c0: 48 89 fa mov %rdi,%rdx
53c3: 49 8b 5c 05 00 mov 0x0(%r13,%rax,1),%rbx
53c8: 4c 89 e8 mov %r13,%rax
53cb: 49 8d 30 lea (%r8),%rsi
53ce: e8 00 00 00 00 call 53d3 <...>
53cf: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
53d3: 48 31 d7 xor %rdx,%rdi
53d6: 4c 31 e8 xor %r13,%rax
53d9: 48 09 c7 or %rax,%rdi
53dc: 75 ae jne 538c <...>
to:
53bc: 48 8d 4a 40 lea 0x40(%rdx),%rcx
53c0: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
53c4: 4c 89 f8 mov %r15,%rax
53c7: 48 8d 37 lea (%rdi),%rsi
53ca: e8 00 00 00 00 call 53cf <...>
53cb: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
53cf: 75 bb jne 538c <...>
reducing the size of mm/slub.o by 80 bytes:
text data bss dec hex filename
39758 5337 4208 49303 c097 slub-new.o
39838 5337 4208 49383 c0e7 slub-old.o
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230906185941.53527-1-ubizjak@gmail.com
2023-09-06 20:58:44 +02:00
|
|
|
if (unlikely(!success)) \
|
|
|
|
*_oval = old__.var; \
|
|
|
|
likely(success); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define raw_cpu_try_cmpxchg64(pcp, ovalp, nval) percpu_try_cmpxchg64_op(8, , pcp, ovalp, nval)
|
|
|
|
#define this_cpu_try_cmpxchg64(pcp, ovalp, nval) percpu_try_cmpxchg64_op(8, volatile, pcp, ovalp, nval)
|
2023-05-31 15:08:39 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
#define raw_cpu_cmpxchg64(pcp, oval, nval) percpu_cmpxchg_op(8, , pcp, oval, nval);
|
|
|
|
#define this_cpu_cmpxchg64(pcp, oval, nval) percpu_cmpxchg_op(8, volatile, pcp, oval, nval);
|
|
|
|
|
x86/percpu: Define {raw,this}_cpu_try_cmpxchg{64,128}
Define target-specific {raw,this}_cpu_try_cmpxchg64() and
{raw,this}_cpu_try_cmpxchg128() macros. These definitions override
the generic fallback definitions and enable target-specific
optimized implementations.
Several places in mm/slub.o improve from e.g.:
53bc: 48 8d 4f 40 lea 0x40(%rdi),%rcx
53c0: 48 89 fa mov %rdi,%rdx
53c3: 49 8b 5c 05 00 mov 0x0(%r13,%rax,1),%rbx
53c8: 4c 89 e8 mov %r13,%rax
53cb: 49 8d 30 lea (%r8),%rsi
53ce: e8 00 00 00 00 call 53d3 <...>
53cf: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
53d3: 48 31 d7 xor %rdx,%rdi
53d6: 4c 31 e8 xor %r13,%rax
53d9: 48 09 c7 or %rax,%rdi
53dc: 75 ae jne 538c <...>
to:
53bc: 48 8d 4a 40 lea 0x40(%rdx),%rcx
53c0: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
53c4: 4c 89 f8 mov %r15,%rax
53c7: 48 8d 37 lea (%rdi),%rsi
53ca: e8 00 00 00 00 call 53cf <...>
53cb: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
53cf: 75 bb jne 538c <...>
reducing the size of mm/slub.o by 80 bytes:
text data bss dec hex filename
39758 5337 4208 49303 c097 slub-new.o
39838 5337 4208 49383 c0e7 slub-old.o
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230906185941.53527-1-ubizjak@gmail.com
2023-09-06 20:58:44 +02:00
|
|
|
#define raw_cpu_try_cmpxchg64(pcp, ovalp, nval) percpu_try_cmpxchg_op(8, , pcp, ovalp, nval);
|
|
|
|
#define this_cpu_try_cmpxchg64(pcp, ovalp, nval) percpu_try_cmpxchg_op(8, volatile, pcp, ovalp, nval);
|
|
|
|
|
2023-05-31 15:08:39 +02:00
|
|
|
#define percpu_cmpxchg128_op(size, qual, _var, _oval, _nval) \
|
|
|
|
({ \
|
|
|
|
union { \
|
|
|
|
u128 var; \
|
|
|
|
struct { \
|
|
|
|
u64 low, high; \
|
|
|
|
}; \
|
|
|
|
} old__, new__; \
|
|
|
|
\
|
|
|
|
old__.var = _oval; \
|
|
|
|
new__.var = _nval; \
|
|
|
|
\
|
x86/percpu: Do not clobber %rsi in percpu_{try_,}cmpxchg{64,128}_op
The fallback alternative uses %rsi register to manually load pointer
to the percpu variable before the call to the emulation function.
This is unoptimal, because the load is hidden from the compiler.
Move the load of %rsi outside inline asm, so the compiler can
reuse the value. The code in slub.o improves from:
55ac: 49 8b 3c 24 mov (%r12),%rdi
55b0: 48 8d 4a 40 lea 0x40(%rdx),%rcx
55b4: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
55b8: 4c 89 f8 mov %r15,%rax
55bb: 48 8d 37 lea (%rdi),%rsi
55be: e8 00 00 00 00 callq 55c3 <...>
55bf: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
55c3: 75 a3 jne 5568 <...>
55c5: ...
0000000000000000 <.altinstr_replacement>:
5: 65 48 0f c7 0f cmpxchg16b %gs:(%rdi)
to:
55ac: 49 8b 34 24 mov (%r12),%rsi
55b0: 48 8d 4a 40 lea 0x40(%rdx),%rcx
55b4: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
55b8: 4c 89 f8 mov %r15,%rax
55bb: e8 00 00 00 00 callq 55c0 <...>
55bc: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
55c0: 75 a6 jne 5568 <...>
55c2: ...
Where the alternative replacement instruction now uses %rsi:
0000000000000000 <.altinstr_replacement>:
5: 65 48 0f c7 0e cmpxchg16b %gs:(%rsi)
The instruction (effectively a reg-reg move) at 55bb: in the original
assembly is removed. Also, both the CALL and replacement CMPXCHG16B
are 5 bytes long, removing the need for NOPs in the asm code.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20230918151452.62344-1-ubizjak@gmail.com
2023-09-18 17:14:10 +02:00
|
|
|
asm qual (ALTERNATIVE("call this_cpu_cmpxchg16b_emu", \
|
2023-05-31 15:08:39 +02:00
|
|
|
"cmpxchg16b " __percpu_arg([var]), X86_FEATURE_CX16) \
|
2023-10-04 16:49:43 +02:00
|
|
|
: [var] "+m" (__my_cpu_var(_var)), \
|
2023-05-31 15:08:39 +02:00
|
|
|
"+a" (old__.low), \
|
|
|
|
"+d" (old__.high) \
|
|
|
|
: "b" (new__.low), \
|
x86/percpu: Do not clobber %rsi in percpu_{try_,}cmpxchg{64,128}_op
The fallback alternative uses %rsi register to manually load pointer
to the percpu variable before the call to the emulation function.
This is unoptimal, because the load is hidden from the compiler.
Move the load of %rsi outside inline asm, so the compiler can
reuse the value. The code in slub.o improves from:
55ac: 49 8b 3c 24 mov (%r12),%rdi
55b0: 48 8d 4a 40 lea 0x40(%rdx),%rcx
55b4: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
55b8: 4c 89 f8 mov %r15,%rax
55bb: 48 8d 37 lea (%rdi),%rsi
55be: e8 00 00 00 00 callq 55c3 <...>
55bf: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
55c3: 75 a3 jne 5568 <...>
55c5: ...
0000000000000000 <.altinstr_replacement>:
5: 65 48 0f c7 0f cmpxchg16b %gs:(%rdi)
to:
55ac: 49 8b 34 24 mov (%r12),%rsi
55b0: 48 8d 4a 40 lea 0x40(%rdx),%rcx
55b4: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
55b8: 4c 89 f8 mov %r15,%rax
55bb: e8 00 00 00 00 callq 55c0 <...>
55bc: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
55c0: 75 a6 jne 5568 <...>
55c2: ...
Where the alternative replacement instruction now uses %rsi:
0000000000000000 <.altinstr_replacement>:
5: 65 48 0f c7 0e cmpxchg16b %gs:(%rsi)
The instruction (effectively a reg-reg move) at 55bb: in the original
assembly is removed. Also, both the CALL and replacement CMPXCHG16B
are 5 bytes long, removing the need for NOPs in the asm code.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20230918151452.62344-1-ubizjak@gmail.com
2023-09-18 17:14:10 +02:00
|
|
|
"c" (new__.high), \
|
|
|
|
"S" (&(_var)) \
|
|
|
|
: "memory"); \
|
2023-05-31 15:08:39 +02:00
|
|
|
\
|
|
|
|
old__.var; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define raw_cpu_cmpxchg128(pcp, oval, nval) percpu_cmpxchg128_op(16, , pcp, oval, nval)
|
|
|
|
#define this_cpu_cmpxchg128(pcp, oval, nval) percpu_cmpxchg128_op(16, volatile, pcp, oval, nval)
|
x86/percpu: Define {raw,this}_cpu_try_cmpxchg{64,128}
Define target-specific {raw,this}_cpu_try_cmpxchg64() and
{raw,this}_cpu_try_cmpxchg128() macros. These definitions override
the generic fallback definitions and enable target-specific
optimized implementations.
Several places in mm/slub.o improve from e.g.:
53bc: 48 8d 4f 40 lea 0x40(%rdi),%rcx
53c0: 48 89 fa mov %rdi,%rdx
53c3: 49 8b 5c 05 00 mov 0x0(%r13,%rax,1),%rbx
53c8: 4c 89 e8 mov %r13,%rax
53cb: 49 8d 30 lea (%r8),%rsi
53ce: e8 00 00 00 00 call 53d3 <...>
53cf: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
53d3: 48 31 d7 xor %rdx,%rdi
53d6: 4c 31 e8 xor %r13,%rax
53d9: 48 09 c7 or %rax,%rdi
53dc: 75 ae jne 538c <...>
to:
53bc: 48 8d 4a 40 lea 0x40(%rdx),%rcx
53c0: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
53c4: 4c 89 f8 mov %r15,%rax
53c7: 48 8d 37 lea (%rdi),%rsi
53ca: e8 00 00 00 00 call 53cf <...>
53cb: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
53cf: 75 bb jne 538c <...>
reducing the size of mm/slub.o by 80 bytes:
text data bss dec hex filename
39758 5337 4208 49303 c097 slub-new.o
39838 5337 4208 49383 c0e7 slub-old.o
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230906185941.53527-1-ubizjak@gmail.com
2023-09-06 20:58:44 +02:00
|
|
|
|
|
|
|
#define percpu_try_cmpxchg128_op(size, qual, _var, _ovalp, _nval) \
|
|
|
|
({ \
|
|
|
|
bool success; \
|
|
|
|
u128 *_oval = (u128 *)(_ovalp); \
|
|
|
|
union { \
|
|
|
|
u128 var; \
|
|
|
|
struct { \
|
|
|
|
u64 low, high; \
|
|
|
|
}; \
|
|
|
|
} old__, new__; \
|
|
|
|
\
|
|
|
|
old__.var = *_oval; \
|
|
|
|
new__.var = _nval; \
|
|
|
|
\
|
x86/percpu: Do not clobber %rsi in percpu_{try_,}cmpxchg{64,128}_op
The fallback alternative uses %rsi register to manually load pointer
to the percpu variable before the call to the emulation function.
This is unoptimal, because the load is hidden from the compiler.
Move the load of %rsi outside inline asm, so the compiler can
reuse the value. The code in slub.o improves from:
55ac: 49 8b 3c 24 mov (%r12),%rdi
55b0: 48 8d 4a 40 lea 0x40(%rdx),%rcx
55b4: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
55b8: 4c 89 f8 mov %r15,%rax
55bb: 48 8d 37 lea (%rdi),%rsi
55be: e8 00 00 00 00 callq 55c3 <...>
55bf: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
55c3: 75 a3 jne 5568 <...>
55c5: ...
0000000000000000 <.altinstr_replacement>:
5: 65 48 0f c7 0f cmpxchg16b %gs:(%rdi)
to:
55ac: 49 8b 34 24 mov (%r12),%rsi
55b0: 48 8d 4a 40 lea 0x40(%rdx),%rcx
55b4: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
55b8: 4c 89 f8 mov %r15,%rax
55bb: e8 00 00 00 00 callq 55c0 <...>
55bc: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
55c0: 75 a6 jne 5568 <...>
55c2: ...
Where the alternative replacement instruction now uses %rsi:
0000000000000000 <.altinstr_replacement>:
5: 65 48 0f c7 0e cmpxchg16b %gs:(%rsi)
The instruction (effectively a reg-reg move) at 55bb: in the original
assembly is removed. Also, both the CALL and replacement CMPXCHG16B
are 5 bytes long, removing the need for NOPs in the asm code.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20230918151452.62344-1-ubizjak@gmail.com
2023-09-18 17:14:10 +02:00
|
|
|
asm qual (ALTERNATIVE("call this_cpu_cmpxchg16b_emu", \
|
x86/percpu: Define {raw,this}_cpu_try_cmpxchg{64,128}
Define target-specific {raw,this}_cpu_try_cmpxchg64() and
{raw,this}_cpu_try_cmpxchg128() macros. These definitions override
the generic fallback definitions and enable target-specific
optimized implementations.
Several places in mm/slub.o improve from e.g.:
53bc: 48 8d 4f 40 lea 0x40(%rdi),%rcx
53c0: 48 89 fa mov %rdi,%rdx
53c3: 49 8b 5c 05 00 mov 0x0(%r13,%rax,1),%rbx
53c8: 4c 89 e8 mov %r13,%rax
53cb: 49 8d 30 lea (%r8),%rsi
53ce: e8 00 00 00 00 call 53d3 <...>
53cf: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
53d3: 48 31 d7 xor %rdx,%rdi
53d6: 4c 31 e8 xor %r13,%rax
53d9: 48 09 c7 or %rax,%rdi
53dc: 75 ae jne 538c <...>
to:
53bc: 48 8d 4a 40 lea 0x40(%rdx),%rcx
53c0: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
53c4: 4c 89 f8 mov %r15,%rax
53c7: 48 8d 37 lea (%rdi),%rsi
53ca: e8 00 00 00 00 call 53cf <...>
53cb: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
53cf: 75 bb jne 538c <...>
reducing the size of mm/slub.o by 80 bytes:
text data bss dec hex filename
39758 5337 4208 49303 c097 slub-new.o
39838 5337 4208 49383 c0e7 slub-old.o
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230906185941.53527-1-ubizjak@gmail.com
2023-09-06 20:58:44 +02:00
|
|
|
"cmpxchg16b " __percpu_arg([var]), X86_FEATURE_CX16) \
|
|
|
|
CC_SET(z) \
|
|
|
|
: CC_OUT(z) (success), \
|
2023-10-04 16:49:43 +02:00
|
|
|
[var] "+m" (__my_cpu_var(_var)), \
|
x86/percpu: Define {raw,this}_cpu_try_cmpxchg{64,128}
Define target-specific {raw,this}_cpu_try_cmpxchg64() and
{raw,this}_cpu_try_cmpxchg128() macros. These definitions override
the generic fallback definitions and enable target-specific
optimized implementations.
Several places in mm/slub.o improve from e.g.:
53bc: 48 8d 4f 40 lea 0x40(%rdi),%rcx
53c0: 48 89 fa mov %rdi,%rdx
53c3: 49 8b 5c 05 00 mov 0x0(%r13,%rax,1),%rbx
53c8: 4c 89 e8 mov %r13,%rax
53cb: 49 8d 30 lea (%r8),%rsi
53ce: e8 00 00 00 00 call 53d3 <...>
53cf: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
53d3: 48 31 d7 xor %rdx,%rdi
53d6: 4c 31 e8 xor %r13,%rax
53d9: 48 09 c7 or %rax,%rdi
53dc: 75 ae jne 538c <...>
to:
53bc: 48 8d 4a 40 lea 0x40(%rdx),%rcx
53c0: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
53c4: 4c 89 f8 mov %r15,%rax
53c7: 48 8d 37 lea (%rdi),%rsi
53ca: e8 00 00 00 00 call 53cf <...>
53cb: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
53cf: 75 bb jne 538c <...>
reducing the size of mm/slub.o by 80 bytes:
text data bss dec hex filename
39758 5337 4208 49303 c097 slub-new.o
39838 5337 4208 49383 c0e7 slub-old.o
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230906185941.53527-1-ubizjak@gmail.com
2023-09-06 20:58:44 +02:00
|
|
|
"+a" (old__.low), \
|
|
|
|
"+d" (old__.high) \
|
|
|
|
: "b" (new__.low), \
|
x86/percpu: Do not clobber %rsi in percpu_{try_,}cmpxchg{64,128}_op
The fallback alternative uses %rsi register to manually load pointer
to the percpu variable before the call to the emulation function.
This is unoptimal, because the load is hidden from the compiler.
Move the load of %rsi outside inline asm, so the compiler can
reuse the value. The code in slub.o improves from:
55ac: 49 8b 3c 24 mov (%r12),%rdi
55b0: 48 8d 4a 40 lea 0x40(%rdx),%rcx
55b4: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
55b8: 4c 89 f8 mov %r15,%rax
55bb: 48 8d 37 lea (%rdi),%rsi
55be: e8 00 00 00 00 callq 55c3 <...>
55bf: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
55c3: 75 a3 jne 5568 <...>
55c5: ...
0000000000000000 <.altinstr_replacement>:
5: 65 48 0f c7 0f cmpxchg16b %gs:(%rdi)
to:
55ac: 49 8b 34 24 mov (%r12),%rsi
55b0: 48 8d 4a 40 lea 0x40(%rdx),%rcx
55b4: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
55b8: 4c 89 f8 mov %r15,%rax
55bb: e8 00 00 00 00 callq 55c0 <...>
55bc: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
55c0: 75 a6 jne 5568 <...>
55c2: ...
Where the alternative replacement instruction now uses %rsi:
0000000000000000 <.altinstr_replacement>:
5: 65 48 0f c7 0e cmpxchg16b %gs:(%rsi)
The instruction (effectively a reg-reg move) at 55bb: in the original
assembly is removed. Also, both the CALL and replacement CMPXCHG16B
are 5 bytes long, removing the need for NOPs in the asm code.
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20230918151452.62344-1-ubizjak@gmail.com
2023-09-18 17:14:10 +02:00
|
|
|
"c" (new__.high), \
|
|
|
|
"S" (&(_var)) \
|
|
|
|
: "memory"); \
|
x86/percpu: Define {raw,this}_cpu_try_cmpxchg{64,128}
Define target-specific {raw,this}_cpu_try_cmpxchg64() and
{raw,this}_cpu_try_cmpxchg128() macros. These definitions override
the generic fallback definitions and enable target-specific
optimized implementations.
Several places in mm/slub.o improve from e.g.:
53bc: 48 8d 4f 40 lea 0x40(%rdi),%rcx
53c0: 48 89 fa mov %rdi,%rdx
53c3: 49 8b 5c 05 00 mov 0x0(%r13,%rax,1),%rbx
53c8: 4c 89 e8 mov %r13,%rax
53cb: 49 8d 30 lea (%r8),%rsi
53ce: e8 00 00 00 00 call 53d3 <...>
53cf: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
53d3: 48 31 d7 xor %rdx,%rdi
53d6: 4c 31 e8 xor %r13,%rax
53d9: 48 09 c7 or %rax,%rdi
53dc: 75 ae jne 538c <...>
to:
53bc: 48 8d 4a 40 lea 0x40(%rdx),%rcx
53c0: 49 8b 1c 07 mov (%r15,%rax,1),%rbx
53c4: 4c 89 f8 mov %r15,%rax
53c7: 48 8d 37 lea (%rdi),%rsi
53ca: e8 00 00 00 00 call 53cf <...>
53cb: R_X86_64_PLT32 this_cpu_cmpxchg16b_emu-0x4
53cf: 75 bb jne 538c <...>
reducing the size of mm/slub.o by 80 bytes:
text data bss dec hex filename
39758 5337 4208 49303 c097 slub-new.o
39838 5337 4208 49383 c0e7 slub-old.o
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: https://lore.kernel.org/r/20230906185941.53527-1-ubizjak@gmail.com
2023-09-06 20:58:44 +02:00
|
|
|
if (unlikely(!success)) \
|
|
|
|
*_oval = old__.var; \
|
|
|
|
likely(success); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define raw_cpu_try_cmpxchg128(pcp, ovalp, nval) percpu_try_cmpxchg128_op(16, , pcp, ovalp, nval)
|
|
|
|
#define this_cpu_try_cmpxchg128(pcp, ovalp, nval) percpu_try_cmpxchg128_op(16, volatile, pcp, ovalp, nval)
|
2023-05-31 15:08:39 +02:00
|
|
|
#endif
|
|
|
|
|
2009-08-03 14:08:48 +09:00
|
|
|
/*
|
2012-05-14 14:15:32 -07:00
|
|
|
* this_cpu_read() makes gcc load the percpu variable every time it is
|
2012-05-11 15:35:27 +08:00
|
|
|
* accessed while this_cpu_read_stable() allows the value to be cached.
|
|
|
|
* this_cpu_read_stable() is more efficient and can be used if its value
|
2009-08-03 14:08:48 +09:00
|
|
|
* is guaranteed to be valid across cpus. The current users include
|
x86/percpu: Introduce const-qualified const_pcpu_hot to micro-optimize code generation
Some variables in pcpu_hot, currently current_task and top_of_stack
are actually per-thread variables implemented as per-CPU variables
and thus stable for the duration of the respective task. There is
already an attempt to eliminate redundant reads from these variables
using this_cpu_read_stable() asm macro, which hides the dependency
on the read memory address. However, the compiler has limited ability
to eliminate asm common subexpressions, so this approach results in a
limited success.
The solution is to allow more aggressive elimination by aliasing
pcpu_hot into a const-qualified const_pcpu_hot, and to read stable
per-CPU variables from this constant copy.
The current per-CPU infrastructure does not support reads from
const-qualified variables. However, when the compiler supports segment
qualifiers, it is possible to declare the const-aliased variable in
the relevant named address space. The compiler considers access to the
variable, declared in this way, as a read from a constant location,
and will optimize reads from the variable accordingly.
By implementing constant-qualified const_pcpu_hot, the compiler can
eliminate redundant reads from the constant variables, reducing the
number of loads from current_task from 3766 to 3217 on a test build,
a -14.6% reduction.
The reduction of loads translates to the following code savings:
text data bss dec hex filename
25,477,353 4389456 808452 30675261 1d4113d vmlinux-old.o
25,476,074 4389440 808452 30673966 1d40c2e vmlinux-new.o
representing a code size reduction of -1279 bytes.
[ mingo: Updated the changelog, EXPORT(const_pcpu_hot). ]
Co-developed-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20231020162004.135244-1-ubizjak@gmail.com
2023-10-20 18:19:20 +02:00
|
|
|
* pcpu_hot.current_task and pcpu_hot.top_of_stack, both of which are
|
|
|
|
* actually per-thread variables implemented as per-CPU variables and
|
|
|
|
* thus stable for the duration of the respective task.
|
2009-08-03 14:08:48 +09:00
|
|
|
*/
|
2020-07-20 13:49:23 -07:00
|
|
|
#define this_cpu_read_stable(pcp) __pcpu_size_call_return(this_cpu_read_stable_, pcp)
|
2009-01-13 20:41:35 +09:00
|
|
|
|
x86/percpu: Use C for percpu read/write accessors
The percpu code mostly uses inline assembly. Using segment qualifiers
allows to use C code instead, which enables the compiler to perform
various optimizations (e.g. propagation of memory arguments). Convert
percpu read and write accessors to C code, so the memory argument can
be propagated to the instruction that uses this argument.
Some examples of propagations:
a) into sign/zero extensions:
the code improves from:
65 8a 05 00 00 00 00 mov %gs:0x0(%rip),%al
0f b6 c0 movzbl %al,%eax
to:
65 0f b6 05 00 00 00 movzbl %gs:0x0(%rip),%eax
00
and in a similar way for:
movzbl %gs:0x0(%rip),%edx
movzwl %gs:0x0(%rip),%esi
movzbl %gs:0x78(%rbx),%eax
movslq %gs:0x0(%rip),%rdx
movslq %gs:(%rdi),%rbx
b) into compares:
the code improves from:
65 8b 05 00 00 00 00 mov %gs:0x0(%rip),%eax
a9 00 00 0f 00 test $0xf0000,%eax
to:
65 f7 05 00 00 00 00 testl $0xf0000,%gs:0x0(%rip)
00 00 0f 00
and in a similar way for:
testl $0xf0000,%gs:0x0(%rip)
testb $0x1,%gs:0x0(%rip)
testl $0xff00,%gs:0x0(%rip)
cmpb $0x0,%gs:0x0(%rip)
cmp %gs:0x0(%rip),%r14d
cmpw $0x8,%gs:0x0(%rip)
cmpb $0x0,%gs:(%rax)
c) into other insns:
the code improves from:
1a355: 83 fa ff cmp $0xffffffff,%edx
1a358: 75 07 jne 1a361 <...>
1a35a: 65 8b 15 00 00 00 00 mov %gs:0x0(%rip),%edx
1a361:
to:
1a35a: 83 fa ff cmp $0xffffffff,%edx
1a35d: 65 0f 44 15 00 00 00 cmove %gs:0x0(%rip),%edx
1a364: 00
The above propagations result in the following code size
improvements for current mainline kernel (with the default config),
compiled with:
# gcc (GCC) 12.3.1 20230508 (Red Hat 12.3.1-1)
text data bss dec filename
25508862 4386540 808388 30703790 vmlinux-vanilla.o
25500922 4386532 808388 30695842 vmlinux-new.o
Co-developed-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Link: https://lore.kernel.org/r/20231004192404.31733-1-ubizjak@gmail.com
2023-10-04 21:23:08 +02:00
|
|
|
#ifdef CONFIG_USE_X86_SEG_SUPPORT
|
|
|
|
|
|
|
|
#define __raw_cpu_read(qual, pcp) \
|
|
|
|
({ \
|
|
|
|
*(qual __my_cpu_type(pcp) *)__my_cpu_ptr(&(pcp)); \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define __raw_cpu_write(qual, pcp, val) \
|
|
|
|
do { \
|
|
|
|
*(qual __my_cpu_type(pcp) *)__my_cpu_ptr(&(pcp)) = (val); \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define raw_cpu_read_1(pcp) __raw_cpu_read(, pcp)
|
|
|
|
#define raw_cpu_read_2(pcp) __raw_cpu_read(, pcp)
|
|
|
|
#define raw_cpu_read_4(pcp) __raw_cpu_read(, pcp)
|
|
|
|
#define raw_cpu_write_1(pcp, val) __raw_cpu_write(, pcp, val)
|
|
|
|
#define raw_cpu_write_2(pcp, val) __raw_cpu_write(, pcp, val)
|
|
|
|
#define raw_cpu_write_4(pcp, val) __raw_cpu_write(, pcp, val)
|
|
|
|
|
|
|
|
#define this_cpu_read_1(pcp) __raw_cpu_read(volatile, pcp)
|
|
|
|
#define this_cpu_read_2(pcp) __raw_cpu_read(volatile, pcp)
|
|
|
|
#define this_cpu_read_4(pcp) __raw_cpu_read(volatile, pcp)
|
|
|
|
#define this_cpu_write_1(pcp, val) __raw_cpu_write(volatile, pcp, val)
|
|
|
|
#define this_cpu_write_2(pcp, val) __raw_cpu_write(volatile, pcp, val)
|
|
|
|
#define this_cpu_write_4(pcp, val) __raw_cpu_write(volatile, pcp, val)
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
#define raw_cpu_read_8(pcp) __raw_cpu_read(, pcp)
|
|
|
|
#define raw_cpu_write_8(pcp, val) __raw_cpu_write(, pcp, val)
|
|
|
|
|
|
|
|
#define this_cpu_read_8(pcp) __raw_cpu_read(volatile, pcp)
|
|
|
|
#define this_cpu_write_8(pcp, val) __raw_cpu_write(volatile, pcp, val)
|
|
|
|
#endif
|
|
|
|
|
2023-12-04 22:02:29 +01:00
|
|
|
#define this_cpu_read_const(pcp) __raw_cpu_read(, pcp)
|
x86/percpu: Use C for percpu read/write accessors
The percpu code mostly uses inline assembly. Using segment qualifiers
allows to use C code instead, which enables the compiler to perform
various optimizations (e.g. propagation of memory arguments). Convert
percpu read and write accessors to C code, so the memory argument can
be propagated to the instruction that uses this argument.
Some examples of propagations:
a) into sign/zero extensions:
the code improves from:
65 8a 05 00 00 00 00 mov %gs:0x0(%rip),%al
0f b6 c0 movzbl %al,%eax
to:
65 0f b6 05 00 00 00 movzbl %gs:0x0(%rip),%eax
00
and in a similar way for:
movzbl %gs:0x0(%rip),%edx
movzwl %gs:0x0(%rip),%esi
movzbl %gs:0x78(%rbx),%eax
movslq %gs:0x0(%rip),%rdx
movslq %gs:(%rdi),%rbx
b) into compares:
the code improves from:
65 8b 05 00 00 00 00 mov %gs:0x0(%rip),%eax
a9 00 00 0f 00 test $0xf0000,%eax
to:
65 f7 05 00 00 00 00 testl $0xf0000,%gs:0x0(%rip)
00 00 0f 00
and in a similar way for:
testl $0xf0000,%gs:0x0(%rip)
testb $0x1,%gs:0x0(%rip)
testl $0xff00,%gs:0x0(%rip)
cmpb $0x0,%gs:0x0(%rip)
cmp %gs:0x0(%rip),%r14d
cmpw $0x8,%gs:0x0(%rip)
cmpb $0x0,%gs:(%rax)
c) into other insns:
the code improves from:
1a355: 83 fa ff cmp $0xffffffff,%edx
1a358: 75 07 jne 1a361 <...>
1a35a: 65 8b 15 00 00 00 00 mov %gs:0x0(%rip),%edx
1a361:
to:
1a35a: 83 fa ff cmp $0xffffffff,%edx
1a35d: 65 0f 44 15 00 00 00 cmove %gs:0x0(%rip),%edx
1a364: 00
The above propagations result in the following code size
improvements for current mainline kernel (with the default config),
compiled with:
# gcc (GCC) 12.3.1 20230508 (Red Hat 12.3.1-1)
text data bss dec filename
25508862 4386540 808388 30703790 vmlinux-vanilla.o
25500922 4386532 808388 30695842 vmlinux-new.o
Co-developed-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Link: https://lore.kernel.org/r/20231004192404.31733-1-ubizjak@gmail.com
2023-10-04 21:23:08 +02:00
|
|
|
#else /* CONFIG_USE_X86_SEG_SUPPORT */
|
|
|
|
|
2020-07-20 13:49:17 -07:00
|
|
|
#define raw_cpu_read_1(pcp) percpu_from_op(1, , "mov", pcp)
|
|
|
|
#define raw_cpu_read_2(pcp) percpu_from_op(2, , "mov", pcp)
|
|
|
|
#define raw_cpu_read_4(pcp) percpu_from_op(4, , "mov", pcp)
|
2020-07-20 13:49:16 -07:00
|
|
|
#define raw_cpu_write_1(pcp, val) percpu_to_op(1, , "mov", (pcp), val)
|
|
|
|
#define raw_cpu_write_2(pcp, val) percpu_to_op(2, , "mov", (pcp), val)
|
|
|
|
#define raw_cpu_write_4(pcp, val) percpu_to_op(4, , "mov", (pcp), val)
|
x86/percpu: Use C for percpu read/write accessors
The percpu code mostly uses inline assembly. Using segment qualifiers
allows to use C code instead, which enables the compiler to perform
various optimizations (e.g. propagation of memory arguments). Convert
percpu read and write accessors to C code, so the memory argument can
be propagated to the instruction that uses this argument.
Some examples of propagations:
a) into sign/zero extensions:
the code improves from:
65 8a 05 00 00 00 00 mov %gs:0x0(%rip),%al
0f b6 c0 movzbl %al,%eax
to:
65 0f b6 05 00 00 00 movzbl %gs:0x0(%rip),%eax
00
and in a similar way for:
movzbl %gs:0x0(%rip),%edx
movzwl %gs:0x0(%rip),%esi
movzbl %gs:0x78(%rbx),%eax
movslq %gs:0x0(%rip),%rdx
movslq %gs:(%rdi),%rbx
b) into compares:
the code improves from:
65 8b 05 00 00 00 00 mov %gs:0x0(%rip),%eax
a9 00 00 0f 00 test $0xf0000,%eax
to:
65 f7 05 00 00 00 00 testl $0xf0000,%gs:0x0(%rip)
00 00 0f 00
and in a similar way for:
testl $0xf0000,%gs:0x0(%rip)
testb $0x1,%gs:0x0(%rip)
testl $0xff00,%gs:0x0(%rip)
cmpb $0x0,%gs:0x0(%rip)
cmp %gs:0x0(%rip),%r14d
cmpw $0x8,%gs:0x0(%rip)
cmpb $0x0,%gs:(%rax)
c) into other insns:
the code improves from:
1a355: 83 fa ff cmp $0xffffffff,%edx
1a358: 75 07 jne 1a361 <...>
1a35a: 65 8b 15 00 00 00 00 mov %gs:0x0(%rip),%edx
1a361:
to:
1a35a: 83 fa ff cmp $0xffffffff,%edx
1a35d: 65 0f 44 15 00 00 00 cmove %gs:0x0(%rip),%edx
1a364: 00
The above propagations result in the following code size
improvements for current mainline kernel (with the default config),
compiled with:
# gcc (GCC) 12.3.1 20230508 (Red Hat 12.3.1-1)
text data bss dec filename
25508862 4386540 808388 30703790 vmlinux-vanilla.o
25500922 4386532 808388 30695842 vmlinux-new.o
Co-developed-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Link: https://lore.kernel.org/r/20231004192404.31733-1-ubizjak@gmail.com
2023-10-04 21:23:08 +02:00
|
|
|
|
|
|
|
#define this_cpu_read_1(pcp) percpu_from_op(1, volatile, "mov", pcp)
|
|
|
|
#define this_cpu_read_2(pcp) percpu_from_op(2, volatile, "mov", pcp)
|
|
|
|
#define this_cpu_read_4(pcp) percpu_from_op(4, volatile, "mov", pcp)
|
|
|
|
#define this_cpu_write_1(pcp, val) percpu_to_op(1, volatile, "mov", (pcp), val)
|
|
|
|
#define this_cpu_write_2(pcp, val) percpu_to_op(2, volatile, "mov", (pcp), val)
|
|
|
|
#define this_cpu_write_4(pcp, val) percpu_to_op(4, volatile, "mov", (pcp), val)
|
|
|
|
|
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
#define raw_cpu_read_8(pcp) percpu_from_op(8, , "mov", pcp)
|
|
|
|
#define raw_cpu_write_8(pcp, val) percpu_to_op(8, , "mov", (pcp), val)
|
|
|
|
|
|
|
|
#define this_cpu_read_8(pcp) percpu_from_op(8, volatile, "mov", pcp)
|
|
|
|
#define this_cpu_write_8(pcp, val) percpu_to_op(8, volatile, "mov", (pcp), val)
|
|
|
|
#endif
|
|
|
|
|
2023-12-04 22:02:29 +01:00
|
|
|
/*
|
|
|
|
* The generic per-cpu infrastrucutre is not suitable for
|
|
|
|
* reading const-qualified variables.
|
|
|
|
*/
|
|
|
|
#define this_cpu_read_const(pcp) ({ BUILD_BUG(); (typeof(pcp))0; })
|
x86/percpu: Use C for percpu read/write accessors
The percpu code mostly uses inline assembly. Using segment qualifiers
allows to use C code instead, which enables the compiler to perform
various optimizations (e.g. propagation of memory arguments). Convert
percpu read and write accessors to C code, so the memory argument can
be propagated to the instruction that uses this argument.
Some examples of propagations:
a) into sign/zero extensions:
the code improves from:
65 8a 05 00 00 00 00 mov %gs:0x0(%rip),%al
0f b6 c0 movzbl %al,%eax
to:
65 0f b6 05 00 00 00 movzbl %gs:0x0(%rip),%eax
00
and in a similar way for:
movzbl %gs:0x0(%rip),%edx
movzwl %gs:0x0(%rip),%esi
movzbl %gs:0x78(%rbx),%eax
movslq %gs:0x0(%rip),%rdx
movslq %gs:(%rdi),%rbx
b) into compares:
the code improves from:
65 8b 05 00 00 00 00 mov %gs:0x0(%rip),%eax
a9 00 00 0f 00 test $0xf0000,%eax
to:
65 f7 05 00 00 00 00 testl $0xf0000,%gs:0x0(%rip)
00 00 0f 00
and in a similar way for:
testl $0xf0000,%gs:0x0(%rip)
testb $0x1,%gs:0x0(%rip)
testl $0xff00,%gs:0x0(%rip)
cmpb $0x0,%gs:0x0(%rip)
cmp %gs:0x0(%rip),%r14d
cmpw $0x8,%gs:0x0(%rip)
cmpb $0x0,%gs:(%rax)
c) into other insns:
the code improves from:
1a355: 83 fa ff cmp $0xffffffff,%edx
1a358: 75 07 jne 1a361 <...>
1a35a: 65 8b 15 00 00 00 00 mov %gs:0x0(%rip),%edx
1a361:
to:
1a35a: 83 fa ff cmp $0xffffffff,%edx
1a35d: 65 0f 44 15 00 00 00 cmove %gs:0x0(%rip),%edx
1a364: 00
The above propagations result in the following code size
improvements for current mainline kernel (with the default config),
compiled with:
# gcc (GCC) 12.3.1 20230508 (Red Hat 12.3.1-1)
text data bss dec filename
25508862 4386540 808388 30703790 vmlinux-vanilla.o
25500922 4386532 808388 30695842 vmlinux-new.o
Co-developed-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Nadav Amit <namit@vmware.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Link: https://lore.kernel.org/r/20231004192404.31733-1-ubizjak@gmail.com
2023-10-04 21:23:08 +02:00
|
|
|
#endif /* CONFIG_USE_X86_SEG_SUPPORT */
|
|
|
|
|
2024-03-24 22:19:45 +01:00
|
|
|
#define this_cpu_read_stable_1(pcp) percpu_stable_op(1, "mov", pcp)
|
|
|
|
#define this_cpu_read_stable_2(pcp) percpu_stable_op(2, "mov", pcp)
|
|
|
|
#define this_cpu_read_stable_4(pcp) percpu_stable_op(4, "mov", pcp)
|
|
|
|
|
2020-07-20 13:49:18 -07:00
|
|
|
#define raw_cpu_add_1(pcp, val) percpu_add_op(1, , (pcp), val)
|
|
|
|
#define raw_cpu_add_2(pcp, val) percpu_add_op(2, , (pcp), val)
|
|
|
|
#define raw_cpu_add_4(pcp, val) percpu_add_op(4, , (pcp), val)
|
2020-07-20 13:49:16 -07:00
|
|
|
#define raw_cpu_and_1(pcp, val) percpu_to_op(1, , "and", (pcp), val)
|
|
|
|
#define raw_cpu_and_2(pcp, val) percpu_to_op(2, , "and", (pcp), val)
|
|
|
|
#define raw_cpu_and_4(pcp, val) percpu_to_op(4, , "and", (pcp), val)
|
|
|
|
#define raw_cpu_or_1(pcp, val) percpu_to_op(1, , "or", (pcp), val)
|
|
|
|
#define raw_cpu_or_2(pcp, val) percpu_to_op(2, , "or", (pcp), val)
|
|
|
|
#define raw_cpu_or_4(pcp, val) percpu_to_op(4, , "or", (pcp), val)
|
2019-02-27 11:09:56 +01:00
|
|
|
#define raw_cpu_xchg_1(pcp, val) raw_percpu_xchg_op(pcp, val)
|
|
|
|
#define raw_cpu_xchg_2(pcp, val) raw_percpu_xchg_op(pcp, val)
|
|
|
|
#define raw_cpu_xchg_4(pcp, val) raw_percpu_xchg_op(pcp, val)
|
2009-10-03 19:48:22 +09:00
|
|
|
|
2020-07-20 13:49:18 -07:00
|
|
|
#define this_cpu_add_1(pcp, val) percpu_add_op(1, volatile, (pcp), val)
|
|
|
|
#define this_cpu_add_2(pcp, val) percpu_add_op(2, volatile, (pcp), val)
|
|
|
|
#define this_cpu_add_4(pcp, val) percpu_add_op(4, volatile, (pcp), val)
|
2020-07-20 13:49:16 -07:00
|
|
|
#define this_cpu_and_1(pcp, val) percpu_to_op(1, volatile, "and", (pcp), val)
|
|
|
|
#define this_cpu_and_2(pcp, val) percpu_to_op(2, volatile, "and", (pcp), val)
|
|
|
|
#define this_cpu_and_4(pcp, val) percpu_to_op(4, volatile, "and", (pcp), val)
|
|
|
|
#define this_cpu_or_1(pcp, val) percpu_to_op(1, volatile, "or", (pcp), val)
|
|
|
|
#define this_cpu_or_2(pcp, val) percpu_to_op(2, volatile, "or", (pcp), val)
|
|
|
|
#define this_cpu_or_4(pcp, val) percpu_to_op(4, volatile, "or", (pcp), val)
|
2024-03-20 09:30:40 +01:00
|
|
|
#define this_cpu_xchg_1(pcp, nval) this_percpu_xchg_op(pcp, nval)
|
|
|
|
#define this_cpu_xchg_2(pcp, nval) this_percpu_xchg_op(pcp, nval)
|
|
|
|
#define this_cpu_xchg_4(pcp, nval) this_percpu_xchg_op(pcp, nval)
|
2009-10-03 19:48:22 +09:00
|
|
|
|
2020-07-20 13:49:20 -07:00
|
|
|
#define raw_cpu_add_return_1(pcp, val) percpu_add_return_op(1, , pcp, val)
|
|
|
|
#define raw_cpu_add_return_2(pcp, val) percpu_add_return_op(2, , pcp, val)
|
|
|
|
#define raw_cpu_add_return_4(pcp, val) percpu_add_return_op(4, , pcp, val)
|
2020-07-20 13:49:22 -07:00
|
|
|
#define raw_cpu_cmpxchg_1(pcp, oval, nval) percpu_cmpxchg_op(1, , pcp, oval, nval)
|
|
|
|
#define raw_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(2, , pcp, oval, nval)
|
|
|
|
#define raw_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(4, , pcp, oval, nval)
|
2023-08-30 17:13:56 +02:00
|
|
|
#define raw_cpu_try_cmpxchg_1(pcp, ovalp, nval) percpu_try_cmpxchg_op(1, , pcp, ovalp, nval)
|
|
|
|
#define raw_cpu_try_cmpxchg_2(pcp, ovalp, nval) percpu_try_cmpxchg_op(2, , pcp, ovalp, nval)
|
|
|
|
#define raw_cpu_try_cmpxchg_4(pcp, ovalp, nval) percpu_try_cmpxchg_op(4, , pcp, ovalp, nval)
|
2010-12-14 10:28:44 -06:00
|
|
|
|
2020-07-20 13:49:20 -07:00
|
|
|
#define this_cpu_add_return_1(pcp, val) percpu_add_return_op(1, volatile, pcp, val)
|
|
|
|
#define this_cpu_add_return_2(pcp, val) percpu_add_return_op(2, volatile, pcp, val)
|
|
|
|
#define this_cpu_add_return_4(pcp, val) percpu_add_return_op(4, volatile, pcp, val)
|
2020-07-20 13:49:22 -07:00
|
|
|
#define this_cpu_cmpxchg_1(pcp, oval, nval) percpu_cmpxchg_op(1, volatile, pcp, oval, nval)
|
|
|
|
#define this_cpu_cmpxchg_2(pcp, oval, nval) percpu_cmpxchg_op(2, volatile, pcp, oval, nval)
|
|
|
|
#define this_cpu_cmpxchg_4(pcp, oval, nval) percpu_cmpxchg_op(4, volatile, pcp, oval, nval)
|
2023-08-30 17:13:56 +02:00
|
|
|
#define this_cpu_try_cmpxchg_1(pcp, ovalp, nval) percpu_try_cmpxchg_op(1, volatile, pcp, ovalp, nval)
|
|
|
|
#define this_cpu_try_cmpxchg_2(pcp, ovalp, nval) percpu_try_cmpxchg_op(2, volatile, pcp, ovalp, nval)
|
|
|
|
#define this_cpu_try_cmpxchg_4(pcp, ovalp, nval) percpu_try_cmpxchg_op(4, volatile, pcp, ovalp, nval)
|
2010-12-14 10:28:44 -06:00
|
|
|
|
2009-10-03 19:48:22 +09:00
|
|
|
/*
|
|
|
|
* Per cpu atomic 64 bit operations are only available under 64 bit.
|
|
|
|
* 32 bit must fall back to generic operations.
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_X86_64
|
2024-03-24 22:19:45 +01:00
|
|
|
#define this_cpu_read_stable_8(pcp) percpu_stable_op(8, "mov", pcp)
|
|
|
|
|
2020-07-20 13:49:18 -07:00
|
|
|
#define raw_cpu_add_8(pcp, val) percpu_add_op(8, , (pcp), val)
|
2020-07-20 13:49:16 -07:00
|
|
|
#define raw_cpu_and_8(pcp, val) percpu_to_op(8, , "and", (pcp), val)
|
|
|
|
#define raw_cpu_or_8(pcp, val) percpu_to_op(8, , "or", (pcp), val)
|
2020-07-20 13:49:20 -07:00
|
|
|
#define raw_cpu_add_return_8(pcp, val) percpu_add_return_op(8, , pcp, val)
|
2019-02-27 11:09:56 +01:00
|
|
|
#define raw_cpu_xchg_8(pcp, nval) raw_percpu_xchg_op(pcp, nval)
|
2020-07-20 13:49:22 -07:00
|
|
|
#define raw_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(8, , pcp, oval, nval)
|
2023-08-30 17:13:56 +02:00
|
|
|
#define raw_cpu_try_cmpxchg_8(pcp, ovalp, nval) percpu_try_cmpxchg_op(8, , pcp, ovalp, nval)
|
2014-04-07 15:39:34 -07:00
|
|
|
|
2020-07-20 13:49:18 -07:00
|
|
|
#define this_cpu_add_8(pcp, val) percpu_add_op(8, volatile, (pcp), val)
|
2020-07-20 13:49:16 -07:00
|
|
|
#define this_cpu_and_8(pcp, val) percpu_to_op(8, volatile, "and", (pcp), val)
|
|
|
|
#define this_cpu_or_8(pcp, val) percpu_to_op(8, volatile, "or", (pcp), val)
|
2020-07-20 13:49:20 -07:00
|
|
|
#define this_cpu_add_return_8(pcp, val) percpu_add_return_op(8, volatile, pcp, val)
|
2024-03-20 09:30:40 +01:00
|
|
|
#define this_cpu_xchg_8(pcp, nval) this_percpu_xchg_op(pcp, nval)
|
2020-07-20 13:49:22 -07:00
|
|
|
#define this_cpu_cmpxchg_8(pcp, oval, nval) percpu_cmpxchg_op(8, volatile, pcp, oval, nval)
|
2023-08-30 17:13:56 +02:00
|
|
|
#define this_cpu_try_cmpxchg_8(pcp, ovalp, nval) percpu_try_cmpxchg_op(8, volatile, pcp, ovalp, nval)
|
2024-04-04 11:42:03 +02:00
|
|
|
|
|
|
|
#define raw_cpu_read_long(pcp) raw_cpu_read_8(pcp)
|
2024-03-24 22:19:45 +01:00
|
|
|
#else
|
|
|
|
/* There is no generic 64 bit read stable operation for 32 bit targets. */
|
2024-04-04 11:42:03 +02:00
|
|
|
#define this_cpu_read_stable_8(pcp) ({ BUILD_BUG(); (typeof(pcp))0; })
|
|
|
|
|
|
|
|
#define raw_cpu_read_long(pcp) raw_cpu_read_4(pcp)
|
2009-10-03 19:48:22 +09:00
|
|
|
#endif
|
|
|
|
|
2024-04-04 11:42:02 +02:00
|
|
|
#define x86_this_cpu_constant_test_bit(_nr, _var) \
|
|
|
|
({ \
|
|
|
|
unsigned long __percpu *addr__ = \
|
|
|
|
(unsigned long __percpu *)&(_var) + ((_nr) / BITS_PER_LONG); \
|
|
|
|
!!((1UL << ((_nr) % BITS_PER_LONG)) & raw_cpu_read(*addr__)); \
|
|
|
|
})
|
2011-03-12 12:50:10 +01:00
|
|
|
|
2024-04-04 11:42:02 +02:00
|
|
|
#define x86_this_cpu_variable_test_bit(_nr, _var) \
|
|
|
|
({ \
|
|
|
|
bool oldbit; \
|
|
|
|
\
|
|
|
|
asm volatile("btl %[nr], " __percpu_arg([var]) \
|
|
|
|
CC_SET(c) \
|
|
|
|
: CC_OUT(c) (oldbit) \
|
|
|
|
: [var] "m" (__my_cpu_var(_var)), \
|
|
|
|
[nr] "rI" (_nr)); \
|
|
|
|
oldbit; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define x86_this_cpu_test_bit(_nr, _var) \
|
|
|
|
(__builtin_constant_p(_nr) \
|
|
|
|
? x86_this_cpu_constant_test_bit(_nr, _var) \
|
|
|
|
: x86_this_cpu_variable_test_bit(_nr, _var))
|
2011-03-12 12:50:10 +01:00
|
|
|
|
|
|
|
|
percpu: add optimized generic percpu accessors
It is an optimization and a cleanup, and adds the following new
generic percpu methods:
percpu_read()
percpu_write()
percpu_add()
percpu_sub()
percpu_and()
percpu_or()
percpu_xor()
and implements support for them on x86. (other architectures will fall
back to a default implementation)
The advantage is that for example to read a local percpu variable,
instead of this sequence:
return __get_cpu_var(var);
ffffffff8102ca2b: 48 8b 14 fd 80 09 74 mov -0x7e8bf680(,%rdi,8),%rdx
ffffffff8102ca32: 81
ffffffff8102ca33: 48 c7 c0 d8 59 00 00 mov $0x59d8,%rax
ffffffff8102ca3a: 48 8b 04 10 mov (%rax,%rdx,1),%rax
We can get a single instruction by using the optimized variants:
return percpu_read(var);
ffffffff8102ca3f: 65 48 8b 05 91 8f fd mov %gs:0x7efd8f91(%rip),%rax
I also cleaned up the x86-specific APIs and made the x86 code use
these new generic percpu primitives.
tj: * fixed generic percpu_sub() definition as Roel Kluin pointed out
* added percpu_and() for completeness's sake
* made generic percpu ops atomic against preemption
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Tejun Heo <tj@kernel.org>
2009-01-15 22:15:53 +09:00
|
|
|
#include <asm-generic/percpu.h>
|
|
|
|
|
|
|
|
/* We can use this directly for local CPU (faster). */
|
2014-11-04 08:26:42 +00:00
|
|
|
DECLARE_PER_CPU_READ_MOSTLY(unsigned long, this_cpu_off);
|
percpu: add optimized generic percpu accessors
It is an optimization and a cleanup, and adds the following new
generic percpu methods:
percpu_read()
percpu_write()
percpu_add()
percpu_sub()
percpu_and()
percpu_or()
percpu_xor()
and implements support for them on x86. (other architectures will fall
back to a default implementation)
The advantage is that for example to read a local percpu variable,
instead of this sequence:
return __get_cpu_var(var);
ffffffff8102ca2b: 48 8b 14 fd 80 09 74 mov -0x7e8bf680(,%rdi,8),%rdx
ffffffff8102ca32: 81
ffffffff8102ca33: 48 c7 c0 d8 59 00 00 mov $0x59d8,%rax
ffffffff8102ca3a: 48 8b 04 10 mov (%rax,%rdx,1),%rax
We can get a single instruction by using the optimized variants:
return percpu_read(var);
ffffffff8102ca3f: 65 48 8b 05 91 8f fd mov %gs:0x7efd8f91(%rip),%rax
I also cleaned up the x86-specific APIs and made the x86 code use
these new generic percpu primitives.
tj: * fixed generic percpu_sub() definition as Roel Kluin pointed out
* added percpu_and() for completeness's sake
* made generic percpu ops atomic against preemption
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Tejun Heo <tj@kernel.org>
2009-01-15 22:15:53 +09:00
|
|
|
|
2008-01-30 13:32:53 +01:00
|
|
|
#endif /* !__ASSEMBLY__ */
|
x86: cleanup early per cpu variables/accesses v4
* Introduce a new PER_CPU macro called "EARLY_PER_CPU". This is
used by some per_cpu variables that are initialized and accessed
before there are per_cpu areas allocated.
["Early" in respect to per_cpu variables is "earlier than the per_cpu
areas have been setup".]
This patchset adds these new macros:
DEFINE_EARLY_PER_CPU(_type, _name, _initvalue)
EXPORT_EARLY_PER_CPU_SYMBOL(_name)
DECLARE_EARLY_PER_CPU(_type, _name)
early_per_cpu_ptr(_name)
early_per_cpu_map(_name, _idx)
early_per_cpu(_name, _cpu)
The DEFINE macro defines the per_cpu variable as well as the early
map and pointer. It also initializes the per_cpu variable and map
elements to "_initvalue". The early_* macros provide access to
the initial map (usually setup during system init) and the early
pointer. This pointer is initialized to point to the early map
but is then NULL'ed when the actual per_cpu areas are setup. After
that the per_cpu variable is the correct access to the variable.
The early_per_cpu() macro is not very efficient but does show how to
access the variable if you have a function that can be called both
"early" and "late". It tests the early ptr to be NULL, and if not
then it's still valid. Otherwise, the per_cpu variable is used
instead:
#define early_per_cpu(_name, _cpu) \
(early_per_cpu_ptr(_name) ? \
early_per_cpu_ptr(_name)[_cpu] : \
per_cpu(_name, _cpu))
A better method is to actually check the pointer manually. In the
case below, numa_set_node can be called both "early" and "late":
void __cpuinit numa_set_node(int cpu, int node)
{
int *cpu_to_node_map = early_per_cpu_ptr(x86_cpu_to_node_map);
if (cpu_to_node_map)
cpu_to_node_map[cpu] = node;
else
per_cpu(x86_cpu_to_node_map, cpu) = node;
}
* Add a flag "arch_provides_topology_pointers" that indicates pointers
to topology cpumask_t maps are available. Otherwise, use the function
returning the cpumask_t value. This is useful if cpumask_t set size
is very large to avoid copying data on to/off of the stack.
* The coverage of CONFIG_DEBUG_PER_CPU_MAPS has been increased while
the non-debug case has been optimized a bit.
* Remove an unreferenced compiler warning in drivers/base/topology.c
* Clean up #ifdef in setup.c
For inclusion into sched-devel/latest tree.
Based on:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
+ sched-devel/latest .../mingo/linux-2.6-sched-devel.git
Signed-off-by: Mike Travis <travis@sgi.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2008-05-12 21:21:12 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Define the "EARLY_PER_CPU" macros. These are used for some per_cpu
|
|
|
|
* variables that are initialized and accessed before there are per_cpu
|
|
|
|
* areas allocated.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEFINE_EARLY_PER_CPU(_type, _name, _initvalue) \
|
|
|
|
DEFINE_PER_CPU(_type, _name) = _initvalue; \
|
|
|
|
__typeof__(_type) _name##_early_map[NR_CPUS] __initdata = \
|
|
|
|
{ [0 ... NR_CPUS-1] = _initvalue }; \
|
x86, percpu: silence section mismatch warnings related to EARLY_PER_CPU variables
Quoting Mike Travis in "x86: cleanup early per cpu variables/accesses v4"
(23ca4bba3e20c6c3cb11c1bb0ab4770b724d39ac):
The DEFINE macro defines the per_cpu variable as well as the early
map and pointer. It also initializes the per_cpu variable and map
elements to "_initvalue". The early_* macros provide access to
the initial map (usually setup during system init) and the early
pointer. This pointer is initialized to point to the early map
but is then NULL'ed when the actual per_cpu areas are setup. After
that the per_cpu variable is the correct access to the variable.
As these variables are NULL'ed before __init sections are dropped
(in setup_per_cpu_maps), they can be safely annotated as __ref.
This change silences following section mismatch warnings:
WARNING: vmlinux.o(.data+0x46c0): Section mismatch in reference from the variable x86_cpu_to_apicid_early_ptr to the variable .init.data:x86_cpu_to_apicid_early_map
The variable x86_cpu_to_apicid_early_ptr references
the variable __initdata x86_cpu_to_apicid_early_map
If the reference is valid then annotate the
variable with __init* (see linux/init.h) or name the variable:
*driver, *_template, *_timer, *_sht, *_ops, *_probe, *_probe_one, *_console,
WARNING: vmlinux.o(.data+0x46c8): Section mismatch in reference from the variable x86_bios_cpu_apicid_early_ptr to the variable .init.data:x86_bios_cpu_apicid_early_map
The variable x86_bios_cpu_apicid_early_ptr references
the variable __initdata x86_bios_cpu_apicid_early_map
If the reference is valid then annotate the
variable with __init* (see linux/init.h) or name the variable:
*driver, *_template, *_timer, *_sht, *_ops, *_probe, *_probe_one, *_console,
WARNING: vmlinux.o(.data+0x46d0): Section mismatch in reference from the variable x86_cpu_to_node_map_early_ptr to the variable .init.data:x86_cpu_to_node_map_early_map
The variable x86_cpu_to_node_map_early_ptr references
the variable __initdata x86_cpu_to_node_map_early_map
If the reference is valid then annotate the
variable with __init* (see linux/init.h) or name the variable:
*driver, *_template, *_timer, *_sht, *_ops, *_probe, *_probe_one, *_console,
Signed-off-by: Marcin Slusarz <marcin.slusarz@gmail.com>
Cc: Mike Travis <travis@sgi.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2008-08-17 17:50:50 +02:00
|
|
|
__typeof__(_type) *_name##_early_ptr __refdata = _name##_early_map
|
x86: cleanup early per cpu variables/accesses v4
* Introduce a new PER_CPU macro called "EARLY_PER_CPU". This is
used by some per_cpu variables that are initialized and accessed
before there are per_cpu areas allocated.
["Early" in respect to per_cpu variables is "earlier than the per_cpu
areas have been setup".]
This patchset adds these new macros:
DEFINE_EARLY_PER_CPU(_type, _name, _initvalue)
EXPORT_EARLY_PER_CPU_SYMBOL(_name)
DECLARE_EARLY_PER_CPU(_type, _name)
early_per_cpu_ptr(_name)
early_per_cpu_map(_name, _idx)
early_per_cpu(_name, _cpu)
The DEFINE macro defines the per_cpu variable as well as the early
map and pointer. It also initializes the per_cpu variable and map
elements to "_initvalue". The early_* macros provide access to
the initial map (usually setup during system init) and the early
pointer. This pointer is initialized to point to the early map
but is then NULL'ed when the actual per_cpu areas are setup. After
that the per_cpu variable is the correct access to the variable.
The early_per_cpu() macro is not very efficient but does show how to
access the variable if you have a function that can be called both
"early" and "late". It tests the early ptr to be NULL, and if not
then it's still valid. Otherwise, the per_cpu variable is used
instead:
#define early_per_cpu(_name, _cpu) \
(early_per_cpu_ptr(_name) ? \
early_per_cpu_ptr(_name)[_cpu] : \
per_cpu(_name, _cpu))
A better method is to actually check the pointer manually. In the
case below, numa_set_node can be called both "early" and "late":
void __cpuinit numa_set_node(int cpu, int node)
{
int *cpu_to_node_map = early_per_cpu_ptr(x86_cpu_to_node_map);
if (cpu_to_node_map)
cpu_to_node_map[cpu] = node;
else
per_cpu(x86_cpu_to_node_map, cpu) = node;
}
* Add a flag "arch_provides_topology_pointers" that indicates pointers
to topology cpumask_t maps are available. Otherwise, use the function
returning the cpumask_t value. This is useful if cpumask_t set size
is very large to avoid copying data on to/off of the stack.
* The coverage of CONFIG_DEBUG_PER_CPU_MAPS has been increased while
the non-debug case has been optimized a bit.
* Remove an unreferenced compiler warning in drivers/base/topology.c
* Clean up #ifdef in setup.c
For inclusion into sched-devel/latest tree.
Based on:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
+ sched-devel/latest .../mingo/linux-2.6-sched-devel.git
Signed-off-by: Mike Travis <travis@sgi.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2008-05-12 21:21:12 +02:00
|
|
|
|
2012-06-11 12:56:45 +03:00
|
|
|
#define DEFINE_EARLY_PER_CPU_READ_MOSTLY(_type, _name, _initvalue) \
|
|
|
|
DEFINE_PER_CPU_READ_MOSTLY(_type, _name) = _initvalue; \
|
|
|
|
__typeof__(_type) _name##_early_map[NR_CPUS] __initdata = \
|
|
|
|
{ [0 ... NR_CPUS-1] = _initvalue }; \
|
|
|
|
__typeof__(_type) *_name##_early_ptr __refdata = _name##_early_map
|
|
|
|
|
x86: cleanup early per cpu variables/accesses v4
* Introduce a new PER_CPU macro called "EARLY_PER_CPU". This is
used by some per_cpu variables that are initialized and accessed
before there are per_cpu areas allocated.
["Early" in respect to per_cpu variables is "earlier than the per_cpu
areas have been setup".]
This patchset adds these new macros:
DEFINE_EARLY_PER_CPU(_type, _name, _initvalue)
EXPORT_EARLY_PER_CPU_SYMBOL(_name)
DECLARE_EARLY_PER_CPU(_type, _name)
early_per_cpu_ptr(_name)
early_per_cpu_map(_name, _idx)
early_per_cpu(_name, _cpu)
The DEFINE macro defines the per_cpu variable as well as the early
map and pointer. It also initializes the per_cpu variable and map
elements to "_initvalue". The early_* macros provide access to
the initial map (usually setup during system init) and the early
pointer. This pointer is initialized to point to the early map
but is then NULL'ed when the actual per_cpu areas are setup. After
that the per_cpu variable is the correct access to the variable.
The early_per_cpu() macro is not very efficient but does show how to
access the variable if you have a function that can be called both
"early" and "late". It tests the early ptr to be NULL, and if not
then it's still valid. Otherwise, the per_cpu variable is used
instead:
#define early_per_cpu(_name, _cpu) \
(early_per_cpu_ptr(_name) ? \
early_per_cpu_ptr(_name)[_cpu] : \
per_cpu(_name, _cpu))
A better method is to actually check the pointer manually. In the
case below, numa_set_node can be called both "early" and "late":
void __cpuinit numa_set_node(int cpu, int node)
{
int *cpu_to_node_map = early_per_cpu_ptr(x86_cpu_to_node_map);
if (cpu_to_node_map)
cpu_to_node_map[cpu] = node;
else
per_cpu(x86_cpu_to_node_map, cpu) = node;
}
* Add a flag "arch_provides_topology_pointers" that indicates pointers
to topology cpumask_t maps are available. Otherwise, use the function
returning the cpumask_t value. This is useful if cpumask_t set size
is very large to avoid copying data on to/off of the stack.
* The coverage of CONFIG_DEBUG_PER_CPU_MAPS has been increased while
the non-debug case has been optimized a bit.
* Remove an unreferenced compiler warning in drivers/base/topology.c
* Clean up #ifdef in setup.c
For inclusion into sched-devel/latest tree.
Based on:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
+ sched-devel/latest .../mingo/linux-2.6-sched-devel.git
Signed-off-by: Mike Travis <travis@sgi.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2008-05-12 21:21:12 +02:00
|
|
|
#define EXPORT_EARLY_PER_CPU_SYMBOL(_name) \
|
|
|
|
EXPORT_PER_CPU_SYMBOL(_name)
|
|
|
|
|
|
|
|
#define DECLARE_EARLY_PER_CPU(_type, _name) \
|
|
|
|
DECLARE_PER_CPU(_type, _name); \
|
|
|
|
extern __typeof__(_type) *_name##_early_ptr; \
|
|
|
|
extern __typeof__(_type) _name##_early_map[]
|
|
|
|
|
2012-06-11 12:56:45 +03:00
|
|
|
#define DECLARE_EARLY_PER_CPU_READ_MOSTLY(_type, _name) \
|
|
|
|
DECLARE_PER_CPU_READ_MOSTLY(_type, _name); \
|
|
|
|
extern __typeof__(_type) *_name##_early_ptr; \
|
|
|
|
extern __typeof__(_type) _name##_early_map[]
|
|
|
|
|
x86: cleanup early per cpu variables/accesses v4
* Introduce a new PER_CPU macro called "EARLY_PER_CPU". This is
used by some per_cpu variables that are initialized and accessed
before there are per_cpu areas allocated.
["Early" in respect to per_cpu variables is "earlier than the per_cpu
areas have been setup".]
This patchset adds these new macros:
DEFINE_EARLY_PER_CPU(_type, _name, _initvalue)
EXPORT_EARLY_PER_CPU_SYMBOL(_name)
DECLARE_EARLY_PER_CPU(_type, _name)
early_per_cpu_ptr(_name)
early_per_cpu_map(_name, _idx)
early_per_cpu(_name, _cpu)
The DEFINE macro defines the per_cpu variable as well as the early
map and pointer. It also initializes the per_cpu variable and map
elements to "_initvalue". The early_* macros provide access to
the initial map (usually setup during system init) and the early
pointer. This pointer is initialized to point to the early map
but is then NULL'ed when the actual per_cpu areas are setup. After
that the per_cpu variable is the correct access to the variable.
The early_per_cpu() macro is not very efficient but does show how to
access the variable if you have a function that can be called both
"early" and "late". It tests the early ptr to be NULL, and if not
then it's still valid. Otherwise, the per_cpu variable is used
instead:
#define early_per_cpu(_name, _cpu) \
(early_per_cpu_ptr(_name) ? \
early_per_cpu_ptr(_name)[_cpu] : \
per_cpu(_name, _cpu))
A better method is to actually check the pointer manually. In the
case below, numa_set_node can be called both "early" and "late":
void __cpuinit numa_set_node(int cpu, int node)
{
int *cpu_to_node_map = early_per_cpu_ptr(x86_cpu_to_node_map);
if (cpu_to_node_map)
cpu_to_node_map[cpu] = node;
else
per_cpu(x86_cpu_to_node_map, cpu) = node;
}
* Add a flag "arch_provides_topology_pointers" that indicates pointers
to topology cpumask_t maps are available. Otherwise, use the function
returning the cpumask_t value. This is useful if cpumask_t set size
is very large to avoid copying data on to/off of the stack.
* The coverage of CONFIG_DEBUG_PER_CPU_MAPS has been increased while
the non-debug case has been optimized a bit.
* Remove an unreferenced compiler warning in drivers/base/topology.c
* Clean up #ifdef in setup.c
For inclusion into sched-devel/latest tree.
Based on:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
+ sched-devel/latest .../mingo/linux-2.6-sched-devel.git
Signed-off-by: Mike Travis <travis@sgi.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2008-05-12 21:21:12 +02:00
|
|
|
#define early_per_cpu_ptr(_name) (_name##_early_ptr)
|
|
|
|
#define early_per_cpu_map(_name, _idx) (_name##_early_map[_idx])
|
|
|
|
#define early_per_cpu(_name, _cpu) \
|
2009-01-13 20:41:34 +09:00
|
|
|
*(early_per_cpu_ptr(_name) ? \
|
|
|
|
&early_per_cpu_ptr(_name)[_cpu] : \
|
|
|
|
&per_cpu(_name, _cpu))
|
x86: cleanup early per cpu variables/accesses v4
* Introduce a new PER_CPU macro called "EARLY_PER_CPU". This is
used by some per_cpu variables that are initialized and accessed
before there are per_cpu areas allocated.
["Early" in respect to per_cpu variables is "earlier than the per_cpu
areas have been setup".]
This patchset adds these new macros:
DEFINE_EARLY_PER_CPU(_type, _name, _initvalue)
EXPORT_EARLY_PER_CPU_SYMBOL(_name)
DECLARE_EARLY_PER_CPU(_type, _name)
early_per_cpu_ptr(_name)
early_per_cpu_map(_name, _idx)
early_per_cpu(_name, _cpu)
The DEFINE macro defines the per_cpu variable as well as the early
map and pointer. It also initializes the per_cpu variable and map
elements to "_initvalue". The early_* macros provide access to
the initial map (usually setup during system init) and the early
pointer. This pointer is initialized to point to the early map
but is then NULL'ed when the actual per_cpu areas are setup. After
that the per_cpu variable is the correct access to the variable.
The early_per_cpu() macro is not very efficient but does show how to
access the variable if you have a function that can be called both
"early" and "late". It tests the early ptr to be NULL, and if not
then it's still valid. Otherwise, the per_cpu variable is used
instead:
#define early_per_cpu(_name, _cpu) \
(early_per_cpu_ptr(_name) ? \
early_per_cpu_ptr(_name)[_cpu] : \
per_cpu(_name, _cpu))
A better method is to actually check the pointer manually. In the
case below, numa_set_node can be called both "early" and "late":
void __cpuinit numa_set_node(int cpu, int node)
{
int *cpu_to_node_map = early_per_cpu_ptr(x86_cpu_to_node_map);
if (cpu_to_node_map)
cpu_to_node_map[cpu] = node;
else
per_cpu(x86_cpu_to_node_map, cpu) = node;
}
* Add a flag "arch_provides_topology_pointers" that indicates pointers
to topology cpumask_t maps are available. Otherwise, use the function
returning the cpumask_t value. This is useful if cpumask_t set size
is very large to avoid copying data on to/off of the stack.
* The coverage of CONFIG_DEBUG_PER_CPU_MAPS has been increased while
the non-debug case has been optimized a bit.
* Remove an unreferenced compiler warning in drivers/base/topology.c
* Clean up #ifdef in setup.c
For inclusion into sched-devel/latest tree.
Based on:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
+ sched-devel/latest .../mingo/linux-2.6-sched-devel.git
Signed-off-by: Mike Travis <travis@sgi.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2008-05-12 21:21:12 +02:00
|
|
|
|
|
|
|
#else /* !CONFIG_SMP */
|
|
|
|
#define DEFINE_EARLY_PER_CPU(_type, _name, _initvalue) \
|
|
|
|
DEFINE_PER_CPU(_type, _name) = _initvalue
|
|
|
|
|
2012-06-11 12:56:45 +03:00
|
|
|
#define DEFINE_EARLY_PER_CPU_READ_MOSTLY(_type, _name, _initvalue) \
|
|
|
|
DEFINE_PER_CPU_READ_MOSTLY(_type, _name) = _initvalue
|
|
|
|
|
x86: cleanup early per cpu variables/accesses v4
* Introduce a new PER_CPU macro called "EARLY_PER_CPU". This is
used by some per_cpu variables that are initialized and accessed
before there are per_cpu areas allocated.
["Early" in respect to per_cpu variables is "earlier than the per_cpu
areas have been setup".]
This patchset adds these new macros:
DEFINE_EARLY_PER_CPU(_type, _name, _initvalue)
EXPORT_EARLY_PER_CPU_SYMBOL(_name)
DECLARE_EARLY_PER_CPU(_type, _name)
early_per_cpu_ptr(_name)
early_per_cpu_map(_name, _idx)
early_per_cpu(_name, _cpu)
The DEFINE macro defines the per_cpu variable as well as the early
map and pointer. It also initializes the per_cpu variable and map
elements to "_initvalue". The early_* macros provide access to
the initial map (usually setup during system init) and the early
pointer. This pointer is initialized to point to the early map
but is then NULL'ed when the actual per_cpu areas are setup. After
that the per_cpu variable is the correct access to the variable.
The early_per_cpu() macro is not very efficient but does show how to
access the variable if you have a function that can be called both
"early" and "late". It tests the early ptr to be NULL, and if not
then it's still valid. Otherwise, the per_cpu variable is used
instead:
#define early_per_cpu(_name, _cpu) \
(early_per_cpu_ptr(_name) ? \
early_per_cpu_ptr(_name)[_cpu] : \
per_cpu(_name, _cpu))
A better method is to actually check the pointer manually. In the
case below, numa_set_node can be called both "early" and "late":
void __cpuinit numa_set_node(int cpu, int node)
{
int *cpu_to_node_map = early_per_cpu_ptr(x86_cpu_to_node_map);
if (cpu_to_node_map)
cpu_to_node_map[cpu] = node;
else
per_cpu(x86_cpu_to_node_map, cpu) = node;
}
* Add a flag "arch_provides_topology_pointers" that indicates pointers
to topology cpumask_t maps are available. Otherwise, use the function
returning the cpumask_t value. This is useful if cpumask_t set size
is very large to avoid copying data on to/off of the stack.
* The coverage of CONFIG_DEBUG_PER_CPU_MAPS has been increased while
the non-debug case has been optimized a bit.
* Remove an unreferenced compiler warning in drivers/base/topology.c
* Clean up #ifdef in setup.c
For inclusion into sched-devel/latest tree.
Based on:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
+ sched-devel/latest .../mingo/linux-2.6-sched-devel.git
Signed-off-by: Mike Travis <travis@sgi.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2008-05-12 21:21:12 +02:00
|
|
|
#define EXPORT_EARLY_PER_CPU_SYMBOL(_name) \
|
|
|
|
EXPORT_PER_CPU_SYMBOL(_name)
|
|
|
|
|
|
|
|
#define DECLARE_EARLY_PER_CPU(_type, _name) \
|
|
|
|
DECLARE_PER_CPU(_type, _name)
|
|
|
|
|
2012-06-11 12:56:45 +03:00
|
|
|
#define DECLARE_EARLY_PER_CPU_READ_MOSTLY(_type, _name) \
|
|
|
|
DECLARE_PER_CPU_READ_MOSTLY(_type, _name)
|
|
|
|
|
x86: cleanup early per cpu variables/accesses v4
* Introduce a new PER_CPU macro called "EARLY_PER_CPU". This is
used by some per_cpu variables that are initialized and accessed
before there are per_cpu areas allocated.
["Early" in respect to per_cpu variables is "earlier than the per_cpu
areas have been setup".]
This patchset adds these new macros:
DEFINE_EARLY_PER_CPU(_type, _name, _initvalue)
EXPORT_EARLY_PER_CPU_SYMBOL(_name)
DECLARE_EARLY_PER_CPU(_type, _name)
early_per_cpu_ptr(_name)
early_per_cpu_map(_name, _idx)
early_per_cpu(_name, _cpu)
The DEFINE macro defines the per_cpu variable as well as the early
map and pointer. It also initializes the per_cpu variable and map
elements to "_initvalue". The early_* macros provide access to
the initial map (usually setup during system init) and the early
pointer. This pointer is initialized to point to the early map
but is then NULL'ed when the actual per_cpu areas are setup. After
that the per_cpu variable is the correct access to the variable.
The early_per_cpu() macro is not very efficient but does show how to
access the variable if you have a function that can be called both
"early" and "late". It tests the early ptr to be NULL, and if not
then it's still valid. Otherwise, the per_cpu variable is used
instead:
#define early_per_cpu(_name, _cpu) \
(early_per_cpu_ptr(_name) ? \
early_per_cpu_ptr(_name)[_cpu] : \
per_cpu(_name, _cpu))
A better method is to actually check the pointer manually. In the
case below, numa_set_node can be called both "early" and "late":
void __cpuinit numa_set_node(int cpu, int node)
{
int *cpu_to_node_map = early_per_cpu_ptr(x86_cpu_to_node_map);
if (cpu_to_node_map)
cpu_to_node_map[cpu] = node;
else
per_cpu(x86_cpu_to_node_map, cpu) = node;
}
* Add a flag "arch_provides_topology_pointers" that indicates pointers
to topology cpumask_t maps are available. Otherwise, use the function
returning the cpumask_t value. This is useful if cpumask_t set size
is very large to avoid copying data on to/off of the stack.
* The coverage of CONFIG_DEBUG_PER_CPU_MAPS has been increased while
the non-debug case has been optimized a bit.
* Remove an unreferenced compiler warning in drivers/base/topology.c
* Clean up #ifdef in setup.c
For inclusion into sched-devel/latest tree.
Based on:
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
+ sched-devel/latest .../mingo/linux-2.6-sched-devel.git
Signed-off-by: Mike Travis <travis@sgi.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2008-05-12 21:21:12 +02:00
|
|
|
#define early_per_cpu(_name, _cpu) per_cpu(_name, _cpu)
|
|
|
|
#define early_per_cpu_ptr(_name) NULL
|
|
|
|
/* no early_per_cpu_map() */
|
|
|
|
|
|
|
|
#endif /* !CONFIG_SMP */
|
|
|
|
|
2008-10-22 22:26:29 -07:00
|
|
|
#endif /* _ASM_X86_PERCPU_H */
|