From patchwork Thu Sep 12 20:51:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colton Lewis X-Patchwork-Id: 13802647 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 E2A1D1C0DD9 for ; Thu, 12 Sep 2024 20:51:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726174299; cv=none; b=tqSQJxh37jqy+5jHS0bVCtUPNSGZRsxgpyf5Er8oSWSYIVqXuQNHH2OuC64QtYy+klwJO6myi/CYrkWezvMYOYbDQIJaOiRJyv3OggghVAVem0qgGUOtWaXq0y0U0S9KIcWRLAslDJEGhDoa5Ap0tCp+JUbkmPrZ3Vp/3QGDVS4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726174299; c=relaxed/simple; bh=MNxtXrr9QPAqRF21OcqTy6lGILMNbXhqSs9zqcWQea0=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=Ml5IdAdbvejMVe/cUvTybKKR3jP5KBEdZ1+8sV2WDwdsyi5SRC68ToOFfhJRHjttJjSQv/6dAwkDnqaPVw8ch6kHhBQHVtD39R/k/+alybXV2IH4kZxzfQaQSTAyfnuTZ3RwihTmTeLtZBRmJsKQTiBlPZ9fLL0npk0NF7+0ugM= 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=D4QAcNin; arc=none smtp.client-ip=209.85.219.201 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="D4QAcNin" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-e1a8de19f7aso2720814276.3 for ; Thu, 12 Sep 2024 13:51:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1726174297; x=1726779097; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=h7GxOQtGez9zo05dGUGsUVNGDqEVne28eAH8BDc6VWA=; b=D4QAcNin6wW0U3HUwqnYDPcAHQH4ljmAgI3l3Ur1mhEN5+st4viWhczRkOLNKpXWgc hIAOXh5sut6tok0WJqSUMz8q3MjGjqQA3lMTtHaANXMq110VjDPflnlKpqVSXkAlZeqH YYVkJTyGIQlMKcmwiy2s0vbs/fq1/hXpgaSKF/h32bJ9Bk3EajQxursxZEWFPtHyr26k rM94nFH4bLKHd5yK0LGjiaf0R5QYl/stZcyO9j9XMF73tkIZ/R60uLEQzoId1AkH+GLb pM4zS0a+KOn0K3A7m3PU1XA+bneM7PYiRGR/zSH7XG4eR+2+2oFk/Iw0C5vRgtUW4Ro4 247A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726174297; x=1726779097; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=h7GxOQtGez9zo05dGUGsUVNGDqEVne28eAH8BDc6VWA=; b=M/cORgdUmR25jaxUPBQ2J6r5wdFmgqIcMP0BrBVsEtbq5ZQDd9fKh9JOPzeLBoIdtx zgPcjP+T2dJKVvWXDJgut+4bR2nQ9bjfsDdWZ8wfcHsQ6NmGtF5g+I9jruL5uR1kJ7PY Cft51XULte8sQloWaHp+lsE2zBu7+A7ux428JGmlxlLWmHvT+Urp5gBN7fW6B+wFsp0v UOZyR3iPvGwPpjvBanyQjnDJ/6NI+if7FPA+Q2QHFT1AneUzH7QXozI1O4ANxh4S5lVO lhdWhnXTZq6zSnkv8JnkNShqNuh9ghooz2GAHKi5HU4tgjHawohY8iX/1FDYqjZTYCql riCA== X-Gm-Message-State: AOJu0YzAp/ngNa4Bgqkda08TEv/lrF7ndol8kSRM5kyqjF9muVqTB2SS s0+SA7dGPwcAY8odHT07UFKYuWb9AlmXRNgptDZa3P8swN741DcaPOhaHHSjM7RF3/i7DblxwPr UL0Bh8b0ltMYiHWUb7p9xu65TgYTQtLwSQf+VrA09MIBDY2csSM/y6DHwzkqRLV9CiyMdjYkvXl IJOI9KAwbeGc6kAL9hqOKKkYlT1VKIBZjTwztlEh2+FNNsX++zwvoDca0= X-Google-Smtp-Source: AGHT+IEKK4aKpKiP70M1q7RoK97ftYvX/6/8VPxfOowbkLjsgUfLaXZWPQb4Cz0o8Wq45udLHTwqEBExFDGaaK+o3A== X-Received: from coltonlewis-kvm.c.googlers.com ([fda3:e722:ac3:cc00:11b:3898:ac11:fa18]) (user=coltonlewis job=sendgmr) by 2002:a05:6902:1781:b0:e1a:6eac:3d0f with SMTP id 3f1490d57ef6-e1d9dc419efmr6874276.8.1726174295745; Thu, 12 Sep 2024 13:51:35 -0700 (PDT) Date: Thu, 12 Sep 2024 20:51:28 +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.662.g92d0881bb0-goog Message-ID: <20240912205133.4171576-1-coltonlewis@google.com> Subject: [PATCH v3 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 v3: * Clarify final commit message further * Remove an unused variable in perf_arch_misc_flags() v2: https://lore.kernel.org/kvm/20240911222433.3415301-1-coltonlewis@google.com/ 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 | 47 +++++++++++--------- arch/x86/include/asm/perf_event.h | 12 ++--- include/linux/perf_event.h | 26 +++++++++-- kernel/events/core.c | 27 ++++++++++- 15 files changed, 95 insertions(+), 99 deletions(-) base-commit: da3ea35007d0af457a0afc87e84fddaebc4e0b63 Reviewed-by: Oliver Upton --- 2.46.0.662.g92d0881bb0-goog