From nobody Tue Dec 2 01:36:32 2025 Received: from mail-pg1-f202.google.com (mail-pg1-f202.google.com [209.85.215.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D07DE2FD7A3 for ; Sat, 22 Nov 2025 08:20:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763799610; cv=none; b=Vc+c8lmHfugdGe48LqdaJvEMBhr72hlf+qaof1CFsQpJNdAXhobx6IPkjxBamv0oxwUfQs8laSWjZrUS5C9fGAjWClYiAU4+kndpxMKde4oWRZgaurAFMK2Y9lfM5UTvC9gYoj7aJVVDce0lN+RxtEsB8OpToOzf5V5GgRQh4Q4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763799610; c=relaxed/simple; bh=77y7tXutito3nnzAoc+ycFKKxLdAvlLV3iqcipeD6VM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Content-Type; b=B84FRfXJ/g5r9csyQRxVIplCIDjN67mPwlpmRKx40c8aaSpbzq06s3gGc2UFQcOcH2TcqESElM5W2I74N/uS+PQl3sEKKhqmExZbU4U3+QXB43qvwpymjpgUO+6K1FBD9gbxU428I/Ym3gErEkoxENFGuU4C6soGTamv5jCr7U0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=FO7VsXYc; arc=none smtp.client-ip=209.85.215.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FO7VsXYc" Received: by mail-pg1-f202.google.com with SMTP id 41be03b00d2f7-b993eb2701bso2754151a12.0 for ; Sat, 22 Nov 2025 00:20:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1763799608; x=1764404408; darn=vger.kernel.org; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=I1FSqCMeHsL++g3NwVXFiLoHBKehFUPc0C8bNPag8O0=; b=FO7VsXYcDBug4auNy2umqJ9iF+h4/tfKAIz/VZ8X1/52OFBovZ523kvPWW1UNXtG92 Q5/oj2dzi6yHTIf+ZZ9Sf96foP2vPKVw3XEF7JgCZUzCQF8NY42SHR3ERtWiV2Lz7834 x6B5g3Z5/f+MhDlXSvCxEg2FEHjdbo6CCoD3DvEpOgqGMOuivHfLC4IGjs0eIsl30rgS OcoZemHX97tGQSPhMpVvsm+Vwkh74sad8qwG6aFdFVXKfyeVkqRh68u/NVGJ5YfuZmy3 I396xoEEdgAFpZFOseiQW4bva4z5gK8VjcLsiy1OS607FJW3uT4IYi4RdHzUMpMgZcNO 8+Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763799608; x=1764404408; h=to:from:subject:message-id:references:mime-version:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=I1FSqCMeHsL++g3NwVXFiLoHBKehFUPc0C8bNPag8O0=; b=A2Dl+MekWPBrmF+XgOfi7D5aWqXmEx339WCjQoMTERj3qdvcATUjlVsavcDyBpaD7r Kvqeok9rwQuxrgw2hLFV1Yzdb/rdn5K5gBIZXFXXCYbTLrJGWXJIA5HmQYAw16TRTfz5 A02Y6hWWXj/U+fGweeL4TPxWaG1Y/kHT3b6c6cGiQep9sWDJIA5QGMWJiKXKgvPYw8WL bcLckWs/Oqy6dVPd+K7yu0iEt9LQqdHWnAxZrxGc0XEUQYLJv1fPf/wBpyCpRlQjj6qh /sJSZWEv9FsGVYPsk47Efmk3E6acg8wTtWnucY6A2UwrnKR/Nq2E+QyYu6O5mNo4VlQt xOFA== X-Forwarded-Encrypted: i=1; AJvYcCUZc5yqc+hlDcrfg+mhR9HxSQLEoXtAm7qNGISG+xPQiF7IrZy32AO3x/8VSfpV8XuqkEeZCuRpEj7DYg4=@vger.kernel.org X-Gm-Message-State: AOJu0YwxaK3AZoC89mVI8xMvkXX1/H/cXYQ3LlBsVEDqQwBUESN8/fY3 q3FXhl0OgSqh0/G4NbYi6byC05gFabwLNjHk0QISWrIK2i/FbXqrBV4UkanKuxKmaHrJe7YyTHZ yrVrCLvUp1A== X-Google-Smtp-Source: AGHT+IGflzDr78v/sru9qBkWDUDP31dQt3lOiXUHw56VDdhoXsu553xPZE3o+BNCwrkxSJyKbDjQLLqsDtJ2 X-Received: from dycog5.prod.google.com ([2002:a05:7301:9a85:b0:2a4:791c:9e95]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:7d0a:b0:2a4:3592:c5f7 with SMTP id 5a478bee46e88-2a71907139amr1640322eec.8.1763799608188; Sat, 22 Nov 2025 00:20:08 -0800 (PST) Date: Sat, 22 Nov 2025 00:19:29 -0800 In-Reply-To: <20251122081929.7588-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251122081929.7588-1-irogers@google.com> X-Mailer: git-send-email 2.52.0.rc2.455.g230fcf2819-goog Message-ID: <20251122081929.7588-18-irogers@google.com> Subject: [PATCH v1 17/17] perf test kvm: Add some basic perf kvm test coverage From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , James Clark , Collin Funk , Dmitry Vyukov , Andi Kleen , Thomas Falcon , Leo Yan , Yicong Yang , Greg Kroah-Hartman , "Masami Hiramatsu (Google)" , Stephen Brennan , Haibo Xu , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Setup qemu with KVM then run kvm stat and some host recording/reporting/build-id tests. Signed-off-by: Ian Rogers --- tools/perf/tests/shell/kvm.sh | 154 ++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100755 tools/perf/tests/shell/kvm.sh diff --git a/tools/perf/tests/shell/kvm.sh b/tools/perf/tests/shell/kvm.sh new file mode 100755 index 000000000000..2fafde1a29cc --- /dev/null +++ b/tools/perf/tests/shell/kvm.sh @@ -0,0 +1,154 @@ +#!/bin/bash +# perf kvm tests +# SPDX-License-Identifier: GPL-2.0 + +set -e + +err=3D0 +perfdata=3D$(mktemp /tmp/__perf_kvm_test.perf.data.XXXXX) +qemu_pid_file=3D$(mktemp /tmp/__perf_kvm_test.qemu.pid.XXXXX) + +cleanup() { + rm -f "${perfdata}" + if [ -f "${qemu_pid_file}" ]; then + if [ -s "${qemu_pid_file}" ]; then + qemu_pid=3D$(cat "${qemu_pid_file}") + if [ -n "${qemu_pid}" ]; then + kill "${qemu_pid}" 2>/dev/null || true + fi + fi + rm -f "${qemu_pid_file}" + fi + trap - EXIT TERM INT +} + +trap_cleanup() { + echo "Unexpected signal in ${FUNCNAME[1]}" + cleanup + exit 1 +} +trap trap_cleanup EXIT TERM INT + +skip() { + echo "Skip: $1" + cleanup + exit 2 +} + +test_kvm_stat() { + echo "Testing perf kvm stat" + + echo "Recording kvm events for pid ${qemu_pid}..." + if ! perf kvm stat record -p "${qemu_pid}" -o "${perfdata}" sleep 1; then + echo "Failed to record kvm events" + err=3D1 + return + fi + + echo "Reporting kvm events..." + if ! perf kvm -i "${perfdata}" stat report 2>&1 | grep -q "VM-EXIT"; then + echo "Failed to find VM-EXIT in report" + perf kvm -i "${perfdata}" stat report 2>&1 + err=3D1 + return + fi + + echo "perf kvm stat test [Success]" +} + +test_kvm_record_report() { + echo "Testing perf kvm record/report" + + echo "Recording kvm profile for pid ${qemu_pid}..." + # Use --host to avoid needing guest symbols/mounts for this simple test + # We just want to verify the command runs and produces data + # We run in background and kill it because 'perf kvm record' appends opti= ons + # after the command, which breaks 'sleep' (e.g. it gets '-e cycles'). + perf kvm --host record -p "${qemu_pid}" -o "${perfdata}" & + rec_pid=3D$! + sleep 1 + kill -INT "${rec_pid}" + wait "${rec_pid}" || true + + echo "Reporting kvm profile..." + # Check for some standard output from report + if ! perf kvm -i "${perfdata}" report --stdio 2>&1 | grep -q "Event count= "; then + echo "Failed to report kvm profile" + perf kvm -i "${perfdata}" report --stdio 2>&1 + err=3D1 + return + fi + + echo "perf kvm record/report test [Success]" +} + +test_kvm_buildid_list() { + echo "Testing perf kvm buildid-list" + + # We reuse the perf.data from the previous record test + if ! perf kvm --host -i "${perfdata}" buildid-list 2>&1 | grep -q "."; th= en + echo "Failed to list buildids" + perf kvm --host -i "${perfdata}" buildid-list 2>&1 + err=3D1 + return + fi + + echo "perf kvm buildid-list test [Success]" +} + +setup_qemu() { + # Find qemu + if [ "$(uname -m)" =3D "x86_64" ]; then + qemu=3D"qemu-system-x86_64" + elif [ "$(uname -m)" =3D "aarch64" ]; then + qemu=3D"qemu-system-aarch64" + elif [ "$(uname -m)" =3D "s390x" ]; then + qemu=3D"qemu-system-s390x" + elif [ "$(uname -m)" =3D "ppc64le" ]; then + qemu=3D"qemu-system-ppc64" + else + qemu=3D"qemu-system-$(uname -m)" + fi + + if ! which -s "$qemu"; then + skip "$qemu not found" + fi + + if [ ! -r /dev/kvm ] || [ ! -w /dev/kvm ]; then + skip "/dev/kvm not accessible" + fi + + if ! perf kvm stat record -a sleep 0.01 >/dev/null 2>&1; then + skip "No permission to record kvm events" + fi + + echo "Starting $qemu..." + # Start qemu in background, detached, with pidfile + # We use -display none -daemonize and a monitor to keep it alive/controll= able if needed + # We don't need a real kernel, just KVM active. + if ! $qemu -enable-kvm -display none -daemonize -pidfile "${qemu_pid_file= }" -monitor none; then + echo "Failed to start qemu" + err=3D1 + return + fi + + # Wait a bit for qemu to start + sleep 1 + qemu_pid=3D$(cat "${qemu_pid_file}") + + if ! kill -0 "${qemu_pid}" 2>/dev/null; then + echo "Qemu process failed to stay alive" + err=3D1 + return + fi +} + +setup_qemu +if [ $err -eq 0 ]; then + test_kvm_stat + test_kvm_record_report + test_kvm_buildid_list +fi + +cleanup +exit $err --=20 2.52.0.rc2.455.g230fcf2819-goog