Processor autodetection (when configuring kernel)
PATCH 1/1 Processor autodetection (when configuring kernel)
Hi Linus!
Here a first try to autodetect the processor when configure kernel.
How it works:
1) I add a CONFIG_CPU_CURRENT boolean.
2) If it is set, the next Makefile will call script/cpu_detect.sh and try to detect the processor (it return CONFIG_M386 if it fails)
3) Makefile sets the autodetected processor and CONFIG_CPU_CURRENT=n, so next time it will use the already detected CPU
4) it does a make oldconfig to configure the the other processor flags ( and to be sure that it will be a correct configuration file)
4) The GNU make will automagically restart makefile, bacause and include (include .config) is changed.
I don't know well the non-intel processors, so addition for extra processors are welcome.
giacomo
The patch
=========
Makefile Fri Dec 29 13:32:10 2000 renamed from Makefile Fri Dec 29 11:26:55 2000 +10 -0
@@ -65,6 +65,16 @@ do-it-all: config endif +# Second stage configuration +# Note that GNU make will read again this Makefile, so the CONFIG are +# updated +ifeq ($(CONFIG_CPU_CURRENT), y) +CONFIGURATION = config2 +do-it-all: config2 +.config: config2 + @echo "Rescanning the main Makefile" +endif + # # INSTALL_PATH specifies where to place the updated kernel and system
map
# images. Uncomment if you want to place them anywhere other than root. @@ -273,6 +283,14 @@
config: symlinks
$(CONFIG_SHELL) scripts/Configure arch/$(ARCH)/config.in
+
+config2:
+ echo "CONFIG_CPU_CURRENT=n" >> .config
+ echo $(CONFIG_SHELL) $(TOPDIR)/scripts/cpu_detect.sh=y >>
.config
+ $(MAKE) oldconfig
+
+config2.test:
+ echo "CONFIG_CPU_CURRENT=$(CONFIG_CPU_CURRENT)"
include/config/MARKER: scripts/split-include include/linux/autoconf.h
scripts/split-include include/linux/autoconf.h include/config
arch/i386/config.in Fri Dec 29 13:14:58 2000 renamed from arch/i386/config.in Fri Dec 29 11:26:55 2000 +7 -1
@@ -26,7 +26,9 @@ mainmenu_option next_comment comment 'Processor type and features' -choice 'Processor family' \ +bool "Optimize for current CPU" CONFIG_CPU_CURRENT +if [ "$CONFIG_CPU_CURRENT" != "y" ]; then + choice 'Processor family' \ "386 CONFIG_M386 \ 486 CONFIG_M486 \ 586/K5/5x86/6x86/6x86MX CONFIG_M586 \
@@ -41,6 +43,10 @@ Winchip-C6 CONFIG_MWINCHIPC6 \ Winchip-2 CONFIG_MWINCHIP2 \ Winchip-2A/Winchip-3 CONFIG_MWINCHIP3D" Pentium-Pro +else + # First configuration stage: Allow all possible processors deps + define_bool CONFIG_M386 y +fi # # Define implied options from the CPU selection here #
scripts/cpu_detect.sh Fri Dec 29 14:10:42 2000 renamed from scripts/cpu_detect.sh Thu Jan 1 01:00:00 1970 +11 -0
@@ -0,0 +1,35 @@ +#! /bin/bash + +# Copyright (C) 2000 Giacomo Catenazzi <[email protected]> +# This is free software, see GNU General Public License 2 for details. + +# This script try to autodetect the CPU. +# On SMP I assume that all processors are of the same type as the first + + +if [ "$ARCH" = "i386" ] ; then + vendor=$(sed -n 's/^vendor_id.*: \([-A-Za-z0-9_]*\).*$/\1/pg'
/proc/cpuinfo)
+ cpu_fam=$(sed -n 's/^cpu family.*: \([0-9A-Za-z]*\).*$/\1/pg' /proc/cpuinfo)
+ cpu_mod=$(sed -n 's/^model[^a-z]*: \([0-9A-Za-z]*\).*$/\1/pg' /proc/cpuinfo)
+ cpu_id="$vendor:$cpu_fam:$cpu_mod"
+
+ #echo $cpu_id # for debug
+
+ case $cpu_id in
+ GenuineIntel:5:[0123] ) echo CONFIG_M586TSC ;;
+ GenuineIntel:5:[48] ) echo CONFIG_M586MMX ;;
+ GenuineIntel:6:[01356] ) echo CONFIG_M686 ;;
+ GenuineIntel:6:{8,9,11} ) echo CONFIG_M686FXSR ;;
+ AuthenticAMD:5:[0123] ) echo CONFIG_M586 ;;
+ AuthenticAMD:5:{8,9,10,11} ) echo CONFIG_MK6 ;;
+ AuthenticAMD:6:[0124] ) echo CONFIG_MK7 ;;
+ UMC:4:[12] ) echo CONFIG_M486 ;; # "UMC" !
+ NexGenDriven:5:0 ) echo CONFIG_M386 ;;
+ {TransmetaCPU,GenuineTMx86}:* ) echo CONFIG_MCROSUE ;; +
+ # some default values
+
+ * ) echo CONFIG_M386 ;;
+
+ esac
+fi
CREDITS Fri Dec 29 13:43:02 2000 renamed from CREDITS Fri Dec 29 13:32:46 2000 +6 -0
@@ -458,6 +458,12 @@ S: Fremont, California 94539 S: USA +N: Giacomo Catenazzi +E: [email protected] +D: Random kernel hack and fixes +D: Author of scripts/cpu_detect.sh +S: Switzerland + N: Gordon Chaffee E: [email protected] W: http://bmrc.berkeley.edu/people/chaffee/
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
Giacomo,
I don't think cpu_info.sh is quite right. It identified my 500 Mhz Pentium III as CONFIG_M386. I think CONFIG_M686 is closer, but as I don't know the significance of all the flags (MMX, TSC, etc), I'm not certain. Since the flags do include fxsr, the correct answer may be CONFIG_M686FXSR.
Anyhow, here are my results:
[relson@osage relson]$ cat /proc/cpuinfo
processor : 0vendor_id : GenuineIntel
cpu family : 6
model : 7
model name : Pentium III (Katmai)
stepping : 3
cpu MHz : 501.147
cache size : 512 KBfdiv_bug : nohlt_bug : nosep_bug : nof00f_bug : nocoma_bug : no
fpu : yesfpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 sep mtrr pge mca cmov pat pse36 mmx fxsr xmm
bogomips : 999.42
[relson@osage relson]$ ARCH=i386 ; . cpu_detect.sh GenuineIntel:6:7CONFIG_M386
Also, here's a patch to make the script echo CONFIG_M686:
cpu_detect.sh renamed from cpu_detect.sh.orig +1 -1
@@ -18,7 +18,7 @@ case $cpu_id in GenuineIntel:5:[0123] ) echo CONFIG_M586TSC ;; GenuineIntel:5:[48] ) echo CONFIG_M586MMX ;; - GenuineIntel:6:[01356] ) echo CONFIG_M686 ;; + GenuineIntel:6:[013567] ) echo CONFIG_M686 ;; GenuineIntel:6:{8,9,11} ) echo CONFIG_M686FXSR ;; AuthenticAMD:5:[0123] ) echo CONFIG_M586 ;; AuthenticAMD:5:{8,9,10,11} ) echo CONFIG_MK6 ;;
David
P.S. I'm running 2.2.18, if it matters.
--------------------------------------------------------
David Relson Osage Software Systems, Inc. [email protected] Ann Arbor, MI 48103 www.osagesoftware.com tel: 734.821.8800
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
Giacomo,
Further experimentation has revealed another problem with the script. The use of curly braces in the case statement, i.e.
GenuineIntel:6:{8,9,11} ) echo CONFIG_M686FXSR ;;does not work. The construct below works, but I don't like it because of its length:
GenuineIntel:6:8|GenuineIntel:6:9|GenuineIntel:6:11 ) echo
CONFIG_M686FXSR ;;
David
--------------------------------------------------------
David Relson Osage Software Systems, Inc. [email protected] Ann Arbor, MI 48103 www.osagesoftware.com tel: 734.821.8800
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/
Review
Quoted 11 lines · Giacomo A. Catenazzi
(quoted diff) +11
-0+ case $cpu_id in + GenuineIntel:5:[0123] ) echo CONFIG_M586TSC ;; + GenuineIntel:5:[48] ) echo CONFIG_M586MMX ;; + GenuineIntel:6:[01356] ) echo CONFIG_M686 ;; + GenuineIntel:6:{8,9,11} ) echo CONFIG_M686FXSR ;; + AuthenticAMD:5:[0123] ) echo CONFIG_M586 ;; + AuthenticAMD:5:{8,9,10,11} ) echo CONFIG_MK6 ;; + AuthenticAMD:6:[0124] ) echo CONFIG_MK7 ;; + UMC:4:[12] ) echo CONFIG_M486 ;; # "UMC" ! + NexGenDriven:5:0 ) echo CONFIG_M386 ;; + {TransmetaCPU,GenuineTMx86}:* ) echo CONFIG_MCROSUE ;;
What about non-ia32 processor based systems? I'd ivolunteer to extend the patch, but I'd need *your* /proc/cpuinfo... I think that's worth it...
MfG, JBG
Signature · 8 lines
Fehler eingestehen, Größe zeigen: Nehmt die Rechtschreibreform zurück!!! /* Jan-Benedict Glaw <[email protected]> -- +49-177-5601720 */ keyID=0x8399E1BB fingerprint=250D 3BCF 7127 0D8C A444 A961 1DBD 5E75 8399 E1BB "insmod vi.o and there we go..." (Alexander Viro on linux-kernel) - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] Please read the FAQ at http://www.tux.org/lkml/
Quoted 1 line · Giacomo A. Catenazzi
+ {TransmetaCPU,GenuineTMx86}:* ) echo
CONFIG_MCROSUE;;
+ {TransmetaCPU,GenuineTMx86}:* ) echo CONFIG_MCRUSOE ;;
This is just a typo, right? ;-)
Regards
Ingo Oeser
Signature · 6 lines
10.+11.03.2001 - 3. Chemnitzer LinuxTag <http://www.tu-chemnitz.de/linux/tag>
<<<<<<<<<<<< come and join the fun >>>>>>>>>>>>
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/Version 2:
. Added a PIII
. Corrected the name of Crusoe
. Added the generic Intel and AMD 486
. Corrected the braces {,} (wrong syntax)
giacomo
CREDITS Fri Dec 29 13:43:02 2000 renamed from CREDITS Fri Dec 29 13:32:46 2000 +6 -0
@@ -458,6 +458,12 @@ S: Fremont, California 94539 S: USA +N: Giacomo Catenazzi +E: [email protected] +D: Random kernel hack and fixes +D: Author of scripts/cpu_detect.sh +S: Switzerland + N: Gordon Chaffee E: [email protected] W: http://bmrc.berkeley.edu/people/chaffee/
Makefile Fri Dec 29 13:32:10 2000 renamed from Makefile Fri Dec 29 11:26:55 2000 +10 -0
@@ -65,6 +65,16 @@ do-it-all: config endif +# Second stage configuration +# Note that GNU make will read again this Makefile, so the CONFIG are +# updated +ifeq ($(CONFIG_CPU_CURRENT), y) +CONFIGURATION = config2 +do-it-all: config2 +.config: config2 + @echo "Rescanning the main Makefile" +endif + # # INSTALL_PATH specifies where to place the updated kernel and system
map
# images. Uncomment if you want to place them anywhere other than root. @@ -273,6 +283,14 @@
config: symlinks
$(CONFIG_SHELL) scripts/Configure arch/$(ARCH)/config.in
+
+config2:
+ echo "CONFIG_CPU_CURRENT=n" >> .config
+ echo $(CONFIG_SHELL) $(TOPDIR)/scripts/cpu_detect.sh=y >>
.config
+ $(MAKE) oldconfig
+
+config2.test:
+ echo "CONFIG_CPU_CURRENT=$(CONFIG_CPU_CURRENT)"
include/config/MARKER: scripts/split-include include/linux/autoconf.h
scripts/split-include include/linux/autoconf.h include/config
arch/i386/config.in Fri Dec 29 13:14:58 2000 renamed from arch/i386/config.in Fri Dec 29 11:26:55 2000 +7 -1
@@ -26,7 +26,9 @@ mainmenu_option next_comment comment 'Processor type and features' -choice 'Processor family' \ +bool "Optimize for current CPU" CONFIG_CPU_CURRENT +if [ "$CONFIG_CPU_CURRENT" != "y" ]; then + choice 'Processor family' \ "386 CONFIG_M386 \ 486 CONFIG_M486 \ 586/K5/5x86/6x86/6x86MX CONFIG_M586 \
@@ -41,6 +43,10 @@ Winchip-C6 CONFIG_MWINCHIPC6 \ Winchip-2 CONFIG_MWINCHIP2 \ Winchip-2A/Winchip-3 CONFIG_MWINCHIP3D" Pentium-Pro +else + # First configuration stage: Allow all possible processors deps + define_bool CONFIG_M386 y +fi # # Define implied options from the CPU selection here #
scripts/cpu_detect.sh Fri Dec 29 17:10:23 2000 renamed from scripts/cpu_detect.sh Thu Jan 1 01:00:00 1970 +11 -0
@@ -0,0 +1,38 @@ +#! /bin/bash + +# Copyright (C) 2000 Giacomo Catenazzi <[email protected]> +# This is free software, see GNU General Public License 2 for details. + +# This script try to autodetect the CPU. +# On SMP I assume that all processors are of the same type as the first + + +if [ "$ARCH" = "i386" ] ; then + vendor=$(sed -n 's/^vendor_id.*: \([-A-Za-z0-9_]*\).*$/\1/pg'
/proc/cpuinfo)
+ cpu_fam=$(sed -n 's/^cpu family.*: \([0-9A-Za-z]*\).*$/\1/pg' /proc/cpuinfo)
+ cpu_mod=$(sed -n 's/^model[^a-z]*: \([0-9A-Za-z]*\).*$/\1/pg' /proc/cpuinfo)
+ cpu_id="$vendor:$cpu_fam:$cpu_mod"
+
+ #echo $cpu_id # for debug
+
+ case $cpu_id in
+ GenuineIntel:4:* ) echo CONFIG_M486 ;; # exists ? + GenuineIntel:5:[0123] ) echo CONFIG_M586TSC ;; + GenuineIntel:5:[48] ) echo CONFIG_M586MMX ;; + GenuineIntel:6:[01356] ) echo CONFIG_M686 ;; + GenuineIntel:6:[789] ) echo CONFIG_M686FXSR ;; + GenuineIntel:6:1[1] ) echo CONFIG_M686FXSR ;; + AuthenticAMD:4:* ) echo CONFIG_M486 ;; + AuthenticAMD:5:[0123] ) echo CONFIG_M586 ;; + AuthenticAMD:5:[89] ) echo CONFIG_MK6 ;; + AuthenticAMD:5:1[01] ) echo CONFIG_MK6 ;; + AuthenticAMD:6:[0124] ) echo CONFIG_MK7 ;; + UMC:4:[12] ) echo CONFIG_M486 ;; # "UMC" ! + NexGenDriven:5:0 ) echo CONFIG_M386 ;; + TransmetaCPU:* ) echo CONFIG_MCRUSOE ;; + GenuineTMx86:* ) echo CONFIG_MCRUSOE ;;
+
+ # default value
+ * ) echo CONFIG_M386 ;;
+ esac
+fi
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
Please read the FAQ at http://www.tux.org/lkml/