1*45cd84bdSIan Rogers#!/bin/bash 2*45cd84bdSIan Rogers# DRM PMU 3*45cd84bdSIan Rogers# SPDX-License-Identifier: GPL-2.0 4*45cd84bdSIan Rogers 5*45cd84bdSIan Rogersset -e 6*45cd84bdSIan Rogers 7*45cd84bdSIan Rogersoutput=$(mktemp /tmp/perf.drm_pmu.XXXXXX.txt) 8*45cd84bdSIan Rogers 9*45cd84bdSIan Rogerscleanup() { 10*45cd84bdSIan Rogers rm -f "${output}" 11*45cd84bdSIan Rogers 12*45cd84bdSIan Rogers trap - EXIT TERM INT 13*45cd84bdSIan Rogers} 14*45cd84bdSIan Rogers 15*45cd84bdSIan Rogerstrap_cleanup() { 16*45cd84bdSIan Rogers echo "Unexpected signal in ${FUNCNAME[1]}" 17*45cd84bdSIan Rogers cleanup 18*45cd84bdSIan Rogers exit 1 19*45cd84bdSIan Rogers} 20*45cd84bdSIan Rogerstrap trap_cleanup EXIT TERM INT 21*45cd84bdSIan Rogers 22*45cd84bdSIan Rogers# Array to store file descriptors and device names 23*45cd84bdSIan Rogersdeclare -A device_fds 24*45cd84bdSIan Rogers 25*45cd84bdSIan Rogers# Open all devices and store file descriptors. Opening the device will create a 26*45cd84bdSIan Rogers# /proc/$$/fdinfo file containing the DRM statistics. 27*45cd84bdSIan Rogersfd_count=3 # Start with file descriptor 3 28*45cd84bdSIan Rogersfor device in /dev/dri/* 29*45cd84bdSIan Rogersdo 30*45cd84bdSIan Rogers if [[ ! -c "$device" ]] 31*45cd84bdSIan Rogers then 32*45cd84bdSIan Rogers continue 33*45cd84bdSIan Rogers fi 34*45cd84bdSIan Rogers major=$(stat -c "%Hr" "$device") 35*45cd84bdSIan Rogers if [[ "$major" != 226 ]] 36*45cd84bdSIan Rogers then 37*45cd84bdSIan Rogers continue 38*45cd84bdSIan Rogers fi 39*45cd84bdSIan Rogers echo "Opening $device" 40*45cd84bdSIan Rogers eval "exec $fd_count<\"$device\"" 41*45cd84bdSIan Rogers echo "fdinfo for: $device (FD: $fd_count)" 42*45cd84bdSIan Rogers cat "/proc/$$/fdinfo/$fd_count" 43*45cd84bdSIan Rogers echo 44*45cd84bdSIan Rogers device_fds["$device"]="$fd_count" 45*45cd84bdSIan Rogers fd_count=$((fd_count + 1)) 46*45cd84bdSIan Rogersdone 47*45cd84bdSIan Rogers 48*45cd84bdSIan Rogersif [[ ${#device_fds[@]} -eq 0 ]] 49*45cd84bdSIan Rogersthen 50*45cd84bdSIan Rogers echo "No DRM devices found [Skip]" 51*45cd84bdSIan Rogers cleanup 52*45cd84bdSIan Rogers exit 2 53*45cd84bdSIan Rogersfi 54*45cd84bdSIan Rogers 55*45cd84bdSIan Rogers# For each DRM event 56*45cd84bdSIan Rogerserr=0 57*45cd84bdSIan Rogersfor p in $(perf list --raw-dump drm-) 58*45cd84bdSIan Rogersdo 59*45cd84bdSIan Rogers echo -n "Testing perf stat of $p. " 60*45cd84bdSIan Rogers perf stat -e "$p" --pid=$$ true > "$output" 2>&1 61*45cd84bdSIan Rogers if ! grep -q "$p" "$output" 62*45cd84bdSIan Rogers then 63*45cd84bdSIan Rogers echo "Missing DRM event in: [Failed]" 64*45cd84bdSIan Rogers cat "$output" 65*45cd84bdSIan Rogers err=1 66*45cd84bdSIan Rogers else 67*45cd84bdSIan Rogers echo "[OK]" 68*45cd84bdSIan Rogers fi 69*45cd84bdSIan Rogersdone 70*45cd84bdSIan Rogers 71*45cd84bdSIan Rogers# Close all file descriptors 72*45cd84bdSIan Rogersfor fd in "${device_fds[@]}"; do 73*45cd84bdSIan Rogers eval "exec $fd<&-" 74*45cd84bdSIan Rogersdone 75*45cd84bdSIan Rogers 76*45cd84bdSIan Rogers# Finished 77*45cd84bdSIan Rogerscleanup 78*45cd84bdSIan Rogersexit $err 79