Skip to contentSkip to conversation

i686 quirk for AMD Geode

PATCH Matteo Croce 20 participants 115 messages Oct 3, 2009 – Nov 23, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi,

the AMD GEode LX has an x86 id of 5 (i586) tought it's technically an i686:

root@alix:/usr/src# cat /proc/cpuinfo
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 5
model           : 10
model name      : Geode(TM) Integrated Processor by AMD PCS
stepping        : 2
cpu MHz         : 498.060
cache size      : 128 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 1
wp              : yes
flags           : fpu de pse tsc msr cx8 sep pge cmov clflush mmx
mmxext 3dnowext 3dnow
bogomips        : 996.12
clflush size    : 32
cache_alignment : 32
address sizes   : 32 bits physical, 32 bits virtual
power management:

indeed it has mmx, mmxext and cmov.
So I added the quirk below and I can confirm that the system is running fine. I did an x264 encode to trigger any SIGILL due to missing opcodes, but it worked.

I also did this simple test which gives a ~2.5x speed boost:
http://pastebin.ca/1590089

I wish some feedback from someone, I really dunno why AMD set the cpuid value to 5

arch/x86/kernel/cpu/bugs.c +7 -0
@@ -151,6 +151,12 @@
 #endif
 }
 
+static void __init check_geode_i586(void)
+{
+	if(boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
+	   boot_cpu_data.x86_model == 10 && boot_cpu_data.x86 == 5)
+		boot_cpu_data.x86 = 6;
+}
 
 void __init check_bugs(void)
 {
@@ -163,6 +169,7 @@
 	check_fpu();
 	check_hlt();
 	check_popad();
+	check_geode_i586();
 	init_utsname()->machine[1] =
 		'0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
 	alternative_instructions();
#1 lore raw
Quoted 4 lines · Matteo Croce

Hi,

the AMD GEode LX has an x86 id of 5 (i586) tought it's technically an i686:

a) Wrong place - it should be in cpu/amd.c.
b) You need to also make sure that it has FCOMI and the long NOP\
instructions.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#2 lore raw
Quoted 10 lines · H. Peter Anvin
Quoted 4 lines · Matteo Croce

Hi,

the AMD GEode LX has an x86 id of 5 (i586) tought it's technically an i686:

a) Wrong place - it should be in cpu/amd.c.
b) You need to also make sure that it has FCOMI and the long NOP\
  instructions.

Quoted 7 lines

       -hpa

--
H. Peter Anvin, Intel Open Source Technology Center I work for Intel.  I don't speak on their behalf.

I've run the attached files and I get this:

root@alix:/usr/src# ./longnop
Long NOPs supported: no
root@alix:/usr/src# ./fcomi
Long FCOMi supported: yes

#include <stdio.h>
#include <signal.h>
#include <setjmp.h>

static sigjmp_buf out;

void sigill(int signal)
{
siglongjmp(out, 1);
}

int main(void)
{
int died;

  signal(SIGILL, sigill);

  died = sigsetjmp(out, 1);

  if (!died)
    asm volatile("nopl 0(%eax)");

printf("Long NOPs supported: %s\n", died ? "no" : "yes"); return died;
}

#include <stdio.h>
#include <signal.h>
#include <setjmp.h>

static sigjmp_buf out;

void sigill(int signal)
{
siglongjmp(out, 1);
}

int main(void)
{
int died;

  signal(SIGILL, sigill);

  died = sigsetjmp(out, 1);

  if (!died)
    asm volatile("fcomi st(0), st(1)");

printf("Long FCOMi supported: %s\n", died ? "no" : "yes"); return died;
}

#3 lore raw
In reply to Matteo Croce
Quoted 4 lines · Matteo Croce

Hi,

the AMD GEode LX has an x86 id of 5 (i586) tought it's technically an i686:

See checkin a7ef94e6889186848573a10c5bdb8271405f44de for additional details.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#4 lore raw
In reply to Matteo Croce
Quoted 56 lines · Matteo Croce

Hi,

the AMD GEode LX has an x86 id of 5 (i586) tought it's technically an i686:

root@alix:/usr/src# cat /proc/cpuinfo
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 5
model           : 10
model name      : Geode(TM) Integrated Processor by AMD PCS
stepping        : 2
cpu MHz         : 498.060
cache size      : 128 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 1
wp              : yes
flags           : fpu de pse tsc msr cx8 sep pge cmov clflush mmx
mmxext 3dnowext 3dnow
bogomips        : 996.12
clflush size    : 32
cache_alignment : 32
address sizes   : 32 bits physical, 32 bits virtual
power management:

indeed it has mmx, mmxext and cmov.
So I added the quirk below and I can confirm that the system is running fine. I did an x264 encode to trigger any SIGILL due to missing opcodes, but it worked.

I also did this simple test which gives a ~2.5x speed boost:
http://pastebin.ca/1590089

I wish some feedback from someone, I really dunno why AMD set the cpuid value to 5

arch/x86/kernel/cpu/bugs.c +6 -0
@@ -151,6 +151,12 @@
 #endif
 }
 
+static void __init check_geode_i586(void)
+{
+	if(boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
+	   boot_cpu_data.x86_model == 10 && boot_cpu_data.x86 == 5)
+		boot_cpu_data.x86 = 6;
+}
 
 void __init check_bugs(void)
 {

arch/x86/kernel/cpu/bugs.c line 175

Quoted 7 lines
arch/x86/kernel/cpu/bugs.c +1 -0
@@ -163,6 +169,7 @@
 	check_fpu();
 	check_hlt();
 	check_popad();
+	check_geode_i586();
 	init_utsname()->machine[1] =
 		'0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
 	alternative_instructions();

Looks good, but your signoff line is missing.

Ingo

#5 lore raw
Quoted 69 lines · Ingo Molnar
Quoted 60 lines · Matteo Croce

Hi,

the AMD GEode LX has an x86 id of 5 (i586) tought it's technically an i686:

root@alix:/usr/src# cat /proc/cpuinfo
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 5
model           : 10
model name      : Geode(TM) Integrated Processor by AMD PCS
stepping        : 2
cpu MHz         : 498.060
cache size      : 128 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 1
wp              : yes
flags           : fpu de pse tsc msr cx8 sep pge cmov clflush mmx
mmxext 3dnowext 3dnow
bogomips        : 996.12
clflush size    : 32
cache_alignment : 32
address sizes   : 32 bits physical, 32 bits virtual
power management:

indeed it has mmx, mmxext and cmov.
So I added the quirk below and I can confirm that the system is running fine. I did an x264 encode to trigger any SIGILL due to missing opcodes, but it worked.

I also did this simple test which gives a ~2.5x speed boost:
http://pastebin.ca/1590089

I wish some feedback from someone, I really dunno why AMD set the cpuid value to 5

arch/x86/kernel/cpu/bugs.c      2009-10-03 03:54:22.582205090 +0200 renamed from arch/x86/kernel/cpu/bugs.c      2009-10-03 03:43:02.399323313 +0200 +7 -0
@@ -151,6 +151,12 @@
  #endif
  }
 
+static void __init check_geode_i586(void)
+{
+     if(boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
+        boot_cpu_data.x86_model == 10 && boot_cpu_data.x86 == 5)
+             boot_cpu_data.x86 = 6;
+}
 
  void __init check_bugs(void)
  {
@@ -163,6 +169,7 @@
       check_fpu();
       check_hlt();
       check_popad();
+     check_geode_i586();
Quoted 3 lines

      init_utsname()->machine[1] =
              '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86); alternative_instructions();

Looks good, but your signoff line is missing.

Quoted 2 lines

       Ingo

Sorry Ingo but if you read my last mail I wrote that the GEODE does supports FCOMI but not NOPL
so i don't know if it's worth it, even is I haven't ANY binary in my system with such instruction:

# find /lib/tls/i686 /lib/i686 -type f |xargs objdump -d |grep -c nopl
0
#6 lore raw
Quoted 8 lines · Matteo Croce

Sorry Ingo but if you read my last mail I wrote that the GEODE does supports FCOMI but not NOPL
so i don't know if it's worth it, even is I haven't ANY binary in my system with such instruction:

# find /lib/tls/i686 /lib/i686 -type f |xargs objdump -d |grep -c nopl
0

Recent gcc/binutils has been known to start to use them.

Either way, it's a user-space-visible difference, so at least the kernel will not signal anything else based on existing precedent.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#7 lore raw
Quoted 7 lines · H. Peter Anvin
Quoted 6 lines · Matteo Croce

Sorry Ingo but if you read my last mail I wrote that the GEODE does supports FCOMI but not NOPL
so i don't know if it's worth it, even is I haven't ANY binary in my system with such instruction:

Quoted 7 lines
Quoted 2 lines
# find /lib/tls/i686 /lib/i686 -type f |xargs objdump -d |grep -c nopl
0

Recent gcc/binutils has been known to start to use them.

Either way, it's a user-space-visible difference, so at least the kernel will not signal anything else based on existing precedent.

So it can't be applied, right?

#8 lore raw
In reply to Ingo Molnar
Quoted 69 lines · Ingo Molnar
Quoted 60 lines · Matteo Croce

Hi,

the AMD GEode LX has an x86 id of 5 (i586) tought it's technically an i686:

root@alix:/usr/src# cat /proc/cpuinfo
processor       : 0
vendor_id       : AuthenticAMD
cpu family      : 5
model           : 10
model name      : Geode(TM) Integrated Processor by AMD PCS
stepping        : 2
cpu MHz         : 498.060
cache size      : 128 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 1
wp              : yes
flags           : fpu de pse tsc msr cx8 sep pge cmov clflush mmx
mmxext 3dnowext 3dnow
bogomips        : 996.12
clflush size    : 32
cache_alignment : 32
address sizes   : 32 bits physical, 32 bits virtual
power management:

indeed it has mmx, mmxext and cmov.
So I added the quirk below and I can confirm that the system is running fine. I did an x264 encode to trigger any SIGILL due to missing opcodes, but it worked.

I also did this simple test which gives a ~2.5x speed boost:
http://pastebin.ca/1590089

I wish some feedback from someone, I really dunno why AMD set the cpuid value to 5

arch/x86/kernel/cpu/bugs.c      2009-10-03 03:54:22.582205090 +0200 renamed from arch/x86/kernel/cpu/bugs.c      2009-10-03 03:43:02.399323313 +0200 +7 -0
@@ -151,6 +151,12 @@
  #endif
  }
 
+static void __init check_geode_i586(void)
+{
+     if(boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
+        boot_cpu_data.x86_model == 10 && boot_cpu_data.x86 == 5)
+             boot_cpu_data.x86 = 6;
+}
 
  void __init check_bugs(void)
  {
@@ -163,6 +169,7 @@
       check_fpu();
       check_hlt();
       check_popad();
+     check_geode_i586();
Quoted 3 lines

      init_utsname()->machine[1] =
              '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86); alternative_instructions();

Looks good, but your signoff line is missing.

Quoted 2 lines

       Ingo

The AMD Geode LX has an x86 id of 5 (i586) tought it's technically an i686:

root@alix:~# egrep '^(cpu family|model name|flags)' /proc/cpuinfo
cpu family      : 5
model name      : Geode(TM) Integrated Processor by AMD PCS
flags           : fpu de pse tsc msr cx8 sep pge cmov clflush mmx
mmxext 3dnowext 3dnow

indeed it has MMX, MMXEXT and CMOV, just lacks the long NOP instruction (NOPL). This patch adds a quirck to promote the Geode to an i686 and emulates the NOPL in the do_invalid_op trap, so the userspace never notices. Emulating the NOPL has minimum performance loss, emulating a NOPL takes 0.5 usecs
and they are rarely used in x86

arch/x86/kernel/Makefile +1 -1
@@ -89,7 +89,7 @@
 obj-$(CONFIG_HPET_TIMER) 	+= hpet.o
 
 obj-$(CONFIG_K8_NB)		+= k8.o
-obj-$(CONFIG_MGEODE_LX)		+= geode_32.o mfgpt_32.o
+obj-$(CONFIG_MGEODE_LX)		+= geode_32.o mfgpt_32.o nopl_emu.o
 obj-$(CONFIG_DEBUG_RODATA_TEST)	+= test_rodata.o
 obj-$(CONFIG_DEBUG_NX_TEST)	+= test_nx.o
 
arch/x86/kernel/cpu/amd.c +4 -2
@@ -138,8 +138,10 @@
 	}
 
 	if (c->x86_model == 10) {
-		/* AMD Geode LX is model 10 */
-		/* placeholder for any needed mods */
+		/* Geode only lacks the NOPL instruction to be i686,
+		   but we can emulate it in the exception handler
+		   and promote it to a class 6 cpu */
+		boot_cpu_data.x86 = 6;
 		return;
 	}
 }
arch/x86/kernel/entry_32.S +4 -0
@@ -901,7 +901,11 @@
 	RING0_INT_FRAME
 	pushl $0
 	CFI_ADJUST_CFA_OFFSET 4
+#ifdef CONFIG_MGEODE_LX
+	pushl $do_nopl_emu
+#else
 	pushl $do_invalid_op
+#endif
 	CFI_ADJUST_CFA_OFFSET 4
 	jmp error_code
 	CFI_ENDPROC
arch/x86/kernel/nopl_emu.c new file +102 -0

102 lines not on this page · raw message

#9 lore raw
Quoted 1 line · Matteo Croce

indeed it has MMX, MMXEXT and CMOV, just lacks the long NOP instruction (NOPL).

MMX and MMXEXT are hardly hallmarks of i686, which leaves only cmov. I'm somewhat wondering about the general value of this patch; is i686 code really that much faster on Geode that it's worth it?

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#10 lore raw
Quoted 7 lines · H. Peter Anvin
Quoted 1 line · Matteo Croce

indeed it has MMX, MMXEXT and CMOV, just lacks the long NOP instruction (NOPL).

MMX and MMXEXT are hardly hallmarks of i686, which leaves only cmov. I'm somewhat wondering about the general value of this patch; is i686 code really that much faster on Geode that it's worth it?

Quoted 7 lines

       -hpa

--
H. Peter Anvin, Intel Open Source Technology Center I work for Intel.  I don't speak on their behalf.

yes, I did some test like gzip, bzip2, lame etc and they give more or less the same results of dhrystone

root@alix:/usr/src# CFLAGS='-march=i586' ./dry.c
gcc -c -O3 -march=i586 ./dry.c -o dry1.o
gcc -DPASS2 -O3 -march=i586 ./dry.c dry1.o  -o dry2

Dhrystone Benchmark, Version C, Version 2.2
Program compiled without 'register' attribute
Using times(), HZ=100

Trying 5000000 runs through Dhrystone:
Microseconds for one run through Dhrystone: 1.4
Dhrystones per Second: 740741

root@alix:/usr/src# CFLAGS='-march=i686' ./dry.c
gcc -c -O3 -march=i686 ./dry.c -o dry1.o
gcc -DPASS2 -O3 -march=i686 ./dry.c dry1.o  -o dry2

Dhrystone Benchmark, Version C, Version 2.2
Program compiled without 'register' attribute
Using times(), HZ=100

Trying 5000000 runs through Dhrystone:
Microseconds for one run through Dhrystone: 1.2
Dhrystones per Second: 841751

#11 lore raw
Quoted 5 lines · On Fri, 6 Nov 2009 23:18:06 +0100 Matteo Croce <[email protected]> wrote:
Quoted 4 lines · H. Peter Anvin
Quoted 1 line · Matteo Croce

indeed it has MMX, MMXEXT and CMOV, just lacks the long NOP instruction (NOPL).

MMX and MMXEXT are hardly hallmarks of i686, which leaves only cmov.

cmov is not i686 either. Its an optional extension that *should* only be used after you test its available. So gcc "i686" isn't quite "686". There are of course good reasons for that choice.

Quoted 2 lines

yes, I did some test like gzip, bzip2, lame etc and they give more or less the same results of dhrystone

