linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] introduce unaligned access under a Kconfig option
@ 2019-01-29 10:49 Eugeniy Paltsev
  2019-01-29 10:49 ` [PATCH 1/5] ARCv2: lib: memcpy: fix doing prefetchw outside of buffer Eugeniy Paltsev
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Eugeniy Paltsev @ 2019-01-29 10:49 UTC (permalink / raw)
  To: linux-snps-arc, Vineet Gupta
  Cc: linux-kernel, Alexey Brodkin, Eugeniy Paltsev

As of today we enable unaligned access unconditionally on ARCv2.
Lets move it under Kconfig option and use it actively in SW if it is
enabled.

While I'm at it fix and optimise ARCv2 memcpy implementaion.

Eugeniy Paltsev (5):
  ARCv2: lib: memcpy: fix doing prefetchw outside of buffer
  ARCv2: introduce unaligned access under a Kconfig option
  ARCv2: Enable unaligned access in early ASM code
  ARCv2: use unaligned access in SW
  ARCv2: LIB: MEMCPY: fixed and optimised routine

 arch/arc/Kconfig                      | 13 ++++++++++
 arch/arc/Makefile                     |  6 +++++
 arch/arc/include/asm/irqflags-arcv2.h |  4 +++
 arch/arc/kernel/head.S                | 14 +++++++++++
 arch/arc/kernel/intc-arcv2.c          |  2 +-
 arch/arc/lib/Makefile                 |  5 +++-
 arch/arc/lib/memcpy-archs-unaligned.S | 46 +++++++++++++++++++++++++++++++++++
 arch/arc/lib/memcpy-archs.S           | 14 -----------
 8 files changed, 88 insertions(+), 16 deletions(-)
 create mode 100644 arch/arc/lib/memcpy-archs-unaligned.S

-- 
2.14.5


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/5] ARCv2: lib: memcpy: fix doing prefetchw outside of buffer
  2019-01-29 10:49 [PATCH 0/5] introduce unaligned access under a Kconfig option Eugeniy Paltsev
@ 2019-01-29 10:49 ` Eugeniy Paltsev
  2019-01-29 10:49 ` [PATCH 2/5] ARCv2: introduce unaligned access under a Kconfig option Eugeniy Paltsev
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Eugeniy Paltsev @ 2019-01-29 10:49 UTC (permalink / raw)
  To: linux-snps-arc, Vineet Gupta
  Cc: linux-kernel, Alexey Brodkin, Eugeniy Paltsev

ARCv2 optimized memcpy uses PREFETCHW instruction for prefetching the
next cache line but doesn't ensure that the line is not past the end of
the buffer. PRETECHW changes the line ownership and marks it dirty,
which can cause data corruption if this area is used for DMA IO.

Fix the issue by avoiding the PREFETCHW. This leads to performance
degradation but it is OK as we'll introduce new memcpy implementation
optimized for unaligned memory access using.

We also cut off all PREFETCH instructions at they are quite useless
according to benchmark.

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
---
 arch/arc/lib/memcpy-archs.S | 14 --------------
 1 file changed, 14 deletions(-)

diff --git a/arch/arc/lib/memcpy-archs.S b/arch/arc/lib/memcpy-archs.S
index d61044dd8b58..ea14b0bf3116 100644
--- a/arch/arc/lib/memcpy-archs.S
+++ b/arch/arc/lib/memcpy-archs.S
@@ -25,15 +25,11 @@
 #endif
 
 #ifdef CONFIG_ARC_HAS_LL64
-# define PREFETCH_READ(RX)	prefetch    [RX, 56]
-# define PREFETCH_WRITE(RX)	prefetchw   [RX, 64]
 # define LOADX(DST,RX)		ldd.ab	DST, [RX, 8]
 # define STOREX(SRC,RX)		std.ab	SRC, [RX, 8]
 # define ZOLSHFT		5
 # define ZOLAND			0x1F
 #else
-# define PREFETCH_READ(RX)	prefetch    [RX, 28]
-# define PREFETCH_WRITE(RX)	prefetchw   [RX, 32]
 # define LOADX(DST,RX)		ld.ab	DST, [RX, 4]
 # define STOREX(SRC,RX)		st.ab	SRC, [RX, 4]
 # define ZOLSHFT		4
@@ -41,8 +37,6 @@
 #endif
 
 ENTRY_CFI(memcpy)
-	prefetch [r1]		; Prefetch the read location
-	prefetchw [r0]		; Prefetch the write location
 	mov.f	0, r2
 ;;; if size is zero
 	jz.d	[blink]
@@ -72,8 +66,6 @@ ENTRY_CFI(memcpy)
 	lpnz	@.Lcopy32_64bytes
 	;; LOOP START
 	LOADX (r6, r1)
-	PREFETCH_READ (r1)
-	PREFETCH_WRITE (r3)
 	LOADX (r8, r1)
 	LOADX (r10, r1)
 	LOADX (r4, r1)
@@ -117,9 +109,7 @@ ENTRY_CFI(memcpy)
 	lpnz	@.Lcopy8bytes_1
 	;; LOOP START
 	ld.ab	r6, [r1, 4]
-	prefetch [r1, 28]	;Prefetch the next read location
 	ld.ab	r8, [r1,4]
-	prefetchw [r3, 32]	;Prefetch the next write location
 
 	SHIFT_1	(r7, r6, 24)
 	or	r7, r7, r5
@@ -162,9 +152,7 @@ ENTRY_CFI(memcpy)
 	lpnz	@.Lcopy8bytes_2
 	;; LOOP START
 	ld.ab	r6, [r1, 4]
-	prefetch [r1, 28]	;Prefetch the next read location
 	ld.ab	r8, [r1,4]
-	prefetchw [r3, 32]	;Prefetch the next write location
 
 	SHIFT_1	(r7, r6, 16)
 	or	r7, r7, r5
@@ -204,9 +192,7 @@ ENTRY_CFI(memcpy)
 	lpnz	@.Lcopy8bytes_3
 	;; LOOP START
 	ld.ab	r6, [r1, 4]
-	prefetch [r1, 28]	;Prefetch the next read location
 	ld.ab	r8, [r1,4]
-	prefetchw [r3, 32]	;Prefetch the next write location
 
 	SHIFT_1	(r7, r6, 8)
 	or	r7, r7, r5
-- 
2.14.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/5] ARCv2: introduce unaligned access under a Kconfig option
  2019-01-29 10:49 [PATCH 0/5] introduce unaligned access under a Kconfig option Eugeniy Paltsev
  2019-01-29 10:49 ` [PATCH 1/5] ARCv2: lib: memcpy: fix doing prefetchw outside of buffer Eugeniy Paltsev
