* /proc/cpuinfo shell script
@ 2000-11-14 5:00 Martin Wilck
0 siblings, 0 replies; only message in thread
From: Martin Wilck @ 2000-11-14 5:00 UTC (permalink / raw)
First of all, many thanks to all people who have answered my request!
I wrote a small sh/sed script that parses the cpuinfo information on
different architectures. The script handles iX86, alpha, m68k, ppc,
mips, and ia64 architectures currently.
(--> cpuinfo contents for sparc are still wanted!)
I am including the script below. I'd like to ask another favour:
Could you run the script on their machines and find out whether it
prints something that you think describes your hardware architecture
well, in terms of CPU, floating-point unit, and cache (cache information
is only available on iX86 and ppc)? Can you suggest improvements for
your architecture?
The default for the script is to output the information in a way that
is suitable as (part of) a file name (it'll be part of the name of the
binary rpm for atlas when I'm done), therefore I tried to keep the output
as short as possible without losing relevant information.
See the usage info at the beginning of the script.
Thanks a lot, Martin
--
Martin Wilck <martin@tropos.de>
Institute for Tropospheric Research, Permoserstr. 15, D-04318 Leipzig, Germany
Tel. +49-341-2352151 / Fax +49-341-2352361
#! /bin/sh
#-----------------------------------------------------------------------
# architecture.sh: determine hardware properties from /proc/cpuinfo
#-----------------------------------------------------------------------
usage="\
$0
Determine detailed architecture model and generate a string
suitable for a file name from it.
Options: -r - output in file name format (default),
-h - output in human-readable format,
-? - print this usage information.
With -r, the output has the form [architecture]-[cache size in kB].
(c) Martin Wilck <martin@tropos.de> 2000
Redistribution and modification granted under the terms of the GNU GPL.
NO WARRANTY OF ANY KIND.
"
#-----------------------------------------------------------------------
# Some sed "procedures" for better readability.
#-----------------------------------------------------------------------
# Remove characters that may irritate the shell.
del_special="s/[^a-zA-Z0-9_.-]\{1,\}/-/g"
# Get rid of stuff in parentheses (except pure numbers).
del_parens='s/(\([0-9]*\))/-\1-/g;s/([^)]*)//g'
# Get rid of words that are useless.
del_useless='s/[pP]rocessor//;s/[cC][pP][uU]//'
# Get rid of spurious "-".
purge_minus='s/-\{2,\}/-/g;s/^-*//;s/-*$//'
# Get the value of an cpuinfo entry
get_value='s/^[^:]*:[ ]*//'
# Get a number from a field.
get_number='s/^[^0-9]*\([0-9]*\)[^0-9]*$/\1/'
# Print hold space contents on a line.
print_hold='x;s/\n/ /g;s/^ *//;s/ *$//;s/^$/unknown/;p;q'
# If all else fails, print "unknown" at end of file.
insert_unknown='$s/^.*$/unknown/p'
#-----------------------------------------------------------------------
# Check Options.
#-----------------------------------------------------------------------
mode=name
if test $# -gt 0; then
case $1 in
-h) mode=human;;
-r) mode=name;;
-\?) echo "$usage" >&2; exit 0 ;;
*) echo "$usage" >&2; exit 1 ;;
esac
fi
#-----------------------------------------------------------------------
# Do the work.
#-----------------------------------------------------------------------
mach=`uname -m`
cpuinfo=/proc/cpuinfo
cache=unknown
test -f $cpuinfo || \
{ echo "$0: cannot read $cpuinfo !" >&2; exit 1 }
case "$mach" in
i?86)
human=`sed -n "$insert_unknown;/^model name/{$get_value;p;q;}" \
<$cpuinfo`
cache=`sed -n "$insert_unknown;/^cache size/{$get_number;p;q;}" \
<$cpuinfo`
;;
alpha)
human=`sed -n '$'"{$print_hold;};\
/^cpu[^a-z:]*:/{$get_value;H;d;};
/^cpu model/{$get_value;H;d;};
/^cpu variation[^:]*: [0-9]/{$get_number;s/^\(.*\)$/(\1)/;H;$print_hold;}" \
< $cpuinfo`
;;
m68k)
human=`sed -n '$'"{$print_hold;};\
/^CPU/{$get_value;H;d;};
/^FPU/{$get_value;s/^\(.*\)$/- FPU \1 -/;H;$print_hold;}" \
< $cpuinfo`
;;
ppc)
human="PPC "`sed -n "$insert_unknown;/^cpu/{$get_value;p;q;}" \
<$cpuinfo`
cache=`sed -n "$insert_unknown;\
/^L2 cache/{$get_value;$get_number;p;q;}" \
<$cpuinfo`
;;
mips)
human=`sed -n '$'"{$print_hold;};\
/^cpu[^a-z:]*:/{$get_value;H;d;};
/^cpu model/{$get_value;H;$print_hold;}" \
< $cpuinfo`
;;
ia64)
human=`sed -n '$'"{$print_hold;};\
/^family/{$get_value;H;d;};
/^model/{$get_value;H;d;};
/^revision/{$get_value;H;$print_hold;}" \
< $cpuinfo`
;;
*)
echo "$0: unknown machine type: \"$mach\" !" >&2
human=$mach
;;
esac
#-----------------------------------------------------------------------
# Print result.
#-----------------------------------------------------------------------
if test $mode = human; then
if test $cache = unknown; then
echo "$human with unknown L2 cache size"
else
echo "$human with $cache kB L2 cache"
fi
else
cpu=`echo $human | \
sed "$del_parens;$del_useless;$del_special;$purge_minus;"`
echo "$cpu-$cache"
fi
exit 0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2000-11-14 5:00 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2000-11-14 5:00 /proc/cpuinfo shell script Martin Wilck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox