ARM: Add support for Hisilicon Kunpeng L3 cache controller
Subsystems (5)
v5 cover ARM: Add support for Hisilicon Kunpeng L3 cache controller
v4 --> v5:
1. Add SoC macro ARCH_KUNPENG50X, and the Kunpeng L3 cache controller only enabled on that platform.
2. Require the compatible string of the Kunpeng L3 cache controller must have a relevant name on a specific SoC. For example:
compatible = "hisilicon,kunpeng509-l3cache", "hisilicon,kunpeng-l3cache";
v3 --> v4:
Rename the compatible string from "hisilicon,l3cache" to "hisilicon,kunpeng-l3cache". Then adjust the file name, configuration option name, and description accordingly.
v2 --> v3:
Add Hisilicon L3 cache controller driver and its document. That's: patch 2-3.
v1 --> v2:
Discard the middle-tier functions and do silent narrowing cast in the outcache hook functions. For example:
-static void l2c220_inv_range(unsigned long start, unsigned long end) +static void l2c220_inv_range(phys_addr_t pa_start, phys_addr_t pa_end)
{
+ unsigned long start = pa_start;
+ unsigned long end = pa_end;
v1:
Do cast phys_addr_t to unsigned long by adding a middle-tier function. For example:
-static void l2c220_inv_range(unsigned long start, unsigned long end) +static void __l2c220_inv_range(unsigned long start, unsigned long end)
{
...
}
+static void l2c220_inv_range(phys_addr_t start, phys_addr_t end) +{
+ __l2c220_inv_range(start, end);
+}
Zhen Lei (4):
ARM: LPAE: Use phys_addr_t instead of unsigned long in outercache
hooks
ARM: hisi: add support for Kunpeng50x SoC
dt-bindings: arm: hisilicon: Add binding for Kunpeng L3 cache
controller
ARM: Add support for Hisilicon Kunpeng L3 cache controller
.../arm/hisilicon/kunpeng-l3cache.yaml | 40 +++++ arch/arm/include/asm/outercache.h | 6 +- arch/arm/mach-hisi/Kconfig | 8 + arch/arm/mm/Kconfig | 10 ++ arch/arm/mm/Makefile | 1 + arch/arm/mm/cache-feroceon-l2.c | 15 +- arch/arm/mm/cache-kunpeng-l3.c | 153 ++++++++++++++++++ arch/arm/mm/cache-kunpeng-l3.h | 30 ++++ arch/arm/mm/cache-l2x0.c | 50 ++++-- arch/arm/mm/cache-tauros2.c | 15 +- arch/arm/mm/cache-uniphier.c | 6 +- arch/arm/mm/cache-xsc3l2.c | 12 +- 12 files changed, 317 insertions(+), 29 deletions(-) create mode 100644 Documentation/devicetree/bindings/arm/hisilicon/kunpeng-l3cache.yaml create mode 100644 arch/arm/mm/cache-kunpeng-l3.c create mode 100644 arch/arm/mm/cache-kunpeng-l3.h
Signature · 1 line
2.26.0.106.g9fadedd
PATCH v5 1/4 ARM: LPAE: Use phys_addr_t instead of unsigned long in outercache hooks
The outercache of some Hisilicon SOCs support physical addresses wider than 32-bits. The unsigned long datatype is not sufficient for mapping physical addresses >= 4GB. The commit ad6b9c9d78b9 ("ARM: 6671/1: LPAE:
use phys_addr_t instead of unsigned long in outercache functions") has already modified the outercache functions. But the parameters of the outercache hooks are not changed. This patch use phys_addr_t instead of unsigned long in outercache hooks: inv_range, clean_range, flush_range.
To ensure the outercache that does not support LPAE works properly, do cast phys_addr_t to unsigned long by adding a group of temporary variables. For example:
-static void l2c220_inv_range(unsigned long start, unsigned long end) +static void l2c220_inv_range(phys_addr_t pa_start, phys_addr_t pa_end)
{
+ unsigned long start = pa_start;
+ unsigned long end = pa_end;
Note that the outercache functions have been doing this cast before this patch. So now, the cast is just moved into the outercache hook functions.
No functional change.
--- arch/arm/include/asm/outercache.h | 6 ++-- arch/arm/mm/cache-feroceon-l2.c | 15 ++++++++-- arch/arm/mm/cache-l2x0.c | 50 ++++++++++++++++++++++--------- arch/arm/mm/cache-tauros2.c | 15 ++++++++-- arch/arm/mm/cache-uniphier.c | 6 ++-- arch/arm/mm/cache-xsc3l2.c | 12 ++++++-- 6 files changed, 75 insertions(+), 29 deletions(-)
arch/arm/include/asm/outercache.h +3 -3
@@ -14,9 +14,9 @@struct l2x0_regs ;struct outer_cache_fns { -void (*inv_range)(unsigned long ,unsigned long ); -void (*clean_range)(unsigned long ,unsigned long ); -void (*flush_range)(unsigned long ,unsigned long ); +void (*inv_range)(phys_addr_t ,phys_addr_t ); +void (*clean_range)(phys_addr_t ,phys_addr_t ); +void (*flush_range)(phys_addr_t ,phys_addr_t );void (*flush_all)(void );void (*disable)(void );#ifdef CONFIG_OUTER_CACHE_SYNC
arch/arm/mm/cache-feroceon-l2.c +12 -3
@@ -168,8 +168,11 @@ static unsigned long calc_range_end(unsigned long start, unsigned long end)return range_end; } -static void feroceon_l2_inv_range (unsigned long start,unsigned long end) +static void feroceon_l2_inv_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end; +/* * Clean and invalidate partial first cache line. */
@@ -198,8 +201,11 @@ static void feroceon_l2_inv_range(unsigned long start, unsigned long end)dsb (); } -static void feroceon_l2_clean_range (unsigned long start,unsigned long end) +static void feroceon_l2_clean_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end; +/* * If L2 is forced to WT, the L2 will always be clean and we * don't need to do anything here.
@@ -217,8 +223,11 @@ static void feroceon_l2_clean_range(unsigned long start, unsigned long end)dsb (); } -static void feroceon_l2_flush_range (unsigned long start,unsigned long end) +static void feroceon_l2_flush_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end; + start &= ~(CACHE_LINE_SIZE -1 ); end = (end +CACHE_LINE_SIZE -1 ) & ~(CACHE_LINE_SIZE -1 );while (start != end) {
arch/arm/mm/cache-l2x0.c +36 -14
143 lines not on this page · raw message
arch/arm/mm/cache-tauros2.c +12 -3
@@ -66,8 +66,11 @@ static inline void tauros2_inv_pa(unsigned long addr)*/ #define CACHE_LINE_SIZE 32 -static void tauros2_inv_range (unsigned long start,unsigned long end) +static void tauros2_inv_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end; +/* * Clean and invalidate partial first cache line. */
@@ -95,8 +98,11 @@ static void tauros2_inv_range(unsigned long start, unsigned long end)dsb (); } -static void tauros2_clean_range (unsigned long start,unsigned long end) +static void tauros2_clean_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end; + start &= ~(CACHE_LINE_SIZE -1 );while (start < end) {tauros2_clean_pa (start);
@@ -106,8 +112,11 @@ static void tauros2_clean_range(unsigned long start, unsigned long end)dsb (); } -static void tauros2_flush_range (unsigned long start,unsigned long end) +static void tauros2_flush_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end; + start &= ~(CACHE_LINE_SIZE -1 );while (start < end) {tauros2_clean_inv_pa (start);
arch/arm/mm/cache-uniphier.c +3 -3
@@ -250,17 +250,17 @@ static void uniphier_cache_maint_all(u32 operation)__uniphier_cache_maint_all (data, operation); } -static void uniphier_cache_inv_range (unsigned long start,unsigned long end) +static void uniphier_cache_inv_range (phys_addr_t start,phys_addr_t end) {uniphier_cache_maint_range (start, end,UNIPHIER_SSCOQM_CM_INV ); } -static void uniphier_cache_clean_range (unsigned long start,unsigned long end) +static void uniphier_cache_clean_range (phys_addr_t start,phys_addr_t end) {uniphier_cache_maint_range (start, end,UNIPHIER_SSCOQM_CM_CLEAN ); } -static void uniphier_cache_flush_range (unsigned long start,unsigned long end) +static void uniphier_cache_flush_range (phys_addr_t start,phys_addr_t end) {uniphier_cache_maint_range (start, end,UNIPHIER_SSCOQM_CM_FLUSH ); }
arch/arm/mm/cache-xsc3l2.c +9 -3
@@ -83,8 +83,10 @@ static inline unsigned long l2_map_va(unsigned long pa, unsigned long prev_va)#endif } -static void xsc3_l2_inv_range (unsigned long start,unsigned long end) +static void xsc3_l2_inv_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end;unsigned long vaddr;if (start ==0 && end ==-1ul ) {
@@ -127,8 +129,10 @@ static void xsc3_l2_inv_range(unsigned long start, unsigned long end)dsb (); } -static void xsc3_l2_clean_range (unsigned long start,unsigned long end) +static void xsc3_l2_clean_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end;unsigned long vaddr; vaddr =-1 ;/* to force the first mapping */
@@ -165,8 +169,10 @@ static inline void xsc3_l2_flush_all(void)dsb (); } -static void xsc3_l2_flush_range (unsigned long start,unsigned long end) +static void xsc3_l2_flush_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end;unsigned long vaddr;if (start ==0 && end ==-1ul ) {
Signature · 1 line
2.26.0.106.g9fadedd
Re: [PATCH v5 1/4] ARM: LPAE: Use phys_addr_t instead of unsigned long in outercache hooks
Quoted 18 lines · Zhen Lei
The outercache of some Hisilicon SOCs support physical addresses wider than 32-bits. The unsigned long datatype is not sufficient for mapping physical addresses >= 4GB. The commit
ad6b9c9d78b9("ARM: 6671/1: LPAE:
usephys_addr_tinstead of unsigned long in outercache functions") has already modified the outercache functions. But the parameters of the outercache hooks are not changed. This patch usephys_addr_tinstead of unsigned long in outercache hooks:inv_range,clean_range,flush_range.To ensure the outercache that does not support LPAE works properly, do cast
phys_addr_tto unsigned long by adding a group of temporary variables. For example:arch/arm/mm/cache-l2x0.c +3
-1-static void l2c220_inv_range (unsigned long start,unsigned long end) +static void l2c220_inv_range (phys_addr_t pa_start,phys_addr_t pa_end) { +unsigned long start = pa_start; +unsigned long end = pa_end;
Quoted 6 lines
Note that the outercache functions have been doing this cast before this patch. So now, the cast is just moved into the outercache hook functions.
No functional change.
Signed-off-by Zhen Lei <[email protected]>
PATCH v5 2/4 ARM: hisi: add support for Kunpeng50x SoC
In reply to Zhen LeiEnable support for the Hisilicon Kunpeng506 and Kunpeng509 SoC.
--- arch/arm/mach-hisi/Kconfig | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/arm/mach-hisi/Kconfig +8 -0
@@ -55,6 +55,14 @@ config ARCH_HIX5HD2 help Support for Hisilicon HIX5HD2 SoC family +config ARCH_KUNPENG50X + bool "Hisilicon Kunpeng50x family" + depends on ARCH_MULTI_V7 + select ARCH_FLATMEM_ENABLE + select ARCH_HAS_HOLES_MEMORYMODEL if SPARSEMEM + help + Support for Hisilicon Kunpeng506 and Kunpeng509 SoC family + config ARCH_SD5203 bool "Hisilicon SD5203 family" depends on ARCH_MULTI_V5
Signature · 1 line
2.26.0.106.g9fadedd
Re: [PATCH v5 2/4] ARM: hisi: add support for Kunpeng50x SoC
Quoted 13 lines · Zhen Lei
Enable support for the Hisilicon Kunpeng506 and Kunpeng509 SoC.
Signed-off-by Zhen Lei <[email protected]>--- arch/arm/mach-hisi/Kconfig | 8 ++++++++ 1 file changed, 8 insertions(+)arch/arm/mach-hisi/Kconfig +0
-0
arch/arm/mach-hisi/Kconfig config ARCH_HIX5HD2 · line 62
Quoted 8 lines
arch/arm/mach-hisi/Kconfig +5
-0@@ -55,6 +55,14 @@ config ARCH_HIX5HD2 help Support for Hisilicon HIX5HD2 SoC family +config ARCH_KUNPENG50X + bool "Hisilicon Kunpeng50x family" + depends on ARCH_MULTI_V7 + select ARCH_FLATMEM_ENABLE + select ARCH_HAS_HOLES_MEMORYMODEL if SPARSEMEM
I think the two 'select' statements are both wrong, though for different reasons:
- ARCH_FLATMEM_ENABLE is already selected by ARCH_MULTIPLATFORM, and is something that should not be platform specific
- ARCH_HAS_HOLES_MEMORYMODEL was removed in v5.11, and should also not be selected by a platform.
Otherwise, this seems fine.
Arnd
Re: [PATCH v5 2/4] ARM: hisi: add support for Kunpeng50x SoC
Quoted 26 lines · Arnd Bergmann
Quoted 13 lines · Zhen Lei
Enable support for the Hisilicon Kunpeng506 and Kunpeng509 SoC.
Signed-off-by Zhen Lei <[email protected]>--- arch/arm/mach-hisi/Kconfig | 8 ++++++++ 1 file changed, 8 insertions(+)arch/arm/mach-hisi/Kconfig +0
-0arch/arm/mach-hisi/Kconfig config ARCH_HIX5HD2 · line 62
Quoted 8 lines
arch/arm/mach-hisi/Kconfig +5
-0@@ -55,6 +55,14 @@ config ARCH_HIX5HD2 help Support for Hisilicon HIX5HD2 SoC family +config ARCH_KUNPENG50X + bool "Hisilicon Kunpeng50x family" + depends on ARCH_MULTI_V7 + select ARCH_FLATMEM_ENABLE + select ARCH_HAS_HOLES_MEMORYMODEL if SPARSEMEMI think the two 'select' statements are both wrong, though for different reasons:
Quoted 2 lines
-
ARCH_FLATMEM_ENABLEis already selected byARCH_MULTIPLATFORM, and is something that should not be platform specific
Right. I will drop it.
Quoted 3 lines
-
ARCH_HAS_HOLES_MEMORYMODELwas removed in v5.11, and should also not be selected by a platform.
Thanks. I will drop it.
Quoted 7 lines
Otherwise, this seems fine.
Arnd
.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 3/4 dt-bindings: arm: hisilicon: Add binding for Kunpeng L3 cache controller
In reply to Zhen LeiAdd devicetree binding for Hisilicon Kunpeng L3 cache controller.
--- .../arm/hisilicon/kunpeng-l3cache.yaml | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/hisilicon/kunpeng-l3cache.yaml
Documentation/devicetree/bindings/arm/hisilicon/kunpeng-l3cache.yaml new file +40 -0
@@ -0,0 +1,40 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/arm/hisilicon/kunpeng-l3cache.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Hisilicon Kunpeng L3 cache controller + +maintainers: + - Wei Xu <[email protected]> + +description: | + The Hisilicon Kunpeng L3 outer cache controller supports a maximum of 36-bit + physical addresses. The data cached in the L3 outer cache can be operated + based on the physical address range or the entire cache. + +properties: + compatible: + items: + - enum: + - hisilicon,kunpeng506-l3cache + - hisilicon,kunpeng509-l3cache + - const: hisilicon,kunpeng-l3cache + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + l3cache@f302b000 { + compatible = "hisilicon,kunpeng509-l3cache", "hisilicon,kunpeng-l3cache"; + reg = <0xf302b000 0x1000>; + }; +...
Signature · 1 line
2.26.0.106.g9fadedd
Re: [PATCH v5 3/4] dt-bindings: arm: hisilicon: Add binding for Kunpeng L3 cache controller
Quoted 6 lines · Zhen Lei
Add devicetree binding for Hisilicon Kunpeng L3 cache controller.
Signed-off-by Zhen Lei <[email protected]>--- .../arm/hisilicon/kunpeng-l3cache.yaml | 40 +++++++++++++++++++
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v5 4/4 ARM: Add support for Hisilicon Kunpeng L3 cache controller
In reply to Zhen LeiAdd support for the Hisilicon Kunpeng L3 cache controller as used with Kunpeng506 and Kunpeng509 SoCs.
These Hisilicon SoCs support LPAE, so the physical addresses is wider than 32-bits, but the actual bit width does not exceed 36 bits. When the cache operation is performed based on the address range, the upper 30 bits of the physical address are recorded in registers L3_MAINT_START and L3_MAINT_END, and ignore the lower 6 bits cacheline offset.
--- arch/arm/mm/Kconfig | 10 +++ arch/arm/mm/Makefile | 1 + arch/arm/mm/cache-kunpeng-l3.c | 153 +++++++++++++++++++++++++++++++++ arch/arm/mm/cache-kunpeng-l3.h | 30 +++++++ 4 files changed, 194 insertions(+) create mode 100644 arch/arm/mm/cache-kunpeng-l3.c create mode 100644 arch/arm/mm/cache-kunpeng-l3.h
arch/arm/mm/Kconfig +10 -0
@@ -1070,6 +1070,16 @@ config CACHE_XSC3L2 help This option enables the L2 cache on XScale3. +config CACHE_KUNPENG_L3 + bool "Enable the Hisilicon Kunpeng L3 cache controller" + depends on ARCH_KUNPENG50X && OF + default y + select OUTER_CACHE + help + This option enables the Kunpeng L3 cache controller on Hisilicon + Kunpeng506 and Kunpeng509 SoCs. It supports a maximum of 36-bit + physical addresses. + config ARM_L1_CACHE_SHIFT_6 bool default y if CPU_V7
arch/arm/mm/Makefile +1 -0
@@ -112,6 +112,7 @@ obj-$(CONFIG_CACHE_L2X0_PMU) += cache-l2x0-pmu.o obj-$(CONFIG_CACHE_XSC3L2) += cache-xsc3l2.o obj-$(CONFIG_CACHE_TAUROS2) += cache-tauros2.o obj-$(CONFIG_CACHE_UNIPHIER) += cache-uniphier.o +obj-$(CONFIG_CACHE_KUNPENG_L3) += cache-kunpeng-l3.o KASAN_SANITIZE_kasan_init.o := n obj-$(CONFIG_KASAN) += kasan_init.o
arch/arm/mm/cache-kunpeng-l3.c new file +153 -0
153 lines not on this page · raw message
arch/arm/mm/cache-kunpeng-l3.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __CACHE_KUNPENG_L3_H +#define __CACHE_KUNPENG_L3_H + +#define L3_CACHE_LINE_SHITF 6 + +#define L3_CTRL 0x0 +#define L3_CTRL_ENABLE (1U << 0) +#define L3_CTRL_DISABLE (0U << 0) + +#define L3_AUCTRL 0x4 +#define L3_AUCTRL_EVENT_EN BIT(23) +#define L3_AUCTRL_ECC_EN BIT(8) + +#define L3_MAINT_CTRL 0x20 +#define L3_MAINT_RANGE_MASK GENMASK(3, 3) +#define L3_MAINT_RANGE_ALL (0U << 3) +#define L3_MAINT_RANGE_ADDR (1U << 3) +#define L3_MAINT_TYPE_MASK GENMASK(2, 1) +#define L3_MAINT_TYPE_CLEAN (1U << 1) +#define L3_MAINT_TYPE_INV (2U << 1) +#define L3_MAINT_TYPE_FLUSH (3U << 1) +#define L3_MAINT_STATUS_MASK GENMASK(0, 0) +#define L3_MAINT_STATUS_START (1U << 0) +#define L3_MAINT_STATUS_END (0U << 0) + +#define L3_MAINT_START 0x24 +#define L3_MAINT_END 0x28 + +#endif
Signature · 1 line
2.26.0.106.g9fadedd
arch/arm/mm/Makefile
Quoted 11 lines · Zhen Lei
arch/arm/mm/Makefile +10
-0+ +static void l3cache_maint_common(u32 range, u32 op_type) +{ + u32 reg; + + reg = readl(l3_ctrl_base + L3_MAINT_CTRL); + reg &= ~(L3_MAINT_RANGE_MASK | L3_MAINT_TYPE_MASK); + reg |= range | op_type; + reg |= L3_MAINT_STATUS_START; + writel(reg, l3_ctrl_base + L3_MAINT_CTRL);
Are there contents of L3_MAINT_CTRL that need to be preserved across calls and can not be inferred? A 'readl()' is often expensive, so it might be more efficient if you can avoid that.
arch/arm/mm/Makefile
Quoted 13 lines
arch/arm/mm/Makefile +13
-0+static inline void l3cache_flush_all_nolock(void) +{ + l3cache_maint_common(L3_MAINT_RANGE_ALL, L3_MAINT_TYPE_FLUSH); +} + +static void l3cache_flush_all(void) +{ + unsigned long flags; + + spin_lock_irqsave(&l3cache_lock, flags); + l3cache_flush_all_nolock(); + spin_unlock_irqrestore(&l3cache_lock, flags); +}
I see that cache-l2x0 uses raw_spin_lock_irqsave() instead of spin_lock_irqsave(), to avoid preemption in the middle of a cache operation. This is probably a good idea here as well.
I also see that l2x0 uses readl_relaxed(), to avoid a deadlock in l2x0_cache_sync(). This may also be beneficial for performance reasons, so it might be helpful to compare performance overhead. On the other hand, readl()/writel() are usually the safe choice, as those avoid the need to argue over whether the relaxed versions are safe in all corner cases.
arch/arm/mm/Makefile
Quoted 8 lines
arch/arm/mm/Makefile +8
-0+static int __init l3cache_init(void) +{ + u32 reg; + struct device_node *node; + + node = of_find_matching_node(NULL, l3cache_ids); + if (!node) + return -ENODEV;
I think the initcall should return '0' to indicate success when running a kernel with this driver built-in on a platform that does not have this device.
arch/arm/mm/cache-kunpeng-l3.h line 5
Quoted 11 lines
arch/arm/mm/cache-kunpeng-l3.h new file +5
-0@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __CACHE_KUNPENG_L3_H +#define __CACHE_KUNPENG_L3_H + +#define L3_CACHE_LINE_SHITF 6
I would suggest moving the contents of the header file into the .c file, since there is only a single user of these macros.
Arnd
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 16 lines · Arnd Bergmann
arch/arm/mm/Makefile
Quoted 11 lines · Zhen Lei
arch/arm/mm/Makefile +10
-0+ +static void l3cache_maint_common(u32 range, u32 op_type) +{ + u32 reg; + + reg = readl(l3_ctrl_base + L3_MAINT_CTRL); + reg &= ~(L3_MAINT_RANGE_MASK | L3_MAINT_TYPE_MASK); + reg |= range | op_type; + reg |= L3_MAINT_STATUS_START; + writel(reg, l3_ctrl_base + L3_MAINT_CTRL);Are there contents of
L3_MAINT_CTRLthat need to be preserved across calls and can not be inferred? A 'readl()' is often expensive, so it might be more efficient if you can avoid that.
Right, this readl() can be replaced with readl_relaxed(). Thanks.
I'll check and correct the readl() and writel() in other places.
Quoted 10 lines
Quoted 10 lines
arch/arm/mm/Makefile +9
-0+static inline void l3cache_flush_all_nolock(void) +{ + l3cache_maint_common(L3_MAINT_RANGE_ALL, L3_MAINT_TYPE_FLUSH); +} + +static void l3cache_flush_all(void) +{ + unsigned long flags; +
Quoted 8 lines
arch/arm/mm/Makefile
Quoted 4 lines
arch/arm/mm/Makefile +4
-0+ spin_lock_irqsave(&l3cache_lock, flags); + l3cache_flush_all_nolock(); + spin_unlock_irqrestore(&l3cache_lock, flags); +}I see that cache-l2x0 uses
raw_spin_lock_irqsave()instead ofspin_lock_irqsave(), to avoid preemption in the middle of a cache operation. This is probably a good idea here as well.
I don't think there's any essential difference between the two! I don't know if the compiler or tool will do anything extra. I checked the git log of the l2x0 driver and it used raw_spin_lock_irqsave() at the beginning. Maybe there's a description in 2.6. Since you mentioned this potential risk, I'll change it to raw_spin_lock_irqsave.
include/linux/spinlock.h:
static __always_inline raw_spinlock_t *spinlock_check(spinlock_t *lock)
{
return &lock->rlock;
}#define spin_lock_irqsave(lock, flags) \
do { \
raw_spin_lock_irqsave(spinlock_check(lock), flags); \} while (0)
Quoted 8 lines
I also see that l2x0 uses
readl_relaxed(), to avoid a deadlock inl2x0_cache_sync(). This may also be beneficial for performance reasons, so it might be helpful to compare performance overhead. On the other hand, readl()/writel() are usually the safe choice, as those avoid the need to argue over whether the relaxed versions are safe in all corner cases.
Quoted 12 lines
arch/arm/mm/Makefile
Quoted 8 lines
arch/arm/mm/Makefile +8
-0+static int __init l3cache_init(void) +{ + u32 reg; + struct device_node *node; + + node = of_find_matching_node(NULL, l3cache_ids); + if (!node) + return -ENODEV;I think the initcall should return '0' to indicate success when running a kernel with this driver built-in on a platform that does not have this device.
I have added "depends on ARCH_KUNPENG50X" for this driver. But it's OK to return 0.
Quoted 15 lines
arch/arm/mm/cache-kunpeng-l3.h line 5
Quoted 12 lines
arch/arm/mm/cache-kunpeng-l3.h new file +5
-0@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __CACHE_KUNPENG_L3_H +#define __CACHE_KUNPENG_L3_H + +#define L3_CACHE_LINE_SHITF 6I would suggest moving the contents of the header file into the .c file, since there is only a single user of these macros.
Okay, I'll move it.
Quoted 5 lines
Arnd
.
Quoted 18 lines · Leizhen (ThunderTown)
Quoted 16 lines · Arnd Bergmann
arch/arm/mm/Makefile
Quoted 11 lines · Zhen Lei
arch/arm/mm/Makefile +10
-0+ +static void l3cache_maint_common(u32 range, u32 op_type) +{ + u32 reg; + + reg = readl(l3_ctrl_base + L3_MAINT_CTRL); + reg &= ~(L3_MAINT_RANGE_MASK | L3_MAINT_TYPE_MASK); + reg |= range | op_type; + reg |= L3_MAINT_STATUS_START; + writel(reg, l3_ctrl_base + L3_MAINT_CTRL);Are there contents of
L3_MAINT_CTRLthat need to be preserved across calls and can not be inferred? A 'readl()' is often expensive, so it might be more efficient if you can avoid that.
Quoted 3 lines
Right, this
readl()can be replaced withreadl_relaxed(). Thanks.I'll check and correct the
readl()andwritel()in other places.
What I meant is that if you want to replace them, you should provide performance numbers that show how much difference this makes and add comments in the source code explaining how you proved that the _relaxed() version is actually correct.
Quoted 26 lines
Quoted 9 lines
Quoted 9 lines
arch/arm/mm/Makefile +9
-0+static inline void l3cache_flush_all_nolock(void) +{ + l3cache_maint_common(L3_MAINT_RANGE_ALL, L3_MAINT_TYPE_FLUSH); +} + +static void l3cache_flush_all(void) +{ + unsigned long flags; +Quoted 8 lines
arch/arm/mm/Makefile
Quoted 4 lines
arch/arm/mm/Makefile +4
-0+ spin_lock_irqsave(&l3cache_lock, flags); + l3cache_flush_all_nolock(); + spin_unlock_irqrestore(&l3cache_lock, flags); +}I see that cache-l2x0 uses
raw_spin_lock_irqsave()instead ofspin_lock_irqsave(), to avoid preemption in the middle of a cache operation. This is probably a good idea here as well.I don't think there's any essential difference between the two! I don't know if the compiler or tool will do anything extra. I checked the git log of the l2x0 driver and it used
raw_spin_lock_irqsave()at the beginning. Maybe there's a description in 2.6. Since you mentioned this potential risk, I'll change it toraw_spin_lock_irqsave.include/linux/spinlock.h:
static__always_inlineraw_spinlock_t*spinlock_check(spinlock_t *lock)
Quoted 8 lines
{ return &lock->rlock; }#define spin_lock_irqsave(lock, flags) \ do { \ raw_spin_lock_irqsave(spinlock_check(lock), flags); \} while (0)
The spin_lock_irqsave() definition is one of the things that differs with CONFIG_PREEMPT_RT=y, where it uses a mutex instead.
See https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git/log/?h=linux-5.11.y-rt-rebase
for the final missing patches including the one that changes the
spinlock definition and some patches that change a few other spin_lock
to raw_spin_lock.
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
arch/arm/mm/Makefile +4
-0+static int __init l3cache_init(void) +{ + u32 reg; + struct device_node *node;Quoted 8 lines
arch/arm/mm/Makefile
Quoted 4 lines
arch/arm/mm/Makefile +4
-0+ + node = of_find_matching_node(NULL, l3cache_ids); + if (!node) + return -ENODEV;I think the initcall should return '0' to indicate success when running a kernel with this driver built-in on a platform that does not have this device.
Quoted 2 lines
I have added "depends on
ARCH_KUNPENG50X" for this driver. But it's OK to return 0.
Note that the "depends on ARCH_KUNPENG50X" is not relevant here, since it only prevents you from enabling the driver on kernels that explicitly exclude the kunpeng platform, but it has no significance to what you are actually running on. The "multi_v7_defconfig" file should have all actively maintained armv7 platforms enabled, similar to how common distros ship their kernels.
Arnd
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 20 lines · Arnd Bergmann
Quoted 18 lines · Leizhen (ThunderTown)
Quoted 16 lines · Arnd Bergmann
arch/arm/mm/Makefile
Quoted 11 lines · Zhen Lei
arch/arm/mm/Makefile +10
-0+ +static void l3cache_maint_common(u32 range, u32 op_type) +{ + u32 reg; + + reg = readl(l3_ctrl_base + L3_MAINT_CTRL); + reg &= ~(L3_MAINT_RANGE_MASK | L3_MAINT_TYPE_MASK); + reg |= range | op_type; + reg |= L3_MAINT_STATUS_START; + writel(reg, l3_ctrl_base + L3_MAINT_CTRL);Are there contents of
L3_MAINT_CTRLthat need to be preserved across calls and can not be inferred? A 'readl()' is often expensive, so it might be more efficient if you can avoid that.
Quoted 8 lines
Quoted 3 lines
Right, this
readl()can be replaced withreadl_relaxed(). Thanks.I'll check and correct the
readl()andwritel()in other places.What I meant is that if you want to replace them, you should provide performance numbers that show how much difference this makes and add comments in the source code explaining how you proved that the
_relaxed()version is actually correct.
Another clarification, as there are actually two independent points here:
* if you can completely remove the readl() above and just write a hardcoded value into the register, or perhaps read the original value once at boot time, that is probably a win because it avoids one of the barriers in the beginning. The datasheet should tell you if there are any bits in the register that have to be preserved
* Regarding the _relaxed() accessors, it's a lot harder to know whether that is safe, as you first have to show, in particular in case any of the accesses stop being guarded by the spinlock in that case, and whether there may be a case where you have to serialize the memory access against accesses that are still in the store queue or prefetched.
Whether this matters at all depends mostly on the type of devices you are driving on your SoC. If you have any high-speed network interfaces that are unable to do cache coherent DMA, any extra instruction here may impact the number of packets you can transfer, but if all your high-speed devices are connected to a coherent interconnect, I would just go with the obvious approach and use the safe MMIO accessors everywhere.
Arnd
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Russell King - ARM Linux admin
maintainerQuoted 17 lines · Arnd Bergmann
Another clarification, as there are actually two independent points here:
* if you can completely remove the
readl()above and just write a hardcoded value into the register, or perhaps read the original value once at boot time, that is probably a win because it avoids one of the barriers in the beginning. The datasheet should tell you if there are any bits in the register that have to be preserved* Regarding the
_relaxed()accessors, it's a lot harder to know whether that is safe, as you first have to show, in particular in case any of the accesses stop being guarded by the spinlock in that case, and whether there may be a case where you have to serialize the memory access against accesses that are still in the store queue or prefetched.
Quoted 7 lines
Whether this matters at all depends mostly on the type of devices you are driving on your SoC. If you have any high-speed network interfaces that are unable to do cache coherent DMA, any extra instruction here may impact the number of packets you can transfer, but if all your high-speed devices are connected to a coherent interconnect, I would just go with the obvious approach and use the safe MMIO accessors everywhere.
For L2 cache code, I would say the opposite, actually, because it is all too easy to get into a deadlock otherwise.
If you implement the sync callback, that will be called from every non-relaxed accessor, which means if you need to take some kind of lock in the sync callback and elsewhere in the L2 cache code, you will definitely deadlock.
It is safer to put explicit barriers where it is necessary.
Also remember that the barrier in readl() etc is _after_ the read, not before, and the barrier in writel() is _before_ the write, not after. The point is to ensure that DMA memory accesses are properly ordered with the IO-accessing instructions.
So, using readl_relaxed() with a read-modify-write is entirely sensible provided you do not access DMA memory inbetween.
Signature · 7 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last! _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 27 lines · Russell King - ARM Linux admin
Quoted 17 lines · Arnd Bergmann
Another clarification, as there are actually two independent points here:
* if you can completely remove the
readl()above and just write a hardcoded value into the register, or perhaps read the original value once at boot time, that is probably a win because it avoids one of the barriers in the beginning. The datasheet should tell you if there are any bits in the register that have to be preserved* Regarding the
_relaxed()accessors, it's a lot harder to know whether that is safe, as you first have to show, in particular in case any of the accesses stop being guarded by the spinlock in that case, and whether there may be a case where you have to serialize the memory access against accesses that are still in the store queue or prefetched.Quoted 7 lines
Whether this matters at all depends mostly on the type of devices you are driving on your SoC. If you have any high-speed network interfaces that are unable to do cache coherent DMA, any extra instruction here may impact the number of packets you can transfer, but if all your high-speed devices are connected to a coherent interconnect, I would just go with the obvious approach and use the safe MMIO accessors everywhere.
Quoted 7 lines
For L2 cache code, I would say the opposite, actually, because it is all too easy to get into a deadlock otherwise.
If you implement the sync callback, that will be called from every non-relaxed accessor, which means if you need to take some kind of lock in the sync callback and elsewhere in the L2 cache code, you will definitely deadlock.
Fair enough. I mentioned the sync callback as the reason for using the relaxed accessor in l2x0 in my first reply. Clearly if there was a sync callback here, it would immediately deadlock when calling back into sync() from readl()/writel().
Quoted 9 lines
It is safer to put explicit barriers where it is necessary.
Also remember that the barrier in
readl()etc is _after_ the read, not before, and the barrier inwritel()is _before_ the write, not after. The point is to ensure that DMA memory accesses are properly ordered with the IO-accessing instructions.So, using
readl_relaxed()with a read-modify-write is entirely sensible provided you do not access DMA memory inbetween.
The part I was not sure about is what happens when you have a store to memory immediately before flushing the cache, and there are no barriers inbetween. Is there a possibility for the mmio store to cause the cache to be flushed before the prior memory store has made it into the cache? My guess would be that this cannot happen, but I'm not sure. If the code gets changed to raw_writel(), I think this should be documented next to the actual raw_writel(), explaining either the presence of the absence of such a barrier.
Arnd
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Russell King - ARM Linux admin
maintainerQuoted 9 lines · Arnd Bergmann
Quoted 7 lines · Russell King - ARM Linux admin
It is safer to put explicit barriers where it is necessary.
Also remember that the barrier in
readl()etc is _after_ the read, not before, and the barrier inwritel()is _before_ the write, not after. The point is to ensure that DMA memory accesses are properly ordered with the IO-accessing instructions.
Quoted 6 lines
Quoted 2 lines
So, using
readl_relaxed()with a read-modify-write is entirely sensible provided you do not access DMA memory inbetween.The part I was not sure about is what happens when you have a store to memory immediately before flushing the cache, and there are no barriers inbetween.
If the caches are non-coherent, we have to flush L1 before we flush L2 to ensure writebacks get pushed out properly, and L1 will already have the necessary barriers.
If we have the situation where L1 is coherent but L2 isn't, then I think we have an "interesting situation" that we haven't considered whether it be in DT or elsewhere.
Signature · 7 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last! _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 34 lines · Russell King - ARM Linux admin
Quoted 17 lines · Arnd Bergmann
Another clarification, as there are actually two independent points here:
* if you can completely remove the
readl()above and just write a hardcoded value into the register, or perhaps read the original value once at boot time, that is probably a win because it avoids one of the barriers in the beginning. The datasheet should tell you if there are any bits in the register that have to be preserved* Regarding the
_relaxed()accessors, it's a lot harder to know whether that is safe, as you first have to show, in particular in case any of the accesses stop being guarded by the spinlock in that case, and whether there may be a case where you have to serialize the memory access against accesses that are still in the store queue or prefetched.Quoted 7 lines
Whether this matters at all depends mostly on the type of devices you are driving on your SoC. If you have any high-speed network interfaces that are unable to do cache coherent DMA, any extra instruction here may impact the number of packets you can transfer, but if all your high-speed devices are connected to a coherent interconnect, I would just go with the obvious approach and use the safe MMIO accessors everywhere.
For L2 cache code, I would say the opposite, actually, because it is all too easy to get into a deadlock otherwise.
If you implement the sync callback, that will be called from every non-relaxed accessor, which means if you need to take some kind of lock in the sync callback and elsewhere in the L2 cache code, you will definitely deadlock.
Quoted 6 lines
It is safer to put explicit barriers where it is necessary.
Also remember that the barrier in
readl()etc is _after_ the read, not before, and the barrier inwritel()is _before_ the write, not after. The point is to ensure that DMA memory accesses are properly ordered with the IO-accessing instructions.
Yes, I known it. writel() must be used for the write operations that control "start/stop" or "enable/disable" function, to ensure that the data of previous write operations reaches the target. I've met this kind of problem before.
Quoted 3 lines
So, using
readl_relaxed()with a read-modify-write is entirely sensible provided you do not access DMA memory inbetween.
Actually, I don't think this register is that complicated. I copied the code back below. All the bits of L3_MAINT_CTRL are not affected by DMA access operations. The software change the "range | op_type" to specify the operation type and scope, the set the bit "L3_MAINT_STATUS_START" to start the operation. Then wait for that bit to change from 1 to 0 by hardware.
+ reg = readl(l3_ctrl_base + L3_MAINT_CTRL);
+ reg &= ~(L3_MAINT_RANGE_MASK | L3_MAINT_TYPE_MASK);
+ reg |= range | op_type;
+ reg |= L3_MAINT_STATUS_START;
+ writel(reg, l3_ctrl_base + L3_MAINT_CTRL);
+
+ /* Wait until the hardware maintenance operation is complete. */
+ do {
+ cpu_relax();
+ reg = readl(l3_ctrl_base + L3_MAINT_CTRL);
+ } while ((reg & L3_MAINT_STATUS_MASK) != L3_MAINT_STATUS_END);
Quoted 1 line
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 33 lines · Arnd Bergmann
Quoted 20 lines · Arnd Bergmann
Quoted 18 lines · Leizhen (ThunderTown)
Quoted 16 lines · Arnd Bergmann
arch/arm/mm/Makefile
Quoted 11 lines · Zhen Lei
arch/arm/mm/Makefile +10
-0+ +static void l3cache_maint_common(u32 range, u32 op_type) +{ + u32 reg; + + reg = readl(l3_ctrl_base + L3_MAINT_CTRL); + reg &= ~(L3_MAINT_RANGE_MASK | L3_MAINT_TYPE_MASK); + reg |= range | op_type; + reg |= L3_MAINT_STATUS_START; + writel(reg, l3_ctrl_base + L3_MAINT_CTRL);Are there contents of
L3_MAINT_CTRLthat need to be preserved across calls and can not be inferred? A 'readl()' is often expensive, so it might be more efficient if you can avoid that.Quoted 8 lines
Quoted 3 lines
Right, this
readl()can be replaced withreadl_relaxed(). Thanks.I'll check and correct the
readl()andwritel()in other places.What I meant is that if you want to replace them, you should provide performance numbers that show how much difference this makes and add comments in the source code explaining how you proved that the
_relaxed()version is actually correct.Another clarification, as there are actually two independent points here:
Quoted 6 lines
* if you can completely remove the
readl()above and just write a hardcoded value into the register, or perhaps read the original value once at boot time, that is probably a win because it avoids one of the barriers in the beginning. The datasheet should tell you if there are any bits in the register that have to be preserved
Code coupling will become very strong.
Quoted 8 lines
* Regarding the
_relaxed()accessors, it's a lot harder to know whether that is safe, as you first have to show, in particular in case any of the accesses stop being guarded by the spinlock in that case, and whether there may be a case where you have to serialize the memory access against accesses that are still in the store queue or prefetched.
Quoted 7 lines
Whether this matters at all depends mostly on the type of devices you are driving on your SoC. If you have any high-speed network interfaces that are unable to do cache coherent DMA, any extra instruction here may impact the number of packets you can transfer, but if all your high-speed devices are connected to a coherent interconnect, I would just go with the obvious approach and use the safe MMIO accessors everywhere.
In fact, this driver has been running on an earlier version for several years and has not received any feedback about the performance issue. So I didn't try to optimize it when I first sent these patches. I had to reconsider it until you noticed it.
How about keeping it unchanged for the moment? It'll take a lot of time and energy to retest.
Quoted 9 lines
Arnd
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 61 lines · Leizhen (ThunderTown)
Quoted 33 lines · Arnd Bergmann
Quoted 20 lines · Arnd Bergmann
Quoted 18 lines · Leizhen (ThunderTown)
Quoted 16 lines · Arnd Bergmann
arch/arm/mm/Makefile
Quoted 11 lines · Zhen Lei
arch/arm/mm/Makefile +10
-0+ +static void l3cache_maint_common(u32 range, u32 op_type) +{ + u32 reg; + + reg = readl(l3_ctrl_base + L3_MAINT_CTRL); + reg &= ~(L3_MAINT_RANGE_MASK | L3_MAINT_TYPE_MASK); + reg |= range | op_type; + reg |= L3_MAINT_STATUS_START; + writel(reg, l3_ctrl_base + L3_MAINT_CTRL);Are there contents of
L3_MAINT_CTRLthat need to be preserved across calls and can not be inferred? A 'readl()' is often expensive, so it might be more efficient if you can avoid that.Quoted 8 lines
Quoted 3 lines
Right, this
readl()can be replaced withreadl_relaxed(). Thanks.I'll check and correct the
readl()andwritel()in other places.What I meant is that if you want to replace them, you should provide performance numbers that show how much difference this makes and add comments in the source code explaining how you proved that the
_relaxed()version is actually correct.Another clarification, as there are actually two independent points here:
Quoted 6 lines
* if you can completely remove the
readl()above and just write a hardcoded value into the register, or perhaps read the original value once at boot time, that is probably a win because it avoids one of the barriers in the beginning. The datasheet should tell you if there are any bits in the register that have to be preservedCode coupling will become very strong.
Quoted 8 lines
* Regarding the
_relaxed()accessors, it's a lot harder to know whether that is safe, as you first have to show, in particular in case any of the accesses stop being guarded by the spinlock in that case, and whether there may be a case where you have to serialize the memory access against accesses that are still in the store queue or prefetched.Quoted 7 lines
Whether this matters at all depends mostly on the type of devices you are driving on your SoC. If you have any high-speed network interfaces that are unable to do cache coherent DMA, any extra instruction here may impact the number of packets you can transfer, but if all your high-speed devices are connected to a coherent interconnect, I would just go with the obvious approach and use the safe MMIO accessors everywhere.
Quoted 7 lines
In fact, this driver has been running on an earlier version for several years and has not received any feedback about the performance issue. So I didn't try to optimize it when I first sent these patches. I had to reconsider it until you noticed it.
How about keeping it unchanged for the moment? It'll take a lot of time and energy to retest.
In the spirit of code excellence, it's still necessary to optimize it. Yesterday, my family urged me to go back, I wrote it in a hurry.
Quoted 12 lines
Quoted 10 lines
Arnd
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 7 lines
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 20 lines · Arnd Bergmann
Quoted 18 lines · Leizhen (ThunderTown)
Quoted 16 lines · Arnd Bergmann
arch/arm/mm/Makefile
Quoted 11 lines · Zhen Lei
arch/arm/mm/Makefile +10
-0+ +static void l3cache_maint_common(u32 range, u32 op_type) +{ + u32 reg; + + reg = readl(l3_ctrl_base + L3_MAINT_CTRL); + reg &= ~(L3_MAINT_RANGE_MASK | L3_MAINT_TYPE_MASK); + reg |= range | op_type; + reg |= L3_MAINT_STATUS_START; + writel(reg, l3_ctrl_base + L3_MAINT_CTRL);Are there contents of
L3_MAINT_CTRLthat need to be preserved across calls and can not be inferred? A 'readl()' is often expensive, so it might be more efficient if you can avoid that.
Quoted 8 lines
Quoted 3 lines
Right, this
readl()can be replaced withreadl_relaxed(). Thanks.I'll check and correct the
readl()andwritel()in other places.What I meant is that if you want to replace them, you should provide performance numbers that show how much difference this makes and add comments in the source code explaining how you proved that the
_relaxed()version is actually correct.
Yes, it's just a theoretical analysis now. After the modification, I'll test it. But then again, outcache operations are not critical path of performance.
Quoted 36 lines
Quoted 27 lines
Quoted 10 lines
Quoted 10 lines
arch/arm/mm/Makefile +9
-0+static inline void l3cache_flush_all_nolock(void) +{ + l3cache_maint_common(L3_MAINT_RANGE_ALL, L3_MAINT_TYPE_FLUSH); +} + +static void l3cache_flush_all(void) +{ + unsigned long flags; +Quoted 8 lines
arch/arm/mm/Makefile
Quoted 4 lines
arch/arm/mm/Makefile +4
-0+ spin_lock_irqsave(&l3cache_lock, flags); + l3cache_flush_all_nolock(); + spin_unlock_irqrestore(&l3cache_lock, flags); +}I see that cache-l2x0 uses
raw_spin_lock_irqsave()instead ofspin_lock_irqsave(), to avoid preemption in the middle of a cache operation. This is probably a good idea here as well.I don't think there's any essential difference between the two! I don't know if the compiler or tool will do anything extra. I checked the git log of the l2x0 driver and it used
raw_spin_lock_irqsave()at the beginning. Maybe there's a description in 2.6. Since you mentioned this potential risk, I'll change it toraw_spin_lock_irqsave.include/linux/spinlock.h:
static__always_inlineraw_spinlock_t*spinlock_check(spinlock_t *lock)Quoted 8 lines
{ return &lock->rlock; }#define spin_lock_irqsave(lock, flags) \ do { \ raw_spin_lock_irqsave(spinlock_check(lock), flags); \} while (0)
Quoted 7 lines
The
spin_lock_irqsave()definition is one of the things that differs withCONFIG_PREEMPT_RT=y, where it uses a mutex instead.See https://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git/log/?h=linux-5.11.y-rt-rebase
for the final missing patches including the one that changes the
spinlock definition and some patches that change a few otherspin_lock
toraw_spin_lock.
OK, thanks.
Quoted 14 lines
Quoted 14 lines
Quoted 13 lines
arch/arm/mm/Makefile
Quoted 9 lines
arch/arm/mm/Makefile +8
-0+static int __init l3cache_init(void) +{ + u32 reg; + struct device_node *node; + + node = of_find_matching_node(NULL, l3cache_ids); + if (!node) + return -ENODEV;I think the initcall should return '0' to indicate success when running a kernel with this driver built-in on a platform that does not have this device.
Quoted 8 lines
Quoted 2 lines
I have added "depends on
ARCH_KUNPENG50X" for this driver. But it's OK to return 0.Note that the "depends on
ARCH_KUNPENG50X" is not relevant here, since it only prevents you from enabling the driver on kernels that explicitly exclude the kunpeng platform, but it has no significance to what you are actually running on. The "multi_v7_defconfig" file should have all actively maintained armv7 platforms enabled, similar to how common distros ship their kernels.
OK, I got it.
Quoted 5 lines
Arnd
.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Russell King - ARM Linux admin
maintainerQuoted 10 lines · Leizhen (ThunderTown)
Quoted 3 lines · Arnd Bergmann
I see that cache-l2x0 uses
raw_spin_lock_irqsave()instead ofspin_lock_irqsave(), to avoid preemption in the middle of a cache operation. This is probably a good idea here as well.I don't think there's any essential difference between the two! I don't know if the compiler or tool will do anything extra. I checked the git log of the l2x0 driver and it used
raw_spin_lock_irqsave()at the beginning. Maybe there's a description in 2.6. Since you mentioned this potential risk, I'll change it toraw_spin_lock_irqsave.
See bd31b85960a7 ("locking, ARM: Annotate low level hw locks as raw")
Signature · 7 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 40Mbps down 10Mbps up. Decent connectivity at last! _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 6 lines · Russell King - ARM Linux admin
Quoted 5 lines · Leizhen (ThunderTown)
Quoted 3 lines · Arnd Bergmann
I see that cache-l2x0 uses
raw_spin_lock_irqsave()instead ofspin_lock_irqsave(), to avoid preemption in the middle of a cache operation. This is probably a good idea here as well.
Quoted 7 lines
Quoted 5 lines
I don't think there's any essential difference between the two! I don't know if the compiler or tool will do anything extra. I checked the git log of the l2x0 driver and it used
raw_spin_lock_irqsave()at the beginning. Maybe there's a description in 2.6. Since you mentioned this potential risk, I'll change it toraw_spin_lock_irqsave.See
bd31b85960a7("locking, ARM: Annotate low level hw locks as raw")
OK, thanks.
Quoted 1 line
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hi Russell and Arnd:
Do you have time to review it?
Quoted 63 lines · Zhen Lei
v4 --> v5:
1. Add SoC macroARCH_KUNPENG50X, and the Kunpeng L3 cache controller only enabled on that platform.
2. Require the compatible string of the Kunpeng L3 cache controller must have a relevant name on a specific SoC. For example:compatible = "hisilicon,kunpeng509-l3cache", "hisilicon,kunpeng-l3cache";v3 --> v4:
Rename the compatible string from "hisilicon,l3cache" to "hisilicon,kunpeng-l3cache". Then adjust the file name, configuration option name, and description accordingly.v2 --> v3:
Add Hisilicon L3 cache controller driver and its document. That's: patch 2-3.v1 --> v2:
Discard the middle-tier functions and do silent narrowing cast in the outcache hook functions. For example:(quoted diff) +3
-1-static void l2c220_inv_range(unsigned long start, unsigned long end) +static void l2c220_inv_range(phys_addr_t pa_start, phys_addr_t pa_end) { + unsigned long start = pa_start; + unsigned long end = pa_end;v1:
Do castphys_addr_tto unsigned long by adding a middle-tier function. For example:(quoted diff) +5
-1-static void l2c220_inv_range(unsigned long start, unsigned long end) +static void __l2c220_inv_range(unsigned long start, unsigned long end) { } +static void l2c220_inv_range(phys_addr_t start, phys_addr_t end) +{ + __l2c220_inv_range(start, end); +}Zhen Lei (4):
ARM: LPAE: Usephys_addr_tinstead of unsigned long in outercache
hooks
ARM: hisi: add support for Kunpeng50x SoC
dt-bindings: arm: hisilicon: Add binding for Kunpeng L3 cache
controller
ARM: Add support for Hisilicon Kunpeng L3 cache controller.../arm/hisilicon/kunpeng-l3cache.yaml | 40 +++++ arch/arm/include/asm/outercache.h | 6 +- arch/arm/mach-hisi/Kconfig | 8 + arch/arm/mm/Kconfig | 10 ++ arch/arm/mm/Makefile | 1 + arch/arm/mm/cache-feroceon-l2.c | 15 +- arch/arm/mm/cache-kunpeng-l3.c | 153 ++++++++++++++++++ arch/arm/mm/cache-kunpeng-l3.h | 30 ++++ arch/arm/mm/cache-l2x0.c | 50 ++++-- arch/arm/mm/cache-tauros2.c | 15 +- arch/arm/mm/cache-uniphier.c | 6 +- arch/arm/mm/cache-xsc3l2.c | 12 +- 12 files changed, 317 insertions(+), 29 deletions(-) create mode 100644 Documentation/devicetree/bindings/arm/hisilicon/kunpeng-l3cache.yaml create mode 100644 arch/arm/mm/cache-kunpeng-l3.c create mode 100644 arch/arm/mm/cache-kunpeng-l3.h