@ 2019-01-29 10:49 ` Eugeniy Paltsev
  2019-01-29 21:44   ` Vineet Gupta
  2019-01-29 10:49 ` [PATCH 3/5] ARCv2: Enable unaligned access in early ASM code Eugeniy Paltsev
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 10+ messages in thread
From: Eugeniy Paltsev @ 2019-01-29 10:49 UTC (permalink / raw)
  To: linux-snps-arc, Vineet Gupta
  Cc: linux-kernel, Alexey Brodkin, Eugeniy Paltsev

As of today we enable unaligned access unconditionally on ARCv2.
Lets move it under Kconfig option so we can disable it in case of
using HW configuration which lacks of it.

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
---
 arch/arc/Kconfig                      | 8 ++++++++
 arch/arc/include/asm/irqflags-arcv2.h | 4 ++++
 arch/arc/kernel/intc-arcv2.c          | 4 +++-
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
index 376366a7db81..37c8aeefa3a5 100644
--- a/arch/arc/Kconfig
+++ b/arch/arc/Kconfig
@@ -387,6 +387,14 @@ config ARC_HAS_SWAPE
 
 if ISA_ARCV2
 
+config ARC_USE_UNALIGNED_MEM_ACCESS
+	bool "Handle unaligned access in HW and use it"
+	default y
+	help
+	  The ARC HS architecture supports unaligned memory access
+	  which is disabled by default. Enable unaligned access in
+	  hardware and use it in software.
+
 config ARC_HAS_LL64
 	bool "Insn: 64bit LDD/STD"
 	help
diff --git a/arch/arc/include/asm/irqflags-arcv2.h b/arch/arc/include/asm/irqflags-arcv2.h
index 8a4f77ea3238..9b911e2c6b31 100644
--- a/arch/arc/include/asm/irqflags-arcv2.h
+++ b/arch/arc/include/asm/irqflags-arcv2.h
@@ -44,8 +44,12 @@
 #define ARCV2_IRQ_DEF_PRIO	1
 
 /* seed value for status register */
+#ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS
 #define ISA_INIT_STATUS_BITS	(STATUS_IE_MASK | STATUS_AD_MASK | \
 					(ARCV2_IRQ_DEF_PRIO << 1))
+#else
+#define ISA_INIT_STATUS_BITS	(STATUS_IE_MASK | (ARCV2_IRQ_DEF_PRIO << 1))
+#endif /* CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS */
 
 #ifndef __ASSEMBLY__
 
diff --git a/arch/arc/kernel/intc-arcv2.c b/arch/arc/kernel/intc-arcv2.c
index 067ea362fb3e..84b1c7157d1b 100644
--- a/arch/arc/kernel/intc-arcv2.c
+++ b/arch/arc/kernel/intc-arcv2.c
@@ -93,7 +93,9 @@ void arc_init_IRQ(void)
 
 	/* setup status32, don't enable intr yet as kernel doesn't want */
 	tmp = read_aux_reg(ARC_REG_STATUS32);
-	tmp |= STATUS_AD_MASK | (ARCV2_IRQ_DEF_PRIO << 1);
+	if (IS_ENABLED(ARC_USE_UNALIGNED_MEM_ACCESS))
+		tmp |= STATUS_AD_MASK;
+	tmp |= ARCV2_IRQ_DEF_PRIO << 1;
 	tmp &= ~STATUS_IE_MASK;
 	asm volatile("kflag %0	\n"::"r"(tmp));
 }
-- 
2.14.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/5] ARCv2: Enable unaligned access in early ASM code
  2019-01-29 10:49 [PATCH 0/5] introduce unaligned access under a Kconfig option Eugeniy Paltsev
  2019-01-29 10:49 ` [PATCH 1/5] ARCv2: lib: memcpy: fix doing prefetchw outside of buffer Eugeniy Paltsev
  2019-01-29 10:49 ` [PATCH 2/5] ARCv2: introduce unaligned access under a Kconfig option Eugeniy Paltsev
@ 2019-01-29 10:49 ` Eugeniy Paltsev
  2019-01-29 10:49 ` [PATCH 4/5] ARCv2: use unaligned access in SW Eugeniy Paltsev
  2019-01-29 10:49 ` [PATCH 5/5] ARCv2: LIB: MEMCPY: fixed and optimised routine Eugeniy Paltsev
  4 siblings, 0 replies; 10+ messages in thread
