All of lore.kernel.org
 help / color / mirror / Atom feed
From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	Ian Rogers <irogers@google.com>, Andi Kleen <ak@linux.intel.com>,
	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	[thread overview]
Message-ID: <20220711093218.10967-18-adrian.hunter@intel.com> (raw)
In-Reply-To: <20220711093218.10967-1-adrian.hunter@intel.com>

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 <adrian.hunter@intel.com>
---
 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,
-- 
2.25.1


  parent reply	other threads:[~2022-07-11 10:12 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-11  9:31 [PATCH 00/35] perf intel-pt: Add support for tracing virtual machine user space on the host Adrian Hunter
2022-07-11  9:31 ` [PATCH 01/35] perf tools: Fix dso_id inode generation comparison Adrian Hunter
2022-07-18 14:57   ` Arnaldo Carvalho de Melo
2022-07-19 10:18     ` Adrian Hunter
2022-07-19 15:13       ` Ian Rogers
2022-07-19 19:16         ` Arnaldo Carvalho de Melo
2022-07-11  9:31 ` [PATCH 02/35] perf tools: Export dsos__for_each_with_build_id() Adrian Hunter
2022-07-19 16:55   ` Ian Rogers
2022-07-11  9:31 ` [PATCH 03/35] perf ordered_events: Add ordered_events__last_flush_time() Adrian Hunter
2022-07-19 16:56   ` Ian Rogers
2022-07-11  9:31 ` [PATCH 04/35] perf tools: Export perf_event__process_finished_round() Adrian Hunter
2022-07-19 17:04   ` Ian Rogers
2022-08-09 11:37     ` Adrian Hunter
2022-07-11  9:31 ` [PATCH 05/35] perf tools: Factor out evsel__id_hdr_size() Adrian Hunter
2022-07-19 17:09   ` Ian Rogers
2022-08-09 11:49     ` Adrian Hunter
2022-08-09 17:07       ` Ian Rogers
2022-07-11  9:31 ` [PATCH 06/35] perf tools: Add perf_event__synthesize_id_sample() Adrian Hunter
2022-07-19 17:10   ` Ian Rogers
2022-07-11  9:31 ` [PATCH 07/35] perf script: Add --dump-unsorted-raw-trace option Adrian Hunter
2022-07-19 17:11   ` Ian Rogers
2022-07-11  9:31 ` [PATCH 08/35] perf buildid-cache: Add guestmount'd files to the build ID cache Adrian Hunter
2022-07-19 17:41   ` Ian Rogers
2022-08-09 12:21     ` Adrian Hunter
2022-07-11  9:31 ` [PATCH 09/35] perf buildid-cache: Do not require purge files to also be in the file system Adrian Hunter
2022-07-19 17:44   ` Ian Rogers
2022-07-11  9:31 ` [PATCH 10/35] perf tools: Add machine_pid and vcpu to id_index Adrian Hunter
2022-07-19 17:48   ` Ian Rogers
2022-08-09 12:19     ` Adrian Hunter
2022-07-11  9:31 ` [PATCH 11/35] perf session: Create guest machines from id_index Adrian Hunter
2022-07-19 17:51   ` Ian Rogers
2022-07-11  9:31 ` [PATCH 12/35] perf tools: Add guest_cpu to hypervisor threads Adrian Hunter
2022-07-20  0:23   ` Ian Rogers
2022-07-11  9:31 ` [PATCH 13/35] perf tools: Add machine_pid and vcpu to perf_sample Adrian Hunter
2022-07-20  0:36   ` Ian Rogers
2022-07-11  9:31 ` [PATCH 14/35] perf tools: Use sample->machine_pid to find guest machine Adrian Hunter
2022-07-20  0:37   ` Ian Rogers
2022-07-11  9:31 ` [PATCH 15/35] perf script: Add machine_pid and vcpu Adrian Hunter
2022-07-20  0:39   ` Ian Rogers
2022-07-11  9:31 ` [PATCH 16/35] perf dlfilter: " Adrian Hunter
2022-07-20  0:42   ` Ian Rogers
2022-07-11  9:32 ` Adrian Hunter [this message]
2022-07-20  0:43   ` [PATCH 17/35] perf auxtrace: Add machine_pid and vcpu to auxtrace_error Ian Rogers
2022-07-11  9:32 ` [PATCH 18/35] perf script python: Add machine_pid and vcpu Adrian Hunter
2022-07-20  0:43   ` Ian Rogers
2022-07-11  9:32 ` [PATCH 19/35] perf script python: intel-pt-events: " Adrian Hunter
2022-07-20  0:44   ` Ian Rogers
2022-07-11  9:32 ` [PATCH 20/35] perf tools: Remove also guest kcore_dir with host kcore_dir Adrian Hunter
2022-07-20  0:45   ` Ian Rogers
2022-07-11  9:32 ` [PATCH 21/35] perf tools: Make has_kcore_dir() work also for guest kcore_dir Adrian Hunter
2022-07-20  0:49   ` Ian Rogers
2022-07-11  9:32 ` [PATCH 22/35] perf tools: Automatically use guest kcore_dir if present Adrian Hunter
2022-07-20  0:51   ` Ian Rogers
2022-07-11  9:32 ` [PATCH 23/35] perf tools: Add reallocarray_as_needed() Adrian Hunter
2022-07-20  0:55   ` Ian Rogers
2022-08-09 16:48     ` Adrian Hunter
2022-07-11  9:32 ` [PATCH 24/35] perf inject: Add support for injecting guest sideband events Adrian Hunter
2022-07-20  1:06   ` Ian Rogers
2022-08-11 17:19     ` Adrian Hunter
2022-07-11  9:32 ` [PATCH 25/35] perf machine: Use realloc_array_as_needed() in machine__set_current_tid() Adrian Hunter
2022-07-11  9:32 ` [PATCH 26/35] perf tools: Handle injected guest kernel mmap event Adrian Hunter
2022-07-20  1:09   ` Ian Rogers
2022-07-11  9:32 ` [PATCH 27/35] perf tools: Add perf_event__is_guest() Adrian Hunter
2022-07-20  1:11   ` Ian Rogers
2022-07-20 14:06     ` Arnaldo Carvalho de Melo
2022-07-20 14:56       ` Ian Rogers
2022-07-11  9:32 ` [PATCH 28/35] perf intel-pt: Remove guest_machine_pid Adrian Hunter
2022-07-20  1:12   ` Ian Rogers
2022-07-11  9:32 ` [PATCH 29/35] perf intel-pt: Add some more logging to intel_pt_walk_next_insn() Adrian Hunter
2022-07-20  1:13   ` Ian Rogers
2022-07-11  9:32 ` [PATCH 30/35] perf intel-pt: Track guest context switches Adrian Hunter
2022-07-20  1:13   ` Ian Rogers
2022-07-11  9:32 ` [PATCH 31/35] perf intel-pt: Disable sync switch with guest sideband Adrian Hunter
2022-07-20  1:14   ` Ian Rogers
2022-07-11  9:32 ` [PATCH 32/35] perf intel-pt: Determine guest thread from " Adrian Hunter
2022-07-20  1:15   ` Ian Rogers
2022-07-11  9:32 ` [PATCH 33/35] perf intel-pt: Add machine_pid and vcpu to auxtrace_error Adrian Hunter
2022-07-20  5:27   ` Ian Rogers
2022-07-11  9:32 ` [PATCH 34/35] perf intel-pt: Use guest pid/tid etc in guest samples Adrian Hunter
2022-07-20  5:28   ` Ian Rogers
2022-07-11  9:32 ` [PATCH 35/35] perf intel-pt: Add documentation for tracing guest machine user space Adrian Hunter
2022-07-20  5:29   ` Ian Rogers
2022-07-18 15:28 ` [PATCH 00/35] perf intel-pt: Add support for tracing virtual machine user space on the host Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220711093218.10967-18-adrian.hunter@intel.com \
    --to=adrian.hunter@intel.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.