@@ -130,6 +130,171 @@ uncore_events_test() {
130130 done
131131}
132132
133+ arch_pebs_cpuid_test () {
134+ # #CPUID.0x23.0.EAX[5] == 1
135+ do_cmd " cpuid_check 23 0 0 0 a 5"
136+
137+ # # For PTL
138+ # # CPUID.0x23.0.EAX[5:4] == 0x3
139+ model=$( < /proc/cpuinfo grep mode | awk ' {print $3}' | awk ' NR==1' )
140+ [[ $model -eq 204 ]] && do_cmd " cpuid_check 23 0 0 0 a 4"
141+ }
142+
143+ reg_group_test (){
144+ reg=$1
145+ perfdata=" pebs.data"
146+ logfile=" temp.txt"
147+ if [ -z " ${cputype} " ]; then
148+ event=" cycles:$level "
149+ else
150+ event=" $cputype /cycles/$level "
151+ fi
152+ test_print_trc " Will test with $reg now!"
153+ perf record -o $perfdata -I$reg -e $event -a sleep 1 2>&1 | tee $logfile
154+ sample_count=$( grep " sample" $logfile | awk ' {print $10}' | tr -cd " 0-9" )
155+ count=$( perf report -D -i $perfdata | grep -v events | grep -c " \. $reg " )
156+ test_print_trc " before sample_count = $sample_count ; count = $count "
157+ sample_count=$(( sample_count))
158+ test_print_trc " after sample_count = $sample_count ; count = $count "
159+ [[ $sample_count -eq 0 ]] && die " samples = 0!"
160+ [[ $sample_count -eq $count ]] || die " samples does not match!"
161+ }
162+
163+ reg_group_test_more_option (){
164+ reg=$1
165+ reg_v=$2
166+ times=$3
167+ perfdata=" pebs.data"
168+ logfile=" temp.txt"
169+ if [ -z " ${cputype} " ]; then
170+ event=" cycles:$level "
171+ else
172+ event=" $cputype /cycles/$level "
173+ fi
174+ test_print_trc " Will test with $reg with $reg_v $times now!"
175+ perf record -o $perfdata -I$reg -e $event -a sleep 1 2>&1 | tee $logfile
176+ sample_count=$( grep " sample" $logfile | awk ' {print $10}' | tr -cd " 0-9" )
177+ count=$( perf report -D -i $perfdata | grep -v events | grep -c " \. $reg_v " )
178+ test_print_trc " before sample_count = $sample_count ; count = $count "
179+ sample_count=` expr $sample_count \* $times `
180+ test_print_trc " after sample_count = $sample_count ; count = $count "
181+ [[ $sample_count -eq 0 ]] && die " samples = 0!"
182+ [[ $sample_count -eq $count ]] || die " samples does not match!"
183+ }
184+
185+ arch_pebs_gp_reg_group_test () {
186+ # #CPUID.0x23.4.EBX.GPR[29] == 1
187+ do_cmd " cpuid_check 23 0 4 0 b 29"
188+ cputype=$1
189+ level=" p"
190+ reg_group_test " AX"
191+ reg_group_test " BX"
192+ reg_group_test " CX"
193+ reg_group_test " DX"
194+ reg_group_test " SI"
195+ reg_group_test " DI"
196+ reg_group_test " BP"
197+ reg_group_test " SP"
198+ reg_group_test " IP"
199+ reg_group_test " FLAGS"
200+ reg_group_test " CS"
201+ reg_group_test " SS"
202+ # reg_group_test "DS"
203+ # reg_group_test "ES"
204+ # reg_group_test "FS"
205+ # reg_group_test "GS"
206+ reg_group_test " R8"
207+ }
208+
209+ arch_pebs_xer_group_test () {
210+ cputype=$1
211+ level=" p"
212+ # reg_group_test_more_option "OPMASK0" "opmask0" 1
213+ reg_group_test_more_option " YMMH0" " YMMH0" 2
214+ # reg_group_test_more_option "ZMMH0" "ZMMLH0" 4
215+ }
216+
217+ arch_pebs_counter_group_test () {
218+ cputype=$1
219+ perfdata=" pebs.data"
220+ logfile=" temp.txt"
221+ perfdata_s=" pebs_s.data"
222+ logfile_s=" temp_s.txt"
223+ mode=$( < /proc/cpuinfo grep mode | awk ' {print $3}' | awk ' NR==1' )
224+ case $mode in
225+ 221)
226+ perf record -o $perfdata_s -e ' {cycles:p,cache-misses,cache-references,topdown-bad-spec,topdown-fe-bound,topdown-retiring}:S' -- sleep 1 2>&1 | tee $logfile_s
227+ perf record -o $perfdata -e ' {cycles,cache-misses,cache-references,topdown-bad-spec,topdown-fe-bound,topdown-retiring}:p' -- sleep 1 2>&1 | tee $logfile
228+ ;;
229+ 1)
230+ # Topdown events don't rely on real counter and they are caculated from perf metrics MSR. Could not sample with P core on DMR.
231+ perf record -o $perfdata_s -e ' {slots,cache-misses,cache-references,branches,branches-misses}:S' -- sleep 1 2>&1 | tee $logfile_s
232+ perf record -o $perfdata -e ' {slots,cache-misses,cache-references,branches,branch-misses}:p' -- sleep 1 2>&1 | tee $logfile
233+ ;;
234+ 204)
235+ event=" {$cputype /cycles/,$cputype /cache-misses/,$cputype /cache-references/,$cputype /topdown-bad-spec/,$cputype /topdown-fe-bound/,$cputype /topdown-retiring/}"
236+ perf record -o $perfdata_s -e " $event :S" -a -- sleep 1 2>&1 | tee $logfile_s
237+ perf record -o $perfdata -e " $event :p" -a -- sleep 1 2>&1 | tee $logfile
238+ ;;
239+ esac
240+ sample_count=$( grep " sample" $logfile_s | awk ' {print $10}' | tr -cd " 0-9" )
241+ [[ $sample_count -eq 0 ]] && die " samples = 0!"
242+ sample_count=$( grep " sample" $logfile | awk ' {print $10}' | tr -cd " 0-9" )
243+ count=$( perf report -D -i $perfdata | grep -c " PERF_RECORD_SAMPLE" )
244+ [[ $sample_count -eq 0 ]] && die " samples = 0!"
245+ [[ $sample_count -eq $count ]] || die " samples does not match!"
246+ }
247+
248+ arch_pebs_counter_group_stress_test () {
249+ cputype=$1
250+ perfdata=" pebs.data"
251+ logfile=" temp.txt"
252+ # because nmi_watchdog will occupy one fix counter, so disable it
253+ echo 0 > /proc/sys/kernel/nmi_watchdog
254+ if [ -z " ${cputype} " ]; then
255+ event=" {branches,branches,branches,branches,branches,branches,branches,branches,cycles,instructions,ref-cycles,topdown-bad-spec,topdown-fe-bound,topdown-retiring"
256+ else
257+ event=" {$cputype /branches/,$cputype /branches/,$cputype /branches/,$cputype /branches/,$cputype /branches/,$cputype /branches/,$cputype /branches/,$cputype /branches/,$cputype /cycles/,$cputype /instructions/,$cputype /ref-cycles/,$cputype /topdown-bad-spec/,$cputype /topdown-fe-bound/,$cputype /topdown-retiring/}"
258+ fi
259+ perf record -o $perfdata -e " $event :p" -a -- sleep 1 2>&1 | tee $logfile
260+ sample_count=$( grep " sample" $logfile | awk ' {print $10}' | tr -cd " 0-9" )
261+ count=$( perf report -D -i $perfdata | grep -c " PERF_RECORD_SAMPLE" )
262+ [[ $sample_count -eq 0 ]] && die " samples = 0!"
263+ [[ $sample_count -eq $count ]] || die " samples does not match!"
264+ }
265+
266+ arch_pebs_gp_counter_test () {
267+ cputype=$1
268+ if [ -z " ${cputype} " ]; then
269+ event=" branches:p"
270+ else
271+ event=" $cputype /branches/p"
272+ fi
273+ perfdata=" pebs.data"
274+ logfile=" temp.txt"
275+ perf record -o $perfdata -e $event -a sleep 1 2>&1 | tee $logfile
276+ sample_count=$( grep " sample" $logfile | awk ' {print $10}' | tr -cd " 0-9" )
277+ count=$( perf report -D -i $perfdata | grep -c " PERF_RECORD_SAMPLE" )
278+ [[ $sample_count -eq 0 ]] && die " samples = 0!"
279+ [[ $sample_count -eq $count ]] || die " samples does not match!"
280+ }
281+
282+ arch_pebs_basic_group_test () {
283+ cputype=$1
284+ if [ -z " ${cputype} " ]; then
285+ event=" cycles:pp"
286+ else
287+ event=" $cputype /cycles/pp"
288+ fi
289+ perfdata=" pebs.data"
290+ logfile=" temp.txt"
291+ perf record -o $perfdata -e $event -a sleep 1 2>&1 | tee $logfile
292+ sample_count=$( grep " sample" $logfile | awk ' {print $10}' | tr -cd " 0-9" )
293+ count=$( perf report -D -i $perfdata | grep -c " PERF_RECORD_SAMPLE" )
294+ [[ $sample_count -eq 0 ]] && die " samples = 0!"
295+ [[ $sample_count -eq $count ]] || die " samples does not match!"
296+ }
297+
133298pmu_test () {
134299 case $TEST_SCENARIO in
135300 fix_counter)
@@ -156,6 +321,27 @@ pmu_test() {
156321 uncore_events)
157322 uncore_events_test
158323 ;;
324+ arch_pebs_cpuid)
325+ arch_pebs_cpuid_test
326+ ;;
327+ arch_pebs_gp_reg_group)
328+ arch_pebs_gp_reg_group_test " $@ "
329+ ;;
330+ arch_pebs_xer_group)
331+ arch_pebs_xer_group_test " $@ "
332+ ;;
333+ arch_pebs_counter_group)
334+ arch_pebs_counter_group_test " $@ "
335+ ;;
336+ arch_pebs_counter_group_stres)
337+ arch_pebs_counter_group_stress_test " $@ "
338+ ;;
339+ arch_pebs_gp_counter)
340+ arch_pebs_gp_counter_test " $@ "
341+ ;;
342+ arch_pebs_basic_group)
343+ arch_pebs_basic_group_test " $@ "
344+ ;;
159345 esac
160346 return 0
161347}
@@ -179,6 +365,6 @@ while getopts :t:H arg; do
179365 esac
180366done
181367
182- pmu_test
368+ pmu_test " $@ "
183369# Call teardown for passing case
184370exec_teardown
0 commit comments