From: Eugeniy Paltsev @ 2019-01-29 10:49 UTC (permalink / raw)
  To: linux-snps-arc, Vineet Gupta
  Cc: linux-kernel, Alexey Brodkin, Eugeniy Paltsev

Even though we do enable AD bit in arc_init_IRQ() we need to do
it in early ASM code otherwise we may face unaligned data until
we reach arc_init_IRQ() because GCC starting from v8.1.0 actively
generates unaligned data as it assumes that:
 * ARCv2 always has support of unaliged data
 * This support is turned on in runtime

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
---
 arch/arc/kernel/head.S       | 14 ++++++++++++++
 arch/arc/kernel/intc-arcv2.c |  2 --
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/arch/arc/kernel/head.S b/arch/arc/kernel/head.S
index 8b90d25a15cc..ffe3d384fca5 100644
--- a/arch/arc/kernel/head.S
+++ b/arch/arc/kernel/head.S
@@ -17,6 +17,9 @@
 #include <asm/entry.h>
 #include <asm/arcregs.h>
 #include <asm/cache.h>
+#ifdef CONFIG_ISA_ARCV2
+#include <asm/irqflags-arcv2.h>
+#endif
 
 .macro CPU_EARLY_SETUP
 
@@ -47,6 +50,17 @@
 	sr	r5, [ARC_REG_DC_CTRL]
 
 1:
+
+	; Enable / disable HW handling of unaligned access in the CPU.
+#ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS
+	kflag	STATUS_AD_MASK
+#else
+	; Handling of unaligned access is disabled by default but we disable it
+	; manually in case of any bootloader enabled it earlier.
+	lr	r5, [ARC_REG_STATUS32]
+	bclr	r5, r5, STATUS_AD_BIT
+	kflag	r5
+#endif
 .endm
 
 	.section .init.text, "ax",@progbits
