Hi, From: Karel Zak <kzak@xxxxxxxxxx> Subject: Re: [RFC] lscpu - CPU architecture information helper Date: Sun, 6 Jul 2008 23:44:09 +0200 > > Hi Cai, > > I have a few (minor) notes: > > On Fri, Jul 04, 2008 at 11:23:10AM +0800, Cai Qian wrote: > > I propose a new tool lscpu to util-linux-ng, This program gathers CPU > > don't forget that a man page is required for all new tools. > > > _______________________________________________________________ > > | | | | | | | | | > > | cpu0 | | | | | | | | > > |______| core0 | | L1d | L1i | L2d | | | > > | | | | 16K | 16K | 256K | | | > > | cpu1 | | | | | | | | > > |______|_______| processor0 |_____|_____|______| L2i | L3 | > > | | | | | | | 1024K | 12288K | > > | cpu2 | | | | | | | | > > |______| core1 | | L1d | L1i | L2d | | | > > | | | | 16K | 16K | 256K | | | > > | cpu3 | | | | | | | | > > |______|_______|____________|_____|_____|______|_______|________| > > | | | | | | | | | > > | cpu4 | | | | | | | | > > |______| core2 | | L1d | L1i | L2d | | | > > | | | | 16K | 16K | 256K | | | > > | cpu5 | | | | | | | | > > |______|_______| processor1 |_____|_____|______| L2i | L3 | > > | | | | | | | 1024K | 12288K | > > | cpu6 | | | | | | | | > > |______| core3 | | L1d | L1i | L2d | | | > > | | | | 16K | 16K | 256K | | | > > | cpu7 | | | | | | | | > > |______|_______|____________|_____|_____|______|_______|________| > > > That's really nice ASCII art. People love pictures :-) > > > usage() > > { > > cat <<EOF > > Usage: $0 [OPTION] > > CPU architecture information helper > > > > -p, --parse print out in parsable instead of printable format. > > -h, --help usage information > > EOF > > } > > Please, read: > http://www.gnu.org/software/autoconf/manual/gettext/Preparing-Shell-Scripts.html > > > arch=$(uname -m) > > # Only i686, X86_64 and IA64 are supported at the moment. > > Do you plan to add any other architectures? > On 2.6.18 Kernel, ppc64 does not have a really helpful cpuinfo and sysfs. I don't know about it on the latest Kernel version though. Also, It does not make too much sense to support s390(x), as each guest just have some virtual CPUs. I don't have access to machines of other architectures though. If it is possible, I'd be happy to test it on those architectures too. CaiQian > > # Dom0 Kernel gives wrong information. > > if grep "control_d" "/proc/xen/capabilities" >/dev/null 2>&1; then > > echo "Error: Dom0 Kernel is not supported." >&2 > > exit 1 > > fi > > BTW, virsh(8) (command "virtsh nodeinfo") from libvirt provides basic > information about virtual HW. > > > # Read through sysfs. > > syspath="/sys/devices/system" > > maybe you also want to define: > > cpu0path="${syspath}/cpu/cpu0" > > > # Read through cpuinfo. > > vendor=$(grep -m 1 "vendor" /proc/cpuinfo | sed 's/.*: \(.*\)/\1/') > > family=$(grep -m 1 "family" /proc/cpuinfo | sed 's/.*: \(.*\)/\1/') > > model=$(grep -m 1 "model.[^n]" /proc/cpuinfo | sed 's/.*: \(.*\)/\1/') > > stepping=$(grep -m 1 "stepping" /proc/cpuinfo | sed 's/.*: \(.*\)/\1/') > > mhz=$(grep -m 1 "cpu MHz" /proc/cpuinfo | sed 's/.*: \(.*\)/\1/') > > Awk lover's note: > > export $(gawk ' > BEGIN {FS=": "} > /^model.[^n]/ {v=$2} > /^cpu family/ {f=$2} > /^model.[^n]/ {m=$2} > /^stepping/ {s=$2} > /^cpu MHz/ {h=$2} > { if (v && f && m && s && h) nextfile } > END { > printf "vendor=" v; > printf "family=" f; > printf "model=" m; > printf "stepping=" s; > printf "mhz=" h; > }' /proc/cpuinfo) > > > level=$(cat "${syspath}/cpu/cpu0/cache/${i}/level") > > type=$(cat "${syspath}/cpu/cpu0/cache/${i}/type") > > type=$(<"${syspath}/cpu/cpu0/cache/${i}/type") > > > Karel > > -- > Karel Zak <kzak@xxxxxxxxxx> -- To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html