[e21569]: testsuite / lib / op_util.exp Maximize Restore History

Download this file

op_util.exp    259 lines (241 with data), 7.0 kB

# op_util.exp
#   Copyright (C) 2006 Red Hat, Inc.
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#


# globals which might change, perhaps?
set op_proc_prefix "/dev/oprofile"
set op_var_prefix "/var/lib/oprofile"


# read contents of file and return
proc op_get_file_contents {fname} {
    set fd [open $fname]
    set res [read $fd]
    close $fd
    return $res
}

# cycle-waster routine
proc op_spin {count} {
    verbose "spinning cpu for $count \"work units\""
    set j 23523
    set k 15431
    set m 73141
    set n 93802
    for {set i 0} {$i < $count} {incr i} {
	set j [expr {($k * $m - ($n >> 2)) % 4294967296}]
	set k [expr {($m + $n * ($j ^ $k)) % 4294967296}]
	set m [expr {($n * $j - ($k << 2)) % 4294967296}]
	set n [expr {($j + $k * ($m ^ $k)) % 4294967296}]
    }
    local_exec "dd bs=16 if=/dev/urandom of=/dev/null count=$count" "" "" 10
}

# If the processor is i386/arch_perfmon, it could be a variant.
proc op_intel_perf_arch {cpu_type} {
    if {[regexp "i386/arch_perfmon" $cpu_type dummy] != 1} {
	return $cpu_type
    }

    #get information from /proc/cpuinfo
    set cpuinfo [ local_exec "cat /proc/cpuinfo" "" "" 100 ]
    if { [ regexp -line "model\t\t: \[0-9\]+" $cpuinfo line] != 1 } {
	return $cpu_type
    }

    if {[regexp "\[0-9]+" $line model] == 1} {
	switch -exact "$model" {
	    15 {set cpu_type i386/core_2}
	    22 {set cpu_type i386/core_2}
	    23 {set cpu_type i386/core_2}
	    29 {set cpu_type i386/core_2}
	    26 {set cpu_type i386/core_i7}
	    30 {set cpu_type i386/core_i7}
	    31 {set cpu_type i386/core_i7}
	    46 {set cpu_type i386/core_i7}
	    28 {set cpu_type i386/atom}
	    37 {set cpu_type i386/westmere}
	    44 {set cpu_type i386/westmere}
	    47 {set cpu_type i386/westmere}
	    42 {set cpu_type i386/sandybridge}
	    45 {set cpu_type i386/sandybridge}
	}
    }

    verbose "arch_perfmon variant is $cpu_type"
    return $cpu_type
}