diff --git a/arch/arc/kernel/intc-arcv2.c b/arch/arc/kernel/intc-arcv2.c
index 84b1c7157d1b..6359896da1ea 100644
--- a/arch/arc/kernel/intc-arcv2.c
+++ b/arch/arc/kernel/intc-arcv2.c
@@ -93,8 +93,6 @@ void arc_init_IRQ(void)
 
 	/* setup status32, don't enable intr yet as kernel doesn't want */
 	tmp = read_aux_reg(ARC_REG_STATUS32);
-	if (IS_ENABLED(ARC_USE_UNALIGNED_MEM_ACCESS))
-		tmp |= STATUS_AD_MASK;
 	tmp |= ARCV2_IRQ_DEF_PRIO << 1;
 	tmp &= ~STATUS_IE_MASK;
 	asm volatile("kflag %0	\n"::"r"(tmp));
-- 
2.14.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/5] ARCv2: use unaligned access in SW
  2019-01-29 10:49 [PATCH 0/5] introduce unaligned access under a Kconfig option Eugeniy Paltsev
                   ` (2 preceding siblings ...)
  2019-01-29 10:49 ` [PATCH 3/5] ARCv2: Enable unaligned access in early ASM code Eugeniy Paltsev
@ 2019-01-29 10:49 ` Eugeniy Paltsev
  2019-01-29 10:49 ` [PATCH 5/5] ARCv2: LIB: MEMCPY: fixed and optimised routine Eugeniy Paltsev
  4 siblings, 0 replies; 10+ messages in thread
From: Eugeniy Paltsev @ 2019-01-29 10:49 UTC (permalink / raw)
  To: linux-snps-arc, Vineet Gupta
  Cc: linux-kernel, Alexey Brodkin, Eugeniy Paltsev

Select HAVE_EFFICIENT_UNALIGNED_ACCESS and allow GCC to generate
unaligned data if we enable enable unaligned access in HW.

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
---
 arch/arc/Kconfig  | 1 +
 arch/arc/Makefile | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
index 37c8aeefa3a5..a1d976c612a6 100644
--- a/arch/arc/Kconfig
+++ b/arch/arc/Kconfig
@@ -390,6 +390,7 @@ if ISA_ARCV2
 config ARC_USE_UNALIGNED_MEM_ACCESS
 	bool "Handle unaligned access in HW and use it"
 	default y
+	select HAVE_EFFICIENT_UNALIGNED_ACCESS
 	help
 	  The ARC HS architecture supports unaligned memory access
 	  which is disabled by default. Enable unaligned access in
diff --git a/arch/arc/Makefile b/arch/arc/Makefile
index df00578c279d..e2b991f75bc5 100644
--- a/arch/arc/Makefile
+++ b/arch/arc/Makefile
@@ -28,6 +28,12 @@ cflags-$(CONFIG_ARC_HAS_SWAPE)		+= -mswape
 
 ifdef CONFIG_ISA_ARCV2
 
+ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS
+cflags-y				+= -munaligned-access
+else
+cflags-y				+= -mno-unaligned-access
+endif
+
 ifndef CONFIG_ARC_HAS_LL64
 cflags-y				+= -mno-ll64
 endif
-- 
2.14.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/5] ARCv2: LIB: MEMCPY: fixed and optimised routine
  2019-01-29 10:49 [PATCH 0/5] introduce unaligned access under a Kconfig option Eugeniy Paltsev
                   ` (3 preceding siblings ...)
  2019-01-29 10:49 ` [PATCH 4/5] ARCv2: use unaligned access in SW Eugeniy Paltsev
@ 2019-01-29 10:49 ` Eugeniy Paltsev
  2019-01-29 21:55   ` Vineet Gupta
  4 siblings, 1 reply; 10+ messages in thread
From: Eugeniy Paltsev @ 2019-01-29 10:49 UTC (permalink / raw)
  To: linux-snps-arc, Vineet Gupta
  Cc: linux-kernel, Alexey Brodkin, Eugeniy Paltsev

Optimise code to use efficient unaligned memory access which is
available on ARCv2. This allows us to really simplify memcpy code
and speed up the code one and a half times (in case of unaligned
source or destination).

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
---
 arch/arc/Kconfig                      |  4 +++
 arch/arc/lib/Makefile                 |  5 +++-
 arch/arc/lib/memcpy-archs-unaligned.S | 46 +++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 arch/arc/lib/memcpy-archs-unaligned.S

diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
index a1d976c612a6..88f1a3205b8f 100644
--- a/arch/arc/Kconfig
+++ b/arch/arc/Kconfig
@@ -396,6 +396,10 @@ config ARC_USE_UNALIGNED_MEM_ACCESS
 	  which is disabled by default. Enable unaligned access in
 	  hardware and use it in software.
 
+#dummy symbol for using in makefile
+config ARC_NO_UNALIGNED_MEM_ACCESS
+	def_bool !ARC_USE_UNALIGNED_MEM_ACCESS
+
 config ARC_HAS_LL64
 	bool "Insn: 64bit LDD/STD"
 	help
diff --git a/arch/arc/lib/Makefile b/arch/arc/lib/Makefile
index b1656d156097..59cc8b61342e 100644
--- a/arch/arc/lib/Makefile
+++ b/arch/arc/lib/Makefile
@@ -8,4 +8,7 @@
 lib-y	:= strchr-700.o strcpy-700.o strlen.o memcmp.o
 
 lib-$(CONFIG_ISA_ARCOMPACT)	+= memcpy-700.o memset.o strcmp.o
-lib-$(CONFIG_ISA_ARCV2)		+= memcpy-archs.o memset-archs.o strcmp-archs.o
+lib-$(CONFIG_ISA_ARCV2)		+= memset-archs.o strcmp-archs.o
+
+lib-$(CONFIG_ARC_NO_UNALIGNED_MEM_ACCESS)	+= memcpy-archs.o
+lib-$(CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS)	+= memcpy-archs-unaligned.o
diff --git a/arch/arc/lib/memcpy-archs-unaligned.S b/arch/arc/lib/memcpy-archs-unaligned.S
new file mode 100644
index 000000000000..e09b51d4de70
--- /dev/null
+++ b/arch/arc/lib/memcpy-archs-unaligned.S
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+//
+// ARCv2 memcpy implementation optimized for unaligned memory access using.
+//
+// Copyright (C) 2019 Synopsys
+// Author: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
+
+#include <linux/linkage.h>
+
+#ifdef CONFIG_ARC_HAS_LL64
+# define LOADX(DST,RX)		ldd.ab	DST, [RX, 8]
+# define STOREX(SRC,RX)		std.ab	SRC, [RX, 8]
+# define ZOLSHFT		5
+# define ZOLAND			0x1F
+#else
+# define LOADX(DST,RX)		ld.ab	DST, [RX, 4]
+# define STOREX(SRC,RX)		st.ab	SRC, [RX, 4]
+# define ZOLSHFT		4
+# define ZOLAND			0xF
+#endif
+
+ENTRY_CFI(memcpy)
+	mov	r3, r0		; don;t clobber ret val
+
+	lsr.f	lp_count, r2, ZOLSHFT
+	lpnz	@.Lcopy32_64bytes
+	;; LOOP START
+	LOADX	(r6, r1)
+	LOADX	(r8, r1)
+	LOADX	(r10, r1)
+	LOADX	(r4, r1)
+	STOREX	(r6, r3)
+	STOREX	(r8, r3)
+	STOREX	(r10, r3)
+	STOREX	(r4, r3)
+.Lcopy32_64bytes:
+
+	and.f	lp_count, r2, ZOLAND ;Last remaining 31 bytes
+	lpnz	@.Lcopyremainingbytes
+	;; LOOP START
+	ldb.ab	r5, [r1, 1]
+	stb.ab	r5, [r3, 1]
+.Lcopyremainingbytes:
+
+	j	[blink]
+END_CFI(memcpy)
-- 
2.14.5


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/5] ARCv2: introduce unaligned access under a Kconfig option
  2019-01-29 10:49 ` [PATCH 2/5] ARCv2: introduce unaligned access under a Kconfig option Eugeniy Paltsev
@ 2019-01-29 21:44   ` Vineet Gupta
  2019-01-30 16:44     ` Eugeniy Paltsev
  0 siblings, 1 reply; 10+ messages in thread
From: Vineet Gupta @ 2019-01-29 21:44 UTC (permalink / raw)
  To: Eugeniy Paltsev, linux-snps-arc; +Cc: linux-kernel, Alexey Brodkin

On 1/29/19 2:49 AM, Eugeniy Paltsev wrote:
> As of today we enable unaligned access unconditionally on ARCv2.
> Lets move it under Kconfig option so we can disable it in case of
> using HW configuration which lacks of it.
>
> Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
> ---
>  arch/arc/Kconfig                      | 8 ++++++++
>  arch/arc/include/asm/irqflags-arcv2.h | 4 ++++
>  arch/arc/kernel/intc-arcv2.c          | 4 +++-
>  3 files changed, 15 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
> index 376366a7db81..37c8aeefa3a5 100644
> --- a/arch/arc/Kconfig
> +++ b/arch/arc/Kconfig
> @@ -387,6 +387,14 @@ config ARC_HAS_SWAPE
>  
>  if ISA_ARCV2
>  
> +config ARC_USE_UNALIGNED_MEM_ACCESS
> +	bool "Handle unaligned access in HW and use it"
> +	default y
> +	help
> +	  The ARC HS architecture supports unaligned memory access
> +	  which is disabled by default. Enable unaligned access in
> +	  hardware and use it in software.
> +
>  config ARC_HAS_LL64
>  	bool "Insn: 64bit LDD/STD"
>  	help
> diff --git a/arch/arc/include/asm/irqflags-arcv2.h b/arch/arc/include/asm/irqflags-arcv2.h
> index 8a4f77ea3238..9b911e2c6b31 100644
> --- a/arch/arc/include/asm/irqflags-arcv2.h
> +++ b/arch/arc/include/asm/irqflags-arcv2.h
> @@ -44,8 +44,12 @@
>  #define ARCV2_IRQ_DEF_PRIO	1
>  
>  /* seed value for status register */
> +#ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS
>  #define ISA_INIT_STATUS_BITS	(STATUS_IE_MASK | STATUS_AD_MASK | \
>  					(ARCV2_IRQ_DEF_PRIO << 1))
> +#else
> +#define ISA_INIT_STATUS_BITS	(STATUS_IE_MASK | (ARCV2_IRQ_DEF_PRIO << 1))
> +#endif /* CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS */

I'd prefer to change the define of STATUS_AD_MASK itself and keep all of this
unchanged !

>  
>  #ifndef __ASSEMBLY__
>  
> diff --git a/arch/arc/kernel/intc-arcv2.c b/arch/arc/kernel/intc-arcv2.c
> index 067ea362fb3e..84b1c7157d1b 100644
> --- a/arch/arc/kernel/intc-arcv2.c
> +++ b/arch/arc/kernel/intc-arcv2.c
> @@ -93,7 +93,9 @@ void arc_init_IRQ(void)
>  
>  	/* setup status32, don't enable intr yet as kernel doesn't want */
>  	tmp = read_aux_reg(ARC_REG_STATUS32);
> -	tmp |= STATUS_AD_MASK | (ARCV2_IRQ_DEF_PRIO << 1);
> +	if (IS_ENABLED(ARC_USE_UNALIGNED_MEM_ACCESS))
> +		tmp |= STATUS_AD_MASK;
> +	tmp |= ARCV2_IRQ_DEF_PRIO << 1;

This will change after rebase as we just need to delete the code here, done in head.S

>  	tmp &= ~STATUS_IE_MASK;
>  	asm volatile("kflag %0	\n"::"r"(tmp));
>  }


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 5/5] ARCv2: LIB: MEMCPY: fixed and optimised routine
  2019-01-29 10:49 ` [PATCH 5/5] ARCv2: LIB: MEMCPY: fixed and optimised routine Eugeniy Paltsev
