OpenCloudOS-Kernel/include
Finn Thain bc13958889 sched/core: Optimize in_task() and in_interrupt() a bit
[ Upstream commit 87c3a5893e865739ce78aa7192d36011022e0af7 ]

Except on x86, preempt_count is always accessed with READ_ONCE().
Repeated invocations in macros like irq_count() produce repeated loads.
These redundant instructions appear in various fast paths. In the one
shown below, for example, irq_count() is evaluated during kernel entry
if !tick_nohz_full_cpu(smp_processor_id()).

0001ed0a <irq_enter_rcu>:
   1ed0a:       4e56 0000       linkw %fp,#0
   1ed0e:       200f            movel %sp,%d0
   1ed10:       0280 ffff e000  andil #-8192,%d0
   1ed16:       2040            moveal %d0,%a0
   1ed18:       2028 0008       movel %a0@(8),%d0
   1ed1c:       0680 0001 0000  addil #65536,%d0
   1ed22:       2140 0008       movel %d0,%a0@(8)
   1ed26:       082a 0001 000f  btst #1,%a2@(15)
   1ed2c:       670c            beqs 1ed3a <irq_enter_rcu+0x30>
   1ed2e:       2028 0008       movel %a0@(8),%d0
   1ed32:       2028 0008       movel %a0@(8),%d0
   1ed36:       2028 0008       movel %a0@(8),%d0
   1ed3a:       4e5e            unlk %fp
   1ed3c:       4e75            rts

This patch doesn't prevent the pointless btst and beqs instructions
above, but it does eliminate 2 of the 3 pointless move instructions
here and elsewhere.

On x86, preempt_count is per-cpu data and the problem does not arise
presumably because the compiler is free to optimize more effectively.

This patch was tested on m68k and x86. I was expecting no changes
to object code for x86 and mostly that's what I saw. However, there
were a few places where code generation was perturbed for some reason.

The performance issue addressed here is minor on uniprocessor m68k. I
got a 0.01% improvement from this patch for a simple "find /sys -false"
benchmark. For architectures and workloads susceptible to cache line bounce
the improvement is expected to be larger. The only SMP architecture I have
is x86, and as x86 unaffected I have not done any further measurements.

Fixes: 15115830c8 ("preempt: Cleanup the macro maze a bit")
Signed-off-by: Finn Thain <fthain@linux-m68k.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/0a403120a682a525e6db2d81d1a3ffcc137c3742.1694756831.git.fthain@linux-m68k.org
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-11-28 17:19:48 +00:00
..
acpi ACPI: APEI: Fix AER info corruption when error status data has multiple sections 2023-11-28 17:19:37 +00:00
asm-generic hyperv-fixes for v6.6-rc6 2023-10-10 11:01:21 -07:00
clocksource
crypto This update includes the following changes: 2023-08-29 11:23:29 -07:00
drm drm: bridge: samsung-dsim: Fix waiting for empty cmd transfer FIFO on older Exynos 2023-11-20 11:59:08 +01:00
dt-bindings IOMMU Updates for Linux v6.6 2023-09-01 16:54:25 -07:00
keys
kunit - An extensive rework of kexec and crash Kconfig from Eric DeVolder 2023-08-29 14:53:51 -07:00
kvm KVM: arm64: timers: Correctly handle TGE flip with CNTPOFF_EL2 2023-10-12 16:55:21 +01:00
linux sched/core: Optimize in_task() and in_interrupt() a bit 2023-11-28 17:19:48 +00:00
math-emu
media media: ipu-bridge: increase sensor_name size 2023-11-28 17:19:46 +00:00
memory
misc
net net: annotate data-races around sk->sk_dst_pending_confirm 2023-11-28 17:19:38 +00:00
pcmcia
ras
rdma
rv rv: Set variable 'da_mon_##name' to static 2023-09-01 21:00:00 -04:00
scsi scsi: sd: Introduce manage_shutdown device flag 2023-10-27 10:00:19 +09:00
soc firmware: tegra: Add suspend hook and reset BPMP IPC early on resume 2023-11-20 11:59:16 +01:00
sound ASoC: SOF: Pass PCI SSID to machine driver 2023-11-28 17:19:42 +00:00
target
trace neighbor: tracing: Move pin6 inside CONFIG_IPV6=y section 2023-10-18 11:16:43 +01:00
uapi vsock: read from socket's error queue 2023-11-28 17:19:38 +00:00
ufs Merge branch 'fixes' into misc 2023-09-02 08:25:19 +01:00
vdso
video fbdev: uvesafb: Remove uvesafb_exec() prototype from include/video/uvesafb.h 2023-10-16 23:19:34 +02:00
xen arm/xen: remove lazy mode related definitions 2023-09-19 07:04:49 +02:00