How does that compare to i486. Certainly the old Nat Semi geode seemed to prefer to be fed i486 code to i586 (and wouldn't of course hack i686). You might also want to play around with -mtune= as well as arch= before assuming why i686 is a win

(I still btw think the patch is a good idea, it simplifies life enormously for users with the CPU)

Alan

#12 lore raw
In reply to Matteo Croce
Quoted 22 lines · Matteo Croce
Quoted 7 lines · H. Peter Anvin
Quoted 1 line · Matteo Croce

indeed it has MMX, MMXEXT and CMOV, just lacks the long NOP instruction (NOPL).

MMX and MMXEXT are hardly hallmarks of i686, which leaves only cmov. I'm somewhat wondering about the general value of this patch; is i686 code really that much faster on Geode that it's worth it?

Quoted 7 lines

? ? ? ?-hpa

--
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. ?I don't speak on their behalf.

yes, I did some test like gzip, bzip2, lame etc and they give more or less the same results of dhrystone

root@alix:/usr/src# CFLAGS='-march=i586' ./dry.c
Microseconds for one run through Dhrystone:        1.4
Dhrystones per Second:                          740741

...

Quoted 4 lines
root@alix:/usr/src# CFLAGS='-march=i686' ./dry.c
Trying 5000000 runs through Dhrystone:
Microseconds for one run through Dhrystone:        1.2
Dhrystones per Second:                          841751

Teach gcc that geodelx exists? No need to break kernel for that... and you probably can gain even bigger gains.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#13 lore raw
Quoted 24 lines · Pavel Machek
Quoted 22 lines · Matteo Croce
Quoted 7 lines · H. Peter Anvin
Quoted 1 line · Matteo Croce

indeed it has MMX, MMXEXT and CMOV, just lacks the long NOP instruction (NOPL).

MMX and MMXEXT are hardly hallmarks of i686, which leaves only cmov. I'm somewhat wondering about the general value of this patch; is i686 code really that much faster on Geode that it's worth it?

Quoted 7 lines

? ? ? ?-hpa

--
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. ?I don't speak on their behalf.

yes, I did some test like gzip, bzip2, lame etc and they give more or less the same results of dhrystone

root@alix:/usr/src# CFLAGS='-march=i586' ./dry.c
Microseconds for one run through Dhrystone:        1.4
Dhrystones per Second:                          740741

...

Quoted 8 lines
Quoted 4 lines
root@alix:/usr/src# CFLAGS='-march=i686' ./dry.c
Trying 5000000 runs through Dhrystone:
Microseconds for one run through Dhrystone:        1.2
Dhrystones per Second:                          841751

Teach gcc that geodelx exists? No need to break kernel for that... and you probably can gain even bigger gains.
                                                                       Pavel

Gcc 4.4 already knows about it, just sucks at optimizing:

# CFLAGS='-march=geode' ./dry.c
gcc -c -O3 -march=geode ./dry.c -o dry1.o gcc -DPASS2 -O3 -march=geode ./dry.c dry1.o -o dry2

Dhrystone Benchmark, Version C, Version 2.2
Program compiled without 'register' attribute
Using times(), HZ=100

Trying 5000000 runs through Dhrystone:
Microseconds for one run through Dhrystone: 1.4
Dhrystones per Second: 719424

#14 lore raw
Quoted 30 lines · Matteo Croce
Quoted 29 lines · Pavel Machek
Quoted 22 lines · Matteo Croce
Quoted 7 lines · H. Peter Anvin
Quoted 1 line · Matteo Croce

indeed it has MMX, MMXEXT and CMOV, just lacks the long NOP instruction (NOPL).

MMX and MMXEXT are hardly hallmarks of i686, which leaves only cmov. I'm somewhat wondering about the general value of this patch; is i686 code really that much faster on Geode that it's worth it?

Quoted 7 lines

? ? ? ?-hpa

--
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. ?I don't speak on their behalf.

yes, I did some test like gzip, bzip2, lame etc and they give more or less the same results of dhrystone

root@alix:/usr/src# CFLAGS='-march=i586' ./dry.c
Microseconds for one run through Dhrystone:        1.4
Dhrystones per Second:                          740741

...

Quoted 4 lines
root@alix:/usr/src# CFLAGS='-march=i686' ./dry.c
Trying 5000000 runs through Dhrystone:
Microseconds for one run through Dhrystone:        1.2
Dhrystones per Second:                          841751
Quoted 4 lines
Quoted 2 lines

Teach gcc that geodelx exists? No need to break kernel for that... and you probably can gain even bigger gains.

Gcc 4.4 already knows about it, just sucks at optimizing:

Good. So there's really no point in breaking kernel.

Quoted 11 lines

# CFLAGS='-march=geode' ./dry.c
gcc -c -O3 -march=geode ./dry.c -o dry1.o gcc -DPASS2 -O3 -march=geode ./dry.c dry1.o -o dry2

Dhrystone Benchmark, Version C, Version 2.2
Program compiled without 'register' attribute
Using times(), HZ=100

Trying 5000000 runs through Dhrystone:
Microseconds for one run through Dhrystone: 1.4
Dhrystones per Second: 719424

...fix gcc to genereta code at least as good as for i686 and you are done...?

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#15 lore raw
Quoted 50 lines · Pavel Machek
Quoted 30 lines · Matteo Croce
Quoted 29 lines · Pavel Machek
Quoted 22 lines · Matteo Croce
Quoted 7 lines · H. Peter Anvin
Quoted 1 line · Matteo Croce

indeed it has MMX, MMXEXT and CMOV, just lacks the long NOP instruction (NOPL).

MMX and MMXEXT are hardly hallmarks of i686, which leaves only cmov. I'm somewhat wondering about the general value of this patch; is i686 code really that much faster on Geode that it's worth it?

Quoted 7 lines

? ? ? ?-hpa

--
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. ?I don't speak on their behalf.

yes, I did some test like gzip, bzip2, lame etc and they give more or less the same results of dhrystone

root@alix:/usr/src# CFLAGS='-march=i586' ./dry.c
Microseconds for one run through Dhrystone:        1.4
Dhrystones per Second:                          740741

...

Quoted 4 lines
root@alix:/usr/src# CFLAGS='-march=i686' ./dry.c
Trying 5000000 runs through Dhrystone:
Microseconds for one run through Dhrystone:        1.2
Dhrystones per Second:                          841751
Quoted 4 lines
Quoted 2 lines

Teach gcc that geodelx exists? No need to break kernel for that... and you probably can gain even bigger gains.

Gcc 4.4 already knows about it, just sucks at optimizing:

Good. So there's really no point in breaking kernel.

Quoted 11 lines

# CFLAGS='-march=geode' ./dry.c
gcc -c -O3 -march=geode ./dry.c -o dry1.o gcc -DPASS2 -O3 -march=geode ./dry.c dry1.o  -o dry2

Dhrystone Benchmark, Version C, Version 2.2 Program compiled without 'register' attribute Using times(), HZ=100

Trying 5000000 runs through Dhrystone:
Microseconds for one run through Dhrystone:        1.4 Dhrystones per Second:                          719424

Quoted 8 lines

...fix gcc to genereta code at least as good as for i686 and you are done...?

                                                                       Pavel --
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

This is on my TODO list, but better to discuss it in the GCC mailing list, the kernel should use -march=geode and GCC should generate the best code for the AMD Geode, actually the i686 one

#16 lore raw
In reply to Pavel Machek
Quoted 25 lines · Pavel Machek
Quoted 24 lines · Matteo Croce
Quoted 23 lines · Pavel Machek
Quoted 22 lines · Matteo Croce
Quoted 7 lines · H. Peter Anvin
Quoted 1 line · Matteo Croce

indeed it has MMX, MMXEXT and CMOV, just lacks the long NOP instruction (NOPL).

MMX and MMXEXT are hardly hallmarks of i686, which leaves only cmov. I'm somewhat wondering about the general value of this patch; is i686 code really that much faster on Geode that it's worth it?

Quoted 7 lines

? ? ? ?-hpa

--
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. ?I don't speak on their behalf.

yes, I did some test like gzip, bzip2, lame etc and they give more or less the same results of dhrystone

root@alix:/usr/src# CFLAGS='-march=i586' ./dry.c
Microseconds for one run through Dhrystone:        1.4
Dhrystones per Second:                          740741
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

...

Quoted 4 lines
root@alix:/usr/src# CFLAGS='-march=i686' ./dry.c
Trying 5000000 runs through Dhrystone:
Microseconds for one run through Dhrystone:        1.2
Dhrystones per Second:                          841751

Teach gcc that geodelx exists? No need to break kernel for that... and you probably can gain even bigger gains.

But no standard distribution will be made available in a geode special version - not enough machines in the marekt. So I think it is better to be able to use the i686 specific things they already support, like libc6-686 from debian for example.

c'ya
sven

Signature · 1 line
The lights are fading out, once more...
#17 lore raw
Quoted 33 lines · Sven-Haegar Koch
Quoted 31 lines · Pavel Machek
Quoted 30 lines · Matteo Croce
Quoted 29 lines · Pavel Machek
Quoted 22 lines · Matteo Croce
Quoted 7 lines · H. Peter Anvin
Quoted 1 line · Matteo Croce

indeed it has MMX, MMXEXT and CMOV, just lacks the long NOP instruction (NOPL).

MMX and MMXEXT are hardly hallmarks of i686, which leaves only cmov. I'm somewhat wondering about the general value of this patch; is i686 code really that much faster on Geode that it's worth it?

Quoted 7 lines

? ? ? ?-hpa

--
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. ?I don't speak on their behalf.

yes, I did some test like gzip, bzip2, lame etc and they give more or less the same results of dhrystone

root@alix:/usr/src# CFLAGS='-march=i586' ./dry.c
Microseconds for one run through Dhrystone:        1.4
Dhrystones per Second:                          740741

...

Quoted 4 lines
root@alix:/usr/src# CFLAGS='-march=i686' ./dry.c
Trying 5000000 runs through Dhrystone:
Microseconds for one run through Dhrystone:        1.2
Dhrystones per Second:                          841751
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Teach gcc that geodelx exists? No need to break kernel for that... and you probably can gain even bigger gains.

But no standard distribution will be made available in a geode special version - not enough machines in the marekt. So I think it is better to be able to use the i686 specific things they already support, like libc6-686 from debian for example.

So hack your distribution to use libc6-686 if you know that it is safe... (that is no NOPL usage there). Still no need to break /proc/cpuinfo.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#18 lore raw
Quoted 42 lines · Pavel Machek
Quoted 33 lines · Sven-Haegar Koch
Quoted 31 lines · Pavel Machek
Quoted 30 lines · Matteo Croce
Quoted 29 lines · Pavel Machek
Quoted 22 lines · Matteo Croce
Quoted 7 lines · H. Peter Anvin
Quoted 1 line · Matteo Croce

indeed it has MMX, MMXEXT and CMOV, just lacks the long NOP instruction (NOPL).

MMX and MMXEXT are hardly hallmarks of i686, which leaves only cmov. I'm somewhat wondering about the general value of this patch; is i686 code really that much faster on Geode that it's worth it?

Quoted 7 lines

? ? ? ?-hpa

--
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. ?I don't speak on their behalf.

yes, I did some test like gzip, bzip2, lame etc and they give more or less the same results of dhrystone

root@alix:/usr/src# CFLAGS='-march=i586' ./dry.c
Microseconds for one run through Dhrystone:        1.4
Dhrystones per Second:                          740741

...

Quoted 4 lines
root@alix:/usr/src# CFLAGS='-march=i686' ./dry.c
Trying 5000000 runs through Dhrystone:
Microseconds for one run through Dhrystone:        1.2
Dhrystones per Second:                          841751
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Teach gcc that geodelx exists? No need to break kernel for that... and you probably can gain even bigger gains.

But no standard distribution will be made available in a geode special version - not enough machines in the marekt. So I think it is better to be able to use the i686 specific things they already support, like libc6-686 from debian for example.

Quoted 9 lines

So hack your distribution to use libc6-686 if you know that it is safe... (that is no NOPL usage there). Still no need to break /proc/cpuinfo.
                                                                       Pavel

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

Better to be sure that a NOPL whouldn't SIGILL your program, isn't it?

#19 lore raw
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines

But no standard distribution will be made available in a geode special version - not enough machines in the marekt. So I think it is better to be able to use the i686 specific things they already support, like libc6-686 from debian for example.

So hack your distribution to use libc6-686 if you know that it is safe... (that is no NOPL usage there). Still no need to break /proc/cpuinfo.

Better to be sure that a NOPL whouldn't SIGILL your program, isn't it?

SIGILL is easier to debug than NOPL mysteriously taking 100x time it should, sorry.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#20 lore raw
Quoted 5 lines
Quoted 2 lines

Better to be sure that a NOPL whouldn't SIGILL your program, isn't it?

SIGILL is easier to debug than NOPL mysteriously taking 100x time it should, sorry.

And a working 686 distribution is a great deal more useful to end users, who outnumber you by a few million to one. It's a very sensible patch, or perhaps you'd prefer we didn't say. And you forget the user "debug" for a Geode + i686 without this will be "it hangs when I try and boot the install CD"

It would probably also be worth having cmov fixups for the VIA C3 as well.

Alan

#21 lore raw
Quoted 10 lines · Alan Cox
Quoted 2 lines

SIGILL is easier to debug than NOPL mysteriously taking 100x time it should, sorry.

And a working 686 distribution is a great deal more useful to end users, who outnumber you by a few million to one. It's a very sensible patch, or perhaps you'd prefer we didn't say. And you forget the user "debug" for a Geode + i686 without this will be "it hangs when I try and boot the install CD"

It would probably also be worth having cmov fixups for the VIA C3 as well.

Agreed! I've been using the cmov patch on my kernels for years and it has helped a lot. It isn't *that* slow and allows you to boot a machine which wouldn't boot otherwise. Also, I have memories about the C3 supporting register-to-register CMOV but faulting only on register-to-memory, which is less common and makes the patch even more useful.

I'm very happy that people finally consider instruction emulation in kernel. Many other systems do that to help porting code between CPUs, and it's easier to work with that than to have builds for a large variety of CPUs in the same family. I'm sure that many distros would prefer to provide a build optimized for the fastest CPUs around and support the other ones in compatiblity mode than optimize for the smallest ones in order to support everyone.

Also, I think that if we start adding emulation, a global and per-task counter would immensely help to know what processes make intensive use of emulation.

Willy

#22 lore raw
Quoted 5 lines · Willy Tarreau

Also, I think that if we start adding emulation, a global and per-task counter would immensely help to know what processes make intensive use of emulation.

Agreed.

My first question would be if the interpreter in KVM can be reused in any way.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#23 lore raw
Quoted 7 lines · H. Peter Anvin
Quoted 5 lines · Willy Tarreau

Also, I think that if we start adding emulation, a global and per-task counter would immensely help to know what processes make intensive use of emulation.

Quoted 6 lines

Agreed.

My first question would be if the interpreter in KVM can be reused in any way.

In theory yes. There would need to be a bit of work to disassociate it from kvm, but nothing too difficult.

Note that the kvm x86 emulator is more general than need be (emulates real mode code and cpl 0 instructions) and less general than needed (many instructions are not emulated, for example nopl).

Signature · 1 line
error compiling committee.c: too many arguments to function
#24 lore raw
Quoted 2 lines

In theory yes. There would need to be a bit of work to disassociate it from kvm, but nothing too difficult.

For the tiny cases that actually matter using the KVM code appears a bit over the top.

#25 lore raw
Quoted 5 lines · Alan Cox
Quoted 2 lines

In theory yes. There would need to be a bit of work to disassociate it from kvm, but nothing too difficult.

For the tiny cases that actually matter using the KVM code appears a bit over the top.

In the short term, yes, of course. However, if we're going to do emulation, we might as well do it right.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#26 lore raw
Quoted 9 lines · On Tue, 10 Nov 2009 09:08:20 -0800 "H. Peter Anvin" <[email protected]> wrote:
Quoted 5 lines · Alan Cox
Quoted 2 lines

In theory yes. There would need to be a bit of work to disassociate it from kvm, but nothing too difficult.

For the tiny cases that actually matter using the KVM code appears a bit over the top.

In the short term, yes, of course. However, if we're going to do emulation, we might as well do it right.

Why is using KVM doing it right ? It sounds like its doing it slowly, and hideously memory inefficiently. You are solving an uninteresting general case problem when you just need two tiny fixups (or perhaps 3 if you want to fix up early x86-64 prefetch)

#27 lore raw
Quoted 8 lines · Alan Cox
Quoted 3 lines

In the short term, yes, of course. However, if we're going to do emulation, we might as well do it right.

Why is using KVM doing it right ? It sounds like its doing it slowly, and hideously memory inefficiently. You are solving an uninteresting general case problem when you just need two tiny fixups (or perhaps 3 if you want to fix up early x86-64 prefetch)

Why do we only need "two tiny fixups"? Where do we draw the line in terms of ISA compatibility? One could easily argue that the Right Thing[TM] is to be able to process any optional instruction -- otherwise one has a very difficult place to draw a line.

Consider SSE3, for example. Why should the same concept not apply to SSE3 instructions as to CMOV?

-hpa

#28 lore raw
Quoted 6 lines · H. Peter Anvin
Quoted 6 lines

Why is using KVM doing it right ? It sounds like its doing it slowly, and hideously memory inefficiently. You are solving an uninteresting general case problem when you just need two tiny fixups (or perhaps 3 if you want to fix up early x86-64 prefetch)

Quoted 8 lines

Why do we only need "two tiny fixups"? Where do we draw the line in terms of ISA compatibility? One could easily argue that the Right Thing[TM] is to be able to process any optional instruction -- otherwise one has a very difficult place to draw a line.

Consider SSE3, for example. Why should the same concept not apply to SSE3 instructions as to CMOV?

Because then user programs would run 20x or more slower than the user expects. Better to terminate early (and teach userspace how to choose the instruction subset correctly).

Signature · 1 line
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
#29 lore raw
Quoted 8 lines · Avi Kivity
Quoted 3 lines

Consider SSE3, for example. Why should the same concept not apply to SSE3 instructions as to CMOV?

Because then user programs would run 20x or more slower than the user expects. Better to terminate early (and teach userspace how to choose the instruction subset correctly).

I picked the example carefully: SSE3 is a small set of instructions which probably aren't used very heavily. In that sense, it has *exactly* the same properties as CMOV - if you have the source, you're better off recompiling, but it *might* help you if you happen to only have a binary.

What I want people to understand is that this is a *huge* rathole, and it doesn't have any obvious bottom that I can see.

-hpa

#30 lore raw
Quoted 10 lines · H. Peter Anvin
Quoted 8 lines · Avi Kivity
Quoted 3 lines

Consider SSE3, for example. Why should the same concept not apply to SSE3 instructions as to CMOV?

Because then user programs would run 20x or more slower than the user expects. Better to terminate early (and teach userspace how to choose the instruction subset correctly).

Quoted 8 lines

I picked the example carefully: SSE3 is a small set of instructions which probably aren't used very heavily. In that sense, it has *exactly* the same properties as CMOV - if you have the source, you're better off recompiling, but it *might* help you if you happen to only have a binary.

What I want people to understand is that this is a *huge* rathole, and it doesn't have any obvious bottom that I can see.

Indeed, but there is a difference between [cmpxchg, bswap, cmov, nopl] on one side and [sse*] on the other : distros are built assuming the former are always available while they are not always. And the distro which make the difference have to provide an dedicated build for earlier systems just for compatibility. SSE*, 3dnow* etc... are only used by a handful of media players/converters/encoders which are able to detect themselves what to use and already have the necessary fallbacks because these instruction sets vary too much between processors and vendors.

One could argue that cmpxchg/bswap/xadd are supported by 486 and that implementing them for 386 is almost useless now (though it costs almost nothing to provide them, I did a few years ago).

CMOV/NOPL are rarely used, thus have no reason to cause a massive performance drop, but are frequent enough (at least cmov) for almost any program to have at least one or two inside, making it incompatible with a given processor, and are almost obvious to implement too.

SSE*/3dnow* would be much much harder and would only serve very few programs, and serve them badly because when they're used, it would be intensive.

I personally am not against being able to emulate every optional instruction, quite the opposite instead. It's just that if in order to do this, we add cost to the other obvious ones, we lose what we expected to win (simplicity and efficiency).

Regards,
Willy

#31 lore raw
Quoted 10 lines · Willy Tarreau

Indeed, but there is a difference between [cmpxchg, bswap, cmov, nopl] on one side and [sse*] on the other : distros are built assuming the former are always available while they are not always. And the distro which make the difference have to provide an dedicated build for earlier systems just for compatibility. SSE*, 3dnow* etc... are only used by a handful of media players/converters/encoders which are able to detect themselves what to use and already have the necessary fallbacks because these instruction sets vary too much between processors and vendors.

That is increasingly not true since gcc is now doing autovectorization.

Quoted 8 lines

One could argue that cmpxchg/bswap/xadd are supported by 486 and that implementing them for 386 is almost useless now (though it costs almost nothing to provide them, I did a few years ago).

CMOV/NOPL are rarely used, thus have no reason to cause a massive performance drop, but are frequent enough (at least cmov) for almost any program to have at least one or two inside, making it incompatible with a given processor, and are almost obvious to implement too.

I could 970 cmovs in libc out of 322660 instructions. That is one in 333 instruction. In other words, a trap-and-emulate of some 500 cycles would add some two cycles *per instruction* during execution -- hardly an insignificant number. All in all, any of this is really only useful as a limp.

Quoted 8 lines

SSE*/3dnow* would be much much harder and would only serve very few programs, and serve them badly because when they're used, it would be intensive.

I personally am not against being able to emulate every optional instruction, quite the opposite instead. It's just that if in order to do this, we add cost to the other obvious ones, we lose what we expected to win (simplicity and efficiency).

I don't see any particular subset as being more obvious than the other, with the *possible* exception of NOPL, simply because NOPL was undocumented for so long.

-hpa

#32 lore raw
Quoted 12 lines · H. Peter Anvin
Quoted 10 lines · Willy Tarreau

Indeed, but there is a difference between [cmpxchg, bswap, cmov, nopl] on one side and [sse*] on the other : distros are built assuming the former are always available while they are not always. And the distro which make the difference have to provide an dedicated build for earlier systems just for compatibility. SSE*, 3dnow* etc... are only used by a handful of media players/converters/encoders which are able to detect themselves what to use and already have the necessary fallbacks because these instruction sets vary too much between processors and vendors.

Quoted 1 line

That is increasingly not true since gcc is now doing autovectorization.

But programs have to be built to use that specific platform anyway ; this is different from all programs built with support for CMOV enabled by default and which will work on 95% of the platforms.

(...)

Quoted 2 lines

I could 970 cmovs in libc out of 322660 instructions. That is one in 333 instruction.

Not bad, I agree ! But on the C3, CMOV from/to register is implemented. It's only CMOV from/to memory which has to be emulated, which makes it a lot less common. Anyway that's why we need counters, so that the user knows when he really ought to recompile.

(...)

Quoted 3 lines

I don't see any particular subset as being more obvious than the other, with the *possible* exception of NOPL, simply because NOPL was undocumented for so long.

well, simply the availability of binaries making use of them. I'm not sure you would find SSE* instructions in your libc where you found the 970 cmov. For NOPL, that's different, I first heard about it in this thread, and my C3 running with the CMOV patch has never complained from missing it :-)