@ 2019-01-29 21:55   ` Vineet Gupta
  0 siblings, 0 replies; 10+ messages in thread
From: Vineet Gupta @ 2019-01-29 21:55 UTC (permalink / raw)
  To: Eugeniy Paltsev, linux-snps-arc; +Cc: linux-kernel, Alexey Brodkin

On 1/29/19 2:49 AM, Eugeniy Paltsev wrote:
> Optimise code to use efficient unaligned memory access which is
> available on ARCv2. This allows us to really simplify memcpy code
> and speed up the code one and a half times (in case of unaligned
> source or destination).
>
> Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
> ---
>  arch/arc/Kconfig                      |  4 +++
>  arch/arc/lib/Makefile                 |  5 +++-
>  arch/arc/lib/memcpy-archs-unaligned.S | 46 +++++++++++++++++++++++++++++++++++
>  3 files changed, 54 insertions(+), 1 deletion(-)
>  create mode 100644 arch/arc/lib/memcpy-archs-unaligned.S
>
> diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig
> index a1d976c612a6..88f1a3205b8f 100644
> --- a/arch/arc/Kconfig
> +++ b/arch/arc/Kconfig
> @@ -396,6 +396,10 @@ config ARC_USE_UNALIGNED_MEM_ACCESS
>  	  which is disabled by default. Enable unaligned access in
>  	  hardware and use it in software.
>  
> +#dummy symbol for using in makefile
> +config ARC_NO_UNALIGNED_MEM_ACCESS
> +	def_bool !ARC_USE_UNALIGNED_MEM_ACCESS
> +

Not needed - you can use the kconfig symbols in Makefile.
See arch/arc/kernel/Makefile

>  config ARC_HAS_LL64
>  	bool "Insn: 64bit LDD/STD"
>  	help
> diff --git a/arch/arc/lib/Makefile b/arch/arc/lib/Makefile
> index b1656d156097..59cc8b61342e 100644
> --- a/arch/arc/lib/Makefile
> +++ b/arch/arc/lib/Makefile
> @@ -8,4 +8,7 @@
>  lib-y	:= strchr-700.o strcpy-700.o strlen.o memcmp.o
>  
>  lib-$(CONFIG_ISA_ARCOMPACT)	+= memcpy-700.o memset.o strcmp.o
> -lib-$(CONFIG_ISA_ARCV2)		+= memcpy-archs.o memset-archs.o strcmp-archs.o
> +lib-$(CONFIG_ISA_ARCV2)		+= memset-archs.o strcmp-archs.o
> +
> +lib-$(CONFIG_ARC_NO_UNALIGNED_MEM_ACCESS)	+= memcpy-archs.o
> +lib-$(CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS)	+= memcpy-archs-unaligned.o

ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS
lib-$(CONFIG_ISA_ARCV2) +=memcpy-archs-unaligned.o
else
lib-$(CONFIG_ISA_ARCV2) +=memcpy-archs.o
endif

> diff --git a/arch/arc/lib/memcpy-archs-unaligned.S b/arch/arc/lib/memcpy-archs-unaligned.S
> new file mode 100644
> index 000000000000..e09b51d4de70
> --- /dev/null
> +++ b/arch/arc/lib/memcpy-archs-unaligned.S
> @@ -0,0 +1,46 @@
> +/* SPDX-License-Identifier: GPL-2.0+ */
> +//
> +// ARCv2 memcpy implementation optimized for unaligned memory access using.
> +//
> +// Copyright (C) 2019 Synopsys
> +// Author: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
> +
> +#include <linux/linkage.h>
> +
> +#ifdef CONFIG_ARC_HAS_LL64
> +# define LOADX(DST,RX)		ldd.ab	DST, [RX, 8]
> +# define STOREX(SRC,RX)		std.ab	SRC, [RX, 8]
> +# define ZOLSHFT		5
> +# define ZOLAND			0x1F
> +#else
> +# define LOADX(DST,RX)		ld.ab	DST, [RX, 4]
> +# define STOREX(SRC,RX)		st.ab	SRC, [RX, 4]
> +# define ZOLSHFT		4
> +# define ZOLAND			0xF
> +#endif
> +
> +ENTRY_CFI(memcpy)
> +	mov	r3, r0		; don;t clobber ret val
> +
> +	lsr.f	lp_count, r2, ZOLSHFT
> +	lpnz	@.Lcopy32_64bytes
> +	;; LOOP START
> +	LOADX	(r6, r1)
> +	LOADX	(r8, r1)
> +	LOADX	(r10, r1)
> +	LOADX	(r4, r1)
> +	STOREX	(r6, r3)
> +	STOREX	(r8, r3)
> +	STOREX	(r10, r3)
> +	STOREX	(r4, r3)
> +.Lcopy32_64bytes:
> +
> +	and.f	lp_count, r2, ZOLAND ;Last remaining 31 bytes
> +	lpnz	@.Lcopyremainingbytes
> +	;; LOOP START
> +	ldb.ab	r5, [r1, 1]
> +	stb.ab	r5, [r3, 1]



> +.Lcopyremainingbytes:
> +
> +	j	[blink]
> +END_CFI(memcpy)


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/5] ARCv2: introduce unaligned access under a Kconfig option
  2019-01-29 21:44   ` Vineet Gupta
