1#!/bin/sh 2# SPDX-License-Identifier: GPL-2.0 3# description: BTF event with typecast and percpu access 4# requires: dynamic_events "this_cpu_read(<fetcharg>)":README "[(structname[,field])]<argname>[->field[->field|.field...]]":README 5 6# Check if the sample module is loaded 7if ! lsmod | grep -q trace_events_sample; then 8 modprobe trace-events-sample || exit_unresolved 9fi 10 11echo 0 > events/enable 12echo > dynamic_events 13 14# The sample_timer_cb(struct timer_list *t) is called. 15# We want to check (STRUCT,FIELD)VAR typecast and this_cpu_read() access. 16# (foo_timer_data,timer)t converts t to struct foo_timer_data * using container_of. 17# data->counter is a per-cpu pointer to int. 18# this_cpu_read(data->counter) should give the value of the counter. 19 20echo 'f:mysample/myevent sample_timer_cb name=(foo_timer_data,timer)t->name:string count=this_cpu_read((foo_timer_data,timer)t->counter)' >> dynamic_events 21 22echo 1 > events/mysample/myevent/enable 23echo 1 > events/sample-trace/foo_timer_fn/enable 24 25sleep 2 26 27echo 0 > events/mysample/myevent/enable 28echo 0 > events/sample-trace/foo_timer_fn/enable 29 30# Compare the values. 31MATCH=0 32while read line; do 33 if echo $line | grep -q "foo_timer_fn:"; then 34 NAME=`echo $line | sed 's/.*name=\([^ ]*\) .*/\1/'` 35 COUNT=`echo $line | sed 's/.*count=\([^ ]*\).*/\1/'` 36 if grep -q "myevent:.*name=\"${NAME}\" count=$COUNT" trace; then 37 MATCH=$((MATCH+1)) 38 fi 39 fi 40done < trace 41 42if [ $MATCH -eq 0 ]; then 43 echo "No matching events found" 44 exit_fail 45fi 46 47# Clean up 48echo 0 > events/mysample/myevent/enable 49echo 0 > events/sample-trace/foo_timer_fn/enable 50echo > dynamic_events 51clear_trace 52