Regards,
Willy

#33 lore raw
In reply to Willy Tarreau

Hi!

Quoted 4 lines

Indeed, but there is a difference between [cmpxchg, bswap, cmov, nopl] on one side and [sse*] on the other : distros are built assuming the former are always available while they are not always. And the distro

Well, fix the distros...

Quoted 6 lines

which make the difference have to provide an dedicated build for earlier systems just for compatibility. SSE*, 3dnow* etc... are only used by a handful of media players/converters/encoders which are able to detect themselves what to use and already have the necessary fallbacks because these instruction sets vary too much between processors and vendors.

Quoted 6 lines

One could argue that cmpxchg/bswap/xadd are supported by 486 and that implementing them for 386 is almost useless now (though it costs almost nothing to provide them, I did a few years ago).

CMOV/NOPL are rarely used, thus have no reason to cause a massive performance drop, but are frequent enough (at least cmov) for almost

*One* CMOV in the inner loop will make your performance go down 20x.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#34 lore raw
Quoted 8 lines · Pavel Machek

Hi!

Quoted 4 lines

Indeed, but there is a difference between [cmpxchg, bswap, cmov, nopl] on one side and [sse*] on the other : distros are built assuming the former are always available while they are not always. And the distro

Well, fix the distros...

you know like me that it's as easy as useless to point the finger at distros, because people running on low end want something that works and people running on high end want something that runs fast. In order to satisfy every one, you would have to build with optimizations for every CPU around, which does not make sense. Simply count the number of CPU variants in the kernel, and imagine that many CDs/DVDs for a single platform distro.

However, targetting the most common denominator of high end machines (basically i686) and having the lower end systems experience a tiny slowdown is not stupid at all since performance is not what matters the most there. The higher end systems will simply be able to run CPU-specific optimizations per-program as they already do right now.

(...)

Quoted 4 lines
Quoted 2 lines

CMOV/NOPL are rarely used, thus have no reason to cause a massive performance drop, but are frequent enough (at least cmov) for almost

*One* CMOV in the inner loop will make your performance go down 20x.

yes, just like with emulated FPU or trapped unaligned accesses. It's just like flying fishes. They exist but they aren't the most common ones. If people encounter these cases on a specific program, then they just have to recompile it if it is a problem. At least they don't rebuild the whole distro. And once again, I've been using cmpxchg/bswap emulation for years on my i386 without feeling any need for a rebuild, and CMOV emulation for years now on my mini-itx C3 without any problem either. These are real experiences, not just fears of imaginary problems. Yes I can design a program to run 400 times slower on these machines if I want. I just don't feel the need to do so and apparently existing programs' authors didn't either.

Regards,
Willy

#35 lore raw
Quoted 11 lines · Willy Tarreau

yes, just like with emulated FPU or trapped unaligned accesses. It's just like flying fishes. They exist but they aren't the most common ones. If people encounter these cases on a specific program, then they just have to recompile it if it is a problem. At least they don't rebuild the whole distro. And once again, I've been using cmpxchg/bswap emulation for years on my i386 without feeling any need for a rebuild, and CMOV emulation for years now on my mini-itx C3 without any problem either. These are real experiences, not just fears of imaginary problems. Yes I can design a program to run 400 times slower on these machines if I want. I just don't feel the need to do so and apparently existing programs' authors didn't either.

Willy, perhaps you can come up with a list of features you think should be emulated, together with an explanation of why you opted for that list of features and *did not* opt for others.

Note: emulated FPU is a special subcase. The FPU operations are heavyweight enough that the overhead of trapping versus library calls is relatively insignificant.

-hpa

#36 lore raw
Quoted 3 lines · H. Peter Anvin

Willy, perhaps you can come up with a list of features you think should be emulated, together with an explanation of why you opted for that list of features and *did not* opt for others.

Well, the instructions I had to emulate were the result of failures to run standard distros on older machines. When I ran a 486 distro on my old 386, I found that almost everything worked except a few programs making use of BSWAP for htonl(), and a small group of other ones making occasional use of CMPXCHG for mutex handling. So I checked the differences between 386 and 486 and found that the last remaining one was XADD which I did not find in my binaries but which was really obvious to implement, so it made sense to complete the emulator. That said, a feature was missing with CMPXCHG. It was generally used with a LOCK prefix which could not be emulated. In practice, that wasn't an issue since I did not have any SMP i386 and I think we might only find them on some very specific industrial boards if any.

So with just CMPXCHG + BSWAP (+xadd for the sake of completeness), my 486 distro was fully operational on my 386.

At one point I got a laptop equipped with a K6-2. This one lacked CMOV but I was very rarely hit, so I did not bother extending the patch.

Later when I bought a VIA C3 the same issue happened when I sometimes transferred a binary from my athlon to the C3 (both mounted the same NFS home dirs, and my GCC on the athlon was optimizing by default for 686). Then I experimented a little bit with CMOV, discovering that it only implemented CMOV reg,reg. So I added the instruction to the patch.

I then regularly started to get mails from people installing i686 distros on their C3 or K6 boards and who wanted the patch for the same reasons (K6 induced people in error because of the "6" in its name).

I remember that Debian at one point merged the part of the patch providing the 486 emulation in their kernel. I don't know if they finally merged the CMOV part too, I think not because they did not optimize for 686.

But what I can say is that after emulating those instructions, I never got any illegal instruction anymore on my systems. Here Matteo reports an issue with NOPL, which might have been introduced with newer compilers. So if we get NOPL+CMOV, I think that every CPU starting from 486 will be able to execute all the applications I have been running on those machines. We can add the 486 ones if we think it's worth it.

Once again, I have no argument against emulating more instructions. It's just that I never needed them, and I fear that doing so might render the code a lot more complex and slower. Maybe time will prove me wrong and I will have no problem with that. We can re-open this thread after the first report of a SIGILL with the patch applied.

So in my opinion, we should have :
- CMOV (for 486, Pentium, C3, K6, ...)
- NOPL (newcomer)

And if we want to extend down to i386 :
- BSWAP (=htonl)
- CMPXCHG (mutex)
- XADD (never encoutered but cheap)

I still have the 2.4 patch for BSWAP, CMPXCHG, CMOV and XADD lying around. I'm appending it to the end of this mail in case it can fuel the discussion. I've not ported it to 2.6 yet simply because my old systems are still on 2.4, but volunteers are welcome :-)

Quoted 3 lines

Note: emulated FPU is a special subcase. The FPU operations are heavyweight enough that the overhead of trapping versus library calls is relatively insignificant.

Agreed for most of them, though some cheap ones such as FADD can see a huge difference. In fact it's mostly that it's been common for a long time to see slow software FPU (till 386 & 486-SX), so it's been avoided for a long time.

Regards,
Willy

---

Documentation/Configure.help +60 -0
diff -urN linux-2.4.25-wt2-base/Documentation/Configure.help linux-2.4.25-wt2/Documentation/Configure.help
@@ -5279,6 +5279,66 @@
 
   Note, this kernel will not boot on older (pre model 9) C3s.
 
+486 emulation
+CONFIG_CPU_EMU486
+  When used on a 386, Linux can emulate 3 instructions from the 486 set.
+  This allows user space programs compiled for 486 to run on a 386
+  without crashing with a SIGILL. As any emulation, performance will be
+  very low, but since these instruction are not often used, this might
+  not hurt. The emulated instructions are :
+     - bswap (does the same as htonl())
+     - cmpxchg (used in multi-threading, mutex locking)
+     - xadd (rarely used)
+
+  Note that this can also allow Step-A 486's to correctly run multi-thread
+  applications since cmpxchg has a wrong opcode on this early CPU.
+
+  Don't use this to enable multi-threading on an SMP machine, the lock
+  atomicity can't be guaranted !
+
+  Although it's highly preferable that you only execute programs targetted
+  for your CPU, it may happen that, consecutively to a hardware replacement,
+  or during rescue of a damaged system, you have to execute such programs
+  on an inadapted processor. In this case, this option will help you get
+  your programs working, even if they will be slower.
+
+  It is recommended that you say N here in any case, except for the
+  kernels that you will use on your rescue disks.
+  
+  This option should not be left on by default, because it means that
+  you execute a program not targetted for your CPU. You should recompile
+  your applications whenever possible.
+
+  If you are not sure, say N.
+
+Pentium-Pro CMOV emulation
+CONFIG_CPU_EMU686
+  Intel Pentium-Pro processor brought a new set of instructions borrowed
+  from RISC processors, which permit to write many simple conditionnal
+  blocks without a branch instruction, thus being faster. They are supported
+  on all PentiumII, PentiumIII, Pentium4 and Celerons to date. GCC generates
+  these instructions when "-march=i686" is specified. There is an ever
+  increasing number of programs compiled with this option, that will simply
+  crash on 386/486/Pentium/AmdK6 and others when trying to execute the
+  faulty instruction.
+
+  Although it's highly preferable that you only execute programs targetted
+  for your CPU, it may happen that, consecutively to a hardware replacement,
+  or during rescue of a damaged system, you have to execute such programs
+  on an inadapted processor. In this case, this option will help you keep
+  your programs working, even if some may be noticeably slower : an overhead
+  of 1us has been measured on a k6-2/450 (about 450 cycles).
+
+  It is recommended that you say N here in any case, except for the
+  kernels that you will use on your rescue disks. This emulation typically
+  increases a bzImage with 500 bytes.
+  
+  This option should not be left on by default, because it means that
+  you execute a program not targetted for your CPU. You should recompile
+  your applications whenever possible.
+
+  If you are not sure, say N.
+
 32-bit PDC
 CONFIG_PDC_NARROW
   Saying Y here will allow developers with a C180, C200, C240, C360,
arch/i386/config.in +13 -0
diff -urN linux-2.4.25-wt2-base/arch/i386/config.in linux-2.4.25-wt2/arch/i386/config.in
@@ -59,6 +59,8 @@
    define_bool CONFIG_RWSEM_XCHGADD_ALGORITHM n
    define_bool CONFIG_X86_PPRO_FENCE y
    define_bool CONFIG_X86_F00F_WORKS_OK n
+   bool '486 emulation' CONFIG_CPU_EMU486
+   dep_bool 'Pentium-Pro CMOV emulation' CONFIG_CPU_EMU686 $CONFIG_CPU_EMU486
 else
    define_bool CONFIG_X86_WP_WORKS_OK y
    define_bool CONFIG_X86_INVLPG y
@@ -75,6 +77,7 @@
    define_bool CONFIG_X86_ALIGNMENT_16 y
    define_bool CONFIG_X86_PPRO_FENCE y
    define_bool CONFIG_X86_F00F_WORKS_OK n
+   bool 'Pentium-Pro CMOV emulation' CONFIG_CPU_EMU686
 fi
 if [ "$CONFIG_M586" = "y" ]; then
    define_int  CONFIG_X86_L1_CACHE_SHIFT 5
@@ -82,6 +85,7 @@
    define_bool CONFIG_X86_ALIGNMENT_16 y
    define_bool CONFIG_X86_PPRO_FENCE y
    define_bool CONFIG_X86_F00F_WORKS_OK n
+   bool 'Pentium-Pro CMOV emulation' CONFIG_CPU_EMU686
 fi
 if [ "$CONFIG_M586TSC" = "y" ]; then
    define_int  CONFIG_X86_L1_CACHE_SHIFT 5
@@ -90,6 +94,7 @@
    define_bool CONFIG_X86_HAS_TSC y
    define_bool CONFIG_X86_PPRO_FENCE y
    define_bool CONFIG_X86_F00F_WORKS_OK n
+   bool 'Pentium-Pro CMOV emulation' CONFIG_CPU_EMU686
 fi
 if [ "$CONFIG_M586MMX" = "y" ]; then
    define_int  CONFIG_X86_L1_CACHE_SHIFT 5
@@ -99,6 +104,7 @@
    define_bool CONFIG_X86_GOOD_APIC y
    define_bool CONFIG_X86_PPRO_FENCE y
    define_bool CONFIG_X86_F00F_WORKS_OK n
+   bool 'Pentium-Pro CMOV emulation' CONFIG_CPU_EMU686
 fi
 if [ "$CONFIG_M686" = "y" ]; then
    define_int  CONFIG_X86_L1_CACHE_SHIFT 5
@@ -139,6 +145,7 @@
    define_bool CONFIG_X86_ALIGNMENT_16 y
    define_bool CONFIG_X86_HAS_TSC y
    define_bool CONFIG_X86_USE_PPRO_CHECKSUM y
+   bool 'Pentium-Pro CMOV emulation' CONFIG_CPU_EMU686
 fi
 if [ "$CONFIG_MK8" = "y" ]; then
    # for now. may later want to add SSE support and optimized
@@ -162,6 +169,7 @@
    define_bool CONFIG_X86_USE_STRING_486 y
    define_bool CONFIG_X86_ALIGNMENT_16 y
    define_bool CONFIG_X86_F00F_WORKS_OK y
+   bool 'Pentium-Pro CMOV emulation' CONFIG_CPU_EMU686
 fi
 if [ "$CONFIG_MCYRIXIII" = "y" ]; then
    define_int  CONFIG_X86_L1_CACHE_SHIFT 5