@ 2019-01-30 16:44     ` Eugeniy Paltsev
  2019-01-30 16:47       ` Vineet Gupta
  0 siblings, 1 reply; 10+ messages in thread
From: Eugeniy Paltsev @ 2019-01-30 16:44 UTC (permalink / raw)
  To: Eugeniy.Paltsev@synopsys.com, Vineet Gupta, linux-snps-arc
  Cc: linux-kernel, Alexey Brodkin

On Tue, 2019-01-29 at 21:44 +0000, Vineet Gupta wrote:
> On 1/29/19 2:49 AM, Eugeniy Paltsev wrote:
> > As of today we enable unaligned access unconditionally on ARCv2.
> > Lets move it under Kconfig option so we can disable it in case of
> > using HW configuration which lacks of it.
> > 
> > Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
> > ---
> >  arch/arc/Kconfig                      | 8 ++++++++
> >  arch/arc/include/asm/irqflags-arcv2.h | 4 ++++
> >  arch/arc/kernel/intc-arcv2.c          | 4 +++-
> >  3 files changed, 15 insertions(+), 1 deletion(-)
> > 
> > diff --git a/arch/arc/include/asm/irqflags-arcv2.h b/arch/arc/include/asm/irqflags-arcv2.h
> > index 8a4f77ea3238..9b911e2c6b31 100644
> > --- a/arch/arc/include/asm/irqflags-arcv2.h
> > +++ b/arch/arc/include/asm/irqflags-arcv2.h
> > @@ -44,8 +44,12 @@
> >  #define ARCV2_IRQ_DEF_PRIO	1
> >  
> >  /* seed value for status register */
> > +#ifdef CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS
> >  #define ISA_INIT_STATUS_BITS	(STATUS_IE_MASK | STATUS_AD_MASK | \
> >  					(ARCV2_IRQ_DEF_PRIO << 1))
> > +#else
> > +#define ISA_INIT_STATUS_BITS	(STATUS_IE_MASK | (ARCV2_IRQ_DEF_PRIO << 1))
> > +#endif /* CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS */
> 
> I'd prefer to change the define of STATUS_AD_MASK itself and keep all of this
> unchanged !
> 

