Skip to contentSkip to conversation

MIPS: SMTC: Correct saving of CP0_STATUS

PATCH Applied Edgar E. Iglesias 4 participants 15 messages Aug 29, 2011 – Sep 17, 2011 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MIPS: SMTC: Correct saving of CP0_STATUS

Hi,

Commit 362e696428590f7d0a5d0971a2d04b0372a761b8 reorders a bunch of insns to improve the flow of the pipeline but for MT_SMTC kernels, AFAICT, the saving of CP0_STATUS seems wrong.

Am I missing something?

If not here is a patch, tested with qemu.

Cheers

commit 1a72dd0ed0a238007d3d67c1e3a634d477527ce2

Author: Edgar E. Iglesias <[email protected]>
Date:   Tue Aug 30 01:07:15 2011 +0200

MIPS: SMTC: Correct saving of CP0_STATUS

arch/mips/include/asm/stackframe.h +3 -3
index b4ba244..1b8d9a0 100644
@@ -189,6 +189,9 @@
 		LONG_S	$0, PT_R0(sp)
 		mfc0	v1, CP0_STATUS
 		LONG_S	$2, PT_R2(sp)
+		LONG_S	$4, PT_R4(sp)
+		LONG_S	$5, PT_R5(sp)
+		LONG_S	v1, PT_STATUS(sp)
 #ifdef CONFIG_MIPS_MT_SMTC
 		/*
 		 * Ideally, these instructions would be shuffled in
@@ -199,9 +202,6 @@
 		.set	mips0
 		LONG_S	v1, PT_TCSTATUS(sp)
 #endif /* CONFIG_MIPS_MT_SMTC */
-		LONG_S	$4, PT_R4(sp)
-		LONG_S	$5, PT_R5(sp)
-		LONG_S	v1, PT_STATUS(sp)
 		mfc0	v1, CP0_CAUSE
 		LONG_S	$6, PT_R6(sp)
 		LONG_S	$7, PT_R7(sp)
#1 lore raw
Quoted 5 lines · Edgar E. Iglesias

Hi,

Commit 362e696428590f7d0a5d0971a2d04b0372a761b8 reorders a bunch of insns to improve the flow of the pipeline but for MT_SMTC kernels, AFAICT, the saving of CP0_STATUS seems wrong.

Indeed.

Quoted 3 lines

Am I missing something?

It does look like in the MIPS_MT_SMTC case we are clobbering the value in v1.

Quoted 2 lines

If not here is a patch, tested with qemu.

How about the attached completely untested one instead?

David Daney

From d0035295ae34bcf84d601b1e25e2642fe0802752 Mon Sep 17 00:00:00 2001
From: David Daney <[email protected]>
Date: Mon, 29 Aug 2011 16:42:12 -0700
Subject: [PATCH] MIPS: Don't clobber CP0_STATUS vaue for CONFIG_MIPS_MT_SMTC

Untested, but it looks nice.

---
 arch/mips/include/asm/stackframe.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/mips/include/asm/stackframe.h +2 -2
index 569681e..51a3a0c 100644
@@ -195,9 +195,9 @@
 		 * to cover the pipeline delay.
 		 */
 		.set	mips32
-		mfc0	v1, CP0_TCSTATUS
+		mfc0	k0, CP0_TCSTATUS
 		.set	mips0
-		LONG_S	v1, PT_TCSTATUS(sp)
+		LONG_S	k0, PT_TCSTATUS(sp)
 #endif /* CONFIG_MIPS_MT_SMTC */
 		LONG_S	$4, PT_R4(sp)
 		LONG_S	$5, PT_R5(sp)
Signature · 1 line
1.7.2.3
#2 lore raw
Quoted 13 lines · David Daney
Quoted 5 lines · Edgar E. Iglesias

Hi,

Commit 362e696428590f7d0a5d0971a2d04b0372a761b8 reorders a bunch of insns to improve the flow of the pipeline but for MT_SMTC kernels, AFAICT, the saving of CP0_STATUS seems wrong.

Indeed.

Quoted 3 lines

Am I missing something?

Quoted 8 lines

It does look like in the MIPS_MT_SMTC case we are clobbering the value in v1.

Quoted 2 lines

If not here is a patch, tested with qemu.

How about the attached completely untested one instead?

Ralf,

I didn't mean to imply that Edgar's patch was not correct, it seems likely that it is. Really either approach is fine with me.

David Daney.

.
.
.

Quoted 30 lines