@@ -170,6 +178,7 @@
    define_bool CONFIG_X86_USE_3DNOW y
    define_bool CONFIG_X86_USE_PPRO_CHECKSUM y
    define_bool CONFIG_X86_F00F_WORKS_OK y
+   bool 'Pentium-Pro CMOV emulation' CONFIG_CPU_EMU686
 fi
 if [ "$CONFIG_MVIAC3_2" = "y" ]; then
    define_int  CONFIG_X86_L1_CACHE_SHIFT 5
@@ -177,6 +186,7 @@
    define_bool CONFIG_X86_ALIGNMENT_16 y
    define_bool CONFIG_X86_USE_PPRO_CHECKSUM y
    define_bool CONFIG_X86_F00F_WORKS_OK y
+   bool 'Pentium-Pro CMOV emulation' CONFIG_CPU_EMU686
 fi
 if [ "$CONFIG_MCRUSOE" = "y" ]; then
    define_int  CONFIG_X86_L1_CACHE_SHIFT 5
@@ -189,6 +199,7 @@
    define_bool CONFIG_X86_USE_PPRO_CHECKSUM y
    define_bool CONFIG_X86_OOSTORE y
    define_bool CONFIG_X86_F00F_WORKS_OK y
+   bool 'Pentium-Pro CMOV emulation' CONFIG_CPU_EMU686
 fi
 if [ "$CONFIG_MWINCHIP2" = "y" ]; then
    define_int  CONFIG_X86_L1_CACHE_SHIFT 5
@@ -197,6 +208,7 @@
    define_bool CONFIG_X86_USE_PPRO_CHECKSUM y
    define_bool CONFIG_X86_OOSTORE y
    define_bool CONFIG_X86_F00F_WORKS_OK y
+   bool 'Pentium-Pro CMOV emulation' CONFIG_CPU_EMU686
 fi
 if [ "$CONFIG_MWINCHIP3D" = "y" ]; then
    define_int  CONFIG_X86_L1_CACHE_SHIFT 5
@@ -205,6 +217,7 @@
    define_bool CONFIG_X86_USE_PPRO_CHECKSUM y
    define_bool CONFIG_X86_OOSTORE y
    define_bool CONFIG_X86_F00F_WORKS_OK y
+   bool 'Pentium-Pro CMOV emulation' CONFIG_CPU_EMU686
 fi
 
 bool 'Machine Check Exception' CONFIG_X86_MCE
arch/i386/kernel/traps.c +508 -0

525 lines not on this page · raw message

---

#37 lore raw
Quoted 5 lines · Willy Tarreau
Quoted 3 lines · H. Peter Anvin

Willy, perhaps you can come up with a list of features you think should be emulated, together with an explanation of why you opted for that list of features and *did not* opt for others.

Quoted 13 lines

Well, the instructions I had to emulate were the result of failures to run standard distros on older machines. When I ran a 486 distro on my old 386, I found that almost everything worked except a few programs making use of BSWAP for htonl(), and a small group of other ones making occasional use of CMPXCHG for mutex handling. So I checked the differences between 386 and 486 and found that the last remaining one was XADD which I did not find in my binaries but which was really obvious to implement, so it made sense to complete the emulator. That said, a feature was missing with CMPXCHG. It was generally used with a LOCK prefix which could not be emulated. In practice, that wasn't an issue since I did not have any SMP i386 and I think we might only find them on some very specific industrial boards if any.

Linux doesn't support 386 SMP anyway, and we really don't support 486 SMP either since noone relevant seems to have a board we can test on.

Quoted 7 lines

But what I can say is that after emulating those instructions, I never got any illegal instruction anymore on my systems. Here Matteo reports an issue with NOPL, which might have been introduced with newer compilers. So if we get NOPL+CMOV, I think that every CPU starting from 486 will be able to execute all the applications I have been running on those machines. We can add the 486 ones if we think it's worth it.

NOPL was introduced with a recent binutils(!) change. They might have backed that one out.

Quoted 24 lines

Once again, I have no argument against emulating more instructions. It's just that I never needed them, and I fear that doing so might render the code a lot more complex and slower. Maybe time will prove me wrong and I will have no problem with that. We can re-open this thread after the first report of a SIGILL with the patch applied.

So in my opinion, we should have :
- CMOV (for 486, Pentium, C3, K6, ...)
- NOPL (newcomer)

And if we want to extend down to i386 :
- BSWAP (=htonl)
- CMPXCHG (mutex)
- XADD (never encoutered but cheap)

I still have the 2.4 patch for BSWAP, CMPXCHG, CMOV and XADD lying around. I'm appending it to the end of this mail in case it can fuel the discussion. I've not ported it to 2.6 yet simply because my old systems are still on 2.4, but volunteers are welcome :-)

Quoted 3 lines

Note: emulated FPU is a special subcase. The FPU operations are heavyweight enough that the overhead of trapping versus library calls is relatively insignificant.

Quoted 7 lines

Agreed for most of them, though some cheap ones such as FADD can see a huge difference. In fact it's mostly that it's been common for a long time to see slow software FPU (till 386 & 486-SX), so it's been avoided for a long time.

Regards,
Willy

I immediately note that you have absolutely no check on the code segment, either in terms of code segment limits or even that we're in the right mode. Furthermore, you read user space -- code in user space is still user space -- without get_user(). We also need NX protection to be honoured, and the various special subtleties of the x86 instruction format (15-byte limit, for example) to be preserved: they aren't just there randomly, but are there to protect against specific failures.

*THIS* is the kind of complexity that makes me think that having a single source for all interpretation done in the kernel is the preferred option.

-hpa

#38 lore raw
Quoted 3 lines · H. Peter Anvin

*THIS* is the kind of complexity that makes me think that having a single source for all interpretation done in the kernel is the preferred option.

Definitely agreed ... The NX code is quite a maze right now, so changes to it should come generously laced with cleanups.

Ingo

#39 lore raw
Quoted 9 lines · Ingo Molnar
Quoted 3 lines · H. Peter Anvin

*THIS* is the kind of complexity that makes me think that having a single source for all interpretation done in the kernel is the preferred option.

Definitely agreed ... The NX code is quite a maze right now, so changes to it should come generously laced with cleanups.

BTW, I don't see why we should be impacted by NX. Trying to execute from an NX page would return a SEGV, not SIGILL, so we should not be bothered, am I wrong ?

Willy

#40 lore raw
Quoted 8 lines · Willy Tarreau
Quoted 7 lines · Ingo Molnar
Quoted 3 lines · H. Peter Anvin

*THIS* is the kind of complexity that makes me think that having a single source for all interpretation done in the kernel is the preferred option.

Quoted 6 lines
Quoted 2 lines

Definitely agreed ... The NX code is quite a maze right now, so changes to it should come generously laced with cleanups.

BTW, I don't see why we should be impacted by NX. Trying to execute from an NX page would return a SEGV, not SIGILL, so we should not be bothered, am I wrong ?

Yes. Consider a page-crossing instruction.

-hpa

#41 lore raw
Quoted 9 lines · H. Peter Anvin
Quoted 8 lines · Willy Tarreau
Quoted 7 lines · Ingo Molnar
Quoted 3 lines · H. Peter Anvin

*THIS* is the kind of complexity that makes me think that having a single source for all interpretation done in the kernel is the preferred option.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Definitely agreed ... The NX code is quite a maze right now, so changes to it should come generously laced with cleanups.

BTW, I don't see why we should be impacted by NX. Trying to execute from an NX page would return a SEGV, not SIGILL, so we should not be bothered, am I wrong ?

Yes. Consider a page-crossing instruction.

OK, but to be pragmatic, NX is there to prevent execution of instructions in the stack (or heap) during buffer overflows. If we only implement the few instructions lised in previous mail, there is very little benefit to check for NX :

- those instructions cannot jump to other code, they just change one register or memory location at most (or just nop)

- once we return from the signal handler, if we have crossed a NX page boundary, the program will segfault anyway, taking with it the change we just completed.

- last, the probability of having an NX page just after an executable one seems too tight to me to even constitute an attack vector ! BTW, I'm not even certain that all CPUs correctly implement this check !

On the other hand, I certainly understand why this would be an important check in a complete emulator which could parse and emulate a flow of instructions.

So in short, I think we could reasonably implement CMOV/NOPL with the instruction length control, with getuser for data accesses but without checking the code pages permissions if we know that the CPU could already fetch the beginning of the instruction correctly to cause an invalid opcode trap.

I'm not saying this is perfect, just that this is reasonable.

Regards,
Willy

#42 lore raw
Quoted 6 lines · Willy Tarreau

- last, the probability of having an NX page just after an executable one seems too tight to me to even constitute an attack vector ! BTW, I'm not even certain that all CPUs correctly implement this check !

Do you have *any* *evidence* *whatsoever* for that assertion?!

I personally will consider something that doesn't implement proper security check to be a potential security hole and will NAK the patch.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#43 lore raw
Quoted 9 lines · H. Peter Anvin
Quoted 6 lines · Willy Tarreau

- last, the probability of having an NX page just after an executable one seems too tight to me to even constitute an attack vector ! BTW, I'm not even certain that all CPUs correctly implement this check !

Do you have *any* *evidence* *whatsoever* for that assertion?!

No, just basic feeling based on implementation cost and difficulty vs gains as I explained.

Quoted 2 lines

I personally will consider something that doesn't implement proper security check to be a potential security hole and will NAK the patch.

Even in the case of the NOPL instruction ? I clearly don't see the potential security hole !

Willy

#44 lore raw
Quoted 5 lines · Willy Tarreau
Quoted 2 lines

Do you have *any* *evidence* *whatsoever* for that assertion?!

No, just basic feeling based on implementation cost and difficulty vs gains as I explained.

Quite on the contrary; in hardware it would be pretty hard to *not* do the right thing.

Quoted 6 lines
Quoted 2 lines

I personally will consider something that doesn't implement proper security check to be a potential security hole and will NAK the patch.

Even in the case of the NOPL instruction ? I clearly don't see the potential security hole !

You have it backwards. Prove that there *isn't* one and we'll talk.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#45 lore raw
Quoted 9 lines · H. Peter Anvin
Quoted 5 lines · Willy Tarreau
Quoted 2 lines

Do you have *any* *evidence* *whatsoever* for that assertion?!

No, just basic feeling based on implementation cost and difficulty vs gains as I explained.

Quite on the contrary; in hardware it would be pretty hard to *not* do the right thing.

It just depends on how the instruction prefetcher is implemented. If the check is only performed on the first byte of the opcode, we can miss the tail. In my experience, intel processors have been doing instruction checks right, but I have no reason to be absolutely certain that all other vendors do that right, especially those targetting cheap embedded systems.

Eventhough this one is not for this precise case, here's an example of such a missed boundary check :

http://download.intel.com/design/processor/specupdt/315593.pdf

AK27: "general protection fault may not be signaled on data segment
limit violation above 4-G limit". Status: "no fix".

Note that I don't find this can present a significant vulnerability risk. Maybe if someone comes with a concrete case where it is a real trouble, they will fix it.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I personally will consider something that doesn't implement proper security check to be a potential security hole and will NAK the patch.

Even in the case of the NOPL instruction ? I clearly don't see the potential security hole !

You have it backwards. Prove that there *isn't* one and we'll talk.

You're not helping. You're asking me to prove that something has no issue, all I can say is that it does not have any issue I can imagine. Proving the opposite with an example would be easier.

All I can say is that executing a NOP results in no state change in the processor except the instruction pointer which points to the next instruction after execution. Since a NOP changes nothing, it cannot be used alone to provide any privilege, access to data or any such thing. Since it does not perform any jump, it cannot either be used to take back control of the execution flow. And it is certain that the next instruction after it will be executed, so if the NOP crosses a page boundary and completes on a non-executable one, the next instruction will trigger the PF.

So I can't see how a NOP can be used to circumvent any protection.

Willy

#46 lore raw
Quoted 11 lines · Willy Tarreau

All I can say is that executing a NOP results in no state change in the processor except the instruction pointer which points to the next instruction after execution. Since a NOP changes nothing, it cannot be used alone to provide any privilege, access to data or any such thing. Since it does not perform any jump, it cannot either be used to take back control of the execution flow. And it is certain that the next instruction after it will be executed, so if the NOP crosses a page boundary and completes on a non-executable one, the next instruction will trigger the PF.

So I can't see how a NOP can be used to circumvent any protection.

So a nop(l) sled won't be a problem, right?

#47 lore raw
Quoted 11 lines · Matt Thrailkill
Quoted 10 lines · Willy Tarreau

All I can say is that executing a NOP results in no state change in the processor except the instruction pointer which points to the next instruction after execution. Since a NOP changes nothing, it cannot be used alone to provide any privilege, access to data or any such thing. Since it does not perform any jump, it cannot either be used to take back control of the execution flow. And it is certain that the next instruction after it will be executed, so if the NOP crosses a page boundary and completes on a non-executable one, the next instruction will trigger the PF.

Quoted 3 lines
Quoted 1 line

So I can't see how a NOP can be used to circumvent any protection.

So a nop(l) sled won't be a problem, right?

Right. However we just noticed that with the KVM emulator, you can make it loop for a long time if you feed it with prefixes only. For instance, write a function which does zillions of 0x66 (data size prefix) then return (0xC3) : 66 66 66 ... 66 C3.

This is typically the sort of things we must be very careful about in emulators, because we don't want users to steal large amounts of system CPU time doing nothing.

Regards,
Willy

#48 lore raw
Quoted 10 lines · Willy Tarreau

Right. However we just noticed that with the KVM emulator, you can make it loop for a long time if you feed it with prefixes only. For instance, write a function which does zillions of 0x66 (data size prefix) then return (0xC3) : 66 66 66 ... 66 C3.

This is typically the sort of things we must be very careful about in emulators, because we don't want users to steal large amounts of system CPU time doing nothing.

That is a (serious) bug in the KVM interpreter, and indeed the exact kind of issues interpreters tend to have... which is why I'd like one piece of code with one set of bugs, and more eyeballs on that one piece of code so they can be fixed.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#49 lore raw
Quoted 12 lines · H. Peter Anvin
Quoted 10 lines · Willy Tarreau

Right. However we just noticed that with the KVM emulator, you can make it loop for a long time if you feed it with prefixes only. For instance, write a function which does zillions of 0x66 (data size prefix) then return (0xC3) : 66 66 66 ... 66 C3.

This is typically the sort of things we must be very careful about in emulators, because we don't want users to steal large amounts of system CPU time doing nothing.

Quoted 4 lines

That is a (serious) bug in the KVM interpreter, and indeed the exact kind of issues interpreters tend to have... which is why I'd like one piece of code with one set of bugs, and more eyeballs on that one piece of code so they can be fixed.

Well, I could try to work on a fix (basically the same principle as in mine, with prefix flags), but I simply don't know how to test the code. I've never experimented with KVM yet and learned it embeds an emulator for the first time a few days ago in this thread :-/ If it's easy to make use of it, I'm not opposed to try.

Willy

#50 lore raw
Quoted 18 lines · Willy Tarreau
Quoted 12 lines · H. Peter Anvin
Quoted 10 lines · Willy Tarreau

Right. However we just noticed that with the KVM emulator, you can make it loop for a long time if you feed it with prefixes only. For instance, write a function which does zillions of 0x66 (data size prefix) then return (0xC3) : 66 66 66 ... 66 C3.

This is typically the sort of things we must be very careful about in emulators, because we don't want users to steal large amounts of system CPU time doing nothing.

Quoted 4 lines

That is a (serious) bug in the KVM interpreter, and indeed the exact kind of issues interpreters tend to have... which is why I'd like one piece of code with one set of bugs, and more eyeballs on that one piece of code so they can be fixed.

Quoted 5 lines

Well, I could try to work on a fix (basically the same principle as in mine, with prefix flags), but I simply don't know how to test the code. I've never experimented with KVM yet and learned it embeds an emulator for the first time a few days ago in this thread :-/ If it's easy to make use of it, I'm not opposed to try.

When working on dosemu and emulating EGA 16 color graphics we had to unmap the frame buffer so we would cause move instructions to fault. Trapping for each mov instruction in the loops that wrote to the frame buffer was unusably slow. Ultimately that was fixed by trapping on the first instruction and then running in the emulator until we had gone N instructions without hitting an instruction we would trap for. The result was usable software emulated EGA graphics.

I expect the same logic will apply any time there is a trapped and emulated instruction in an inner loop. Emulating the entire loop will be more efficient than trapping for each loop iteration.

Eric

#51 lore raw
Quoted 9 lines · Eric W. Biederman

When working on dosemu and emulating EGA 16 color graphics we had to unmap the frame buffer so we would cause move instructions to fault. Trapping for each mov instruction in the loops that wrote to the frame buffer was unusably slow. Ultimately that was fixed by trapping on the first instruction and then running in the emulator until we had gone N instructions without hitting an instruction we would trap for. The result was usable software emulated EGA graphics.

Quoted 4 lines

I expect the same logic will apply any time there is a trapped and emulated instruction in an inner loop. Emulating the entire loop will be more efficient than trapping for each loop iteration.

Yes, this is pretty typical. In terms of EGA/VGA it depends heavily on how the application is coded, since it is possible to put EGA/VGA into modes where the frame buffer depends mostly like memory except at specific I/O points, and other modes where the frame buffer behaves nothing like memory at all and every reference needs to be handled specially. In real use, the former tends to dominate simply because it's the sane way to code, but the only way to make the latter perform sanely at all is to interpret everything.

-hpa

#52 lore raw
Quoted 15 lines · H. Peter Anvin
Quoted 9 lines · Eric W. Biederman