Actually I'd prefer to leave STATUS_AD_MASK untouched. Otherwise we will implicitly assign
wrong value to STATUS_AD_MASK which is quite misleading.

BTW, STATUS_AD_MASK is used in ASM code in v2 patch and it shouldn't be dependent on
CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS.

-- 
 Eugeniy Paltsev

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/5] ARCv2: introduce unaligned access under a Kconfig option
  2019-01-30 16:44     ` Eugeniy Paltsev
@ 2019-01-30 16:47       ` Vineet Gupta
  0 siblings, 0 replies; 10+ messages in thread
From: Vineet Gupta @ 2019-01-30 16:47 UTC (permalink / raw)
  To: Eugeniy Paltsev, Eugeniy.Paltsev@synopsys.com, linux-snps-arc
  Cc: linux-kernel, Alexey Brodkin

On 1/30/19 8:44 AM, Eugeniy Paltsev wrote:
>> I'd prefer to change the define of STATUS_AD_MASK itself and keep all of this
>> unchanged !
>>
> Actually I'd prefer to leave STATUS_AD_MASK untouched. Otherwise we will implicitly assign
> wrong value to STATUS_AD_MASK which is quite misleading.
>
> BTW, STATUS_AD_MASK is used in ASM code in v2 patch and it shouldn't be dependent on
> CONFIG_ARC_USE_UNALIGNED_MEM_ACCESS.

Agree !

-Vineet

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2019-01-30 16:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-29 10:49 [PATCH 0/5] introduce unaligned access under a Kconfig option Eugeniy Paltsev
2019-01-29 10:49 ` [PATCH 1/5] ARCv2: lib: memcpy: fix doing prefetchw outside of buffer Eugeniy Paltsev
2019-01-29 10:49 ` [PATCH 2/5] ARCv2: introduce unaligned access under a Kconfig option Eugeniy Paltsev
2019-01-29 21:44   ` Vineet Gupta
2019-01-30 16:44     ` Eugeniy Paltsev
2019-01-30 16:47       ` Vineet Gupta
2019-01-29 10:49 ` [PATCH 3/5] ARCv2: Enable unaligned access in early ASM code Eugeniy Paltsev
2019-01-29 10:49 ` [PATCH 4/5] ARCv2: use unaligned access in SW Eugeniy Paltsev
2019-01-29 10:49 ` [PATCH 5/5] ARCv2: LIB: MEMCPY: fixed and optimised routine Eugeniy Paltsev
2019-01-29 21:55   ` Vineet Gupta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).