Skip to contentSkip to conversation

arm: Fix mounting root on omaps with CPU_V6 and CPU_V7

PATCH New Tony Lindgren 4 participants 14 messages Mar 17, 2010 – Mar 23, 2010 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm: Fix mounting root on omaps with CPU_V6 and CPU_V7

Hi all,

Here's an updated version of this patch with more details.

Looks like VFPv3 is only available on V7:

http://www.arm.com/products/processors/technologies/vector-floating-point.php

HAS_TLS reg is only on ARM11 starting with r1p0:

http://infocenter.arm.com/help/topic/com.arm.doc.ddi0211k/Babeihid.html

So that explains why it won't work on omap2420 as it's r0p2.

Regards,

Tony

Quoted 1 line

From adebf62d18a03ed26ec20f95860976f80690e9f1 Mon Sep 17 00:00:00 2001

From: Tony Lindgren <[email protected]>
Date: Mon, 15 Mar 2010 15:25:43 -0700
Subject: [PATCH] arm: Fix mounting root on omaps with CPU_V6 and CPU_V7

To mount root on omap2420, we need to disable VFPv3 and HAS_TLS_REG.

VFPv3 is only available on CPU_V7. TLS_REG is only available on ARM11 starting with r1p0 and later. As omap2420 is r0p2, it does not have TLS_REG.

Otherwise we'll get something like this for CPUv3:

Freeing init memory: 184K