When working on dosemu and emulating EGA 16 color graphics we had to unmap the frame buffer so we would cause move instructions to fault. Trapping for each mov instruction in the loops that wrote to the frame buffer was unusably slow. Ultimately that was fixed by trapping on the first instruction and then running in the emulator until we had gone N instructions without hitting an instruction we would trap for. The result was usable software emulated EGA graphics.

Quoted 4 lines

I expect the same logic will apply any time there is a trapped and emulated instruction in an inner loop. Emulating the entire loop will be more efficient than trapping for each loop iteration.

Quoted 8 lines

Yes, this is pretty typical. In terms of EGA/VGA it depends heavily on how the application is coded, since it is possible to put EGA/VGA into modes where the frame buffer depends mostly like memory except at specific I/O points, and other modes where the frame buffer behaves nothing like memory at all and every reference needs to be handled specially. In real use, the former tends to dominate simply because it's the sane way to code, but the only way to make the latter perform sanely at all is to interpret everything.

For old applications that we were concerned about in dosemu the masked modes where you write to multiple frame buffer pages at once with a single write dominated because on real hardware it is faster.

As I recall if the things were setup so we did not need to trap dosemu mapped the appropriate frame buffer page directly, so we did not need to handle that case.

Regardless the point is that if we start emulating rare instructions with traps I expect we will reach the point where we have inner loops that we want to emulate entirely instead of taking a multitude of traps.

Eric

#53 lore raw
In reply to H. Peter Anvin
Quoted 8 lines · On Tue, 10 Nov 2009 22:15:58 -0800 "H. Peter Anvin" <[email protected]> wrote:
Quoted 6 lines · Willy Tarreau

- last, the probability of having an NX page just after an executable one seems too tight to me to even constitute an attack vector ! BTW, I'm not even certain that all CPUs correctly implement this check !

Quoted 4 lines

Do you have *any* *evidence* *whatsoever* for that assertion?!

I personally will consider something that doesn't implement proper security check to be a potential security hole and will NAK the patch.

Assuming you are doing the fault handling only for a CPU where you expect to need it (which would be wise I think) then it's a question of whether the CPU supports NX in the first place.

Even if it does the only thing you can reasonably hope to do is move the program counter one instruction into the next page. The user access checks will trap any attempt to cross 0xC0000000 and the protection fault might just occur one or part of an instruction on in the other cases.

Alan

#54 lore raw
In reply to Willy Tarreau

Hi!

Quoted 21 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

*THIS* is the kind of complexity that makes me think that having a single source for all interpretation done in the kernel is the preferred option.

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Definitely agreed ... The NX code is quite a maze right now, so changes to it should come generously laced with cleanups.

BTW, I don't see why we should be impacted by NX. Trying to execute from an NX page would return a SEGV, not SIGILL, so we should not be bothered, am I wrong ?

Yes. Consider a page-crossing instruction.

OK, but to be pragmatic, NX is there to prevent execution of instructions in the stack (or heap) during buffer overflows. If we only implement the few instructions lised in previous mail, there is very little benefit to check for NX :

- those instructions cannot jump to other code, they just change one register or memory location at most (or just nop)

Quoted 8 lines

- once we return from the signal handler, if we have crossed a NX page boundary, the program will segfault anyway, taking with it the change we just completed.

- last, the probability of having an NX page just after an executable one seems too tight to me to even constitute an attack vector ! BTW, I'm not even certain that all CPUs correctly implement this check !

Yes, you can probably "get away" with it. But I would not want to debug problems on systems with half-instruction-emulation. Please do it right, or not at all.

Quoted 7 lines

So in short, I think we could reasonably implement CMOV/NOPL with the instruction length control, with getuser for data accesses but without checking the code pages permissions if we know that the CPU could already fetch the beginning of the instruction correctly to cause an invalid opcode trap.

I'm not saying this is perfect, just that this is reasonable.

Reasonable hack to get distro booting yes. Reasonable for mainline? No.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#55 lore raw
In reply to H. Peter Anvin
Quoted 4 lines · H. Peter Anvin

I immediately note that you have absolutely no check on the code segment, either in terms of code segment limits or even that we're in the right mode. Furthermore, you read user space -- code in user space is still user space -- without get_user().

Yes I remember about that one now. HCH told me about it.

Quoted 5 lines

We also need NX protection
to be honoured, and the various special subtleties of the x86 instruction format (15-byte limit, for example) to be preserved: they aren't just there randomly, but are there to protect against specific failures.

OK.

Quoted 3 lines

*THIS* is the kind of complexity that makes me think that having a single source for all interpretation done in the kernel is the preferred option.

I understand, your point. We just need to check when it becomes overkill to use a full-blown emulator of 3 instructions and a few "simple" rules.

Willy

#56 lore raw
In reply to Willy Tarreau
Quoted 11 lines

So in my opinion, we should have :
- CMOV (for 486, Pentium, C3, K6, ...)
- NOPL (newcomer)

And if we want to extend down to i386 :
- BSWAP (=htonl)
- CMPXCHG (mutex)
- XADD (never encoutered but cheap)

I still have the 2.4 patch for BSWAP, CMPXCHG, CMOV and XADD lying

If we go that far it needs a lot more thought and probably to use the KVM code simply because of all the complexities around prefixes and the like

(Not of course that the real CPUs are consistent either)

#57 lore raw
Quoted 10 lines · Alan Cox
Quoted 10 lines

So in my opinion, we should have :
- CMOV (for 486, Pentium, C3, K6, ...)
- NOPL (newcomer)

And if we want to extend down to i386 :
- BSWAP (=htonl)
- CMPXCHG (mutex)
- XADD (never encoutered but cheap)

Quoted 4 lines
Quoted 1 line

I still have the 2.4 patch for BSWAP, CMPXCHG, CMOV and XADD lying

If we go that far it needs a lot more thought and probably to use the KVM code simply because of all the complexities around prefixes and the like

well, ironically the KVM decoder can decode an infinite string of prefixes while the very simple and limited one in the patch I showed did correct checks for invalid cases (multiple segments, repeated locks, etc...). It would only accept one data size prefix, one address size prefix, one lock and one segment prefix.

I have nothing against the KVM one, it's just that it's a full-featured emulator while we were speaking about a 686 emulators for lower-end processors. 98% of the instructions supported by KVM will never be used for that purpose. This is where I see a waste. We're comparing 7000 lines of code supporting 64-bit, real mode, NX, etc... to 400. I fail to see how we can guarantee that we do it right in that larger code (and the example above proves it wrong).

And as you said, NX is not an issue on the CPUs we're targetting.

Regards,
Willy

#58 lore raw
Quoted 16 lines · Willy Tarreau

well, ironically the KVM decoder can decode an infinite string of prefixes while the very simple and limited one in the patch I showed did correct checks for invalid cases (multiple segments, repeated locks, etc...). It would only accept one data size prefix, one address size prefix, one lock and one segment prefix.

I have nothing against the KVM one, it's just that it's a full-featured emulator while we were speaking about a 686 emulators for lower-end processors. 98% of the instructions supported by KVM will never be used for that purpose. This is where I see a waste. We're comparing 7000 lines of code supporting 64-bit, real mode, NX, etc... to 400. I fail to see how we can guarantee that we do it right in that larger code (and the example above proves it wrong).

Quoted 3 lines

And as you said, NX is not an issue on the CPUs we're targetting.

RIGHT NOW. Except that, guess what, once we have emulation in the kernel, people are going to demand new instructions to cover *new* gaps in the instruction set. And yes, this is going to mean 64 bits and what not.

