OSDN Git Service

perf auxtrace: Add machine_pid and vcpu to auxtrace_error
authorAdrian Hunter <adrian.hunter@intel.com>
Mon, 11 Jul 2022 09:32:00 +0000 (12:32 +0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 20 Jul 2022 14:08:17 +0000 (11:08 -0300)
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>
Acked-by: Ian Rogers <irogers@google.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: kvm@vger.kernel.org
Link: https://lore.kernel.org/r/20220711093218.10967-18-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/lib/perf/include/perf/event.h
tools/perf/util/auxtrace.c
tools/perf/util/auxtrace.h
tools/perf/util/scripting-engines/trace-event-python.c
tools/perf/util/session.c

index c2dbd3e..556bb06 100644 (file)
@@ -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 {
index 511dd3c..6edab8a 100644 (file)
@@ -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;
index cd0d25c..6a4fbfd 100644 (file)
@@ -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);
index adba01b..3367c54 100644 (file)
@@ -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);
 
index f3e9fa5..7ea0b91 100644 (file)
@@ -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,