Skip to contentSkip to conversation

sparc family optimising support

PATCH Alexander Clouter 3 participants 4 messages Sep 10, 2005 – Sep 11, 2005 SPARC + UltraSPARC (sparc/sparc64)

lore
Share & tools
lore
#0 lore raw

Hi All,

Digging around I cannot see any reference to someone having done this before, and not to come over as a Gentoo Ricer ;) but I rolled out the following patch which does give me a bit more umpft from my old Sun 50Mhz Lunchbox[1].

Missing those integer divides/multiples really hurts her needlessly. :( I noticed when compiling 2.6 kernels no -mcpu=<cheese> flags appear, or anything equivalent, so thought it would be a good idea to add my own. The effect for my 50Mhz v8 sparc, ssh does connect much faster; I guess thats due to /dev/random'ness....not sure but I give it the "Works for Me(tm)" stamp of approval. Really I just did all this to get ssh connecting to go faster and this probably helps the IPSec'ing I do on her too :)

As the x86 crowd can optimise in a cute menu for 586, 686, etc I thought us sparc users were missing out and should be able to do v8, v9, etc. To make the patch I pretty much lifted the information from the gcc manpages and it seems to work.

Comments, flames, praise are welcome of course. Just curious why something like this has not appeared earlier, I'm sure there is a reason that I have missed upon? Would be interesting to know if anyone else finds this useful, having gcc default to v7 can be awkward.

My reasoning for defaulting to v8 is that most people, I guess, have a v8 suitable chip or above and its rather expensive dropping those integer divides/multiples by default; just my opinion, if people think a v7 default would be a better idea then go for that. If you have a v7 chip you would normally be aware of its limitations in comparison to the later chips I would assume?

Cheers

Alex

[1] http://eintr.net/systems/sun/sparcclassic/

Signature · 9 lines
 ________________________________________ 
/ Scintillation is not always            \
\ identification for an auric substance. /
 ---------------------------------------- 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||
arch/sparc/Kconfig +116 -0
diff -r -u linux-2.6.13.orig/arch/sparc/Kconfig linux-2.6.13/arch/sparc/Kconfig
@@ -229,6 +229,122 @@
 
 if !SUN4
 
+choice
+	prompt "Processor family" 
+		default MV8
+
+config MV7
+	bool "v7"
+	help
+	  Select this for a v7 variant of the SPARC CPU architecture.  This
+	  particular chip series does not include the integer multiply and
+	  divide instructions and gcc by defaults produces code for this
+	  chip; as a result there can be a significant performance hit if
+	  your CPU actually supports this additional instructions.
+
+	  If you have a SPARCStation 1, 2, IPX machine you should opt for
+	  this otherwise keep with the default (v8) if you are unsure.
+
+config MCYPRESS
+	bool "v7 - cypress"
+	help
+	  Select this for a Cypress variant of the SPARC CU architecture
+	  that is based on the v7 instruction set.  Chosing this option will
+	  add further compiler optimisations for the Cypress CY7C602 chip as
+	  found in the SPARCStation/SPARCServer 3xx series of machines.
+
+config MV8
+	bool "v8"
+	help
+	  Select this for a v8 variant of the SPARC CPU architecture.  The
+	  only difference from the v7 code is that there are integer
+	  multiply and divide instructions which significantly speed up the
+	  execution of your code.
+	  
+	  This is the default setting as v7 chips are rather rare and the
+	  performance penalty to the more advanced variants is rather high.
+	  Lets face it, if you have a v7 chip, you probably know it or
+	  should know about it :)
+
+config MSUPERSPARC
+	bool "v8 - supersparc"
+	help
+	  Select this for a supersparc variant of the SPARC CPU
+	  architecture.  Choosing this adds futher compiler optimisations
+	  for the SuperSPARC chip as found in the SPARCStation 10, 1000 and
+	  2000 series of computers.
+
+config MHYPERSPARC
+	bool "v8 - hypersparc"
+	help
+	  Select this for a hypersparc variant of the SPARC CPU
+	  architecture.
+
+config MSPARCLITE
+	bool "sparclite"
+	help
+	  Select this for a sparclite variant of the SPARC CPU architecture.
+	  Over the v7 architecture it adds the integer multiply, divide step
+	  and scan instructions.
+
+config MF930
+	bool "sparclite - mf930"
+	help
+	  Select this for a f930 variant of the SPARC CPU architecture that
+	  adds compiler based optimisations for the Fujitsu MB86930 chip;
+	  it has no FPU.
+
+config MF934
+	bool "sparclite - mf934"
+	help
+	  Select this for a f934 variant of the SPARC CPU architecture that
+	  adds compiler based optimisations for the Fujitsu MB86934 chip
+	  which is more recent than the f930 and adds a FPU to its handbag.
+
+config MSPARCLITE86X
+	bool "sparclite - 86x"
+	help
+	  Select this for a 86x variant of the SPARC CPU architecture.
+
+config MSPARCLET
+	bool "sparclet"
+	help
+	  Select this for a sparclet variant of the SPARC CPU architecture.
+	  Over the v7 architecture it adds the integer multiply,
+	  multiply/accumulate and divide step and scan instructions.
+
+config MTSC701
+	bool "sparclet - tsc701"
+	help
+	  Select this for a tsc701 variant of the SPARC CPU architecture
+	  that adds compiler based optimisations for the TEMIC SPARClet
+	  chip.
+
+config MV9
+	bool "v9"
+	help
+	  Select this for a v9 variant of the SPARC CPU architecture.  In
+	  addition to the v8 instruction set 64-bit based integer and
+	  floating-point move instructions, three additional floating-point
+	  condition code registers and conditional move instructions have
+	  been added.
+
+config MULTRASPARC
+	bool "v9 - ultrasparc"
+	help
+	  Select this for a ultraspace variant of the SPARC CPU
+	  architecture that adds compiler based optimisations for the
+	  Sun UltraSPARC I/II chips.
+
+config MULTRASPARC3
+	bool "v9 - ultrasparc3"
+	help
+	  Select this for a ultraspace variant of the SPARC CPU
+	  architecture that adds compiler based optimisations for the
+	  Sun UltraSPARC III chip.
+
+endchoice
+
 config PCI
 	bool "Support for PCI and PS/2 keyboard/mouse"
 	help