The main reason to unify with KVM is not because KVM is doing everything right (I am perfectly aware that it doesn't), but because I don't really want to see a plethora of half-arsed emulators spread across the kernel, each with its own bugs. If unified, at least there is one codebase which can get fixed.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#59 lore raw
In reply to H. Peter Anvin
Quoted 7 lines · H. Peter Anvin

Willy, perhaps you can come up with a list of features you think should be emulated, together with an explanation of why you opted for that list of features and *did not* opt for others.

Note: emulated FPU is a special subcase. The FPU operations are heavyweight enough that the overhead of trapping versus library calls is relatively insignificant.

That doesn't seem to be the experience of the arm EABI versus the old arm ABI with kernel FPU emulation. Using user space library calls for FPU is vastly faster than the trapping and kernel FPU emulation.

Signature · 1 line
Len Sorensen
#60 lore raw
Quoted 5 lines · Lennart Sorensen
Quoted 4 lines · H. Peter Anvin

Willy, perhaps you can come up with a list of features you think should be emulated, together with an explanation of why you opted for that list of features and *did not* opt for others.

Quoted 7 lines
Quoted 3 lines

Note: emulated FPU is a special subcase. The FPU operations are heavyweight enough that the overhead of trapping versus library calls is relatively insignificant.

That doesn't seem to be the experience of the arm EABI versus the old arm ABI with kernel FPU emulation. Using user space library calls for FPU is vastly faster than the trapping and kernel FPU emulation.

I don't believe we were talking about ARM.

-hpa

#61 lore raw
Quoted 1 line · H. Peter Anvin

I don't believe we were talking about ARM.

True. I do get the impression the ARM has higher trap overhead than x86.

Signature · 1 line
Len Sorensen
#62 lore raw
Quoted 4 lines · Lennart Sorensen
Quoted 1 line · H. Peter Anvin

I don't believe we were talking about ARM.

True. I do get the impression the ARM has higher trap overhead than x86.

Also, the x87 FPU is a very clunky beast that's slow to emulate (unlike SSE).

-hpa

#63 lore raw
Quoted 2 lines · H. Peter Anvin

Also, the x87 FPU is a very clunky beast that's slow to emulate (unlike SSE).

Yeah x87 is rather horrible.

Signature · 1 line
Len Sorensen
#64 lore raw
In reply to Willy Tarreau
Quoted 7 lines

(...)

Quoted 4 lines
Quoted 2 lines

CMOV/NOPL are rarely used, thus have no reason to cause a massive performance drop, but are frequent enough (at least cmov) for almost

*One* CMOV in the inner loop will make your performance go down 20x.

Quoted 7 lines

yes, just like with emulated FPU or trapped unaligned accesses. It's just like flying fishes. They exist but they aren't the most common ones. If people encounter these cases on a specific program, then they just have to recompile it if it is a problem. At least they don't rebuild the whole distro. And once again, I've been using cmpxchg/bswap emulation for years on my i386 without feeling any need for a rebuild, and CMOV emulation for years now on my mini-itx

And did you set cpu family to 6 for your 386?

That's the part I was objecting most. Yes, you can emulate, but emulation is very bad for performance... so don't lie about cpu family.

(Imagine application that has NOPL in inner loop, for performance reasons. You want to use version _without_ the NOPL on processors that lack it.)

So... I don't like instruction emulation, but can live with it. But don't lie about supported instructions in /proc as original patch did.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#65 lore raw
Quoted 15 lines · Pavel Machek
Quoted 7 lines

(...)

Quoted 4 lines
Quoted 2 lines

CMOV/NOPL are rarely used, thus have no reason to cause a massive performance drop, but are frequent enough (at least cmov) for almost

*One* CMOV in the inner loop will make your performance go down 20x.

Quoted 7 lines

yes, just like with emulated FPU or trapped unaligned accesses. It's just like flying fishes. They exist but they aren't the most common ones. If people encounter these cases on a specific program, then they just have to recompile it if it is a problem. At least they don't rebuild the whole distro. And once again, I've been using cmpxchg/bswap emulation for years on my i386 without feeling any need for a rebuild, and CMOV emulation for years now on my mini-itx

Quoted 1 line

And did you set cpu family to 6 for your 386?

No, not at all !

Quoted 3 lines

That's the part I was objecting most. Yes, you can emulate, but emulation is very bad for performance... so don't lie about cpu family.

That's the point I agree with you, I don't like this setting either. I don't want to incite applications to use features that are emulated. However I think that allowing applications run when they don't/can't perform the check is useful.

Quoted 3 lines

(Imagine application that has NOPL in inner loop, for performance reasons. You want to use version _without_ the NOPL on processors that lack it.)

Exactly. Same for MMX, 3DNOW, SSE* and such.

Quoted 2 lines

So... I don't like instruction emulation, but can live with it. But don't lie about supported instructions in /proc as original patch did.

100% agreed !

Regards,
Willy

#67 lore raw
Quoted 4 lines · Matt Thrailkill
Quoted 1 line · Pavel Machek

*One* CMOV in the inner loop will make your performance go down 20x.

This is 20x slower than not running at all, right?

And that's the fundamental win of doing a fullscale emulator: you will always be able to run, at *some* performance level.

-hpa

#68 lore raw
In reply to Pavel Machek
Quoted 8 lines · Pavel Machek

Hi!

Quoted 4 lines

Indeed, but there is a difference between [cmpxchg, bswap, cmov, nopl] on one side and [sse*] on the other : distros are built assuming the former are always available while they are not always. And the distro

Well, fix the distros...

$ objdump -d libflashplayer.so |grep cmov -c
10

and ask the companies to fix their binaries too?

Quoted 6 lines
Quoted 6 lines

which make the difference have to provide an dedicated build for earlier systems just for compatibility. SSE*, 3dnow* etc... are only used by a handful of media players/converters/encoders which are able to detect themselves what to use and already have the necessary fallbacks because these instruction sets vary too much between processors and vendors.

Quoted 8 lines
Quoted 6 lines

One could argue that cmpxchg/bswap/xadd are supported by 486 and that implementing them for 386 is almost useless now (though it costs almost nothing to provide them, I did a few years ago).

CMOV/NOPL are rarely used, thus have no reason to cause a massive performance drop, but are frequent enough (at least cmov) for almost

*One* CMOV in the inner loop will make your performance go down 20x.

Still better than a browser crashing for a SIGILL

#69 lore raw
Quoted 8 lines · Matteo Croce
Quoted 7 lines · Pavel Machek

Hi!

Quoted 4 lines

Indeed, but there is a difference between [cmpxchg, bswap, cmov, nopl] on one side and [sse*] on the other : distros are built assuming the former are always available while they are not always. And the distro

Quoted 4 lines
Quoted 1 line

Well, fix the distros...

$ objdump -d libflashplayer.so |grep cmov -c
10

Good point !
Same here, only 2 of them won't work on C3 (the first ones) :

  7e3a7c:       0f 4d 45 c8             cmovge -0x38(%ebp),%eax
  7e3b4d:       0f 4d 45 c8             cmovge -0x38(%ebp),%eax
  7e97b3:       0f 4c c2                cmovl  %edx,%eax
  7e9823:       0f 4c c2                cmovl  %edx,%eax
  7eb884:       0f 4c c2                cmovl  %edx,%eax
  7eb91d:       0f 4c c2                cmovl  %edx,%eax
  8095d7:       0f 42 ca                cmovb  %edx,%ecx
  80997a:       0f 42 ca                cmovb  %edx,%ecx
  809a4a:       0f 42 ca                cmovb  %edx,%ecx
  80a5cb:       0f 42 ca                cmovb  %edx,%ecx

clearly worth emulating in my opinion.

Willy

#70 lore raw
In reply to Pavel Machek

Hi!

On Tue, 2009-11-10 at 21:54 +0100, Pavel Machek wrote:
[...]

Quoted 4 lines
Quoted 2 lines

CMOV/NOPL are rarely used, thus have no reason to cause a massive performance drop, but are frequent enough (at least cmov) for almost

*One* CMOV in the inner loop will make your performance go down 20x.

But it runs.
The pragmatic side is:
If people notices the performance drop, it would be good to have something in syslog and/or dmesg and/or /proc and/or sysfs If people do not notice the performance drop, who cares?

Bernd

Signature · 3 lines
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services
#71 lore raw
In reply to H. Peter Anvin
Quoted 10 lines · H. Peter Anvin
Quoted 8 lines · Alan Cox
Quoted 3 lines

In the short term, yes, of course. However, if we're going to do emulation, we might as well do it right.

Why is using KVM doing it right ? It sounds like its doing it slowly, and hideously memory inefficiently. You are solving an uninteresting general case problem when you just need two tiny fixups (or perhaps 3 if you want to fix up early x86-64 prefetch)

Quoted 7 lines

Why do we only need "two tiny fixups"? Where do we draw the line in terms of ISA compatibility? One could easily argue that the Right Thing[TM] is to be able to process any optional instruction -- otherwise one has a very difficult place to draw a line.

Consider SSE3, for example. Why should the same concept not apply to SSE3 instructions as to CMOV?

FWIW, the issue of the binary-only flashplayer.so came up later in the thread, but to add my few cents:

When flash 10 was released the binary only 64-bit version generated instructions from the LAHF set unconditionally, in part because Windows chose to emulate those on the very few x86-64 platforms that didn't do them in hardware.

At that time it would have been very nice from a "user support" point of view to be able to add LAHF emulation to support the software. Yes, it is ugly, binary-only code, but it is reasonably popular...

Daniel

...in the end, in fact, popular enough to have at least a couple of people I know purchase a new CPU that did implement it, just for flash on Linux.

Signature · 2 lines
✣ Daniel Pittman            ✉ [email protected]            ☎ +61 401 155 707
               ♽ made with 100 percent post-consumer electrons
#72 lore raw
Quoted 12 lines · Daniel Pittman
Quoted 3 lines

Consider SSE3, for example. Why should the same concept not apply to SSE3 instructions as to CMOV?

FWIW, the issue of the binary-only flashplayer.so came up later in the thread, but to add my few cents:

When flash 10 was released the binary only 64-bit version generated instructions from the LAHF set unconditionally, in part because Windows chose to emulate those on the very few x86-64 platforms that didn't do them in hardware.

Quoted 6 lines

At that time it would have been very nice from a "user support" point of view to be able to add LAHF emulation to support the software. Yes, it is ugly, binary-only code, but it is reasonably popular...

...in the end, in fact, popular enough to have at least a couple of people I know purchase a new CPU that did implement it, just for flash on Linux.

The main use case for emulation is indeed to support binary-only or otherwise precompiled software that exposes holes in the instruction set. As such, emulation can also be used to "raise the baseline", which can be a highly desirable thing to do.

My point in all of this is that this is not a static problem, and that if we're going to do emulation we need to consider the requirements going forward. I would *prefer* to have only one interpreter to deal with when it's broken, and I certainly trust Avi & co to do the right thing, but I'm certainly willing to entertain technical reasons why it is not the right thing to do -- *not just now but in the future*. The latter is an absolutely critical constraint, though.

Once we have a general enough interpreter framework, we can add new instructions as needed; it should make it a lot easier to phase in new instructions while not breaking old legacy machines.

-hpa

#73 lore raw
In reply to Avi Kivity
Quoted 8 lines · Avi Kivity

In theory yes. There would need to be a bit of work to disassociate it from kvm, but nothing too difficult.

Note that the kvm x86 emulator is more general than need be (emulates real mode code and cpl 0 instructions) and less general than needed (many instructions are not emulated, for example nopl).

Yes, but I suspect that adding new instructions probably is straightforward. I would still prefer to have a single interpreter in the kernel as opposed to two different ones which are going to have different bugs.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#74 lore raw
In reply to Sven-Haegar Koch
Quoted 33 lines · Sven-Haegar Koch
Quoted 31 lines · Pavel Machek
Quoted 30 lines · Matteo Croce
Quoted 29 lines · Pavel Machek
Quoted 22 lines · Matteo Croce
Quoted 7 lines · H. Peter Anvin
Quoted 1 line · Matteo Croce

indeed it has MMX, MMXEXT and CMOV, just lacks the long NOP instruction (NOPL).

MMX and MMXEXT are hardly hallmarks of i686, which leaves only cmov. I'm somewhat wondering about the general value of this patch; is i686 code really that much faster on Geode that it's worth it?

Quoted 7 lines

? ? ? ?-hpa

--
H. Peter Anvin, Intel Open Source Technology Center I work for Intel. ?I don't speak on their behalf.

yes, I did some test like gzip, bzip2, lame etc and they give more or less the same results of dhrystone

root@alix:/usr/src# CFLAGS='-march=i586' ./dry.c
Microseconds for one run through Dhrystone:        1.4
Dhrystones per Second:                          740741

...

Quoted 4 lines
root@alix:/usr/src# CFLAGS='-march=i686' ./dry.c
Trying 5000000 runs through Dhrystone:
Microseconds for one run through Dhrystone:        1.2
Dhrystones per Second:                          841751
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Teach gcc that geodelx exists? No need to break kernel for that... and you probably can gain even bigger gains.

But no standard distribution will be made available in a geode special version - not enough machines in the marekt. So I think it is better to be able to use the i686 specific things they already support, like libc6-686 from debian for example.

That's exactly the patch point

#75 lore raw
Quoted 9 lines
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Teach gcc that geodelx exists? No need to break kernel for that... and you probably can gain even bigger gains.

But no standard distribution will be made available in a geode special version - not enough machines in the marekt. So I think it is better to be able to use the i686 specific things they already support, like libc6-686 from debian for example.

That's exactly the patch point

Not quite.

Your cpu is not 686; stop trying to pretend it is.

Now, maybe it is good idea to run libc6-686 on it. If you can guarantee it contains no NOPL, fix whatever code is responsible for selecting libc to use libc6-686 to use that. (Bonus points for renaming libc6-686 to something more suitable. libc6-cmov?)

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#76 lore raw
In reply to Sven-Haegar Koch
Quoted 4 lines · Sven-Haegar Koch

But no standard distribution will be made available in a geode special version - not enough machines in the marekt. So I think it is better to be able to use the i686 specific things they already support, like libc6-686 from debian for example.

If it's only libc issue (and maybe of a couple of other packages like gzip and bzip2), then I think it would be preferable for distributions to provide a version optimized for Geode, without kernel hacks. Though I guess the above is not actually the case, is it?

Signature · 1 line
Krzysztof Halasa
#77 lore raw
In reply to H. Peter Anvin
Quoted 7 lines · H. Peter Anvin
Quoted 1 line · Matteo Croce

indeed it has MMX, MMXEXT and CMOV, just lacks the long NOP instruction (NOPL).

MMX and MMXEXT are hardly hallmarks of i686, which leaves only cmov. I'm somewhat wondering about the general value of this patch; is i686 code really that much faster on Geode that it's worth it?

Quoted 7 lines

       -hpa

--
H. Peter Anvin, Intel Open Source Technology Center I work for Intel.  I don't speak on their behalf.

There is a small advantage, but considering that GCC isn't much geode aware yet there is stil room for improvement IMHO:

root@alix:/usr/src/dist# ll
totale 257M
-rwxr-xr-x 1 1000 src  93K  8 nov  2009 bzip2-i586
-rwxr-xr-x 1 1000 src  93K  8 nov  2009 bzip2-i686
-rwxr-xr-x 1 1000 src  60K  8 nov  2009 gzip-i586
-rwxr-xr-x 1 1000 src  60K  8 nov  2009 gzip-i686
-rw-r--r-- 1 1000 src 256M  8 nov  2009 linux-2.6.31.5.tar
-rwxr-xr-x 1 1000 src  90K  8 nov  2009 lzma-i586
-rwxr-xr-x 1 1000 src  94K  8 nov  2009 lzma-i686
root@alix:/usr/src/dist# time cat linux-2.6.31.5.tar >/dev/null
real    0m10.168s
user    0m0.030s
sys     0m1.390s
root@alix:/usr/src/dist# time ./gzip-i586 -9 < linux-2.6.31.5.tar >/dev/null
real    5m22.331s
user    5m10.820s
sys     0m11.170s
root@alix:/usr/src/dist# time ./gzip-i686 -9 < linux-2.6.31.5.tar >/dev/null
real    5m3.737s
user    4m51.880s
sys     0m11.510s
root@alix:/usr/src/dist# time ./bzip2-i586 -9 < linux-2.6.31.5.tar >/dev/null
real    9m16.539s
user    9m4.410s
sys     0m11.760s
root@alix:/usr/src/dist# time ./bzip2-i686 -9 < linux-2.6.31.5.tar >/dev/null
real    8m48.682s
user    8m34.950s
sys     0m13.260s
#78 lore raw
Quoted 2 lines · Matteo Croce

There is a small advantage, but considering that GCC isn't much geode aware yet there is stil room for improvement IMHO:

Perhaps gcc considers geode to mean geode GX[m12] not geode LX (which is newer and the one in question here).

The Geode GX line prefers i486 code to i586 code (which appears to be what -march=geode is for). I am using i486 at the moment when I build for this one.

The Geode LX is what is being discussed which is in fact mostly a K6 as far as I understand things. It seems to like i686 code, other than apparently those NOP instructions. I wonder if the K6 has those noop instructions and if not, perhaps gcc 4.4's -march=k6-3 would be the right choice. I have always suspected the LX was really a K6-3 based design (the cache sizes are a bit different, but clock speeds and instruction sets seem to match).

The Geode NX (which no one has mentioned yet) is an Athlon derived chip.

Quoted 34 lines
root@alix:/usr/src/dist# ll
totale 257M
(quoted diff) +0 -7
-rwxr-xr-x 1 1000 src  93K  8 nov  2009 bzip2-i586
-rwxr-xr-x 1 1000 src  93K  8 nov  2009 bzip2-i686
-rwxr-xr-x 1 1000 src  60K  8 nov  2009 gzip-i586
-rwxr-xr-x 1 1000 src  60K  8 nov  2009 gzip-i686
-rw-r--r-- 1 1000 src 256M  8 nov  2009 linux-2.6.31.5.tar
-rwxr-xr-x 1 1000 src  90K  8 nov  2009 lzma-i586
-rwxr-xr-x 1 1000 src  94K  8 nov  2009 lzma-i686
root@alix:/usr/src/dist# time cat linux-2.6.31.5.tar >/dev/null
real    0m10.168s
user    0m0.030s
sys     0m1.390s
root@alix:/usr/src/dist# time ./gzip-i586 -9 < linux-2.6.31.5.tar >/dev/null
real    5m22.331s
user    5m10.820s
sys     0m11.170s
root@alix:/usr/src/dist# time ./gzip-i686 -9 < linux-2.6.31.5.tar >/dev/null
real    5m3.737s
user    4m51.880s
sys     0m11.510s
root@alix:/usr/src/dist# time ./bzip2-i586 -9 < linux-2.6.31.5.tar >/dev/null
real    9m16.539s
user    9m4.410s
sys     0m11.760s
root@alix:/usr/src/dist# time ./bzip2-i686 -9 < linux-2.6.31.5.tar >/dev/null
real    8m48.682s
user    8m34.950s
sys     0m13.260s
Signature · 1 line
Len Sorensen
#79 lore raw
Quoted 52 lines · Lennart Sorensen
Quoted 2 lines · Matteo Croce

There is a small advantage, but considering that GCC isn't much geode aware yet there is stil room for improvement IMHO:

Perhaps gcc considers geode to mean geode GX[m12] not geode LX (which is newer and the one in question here).

The Geode GX line prefers i486 code to i586 code (which appears to be what -march=geode is for).  I am using i486 at the moment when I build for this one.

The Geode LX is what is being discussed which is in fact mostly a K6 as far as I understand things.  It seems to like i686 code, other than apparently those NOP instructions.  I wonder if the K6 has those noop instructions and if not, perhaps gcc 4.4's -march=k6-3 would be the right choice.  I have always suspected the LX was really a K6-3 based design (the cache sizes are a bit different, but clock speeds and instruction sets seem to match).

The Geode NX (which no one has mentioned yet) is an Athlon derived chip.

Quoted 31 lines
root@alix:/usr/src/dist# ll
totale 257M
(quoted diff) +0 -7
-rwxr-xr-x 1 1000 src  93K  8 nov  2009 bzip2-i586
-rwxr-xr-x 1 1000 src  93K  8 nov  2009 bzip2-i686
-rwxr-xr-x 1 1000 src  60K  8 nov  2009 gzip-i586
-rwxr-xr-x 1 1000 src  60K  8 nov  2009 gzip-i686
-rw-r--r-- 1 1000 src 256M  8 nov  2009 linux-2.6.31.5.tar
-rwxr-xr-x 1 1000 src  90K  8 nov  2009 lzma-i586
-rwxr-xr-x 1 1000 src  94K  8 nov  2009 lzma-i686
root@alix:/usr/src/dist# time cat linux-2.6.31.5.tar >/dev/null

real    0m10.168s
user    0m0.030s
sys     0m1.390s

root@alix:/usr/src/dist# time ./gzip-i586 -9 < linux-2.6.31.5.tar >/dev/null

real    5m22.331s
user    5m10.820s
sys     0m11.170s

root@alix:/usr/src/dist# time ./gzip-i686 -9 < linux-2.6.31.5.tar >/dev/null

real    5m3.737s
user    4m51.880s
sys     0m11.510s

root@alix:/usr/src/dist# time ./bzip2-i586 -9 < linux-2.6.31.5.tar >/dev/null

real    9m16.539s
user    9m4.410s
sys     0m11.760s

root@alix:/usr/src/dist# time ./bzip2-i686 -9 < linux-2.6.31.5.tar >/dev/null
Quoted 7 lines
Quoted 3 lines

real    8m48.682s
user    8m34.950s
sys     0m13.260s

--
Len Sorensen

You're right, indeed this is being discussed here:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41989

#80 lore raw
In reply to Lennart Sorensen
Quoted 11 lines · Lennart Sorensen

The Geode LX is what is being discussed which is in fact mostly a K6 as far as I understand things. It seems to like i686 code, other than apparently those NOP instructions. I wonder if the K6 has those noop instructions and if not, perhaps gcc 4.4's -march=k6-3 would be the right choice. I have always suspected the LX was really a K6-3 based design (the cache sizes are a bit different, but clock speeds and instruction sets seem to match).

The Geode NX (which no one has mentioned yet) is an Athlon derived chip.

*As far as I know* K6 didn't have NOPL, whereas K7 does.

Someone who has access to these chips could run that as an experiment.

-hpa

#81 lore raw
Quoted 10 lines · H. Peter Anvin
Quoted 9 lines · Lennart Sorensen

The Geode LX is what is being discussed which is in fact mostly a K6 as far as I understand things. It seems to like i686 code, other than apparently those NOP instructions. I wonder if the K6 has those noop instructions and if not, perhaps gcc 4.4's -march=k6-3 would be the right choice. I have always suspected the LX was really a K6-3 based design (the cache sizes are a bit different, but clock speeds and instruction sets seem to match).

Quoted 4 lines
Quoted 2 lines

The Geode NX (which no one has mentioned yet) is an Athlon derived chip.

*As far as I know* K6 didn't have NOPL, whereas K7 does.

Which would be mroe indication that the Geode LX may in fact be a K6 based CPU design. The Geode NX is very clearly an Athlon (K7) and AMD has never even tried to hide that. They have never said what the LX is based on, other than it isn't based on the GX (fortunately, that thing was a buggy piece of crap).

Quoted 1 line

Someone who has access to these chips could run that as an experiment.

I have lots of Geode SC1200 (GX2 SoC) and Geode LX systems around. I think I might even have a K6-2 at home in the garage come to think of it.

Signature · 1 line
Len Sorensen
#82 lore raw

Hi!

Quoted 9 lines
Quoted 3 lines
Quoted 1 line

The Geode NX (which no one has mentioned yet) is an Athlon derived chip.

*As far as I know* K6 didn't have NOPL, whereas K7 does.

Which would be mroe indication that the Geode LX may in fact be a K6 based CPU design. The Geode NX is very clearly an Athlon (K7) and AMD has never even tried to hide that. They have never said what the LX is based on, other than it isn't based on the GX (fortunately, that thing was a buggy piece of crap).

Interesting...geode gx being buggy? I know pentium was famous for the fdiv bug, but never heard of geode gx problems...

Are they something kernel can work around, or do those chips just have to be avoided? Anything malicious user can use to crash the system? Anything malicious user can use to gain extra priviledge?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#83 lore raw
Quoted 7 lines · On Thu, 12 Nov 2009 13:18:05 +0100 Pavel Machek <[email protected]> wrote:

Hi!

Quoted 5 lines
Quoted 4 lines
Quoted 2 lines

The Geode NX (which no one has mentioned yet) is an Athlon derived chip.

*As far as I know* K6 didn't have NOPL, whereas K7 does.

Quoted 8 lines
Quoted 5 lines

Which would be mroe indication that the Geode LX may in fact be a K6 based CPU design. The Geode NX is very clearly an Athlon (K7) and AMD has never even tried to hide that. They have never said what the LX is based on, other than it isn't based on the GX (fortunately, that thing was a buggy piece of crap).

Interesting...geode gx being buggy? I know pentium was famous for the fdiv bug, but never heard of geode gx problems...

http://www.amd.com/files/connectivitysolutions/geode/geode_gx/31533E_gx_2.1_specupdate.pdf

1.4 is my favorite. The branch prediction logic can send the instruction pointer off to la-la land.

While at olpc, we had a sad discussion about what the *real* impact of the workaround was...

#84 lore raw
In reply to Pavel Machek
Quoted 2 lines

Interesting...geode gx being buggy? I know pentium was famous for the fdiv bug, but never heard of geode gx problems...

Depends which one - the older ones were very solid. The very first (5510) had some interesting bugs but they were fairly soon stomped.

Alan

#85 lore raw
In reply to Pavel Machek
Quoted 6 lines · Pavel Machek

Interesting...geode gx being buggy? I know pentium was famous for the fdiv bug, but never heard of geode gx problems...

Are they something kernel can work around, or do those chips just have to be avoided? Anything malicious user can use to crash the system? Anything malicious user can use to gain extra priviledge?

Well the one problem I have encountered is in the jsm driver (exar pci uart driver).

On a typical PC with a P3, P4, Core 2, athlong, etc, it works perfectly. It works perfectly on a Geode LX as well. On a Geode SC1200 (which is a GX with companion chip in one) it transmits out of order in a consistent way.

If you transmit a chunk of data that looks like this:

0123456789abcdef

The data that comes out of the UART is:

123056749ab8defc

The fix to avoid the problem is:

- memcpy_toio(&ch->ch_neo_uart->txrxburst, ch->ch_wqueue + tail, s);
+ for(i=0;i<s;i++) {
+ memcpy_toio(&(ch->ch_neo_uart->txrxburst[i]), ch->ch_wqueue + tail + i, 1);
+ }

Calling memcpy_toio on the Geode SC1200 on anything larger than 1 byte causes the data to be delivered (at least on the PCI bus) reordered in that very consistent manner.

The alignment doesn't affect it (I tested that). Simply doing more than 1 byte at a time with memcpy_toio to the pci device messes up.

So as a result we run with this patch applied even though it certainly is less efficient, but at least it works.

Every other CPU works fine that I have ever tried the driver on.

Signature · 1 line
Len Sorensen
#86 lore raw

O> Calling memcpy_toio on the Geode SC1200 on anything larger than 1 byte

Quoted 2 lines

causes the data to be delivered (at least on the PCI bus) reordered in that very consistent manner.

Sounds like you or your firmware have the caching and write combining misconfigured.

Quoted 3 lines

The alignment doesn't affect it (I tested that). Simply doing more than 1 byte at a time with memcpy_toio to the pci device messes up.

Which usually means some form of write gathering is enabled or something thinks the device is write combining on the PCI bus. What does the PCI bus and the RCRR MTRR set look like ?

#87 lore raw
Quoted 6 lines · Alan Cox

O> Calling memcpy_toio on the Geode SC1200 on anything larger than 1 byte

Quoted 2 lines

causes the data to be delivered (at least on the PCI bus) reordered in that very consistent manner.

Sounds like you or your firmware have the caching and write combining misconfigured.

Well I can't wouch for the firmware, and unfortunately without knowing what address the firmware placed the configuration registers at there is no way for me to check the settings.

Quoted 6 lines
Quoted 2 lines

The alignment doesn't affect it (I tested that). Simply doing more than 1 byte at a time with memcpy_toio to the pci device messes up.

Which usually means some form of write gathering is enabled or something thinks the device is write combining on the PCI bus. What does the PCI bus and the RCRR MTRR set look like ?

Well there is no /proc/mtrr.

Here is lspci -vvx output. It is device 01:08.

00:00.0 Host bridge: Cyrix Corporation PCI Master
Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
Status: Cap- 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort+ >SERR- <PERR-
Latency: 0
00: 78 10 01 00 07 00 80 22 00 00 00 06 00 00 00 00
10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

00:0e.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+ (rev 10)
Subsystem: Realtek Semiconductor Co., Ltd. RT8139
Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
Status: Cap+ 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
Interrupt: pin A routed to IRQ 10
Region 0: I/O ports at f800 [size=256]
Region 1: Memory at e0000000 (32-bit, non-prefetchable) [size=256]
Capabilities: [50] Power Management version 2
Flags: PMEClk- DSI- D1+ D2+ AuxCurrent=0mA PME(D0-,D1+,D2+,D3hot+,D3cold-)
Status: D0 PME-Enable- DSel=0 DScale=0 PME-
00: ec 10 39 81 03 00 90 02 10 00 00 02 00 40 00 00
10: 01 f8 00 00 00 00 00 e0 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 ec 10 39 81
30: 00 00 00 00 50 00 00 00 00 00 00 00 0a 01 20 40

00:11.0 PCI bridge: Hint Corp Unknown device 0031 (rev 01) (prog-if 00 [Normal decode])
Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
Status: Cap+ 66MHz+ UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
Latency: 64, Cache Line Size: 32 bytes
Bus: primary=00, secondary=01, subordinate=01, sec-latency=0
I/O behind bridge: 0000d000-0000dfff
Memory behind bridge: e0100000-e01fffff
Prefetchable memory behind bridge: 00000000c0000000-00000000c03fffff
Secondary status: 66MHz+ FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- <SERR- <PERR-
BridgeCtl: Parity- SERR- NoISA- VGA- MAbort- >Reset- FastB2B-
Capabilities: [80] Power Management version 2
Flags: PMEClk- DSI- D1+ D2+ AuxCurrent=0mA PME(D0+,D1+,D2+,D3hot+,D3cold-)
Status: D0 PME-Enable- DSel=0 DScale=0 PME-
Capabilities: [a0] Vital Product Data
00: 88 33 31 00 07 00 b0 02 01 00 04 06 08 40 01 00
10: 00 00 00 00 00 00 00 00 00 01 01 00 d1 d1 a0 02
20: 10 e0 10 e0 01 c0 31 c0 00 00 00 00 00 00 00 00
30: 00 00 00 00 80 00 00 00 00 00 00 00 ff 00 00 00

00:12.0 ISA bridge: National Semiconductor Corporation SCx200 Bridge
Subsystem: National Semiconductor Corporation SCx200 Bridge
Control: I/O+ Mem+ BusMaster+ SpecCycle+ MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
Status: Cap- 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
Latency: 0, Cache Line Size: 32 bytes
Region 0: I/O ports at 6400 [size=64]
Region 1: I/O ports at 6600 [size=64]
00: 0b 10 00 05 0f 00 80 02 00 00 01 06 08 00 80 00
10: 01 64 00 00 01 66 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 0b 10 00 05
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

00:12.1 Bridge: National Semiconductor Corporation SCx200 SMI
Subsystem: National Semiconductor Corporation SCx200 SMI
Control: I/O+ Mem- BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
Status: Cap- 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- Region 0: I/O ports at 6000 [size=256]
00: 0b 10 01 05 01 00 80 02 00 00 80 06 00 00 00 00
10: 01 60 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 0b 10 01 05
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

00:12.2 IDE interface: National Semiconductor Corporation SCx200 IDE (rev 01) (prog-if 80 [Master])

        Subsystem: National Semiconductor Corporation SCx200 IDE
        Control: I/O+ Mem- BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
        Status: Cap- 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
        Latency: 0
        Region 0: [virtual] Memory at 000001f0 (32-bit, non-prefetchable) [disabled] [size=8]
        Region 1: [virtual] Memory at 000003f0 (type 3, non-prefetchable) [disabled] [size=1]
        Region 2: [virtual] Memory at 00000170 (32-bit, non-prefetchable) [disabled] [size=8]
        Region 3: [virtual] Memory at 00000370 (type 3, non-prefetchable) [disabled] [size=1]
        Region 4: I/O ports at fc00 [size=16]

00: 0b 10 02 05 05 00 80 02 01 80 01 01 00 00 00 00 10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 20: 01 fc 00 00 00 00 00 00 00 00 00 00 0b 10 02 05 30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

00:12.3 Multimedia audio controller: National Semiconductor Corporation SCx200 Audio
Subsystem: National Semiconductor Corporation SCx200 Audio
Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
Status: Cap- 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
Latency: 0
Region 0: Memory at 40011000 (32-bit, non-prefetchable) [size=4K]
00: 0b 10 03 05 06 00 80 02 00 00 01 04 00 00 00 00
10: 00 10 01 40 00 00 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 0b 10 03 05
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

00:12.4 VGA compatible controller: National Semiconductor Corporation SCx200 Video (rev 01) (prog-if 00 [VGA])
Subsystem: National Semiconductor Corporation SCx200 Video
Control: I/O- Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
Status: Cap- 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
Interrupt: pin C routed to IRQ 0
Region 0: Memory at 40800000 (32-bit, non-prefetchable) [size=4K]
Region 1: Memory at 40010000 (32-bit, non-prefetchable) [size=4K]
Region 2: Memory at e0004000 (32-bit, non-prefetchable) [size=4K]
00: 0b 10 04 05 02 00 80 02 01 00 00 03 00 00 00 00
10: 00 00 80 40 00 00 01 40 00 40 00 e0 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 0b 10 04 05
30: 00 00 00 00 00 00 00 00 00 00 00 00 fe 03 00 00

00:12.5 Bridge: National Semiconductor Corporation SCx200 XBus
Subsystem: National Semiconductor Corporation SCx200 XBus
Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
Status: Cap- 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR- Region 0: I/O ports at 6200 [size=64]
00: 0b 10 05 05 03 00 80 02 00 00 80 06 00 00 00 00
10: 01 62 00 00 00 00 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 0b 10 05 05
30: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

00:13.0 USB Controller: Compaq Computer Corporation ZFMicro Chipset USB (rev 08) (prog-if 10 [OHCI])
Subsystem: Compaq Computer Corporation ZFMicro Chipset USB
Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
Status: Cap- 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
Latency: 0 (20000ns max), Cache Line Size: 32 bytes
Interrupt: pin A routed to IRQ 11
Region 0: Memory at e0005000 (32-bit, non-prefetchable) [size=4K]
00: 11 0e f8 a0 07 00 80 02 08 10 03 0c 08 00 00 00
10: 00 50 00 e0 00 00 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 11 0e f8 a0
30: 00 00 00 00 00 00 00 00 00 00 00 00 0b 01 00 50

01:04.0 Ethernet controller: Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE] (rev 36)
Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
Status: Cap+ 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
Latency: 64 (6000ns min, 6000ns max)
Interrupt: pin A routed to IRQ 11
Region 0: I/O ports at dc00 [size=32]
Region 1: Memory at e0100000 (32-bit, non-prefetchable) [size=32]
Expansion ROM at c0000000 [disabled] [size=1M]
Capabilities: [40] Power Management version 1
Flags: PMEClk- DSI- D1- D2- AuxCurrent=0mA PME(D0+,D1-,D2-,D3hot+,D3cold+)
Status: D0 PME-Enable- DSel=0 DScale=0 PME-
00: 22 10 00 20 07 00 90 02 36 00 00 02 00 40 00 00
10: 01 dc 00 00 00 00 10 e0 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
30: 00 00 00 ff 40 00 00 00 00 00 00 00 0b 01 18 18

