Skip to content

RFC x86/percpu: Use segment qualifiers

Nadav Amit lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest7 patches 5 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/7compiler: Report x86 segment supportinclude/linux/compiler-gcc.h+4 -00 replies
2/7x86/percpu: Use compiler segment prefix qualifierarch/x86/include/asm/percpu.h+102 -510 replies
3/7x86/percpu: Use C for percpu accesses when possiblearch/x86/include/asm/percpu.h arch/x86/include/asm/preempt.h+107 -112 replies
4/7x86: Fix possible caching of current_taskarch/x86/include/asm/fpu/internal.h arch/x86/include/asm/resctrl_sched.h arch/x86/kernel/cpu/resctrl/rdtgroup.c +2 more+17 -160 replies
5/7percpu: Assume preemption is disabled on per_cpu_ptr()include/asm-generic/percpu.h include/linux/percpu-defs.h+44 -10 replies
6/7x86/percpu: Optimized arch_raw_cpu_ptr()arch/x86/include/asm/percpu.h+23 -20 replies
7/7x86/current: Aggressive caching of currentarch/x86/include/asm/current.h arch/x86/kernel/cpu/Makefile arch/x86/kernel/cpu/common.c +2 more+49 -72 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC 0/7] x86/percpu: Use segment qualifiers

GCC 6+ supports segment qualifiers. Using them allows to implement several optimizations:

1. Avoid unnecessary instructions when an operation is carried on read/written per-cpu value, and instead allow the compiler to set instructions that access per-cpu value directly.

2. Make this_cpu_ptr() more efficient and allow its value to be cached, since preemption must be disabled when this_cpu_ptr() is used.

3. Provide better alternative for this_cpu_read_stable() that caches values more efficiently using alias attribute to const variable.

4. Allow the compiler to perform other optimizations (e.g. CSE).

5. Use rip-relative addressing in per_cpu_read_stable(), which make it PIE-ready.

"size" and Peter's compare do not seem to show the impact on code size reduction correctly. Summing the code size according to nm on defconfig shows a minor reduction from 11349763 to 11339840 (0.09%).

Nadav Amit (7):
compiler: Report x86 segment support x86/percpu: Use compiler segment prefix qualifier x86/percpu: Use C for percpu accesses when possible
x86: Fix possible caching of current_task
percpu: Assume preemption is disabled on per_cpu_ptr() x86/percpu: Optimized arch_raw_cpu_ptr() x86/current: Aggressive caching of current

 arch/x86/include/asm/current.h         |  30 +++
 arch/x86/include/asm/fpu/internal.h    |   7 +-
 arch/x86/include/asm/percpu.h          | 293 +++++++++++++++++++------
 arch/x86/include/asm/preempt.h         |   3 +-
 arch/x86/include/asm/resctrl_sched.h   |  14 +-
 arch/x86/kernel/cpu/Makefile           |   1 +
 arch/x86/kernel/cpu/common.c           |   7 +-
 arch/x86/kernel/cpu/current.c          |  16 ++
 arch/x86/kernel/cpu/resctrl/rdtgroup.c |   4 +-
 arch/x86/kernel/process_32.c           |   4 +-
 arch/x86/kernel/process_64.c           |   4 +-
 include/asm-generic/percpu.h           |  12 +
 include/linux/compiler-gcc.h           |   4 +
 include/linux/compiler.h               |   2 +-
 include/linux/percpu-defs.h            |  33 ++-
 15 files changed, 346 insertions(+), 88 deletions(-)
 create mode 100644 arch/x86/kernel/cpu/current.c
Signature · 1 line
2.17.1