On Thu, Dec 24, 2009 at 11:45:42PM +0530, Poornima Nayak wrote:
> Patch to learn topology of system through sysfs.
>
> Signed-off-by: poornima nayak <[email protected]>
>
> diff -uprN
> ltp-intermediate-20091209.orig/testcases/kernel/power_management/pm_include.sh
>
> ltp-intermediate-20091209.fixes/testcases/kernel/power_management/pm_include.sh
> ---
> ltp-intermediate-20091209.orig/testcases/kernel/power_management/pm_include.sh
> 2009-12-09 13:18:25.000000000 +0530
> +++
> ltp-intermediate-20091209.fixes/testcases/kernel/power_management/pm_include.sh
> 2009-12-24 23:17:37.798995821 +0530
> @@ -69,9 +69,24 @@ get_supporting_govr() {
> }
>
> is_hyper_threaded() {
> - siblings=`cat /proc/cpuinfo | grep siblings | uniq | cut -f2 -d':'`
> - cpu_cores=`cat /proc/cpuinfo | grep "cpu cores" | uniq | cut -f2 -d':'`
> - [ $siblings -gt $cpu_cores ]; return $?
> + entries=`cat /sys/devices/system/cpu/cpu0/topology/thread_siblings`
> + count=`echo $entries | awk -F"," '{ print NF }'`
> + cpucount=0
> + for ((i=1;i<=$count;i++))
> + do
> +
> + cpumask=`echo $entries | awk -v x=$i 'BEGIN{FS=","} {print $x}'`
> + while [ $cpumask -gt 0 ]
> + do
> + ((cpucount=cpucount+1))
> + ((cpumask=$cpumask>>1))
> + done
> + done
> + if [ $cpucount -gt 1 ]; then
> + return 0
> + else
> + return 1
> + fi
> }
>
> check_input() {
> @@ -110,26 +125,38 @@ is_multi_socket() {
> [ $no_of_sockets -gt 1 ] ; return $?
> }
>
> +get_core_sibling_count() {
> + entries=`cat /sys/devices/system/cpu/cpu0/topology/core_siblings`
> + count=`echo $entries | awk -F"," '{ print NF }'`
> + cpucount=0
> + for ((i=1;i<=$count;i++))
> + do
> + cpumask=`echo $entries | awk -v x=$i 'BEGIN{FS=","} {print $x}'`
> + while [ $cpumask -gt 0 ]
> + do
> + ((cpucount=cpucount+1))
> + ((cpumask=$cpumask>>1))
> + done
> + done
> + echo $cpucount
> +}
I find code duplication here.
Cant we have,
get_entity_count() {
ENTITY=$1
entries=`cat /sys/devices/system/cpu/cpu0/topology/$ENTITY_SIBLINGS`
.
.
.
.
.
echo $cpucount
}
get_core_siblings_count() {
get_entity_count "core"
}
get_thread_siblings_count() {
get_entity_count "thread"
}
is_hyperthreaded() {
nr_threads = get_thread_siblings_count()
if [$nr_threads -gt 1 ]; then
return 0
else
return 1
fi
}
and so on ?
}
> +
> is_multi_core() {
> - siblings=`cat /proc/cpuinfo | grep siblings | uniq | cut -f2 -d':'`
> - cpu_cores=`cat /proc/cpuinfo | grep "cpu cores" | uniq | cut -f2 -d':'`
> - if [ $siblings -eq $cpu_cores ]; then
> - [ $cpu_cores -gt 1 ]; return $?
> - else
> - : $(( num_of_cpus = siblings / cpu_cores ))
> - [ $num_of_cpus -gt 1 ]; return $?
> + sibling_cnt=$(get_core_sibling_count)
> + if [ $sibling_cnt -gt 1 ]; then
> + return 0
> + else
> + return 1
> fi
> }
>
> is_dual_core() {
> - siblings=`cat /proc/cpuinfo | grep siblings | uniq | cut -f2 -d':'`
> - cpu_cores=`cat /proc/cpuinfo | grep "cpu cores" | uniq | cut -f2
> -d':'`
> - if [ $siblings -eq $cpu_cores ]; then
> - [ $cpu_cores -eq 2 ]; return $?
> - else
> - : $(( num_of_cpus = siblings / cpu_cores ))
> - [ $num_of_cpus -eq 2 ]; return $?
> - fi
> + sibling_cnt=$(get_core_sibling_count)
> + if [ $sibling_cnt -eq 2 ]; then
> + return 0
> + else
> + return 1
> + fi
> }
>
> get_kernel_version() {
--
Thanks and Regards
gautham
------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list