From d0035295ae34bcf84d601b1e25e2642fe0802752 Mon Sep 17 00:00:00 2001
From: David Daney<[email protected]>
Date: Mon, 29 Aug 2011 16:42:12 -0700
Subject: [PATCH] MIPS: Don't clobber CP0_STATUS vaue for CONFIG_MIPS_MT_SMTC

Untested, but it looks nice.

---
  arch/mips/include/asm/stackframe.h |    4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)
arch/mips/include/asm/stackframe.h +2 -2
index 569681e..51a3a0c 100644
@@ -195,9 +195,9 @@
  		 * to cover the pipeline delay.
  		 */
  		.set	mips32
-		mfc0	v1, CP0_TCSTATUS
+		mfc0	k0, CP0_TCSTATUS
  		.set	mips0
-		LONG_S	v1, PT_TCSTATUS(sp)
+		LONG_S	k0, PT_TCSTATUS(sp)
  #endif /* CONFIG_MIPS_MT_SMTC */
  		LONG_S	$4, PT_R4(sp)
  		LONG_S	$5, PT_R5(sp)
#3 lore raw
In reply to David Daney

I submitted that exact patch (David's more minimal version) in December 2010 (and I did test it). Did it not take? See the thread "SMTC support status in latest git head". The patch went out on December 24 (why I was spending my Christmas Eve fixing MIPS Linux is another question... :op )

Kevin K.

Quoted 22 lines · David Daney
Quoted 5 lines · Edgar E. Iglesias

Hi,

Commit 362e696428590f7d0a5d0971a2d04b0372a761b8 reorders a bunch of insns to improve the flow of the pipeline but for MT_SMTC kernels, AFAICT, the saving of CP0_STATUS seems wrong.

Indeed.

Quoted 3 lines

Am I missing something?

It does look like in the MIPS_MT_SMTC case we are clobbering the value in v1.

Quoted 2 lines

If not here is a patch, tested with qemu.

How about the attached completely untested one instead?

David Daney

#4 lore raw
Quoted 2 lines · Kevin D. Kissell

I submitted that exact patch (David's more minimal version) in December 2010 (and I did test it). Did it not take?

Evidently not. Perhaps Ralf will see fit to commit it this time.

Quoted 5 lines

See the thread "SMTC
support status in latest git head". The patch went out on December 24 (why I was spending my Christmas Eve fixing MIPS Linux is another question... :op )

... one which I will not attempt to address.

David Daney.

Quoted 27 lines

Kevin K.

Quoted 22 lines · David Daney
Quoted 5 lines · Edgar E. Iglesias

Hi,

Commit 362e696428590f7d0a5d0971a2d04b0372a761b8 reorders a bunch of insns to improve the flow of the pipeline but for MT_SMTC kernels, AFAICT, the saving of CP0_STATUS seems wrong.

Indeed.

Quoted 3 lines

Am I missing something?

It does look like in the MIPS_MT_SMTC case we are clobbering the value in v1.

Quoted 2 lines

If not here is a patch, tested with qemu.

How about the attached completely untested one instead?

David Daney

#5 lore raw
Quoted 5 lines · David Daney
Quoted 2 lines · Kevin D. Kissell

I submitted that exact patch (David's more minimal version) in December 2010 (and I did test it). Did it not take?

Evidently not. Perhaps Ralf will see fit to commit it this time.

Looking back over the exchange and thinking about the date, in all fairness to Ralf, when I submitted it, it was a diff -u and not a git diff, because I was at my brother-in-law's house for the holidays and had no access to my MIPS Linux git machine. It got picked up by patchwork.linux-mips.org ( patch/1896 ), but was only actually tested by Anoop a couple of days later. He confirmed that it solved the problem, but also that there were other problems with SMTC in the then-current head, apparently relating to timekeeping_notify(). Those problems weren't resolved in the context of that email thread, so the patch - something along the lines of which really and truly is necessary - may have been ignored as a partial fix, even though it is a self-contained solution to a self-contained bug.

Regards,

Kevin K.

#6 lore raw
Quoted 7 lines · Kevin D. Kissell
Quoted 5 lines · David Daney
Quoted 2 lines · Kevin D. Kissell

I submitted that exact patch (David's more minimal version) in December 2010 (and I did test it). Did it not take?

Evidently not. Perhaps Ralf will see fit to commit it this time.

Quoted 13 lines

Looking back over the exchange and thinking about the date, in all fairness to Ralf, when I submitted it, it was a diff -u and not a git diff, because I was at my brother-in-law's house for the holidays and had no access to my MIPS Linux git machine. It got picked up by patchwork.linux-mips.org ( patch/1896 ), but was only actually tested by Anoop a couple of days later. He confirmed that it solved the problem, but also that there were other problems with SMTC in the then-current head, apparently relating to timekeeping_notify(). Those problems weren't resolved in the context of that email thread, so the patch - something along the lines of which really and truly is necessary - may have been ignored as a partial fix, even though it is a self-contained solution to a self-contained bug.

Interesting. Coincidentally, after getting pass the CP0_Status issue, I ran into some issues related to time-keeping, but I got the impression I was seeing a mix of problems with QEMU and possibly the kernel. I never hunted these issues down though. Maybe I'll give it a go some other time..

It makes me wonder, what is the state of SMTC kernels? Are they widely used and considered stable?
Or is the SMP mode (1 TC per VPE) the common choice?

Cheers

#7 lore raw
Quoted 19 lines · Edgar E. Iglesias
Quoted 5 lines · Kevin D. Kissell
Quoted 4 lines · David Daney
Quoted 2 lines · Kevin D. Kissell

I submitted that exact patch (David's more minimal version) in December 2010 (and I did test it). Did it not take?

Evidently not. Perhaps Ralf will see fit to commit it this time.

Quoted 13 lines

Looking back over the exchange and thinking about the date, in all fairness to Ralf, when I submitted it, it was a diff -u and not a git diff, because I was at my brother-in-law's house for the holidays and had no access to my MIPS Linux git machine. It got picked up by patchwork.linux-mips.org ( patch/1896 ), but was only actually tested by Anoop a couple of days later. He confirmed that it solved the problem, but also that there were other problems with SMTC in the then-current head, apparently relating to timekeeping_notify(). Those problems weren't resolved in the context of that email thread, so the patch - something along the lines of which really and truly is necessary - may have been ignored as a partial fix, even though it is a self-contained solution to a self-contained bug.

Quoted 4 lines

Interesting. Coincidentally, after getting pass the CP0_Status issue, I ran into some issues related to time-keeping, but I got the impression I was seeing a mix of problems with QEMU and possibly the kernel. I never hunted these issues down though. Maybe I'll give it a go some other time..

It could very well have been a QEMU issue. At the time, I did spend a while staring at the diffs between the working and non-working kernel sources and I was unable to spot anything obviously suspect.

Quoted 3 lines

It makes me wonder, what is the state of SMTC kernels? Are they widely used and considered stable?
Or is the SMP mode (1 TC per VPE) the common choice?

The virtual SMP mode is far more common. SMTC has the advantage that it allows the maximum throughput to be extracted from a 34K core - depending on the application/benchmark, the "sweet spot" may be more than 2 concurrent threads - but it's less well maintained.

Regards,

Kevin K.

#8 lore raw
Quoted 10 lines · Kevin D. Kissell

It could very well have been a QEMU issue. At the time, I did spend a while staring at the diffs between the working and non-working kernel sources and I was unable to spot anything obviously suspect.

Quoted 3 lines

It makes me wonder, what is the state of SMTC kernels? Are they widely used and considered stable?
Or is the SMP mode (1 TC per VPE) the common choice?

The virtual SMP mode is far more common. SMTC has the advantage that it allows the maximum throughput to be extracted from a 34K core - depending on the application/benchmark, the "sweet spot" may be more than 2 concurrent threads - but it's less well maintained.

Not to mention that SMTC was developed for a single 34K core. It has never been pimped up to support multi-core systems such as the 1004K which would add some considerable complexity.

Ralf

#9 lore raw
Quoted 8 lines · Ralf Baechle
Quoted 6 lines · Kevin D. Kissell

It could very well have been a QEMU issue. At the time, I did spend a while staring at the diffs between the working and non-working kernel sources and I was unable to spot anything obviously suspect.

Quoted 3 lines

It makes me wonder, what is the state of SMTC kernels? Are they widely used and considered stable?
Or is the SMP mode (1 TC per VPE) the common choice?

Quoted 7 lines
Quoted 4 lines

The virtual SMP mode is far more common. SMTC has the advantage that it allows the maximum throughput to be extracted from a 34K core - depending on the application/benchmark, the "sweet spot" may be more than 2 concurrent threads - but it's less well maintained.

Not to mention that SMTC was developed for a single 34K core. It has never been pimped up to support multi-core systems such as the 1004K which would add some considerable complexity.

SMTC was only *run* on single 34K cores, but the design was done keeping in mind the possibility that a multi-MT-core configuration might be built. The main thing that would need to be done would be to add startup code that would make the first TC/VPE of the second (and subsequent) cores recognize that they are secondary CPUs and follow the same code path as the non-zeroth TC/VPE in the single-core configuration. One would also need to do "real" IPIs between cores, which is anyway what the actual production parts with 34Ks in them do (as opposed to what we had to do on the FPGA prototypes).

The 1004K, as I understand it, was designed with exactly 2 VPEs and 2 TCs, and unless there's an option in the core configuration to synthesize it with more TCs per VPE (>2 TCs or <2 VPEs), SMTC would not be meaningful. Even if you could build a single-VPE 1004K with 2 TCs, the area savings would be relatively small and would have to be balanced against the small per-TC kernel performance hit of going to SMTC. SMTC rocks when you can put 3 or 4 TCs in a single VPE, so that the better utilization of functional units has a chance to more than make up for the SMTC efficiency hit in kernel mode.

Regards,

Kevin K.

#10 lore raw
In reply to David Daney
Quoted 21 lines · David Daney
Quoted 5 lines · Edgar E. Iglesias

Hi,

Commit 362e696428590f7d0a5d0971a2d04b0372a761b8 reorders a bunch of insns to improve the flow of the pipeline but for MT_SMTC kernels, AFAICT, the saving of CP0_STATUS seems wrong.

Indeed.

Quoted 3 lines

Am I missing something?

It does look like in the MIPS_MT_SMTC case we are clobbering the value in v1.

Quoted 2 lines

If not here is a patch, tested with qemu.

How about the attached completely untested one instead?

Quoted 8 lines

David Daney

From d0035295ae34bcf84d601b1e25e2642fe0802752 Mon Sep 17 00:00:00 2001
From: David Daney <[email protected]>
Date: Mon, 29 Aug 2011 16:42:12 -0700
Subject: [PATCH] MIPS: Don't clobber CP0_STATUS vaue for CONFIG_MIPS_MT_SMTC

Untested, but it looks nice.

Thanks, I like you patch better. But whichever version will do.

Cheers

Applied
#11 lore raw
In reply to David Daney
Quoted 1 line · David Daney

How about the attached completely untested one instead?

Applied. I like it more than than Edgar's patch because of the better scheduling.

I didn't apply Kevin's original patch because a followup to the patch mentioned there were still problems remaining - but it seems they were unrelated.

Thanks everybody,

Ralf

#12 lore raw
Quoted 6 lines · Ralf Baechle
Quoted 1 line · David Daney

How about the attached completely untested one instead?

Applied. I like it more than than Edgar's patch because of the better scheduling.

I agree, thanks!

BTW, in case anyone is intersted, it is now possible to boot malta boards with SMP with the latest QEMU. The neat thing is that if you debug the kernel with GDB, you'll see the different cores execution contexts as differten threads and can singletep them individually.

You need a QEMU from latest git.

Cheers

#13 lore raw
Quoted 1 line · Edgar E. Iglesias

I agree, thanks!

You're welcome.

Quoted 4 lines

BTW, in case anyone is intersted, it is now possible to boot malta boards with SMP with the latest QEMU. The neat thing is that if you debug the kernel with GDB, you'll see the different cores execution contexts as differten threads and can singletep them individually.

Very interesting. What type of SMP system does it emulate?

Ralf

#14 lore raw
Quoted 4 lines · Ralf Baechle
Quoted 1 line · Edgar E. Iglesias

I agree, thanks!

Quoted 8 lines

You're welcome.

Quoted 4 lines

BTW, in case anyone is intersted, it is now possible to boot malta boards with SMP with the latest QEMU. The neat thing is that if you debug the kernel with GDB, you'll see the different cores execution contexts as differten threads and can singletep them individually.

Very interesting. What type of SMP system does it emulate?

I'm not all familiar with the terminology, but it works with the kind where you've got multiple VPEs with one TC per VPE, vSMP IIUC.

You need to pass these options to QEMU, -cpu 34Kf -smp 2, where 2 maybe anything up to 16.

We've (AXIS) got models for the GIC aswell, but I need to check with MTI before publishing those. IMO these models would help everybody cause it's, to say the leaast, a huge pain to setup the GIC without having QEMU or any emulator to check the interrupt routing.

Cheers