01:05.0 Ethernet controller: Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE] (rev 36)
Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
Status: Cap+ 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
Latency: 64 (6000ns min, 6000ns max)
Interrupt: pin A routed to IRQ 10
Region 0: I/O ports at d800 [size=32]
Region 1: Memory at e0100020 (32-bit, non-prefetchable) [size=32]
Expansion ROM at c0100000 [disabled] [size=1M]
Capabilities: [40] Power Management version 1
Flags: PMEClk- DSI- D1- D2- AuxCurrent=0mA PME(D0+,D1-,D2-,D3hot+,D3cold+)
Status: D0 PME-Enable- DSel=0 DScale=0 PME-
00: 22 10 00 20 07 00 90 02 36 00 00 02 00 40 00 00
10: 01 d8 00 00 20 00 10 e0 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
30: 00 00 00 ff 40 00 00 00 00 00 00 00 0a 01 18 18

01:06.0 Ethernet controller: Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE] (rev 36)
Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
Status: Cap+ 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
Interrupt: pin A routed to IRQ 11
Region 0: I/O ports at d400 [size=32]
Region 1: Memory at e0100040 (32-bit, non-prefetchable) [size=32]
Expansion ROM at c0200000 [disabled] [size=1M]
Capabilities: [40] Power Management version 1
Flags: PMEClk- DSI- D1- D2- AuxCurrent=0mA PME(D0+,D1-,D2-,D3hot+,D3cold+)
Status: D0 PME-Enable- DSel=0 DScale=0 PME-
00: 22 10 00 20 03 00 90 02 36 00 00 02 00 40 00 00
10: 01 d4 00 00 40 00 10 e0 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
30: 00 00 00 ff 40 00 00 00 00 00 00 00 0b 01 18 18

01:07.0 Ethernet controller: Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE] (rev 36)
Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
Status: Cap+ 66MHz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
Interrupt: pin A routed to IRQ 10
Region 0: I/O ports at d000 [size=32]
Region 1: Memory at e0100060 (32-bit, non-prefetchable) [size=32]
Expansion ROM at c0300000 [disabled] [size=1M]
Capabilities: [40] Power Management version 1
Flags: PMEClk- DSI- D1- D2- AuxCurrent=0mA PME(D0+,D1-,D2-,D3hot+,D3cold+)
Status: D0 PME-Enable- DSel=0 DScale=0 PME-
00: 22 10 00 20 03 00 90 02 36 00 00 02 00 40 00 00
10: 01 d0 00 00 60 00 10 e0 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
30: 00 00 00 ff 40 00 00 00 00 00 00 00 0a 01 18 18

01:08.0 Serial controller: Unknown device 5243:0001 (rev 04) (prog-if 02 [16550])
Control: I/O- Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
Status: Cap- 66MHz- UDF- FastB2B+ ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR-
Interrupt: pin A routed to IRQ 11
Region 0: Memory at e0100800 (32-bit, non-prefetchable) [size=2K]
00: 43 52 01 00 02 00 80 00 04 02 00 07 00 00 00 00
10: 00 08 10 e0 00 00 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff
30: 00 00 00 00 00 00 00 00 00 00 00 00 0b 01 00 00

01:09.0 Network controller: Sangoma Technologies Corp. A104u Quad T1/E1 AFT
Subsystem: Unknown device a013:1400
Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
Status: Cap- 66MHz- UDF- FastB2B- ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
Latency: 64 (1250ns min, 3750ns max)
Interrupt: pin A routed to IRQ 10
Region 0: Memory at e0110000 (32-bit, non-prefetchable) [size=64K]
00: 23 19 00 04 06 00 00 02 00 00 80 02 00 40 00 00
10: 00 00 11 e0 00 00 00 00 00 00 00 00 00 00 00 00
20: 00 00 00 00 00 00 00 00 00 00 00 00 13 a0 00 14
30: 00 00 00 00 00 00 00 00 00 00 00 00 0a 01 05 0f

Anything else I can grab that might give a clue?

Signature · 1 line
Len Sorensen
#88 lore raw
Quoted 5 lines
Quoted 3 lines

Which usually means some form of write gathering is enabled or something thinks the device is write combining on the PCI bus. What does the PCI bus and the RCRR MTRR set look like ?

Well there is no /proc/mtrr.

Linux doesn't have an RCRR driver - so you need to dump the MSRs directly (see the Geode GX manual MSR list) and read out the msrs.

#89 lore raw
Quoted 8 lines · Alan Cox
Quoted 5 lines
Quoted 3 lines

Which usually means some form of write gathering is enabled or something thinks the device is write combining on the PCI bus. What does the PCI bus and the RCRR MTRR set look like ?

Well there is no /proc/mtrr.

Linux doesn't have an RCRR driver - so you need to dump the MSRs directly (see the Geode GX manual MSR list) and read out the msrs.

Hmm, so looking at the Geode SC1200 data book, it doesn't mention mtrr, rcrr or msr. I know the Geode LX has lots of MSR documentation.

Looking at the GX1 data book (which it seems the SC1200 refers to), it does mention mtrr, as not supported. I have managed to find something called the region configuration range registers, which must be RCRR.

I think this is a dump of the 8 region MSRs:

0x00001810->0xbf848ba8b7f282e8
0x00001811->0xbfcb5328b7f932e8
0x00001812->0xbfe93418b7f712e8
0x00001813->0xbfbd59b8b7fb52e8
0x00001814->0xbfb5f868b7f3d2e8
0x00001815->0xbf815018b7ef42e8
0x00001816->0xbfc4c0d8b7f2a2e8
0x00001817->0xbfe1eea8b7eff2e8

This must of course mean I read them wrong because those are not the right values. Some bit ranges must be 0 and are not.

Trying rdmsr from msr-tools 1.2 gives me:

# ./rdmsr -x 0x00001810
rdmsr: CPU 0 cannot read MSR 0x00001810

Hmm, now what?

Signature · 1 line
Len Sorensen
#90 lore raw
Quoted 6 lines

Trying rdmsr from msr-tools 1.2 gives me:

# ./rdmsr -x 0x00001810
rdmsr: CPU 0 cannot read MSR 0x00001810

Hmm, now what?

Beats me - I thought the region registers were read/write.

#91 lore raw
Quoted 8 lines · Alan Cox
Quoted 6 lines

Trying rdmsr from msr-tools 1.2 gives me:

# ./rdmsr -x 0x00001810
rdmsr: CPU 0 cannot read MSR 0x00001810

Hmm, now what?

Beats me - I thought the region registers were read/write.

Actually it seems I can't read any MSRs on it.

Using the same kernel, same msr module, same rdmsr on a Geode LX system works fine. I can read MSRs no problem. Seems the msr module isn't working on the Geode SC1200 (and hence possibly the GX1).

Signature · 1 line
Len Sorensen
#92 lore raw
Quoted 8 lines · Lennart Sorensen
Quoted 7 lines · Alan Cox
Quoted 6 lines

Trying rdmsr from msr-tools 1.2 gives me:

# ./rdmsr -x 0x00001810
rdmsr: CPU 0 cannot read MSR 0x00001810

Hmm, now what?

Quoted 8 lines
Quoted 1 line

Beats me - I thought the region registers were read/write.

Actually it seems I can't read any MSRs on it.

Using the same kernel, same msr module, same rdmsr on a Geode LX system works fine. I can read MSRs no problem. Seems the msr module isn't working on the Geode SC1200 (and hence possibly the GX1).

That would seem highly unlikely ... unless the MSR flag isn't exposed in CPUID.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#93 lore raw
Quoted 13 lines · H. Peter Anvin
Quoted 12 lines · Lennart Sorensen
Quoted 8 lines · Alan Cox
Quoted 6 lines

Trying rdmsr from msr-tools 1.2 gives me:

# ./rdmsr -x 0x00001810
rdmsr: CPU 0 cannot read MSR 0x00001810

Hmm, now what?

Beats me - I thought the region registers were read/write.

Actually it seems I can't read any MSRs on it.

Quoted 7 lines
Quoted 4 lines

Using the same kernel, same msr module, same rdmsr on a Geode LX system works fine. I can read MSRs no problem. Seems the msr module isn't working on the Geode SC1200 (and hence possibly the GX1).

That would seem highly unlikely ... unless the MSR flag isn't exposed in CPUID.

That would be odd yes.

# cat /proc/cpuinfo
processor       : 0
vendor_id       : CyrixInstead
cpu family      : 5
model           : 9
model name      : Geode(TM) Integrated Processor by National Semi
stepping        : 1
cpu MHz         : 266.612
cache size      : 16 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 2
wp              : yes
flags           : fpu tsc msr cx8 cmov mmx cxmmx
bogomips        : 534.41
clflush size    : 32
power management:

That part looks OK. So why is reading MSRs not working on this stupid CPU at any of the addresses the data book says should work.

