Skip to content

Commit fc8d296

Browse files
Peng Wangcasparant
authored andcommitted
alinux: arm64: adjust tk_core memory layout
to #29722367 On some specific hardware with 128 bytes LLC cacheline, tk_core may cause false sharing problem. We can align it to 128 bytes so that it won't be affected by other global variables. This change will make a bit waste on cache utilization but get good number of performance improvement. So for both 64 and 128 bytes aligned LLC cacheline, we adjust tk_core memory layout to avoid potential cacheline contention. Signed-off-by: Peng Wang <rocking@linux.alibaba.com> Acked-by: Shanpei Chen <shanpeic@linux.alibaba.com> Reviewed-by: Shile Zhang <shile.zhang@linux.alibaba.com>
1 parent e7ac16c commit fc8d296

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

arch/arm64/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,16 @@ config ARCH_WANT_HUGE_PMD_SHARE
865865
config ARCH_HAS_CACHE_LINE_SIZE
866866
def_bool y
867867

868+
config ARCH_LLC_128_WORKAROUND
869+
bool "Workaround for 128 bytes LLC cacheline"
870+
depends on ARM64
871+
default n
872+
help
873+
LLC cacheline size may be up to 128 bytes, and this
874+
is useful if you want to do workaround on such
875+
case. It can be used to align memory address to get
876+
good cache utilization et al.
877+
868878
config SECCOMP
869879
bool "Enable seccomp to safely compute untrusted bytecode"
870880
---help---

configs/config-4.19.y-aarch64

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ CONFIG_HW_PERF_EVENTS=y
435435
CONFIG_SYS_SUPPORTS_HUGETLBFS=y
436436
CONFIG_ARCH_WANT_HUGE_PMD_SHARE=y
437437
CONFIG_ARCH_HAS_CACHE_LINE_SIZE=y
438+
CONFIG_ARCH_LLC_128_WORKAROUND=y
438439
CONFIG_SECCOMP=y
439440
CONFIG_PARAVIRT=y
440441
CONFIG_PARAVIRT_TIME_ACCOUNTING=y

configs/config-4.19.y-aarch64-debug

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,7 @@ CONFIG_HW_PERF_EVENTS=y
436436
CONFIG_SYS_SUPPORTS_HUGETLBFS=y
437437
CONFIG_ARCH_WANT_HUGE_PMD_SHARE=y
438438
CONFIG_ARCH_HAS_CACHE_LINE_SIZE=y
439+
CONFIG_ARCH_LLC_128_WORKAROUND=y
439440
CONFIG_SECCOMP=y
440441
CONFIG_PARAVIRT=y
441442
CONFIG_PARAVIRT_TIME_ACCOUNTING=y

kernel/time/timekeeping.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,24 @@ enum timekeeping_adv_mode {
4848
* cache line.
4949
*/
5050
static struct {
51+
#ifdef CONFIG_ARCH_LLC_128_WORKAROUND
52+
/* Start seq on the middle of 128 bytes aligned address to
53+
* keep some members of tk_core in the same 64 bytes for
54+
* principle of locality while pushing others to another LLC
55+
* cacheline to avoid false sharing.
56+
*/
57+
u8 padding1[64];
58+
seqcount_t seq;
59+
/* Push some timekeeper memebers to another LLC cacheline */
60+
u8 padding2[16];
61+
struct timekeeper timekeeper;
62+
/* For 128 bytes LLC cacheline */
63+
} tk_core __aligned(128) = {
64+
#else
5165
seqcount_t seq;
5266
struct timekeeper timekeeper;
5367
} tk_core ____cacheline_aligned = {
68+
#endif
5469
.seq = SEQCNT_ZERO(tk_core.seq),
5570
};
5671

0 commit comments

Comments
 (0)