From patchwork Mon Jul 11 09:31:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913241 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E07AC433EF for ; Mon, 11 Jul 2022 10:10:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234467AbiGKKK0 (ORCPT ); Mon, 11 Jul 2022 06:10:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231342AbiGKKKB (ORCPT ); Mon, 11 Jul 2022 06:10:01 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7A8FBFAE8; Mon, 11 Jul 2022 02:32:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657531964; x=1689067964; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Y7AN7Ia9WCu3XxURhv+nR2BWwjg+1aZxtMTR6oL3b4M=; b=maO6LBJ4cZ55Pv7V1S9tubvuRpWaa2maztrFq4ivpKPVVCJuhWU2kV9c 3DDPr7dhcfO2mrZYRyTg6qoQSR1Xn798nKxBnwOzOtHwoC78KO67cRnt3 h/vqzMelpYWUz7zCkztbLEd1xJuAYCubEyELfSlh1H4nZJLXrNI/S4SA1 zqcGA5WmlUBz3aeae5OhIR0S8y4i/SQ4q6gd6eUBIw/lUFwvh9bpTP3Fr wua0/uTdWbES1lwUVWh+RazYU6CistngxYJQybUfzFIPoCDOureqPdGI2 uUbA1Ni8GoDIl2PYceekY7xW0Hi/Iw3izELYS8CWnwpZf6Tcex0QuL/qj A==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371512" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371512" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:32:44 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652386995" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:32:42 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 01/35] perf tools: Fix dso_id inode generation comparison Date: Mon, 11 Jul 2022 12:31:44 +0300 Message-Id: <20220711093218.10967-2-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Synthesized MMAP events have zero ino_generation, so do not compare zero values. Fixes: 0e3149f86b99 ("perf dso: Move dso_id from 'struct map' to 'struct dso'") Signed-off-by: Adrian Hunter --- tools/perf/util/dsos.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/dsos.c b/tools/perf/util/dsos.c index b97366f77bbf..839a1f384733 100644 --- a/tools/perf/util/dsos.c +++ b/tools/perf/util/dsos.c @@ -23,8 +23,14 @@ static int __dso_id__cmp(struct dso_id *a, struct dso_id *b) if (a->ino > b->ino) return -1; if (a->ino < b->ino) return 1; - if (a->ino_generation > b->ino_generation) return -1; - if (a->ino_generation < b->ino_generation) return 1; + /* + * Synthesized MMAP events have zero ino_generation, so do not compare + * zero values. + */ + if (a->ino_generation && b->ino_generation) { + if (a->ino_generation > b->ino_generation) return -1; + if (a->ino_generation < b->ino_generation) return 1; + } return 0; } From patchwork Mon Jul 11 09:31:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913242 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A70BC43334 for ; Mon, 11 Jul 2022 10:10:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231375AbiGKKKd (ORCPT ); Mon, 11 Jul 2022 06:10:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231182AbiGKKKM (ORCPT ); Mon, 11 Jul 2022 06:10:12 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64D3FBFADE; Mon, 11 Jul 2022 02:32:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657531967; x=1689067967; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ibfm1AW6+ERdLJFJaC+jfaM1CrmGAD8hN89rymrkIZ8=; b=LjloBicYaYsyq1cu8X9xMyvxijV4Cc+51a2RcdGF2rQESWjqEPYffoPN wuFiE6sO/eowfSYPjEMfxNHO7wasE30lW1pD+eYK0c6yCJQTO+GLhmrqN OVfUQmgR3ii5+mp6hRqFk1B64znkjo8cDWNvyt/ipwBeBJ1n4B9q/q92e t17bvZOPL1xcwesRtoeRnliYk/PD7BqBuacDzQ6GPbkHBwCbnEWoYm+uC alBotV+y4SPnhOW0fEcripDbahuAH2NBqQ7bBlKIMlr5A8s+oG4aR/WFA hvfPs+RYNCEI4ntn8ka7I5nFvG3wnotcfR1af/xVUQXJkciy4O92hBEO5 A==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371514" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371514" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:32:46 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387004" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:32:44 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 02/35] perf tools: Export dsos__for_each_with_build_id() Date: Mon, 11 Jul 2022 12:31:45 +0300 Message-Id: <20220711093218.10967-3-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Export dsos__for_each_with_build_id() so it can be used elsewhere. Signed-off-by: Adrian Hunter Acked-by: Ian Rogers --- tools/perf/util/build-id.c | 6 ------ tools/perf/util/dso.h | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 328668f38c69..4c9093b64d1f 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -300,12 +300,6 @@ char *dso__build_id_filename(const struct dso *dso, char *bf, size_t size, return __dso__build_id_filename(dso, bf, size, is_debug, is_kallsyms); } -#define dsos__for_each_with_build_id(pos, head) \ - list_for_each_entry(pos, head, node) \ - if (!pos->has_build_id) \ - continue; \ - else - static int write_buildid(const char *name, size_t name_len, struct build_id *bid, pid_t pid, u16 misc, struct feat_fd *fd) { diff --git a/tools/perf/util/dso.h b/tools/perf/util/dso.h index 97047a11282b..66981c7a9a18 100644 --- a/tools/perf/util/dso.h +++ b/tools/perf/util/dso.h @@ -227,6 +227,12 @@ struct dso { #define dso__for_each_symbol(dso, pos, n) \ symbols__for_each_entry(&(dso)->symbols, pos, n) +#define dsos__for_each_with_build_id(pos, head) \ + list_for_each_entry(pos, head, node) \ + if (!pos->has_build_id) \ + continue; \ + else + static inline void dso__set_loaded(struct dso *dso) { dso->loaded = true; From patchwork Mon Jul 11 09:31:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913243 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0B57C43334 for ; Mon, 11 Jul 2022 10:10:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234593AbiGKKKh (ORCPT ); Mon, 11 Jul 2022 06:10:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46038 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231383AbiGKKKP (ORCPT ); Mon, 11 Jul 2022 06:10:15 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8AEABFAF0; Mon, 11 Jul 2022 02:32:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657531969; x=1689067969; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=peNY5Wsb9AA5sM1LjO+8sxYcFY1txqJD8C6nMA1BaP8=; b=PmgVEoZeVlxSfO097gNHi+9qKA1uIV4GPHnH3QVRM54dTfa8WsjZdZcU V7ivU/6ZjTUyjCDbLcjnqHGMT1PXr2wVc2vPPCX6z9TCfuB1j7Of3T+5B qyBhoVQgcxgVLBLkJnCrNT7iwWm6EgKhOp2Rj6wMymWtHFHUZAXH56Grx tnTxMPvClufCrG2V+dG+zOWUvFRx6CTF520EWd4Eh65kSK5RmqVR5dhkt pasFYj2iHDvPSqqE1Q/jMhOAPMJ9zQFk4PUn8HNWfSQE4otpL3RDBBP0r Z0Hn+Vi9dYU3qs4Lpr5IdrNBC2WHRcNkQ31N/8hl9nMEzZWzexaljWYyt g==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371521" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371521" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:32:49 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387014" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:32:47 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 03/35] perf ordered_events: Add ordered_events__last_flush_time() Date: Mon, 11 Jul 2022 12:31:46 +0300 Message-Id: <20220711093218.10967-4-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Allow callers to get the ordered_events last flush timestamp. This is needed in perf inject to obey finished-round ordering when injecting additional events (e.g. from a guest perf.data file) with timestamps. Any additional events that have timestamps before the last flush time must be injected before the corresponding FINISHED_ROUND event. Signed-off-by: Adrian Hunter Acked-by: Ian Rogers --- tools/perf/util/ordered-events.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/perf/util/ordered-events.h b/tools/perf/util/ordered-events.h index 0b05c3c0aeaa..8febbd7c98ca 100644 --- a/tools/perf/util/ordered-events.h +++ b/tools/perf/util/ordered-events.h @@ -75,4 +75,10 @@ void ordered_events__set_copy_on_queue(struct ordered_events *oe, bool copy) { oe->copy_on_queue = copy; } + +static inline u64 ordered_events__last_flush_time(struct ordered_events *oe) +{ + return oe->last_flush; +} + #endif /* __ORDERED_EVENTS_H */ From patchwork Mon Jul 11 09:31:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913244 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E256BC433EF for ; Mon, 11 Jul 2022 10:10:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231787AbiGKKKk (ORCPT ); Mon, 11 Jul 2022 06:10:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231693AbiGKKKP (ORCPT ); Mon, 11 Jul 2022 06:10:15 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B199F4332D; Mon, 11 Jul 2022 02:32:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657531971; x=1689067971; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RBbXX7qaIoqHIXjBzFEPU7bF82bk5P3sOeLB5375eY0=; b=LjfQbfI9xQWDxL3UJE4wQL2GY8W2K8Zl+4WgUW2l0EtmAkjOtVfdlvG4 nJUopmcXSlkqgbrKo+nrRroRGzWx5CZkTFUeo7Ek1bYHMlZ5TfFA++c3W mQpMVwN8gRBe6hb3kaSi/de+a7nwkeGcsWx/fqA8nfk+QYPf6+wCkTWRB 96nfPllBX0UHVQsLchNa67Rtyzbp5baO3V3bXAmv0REVjfbhXcsOonR5f q1abbpXIqKlMrBhHkzqo2Uigzo++raU+ik6xgarirmKGBOFCInaJ6pben Pm3fkIx4JiH17FQ1sJ1miBikUKPNdUe3t2MJUOykVLiv+L1K3ZUpj1Ufw w==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371529" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371529" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:32:51 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387021" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:32:49 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 04/35] perf tools: Export perf_event__process_finished_round() Date: Mon, 11 Jul 2022 12:31:47 +0300 Message-Id: <20220711093218.10967-5-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Export perf_event__process_finished_round() so it can be used elsewhere. This is needed in perf inject to obey finished-round ordering. Signed-off-by: Adrian Hunter Acked-by: Ian Rogers --- tools/perf/util/session.c | 12 ++++-------- tools/perf/util/session.h | 4 ++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 37f833c3c81b..4c9513bc6d89 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -374,10 +374,6 @@ static int process_finished_round_stub(struct perf_tool *tool __maybe_unused, return 0; } -static int process_finished_round(struct perf_tool *tool, - union perf_event *event, - struct ordered_events *oe); - static int skipn(int fd, off_t n) { char buf[4096]; @@ -534,7 +530,7 @@ void perf_tool__fill_defaults(struct perf_tool *tool) tool->build_id = process_event_op2_stub; if (tool->finished_round == NULL) { if (tool->ordered_events) - tool->finished_round = process_finished_round; + tool->finished_round = perf_event__process_finished_round; else tool->finished_round = process_finished_round_stub; } @@ -1069,9 +1065,9 @@ static perf_event__swap_op perf_event__swap_ops[] = { * Flush every events below timestamp 7 * etc... */ -static int process_finished_round(struct perf_tool *tool __maybe_unused, - union perf_event *event __maybe_unused, - struct ordered_events *oe) +int perf_event__process_finished_round(struct perf_tool *tool __maybe_unused, + union perf_event *event __maybe_unused, + struct ordered_events *oe) { if (dump_trace) fprintf(stdout, "\n"); diff --git a/tools/perf/util/session.h b/tools/perf/util/session.h index 34500a3da735..be5871ea558f 100644 --- a/tools/perf/util/session.h +++ b/tools/perf/util/session.h @@ -155,4 +155,8 @@ int perf_session__deliver_synth_event(struct perf_session *session, int perf_event__process_id_index(struct perf_session *session, union perf_event *event); +int perf_event__process_finished_round(struct perf_tool *tool, + union perf_event *event, + struct ordered_events *oe); + #endif /* __PERF_SESSION_H */ From patchwork Mon Jul 11 09:31:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913245 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B047FC43334 for ; Mon, 11 Jul 2022 10:10:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231182AbiGKKKm (ORCPT ); Mon, 11 Jul 2022 06:10:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231848AbiGKKKQ (ORCPT ); Mon, 11 Jul 2022 06:10:16 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CDEDBFAF9; Mon, 11 Jul 2022 02:32:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657531974; x=1689067974; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hL21TJrX9GOGzRml4dqgYs6puEA8/R32Vt5xw54wtNQ=; b=T0jdFu2+FTWBZ5BjSssisLx/JcH3g0YwW6OULzg0Ar/ONmkXy7Cmyntk YK3c24iwoTqcitNOztJ33JX+91lIjoTf9pCntI4HQFjr1yagS8BhLYQZf w7lNKC1k5EX7DFKywT7q8bbK1FbsOb17GSR1Lai9kLk5gEOf8ZUsJ7kHR J9rbezbfoJ5/9HBMT20zoRuUqBsUzpN5bfKr68ePrI3gVmPwsg9YpcFgB TkTdimvkrdK+SySGw9JK/nIeg584A8QSlqJp/QOslMbubSmqd/BSaR94e 5EmjjQ9EGr8P9aj1EBUoHysx6zQ7DNb4i0FnRtjPZSAA4kTerrfM0Tj8+ A==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371531" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371531" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:32:53 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387025" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:32:51 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 05/35] perf tools: Factor out evsel__id_hdr_size() Date: Mon, 11 Jul 2022 12:31:48 +0300 Message-Id: <20220711093218.10967-6-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Factor out evsel__id_hdr_size() so it can be reused. This is needed by perf inject. When injecting events from a guest perf.data file, there is a possibility that the sample ID numbers conflict. To re-write an ID sample, the old one needs to be removed first, which means determining how big it is with evsel__id_hdr_size() and then subtracting that from the event size. Signed-off-by: Adrian Hunter --- tools/perf/util/evlist.c | 28 +--------------------------- tools/perf/util/evsel.c | 26 ++++++++++++++++++++++++++ tools/perf/util/evsel.h | 2 ++ 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 48af7d379d82..03fbe151b0c4 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1244,34 +1244,8 @@ bool evlist__valid_read_format(struct evlist *evlist) u16 evlist__id_hdr_size(struct evlist *evlist) { struct evsel *first = evlist__first(evlist); - struct perf_sample *data; - u64 sample_type; - u16 size = 0; - if (!first->core.attr.sample_id_all) - goto out; - - sample_type = first->core.attr.sample_type; - - if (sample_type & PERF_SAMPLE_TID) - size += sizeof(data->tid) * 2; - - if (sample_type & PERF_SAMPLE_TIME) - size += sizeof(data->time); - - if (sample_type & PERF_SAMPLE_ID) - size += sizeof(data->id); - - if (sample_type & PERF_SAMPLE_STREAM_ID) - size += sizeof(data->stream_id); - - if (sample_type & PERF_SAMPLE_CPU) - size += sizeof(data->cpu) * 2; - - if (sample_type & PERF_SAMPLE_IDENTIFIER) - size += sizeof(data->id); -out: - return size; + return first->core.attr.sample_id_all ? evsel__id_hdr_size(first) : 0; } bool evlist__valid_sample_id_all(struct evlist *evlist) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index a67cc3f2fa74..9a30ccb7b104 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2724,6 +2724,32 @@ int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event, return 0; } +u16 evsel__id_hdr_size(struct evsel *evsel) +{ + u64 sample_type = evsel->core.attr.sample_type; + u16 size = 0; + + if (sample_type & PERF_SAMPLE_TID) + size += sizeof(u64); + + if (sample_type & PERF_SAMPLE_TIME) + size += sizeof(u64); + + if (sample_type & PERF_SAMPLE_ID) + size += sizeof(u64); + + if (sample_type & PERF_SAMPLE_STREAM_ID) + size += sizeof(u64); + + if (sample_type & PERF_SAMPLE_CPU) + size += sizeof(u64); + + if (sample_type & PERF_SAMPLE_IDENTIFIER) + size += sizeof(u64); + + return size; +} + struct tep_format_field *evsel__field(struct evsel *evsel, const char *name) { return tep_find_field(evsel->tp_format, name); diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 92bed8e2f7d8..699448f2bc2b 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -381,6 +381,8 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, int evsel__parse_sample_timestamp(struct evsel *evsel, union perf_event *event, u64 *timestamp); +u16 evsel__id_hdr_size(struct evsel *evsel); + static inline struct evsel *evsel__next(struct evsel *evsel) { return list_entry(evsel->core.node.next, struct evsel, core.node); From patchwork Mon Jul 11 09:31:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913246 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8C2DC433EF for ; Mon, 11 Jul 2022 10:10:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234632AbiGKKKv (ORCPT ); Mon, 11 Jul 2022 06:10:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232072AbiGKKKT (ORCPT ); Mon, 11 Jul 2022 06:10:19 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66F71BFAFE; Mon, 11 Jul 2022 02:32:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657531976; x=1689067976; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EQmJPhIRVFDcY2WyYLRk47c63sx+cSKRVC+YAWr9f2E=; b=nwODpKNyYyHWtB4p8hSquZX+QRNhBLtwulewXQIbWYAy/KfYXXDgq0do alMhpaZQbmo7bGd2Ld6bwx9Y/JDBo0TZs3LBZTosaByEkThb1gRHNjqSZ 9ID53IplxIFC7LwxNK5Ba7YiuyGo8Qmtrr+QuEfmSnYg6ruihVNF6xHY0 RRiMfwt+TpcFMZ+BtzZbxR4FNPXhpeaV4uxYrL4GkkvL1ehqP8RX8gl90 2gTxsL4vETu2WEyttSyZI4XeptIPFxHTCvReZG2iS/3eYRSnmejJPcTyT o630SCBnM/cMGXV0a1WYx4WSB0Zrn6iCPHuUmGv5IfW0xdLg0QROm1/M6 g==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371540" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371540" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:32:56 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387031" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:32:54 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 06/35] perf tools: Add perf_event__synthesize_id_sample() Date: Mon, 11 Jul 2022 12:31:49 +0300 Message-Id: <20220711093218.10967-7-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add perf_event__synthesize_id_sample() to enable the synthesis of ID samples. This is needed by perf inject. When injecting events from a guest perf.data file, there is a possibility that the sample ID numbers conflict. In that case, perf_event__synthesize_id_sample() can be used to re-write the ID sample. Signed-off-by: Adrian Hunter --- tools/perf/util/synthetic-events.c | 47 ++++++++++++++++++++++++++++++ tools/perf/util/synthetic-events.h | 1 + 2 files changed, 48 insertions(+) diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c index fe5db4bf0042..ed9623702f34 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -1712,6 +1712,53 @@ int perf_event__synthesize_sample(union perf_event *event, u64 type, u64 read_fo return 0; } +int perf_event__synthesize_id_sample(__u64 *array, u64 type, const struct perf_sample *sample) +{ + __u64 *start = array; + + /* + * used for cross-endian analysis. See git commit 65014ab3 + * for why this goofiness is needed. + */ + union u64_swap u; + + if (type & PERF_SAMPLE_TID) { + u.val32[0] = sample->pid; + u.val32[1] = sample->tid; + *array = u.val64; + array++; + } + + if (type & PERF_SAMPLE_TIME) { + *array = sample->time; + array++; + } + + if (type & PERF_SAMPLE_ID) { + *array = sample->id; + array++; + } + + if (type & PERF_SAMPLE_STREAM_ID) { + *array = sample->stream_id; + array++; + } + + if (type & PERF_SAMPLE_CPU) { + u.val32[0] = sample->cpu; + u.val32[1] = 0; + *array = u.val64; + array++; + } + + if (type & PERF_SAMPLE_IDENTIFIER) { + *array = sample->id; + array++; + } + + return (void *)array - (void *)start; +} + int perf_event__synthesize_id_index(struct perf_tool *tool, perf_event__handler_t process, struct evlist *evlist, struct machine *machine) { diff --git a/tools/perf/util/synthetic-events.h b/tools/perf/util/synthetic-events.h index 78a0450db164..b136ec3ec95d 100644 --- a/tools/perf/util/synthetic-events.h +++ b/tools/perf/util/synthetic-events.h @@ -55,6 +55,7 @@ int perf_event__synthesize_extra_attr(struct perf_tool *tool, struct evlist *evs int perf_event__synthesize_extra_kmaps(struct perf_tool *tool, perf_event__handler_t process, struct machine *machine); int perf_event__synthesize_features(struct perf_tool *tool, struct perf_session *session, struct evlist *evlist, perf_event__handler_t process); int perf_event__synthesize_id_index(struct perf_tool *tool, perf_event__handler_t process, struct evlist *evlist, struct machine *machine); +int perf_event__synthesize_id_sample(__u64 *array, u64 type, const struct perf_sample *sample); int perf_event__synthesize_kernel_mmap(struct perf_tool *tool, perf_event__handler_t process, struct machine *machine); int perf_event__synthesize_mmap_events(struct perf_tool *tool, union perf_event *event, pid_t pid, pid_t tgid, perf_event__handler_t process, struct machine *machine, bool mmap_data); int perf_event__synthesize_modules(struct perf_tool *tool, perf_event__handler_t process, struct machine *machine); From patchwork Mon Jul 11 09:31:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913247 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 089EFC433EF for ; Mon, 11 Jul 2022 10:11:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232721AbiGKKLB (ORCPT ); Mon, 11 Jul 2022 06:11:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232690AbiGKKKV (ORCPT ); Mon, 11 Jul 2022 06:10:21 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8635774A0; Mon, 11 Jul 2022 02:32:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657531980; x=1689067980; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uvOjO7SAHwYws30A/h/vjMwuhgOCudN5JHVzUoXQMg4=; b=Gi+hAIKSqFs6s3AUVq2CnmqjnyZavA+tlOqGMLzwwQRFed2g7l6kgx2B /zldkF5Xo5+wpwhY+FS8KHmnMld2ygIFg32Jzlm/L2FMh1YiLkBdTnoqM BMXRfNE/fRfk765FVQhspe4pp0sd4vbTAOJOf8hdvq02ySjfRf1AbUBR6 lno6n6JDBs69y1kKXLd4WJDsJySohKfRjMuf9LQNEeaJWRSDba2d9s7Nj tzdmUxL3xaLlr+LBQs/hddK/UsQrwBjJ829zAzktjwqvNWBNvAl6sB9uF xkyoxNSzgC1vUAkRV8ewj9qdK5I5hFv9DtvVaSUtXhUYbFW4lyPHwEPhd Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371544" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371544" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:32:58 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387035" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:32:56 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 07/35] perf script: Add --dump-unsorted-raw-trace option Date: Mon, 11 Jul 2022 12:31:50 +0300 Message-Id: <20220711093218.10967-8-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When reviewing the results of perf inject, it is useful to be able to see the events in the order they appear in the file. So add --dump-unsorted-raw-trace option to do an unsorted dump. Signed-off-by: Adrian Hunter Acked-by: Ian Rogers --- tools/perf/Documentation/perf-script.txt | 3 +++ tools/perf/builtin-script.c | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt index 1a557ff8f210..e250ff5566cf 100644 --- a/tools/perf/Documentation/perf-script.txt +++ b/tools/perf/Documentation/perf-script.txt @@ -79,6 +79,9 @@ OPTIONS --dump-raw-trace=:: Display verbose dump of the trace data. +--dump-unsorted-raw-trace=:: + Same as --dump-raw-trace but not sorted in time order. + -L:: --Latency=:: Show latency attributes (irqs/preemption disabled, etc). diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 7cf21ab16f4f..4b00a50faf00 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -3746,6 +3746,7 @@ int cmd_script(int argc, const char **argv) bool header = false; bool header_only = false; bool script_started = false; + bool unsorted_dump = false; char *rec_script_path = NULL; char *rep_script_path = NULL; struct perf_session *session; @@ -3794,6 +3795,8 @@ int cmd_script(int argc, const char **argv) const struct option options[] = { OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, "dump raw trace in ASCII"), + OPT_BOOLEAN(0, "dump-unsorted-raw-trace", &unsorted_dump, + "dump unsorted raw trace in ASCII"), OPT_INCR('v', "verbose", &verbose, "be more verbose (show symbol address, etc)"), OPT_BOOLEAN('L', "Latency", &latency_format, @@ -3956,6 +3959,11 @@ int cmd_script(int argc, const char **argv) data.path = input_name; data.force = symbol_conf.force; + if (unsorted_dump) { + dump_trace = true; + script.tool.ordered_events = false; + } + if (symbol__validate_sym_arguments()) return -1; From patchwork Mon Jul 11 09:31:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913248 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C7EE3CCA47B for ; Mon, 11 Jul 2022 10:11:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234613AbiGKKLP (ORCPT ); Mon, 11 Jul 2022 06:11:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233909AbiGKKKX (ORCPT ); Mon, 11 Jul 2022 06:10:23 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45C70774B3; Mon, 11 Jul 2022 02:33:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657531981; x=1689067981; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=06NuWXD+A69I7tbKdaelDYf1QOfCRyX2oUN29GJhdUY=; b=j0xdvo5Pyef6vYTA8E4t8sXFvi6A2+Y5x2uYW+ErkTg+RZyN0UTQelj+ EmCyYuu/FTVe2E01k0zrzwgN7C0OoIHrur67zwYm2kKFjtgFLKKfnf3d8 b0F49X27C3cWBTz/w4DJPs3uXF2t6DgUMV4wRJnY6vgSpMyaHKHW+Lxt1 F22q3B0wjO4TFveMTMAfRW78Otz01QHxdaTDQV6388wQNWGchT3y7pAVo fUAk1dnq0r3GjZZ5D3NL7GxVz2ddvAXk5vKj7azTLCIl+/J3ABFaBUtw8 2XEej+nVGSRa/skKmj7WVshlpt9fbgKz1SbV/SfwsH0lJ8W/EQyWTIREJ Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371548" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371548" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:00 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387042" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:32:58 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 08/35] perf buildid-cache: Add guestmount'd files to the build ID cache Date: Mon, 11 Jul 2022 12:31:51 +0300 Message-Id: <20220711093218.10967-9-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When the guestmount option is used, a guest machine's file system mount point is recorded in machine->root_dir. perf already iterates guest machines when adding files to the build ID cache, but does not take machine->root_dir into account. Use machine->root_dir to find files for guest build IDs, and add them to the build ID cache using the "proper" name i.e. relative to the guest root directory not the host root directory. Signed-off-by: Adrian Hunter Acked-by: Ian Rogers --- tools/perf/util/build-id.c | 67 +++++++++++++++++++++++++++++--------- tools/perf/util/build-id.h | 16 ++++++--- 2 files changed, 63 insertions(+), 20 deletions(-) diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 4c9093b64d1f..7c9f441936ee 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -625,9 +625,12 @@ static int build_id_cache__add_sdt_cache(const char *sbuild_id, #endif static char *build_id_cache__find_debug(const char *sbuild_id, - struct nsinfo *nsi) + struct nsinfo *nsi, + const char *root_dir) { + const char *dirname = "/usr/lib/debug/.build-id/"; char *realname = NULL; + char dirbuf[PATH_MAX]; char *debugfile; struct nscookie nsc; size_t len = 0; @@ -636,8 +639,12 @@ static char *build_id_cache__find_debug(const char *sbuild_id, if (!debugfile) goto out; - len = __symbol__join_symfs(debugfile, PATH_MAX, - "/usr/lib/debug/.build-id/"); + if (root_dir) { + path__join(dirbuf, PATH_MAX, root_dir, dirname); + dirname = dirbuf; + } + + len = __symbol__join_symfs(debugfile, PATH_MAX, dirname); snprintf(debugfile + len, PATH_MAX - len, "%.2s/%s.debug", sbuild_id, sbuild_id + 2); @@ -668,14 +675,18 @@ static char *build_id_cache__find_debug(const char *sbuild_id, int build_id_cache__add(const char *sbuild_id, const char *name, const char *realname, - struct nsinfo *nsi, bool is_kallsyms, bool is_vdso) + struct nsinfo *nsi, bool is_kallsyms, bool is_vdso, + const char *proper_name, const char *root_dir) { const size_t size = PATH_MAX; char *filename = NULL, *dir_name = NULL, *linkname = zalloc(size), *tmp; char *debugfile = NULL; int err = -1; - dir_name = build_id_cache__cachedir(sbuild_id, name, nsi, is_kallsyms, + if (!proper_name) + proper_name = name; + + dir_name = build_id_cache__cachedir(sbuild_id, proper_name, nsi, is_kallsyms, is_vdso); if (!dir_name) goto out_free; @@ -715,7 +726,7 @@ build_id_cache__add(const char *sbuild_id, const char *name, const char *realnam */ if (!is_kallsyms && !is_vdso && strncmp(".ko", name + strlen(name) - 3, 3)) { - debugfile = build_id_cache__find_debug(sbuild_id, nsi); + debugfile = build_id_cache__find_debug(sbuild_id, nsi, root_dir); if (debugfile) { zfree(&filename); if (asprintf(&filename, "%s/%s", dir_name, @@ -781,8 +792,9 @@ build_id_cache__add(const char *sbuild_id, const char *name, const char *realnam return err; } -int build_id_cache__add_s(const char *sbuild_id, const char *name, - struct nsinfo *nsi, bool is_kallsyms, bool is_vdso) +int __build_id_cache__add_s(const char *sbuild_id, const char *name, + struct nsinfo *nsi, bool is_kallsyms, bool is_vdso, + const char *proper_name, const char *root_dir) { char *realname = NULL; int err = -1; @@ -796,8 +808,8 @@ int build_id_cache__add_s(const char *sbuild_id, const char *name, goto out_free; } - err = build_id_cache__add(sbuild_id, name, realname, nsi, is_kallsyms, is_vdso); - + err = build_id_cache__add(sbuild_id, name, realname, nsi, + is_kallsyms, is_vdso, proper_name, root_dir); out_free: if (!is_kallsyms) free(realname); @@ -806,14 +818,16 @@ int build_id_cache__add_s(const char *sbuild_id, const char *name, static int build_id_cache__add_b(const struct build_id *bid, const char *name, struct nsinfo *nsi, - bool is_kallsyms, bool is_vdso) + bool is_kallsyms, bool is_vdso, + const char *proper_name, + const char *root_dir) { char sbuild_id[SBUILD_ID_SIZE]; build_id__sprintf(bid, sbuild_id); - return build_id_cache__add_s(sbuild_id, name, nsi, is_kallsyms, - is_vdso); + return __build_id_cache__add_s(sbuild_id, name, nsi, is_kallsyms, + is_vdso, proper_name, root_dir); } bool build_id_cache__cached(const char *sbuild_id) @@ -896,6 +910,10 @@ static int dso__cache_build_id(struct dso *dso, struct machine *machine, bool is_kallsyms = dso__is_kallsyms(dso); bool is_vdso = dso__is_vdso(dso); const char *name = dso->long_name; + const char *proper_name = NULL; + const char *root_dir = NULL; + char *allocated_name = NULL; + int ret = 0; if (!dso->has_build_id) return 0; @@ -905,11 +923,28 @@ static int dso__cache_build_id(struct dso *dso, struct machine *machine, name = machine->mmap_name; } + if (!machine__is_host(machine)) { + if (*machine->root_dir) { + root_dir = machine->root_dir; + ret = asprintf(&allocated_name, "%s/%s", root_dir, name); + if (ret < 0) + return ret; + proper_name = name; + name = allocated_name; + } else if (is_kallsyms) { + /* Cannot get guest kallsyms */ + return 0; + } + } + if (!is_kallsyms && dso__build_id_mismatch(dso, name)) - return 0; + goto out_free; - return build_id_cache__add_b(&dso->bid, name, dso->nsinfo, - is_kallsyms, is_vdso); + ret = build_id_cache__add_b(&dso->bid, name, dso->nsinfo, + is_kallsyms, is_vdso, proper_name, root_dir); +out_free: + free(allocated_name); + return ret; } static int diff --git a/tools/perf/util/build-id.h b/tools/perf/util/build-id.h index c19617151670..4e3a1169379b 100644 --- a/tools/perf/util/build-id.h +++ b/tools/perf/util/build-id.h @@ -66,10 +66,18 @@ int build_id_cache__list_build_ids(const char *pathname, struct nsinfo *nsi, struct strlist **result); bool build_id_cache__cached(const char *sbuild_id); int build_id_cache__add(const char *sbuild_id, const char *name, const char *realname, - struct nsinfo *nsi, bool is_kallsyms, bool is_vdso); -int build_id_cache__add_s(const char *sbuild_id, - const char *name, struct nsinfo *nsi, - bool is_kallsyms, bool is_vdso); + struct nsinfo *nsi, bool is_kallsyms, bool is_vdso, + const char *proper_name, const char *root_dir); +int __build_id_cache__add_s(const char *sbuild_id, + const char *name, struct nsinfo *nsi, + bool is_kallsyms, bool is_vdso, + const char *proper_name, const char *root_dir); +static inline int build_id_cache__add_s(const char *sbuild_id, + const char *name, struct nsinfo *nsi, + bool is_kallsyms, bool is_vdso) +{ + return __build_id_cache__add_s(sbuild_id, name, nsi, is_kallsyms, is_vdso, NULL, NULL); +} int build_id_cache__remove_s(const char *sbuild_id); extern char buildid_dir[]; From patchwork Mon Jul 11 09:31:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913249 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7615C433EF for ; Mon, 11 Jul 2022 10:11:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232911AbiGKKLW (ORCPT ); Mon, 11 Jul 2022 06:11:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234403AbiGKKKZ (ORCPT ); Mon, 11 Jul 2022 06:10:25 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AC0D78203; Mon, 11 Jul 2022 02:33:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657531983; x=1689067983; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=f5C4voCgvVR8bp8zTIbCS74Eqs9Ys1LBQmXx+/5R2lg=; b=kkUCjC4PlgbKRYD62cploYbMeSipmdtbIiUIaXTFXMXSFz+494f7tQ0k mkJrfAHDwNVZOqqDzxl1Yk6k89x5YUmMpv/Cc4Z3WJGVNuqv0ZMEWgp+3 /nqu5Zow5dPhAS94m4mrRsxpN5vGsdO+q1KMKdWSGsG8YG9ugsnJDq6+Y GMeFVddVNCYFAugoEWWq9NY/A7TJCfOKSz8BPSZQPgGVuJwjOm0E6RDxe iRd60OF2bB12RKcSI/41m0g3I3xnC0XbF1V4JEP08FILGH/rCvxG4Qcv2 4NwXjxlEgZn4Y3u2sfZU2eEVRq+A1BnNhoYUFPpRN9qcRdvEzEXBK9KEO w==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371550" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371550" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:03 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387052" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:01 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 09/35] perf buildid-cache: Do not require purge files to also be in the file system Date: Mon, 11 Jul 2022 12:31:52 +0300 Message-Id: <20220711093218.10967-10-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org realname() returns NULL if the file is not in the file system, but we can still remove it from the build ID cache in that case, so continue and attempt the purge with the name provided. Signed-off-by: Adrian Hunter --- tools/perf/util/build-id.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/build-id.c b/tools/perf/util/build-id.c index 7c9f441936ee..9e176146eb10 100644 --- a/tools/perf/util/build-id.c +++ b/tools/perf/util/build-id.c @@ -561,14 +561,11 @@ char *build_id_cache__cachedir(const char *sbuild_id, const char *name, char *realname = (char *)name, *filename; bool slash = is_kallsyms || is_vdso; - if (!slash) { + if (!slash) realname = nsinfo__realpath(name, nsi); - if (!realname) - return NULL; - } if (asprintf(&filename, "%s%s%s%s%s", buildid_dir, slash ? "/" : "", - is_vdso ? DSO__NAME_VDSO : realname, + is_vdso ? DSO__NAME_VDSO : (realname ? realname : name), sbuild_id ? "/" : "", sbuild_id ?: "") < 0) filename = NULL; From patchwork Mon Jul 11 09:31:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913250 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3374C43334 for ; Mon, 11 Jul 2022 10:11:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234670AbiGKKL2 (ORCPT ); Mon, 11 Jul 2022 06:11:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230134AbiGKKK0 (ORCPT ); Mon, 11 Jul 2022 06:10:26 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADB857820F; Mon, 11 Jul 2022 02:33:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657531985; x=1689067985; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yN8l0HnChol0FDVhQIhHHh94ut1DeNTcvpI2bpWYEZM=; b=fnpRaxrWyi3lkOEeAXBDBGLJzqM/n2YVZs3l4jL76NBgtQTtaYN/qQ6+ YFu8u0TzpGK73/axld1ic4XgJbgZBjoEDRlnp/fyxODQ2h0X1acgE4V59 rAxxWtxAMFOTbGsD3YWy/+UEgzMPkKdM0P5mASnpNFU2+MVbks8ghervK ZfWMqkgz641mPo+7w4VpOj4iZeFHgv/1eo3KFgpr4ObPWSflnQdeZIDG8 RcYiZnUwPProS7c0xtb7NPiSE6JUQkrVdTbLZ89CR+X7ZcJaqGvsq721l H/zAgaQ4475mQPMqGRRQ8zbN3oe0zeSvomanODluW9Lp6cAWc8pTP1HH8 A==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371557" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371557" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:05 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387060" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:03 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 10/35] perf tools: Add machine_pid and vcpu to id_index Date: Mon, 11 Jul 2022 12:31:53 +0300 Message-Id: <20220711093218.10967-11-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When injecting events from a guest perf.data file, the events will have separate sample ID numbers. These ID numbers can then be used to determine which machine an event belongs to. To facilitate that, add machine_pid and vcpu to id_index records. For backward compatibility, these are added at the end of the record, and the length of the record is used to determine if they are present or not. Note, this is needed because the events from a guest perf.data file contain the pid/tid of the process running at that time inside the VM not the pid/tid of the (QEMU) hypervisor thread. So a way is needed to relate guest events back to the guest machine and VCPU, and using sample ID numbers for that is relatively simple and convenient. Signed-off-by: Adrian Hunter --- tools/lib/perf/include/internal/evsel.h | 4 ++ tools/lib/perf/include/perf/event.h | 5 +++ tools/perf/util/session.c | 40 ++++++++++++++++--- tools/perf/util/synthetic-events.c | 51 +++++++++++++++++++------ tools/perf/util/synthetic-events.h | 1 + 5 files changed, 84 insertions(+), 17 deletions(-) diff --git a/tools/lib/perf/include/internal/evsel.h b/tools/lib/perf/include/internal/evsel.h index 2a912a1f1989..a99a75d9e78f 100644 --- a/tools/lib/perf/include/internal/evsel.h +++ b/tools/lib/perf/include/internal/evsel.h @@ -30,6 +30,10 @@ struct perf_sample_id { struct perf_cpu cpu; pid_t tid; + /* Guest machine pid and VCPU, valid only if machine_pid is non-zero */ + pid_t machine_pid; + struct perf_cpu vcpu; + /* Holds total ID period value for PERF_SAMPLE_READ processing. */ u64 period; }; diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/perf/event.h index 9f7ca070da87..c2dbd3e88885 100644 --- a/tools/lib/perf/include/perf/event.h +++ b/tools/lib/perf/include/perf/event.h @@ -237,6 +237,11 @@ struct id_index_entry { __u64 tid; }; +struct id_index_entry_2 { + __u64 machine_pid; + __u64 vcpu; +}; + struct perf_record_id_index { struct perf_event_header header; __u64 nr; diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 4c9513bc6d89..5141fe164e97 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2756,18 +2756,35 @@ int perf_event__process_id_index(struct perf_session *session, { struct evlist *evlist = session->evlist; struct perf_record_id_index *ie = &event->id_index; + size_t sz = ie->header.size - sizeof(*ie); size_t i, nr, max_nr; + size_t e1_sz = sizeof(struct id_index_entry); + size_t e2_sz = sizeof(struct id_index_entry_2); + size_t etot_sz = e1_sz + e2_sz; + struct id_index_entry_2 *e2; - max_nr = (ie->header.size - sizeof(struct perf_record_id_index)) / - sizeof(struct id_index_entry); + max_nr = sz / e1_sz; nr = ie->nr; - if (nr > max_nr) + if (nr > max_nr) { + printf("Too big: nr %zu max_nr %zu\n", nr, max_nr); return -EINVAL; + } + + if (sz >= nr * etot_sz) { + max_nr = sz / etot_sz; + if (nr > max_nr) { + printf("Too big2: nr %zu max_nr %zu\n", nr, max_nr); + return -EINVAL; + } + e2 = (void *)ie + sizeof(*ie) + nr * e1_sz; + } else { + e2 = NULL; + } if (dump_trace) fprintf(stdout, " nr: %zu\n", nr); - for (i = 0; i < nr; i++) { + for (i = 0; i < nr; i++, (e2 ? e2++ : 0)) { struct id_index_entry *e = &ie->entries[i]; struct perf_sample_id *sid; @@ -2775,15 +2792,28 @@ int perf_event__process_id_index(struct perf_session *session, fprintf(stdout, " ... id: %"PRI_lu64, e->id); fprintf(stdout, " idx: %"PRI_lu64, e->idx); fprintf(stdout, " cpu: %"PRI_ld64, e->cpu); - fprintf(stdout, " tid: %"PRI_ld64"\n", e->tid); + fprintf(stdout, " tid: %"PRI_ld64, e->tid); + if (e2) { + fprintf(stdout, " machine_pid: %"PRI_ld64, e2->machine_pid); + fprintf(stdout, " vcpu: %"PRI_lu64"\n", e2->vcpu); + } else { + fprintf(stdout, "\n"); + } } sid = evlist__id2sid(evlist, e->id); if (!sid) return -ENOENT; + sid->idx = e->idx; sid->cpu.cpu = e->cpu; sid->tid = e->tid; + + if (!e2) + continue; + + sid->machine_pid = e2->machine_pid; + sid->vcpu.cpu = e2->vcpu; } return 0; } diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c index ed9623702f34..2ae59c03ae77 100644 --- a/tools/perf/util/synthetic-events.c +++ b/tools/perf/util/synthetic-events.c @@ -1759,19 +1759,26 @@ int perf_event__synthesize_id_sample(__u64 *array, u64 type, const struct perf_s return (void *)array - (void *)start; } -int perf_event__synthesize_id_index(struct perf_tool *tool, perf_event__handler_t process, - struct evlist *evlist, struct machine *machine) +int __perf_event__synthesize_id_index(struct perf_tool *tool, perf_event__handler_t process, + struct evlist *evlist, struct machine *machine, size_t from) { union perf_event *ev; struct evsel *evsel; - size_t nr = 0, i = 0, sz, max_nr, n; + size_t nr = 0, i = 0, sz, max_nr, n, pos; + size_t e1_sz = sizeof(struct id_index_entry); + size_t e2_sz = sizeof(struct id_index_entry_2); + size_t etot_sz = e1_sz + e2_sz; + bool e2_needed = false; int err; - max_nr = (UINT16_MAX - sizeof(struct perf_record_id_index)) / - sizeof(struct id_index_entry); + max_nr = (UINT16_MAX - sizeof(struct perf_record_id_index)) / etot_sz; - evlist__for_each_entry(evlist, evsel) + pos = 0; + evlist__for_each_entry(evlist, evsel) { + if (pos++ < from) + continue; nr += evsel->core.ids; + } if (!nr) return 0; @@ -1779,31 +1786,38 @@ int perf_event__synthesize_id_index(struct perf_tool *tool, perf_event__handler_ pr_debug2("Synthesizing id index\n"); n = nr > max_nr ? max_nr : nr; - sz = sizeof(struct perf_record_id_index) + n * sizeof(struct id_index_entry); + sz = sizeof(struct perf_record_id_index) + n * etot_sz; ev = zalloc(sz); if (!ev) return -ENOMEM; + sz = sizeof(struct perf_record_id_index) + n * e1_sz; + ev->id_index.header.type = PERF_RECORD_ID_INDEX; - ev->id_index.header.size = sz; ev->id_index.nr = n; + pos = 0; evlist__for_each_entry(evlist, evsel) { u32 j; - for (j = 0; j < evsel->core.ids; j++) { + if (pos++ < from) + continue; + for (j = 0; j < evsel->core.ids; j++, i++) { struct id_index_entry *e; + struct id_index_entry_2 *e2; struct perf_sample_id *sid; if (i >= n) { + ev->id_index.header.size = sz + (e2_needed ? n * e2_sz : 0); err = process(tool, ev, NULL, machine); if (err) goto out_err; nr -= n; i = 0; + e2_needed = false; } - e = &ev->id_index.entries[i++]; + e = &ev->id_index.entries[i]; e->id = evsel->core.id[j]; @@ -1816,11 +1830,18 @@ int perf_event__synthesize_id_index(struct perf_tool *tool, perf_event__handler_ e->idx = sid->idx; e->cpu = sid->cpu.cpu; e->tid = sid->tid; + + if (sid->machine_pid) + e2_needed = true; + + e2 = (void *)ev + sz; + e2[i].machine_pid = sid->machine_pid; + e2[i].vcpu = sid->vcpu.cpu; } } - sz = sizeof(struct perf_record_id_index) + nr * sizeof(struct id_index_entry); - ev->id_index.header.size = sz; + sz = sizeof(struct perf_record_id_index) + nr * e1_sz; + ev->id_index.header.size = sz + (e2_needed ? nr * e2_sz : 0); ev->id_index.nr = nr; err = process(tool, ev, NULL, machine); @@ -1830,6 +1851,12 @@ int perf_event__synthesize_id_index(struct perf_tool *tool, perf_event__handler_ return err; } +int perf_event__synthesize_id_index(struct perf_tool *tool, perf_event__handler_t process, + struct evlist *evlist, struct machine *machine) +{ + return __perf_event__synthesize_id_index(tool, process, evlist, machine, 0); +} + int __machine__synthesize_threads(struct machine *machine, struct perf_tool *tool, struct target *target, struct perf_thread_map *threads, perf_event__handler_t process, bool needs_mmap, diff --git a/tools/perf/util/synthetic-events.h b/tools/perf/util/synthetic-events.h index b136ec3ec95d..81cb3d6af0b9 100644 --- a/tools/perf/util/synthetic-events.h +++ b/tools/perf/util/synthetic-events.h @@ -55,6 +55,7 @@ int perf_event__synthesize_extra_attr(struct perf_tool *tool, struct evlist *evs int perf_event__synthesize_extra_kmaps(struct perf_tool *tool, perf_event__handler_t process, struct machine *machine); int perf_event__synthesize_features(struct perf_tool *tool, struct perf_session *session, struct evlist *evlist, perf_event__handler_t process); int perf_event__synthesize_id_index(struct perf_tool *tool, perf_event__handler_t process, struct evlist *evlist, struct machine *machine); +int __perf_event__synthesize_id_index(struct perf_tool *tool, perf_event__handler_t process, struct evlist *evlist, struct machine *machine, size_t from); int perf_event__synthesize_id_sample(__u64 *array, u64 type, const struct perf_sample *sample); int perf_event__synthesize_kernel_mmap(struct perf_tool *tool, perf_event__handler_t process, struct machine *machine); int perf_event__synthesize_mmap_events(struct perf_tool *tool, union perf_event *event, pid_t pid, pid_t tgid, perf_event__handler_t process, struct machine *machine, bool mmap_data); From patchwork Mon Jul 11 09:31:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913251 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1194BC43334 for ; Mon, 11 Jul 2022 10:11:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231475AbiGKKLe (ORCPT ); Mon, 11 Jul 2022 06:11:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230088AbiGKKK1 (ORCPT ); Mon, 11 Jul 2022 06:10:27 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE11C7821D; Mon, 11 Jul 2022 02:33:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657531987; x=1689067987; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9LHhcnJuSuRIWLt7apSo+PbscteJazX7X8zRWVqb3Jk=; b=HOrOcqJFdX3pN7Svbg6HcD38YEZsPkEogswp/oUmjQ/DQqMky4o1fe+g g2mL6XWL2GwjOTfbzNzPx/vf9koAjx/rIc3V80eElqJPMncZc4byxNDpx M+Tq8R9b9WrVEMjlUzuK7ASZgDRv8Fewj3gMleBZ3nb4x6MTma3bcLMRY wiMTE08jsFKc56mQFw1ZQS+juERU9ao7aExoYTIxcuKZELQB8TNFEt/fD pHp/7LdshzRoPBoKw+QZy/0DNI7JlUy4vRK6iO7skqL0u4l25+bL15tnC T241i2vApWh6VKlEBRSfCiPBL40tQqyEBxg/wUmjk4T1eqFI1d0IsDDxw Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371564" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371564" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:07 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387065" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:05 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 11/35] perf session: Create guest machines from id_index Date: Mon, 11 Jul 2022 12:31:54 +0300 Message-Id: <20220711093218.10967-12-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Now that id_index has machine_pid, use it to create guest machines. Create the guest machines with an idle thread because guest events for "swapper" will be possible. Signed-off-by: Adrian Hunter Acked-by: Ian Rogers --- tools/perf/util/session.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 5141fe164e97..1af981d5ad3c 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2751,6 +2751,24 @@ void perf_session__fprintf_info(struct perf_session *session, FILE *fp, fprintf(fp, "# ========\n#\n"); } +static int perf_session__register_guest(struct perf_session *session, pid_t machine_pid) +{ + struct machine *machine = machines__findnew(&session->machines, machine_pid); + struct thread *thread; + + if (!machine) + return -ENOMEM; + + machine->single_address_space = session->machines.host.single_address_space; + + thread = machine__idle_thread(machine); + if (!thread) + return -ENOMEM; + thread__put(thread); + + return 0; +} + int perf_event__process_id_index(struct perf_session *session, union perf_event *event) { @@ -2762,6 +2780,7 @@ int perf_event__process_id_index(struct perf_session *session, size_t e2_sz = sizeof(struct id_index_entry_2); size_t etot_sz = e1_sz + e2_sz; struct id_index_entry_2 *e2; + pid_t last_pid = 0; max_nr = sz / e1_sz; nr = ie->nr; @@ -2787,6 +2806,7 @@ int perf_event__process_id_index(struct perf_session *session, for (i = 0; i < nr; i++, (e2 ? e2++ : 0)) { struct id_index_entry *e = &ie->entries[i]; struct perf_sample_id *sid; + int ret; if (dump_trace) { fprintf(stdout, " ... id: %"PRI_lu64, e->id); @@ -2814,6 +2834,17 @@ int perf_event__process_id_index(struct perf_session *session, sid->machine_pid = e2->machine_pid; sid->vcpu.cpu = e2->vcpu; + + if (!sid->machine_pid) + continue; + + if (sid->machine_pid != last_pid) { + ret = perf_session__register_guest(session, sid->machine_pid); + if (ret) + return ret; + last_pid = sid->machine_pid; + perf_guest = true; + } } return 0; } From patchwork Mon Jul 11 09:31:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913252 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 75BF5C433EF for ; Mon, 11 Jul 2022 10:11:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234683AbiGKKLh (ORCPT ); Mon, 11 Jul 2022 06:11:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230517AbiGKKKa (ORCPT ); Mon, 11 Jul 2022 06:10:30 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E73A45045; Mon, 11 Jul 2022 02:33:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657531990; x=1689067990; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QvQDeEVrAbIyF4HuhXZfOKtXRE1qctyELzoePKMwEPQ=; b=X7deRruWUJJYfC3R7QEt5XnzKNUNQugLR6JC9C4eu0L9TkuQW//lx+sH 7p6+I+miYOz8/9iKr1X4LgswiNYs/wIrwcKTih3zmppIz76cEaK62Gxkz dqfaix3BmcG72r2oHk9/IBrezH9XhK3N4S8rFkgGfn6W9e3Rwdkvfg+tW l7/56622TgAsLjQ8hYGKr6j108kRPEzV+tGZK/6apRX0vpN/y4iYX6THu ZtHcCkYWsHXiwCrsLKdx+k0CT5vmjYafcdDSB7XcrIXDprhr89u+5UeV4 mM02n+17w0fab3ldLy2Y623vDUk5AlCN+ZTs3j2/GWrKYnDIfHypfh+N4 g==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371566" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371566" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:10 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387079" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:08 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 12/35] perf tools: Add guest_cpu to hypervisor threads Date: Mon, 11 Jul 2022 12:31:55 +0300 Message-Id: <20220711093218.10967-13-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org It is possible to know which guest machine was running at a point in time based on the PID of the currently running host thread. That is, perf identifies guest machines by the PID of the hypervisor. To determine the guest CPU, put it on the hypervisor (QEMU) thread for that VCPU. This is done when processing the id_index which provides the necessary information. Signed-off-by: Adrian Hunter --- tools/perf/util/session.c | 18 ++++++++++++++++++ tools/perf/util/thread.c | 1 + tools/perf/util/thread.h | 1 + 3 files changed, 20 insertions(+) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 1af981d5ad3c..91a091c35945 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2769,6 +2769,20 @@ static int perf_session__register_guest(struct perf_session *session, pid_t mach return 0; } +static int perf_session__set_guest_cpu(struct perf_session *session, pid_t pid, + pid_t tid, int guest_cpu) +{ + struct machine *machine = &session->machines.host; + struct thread *thread = machine__findnew_thread(machine, pid, tid); + + if (!thread) + return -ENOMEM; + thread->guest_cpu = guest_cpu; + thread__put(thread); + + return 0; +} + int perf_event__process_id_index(struct perf_session *session, union perf_event *event) { @@ -2845,6 +2859,10 @@ int perf_event__process_id_index(struct perf_session *session, last_pid = sid->machine_pid; perf_guest = true; } + + ret = perf_session__set_guest_cpu(session, sid->machine_pid, e->tid, e2->vcpu); + if (ret) + return ret; } return 0; } diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 665e5c0618ed..e3e5427e1c3c 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -47,6 +47,7 @@ struct thread *thread__new(pid_t pid, pid_t tid) thread->tid = tid; thread->ppid = -1; thread->cpu = -1; + thread->guest_cpu = -1; thread->lbr_stitch_enable = false; INIT_LIST_HEAD(&thread->namespaces_list); INIT_LIST_HEAD(&thread->comm_list); diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h index b066fb30d203..241f300d7d6e 100644 --- a/tools/perf/util/thread.h +++ b/tools/perf/util/thread.h @@ -39,6 +39,7 @@ struct thread { pid_t tid; pid_t ppid; int cpu; + int guest_cpu; /* For QEMU thread */ refcount_t refcnt; bool comm_set; int comm_len; From patchwork Mon Jul 11 09:31:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913253 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 823CFC43334 for ; Mon, 11 Jul 2022 10:11:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232187AbiGKKLk (ORCPT ); Mon, 11 Jul 2022 06:11:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231338AbiGKKKc (ORCPT ); Mon, 11 Jul 2022 06:10:32 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E83D78201; Mon, 11 Jul 2022 02:33:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657531992; x=1689067992; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7kb4HBudqHsXBA4pBL5EI6hzUy1OLVfysrxe1GNe/1g=; b=Y7Z/9T5coS/cJ6q9ht1SH6Ou98Jc0rvizrC8tbkQLIb9GV8RTg26n+FG Vu0ppSsZ4q3xKEMnGJN5KA0wBB3n3l1OEEo8y0BZWjA5ybJnCMZMougGD fkTJBGDIx6c7dyyGs3RIyrOvSMURnd+6p/nEYPXF/RAnZcnOggRyM+BVm as1bjkGGKQ00AoJGpQqzdRkrA0RPpDoh5hZdYw6hhc2RlADSY5yiuOtBD vV5lUNCvz84x8yBj5fu9wAmAx2Z2adW6eVyiRoYOpICvFJxwy5aml49g2 hqOz+7fEt3NtGSWcBkSmK4MQv5j2cjtB0SSlwreBgMZOczVLhS6ZtD/Dh g==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371570" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371570" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:12 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387093" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:10 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 13/35] perf tools: Add machine_pid and vcpu to perf_sample Date: Mon, 11 Jul 2022 12:31:56 +0300 Message-Id: <20220711093218.10967-14-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When parsing a sample with a sample ID, copy machine_pid and vcpu from perf_sample_id to perf_sample. Note, machine_pid will be zero when unused, so only a non-zero value represents a guest machine. vcpu should be ignored if machine_pid is zero. Note also, machine_pid is used with events that have come from injecting a guest perf.data file, however guest events recorded on the host (i.e. using perf kvm) have the (QEMU) hypervisor process pid to identify them - refer machines__find_for_cpumode(). Signed-off-by: Adrian Hunter Acked-by: Ian Rogers --- tools/perf/util/event.h | 2 ++ tools/perf/util/evlist.c | 14 +++++++++++++- tools/perf/util/evsel.c | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/event.h b/tools/perf/util/event.h index cdd72e05fd28..a660f304f83c 100644 --- a/tools/perf/util/event.h +++ b/tools/perf/util/event.h @@ -148,6 +148,8 @@ struct perf_sample { u64 code_page_size; u64 cgroup; u32 flags; + u32 machine_pid; + u32 vcpu; u16 insn_len; u8 cpumode; u16 misc; diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 03fbe151b0c4..64f5a8074c0c 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1507,10 +1507,22 @@ int evlist__start_workload(struct evlist *evlist) int evlist__parse_sample(struct evlist *evlist, union perf_event *event, struct perf_sample *sample) { struct evsel *evsel = evlist__event2evsel(evlist, event); + int ret; if (!evsel) return -EFAULT; - return evsel__parse_sample(evsel, event, sample); + ret = evsel__parse_sample(evsel, event, sample); + if (ret) + return ret; + if (perf_guest && sample->id) { + struct perf_sample_id *sid = evlist__id2sid(evlist, sample->id); + + if (sid) { + sample->machine_pid = sid->machine_pid; + sample->vcpu = sid->vcpu.cpu; + } + } + return 0; } int evlist__parse_sample_timestamp(struct evlist *evlist, union perf_event *event, u64 *timestamp) diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 9a30ccb7b104..14396ea5a968 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2365,6 +2365,7 @@ int evsel__parse_sample(struct evsel *evsel, union perf_event *event, data->misc = event->header.misc; data->id = -1ULL; data->data_src = PERF_MEM_DATA_SRC_NONE; + data->vcpu = -1; if (event->header.type != PERF_RECORD_SAMPLE) { if (!evsel->core.attr.sample_id_all) From patchwork Mon Jul 11 09:31:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913254 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E0DEBCCA482 for ; Mon, 11 Jul 2022 10:11:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234697AbiGKKLo (ORCPT ); Mon, 11 Jul 2022 06:11:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234578AbiGKKKc (ORCPT ); Mon, 11 Jul 2022 06:10:32 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E70E578222; Mon, 11 Jul 2022 02:33:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657531994; x=1689067994; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/XMNx68flhNUFZWIfR1uqdJgwP7vZetAfA4HOwuX0ac=; b=j941F69Ri2hH88HXMZ94KM4ELsXkf5WvnLPcCCTJHa2Hrb06pwqQN9IN p1gl27lTO/yn35u9dhJoXXfcLewm+/qOOwMJBPH3qt/sxlyL2aLjN1DCV 81ZiWi4pLe0V+mIqdJg04T3+4glPIZ9NNMXL68OOrS/4AXX/ayNJZpJHG IeWEtjjGWAZ0Ki6Co3D2vs6MTXMrfojtquHZ06y7q8TTjXHD6B9/mSGXh fRpoyYXtgKV/F4avhtaT4Jt4NFXNw87+zuLkz74jYTB1BLiRTJlAldqld TfQBaFE1WAA+3YjuVdXubySRQwxGmCl2ckrfAEmi6rGUCEUFgXKXQ/1hh g==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371577" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371577" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:14 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387102" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:12 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 14/35] perf tools: Use sample->machine_pid to find guest machine Date: Mon, 11 Jul 2022 12:31:57 +0300 Message-Id: <20220711093218.10967-15-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org If machine_pid is set, use it to find the guest machine. Signed-off-by: Adrian Hunter Acked-by: Ian Rogers --- tools/perf/util/session.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 91a091c35945..f3e9fa557bc9 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1418,7 +1418,9 @@ static struct machine *machines__find_for_cpumode(struct machines *machines, (sample->cpumode == PERF_RECORD_MISC_GUEST_USER))) { u32 pid; - if (event->header.type == PERF_RECORD_MMAP + if (sample->machine_pid) + pid = sample->machine_pid; + else if (event->header.type == PERF_RECORD_MMAP || event->header.type == PERF_RECORD_MMAP2) pid = event->mmap.pid; else From patchwork Mon Jul 11 09:31:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913255 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AB38C43334 for ; Mon, 11 Jul 2022 10:11:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231594AbiGKKLq (ORCPT ); Mon, 11 Jul 2022 06:11:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234590AbiGKKKg (ORCPT ); Mon, 11 Jul 2022 06:10:36 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EA9A6415; Mon, 11 Jul 2022 02:33:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657531997; x=1689067997; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=oEbAfK9ZI0wBxkxPminDpw20jY+9VgtTDp4oTNs6CU8=; b=J9sU8E3YGxzFJpn63VocNdubhlsFxfrmIwo/7uajd9ZRldljzx03GkRE rlcx6iiME6OT0ob8q2cEl7JSEKhwy0rFrlI6VQUTAP3hq8jST04Xumr/5 2vKEtVCIJ4CXOHzT3WEJsyxiZub/+4GrmA/kuKn+DdXvmhevdIn6Xr2dJ 2h05MYG8a4ga6OfJ696xdl0paOwwATqfZdaV4Y6ZC4cbD7FaaHqPSyAZL F+Jei4watxKDcN0YInCTkjkbze/aK00NOvI5ElaZSbQKPtbmCYQ/516g/ XoW4Il0JMGRP7ghsfBOk5aSqkE6QBAwfwXiG13b8lBB+s5ilzm0CombWl g==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371584" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371584" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:17 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387108" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:15 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 15/35] perf script: Add machine_pid and vcpu Date: Mon, 11 Jul 2022 12:31:58 +0300 Message-Id: <20220711093218.10967-16-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add fields machine_pid and vcpu. These are displayed only if machine_pid is non-zero. Signed-off-by: Adrian Hunter --- tools/perf/Documentation/perf-script.txt | 7 ++++++- tools/perf/builtin-script.c | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt index e250ff5566cf..c09cc44e50ee 100644 --- a/tools/perf/Documentation/perf-script.txt +++ b/tools/perf/Documentation/perf-script.txt @@ -133,7 +133,8 @@ OPTIONS comm, tid, pid, time, cpu, event, trace, ip, sym, dso, addr, symoff, srcline, period, iregs, uregs, brstack, brstacksym, flags, bpf-output, brstackinsn, brstackinsnlen, brstackoff, callindent, insn, insnlen, synth, - phys_addr, metric, misc, srccode, ipc, data_page_size, code_page_size, ins_lat. + phys_addr, metric, misc, srccode, ipc, data_page_size, code_page_size, ins_lat, + machine_pid, vcpu. Field list can be prepended with the type, trace, sw or hw, to indicate to which event type the field list applies. e.g., -F sw:comm,tid,time,ip,sym and -F trace:time,cpu,trace @@ -226,6 +227,10 @@ OPTIONS The ipc (instructions per cycle) field is synthesized and may have a value when Instruction Trace decoding. + The machine_pid and vcpu fields are derived from data resulting from using + perf insert to insert a perf.data file recorded inside a virtual machine into + a perf.data file recorded on the host at the same time. + Finally, a user may not set fields to none for all event types. i.e., -F "" is not allowed. diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 4b00a50faf00..ac19fee62d8e 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -125,6 +125,8 @@ enum perf_output_field { PERF_OUTPUT_CODE_PAGE_SIZE = 1ULL << 34, PERF_OUTPUT_INS_LAT = 1ULL << 35, PERF_OUTPUT_BRSTACKINSNLEN = 1ULL << 36, + PERF_OUTPUT_MACHINE_PID = 1ULL << 37, + PERF_OUTPUT_VCPU = 1ULL << 38, }; struct perf_script { @@ -193,6 +195,8 @@ struct output_option { {.str = "code_page_size", .field = PERF_OUTPUT_CODE_PAGE_SIZE}, {.str = "ins_lat", .field = PERF_OUTPUT_INS_LAT}, {.str = "brstackinsnlen", .field = PERF_OUTPUT_BRSTACKINSNLEN}, + {.str = "machine_pid", .field = PERF_OUTPUT_MACHINE_PID}, + {.str = "vcpu", .field = PERF_OUTPUT_VCPU}, }; enum { @@ -746,6 +750,13 @@ static int perf_sample__fprintf_start(struct perf_script *script, int printed = 0; char tstr[128]; + if (PRINT_FIELD(MACHINE_PID) && sample->machine_pid) + printed += fprintf(fp, "VM:%5d ", sample->machine_pid); + + /* Print VCPU only for guest events i.e. with machine_pid */ + if (PRINT_FIELD(VCPU) && sample->machine_pid) + printed += fprintf(fp, "VCPU:%03d ", sample->vcpu); + if (PRINT_FIELD(COMM)) { const char *comm = thread ? thread__comm_str(thread) : ":-1"; From patchwork Mon Jul 11 09:31:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913256 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4411AC43334 for ; Mon, 11 Jul 2022 10:11:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234712AbiGKKLs (ORCPT ); Mon, 11 Jul 2022 06:11:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234621AbiGKKKm (ORCPT ); Mon, 11 Jul 2022 06:10:42 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3FF045079; Mon, 11 Jul 2022 02:33:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657531999; x=1689067999; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FqQdpjTqWQVvim+9bsHNS/QprUCFxf3kl2b4kFsDg9o=; b=AbDYK9dZ0g1uNm0PJz+J2mxyzE6+FJMYPYpoygMRhrr1KRpeFQj5T3pD ldH9mU5DyipKtb0M3j3yorME1So00mjGDscbFMcvcCFwutu2iB8PaBFrg SBMhgKajktK777lV9DrK/6CtLG1yqrk+hrVMD7cDnCo2HKd2NdUavDHNm aeTgHz6K5xW52O6HUyXh6xOy8f554TwsEr3KjWSzmgc6IM9G0XmLp7be0 AwViWVG2SkayNPSe7fPABMg0LdWWArpilzek5be9ph2bjDnfeJZGv5lFY 5L2PFTg0jINGUDXXupy6aumkFW3Q01M1Ph7ZEfScynkoOWGEtWPkB0/ke w==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371590" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371590" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:19 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387121" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:17 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 16/35] perf dlfilter: Add machine_pid and vcpu Date: Mon, 11 Jul 2022 12:31:59 +0300 Message-Id: <20220711093218.10967-17-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add machine_pid and vcpu to struct perf_dlfilter_sample. The 'size' can be used to determine if the values are present, however machine_pid is zero if unused in any case. vcpu should be ignored if machine_pid is zero. Signed-off-by: Adrian Hunter Acked-by: Ian Rogers --- tools/perf/Documentation/perf-dlfilter.txt | 22 ++++++++++++++++++++++ tools/perf/include/perf/perf_dlfilter.h | 8 ++++++++ tools/perf/util/dlfilter.c | 2 ++ 3 files changed, 32 insertions(+) diff --git a/tools/perf/Documentation/perf-dlfilter.txt b/tools/perf/Documentation/perf-dlfilter.txt index 594f5a5a0c9e..fb22e3b31dc5 100644 --- a/tools/perf/Documentation/perf-dlfilter.txt +++ b/tools/perf/Documentation/perf-dlfilter.txt @@ -107,9 +107,31 @@ struct perf_dlfilter_sample { __u64 raw_callchain_nr; /* Number of raw_callchain entries */ const __u64 *raw_callchain; /* Refer */ const char *event; + __s32 machine_pid; + __s32 vcpu; }; ---- +Note: 'machine_pid' and 'vcpu' are not original members, but were added together later. +'size' can be used to determine their presence at run time. +PERF_DLFILTER_HAS_MACHINE_PID will be defined if they are present at compile time. +For example: +[source,c] +---- +#include +#include +#include + +static inline bool have_machine_pid(const struct perf_dlfilter_sample *sample) +{ +#ifdef PERF_DLFILTER_HAS_MACHINE_PID + return sample->size >= offsetof(struct perf_dlfilter_sample, vcpu) + sizeof(sample->vcpu); +#else + return false; +#endif +} +---- + The perf_dlfilter_fns structure ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tools/perf/include/perf/perf_dlfilter.h b/tools/perf/include/perf/perf_dlfilter.h index 3eef03d661b4..a26e2f129f83 100644 --- a/tools/perf/include/perf/perf_dlfilter.h +++ b/tools/perf/include/perf/perf_dlfilter.h @@ -9,6 +9,12 @@ #include #include +/* + * The following macro can be used to determine if this header defines + * perf_dlfilter_sample machine_pid and vcpu. + */ +#define PERF_DLFILTER_HAS_MACHINE_PID + /* Definitions for perf_dlfilter_sample flags */ enum { PERF_DLFILTER_FLAG_BRANCH = 1ULL << 0, @@ -62,6 +68,8 @@ struct perf_dlfilter_sample { __u64 raw_callchain_nr; /* Number of raw_callchain entries */ const __u64 *raw_callchain; /* Refer */ const char *event; + __s32 machine_pid; + __s32 vcpu; }; /* diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c index db964d5a52af..54e4d4495e00 100644 --- a/tools/perf/util/dlfilter.c +++ b/tools/perf/util/dlfilter.c @@ -495,6 +495,8 @@ int dlfilter__do_filter_event(struct dlfilter *d, ASSIGN(misc); ASSIGN(raw_size); ASSIGN(raw_data); + ASSIGN(machine_pid); + ASSIGN(vcpu); if (sample->branch_stack) { d_sample.brstack_nr = sample->branch_stack->nr; From patchwork Mon Jul 11 09:32:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913257 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4871FC433EF for ; Mon, 11 Jul 2022 10:12:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234193AbiGKKMb (ORCPT ); Mon, 11 Jul 2022 06:12:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234145AbiGKKLO (ORCPT ); Mon, 11 Jul 2022 06:11:14 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8E6EFC0; Mon, 11 Jul 2022 02:33:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657532018; x=1689068018; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/a5qZZGpNtndm6rUQqcl56PShNnw1rr+WD+uSPlLNzA=; b=dgPdmbQsjJMA+I5S0LDgqN6aM/8fmZETci3N/Qlybq6/eJ6gFoP1G1TP j2eRFLMtwSypJ0ipQn1Xtl+dHcAl1jcLLEX43ScFadc2GUs1BaDnBOh54 W9txin2STEgdtFPvVXUdDXaiEUY5l0xFTkNhE16j72GrN6bdsq0NaK2/+ yGs8xRNKqlKKQgpveJsDOd6ItqOufnTBTvzAbcHAb+0FCUMQf7c1HdOIp bNv51kTBo4UuVcrmsegzsuhDPD9Nv3kyikgaP2O9DpYqpGVkr3hjcc8/M Al2blgGtJEfUPldhOY0+BkyQ3zd2AVxpZJaR5jw6p6I3gfsIJQKDCp++7 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371600" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371600" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:21 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387132" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:19 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 17/35] perf auxtrace: Add machine_pid and vcpu to auxtrace_error Date: Mon, 11 Jul 2022 12:32:00 +0300 Message-Id: <20220711093218.10967-18-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add machine_pid and vcpu to struct perf_record_auxtrace_error. The existing fmt member is used to identify the new format. The new members make it possible to easily differentiate errors from guest machines. Signed-off-by: Adrian Hunter Acked-by: Ian Rogers --- tools/lib/perf/include/perf/event.h | 2 ++ tools/perf/util/auxtrace.c | 30 +++++++++++++++---- tools/perf/util/auxtrace.h | 4 +++ .../scripting-engines/trace-event-python.c | 4 ++- tools/perf/util/session.c | 4 +++ 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/perf/event.h index c2dbd3e88885..556bb06798f2 100644 --- a/tools/lib/perf/include/perf/event.h +++ b/tools/lib/perf/include/perf/event.h @@ -279,6 +279,8 @@ struct perf_record_auxtrace_error { __u64 ip; __u64 time; char msg[MAX_AUXTRACE_ERROR_MSG]; + __u32 machine_pid; + __u32 vcpu; }; struct perf_record_aux { diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c index 511dd3caa1bc..6edab8a16de6 100644 --- a/tools/perf/util/auxtrace.c +++ b/tools/perf/util/auxtrace.c @@ -1189,9 +1189,10 @@ void auxtrace_buffer__free(struct auxtrace_buffer *buffer) free(buffer); } -void auxtrace_synth_error(struct perf_record_auxtrace_error *auxtrace_error, int type, - int code, int cpu, pid_t pid, pid_t tid, u64 ip, - const char *msg, u64 timestamp) +void auxtrace_synth_guest_error(struct perf_record_auxtrace_error *auxtrace_error, int type, + int code, int cpu, pid_t pid, pid_t tid, u64 ip, + const char *msg, u64 timestamp, + pid_t machine_pid, int vcpu) { size_t size; @@ -1207,12 +1208,26 @@ void auxtrace_synth_error(struct perf_record_auxtrace_error *auxtrace_error, int auxtrace_error->ip = ip; auxtrace_error->time = timestamp; strlcpy(auxtrace_error->msg, msg, MAX_AUXTRACE_ERROR_MSG); - - size = (void *)auxtrace_error->msg - (void *)auxtrace_error + - strlen(auxtrace_error->msg) + 1; + if (machine_pid) { + auxtrace_error->fmt = 2; + auxtrace_error->machine_pid = machine_pid; + auxtrace_error->vcpu = vcpu; + size = sizeof(*auxtrace_error); + } else { + size = (void *)auxtrace_error->msg - (void *)auxtrace_error + + strlen(auxtrace_error->msg) + 1; + } auxtrace_error->header.size = PERF_ALIGN(size, sizeof(u64)); } +void auxtrace_synth_error(struct perf_record_auxtrace_error *auxtrace_error, int type, + int code, int cpu, pid_t pid, pid_t tid, u64 ip, + const char *msg, u64 timestamp) +{ + auxtrace_synth_guest_error(auxtrace_error, type, code, cpu, pid, tid, + ip, msg, timestamp, 0, -1); +} + int perf_event__synthesize_auxtrace_info(struct auxtrace_record *itr, struct perf_tool *tool, struct perf_session *session, @@ -1662,6 +1677,9 @@ size_t perf_event__fprintf_auxtrace_error(union perf_event *event, FILE *fp) if (!e->fmt) msg = (const char *)&e->time; + if (e->fmt >= 2 && e->machine_pid) + ret += fprintf(fp, " machine_pid %d vcpu %d", e->machine_pid, e->vcpu); + ret += fprintf(fp, " cpu %d pid %d tid %d ip %#"PRI_lx64" code %u: %s\n", e->cpu, e->pid, e->tid, e->ip, e->code, msg); return ret; diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h index cd0d25c2751c..6a4fbfd34c6b 100644 --- a/tools/perf/util/auxtrace.h +++ b/tools/perf/util/auxtrace.h @@ -595,6 +595,10 @@ int auxtrace_index__process(int fd, u64 size, struct perf_session *session, bool needs_swap); void auxtrace_index__free(struct list_head *head); +void auxtrace_synth_guest_error(struct perf_record_auxtrace_error *auxtrace_error, int type, + int code, int cpu, pid_t pid, pid_t tid, u64 ip, + const char *msg, u64 timestamp, + pid_t machine_pid, int vcpu); void auxtrace_synth_error(struct perf_record_auxtrace_error *auxtrace_error, int type, int code, int cpu, pid_t pid, pid_t tid, u64 ip, const char *msg, u64 timestamp); diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index adba01b7d9dd..3367c5479199 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -1559,7 +1559,7 @@ static void python_process_auxtrace_error(struct perf_session *session __maybe_u msg = (const char *)&e->time; } - t = tuple_new(9); + t = tuple_new(11); tuple_set_u32(t, 0, e->type); tuple_set_u32(t, 1, e->code); @@ -1570,6 +1570,8 @@ static void python_process_auxtrace_error(struct perf_session *session __maybe_u tuple_set_u64(t, 6, tm); tuple_set_string(t, 7, msg); tuple_set_u32(t, 8, cpumode); + tuple_set_s32(t, 9, e->machine_pid); + tuple_set_s32(t, 10, e->vcpu); call_object(handler, t, handler_name); diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index f3e9fa557bc9..7ea0b91013ea 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -895,6 +895,10 @@ static void perf_event__auxtrace_error_swap(union perf_event *event, event->auxtrace_error.ip = bswap_64(event->auxtrace_error.ip); if (event->auxtrace_error.fmt) event->auxtrace_error.time = bswap_64(event->auxtrace_error.time); + if (event->auxtrace_error.fmt >= 2) { + event->auxtrace_error.machine_pid = bswap_32(event->auxtrace_error.machine_pid); + event->auxtrace_error.vcpu = bswap_32(event->auxtrace_error.vcpu); + } } static void perf_event__thread_map_swap(union perf_event *event, From patchwork Mon Jul 11 09:32:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913258 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF65CC43334 for ; Mon, 11 Jul 2022 10:12:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234745AbiGKKMg (ORCPT ); Mon, 11 Jul 2022 06:12:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234440AbiGKKLY (ORCPT ); Mon, 11 Jul 2022 06:11:24 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6024BDEAE; Mon, 11 Jul 2022 02:33:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657532020; x=1689068020; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pgd6eg3rwjK89yXrGs71hxRXZOcNGoFUVN/EP5zdtf0=; b=c2yyH9h/Ph3r4c8DROmuooHXmCuaRJRATPnNL1ZWWPqepOLhnXi9bPUh lRmlH2DJCLBEZW+h8HZ2MKdANNFaDQsvIMemx1TVmSENDgxcdFT3MQN63 VOnhbXqSPmWJjVLoN70QWt6BnCamitumg2LzWfyG0eIY1U7v5moLvlMz2 ExQWhnXQw57ISC8Xsgc/lembsxNKrXUnR7etz/CHyeDu6qkySkBlk7VAK bMmP6QIn0c5UiH8r9vnUhesGSdMTL5xW3n0JkrkaweVG0qGnKLwE7zm/9 u5h19TX+QB4s9kvR1rWUbMU6zXCgRRQcAvyTHchd6H2NQwhcrPANa47iL Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371606" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371606" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:24 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387146" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:22 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 18/35] perf script python: Add machine_pid and vcpu Date: Mon, 11 Jul 2022 12:32:01 +0300 Message-Id: <20220711093218.10967-19-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add machine_pid and vcpu to python sample events and context switch events. Signed-off-by: Adrian Hunter Acked-by: Ian Rogers --- .../perf/util/scripting-engines/trace-event-python.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/scripting-engines/trace-event-python.c b/tools/perf/util/scripting-engines/trace-event-python.c index 3367c5479199..5bbc1b16f368 100644 --- a/tools/perf/util/scripting-engines/trace-event-python.c +++ b/tools/perf/util/scripting-engines/trace-event-python.c @@ -861,6 +861,13 @@ static PyObject *get_perf_sample_dict(struct perf_sample *sample, brstacksym = python_process_brstacksym(sample, al->thread); pydict_set_item_string_decref(dict, "brstacksym", brstacksym); + if (sample->machine_pid) { + pydict_set_item_string_decref(dict_sample, "machine_pid", + _PyLong_FromLong(sample->machine_pid)); + pydict_set_item_string_decref(dict_sample, "vcpu", + _PyLong_FromLong(sample->vcpu)); + } + pydict_set_item_string_decref(dict_sample, "cpumode", _PyLong_FromLong((unsigned long)sample->cpumode)); @@ -1509,7 +1516,7 @@ static void python_do_process_switch(union perf_event *event, np_tid = event->context_switch.next_prev_tid; } - t = tuple_new(9); + t = tuple_new(11); if (!t) return; @@ -1522,6 +1529,8 @@ static void python_do_process_switch(union perf_event *event, tuple_set_s32(t, 6, machine->pid); tuple_set_bool(t, 7, out); tuple_set_bool(t, 8, out_preempt); + tuple_set_s32(t, 9, sample->machine_pid); + tuple_set_s32(t, 10, sample->vcpu); call_object(handler, t, handler_name); From patchwork Mon Jul 11 09:32:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913259 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15034C43334 for ; Mon, 11 Jul 2022 10:12:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231703AbiGKKMs (ORCPT ); Mon, 11 Jul 2022 06:12:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49492 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234681AbiGKKLg (ORCPT ); Mon, 11 Jul 2022 06:11:36 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D11BDF9A; Mon, 11 Jul 2022 02:33:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657532021; x=1689068021; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8rGCD6GA8/kbp19c1VCS4tx/aWpDWn0cNjJ7aA2rrME=; b=V+TFjPMw5ulBfZkvOqULXSGWTZ3J2Qyc2E5pPft+tAdr7JHBR6PcMN8o ikOSCBhVJ6gjlSh9DfhI34OgqfL77vZ9PM09wQLijT6HFZ2sz4kDFAvbi WJTO2kciz+8AedtTj+gFeB1pXaKg24I5BAJd3LpOQzcVASokz0WSh3Gpw rz63YDrDvNv2L5cw7o1Sfenqd/8pPgIs45RVneG+D9dMPI7A6L3KCY5EX TbqMPCNzIQ1flZ9td2dXndUN45jbdfEVlMih/5e9m7D0COfCFDTQX55/w 3m3QxfsP2Z2gxijo2/dxJObLbZNL5nii87BT2mqrYqy3aquMcGJOvN6O8 g==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371609" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371609" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:26 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387158" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:24 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 19/35] perf script python: intel-pt-events: Add machine_pid and vcpu Date: Mon, 11 Jul 2022 12:32:02 +0300 Message-Id: <20220711093218.10967-20-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add machine_pid and vcpu to the intel-pt-events.py script. Signed-off-by: Adrian Hunter Acked-by: Ian Rogers --- tools/perf/scripts/python/intel-pt-events.py | 32 +++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/tools/perf/scripts/python/intel-pt-events.py b/tools/perf/scripts/python/intel-pt-events.py index 9b7746b89381..6be7fd8fd615 100644 --- a/tools/perf/scripts/python/intel-pt-events.py +++ b/tools/perf/scripts/python/intel-pt-events.py @@ -197,7 +197,12 @@ def common_start_str(comm, sample): cpu = sample["cpu"] pid = sample["pid"] tid = sample["tid"] - return "%16s %5u/%-5u [%03u] %9u.%09u " % (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000) + if "machine_pid" in sample: + machine_pid = sample["machine_pid"] + vcpu = sample["vcpu"] + return "VM:%5d VCPU:%03d %16s %5u/%-5u [%03u] %9u.%09u " % (machine_pid, vcpu, comm, pid, tid, cpu, ts / 1000000000, ts %1000000000) + else: + return "%16s %5u/%-5u [%03u] %9u.%09u " % (comm, pid, tid, cpu, ts / 1000000000, ts %1000000000) def print_common_start(comm, sample, name): flags_disp = get_optional_null(sample, "flags_disp") @@ -379,9 +384,19 @@ def process_event(param_dict): sys.exit(1) def auxtrace_error(typ, code, cpu, pid, tid, ip, ts, msg, cpumode, *x): + if len(x) >= 2 and x[0]: + machine_pid = x[0] + vcpu = x[1] + else: + machine_pid = 0 + vcpu = -1 try: - print("%16s %5u/%-5u [%03u] %9u.%09u error type %u code %u: %s ip 0x%16x" % - ("Trace error", pid, tid, cpu, ts / 1000000000, ts %1000000000, typ, code, msg, ip)) + if machine_pid: + print("VM:%5d VCPU:%03d %16s %5u/%-5u [%03u] %9u.%09u error type %u code %u: %s ip 0x%16x" % + (machine_pid, vcpu, "Trace error", pid, tid, cpu, ts / 1000000000, ts %1000000000, typ, code, msg, ip)) + else: + print("%16s %5u/%-5u [%03u] %9u.%09u error type %u code %u: %s ip 0x%16x" % + ("Trace error", pid, tid, cpu, ts / 1000000000, ts %1000000000, typ, code, msg, ip)) except broken_pipe_exception: # Stop python printing broken pipe errors and traceback sys.stdout = open(os.devnull, 'w') @@ -396,14 +411,21 @@ def context_switch(ts, cpu, pid, tid, np_pid, np_tid, machine_pid, out, out_pree preempt_str = "preempt" else: preempt_str = "" + if len(x) >= 2 and x[0]: + machine_pid = x[0] + vcpu = x[1] + else: + vcpu = None; if machine_pid == -1: machine_str = "" - else: + elif vcpu is None: machine_str = "machine PID %d" % machine_pid + else: + machine_str = "machine PID %d VCPU %d" % (machine_pid, vcpu) switch_str = "%16s %5d/%-5d [%03u] %9u.%09u %5d/%-5d %s %s" % \ (out_str, pid, tid, cpu, ts / 1000000000, ts %1000000000, np_pid, np_tid, machine_str, preempt_str) if glb_args.all_switch_events: - print(switch_str); + print(switch_str) else: global glb_switch_str glb_switch_str[cpu] = switch_str From patchwork Mon Jul 11 09:32:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913260 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02232C433EF for ; Mon, 11 Jul 2022 10:12:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234768AbiGKKMu (ORCPT ); Mon, 11 Jul 2022 06:12:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231154AbiGKKLg (ORCPT ); Mon, 11 Jul 2022 06:11:36 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88DB32733; Mon, 11 Jul 2022 02:33:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657532021; x=1689068021; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=u/lZbP19TfSiTGeORdm6GBpFVMQbLNARmuyPv6JLXdE=; b=jKE5/UYUPDbfLhF3ZottgDnCSgL3e3kigs/BcD51blpZvV2FZxRZ4Z5s MPmd/gNKbaD0Qwq4bjzsGXY3r0atSSF0xjeuuHAzGLhU8ihUpQ9jHxGCw 0iZOaHRNj+h1+muBSjaolAP0lS0F2O86pqYwUCVycEfax1DpwROP4/ifN g070n7bN9XOZZs12lqiO/NCrY7sbmKQMmWV6QPUIKHxVSLuhSR84J7iQN SlXoCIs/tMdD7gAYrWZjFVPiJw+vblYjdKahGb1ou4o4CMeM1ZCkGehNR koAX7w4i8Ka31A9KZxrE3prCRElIswfv/BFi9ii/qQAjw1ab0GEKi1z1K g==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371628" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371628" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:29 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387172" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:26 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 20/35] perf tools: Remove also guest kcore_dir with host kcore_dir Date: Mon, 11 Jul 2022 12:32:03 +0300 Message-Id: <20220711093218.10967-21-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Copies of /proc/kallsyms, /proc/modules and an extract of /proc/kcore can be stored in the perf.data output directory under the subdirectory named kcore_dir. Guest machines will have their files also under subdirectories beginning kcore_dir__ followed by the machine pid. Remove these also when removing kcore_dir. Signed-off-by: Adrian Hunter Acked-by: Ian Rogers --- tools/perf/util/util.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index eeb83c80f458..9b02edf9311d 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -200,7 +200,7 @@ static int rm_rf_depth_pat(const char *path, int depth, const char **pat) return rmdir(path); } -static int rm_rf_kcore_dir(const char *path) +static int rm_rf_a_kcore_dir(const char *path, const char *name) { char kcore_dir_path[PATH_MAX]; const char *pat[] = { @@ -210,11 +210,44 @@ static int rm_rf_kcore_dir(const char *path) NULL, }; - snprintf(kcore_dir_path, sizeof(kcore_dir_path), "%s/kcore_dir", path); + snprintf(kcore_dir_path, sizeof(kcore_dir_path), "%s/%s", path, name); return rm_rf_depth_pat(kcore_dir_path, 0, pat); } +static bool kcore_dir_filter(const char *name __maybe_unused, struct dirent *d) +{ + const char *pat[] = { + "kcore_dir", + "kcore_dir__[1-9]*", + NULL, + }; + + return match_pat(d->d_name, pat); +} + +static int rm_rf_kcore_dir(const char *path) +{ + struct strlist *kcore_dirs; + struct str_node *nd; + int ret; + + kcore_dirs = lsdir(path, kcore_dir_filter); + + if (!kcore_dirs) + return 0; + + strlist__for_each_entry(nd, kcore_dirs) { + ret = rm_rf_a_kcore_dir(path, nd->s); + if (ret) + return ret; + } + + strlist__delete(kcore_dirs); + + return 0; +} + int rm_rf_perf_data(const char *path) { const char *pat[] = { From patchwork Mon Jul 11 09:32:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913261 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C5D1CCA47B for ; Mon, 11 Jul 2022 10:12:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230211AbiGKKM5 (ORCPT ); Mon, 11 Jul 2022 06:12:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234723AbiGKKL5 (ORCPT ); Mon, 11 Jul 2022 06:11:57 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AC4455A9; Mon, 11 Jul 2022 02:33:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657532024; x=1689068024; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uv97+oKSaSLbC0t8Sjzx49zmD3D9p0QxZCe3Ik4Va4c=; b=CxRfHm6LOixTggnVPrTB2MAYWmmvxudcTWnDp/1yKO0rVmXYUtUszEYI EAj+UB/GQLw8e0aIa0Ncd93cz57mZ08h4t1uPLTAzmmDeIZZ388SshArk +6dADbwhg2RNpmAXFuuDy7QUr2y2pmZK59zkYfrokeEhtZESBGAjCEJMS iRuMXtl5lIhgw2gFyA9cgZynqoScYW1tsEIia5hzU6GoIm68K8gwUlB2w fn+WqYmndq5CHE+DLlaYUkVLfxjY+AUXSlaPLqmnxu9a2RrQUnLea7K9X uTX2BlJN9wFGspC2vrCm9yaC7b/MnG2EkzeXpyKYs+/RwrStUXo+m07qp A==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371634" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371634" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:31 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387188" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:29 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 21/35] perf tools: Make has_kcore_dir() work also for guest kcore_dir Date: Mon, 11 Jul 2022 12:32:04 +0300 Message-Id: <20220711093218.10967-22-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Copies of /proc/kallsyms, /proc/modules and an extract of /proc/kcore can be stored in the perf.data output directory under the subdirectory named kcore_dir. Guest machines will have their files also under subdirectories beginning kcore_dir__ followed by the machine pid. Make has_kcore_dir() return true also if there is a guest machine kcore_dir. Signed-off-by: Adrian Hunter Acked-by: Ian Rogers --- tools/perf/util/data.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c index caabeac24c69..9782ccbe595d 100644 --- a/tools/perf/util/data.c +++ b/tools/perf/util/data.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -481,16 +482,21 @@ int perf_data__make_kcore_dir(struct perf_data *data, char *buf, size_t buf_sz) bool has_kcore_dir(const char *path) { - char *kcore_dir; - int ret; - - if (asprintf(&kcore_dir, "%s/kcore_dir", path) < 0) - return false; - - ret = access(kcore_dir, F_OK); + struct dirent *d = ERR_PTR(-EINVAL); + const char *name = "kcore_dir"; + DIR *dir = opendir(path); + size_t n = strlen(name); + bool result = false; + + if (dir) { + while (d && !result) { + d = readdir(dir); + result = d ? strncmp(d->d_name, name, n) : false; + } + closedir(dir); + } - free(kcore_dir); - return !ret; + return result; } char *perf_data__kallsyms_name(struct perf_data *data) From patchwork Mon Jul 11 09:32:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913262 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 643D7C43334 for ; Mon, 11 Jul 2022 10:13:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234642AbiGKKNS (ORCPT ); Mon, 11 Jul 2022 06:13:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231379AbiGKKML (ORCPT ); Mon, 11 Jul 2022 06:12:11 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B72E1A82C; Mon, 11 Jul 2022 02:33:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657532032; x=1689068032; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jRr+7NI/zfQcj5nU1mVzJyO/+NhSDeVlZPAKmSQ7DEE=; b=Nlx5XAOesV2AAf8Z9zwg/6FRYtjHplhqCwMvj3SFir1aM2vbABPZrKGp q3G9mAjGyl9UdXtThAQ6q+Z7Ui/3RXpzrYbSPFcdmNZBmZjwIglyrVAwB e6urdgZWbEbmCroKXhaFcZRTEkPUVX18uIW/nszCHw34jaON6jx2evSEP xARgmTGDUO2coj7gS1fDeQ5IuJd+/O0LeSrJcOqriQ6sJgPKoDEW/lYef yDQUsAnq+0emA2xWn33TsI1goXiZwOj1tvCQIT5QTqPI5DVBw34W1RIru 7+FxEwMbvFybPqPN2KArhbIkZMvsvePHwdkMVJw/yr80Hsgzb3DFRXunD w==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371642" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371642" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:33 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387201" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:31 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 22/35] perf tools: Automatically use guest kcore_dir if present Date: Mon, 11 Jul 2022 12:32:05 +0300 Message-Id: <20220711093218.10967-23-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When registering a guest machine using machine_pid from the id index, check perf.data for a matching kcore_dir subdirectory and set the kallsyms file name accordingly. If set, use it to find the machine's kernel symbols and object code (from kcore). Signed-off-by: Adrian Hunter --- tools/perf/util/data.c | 19 +++++++++++++++++++ tools/perf/util/data.h | 1 + tools/perf/util/machine.h | 1 + tools/perf/util/session.c | 2 ++ tools/perf/util/symbol.c | 6 ++++-- 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/data.c b/tools/perf/util/data.c index 9782ccbe595d..a7f68c309545 100644 --- a/tools/perf/util/data.c +++ b/tools/perf/util/data.c @@ -518,6 +518,25 @@ char *perf_data__kallsyms_name(struct perf_data *data) return kallsyms_name; } +char *perf_data__guest_kallsyms_name(struct perf_data *data, pid_t machine_pid) +{ + char *kallsyms_name; + struct stat st; + + if (!data->is_dir) + return NULL; + + if (asprintf(&kallsyms_name, "%s/kcore_dir__%d/kallsyms", data->path, machine_pid) < 0) + return NULL; + + if (stat(kallsyms_name, &st)) { + free(kallsyms_name); + return NULL; + } + + return kallsyms_name; +} + bool is_perf_data(const char *path) { bool ret = false; diff --git a/tools/perf/util/data.h b/tools/perf/util/data.h index 7de53d6e2d7f..173132d502f5 100644 --- a/tools/perf/util/data.h +++ b/tools/perf/util/data.h @@ -101,5 +101,6 @@ unsigned long perf_data__size(struct perf_data *data); int perf_data__make_kcore_dir(struct perf_data *data, char *buf, size_t buf_sz); bool has_kcore_dir(const char *path); char *perf_data__kallsyms_name(struct perf_data *data); +char *perf_data__guest_kallsyms_name(struct perf_data *data, pid_t machine_pid); bool is_perf_data(const char *path); #endif /* __PERF_DATA_H */ diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h index 5d7daf7cb7bc..d40b23c71420 100644 --- a/tools/perf/util/machine.h +++ b/tools/perf/util/machine.h @@ -48,6 +48,7 @@ struct machine { bool single_address_space; char *root_dir; char *mmap_name; + char *kallsyms_filename; struct threads threads[THREADS__TABLE_SIZE]; struct vdso_info *vdso_info; struct perf_env *env; diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 7ea0b91013ea..98e16659a149 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -2772,6 +2772,8 @@ static int perf_session__register_guest(struct perf_session *session, pid_t mach return -ENOMEM; thread__put(thread); + machine->kallsyms_filename = perf_data__guest_kallsyms_name(session->data, machine_pid); + return 0; } diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index f72baf636724..a4b22caa7c24 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -2300,11 +2300,13 @@ static int dso__load_kernel_sym(struct dso *dso, struct map *map) static int dso__load_guest_kernel_sym(struct dso *dso, struct map *map) { int err; - const char *kallsyms_filename = NULL; + const char *kallsyms_filename; struct machine *machine = map__kmaps(map)->machine; char path[PATH_MAX]; - if (machine__is_default_guest(machine)) { + if (machine->kallsyms_filename) { + kallsyms_filename = machine->kallsyms_filename; + } else if (machine__is_default_guest(machine)) { /* * if the user specified a vmlinux filename, use it and only * it, reporting errors to the user if it cannot be used. From patchwork Mon Jul 11 09:32:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913263 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C8D9C433EF for ; Mon, 11 Jul 2022 10:13:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232289AbiGKKNU (ORCPT ); Mon, 11 Jul 2022 06:13:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229975AbiGKKMZ (ORCPT ); Mon, 11 Jul 2022 06:12:25 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E5F31ADA1; Mon, 11 Jul 2022 02:33:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657532032; x=1689068032; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0PjRAq8c7ozAKryjV1wb1wkTewpQijIbzSfrTn770+0=; b=b+pmm2Gy+ZsHIl+mwzL7zseWNtDcpoWoeW0WBRL1WTE02neceM57NIYg tvL5na340URjOC3Hh36ssCNDYqJV8//QQclSrzat6YkhmQoJHcdO3rCEh bxSyY7T1uCUpAOOoWv1uUw6SuvZLCwSOL/WwiWtf9FUVGS4LH23al19RP ev9GoU1OEeIj5ZMT5fLDszGE2WPFMZro//2AfgfaBzPc6mBrf3rxhVzs6 lkO4N9sr49/tqPQOvTEDMD77VBuwcZBvj3dAvbWP1k2x/fkrf4J9TBDVE GFlrVaomM3oaOJOTstGtujiKBXd1+Ye6bipiOaaz1y92kj4Gx1j07By6K g==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371650" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371650" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:36 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387208" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:33 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 23/35] perf tools: Add reallocarray_as_needed() Date: Mon, 11 Jul 2022 12:32:06 +0300 Message-Id: <20220711093218.10967-24-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add helper reallocarray_as_needed() to reallocate an array to a larger size and initialize the extra entries to an arbitrary value. Signed-off-by: Adrian Hunter --- tools/perf/util/util.c | 33 +++++++++++++++++++++++++++++++++ tools/perf/util/util.h | 15 +++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 9b02edf9311d..391c1e928bd7 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include "cap.h" #include "strlist.h" @@ -500,3 +501,35 @@ char *filename_with_chroot(int pid, const char *filename) return new_name; } + +/* + * Reallocate an array *arr of size *arr_sz so that it is big enough to contain + * x elements of size msz, initializing new entries to *init_val or zero if + * init_val is NULL + */ +int do_realloc_array_as_needed(void **arr, size_t *arr_sz, size_t x, size_t msz, const void *init_val) +{ + size_t new_sz = *arr_sz; + void *new_arr; + size_t i; + + if (!new_sz) + new_sz = msz >= 64 ? 1 : roundup(64, msz); /* Start with at least 64 bytes */ + while (x >= new_sz) { + if (check_mul_overflow(new_sz, (size_t)2, &new_sz)) + return -ENOMEM; + } + if (new_sz == *arr_sz) + return 0; + new_arr = calloc(new_sz, msz); + if (!new_arr) + return -ENOMEM; + memcpy(new_arr, *arr, *arr_sz * msz); + if (init_val) { + for (i = *arr_sz; i < new_sz; i++) + memcpy(new_arr + (i * msz), init_val, msz); + } + *arr = new_arr; + *arr_sz = new_sz; + return 0; +} diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 0f78f1e7782d..c1f2d423a9ec 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -79,4 +79,19 @@ struct perf_debuginfod { void perf_debuginfod_setup(struct perf_debuginfod *di); char *filename_with_chroot(int pid, const char *filename); + +int do_realloc_array_as_needed(void **arr, size_t *arr_sz, size_t x, + size_t msz, const void *init_val); + +#define realloc_array_as_needed(a, n, x, v) ({ \ + typeof(x) __x = (x); \ + __x >= (n) ? \ + do_realloc_array_as_needed((void **)&(a), \ + &(n), \ + __x, \ + sizeof(*(a)), \ + (const void *)(v)) : \ + 0; \ + }) + #endif /* GIT_COMPAT_UTIL_H */ From patchwork Mon Jul 11 09:32:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12913269 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44941C43334 for ; Mon, 11 Jul 2022 10:13:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234774AbiGKKN3 (ORCPT ); Mon, 11 Jul 2022 06:13:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234740AbiGKKMb (ORCPT ); Mon, 11 Jul 2022 06:12:31 -0400 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8334E1C102; Mon, 11 Jul 2022 02:33:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657532032; x=1689068032; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eex2yZhJW9ZJuQwtRuyOx7kkR4fVnIDmB0UGb/smNN4=; b=NacfhUOZpgQUA7ee7ywL4p1jOvp9lNv8R2LTU5xd6tb0BbwrjrkoZuuM zvj84IGOk5279qzXS5KTYoDxBNpJtrIBxM8uWiOje5i9EDlwkjvTI+2B6 rLaU7VhxSD1WFRCeIQzmafojGar5GLuB6a242SFuuHCVAjfsAigRTbmVC nPRp1Twac4dd5w33Vh38H/KL0CaWBJyP6cFPcK+zTZlEzt57duIcNzH0h u0JVFOiXpe6M4qrjJszIgIToV+un/LYUii5c8iabClUtbFFp1JneTwHSd xG/U1WNhk2+IZ19Xh2okSXuO988boc0+pGpKS2zTK/c5GTx1Bw1yeYJTq A==; X-IronPort-AV: E=McAfee;i="6400,9594,10404"; a="283371655" X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="283371655" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:38 -0700 X-IronPort-AV: E=Sophos;i="5.92,262,1650956400"; d="scan'208";a="652387215" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.111]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Jul 2022 02:33:36 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Andi Kleen , linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH 24/35] perf inject: Add support for injecting guest sideband events Date: Mon, 11 Jul 2022 12:32:07 +0300 Message-Id: <20220711093218.10967-25-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com> References: <20220711093218.10967-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Inject events from a perf.data file recorded in a virtual machine into a perf.data file recorded on the host at the same time. Only side band events (e.g. mmap, comm, fork, exit etc) and build IDs are injected. Additionally, the guest kcore_dir is copied as kcore_dir__ appended to the machine PID. This is non-trivial because: o It is not possible to process 2 sessions simultaneously so instead events are first written to a temporary file. o To avoid conflict, guest sample IDs are replaced with new unused sample IDs. o Guest event's CPU is changed to be the host CPU because it is more useful for reporting and analysis. o Sample ID is mapped to machine PID which is recorded with VCPU in the id index. This is important to allow guest events to be related to the guest machine and VCPU. o Timestamps must be converted. o Events are inserted to obey finished-round ordering. The anticipated use-case is: - start recording sideband events in a guest machine - start recording an AUX area trace on the host which can trace also the guest (e.g. Intel PT) - run test case on the guest - stop recording on the host - stop recording on the guest - copy the guest perf.data file to the host - inject the guest perf.data file sideband events into the host perf.data file using perf inject - the resulting perf.data file can now be used Subsequent patches provide Intel PT support for this. Signed-off-by: Adrian Hunter --- tools/perf/Documentation/perf-inject.txt | 17 + tools/perf/builtin-inject.c | 1043 +++++++++++++++++++++- 2 files changed, 1059 insertions(+), 1 deletion(-) diff --git a/tools/perf/Documentation/perf-inject.txt b/tools/perf/Documentation/perf-inject.txt index 0570a1ccd344..646aa31586ed 100644 --- a/tools/perf/Documentation/perf-inject.txt +++ b/tools/perf/Documentation/perf-inject.txt @@ -85,6 +85,23 @@ include::itrace.txt[] without updating it. Currently this option is supported only by Intel PT, refer linkperf:perf-intel-pt[1] +--guest-data=,[,