#!/bin/sh # /usr/sbin/dphys-kernel-cputype - determine what cpu type this host is # author Neil Franklin, last modification 2006.10.20 # copyright ETH Zuerich Physics Departement, # use under either modified/non-advertising BSD or GPL license DEBUG=false #DEBUG=true set -e # get ready to work PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH # global config file GLOBAL_CONFIG=/etc/dphys-kernel-packages LOCAL_CONFIG=$HOME/.dphys-kernel-packages [ -e ${GLOBAL_CONFIG} ] && . ${GLOBAL_CONFIG} [ -e ${LOCAL_CONFIG} ] && . ${LOCAL_CONFIG} # --- processor type MODEL_NAME="`cat /proc/cpuinfo | grep '^model name' | \ cut -f 2 -d ':' | cut -f 2- -d ' '`" if ( echo "${MODEL_NAME}" | grep "Opteron" > /dev/null ) ; then # we can not generate kernels for k8 yet, as no config analysis CPU_TYPE=k8 elif ( echo "${MODEL_NAME}" | grep "Athlon.*64" > /dev/null ) ; then # we can not generate kernels for k8 yet, as no config analysis CPU_TYPE=k8 elif ( echo "${MODEL_NAME}" | grep "Duron" > /dev/null ) ; then CPU_TYPE=k7 elif ( echo "${MODEL_NAME}" | grep "Sempron" > /dev/null ) ; then CPU_TYPE=k7 elif ( echo "${MODEL_NAME}" | grep "Athlon" > /dev/null ) ; then CPU_TYPE=k7 elif ( echo "${MODEL_NAME}" | grep "Xeon" > /dev/null) ; then # this test will also trigger on PIII Xeon, we have none to test difference CPU_TYPE=p4 elif ( echo "${MODEL_NAME}" | grep "Celeron" > /dev/null) ; then # this test will also trigger on PIII Celeron, we have none to test diff CPU_TYPE=p4 elif ( echo "${MODEL_NAME}" | grep "Pentium.* 4 " > /dev/null) ; then CPU_TYPE=p4 elif ( echo "${MODEL_NAME}" | grep "Pentium.* III " > /dev/null) ; then CPU_TYPE=p3 elif ( echo "${MODEL_NAME}" | grep "Genuine Intel.*2140.*" > /dev/null) ; then CPU_TYPE=p4 elif ( echo "${MODEL_NAME}" | grep "Intel.* XEON.* CPU.*" > /dev/null) ; then CPU_TYPE=p4 elif ( echo "${MODEL_NAME}" | grep "Pentium.* II " > /dev/null) ; then # not tested as we have none, fallback to PI, as no config analysis for PII CPU_TYPE=p1 elif ( echo "${MODEL_NAME}" | grep "Pentium" > /dev/null) ; then CPU_TYPE=p1 else echo "$0: ERROR: unknown CPU model name: ${MODEL_NAME}" >&2 # error output for script using this to screw up on echo "unknown_cpu_model_report_this" exit 1 fi # --- SMP option # this fails, if only non-smp kernel running, such as universal install kernel # then even smp machines appear as non-smp, as rest not used and not listed #LAST_CPU="`cat /proc/cpuinfo | grep ^processor | tail -1 | \ # cut -f 2 -d ':' | cut -f 2 -d ' '`" #if [ "${LAST_CPU}" = "0" ] ; then # SMP_OPT="" #else # SMP_OPT="-smp" #fi # so use external lshw to detect this if ! which lshw > /dev/null ; then echo "$0: FATAL: failed to find lshw, can not work, aborting ..." >&2 fi # get rid of unnecessary tests as lshw is called twice for each of 7 packages SPEEDUP="-disable spd -disable cpuid -disable pci -disable isapnp \ -disable pcmcia -disable ide -disable usb -disable scsi -disable network" # simply count *-cpu[:n] lines # no "" around ${SPEEDUP}, lshw can not handle the result CPUS="`lshw ${SPEEDUP} -class processor 2>/dev/null | \ grep '^ *\*-cpu' | wc -l | tr -d ' '`" if [ "${CPUS}" = "1" ] ; then SMP_OPT="${CONF_CPUTYPE_SMP_OPT_DEFAULT}" else SMP_OPT="-smp" fi # --- memory size # use external lshw to detect memory size # Sarge has lshw in /usr/sbin and nobody hasn't that one in $PATH LSHW=`which lshw` # find size: line of first (and hopefully main) *-memory section # 'head' because some machines have an 2nd memory section for flash # Use nobody instead of root, since lshw otherwise doesn't summarize memory if [ "`id -u`" = "0" ]; then MEMORY="`su nobody -c \"${LSHW} ${SPEEDUP} -class memory 2>/dev/null | \ sed -ne '/ *\*-memory/,/ *\*-/{ /.*size: /s/.*size: //p }' | \ head -n 1\"`" else MEMORY="`${LSHW} ${SPEEDUP} -class memory 2>/dev/null | \ sed -ne '/ *\*-memory/,/ *\*-/{ /.*size: /s/.*size: //p }' | \ head -n 1`" fi if [ "${MEMORY}" = "" ] ; then # on some machines *-memory section delivers no size: line # fall back to capacity: but standard use size: is more reliable value # actually capacity: seems to be maximal memory that can be plugged in # better would be to sum up size: from all banks, but that is difficult MEMORY="`lshw ${SPEEDUP} -class memory 2>/dev/null | \ awk '$2~/GB/ && $1=="size:" { gsub(/GB/,"",$2); $2=$2*1024; print $2; }; $2~/MB/ && $1=="size:" { gsub(/MB/,"",$2); print $2 }; $2~/[Kk]B/ && $1=="size:" { gsub(/[Kk]B/,"",$2); print $2/1024 }; $2!~/[GMkK]B/ && $1=="size:" { print $2/1024/1024 }' | \ awk '$1 > 64 { i += $1 } END { print i }'`" fi if [ "${MEMORY}" = "" ] ; then # this also fails when small memory install kernel is running MEMORY_MB="`free -m | grep '^Mem:' | awk '{print $2}'`" fi # standardise on MB, convert GB to MB if [ "`echo "${MEMORY}" | tr -d '[0-9]'`" = GB ] ; then MEMORY_GB="`echo "${MEMORY}" | tr -d '[A-Z]'`" MEMORY_MB="`expr "${MEMORY_GB}" '*' 1024`" else MEMORY_MB="`echo "${MEMORY}" | tr -d '[A-Z]'`" fi ${DEBUG} && echo MEMORY=${MEMORY} ${DEBUG} && echo MEMORY_MB="${MEMORY_MB}MB " ${DEBUG} && echo MEMORY_GB=${MEMORY_GB} if [ "${MEMORY_MB}" -gt 3200 ] ; then ${DEBUG} && echo "64GB: ${MEMORY_MB} -gt 3200" MEM_TYPE="-64gb" # 880 fails to recognize some machines as 1gb -> 900 elif [ "${MEMORY_MB}" -gt 900 ] ; then ${DEBUG} && echo "4GB: ${MEMORY_MB} -gt 900" MEM_TYPE="-4gb" else ${DEBUG} && echo 1GB MEM_TYPE=${CONF_MIN_MEM_OPT:--1gb} fi # ARGH, this seems to break more than it fixes -- Axel #if (cat /proc/cpuinfo | grep processor | wc -l | grep 2 >/dev/null); then # SMP_OPT="-smp" # # ugly fix so we don't have to build p4-smp-4gb kernels # MEM_TYPE="-64gb" #fi # --- output # this should be the only output generated echo "${CPU_TYPE}${SMP_OPT}${MEM_TYPE}" exit 0