Internal error: Oops - undefined instruction: 0 [#1]
last sysfs file:
Modules linked in:
CPU: 0    Not tainted  (2.6.33-rc8-07824-gf2e1d91-dirty #36)
PC is at no_old_VFP_process+0x8/0x3c
LR is at __und_usr_unknown+0x0/0x14

...

Or the system just hangs if HAS_TLS_REG is set.

arch/arm/Kconfig +1 -1
index d97d893..409ae23 100644
@@ -1549,7 +1549,7 @@ config VFP
 config VFPv3
 	bool
 	depends on VFP
-	default y if CPU_V7
+	default y if CPU_V7 && !CPU_V6
 
 config NEON
 	bool "Advanced SIMD (NEON) Extension support"
arch/arm/mm/Kconfig +3 -3
index c4ed9f9..ff0c829 100644
@@ -718,11 +718,11 @@ config TLS_REG_EMUL
 config HAS_TLS_REG
 	bool
 	depends on !TLS_REG_EMUL
-	default y if SMP || CPU_32v7
+	default y if (SMP || CPU_32v7) && !ARCH_OMAP2
 	help
 	  This selects support for the CP15 thread register.
-	  It is defined to be available on some ARMv6 processors (including
-	  all SMP capable ARMv6's) or later processors.  User space may
+	  It is defined to be available on some ARMv6 processors (r1p0 and
+	  later, including all SMP capable ARMv6's).  User space may
 	  assume directly accessing that register and always obtain the
 	  expected value only on ARMv7 and above.
 
#1 lore raw

PATCH 1/1 arm: Fix mounting root on omaps with CPU_V6 and CPU_V7

Quoted 5 lines · Tony Lindgren

Here's an updated version of this patch with more details.

Looks like VFPv3 is only available on V7:

http://www.arm.com/products/processors/technologies/vector-floating-point.php

But does it cause any problem if the feature is enabled in the kernel? The vfp_init() code should check for its presence and set the hwcap accordingly.

Ideally, we should fix the VFP handling code to cope with dynamic detection.

Quoted 5 lines

HAS_TLS reg is only on ARM11 starting with r1p0:

http://infocenter.arm.com/help/topic/com.arm.doc.ddi0211k/Babeihid.html

So that explains why it won't work on omap2420 as it's r0p2.

Same here, would it work with dynamic detection?

I would like to get v6+v7 support working fine together on RealView boards as well (though not much spare time) but without disabling the features that are present on v7 if they can be detected at run-time.

Signature · 1 line
Catalin
#2 lore raw

PATCH 1/1 arm: Fix mounting root on omaps with CPU_V6 and CPU_V7

Quoted 10 lines · Catalin Marinas
Quoted 5 lines · Tony Lindgren

Here's an updated version of this patch with more details.

Looks like VFPv3 is only available on V7:

http://www.arm.com/products/processors/technologies/vector-floating-point.php

But does it cause any problem if the feature is enabled in the kernel? The vfp_init() code should check for its presence and set the hwcap accordingly.

Yeah, it causes the problem posted in the patch description. I took a quick look at it and at least the VFPFMRX in vfpmacros.h for CONFIG_VFPv3 is a problem.

Also I think we would need to have separate vfp_get_double functions in vfphw.S for VFPv2 and 3 that get used based on the features.

Quoted 2 lines

Ideally, we should fix the VFP handling code to cope with dynamic detection.

I agree, being able to boot the same kernel and avoiding tens of recompiles to test something is a major time saver :)

Quoted 7 lines
Quoted 5 lines

HAS_TLS reg is only on ARM11 starting with r1p0:

http://infocenter.arm.com/help/topic/com.arm.doc.ddi0211k/Babeihid.html

So that explains why it won't work on omap2420 as it's r0p2.

Same here, would it work with dynamic detection?

Hmm I believe here the problem is __switch_to in entry-armv.S. I don't think we want to dynamically test it every time.. Or at least it would have to be optimized out in most cases.

Quoted 3 lines

I would like to get v6+v7 support working fine together on RealView boards as well (though not much spare time) but without disabling the features that are present on v7 if they can be detected at run-time.

I totally agree with you there.

Regards,

Tony

#3 lore raw

PATCH 1/1 arm: Fix mounting root on omaps with CPU_V6 and CPU_V7

Quoted 8 lines · Tony Lindgren
Quoted 7 lines · Catalin Marinas
Quoted 5 lines · Tony Lindgren

Here's an updated version of this patch with more details.

Looks like VFPv3 is only available on V7:

http://www.arm.com/products/processors/technologies/vector-floating-point.php

Quoted 7 lines
Quoted 3 lines

But does it cause any problem if the feature is enabled in the kernel? The vfp_init() code should check for its presence and set the hwcap accordingly.

Yeah, it causes the problem posted in the patch description. I took a quick look at it and at least the VFPFMRX in vfpmacros.h for CONFIG_VFPv3 is a problem.

This would indeed need more checking to avoid reading some registers which aren't present on ARMv6.

I think the main problem with just falling back to VFPv2 is the lack of NEON support even if the CPU supports it.

Quoted 2 lines

Also I think we would need to have separate vfp_get_double functions in vfphw.S for VFPv2 and 3 that get used based on the features.

I don't think that's causing problems (or at least we can identify where the function gets called for higher VFP registers). Even with VFPv3, you may not have the D16-D31 registers.

Quoted 11 lines
Quoted 7 lines
Quoted 5 lines

HAS_TLS reg is only on ARM11 starting with r1p0:

http://infocenter.arm.com/help/topic/com.arm.doc.ddi0211k/Babeihid.html

So that explains why it won't work on omap2420 as it's r0p2.

Same here, would it work with dynamic detection?

Hmm I believe here the problem is __switch_to in entry-armv.S. I don't think we want to dynamically test it every time.. Or at least it would have to be optimized out in most cases.

But if you disable this, you won't be able to use an SMP build on both v6 and v7. Anyway, I don't think that dynamically checking this would introduce performance penalties, the __switch_to code is pretty complex already with all the notifier calls.

We may also have optimised user space that reads the TLS register directly rather than going through the kuser helper, in which case we would need a kernel built only for ARMv7 (maybe that's acceptable in this situation).

Signature · 1 line
Catalin
#4 lore raw

PATCH 1/1 arm: Fix mounting root on omaps with CPU_V6 and CPU_V7

Quoted 17 lines · Catalin Marinas
Quoted 8 lines · Tony Lindgren
Quoted 7 lines · Catalin Marinas
Quoted 5 lines · Tony Lindgren

Here's an updated version of this patch with more details.

Looks like VFPv3 is only available on V7:

http://www.arm.com/products/processors/technologies/vector-floating-point.php

Quoted 7 lines
Quoted 3 lines

But does it cause any problem if the feature is enabled in the kernel? The vfp_init() code should check for its presence and set the hwcap accordingly.

Yeah, it causes the problem posted in the patch description. I took a quick look at it and at least the VFPFMRX in vfpmacros.h for CONFIG_VFPv3 is a problem.

Quoted 5 lines

This would indeed need more checking to avoid reading some registers which aren't present on ARMv6.

I think the main problem with just falling back to VFPv2 is the lack of NEON support even if the CPU supports it.

Yeah it would be nice to have things also working in a reasonably fast and usable way for distros etc.

Quoted 6 lines
Quoted 2 lines

Also I think we would need to have separate vfp_get_double functions in vfphw.S for VFPv2 and 3 that get used based on the features.

I don't think that's causing problems (or at least we can identify where the function gets called for higher VFP registers). Even with VFPv3, you may not have the D16-D31 registers.

OK. There's also an ifdef else define for VFP_REG_ZERO in vfp.h. Sounds like that test would also need to be done dynamically.

Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines

HAS_TLS reg is only on ARM11 starting with r1p0:

http://infocenter.arm.com/help/topic/com.arm.doc.ddi0211k/Babeihid.html

So that explains why it won't work on omap2420 as it's r0p2.

Same here, would it work with dynamic detection?

Quoted 8 lines
Quoted 3 lines

Hmm I believe here the problem is __switch_to in entry-armv.S. I don't think we want to dynamically test it every time.. Or at least it would have to be optimized out in most cases.

But if you disable this, you won't be able to use an SMP build on both v6 and v7. Anyway, I don't think that dynamically checking this would introduce performance penalties, the __switch_to code is pretty complex already with all the notifier calls.

OK. I'll take a look at setting the TLS a HWCAP flag.

Quoted 4 lines

We may also have optimised user space that reads the TLS register directly rather than going through the kuser helper, in which case we would need a kernel built only for ARMv7 (maybe that's acceptable in this situation).

Sounds like more of a hassle to me :)

Tony

#5 lore raw

PATCH 1/1 arm: Replace CONFIG_HAS_TLS_REG with HWCAP_TLS and check for it on V6

Quoted 16 lines · Tony Lindgren
Quoted 15 lines · Catalin Marinas
Quoted 13 lines · Tony Lindgren
Quoted 8 lines · Catalin Marinas
Quoted 5 lines · Tony Lindgren

HAS_TLS reg is only on ARM11 starting with r1p0:

http://infocenter.arm.com/help/topic/com.arm.doc.ddi0211k/Babeihid.html

So that explains why it won't work on omap2420 as it's r0p2.

Same here, would it work with dynamic detection?

Hmm I believe here the problem is __switch_to in entry-armv.S. I don't think we want to dynamically test it every time.. Or at least it would have to be optimized out in most cases.

Quoted 6 lines
Quoted 4 lines

But if you disable this, you won't be able to use an SMP build on both v6 and v7. Anyway, I don't think that dynamically checking this would introduce performance penalties, the __switch_to code is pretty complex already with all the notifier calls.

OK. I'll take a look at setting the TLS a HWCAP flag.

Below is a patch for convert CONFIG_HAS_TLS_REG into HWCAP_TLS.

I've tested it with V6 r0p2 with no HWCAP_TLS, and V7 that has HWCAP_TLS. I also forced CONFIG_TLS_REG_EMUL and booted on V6 r0p2, and it booted OK.

Could somebody please test this patch on a real CONFIG_TLS_REG_EMUL system?

Also, I wonder if the change __kuser_get_tls is safe?

I changed it to assume that if 0xffff0ff0 == 0, then we have HWCAP_TLS.

Regards,

Tony

Quoted 1 line

From 81d4bf2481c4ef5fd80261605977b5f55e4515e4 Mon Sep 17 00:00:00 2001

From: Tony Lindgren <[email protected]>
Date: Thu, 18 Mar 2010 12:02:43 -0700
Subject: [PATCH] arm: Replace CONFIG_HAS_TLS_REG with HWCAP_TLS and check for it on V6

The TLS register is only available on V6 r1p0 and later. Test for it and use it if available.

arch/arm/include/asm/hwcap.h +1 -0
index f7bd52b..c1062c3 100644
@@ -19,6 +19,7 @@
 #define HWCAP_NEON	4096
 #define HWCAP_VFPv3	8192
 #define HWCAP_VFPv3D16	16384
+#define HWCAP_TLS	32768
 
 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
 /*
arch/arm/kernel/entry-armv.S +11 -12
index 6c5cf36..5a5aac8 100644
@@ -739,11 +739,13 @@ ENTRY(__switch_to)
 #ifdef CONFIG_MMU
 	ldr	r6, [r2, #TI_CPU_DOMAIN]
 #endif
-#if defined(CONFIG_HAS_TLS_REG)
-	mcr	p15, 0, r3, c13, c0, 3		@ set TLS register
-#elif !defined(CONFIG_TLS_REG_EMUL)
-	mov	r4, #0xffff0fff
-	str	r3, [r4, #-15]			@ TLS val at 0xffff0ff0
+#if !defined(CONFIG_TLS_REG_EMUL)
+	ldr	r4, =elf_hwcap
+	ldr	r4, [r4, #0]
+	tst	r4, #HWCAP_TLS			@ hardware with TLS?
+	mcrne	p15, 0, r3, c13, c0, 3		@ set TLS register
+	moveq	r4, #0xffff0fff
+	streq	r3, [r4, #-15]			@ TLS val at 0xffff0ff0
 #endif
 #ifdef CONFIG_MMU
 	mcr	p15, 0, r6, c3, c0, 0		@ Set domain register
@@ -1009,15 +1011,12 @@ kuser_cmpxchg_fixup:
  */
 
 __kuser_get_tls:				@ 0xffff0fe0
-
-#if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL)
-	ldr	r0, [pc, #(16 - 8)]		@ TLS stored at 0xffff0ff0
-#else
-	mrc	p15, 0, r0, c13, c0, 3		@ read TLS register
-#endif
+	ldr     r0, [pc, #(16 - 8)]		@ TLS set at 0xffff0ff0?
+	cmp	r0, #0				@ assume hw TLS if not set
+	mrceq	p15, 0, r0, c13, c0, 3		@ read TLS register
 	usr_ret	lr
 
-	.rep	5
+	.rep	3
 	.word	0			@ pad up to __kuser_helper_version
 	.endr
 
arch/arm/kernel/setup.c +20 -0
index c91c77b..de9d2dc 100644
@@ -269,6 +269,24 @@ static void __init cacheid_init(void)
 extern struct proc_info_list *lookup_processor_type(unsigned int);
 extern struct machine_desc *lookup_machine_type(unsigned int);
 
+#ifdef CONFIG_CPU_V6
+static void __init feat_v6_fixup(void)
+{
+	int id = read_cpuid_id();
+
+	if (id & 0x000f0000 != 0x00070000)
+		return;
+
+	/* HWCAP_TLS is available only on V6 r1p0 and later */
+	if (((id >> 20) & 3) == 0)
+		elf_hwcap &= ~HWCAP_TLS;
+}
+#else
+static inline void feat_v6_fixup(void)
+{
+}
+#endif
+
 static void __init setup_processor(void)
 {
 	struct proc_info_list *list;
@@ -311,6 +329,8 @@ static void __init setup_processor(void)
 	elf_hwcap &= ~HWCAP_THUMB;
 #endif
 
+	feat_v6_fixup();
+
 	cacheid_init();
 	cpu_proc_init();
 }
arch/arm/kernel/traps.c +13 -10
index 1621e53..bdffef5 100644
@@ -518,16 +518,19 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
 
 	case NR(set_tls):
 		thread->tp_value = regs->ARM_r0;
-#if defined(CONFIG_HAS_TLS_REG)
-		asm ("mcr p15, 0, %0, c13, c0, 3" : : "r" (regs->ARM_r0) );
-#elif !defined(CONFIG_TLS_REG_EMUL)
-		/*
-		 * User space must never try to access this directly.
-		 * Expect your app to break eventually if you do so.
-		 * The user helper at 0xffff0fe0 must be used instead.
-		 * (see entry-armv.S for details)
-		 */
-		*((unsigned int *)0xffff0ff0) = regs->ARM_r0;
+#if !defined(CONFIG_TLS_REG_EMUL)
+		if (elf_hwcap & HWCAP_TLS) {
+			asm ("mcr p15, 0, %0, c13, c0, 3"
+				: : "r" (regs->ARM_r0));
+		} else {
+			/*
+			 * User space must never try to access this directly.
+			 * Expect your app to break eventually if you do so.
+			 * The user helper at 0xffff0fe0 must be used instead.
+			 * (see entry-armv.S for details)
+			 */
+			*((unsigned int *)0xffff0ff0) = regs->ARM_r0;
+		}
 #endif
 		return 0;
 
arch/arm/mm/Kconfig +0 -11
index c4ed9f9..45e99c1 100644
@@ -715,17 +715,6 @@ config TLS_REG_EMUL
 	  a few prototypes like that in existence) and therefore access to
 	  that required register must be emulated.
 
-config HAS_TLS_REG
-	bool
-	depends on !TLS_REG_EMUL
-	default y if SMP || CPU_32v7
-	help
-	  This selects support for the CP15 thread register.
-	  It is defined to be available on some ARMv6 processors (including
-	  all SMP capable ARMv6's) or later processors.  User space may
-	  assume directly accessing that register and always obtain the
-	  expected value only on ARMv7 and above.
-
 config NEEDS_SYSCALL_FOR_CMPXCHG
 	bool
 	help
arch/arm/mm/proc-v6.S +4 -2
index 7a5337e..e10626a 100644
@@ -239,7 +239,8 @@ __v6_proc_info:
 	b	__v6_setup
 	.long	cpu_arch_name
 	.long	cpu_elf_name
-	.long	HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_JAVA
+	/* See also feat_v6_fixup() for HWCAP_TLS */
+	.long	HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_JAVA|HWCAP_TLS
 	.long	cpu_v6_name
 	.long	v6_processor_functions
 	.long	v6wbi_tlb_fns
@@ -262,7 +263,8 @@ __pj4_v6_proc_info:
 	b	__v6_setup
 	.long	cpu_arch_name
 	.long	cpu_elf_name
-	.long	HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
+	/* See also feat_v6_fixup() for HWCAP_TLS */
+	.long	HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_TLS
 	.long	cpu_pj4_name
 	.long	v6_processor_functions
 	.long	v6wbi_tlb_fns
arch/arm/mm/proc-v7.S +1 -1
index 7aaf88a..8071bcd 100644
@@ -344,7 +344,7 @@ __v7_proc_info:
 	b	__v7_setup
 	.long	cpu_arch_name
 	.long	cpu_elf_name
-	.long	HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
+	.long	HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_TLS
 	.long	cpu_v7_name
 	.long	v7_processor_functions
 	.long	v7wbi_tlb_fns
#6 lore raw

PATCH 1/1 arm: Replace CONFIG_HAS_TLS_REG with HWCAP_TLS and check for it on V6

Quoted 8 lines · Tony Lindgren
arch/arm/kernel/setup.c +2 -0
@@ -269,6 +269,24 @@ static void __init cacheid_init(void)
 extern struct proc_info_list *lookup_processor_type(unsigned int);
 extern struct machine_desc *lookup_machine_type(unsigned int);
 
+#ifdef CONFIG_CPU_V6
+static void __init feat_v6_fixup(void)

arch/arm/kernel/setup.c static void __init cacheid_init(void) · line 283

Quoted 10 lines
arch/arm/kernel/setup.c +10 -0
+{
+	int id = read_cpuid_id();
+
+	if (id & 0x000f0000 != 0x00070000)
+		return;
+
+	/* HWCAP_TLS is available only on V6 r1p0 and later */
+	if (((id >> 20) & 3) == 0)
+		elf_hwcap &= ~HWCAP_TLS;
+}

This test probably needs to only look at ARM1136, and ignore others such as ARM1176. Will take a look tomorrow.

Tony

#7 lore raw

PATCH 1/1 arm: Replace CONFIG_HAS_TLS_REG with HWCAP_TLS and check for it on V6

In reply to Tony Lindgren

Review

Quoted 5 lines · Tony Lindgren

Also, I wonder if the change __kuser_get_tls is safe?

(quoted diff) +3 -0
+	ldr     r0, [pc, #(16 - 8)]		@ TLS set at 0xffff0ff0?
+	cmp	r0, #0				@ assume hw TLS if not set
+	mrceq	p15, 0, r0, c13, c0, 3		@ read TLS register

You cannot assume the TLS value is non-zero, because it's provided by userspace to use however it wants. It doesn't even have to be an address.

I'm thinking, why not an alternative() macro like on x86, which is a very nice way to describe run-time patches of one or a few instructions which depend on arch feature bits.

Then all that switch_to() logic could be made the size it was before.

An alternative() macro could make a lot of other chip-dependent calls smaller too, i.e. all those which dispatch through function pointers at present for cache flushing etc - they could become direct calls, or an inline instruction or two when possible.

-- Jamie

#8 lore raw

PATCH 1/1 arm: Replace CONFIG_HAS_TLS_REG with HWCAP_TLS and check for it on V6

Quoted 3 lines · Jamie Lokier

I'm thinking, why not an alternative() macro like on x86, which is a very nice way to describe run-time patches of one or a few instructions which depend on arch feature bits.

Having XIP support prevents that kind of thing.

#9 lore raw

PATCH 1/1 arm: Replace CONFIG_HAS_TLS_REG with HWCAP_TLS and check for it on V6

Quoted 6 lines · Russell King - ARM Linux
Quoted 3 lines · Jamie Lokier

I'm thinking, why not an alternative() macro like on x86, which is a very nice way to describe run-time patches of one or a few instructions which depend on arch feature bits.

Having XIP support prevents that kind of thing.

How about we store the HWCAP_TLS flag into 0xffff0ff4 for __kuser_get_tls? That way the userspace won't be able to set it.

Tony

#10 lore raw

PATCH 1/1 arm: Replace CONFIG_HAS_TLS_REG with HWCAP_TLS and check for it on V6

In reply to Tony Lindgren

Review

Quoted 9 lines · Tony Lindgren
(quoted diff) +4 -5
-#if defined(CONFIG_HAS_TLS_REG)
-	mcr	p15, 0, r3, c13, c0, 3		@ set TLS register
-#elif !defined(CONFIG_TLS_REG_EMUL)
-	mov	r4, #0xffff0fff
-	str	r3, [r4, #-15]			@ TLS val at 0xffff0ff0
+#if !defined(CONFIG_TLS_REG_EMUL)
+	ldr	r4, =elf_hwcap
+	ldr	r4, [r4, #0]
+	tst	r4, #HWCAP_TLS			@ hardware with TLS?

This is really really inefficient. Both the second ldr and tst will stall the pipeline because they need to wait for the result of the precending ldr. Can we do better by re-ordering some instructions?

Also, the ifndef seems incorrect - if we have TLS_REG_EMUL we seem to omit all this code.

#11 lore raw

PATCH 1/1 arm: Replace CONFIG_HAS_TLS_REG with HWCAP_TLS and check for it on V6

Quoted 14 lines · Russell King - ARM Linux

Review

Quoted 9 lines · Tony Lindgren
(quoted diff) +4 -5
-#if defined(CONFIG_HAS_TLS_REG)
-	mcr	p15, 0, r3, c13, c0, 3		@ set TLS register
-#elif !defined(CONFIG_TLS_REG_EMUL)
-	mov	r4, #0xffff0fff
-	str	r3, [r4, #-15]			@ TLS val at 0xffff0ff0
+#if !defined(CONFIG_TLS_REG_EMUL)
+	ldr	r4, =elf_hwcap
+	ldr	r4, [r4, #0]
+	tst	r4, #HWCAP_TLS			@ hardware with TLS?

This is really really inefficient. Both the second ldr and tst will stall the pipeline because they need to wait for the result of the precending ldr. Can we do better by re-ordering some instructions?

Or set ifdef CONFIG_CPU_V6 and test for the cp15 id register every time..

Quoted 2 lines

Also, the ifndef seems incorrect - if we have TLS_REG_EMUL we seem to omit all this code.

Is the current ifdef elif wrong? The current code does not seem to do anything if TLS_REG_EMUL is set and HAS_TLS_REG is not set. HAS_TLS_REG depends !TLS_REG_EMUL.

Regards,

Tony

#12 lore raw

PATCH 1/1 arm: Replace CONFIG_HAS_TLS_REG with HWCAP_TLS and check for it on V6

Quoted 16 lines · Tony Lindgren
Quoted 14 lines · Russell King - ARM Linux

Review

Quoted 9 lines · Tony Lindgren
(quoted diff) +4 -5
-#if defined(CONFIG_HAS_TLS_REG)
-	mcr	p15, 0, r3, c13, c0, 3		@ set TLS register
-#elif !defined(CONFIG_TLS_REG_EMUL)
-	mov	r4, #0xffff0fff
-	str	r3, [r4, #-15]			@ TLS val at 0xffff0ff0
+#if !defined(CONFIG_TLS_REG_EMUL)
+	ldr	r4, =elf_hwcap
+	ldr	r4, [r4, #0]
+	tst	r4, #HWCAP_TLS			@ hardware with TLS?

This is really really inefficient. Both the second ldr and tst will stall the pipeline because they need to wait for the result of the precending ldr. Can we do better by re-ordering some instructions?

Quoted 1 line

Or set ifdef CONFIG_CPU_V6 and test for the cp15 id register every time..

I was suggesting that it might be worth trying to reorder the instructions here so that we're not immediately using the result of the ldr in the next instruction. We have plenty of registers available here (everything except r0-r2, r6, fp.)

Quoted 6 lines
Quoted 2 lines

Also, the ifndef seems incorrect - if we have TLS_REG_EMUL we seem to omit all this code.

Is the current ifdef elif wrong? The current code does not seem to do anything if TLS_REG_EMUL is set and HAS_TLS_REG is not set. HAS_TLS_REG depends !TLS_REG_EMUL.

Now I look back, I don't think so. Ignore that comment.

#13 lore raw

PATCH 1/1 arm: Replace CONFIG_HAS_TLS_REG with HWCAP_TLS and check for it on V6

Quoted 17 lines · Russell King - ARM Linux
Quoted 16 lines · Tony Lindgren
Quoted 14 lines · Russell King - ARM Linux

Review

Quoted 9 lines · Tony Lindgren
(quoted diff) +4 -5
-#if defined(CONFIG_HAS_TLS_REG)
-	mcr	p15, 0, r3, c13, c0, 3		@ set TLS register
-#elif !defined(CONFIG_TLS_REG_EMUL)
-	mov	r4, #0xffff0fff
-	str	r3, [r4, #-15]			@ TLS val at 0xffff0ff0
+#if !defined(CONFIG_TLS_REG_EMUL)
+	ldr	r4, =elf_hwcap
+	ldr	r4, [r4, #0]
+	tst	r4, #HWCAP_TLS			@ hardware with TLS?

This is really really inefficient. Both the second ldr and tst will stall the pipeline because they need to wait for the result of the precending ldr. Can we do better by re-ordering some instructions?

Quoted 6 lines
Quoted 1 line

Or set ifdef CONFIG_CPU_V6 and test for the cp15 id register every time..

I was suggesting that it might be worth trying to reorder the instructions here so that we're not immediately using the result of the ldr in the next instruction. We have plenty of registers available here (everything except r0-r2, r6, fp.)

Yeah sure, I'll take a look. I'll repost an updated version after I get a chance to play with this again. Might be a little while before I get back to this, but this would be for the next merge window anyways.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Also, the ifndef seems incorrect - if we have TLS_REG_EMUL we seem to omit all this code.

Is the current ifdef elif wrong? The current code does not seem to do anything if TLS_REG_EMUL is set and HAS_TLS_REG is not set. HAS_TLS_REG depends !TLS_REG_EMUL.

Now I look back, I don't think so. Ignore that comment.

OK

Regards,

Tony