# detect CPU type
proc op_cpu_type {} {

    global op_proc_prefix
    set type rtc
    set cpu_type [op_get_file_contents "$op_proc_prefix/cpu_type"]

    # Do additional mappings for Intel architected performance counters
    set cpu_type [ op_intel_perf_arch "$cpu_type"]

    verbose "cpu_type is $cpu_type"
    switch -exact "$cpu_type" {
	0 {set type ppro}
	i386/ppro {set type ppro}
	1 {set type ppro}
	i386/pii {set type ppro}
	2 {set type ppro}
	i386/piii {set type ppro}
	3 {set type athlon}
	i386/athlon {set type athlon}
	4 {set type timer}
	timer {set type timer}
	5 {set type rtc}
	rtc {set type rtc}
	6 {set type p4}
	i386/p4 {set type p4}
	7 {set type ia64}
	ia64/ia64 {set type ia64}
	8 {set type ia64}
	ia64/itanium {set type ia64}
	9 {set type ia64}
	ia64/itanium2 {set type ia64}
	10 {set type athlon}
	x86-64/hammer {set type athlon}
	11 {set type p4}
	i386/p4-ht {set type p4}
	12 {set type alpha}
	alpha/ev4 {set type alpha}
	13 {set type alpha}
	alpha/ev5 {set type alpha}
	14 {set type alpha}
	alpha/pca56 {set type alpha}
	15 {set type alpha}
	alpha/ev6 {set type alpha}
	16 {set type alpha7}
	alpha/ev67 {set type alpha}
	17 {set type ppro}
	i386/p6_mobile {set type ppro}
	18 {set type gen_arm}
	arm/xscale1 {set type gen_arm}
	19 {set type gen_arm}
	arm/xscale2 {set type gen_arm}
	20 {set type power4}
	ppc64/power4 {set type power4}
	21 {set type power5}
	ppc64/power5 {set type power5}
	22 {set type power5p}
	ppc64/power5+ {set type power5p}
	23 {set type power970}
	ppc64/970 {set type ppc970}
	24 {set type mips}
	mips/20K {set type mips}
	25 {set type mips}
	mips/24K {set type mips}
	26 {set type mips}
	mips/25K {set type mips}
	27 {set type mips}
	mips/34K {set type mips}
	28 {set type mips}
	mips/5K {set type mips}
	29 {set type mips}
	mips/r10000 {set type mips}
	30 {set type mips}
	mips/r12000 {set type mips}
	31 {set type mips}
	mips/rm7000 {set type mips}
	32 {set type mips}
	mips/rm9000 {set type mips}
	33 {set type mips}
	mips/sb1 {set type mips}
	34 {set type mips}
	mips/vr5432 {set type mips}
	35 {set type mips}
	mips/vr5500 {set type mips}
	36 {set type e500}
	ppc/e500 {set type e500}
	37 {set type e500}
	ppc/e500v2 {set type e500}
	38 {set type ppro}
	i386/core {set type ppro}
	39 {set type ppc7450}
	ppc/7450 {set type ppc7450}
	40 {set type core2}
	i386/core_2 {set type core2}
	41 {set type power6}
	ppc64/power6 {set type power6}
	42 {set type power970}
	ppc64/970MP {set type power970}
	43 {set type cell_be}
	ppc64/cell-be {set type cell_be}
	44 {set type athlon}
	x86-64/family10 {set type athlon}
	45 {set type pa6t}
	ppc64/pa6t {set type pa6t}
	46 {set type gen_arm}
	arm/mpcore {set type gen_arm}
	47 {set type gen_arm}
	arm/armv6 {set type gen_arm}
	48 {set type power5pp}
	ppc64/power5++ {set type power5pp}
	49 {set type e500}
	ppc/e300 {set type e500}
	50 {set type avr32}
	avr32 {set type avr32}
	51 {set type arm7}
	arm/armv7 {set type arm7}
	52 {set type arch_perf}
	i386/arch_perfmon {set type arch_perf}
	53  {set type athlon}
	x86-64/family11h {set type athlon}
	54 {set type power7}
	ppc64/power7 {set type power7}
	55 {set type ibm_compat_v1}
	ppc64/ibm-compat-v1 {set type ibm_compat_v1}
	56 {set type arch_perf}
	i386/core_i7 {set type arch_perf}
	57 {set type arch_perf}
	i386/atom {set type arch_perf}
	58 {set type mips}
	mips/loongson2 {set type mips}
	59 {set type arch_perf}
	i386/nehalem {set type arch_perf}
	60 {set type arm7}
	arm/armv7-ca9 {set type arm7}
	61 {set type mips}
	mips/74K {set type mips}
	62 {set type mips}
	mips/1004K {set type mips}
	63 {set type athlon}
	x86-64/family12h {set type athlon}
	64 {set type athlon}
	x86-64/family14h {set type athlon}
	65 {set type athlon}
	x86-64/family15h {set type athlon}
	66 {set type arch_perf}
	i386/westmere  {set type arch_perf}
	67 {set type arm7}
	arm/armv7-scorpion {set type arm7}
	68 {set type arm7}
	arm/armv7-scorpionmp {set type arm7}
	69 {set type arch_perf}
	i386/sandybridge {set type sandybridge}
	# Newer kernels do not have cpu number, just strings
	arm/armv7-ca5 {set type arm7}
	arm/armv7-ca7 {set type arm7}
	arm/armv7-ca15 {set type arm7}
    }

    verbose "cpu type is $type"
    return $type
}

proc check_user {} {
    global user_is_root

    set result [ local_exec "whoami" "" "" 100 ]

    if {[regexp "root" $result] == 1} {
	verbose "Running as root"
	set user_is_root 1
    } else {
	verbose "Not running as root"
	set user_is_root 0
    }
}