Received: from mail-il1-f202.google.com (mail-il1-f202.google.com [209.85.166.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 0D99F1AED23 for ; Wed, 11 Sep 2024 22:25:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726093512; cv=none; b=WlbpO7Nz5kSKLrD9VXqWIWlSusyd8QoJJRBe/I9L96VZllMW0W+iy1W8JI+lPaWhA+F/rVJAXZmizHECRbmlV/L6EZwLOnV7RxDbFvlIlAPimMV4XVXC7n8YwOd8R2r0Q/88XxPm5AtUvyjNl4MOTdEMZGlAXjOqYnjcSqNg3Sc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726093512; c=relaxed/simple; bh=apDpA6syedftKsJ1hl/KzMx2AnXk35NohmXXBB9ax+I=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=Oe11GDjEjOocf9YZBtiAJYDufTfvwwpYudrwnzD0v0zl1JMMHuu7UWWC8pcUkaDCQk+FfAAwevif0eUePqz5HYAVrq5pzcULON42iVAWockjBtJfRkW4XGdXuH3xQaBHdYEKeQG4bkL96cEA/l+vUAq0HdaTZTzQ/byPLkQ+Has= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--coltonlewis.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=RrFvyle7; arc=none smtp.client-ip=209.85.166.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--coltonlewis.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RrFvyle7" Received: by mail-il1-f202.google.com with SMTP id e9e14a558f8ab-39f53b1932aso6504745ab.3 for ; Wed, 11 Sep 2024 15:25:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726093510; x=1726698310; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=T+nODGyulHWxs0JnvJus4UAc0zy0GDYGIyi7bhZj7WY=; b=RrFvyle7cepJK0fzMSOA+VTeoZgXnbvo6F84CzNTFmd6dgKm1ty+JjfJhOCXeetoHf teIl/Fg1zo1JXFIBKZd6j6sMKLTyUo1T1pfVnfxgNdoL3H9ThCoTlUkJepEWApSSfkiV B+2wJnO24ylot0c8LvRhhoS/fFeNSDq3Kzi9dQFNqn56uEWvl/Cv6EH9R0rGIb+ruoA8 G3qEk4qM0AAKeY3ZOAnXy4t0vhe/Fh/G/ZheU1TOb4uov/QfQwiaz01nXmOQeFtI1aF5 5/1NOIjOQOm/dBhkOlaBcIpViQSQBFIukI4EorMiEUUzcXpuOOV3u1wO/DR8KP2Y+l/X cIUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726093510; x=1726698310; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=T+nODGyulHWxs0JnvJus4UAc0zy0GDYGIyi7bhZj7WY=; b=XULWgJ+6jhblq8VFPSoVTpQO2BTs3jAJhcAqHikjHqK3XWs4RzXvoE4xW0ATp9Vc77 5QtYU8eweyR+9Z2NMiZzClqBrPOYPhjqzooOK15hER35bHZS9ZG28w02XaC/RrihHSl1 hJh3+ZjG1krfymuuXWxu3wgZy0quIlkhLTNVYOV5Hz5MoB/DhX+SnHohCE7yIJqmU0Zt 8jVOrtw+nvzYPXXYwCcK6zdhJmig8wXNdpXSOZDN/sV9/lPc5Fb5UO0KmfLd98Krs4C6 acGBNGUucSt0pIxg0FvKBGr+E43vN8PcxOY0t8jKZizLlfLv0Y8QshK/dk/gvHibElvI sccg== X-Gm-Message-State: AOJu0YzMIkp+ElTh6vaBM1YKp9V6DlDqDm2eBTLkLbMqU61dhBxAsYyo FTYoChHozIZlpPomGZtqFIyK4KX1XjSLLPEMPIUCUjyFr0kaER1rzz9o6HS2oa22BH2XkxuAt/C njWJUrpStmjD2HgqDOyI8hYz1By1nAQP0j7oQuirk30VRADo0ZGfcZzANPXZZKyd2ln4SYToshY SsO0iOztL84Nd/fiYJFvtxdZvJV7lkHTn1t+vaZBVe55TFG5fr76AhRxU= X-Google-Smtp-Source: AGHT+IGXXpOojFFO7Gu+zUTSei0211tStzLtWSxgCQLqddaqaDV88691OqMetcHXtFlM9KtKiGpFHXylg3PWPs5bQA== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:6e02:2181:b0:3a0:80ae:71b6 with SMTP id e9e14a558f8ab-3a084976fe0mr327905ab.6.1726093509599; Wed, 11 Sep 2024 15:25:09 -0700 (PDT) Date: Wed, 11 Sep 2024 22:24:27 +0000 Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog Message-ID: <20240911222433.3415301-1-coltonlewis@google.com> Subject: [PATCH v2 0/5] Correct perf sampling with Guest VMs From: Colton Lewis To: kvm@vger.kernel.org Cc: Oliver Upton , Sean Christopherson , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , Will Deacon , Russell King , Catalin Marinas , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Thomas Gleixner , Borislav Petkov , Dave Hansen , x86@kernel.org, "H . Peter Anvin" , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-s390@vger.kernel.org, Colton Lewis Content-Type: text/plain; charset="UTF-8" v2: * Better explain commit messages * Fix incorrect type in patch 2 * Fix missing argument in call to common_misc_flags() in patch 5 * Rebase to 6.11-rc7 and include base commit in letter v1: https://lore.kernel.org/kvm/20240904204133.1442132-1-coltonlewis@google.com/ This series cleans up perf recording around guest events and improves the accuracy of the resulting perf reports. Perf was incorrectly counting any PMU overflow interrupt that occurred while a VCPU was loaded as a guest event even when the events were not truely guest events. This lead to much less accurate and useful perf recordings. See as an example the below reports of `perf record dirty_log_perf_test -m 2 -v 4` before and after the series on ARM64. Without series: Samples: 15K of event 'instructions', Event count (approx.): 31830580924 Overhead Command Shared Object Symbol 54.54% dirty_log_perf_ dirty_log_perf_test [.] run_test 5.39% dirty_log_perf_ dirty_log_perf_test [.] vcpu_worker 0.89% dirty_log_perf_ [kernel.vmlinux] [k] release_pages 0.70% dirty_log_perf_ [kernel.vmlinux] [k] free_pcppages_bulk 0.62% dirty_log_perf_ dirty_log_perf_test [.] userspace_mem_region_find 0.49% dirty_log_perf_ dirty_log_perf_test [.] sparsebit_is_set 0.46% dirty_log_perf_ dirty_log_perf_test [.] _virt_pg_map 0.46% dirty_log_perf_ dirty_log_perf_test [.] node_add 0.37% dirty_log_perf_ dirty_log_perf_test [.] node_reduce 0.35% dirty_log_perf_ [kernel.vmlinux] [k] free_unref_page_commit 0.33% dirty_log_perf_ [kernel.vmlinux] [k] __kvm_pgtable_walk 0.31% dirty_log_perf_ [kernel.vmlinux] [k] stage2_attr_walker 0.29% dirty_log_perf_ [kernel.vmlinux] [k] unmap_page_range 0.29% dirty_log_perf_ dirty_log_perf_test [.] test_assert 0.26% dirty_log_perf_ [kernel.vmlinux] [k] __mod_memcg_lruvec_state 0.24% dirty_log_perf_ [kernel.vmlinux] [k] kvm_s2_put_page With series: Samples: 15K of event 'instructions', Event count (approx.): 31830580924 Samples: 15K of event 'instructions', Event count (approx.): 30898031385 Overhead Command Shared Object Symbol 54.05% dirty_log_perf_ dirty_log_perf_test [.] run_test 5.48% dirty_log_perf_ [kernel.kallsyms] [k] kvm_arch_vcpu_ioctl_run 4.70% dirty_log_perf_ dirty_log_perf_test [.] vcpu_worker 3.11% dirty_log_perf_ [kernel.kallsyms] [k] kvm_handle_guest_abort 2.24% dirty_log_perf_ [kernel.kallsyms] [k] up_read 1.98% dirty_log_perf_ [kernel.kallsyms] [k] __kvm_tlb_flush_vmid_ipa_nsh 1.97% dirty_log_perf_ [kernel.kallsyms] [k] __pi_clear_page 1.30% dirty_log_perf_ [kernel.kallsyms] [k] down_read 1.13% dirty_log_perf_ [kernel.kallsyms] [k] release_pages 1.12% dirty_log_perf_ [kernel.kallsyms] [k] __kvm_pgtable_walk 1.08% dirty_log_perf_ [kernel.kallsyms] [k] folio_batch_move_lru 1.06% dirty_log_perf_ [kernel.kallsyms] [k] __srcu_read_lock 1.03% dirty_log_perf_ [kernel.kallsyms] [k] get_page_from_freelist 1.01% dirty_log_perf_ [kernel.kallsyms] [k] __pte_offset_map_lock 0.82% dirty_log_perf_ [kernel.kallsyms] [k] handle_mm_fault 0.74% dirty_log_perf_ [kernel.kallsyms] [k] mas_state_walk Colton Lewis (5): arm: perf: Drop unused functions perf: Hoist perf_instruction_pointer() and perf_misc_flags() powerpc: perf: Use perf_arch_instruction_pointer() x86: perf: Refactor misc flag assignments perf: Correct perf sampling with guest VMs arch/arm/include/asm/perf_event.h | 7 --- arch/arm/kernel/perf_callchain.c | 17 ------- arch/arm64/include/asm/perf_event.h | 4 -- arch/arm64/kernel/perf_callchain.c | 28 ------------ arch/powerpc/include/asm/perf_event_server.h | 6 +-- arch/powerpc/perf/callchain.c | 2 +- arch/powerpc/perf/callchain_32.c | 2 +- arch/powerpc/perf/callchain_64.c | 2 +- arch/powerpc/perf/core-book3s.c | 4 +- arch/s390/include/asm/perf_event.h | 6 +-- arch/s390/kernel/perf_event.c | 4 +- arch/x86/events/core.c | 48 ++++++++++++-------- arch/x86/include/asm/perf_event.h | 12 +++-- include/linux/perf_event.h | 26 +++++++++-- kernel/events/core.c | 27 ++++++++++- 15 files changed, 96 insertions(+), 99 deletions(-) base-commit: da3ea35007d0af457a0afc87e84fddaebc4e0b63 -- 2.46.0.598.g6f2099f65c-goog