Signature · 1 line
Len Sorensen
#94 lore raw
In reply to Alan Cox
Quoted 8 lines · Alan Cox
Quoted 6 lines

Trying rdmsr from msr-tools 1.2 gives me:

# ./rdmsr -x 0x00001810
rdmsr: CPU 0 cannot read MSR 0x00001810

Hmm, now what?

Beats me - I thought the region registers were read/write.

Umm... 'modprobe msr'?

(Recently I had what *looked* like an xorg server bug, turned out to be a missing CONFIG_INPUT_EVDEV.. Whoops. ;)

#95 lore raw
Quoted 4 lines · On Tue, Nov 17, 2009 at 11:48:47AM -0500, [email protected] wrote:

Umm... 'modprobe msr'?

(Recently I had what *looked* like an xorg server bug, turned out to be a missing CONFIG_INPUT_EVDEV.. Whoops. ;)

I did. Makes no difference. If I unload it I get the same error.

# modinfo msr
filename:       /lib/modules/2.6.26-2-gx1/kernel/arch/x86/kernel/msr.ko
author:         H. Peter Anvin <[email protected]>
description:    x86 generic MSR driver
license:        GPL
vermagic:       2.6.26-2-gx1 mod_unload GEODEGX1
depends:
# lsmod |grep msr
msr                     2692  0

I don't get it.

Signature · 1 line
Len Sorensen
#96 lore raw
Quoted 16 lines · Lennart Sorensen
Quoted 4 lines · On Tue, Nov 17, 2009 at 11:48:47AM -0500, [email protected] wrote:

Umm... 'modprobe msr'?

(Recently I had what *looked* like an xorg server bug, turned out to be a missing CONFIG_INPUT_EVDEV.. Whoops. ;)

I did. Makes no difference. If I unload it I get the same error.

# modinfo msr
filename:       /lib/modules/2.6.26-2-gx1/kernel/arch/x86/kernel/msr.ko
author:         H. Peter Anvin <[email protected]>
description:    x86 generic MSR driver
license:        GPL
vermagic:       2.6.26-2-gx1 mod_unload GEODEGX1
depends:
Quoted 5 lines
# lsmod |grep msr
msr                     2692  0

I don't get it.

Does /dev/cpu/*/msr exist?

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#97 lore raw
Quoted 17 lines · H. Peter Anvin
Quoted 16 lines · Lennart Sorensen
Quoted 4 lines · On Tue, Nov 17, 2009 at 11:48:47AM -0500, [email protected] wrote:

Umm... 'modprobe msr'?

(Recently I had what *looked* like an xorg server bug, turned out to be a missing CONFIG_INPUT_EVDEV.. Whoops. ;)

I did. Makes no difference. If I unload it I get the same error.

# modinfo msr
filename:       /lib/modules/2.6.26-2-gx1/kernel/arch/x86/kernel/msr.ko
author:         H. Peter Anvin <[email protected]>
description:    x86 generic MSR driver
license:        GPL
vermagic:       2.6.26-2-gx1 mod_unload GEODEGX1
depends:
Quoted 7 lines
Quoted 5 lines
# lsmod |grep msr
msr                     2692  0

I don't get it.

Does /dev/cpu/*/msr exist?

I ran MAKEDEV cpu in /dev, but to make sure...

# ls -l /dev/cpu/*/msr
crw------- 1 root root 202, 0 Nov 16 12:28 /dev/cpu/0/msr
crw------- 1 root root 202, 1 Nov 16 12:28 /dev/cpu/1/msr
crw------- 1 root root 202, 2 Nov 16 12:28 /dev/cpu/2/msr
crw------- 1 root root 202, 3 Nov 16 12:28 /dev/cpu/3/msr

Looks OK too.

# strace ./rdmsr -x 0x00001810
execve("./rdmsr", ["./rdmsr", "-x", "0x00001810"], [/* 13 vars */]) = 0
uname({sys="Linux", node="ruggedrouter", ...}) = 0
brk(0)                                  = 0x8106000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f23000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f22000
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=14975, ...}) = 0
mmap2(NULL, 14975, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7f1e000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/tls/libc.so.6", O_RDONLY)    = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\240O\1"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0644, st_size=1245488, ...}) = 0
mmap2(NULL, 1251484, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7dec000
mmap2(0xb7f14000, 28672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x128) = 0xb7f14000
mmap2(0xb7f1b000, 10396, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb7f1b000
close(3)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7deb000
mprotect(0xb7f14000, 20480, PROT_READ)  = 0
set_thread_area({entry_number:-1 -> 6, base_addr:0xb7deb6c0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
munmap(0xb7f1e000, 14975)               = 0
open("/dev/cpu/0/msr", O_RDONLY|O_LARGEFILE) = 3
pread64(3, 0xbf83ac00, 8, 6160)         = -1 EIO (Input/output error)
write(2, "rdmsr: CPU 0 cannot read MSR 0x0"..., 40rdmsr: CPU 0 cannot read MSR 0x00001810
) = 40
exit_group(4)                           = ?
Process 15044 detached
Signature · 1 line
Len Sorensen
#98 lore raw
Quoted 22 lines · Lennart Sorensen
# strace ./rdmsr -x 0x00001810
execve("./rdmsr", ["./rdmsr", "-x", "0x00001810"], [/* 13 vars */]) = 0
uname({sys="Linux", node="ruggedrouter", ...}) = 0
brk(0)                                  = 0x8106000
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f23000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7f22000
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat64(3, {st_mode=S_IFREG|0644, st_size=14975, ...}) = 0
mmap2(NULL, 14975, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7f1e000
close(3)                                = 0
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
open("/lib/tls/libc.so.6", O_RDONLY)    = 3
read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\240O\1"..., 512) = 512
fstat64(3, {st_mode=S_IFREG|0644, st_size=1245488, ...}) = 0
mmap2(NULL, 1251484, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0xb7dec000
mmap2(0xb7f14000, 28672, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x128) = 0xb7f14000
mmap2(0xb7f1b000, 10396, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb7f1b000
close(3)                                = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7deb000
mprotect(0xb7f14000, 20480, PROT_READ)  = 0
Quoted 8 lines
set_thread_area({entry_number:-1 -> 6, base_addr:0xb7deb6c0, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}) = 0
munmap(0xb7f1e000, 14975)               = 0
open("/dev/cpu/0/msr", O_RDONLY|O_LARGEFILE) = 3
pread64(3, 0xbf83ac00, 8, 6160)         = -1 EIO (Input/output error)
write(2, "rdmsr: CPU 0 cannot read MSR 0x0"..., 40rdmsr: CPU 0 cannot read MSR 0x00001810
) = 40
exit_group(4)                           = ?
Process 15044 detached

OK, I added a bit of debuging print statements to msr.c and I find that calling rdmsr 0x1810 returns error 0xfffffff2 (-14 that is).

It seems to end up calling:

static inline unsigned long long native_read_msr_safe(unsigned int msr,
int *err)

{
        DECLARE_ARGS(val, low, high);

        asm volatile("2: rdmsr ; xor %0,%0\n"
                     "1:\n\t"
                     ".section .fixup,\"ax\"\n\t"
                     "3:  mov %3,%0 ; jmp 1b\n\t"
                     ".previous\n\t"
                     _ASM_EXTABLE(2b, 3b)
                     : "=r" (*err), EAX_EDX_RET(val, low, high)
                     : "c" (msr), "i" (-EFAULT));
        return EAX_EDX_VAL(val, low, high);
}

That unfortunately is too low level for me to make sense of.

Signature · 1 line
Len Sorensen
#99 lore raw
Quoted 4 lines · Lennart Sorensen

OK, I added a bit of debuging print statements to msr.c and I find that calling rdmsr 0x1810 returns error 0xfffffff2 (-14 that is).

What this means is the RDMSR instruction traps -- the CPU doesn't recognize this as a valid MSR.

-hpa

#100 lore raw
Quoted 8 lines · H. Peter Anvin
Quoted 4 lines · Lennart Sorensen

OK, I added a bit of debuging print statements to msr.c and I find that calling rdmsr 0x1810 returns error 0xfffffff2 (-14 that is).

What this means is the RDMSR instruction traps -- the CPU doesn't recognize this as a valid MSR.

Strange how it says that for every value I have tried so far. Makes me wonder if there is a register somewhere that disables MSR support. I did find a lockout value but I can't read that one either (which says it is always readable).

Signature · 1 line
Len Sorensen
#101 lore raw
Quoted 4 lines · Lennart Sorensen

Strange how it says that for every value I have tried so far. Makes me wonder if there is a register somewhere that disables MSR support. I did find a lockout value but I can't read that one either (which says it is always readable).

I tried doing rdmsr on 0x1810 from grub, and it faults too. cpuid says MSRs are supported, I just can't find any that work.

Signature · 1 line
Len Sorensen
#102 lore raw
In reply to Lennart Sorensen
Quoted 7 lines

Which would be mroe indication that the Geode LX may in fact be a K6 based CPU design. The Geode NX is very clearly an Athlon (K7) and AMD has never even tried to hide that. They have never said what the LX is based on, other than it isn't based on the GX (fortunately, that thing was a buggy piece of crap).

Well, do you know the history of the Geode line? It originated in the Cyrix MediaGX, then that was sold to NSC and renamed to Geode, then that was sold to AMD later.

Yuhong Bao

_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.
http://clk.atdmt.com/GBL/go/171222986/direct/01/

#103 lore raw
Quoted 1 line · Yuhong Bao

Well, do you know the history of the Geode line? It originated in the Cyrix MediaGX, then that was sold to NSC and renamed to Geode, then that was sold to AMD later.

That is the history of the Geode GX line yes. The Geode LX is an AMD design, and the Geode NX is an athlon with a lower voltage. Hence the LX probably isn't anything like the original GX. It certainly has none of the bugs or performance issues of the GX.

Signature · 1 line
Len Sorensen
#104 lore raw
In reply to Lennart Sorensen
Quoted 5 lines · Lennart Sorensen

Which would be mroe indication that the Geode LX may in fact be a K6 based CPU design. The Geode NX is very clearly an Athlon (K7) and AMD has never even tried to hide that. They have never said what the LX is based on, other than it isn't based on the GX (fortunately, that thing was a buggy piece of crap).

When looking this up for http://www.pixelbeat.org/scripts/gcccpuopt
I determined that gcc --march=geode is for the LX which is
K6 + 3dnowext. Note gcc has no way currently of explicitly selecting 3dnowext.

cheers,
Pádraig.

#105 lore raw
Quoted 10 lines · Pádraig Brady
Quoted 5 lines · Lennart Sorensen

Which would be mroe indication that the Geode LX may in fact be a K6 based CPU design. The Geode NX is very clearly an Athlon (K7) and AMD has never even tried to hide that. They have never said what the LX is based on, other than it isn't based on the GX (fortunately, that thing was a buggy piece of crap).

When looking this up for http://www.pixelbeat.org/scripts/gcccpuopt
I determined that gcc --march=geode is for the LX which is
K6 + 3dnowext. Note gcc has no way currently of explicitly selecting 3dnowext.

If that is the case then geode is an awful name choice given the GX, LX and NX all have vastly different features and requirements, yet are all geodes.

Signature · 1 line
Len Sorensen
#106 lore raw
In reply to Matteo Croce

Hi!

Quoted 1 line

The AMD Geode LX has an x86 id of 5 (i586) tought it's technically an i686:

It is not.

Quoted 6 lines
root@alix:~# egrep '^(cpu family|model name|flags)' /proc/cpuinfo
cpu family      : 5
model name      : Geode(TM) Integrated Processor by AMD PCS
flags           : fpu de pse tsc msr cx8 sep pge cmov clflush mmx
mmxext 3dnowext 3dnow
Quoted 6 lines

indeed it has MMX, MMXEXT and CMOV, just lacks the long NOP instruction (NOPL). This patch adds a quirck to promote the Geode to an i686 and emulates the NOPL in the do_invalid_op trap, so the userspace never notices. Emulating the NOPL has minimum performance loss, emulating a NOPL takes 0.5 usecs
and they are rarely used in x86

NOP should be fast, so this is bad idea.
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#107 lore raw
In reply to Matteo Croce
Quoted 3 lines · On Sat, 3 Oct 2009 04:12:47 +0200 Matteo Croce <[email protected]> wrote:

I also did this simple test which gives a ~2.5x speed boost:
http://pastebin.ca/1590089

the number that is exposed in /proc/cpuinfo does not control if cmov is used... so the patch and the benchmark are totally unrelated.

Anything that needs to know if cmov can be used will need to read the flags line..

(since technically cmov is also optional for generation 6 and later)

While I can't say anything against your patch, I do need to say that it is something purely cosmetic on first sight...

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#108 lore raw
Quoted 14 lines · Arjan van de Ven
Quoted 3 lines · On Sat, 3 Oct 2009 04:12:47 +0200 Matteo Croce <[email protected]> wrote:

I also did this simple test which gives a ~2.5x speed boost:
http://pastebin.ca/1590089

the number that is exposed in /proc/cpuinfo does not control if cmov is used... so the patch and the benchmark are totally unrelated.

Anything that needs to know if cmov can be used will need to read the flags line..

(since technically cmov is also optional for generation 6 and later)

Quoted 8 lines

While I can't say anything against your patch, I do need to say that it is something purely cosmetic on first sight...

--
Arjan van de Ven        Intel Open Source Technology Centre For development, discussion and tips for power savings, visit http://www.lesswatts.org

yes cmov and i686 are unrelated but some distros (Debian & co.) compiles libraries for two archs:
i486 and i686-cmov so only i686 machines does benefit from cmov. This is why I cared about having an i686 aware userspace but it seems that for a missing instruction I can't do that

#109 lore raw
Quoted 5 lines · Matteo Croce

yes cmov and i686 are unrelated but some distros (Debian & co.) compiles libraries for two archs:
i486 and i686-cmov so only i686 machines does benefit from cmov. This is why I cared about having an i686 aware userspace but it seems that for a missing instruction I can't do that

You could emulate the missing instruction. As long as it is not really used, the performance cost of the emulation should not matter. Of course if userspace starts to use long NOPs extensively then it becomes a problem.

Gabor

Signature · 4 lines
     ---------------------------------------------------------
     MTA SZTAKI Computer and Automation Research Institute
                Hungarian Academy of Sciences
     ---------------------------------------------------------
#110 lore raw
Quoted 8 lines · Gabor Gombas
Quoted 5 lines · Matteo Croce

yes cmov and i686 are unrelated but some distros (Debian & co.) compiles libraries for two archs:
i486 and i686-cmov so only i686 machines does benefit from cmov. This is why I cared about having an i686 aware userspace but it seems that for a missing instruction I can't do that

Quoted 4 lines

You could emulate the missing instruction. As long as it is not really used, the performance cost of the emulation should not matter. Of course if userspace starts to use long NOPs extensively then it becomes a problem.

Emulate? I can replace it with two plain NOPs.
How can I do the "emulation"? trapping SIGILL?

#111 lore raw
Quoted 2 lines · Matteo Croce

Emulate? I can replace it with two plain NOPs.
How can I do the "emulation"? trapping SIGILL?

No, emulate it in the kernel, so userspace never notices.

Gabor

Signature · 4 lines
     ---------------------------------------------------------
     MTA SZTAKI Computer and Automation Research Institute
                Hungarian Academy of Sciences
     ---------------------------------------------------------
#112 lore raw
In reply to Matteo Croce
Quoted 11 lines · On Sun, 4 Oct 2009 00:04:03 +0200 Matteo Croce <[email protected]> wrote:
Quoted 5 lines

the number that is exposed in /proc/cpuinfo does not control if cmov is used... so the patch and the benchmark are totally unrelated.

yes cmov and i686 are unrelated but some distros (Debian & co.) compiles libraries for two archs:
i486 and i686-cmov so only i686 machines does benefit from cmov. This is why I cared about having an i686 aware userspace but it seems that for a missing instruction I can't do that

I'm surprised that "i686" in debian depends on the family flag in /proc/cpuinfo.. but hey.. weirder things have been done.

Signature · 3 lines
Arjan van de Ven 	Intel Open Source Technology Centre
For development, discussion and tips for power savings, 
visit http://www.lesswatts.org
#113 lore raw
Quoted 2 lines

I'm surprised that "i686" in debian depends on the family flag in /proc/cpuinfo.. but hey.. weirder things have been done.

Its compensating for the old gcc bugs where gcc "i686" generated cmov instructions without any checks whether the CPU supported cmov (which is optional for a 686 architecture)

RPM has (or had) similar hacks. Both arguably come about from fundamental design thinkos in that they treat architecture as "special", not simply as a set of dependancies (needs x86, x86-cmov, glibc x86-32, ...) as should hve been done and which would also have made emulators just work out of the box instead of the current mess.

Alan

#114 lore raw
Quoted 7 lines · Alan Cox
Quoted 2 lines

I'm surprised that "i686" in debian depends on the family flag in /proc/cpuinfo.. but hey.. weirder things have been done.

Its compensating for the old gcc bugs where gcc "i686" generated cmov instructions without any checks whether the CPU supported cmov (which is optional for a 686 architecture)

Quoted 7 lines

RPM has (or had) similar hacks. Both arguably come about from fundamental design thinkos in that they treat architecture as "special", not simply as a set of dependancies (needs x86, x86-cmov, glibc x86-32, ...) as should hve been done and which would also have made emulators just work out of the box instead of the current mess.

Alan

Well, for gcc, the string "i686" really means "pentiumpro". All of these are nothing but named feature sets.

-hpa