1#!/bin/bash
2#
3# CPU helpers
4
5# protect against multiple inclusion
6if [ $FILE_CPU ]; then
7	return 0
8else
9	FILE_CPU=DONE
10fi
11
12source cpufreq.sh
13
14for_each_cpu()
15{
16	cpus=$(ls $CPUROOT | grep "cpu[0-9].*")
17	for cpu in $cpus; do
18		$@ $cpu
19	done
20}
21
22for_each_non_boot_cpu()
23{
24	cpus=$(ls $CPUROOT | grep "cpu[1-9].*")
25	for cpu in $cpus; do
26		$@ $cpu
27	done
28}
29
30#$1: cpu
31offline_cpu()
32{
33	printf "Offline $1\n"
34	echo 0 > $CPUROOT/$1/online
35}
36
37#$1: cpu
38online_cpu()
39{
40	printf "Online $1\n"
41	echo 1 > $CPUROOT/$1/online
42}
43
44#$1: cpu
45reboot_cpu()
46{
47	offline_cpu $1
48	online_cpu $1
49}
50
51# Reboot CPUs
52# param: number of times we want to run the loop
53reboot_cpus()
54{
55	printf "** Test: Running ${FUNCNAME[0]} for $1 loops **\n\n"
56
57	for i in `seq 1 $1`; do
58		for_each_non_boot_cpu offline_cpu
59		for_each_non_boot_cpu online_cpu
60		printf "\n"
61	done
62
63	printf "\n%s\n\n" "------------------------------------------------"
64}
65
66# Prints warning for all CPUs with missing cpufreq directory
67print_unmanaged_cpus()
68{
69	for_each_cpu cpu_should_have_cpufreq_directory
70}
71
72# Counts CPUs with cpufreq directories
73count_cpufreq_managed_cpus()
74{
75	count=0;
76
77	for cpu in `ls $CPUROOT | grep "cpu[0-9].*"`; do
78		if [ -d $CPUROOT/$cpu/cpufreq ]; then
79			let count=count+1;
80		fi
81	done
82
83	echo $count;
84}
85