arch/sparc/Makefile +17 -0
diff -r -u linux-2.6.13.orig/arch/sparc/Makefile linux-2.6.13/arch/sparc/Makefile
@@ -27,6 +27,23 @@
 head-y := arch/sparc/kernel/head.o arch/sparc/kernel/init_task.o
 HEAD_Y := $(head-y)
 
+cflags-$(CONFIG_MV7)		+= -mcpu=v7
+cflags-$(CONFIG_MCYPRESS)	+= -mcpu=cypress
+cflags-$(CONFIG_MV8)		+= -mcpu=v8
+cflags-$(CONFIG_MSUPERSPARC)	+= -mcpu=supersparc
+cflags-$(CONFIG_MHYPERSPARC)	+= -mcpu=hypersparc
+cflags-$(CONFIG_MSPARCLITE)	+= -mcpu=sparclite
+cflags-$(CONFIG_MF930)		+= -mcpu=f930
+cflags-$(CONFIG_MF934)		+= -mcpu=f934
+cflags-$(CONFIG_MSPARCLITE86X)	+= -mcpu=sparclite86x
+cflags-$(CONFIG_MSPARCLET)	+= -mcpu=sparclet
+cflags-$(CONFIG_MTSC701)	+= -mcpu=tsc701
+cflags-$(CONFIG_MV9)		+= -mcpu=v9
+cflags-$(CONFIG_MULTRASPARC)	+= -mcpu=ultrasparc
+cflags-$(CONFIG_MULTRASPARC3)	+= -mcpu=ultrasparc3
+
+CFLAGS += $(cflags-y)
+
 core-y += arch/sparc/kernel/ arch/sparc/mm/ arch/sparc/math-emu/
 libs-y += arch/sparc/prom/ arch/sparc/lib/
 
#1 lore raw
Quoted 5 lines · Alexander Clouter

Hi All,

Digging around I cannot see any reference to someone having done this before, and not to come over as a Gentoo Ricer ;) but I rolled out the following patch which does give me a bit more umpft from my old Sun 50Mhz Lunchbox[1].

This has been brought up before (my archives show a reference back in March of 2004), and the answer was that doing this is pointless. The sparc kernel patches in the hw versions of the muldiv functions at kernel startup anyway, so passing -mcpu=v8 is just a waste.

So, any improvement that you see from -mcpu=v8 should be psychosomatic... instead, I suspect the real valuable speed-up will come from compiling the userspace applications with v8 opt.

Now, if you've got solid benchmark data showing repeatable performance improvement by using some set of compiler opts on a sparc32 kernel, that might be more interesting. ;)

~spot

Signature · 4 lines
Tom "spot" Callaway: Red Hat Senior Sales Engineer || GPG ID: 93054260
Fedora Extras Steering Committee Member (RPM Standards and Practices)
Aurora Linux Project Leader: http://auroralinux.org
Lemurs, llamas, and sparcs, oh my!
maintainer
#2 lore raw
In reply to Alexander Clouter

From: "Tom 'spot' Callaway" <[email protected]>
Date: Sat, 10 Sep 2005 14:50:46 -0500

Quoted 7 lines

This has been brought up before (my archives show a reference back in March of 2004), and the answer was that doing this is pointless. The sparc kernel patches in the hw versions of the muldiv functions at kernel startup anyway, so passing -mcpu=v8 is just a waste.

So, any improvement that you see from -mcpu=v8 should be psychosomatic...

Half true, half false :-)

True, the kernel patches the muldiv functions, so calls to .mul, .div, .udiv, .umul et al. do end up using the hw instructions, but:

1) When libcalls are used like this for such fundamental integer operations, gcc fails to optimize many things, including important strength reduction loop optimizations among other things.

2) It costs a call, and return. It also makes it impossible for functions doing a multiply or divide from being leaf functions which is an incredibly big deal on sparc. Something as trivial as:

	int foo(int a, int b)
	{
		return a * b;
	}

needs a stack frame even though everything fits in registers without one. And all of this merely because gcc had to emit a function call to '.mul'.

So a -mcpu=v8 kernel would be significantly faster than the default.

#3 lore raw
In reply to Alexander Clouter
Quoted 2 lines · David S. Miller

So a -mcpu=v8 kernel would be significantly faster than the default.

I stand corrected. :)

~spot

Signature · 4 lines
Tom "spot" Callaway: Red Hat Senior Sales Engineer || GPG ID: 93054260
Fedora Extras Steering Committee Member (RPM Standards and Practices)
Aurora Linux Project Leader: http://auroralinux.org
Lemurs, llamas, and sparcs, oh my!