Commit fcda5ff7 authored by Adrian Hunter's avatar Adrian Hunter Committed by Arnaldo Carvalho de Melo

perf machine: Factor out machines__find_guest()

Factor out machines__find_guest() so it can be re-used.
Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Acked-by: default avatarAndi Kleen <ak@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: https://lore.kernel.org/r/20210218095801.19576-6-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 80a03886
...@@ -369,6 +369,15 @@ struct machine *machines__findnew(struct machines *machines, pid_t pid) ...@@ -369,6 +369,15 @@ struct machine *machines__findnew(struct machines *machines, pid_t pid)
return machine; return machine;
} }
struct machine *machines__find_guest(struct machines *machines, pid_t pid)
{
struct machine *machine = machines__find(machines, pid);
if (!machine)
machine = machines__findnew(machines, DEFAULT_GUEST_KERNEL_ID);
return machine;
}
void machines__process_guests(struct machines *machines, void machines__process_guests(struct machines *machines,
machine__process_t process, void *data) machine__process_t process, void *data)
{ {
......
...@@ -162,6 +162,7 @@ struct machine *machines__add(struct machines *machines, pid_t pid, ...@@ -162,6 +162,7 @@ struct machine *machines__add(struct machines *machines, pid_t pid,
struct machine *machines__find_host(struct machines *machines); struct machine *machines__find_host(struct machines *machines);
struct machine *machines__find(struct machines *machines, pid_t pid); struct machine *machines__find(struct machines *machines, pid_t pid);
struct machine *machines__findnew(struct machines *machines, pid_t pid); struct machine *machines__findnew(struct machines *machines, pid_t pid);
struct machine *machines__find_guest(struct machines *machines, pid_t pid);
void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size); void machines__set_id_hdr_size(struct machines *machines, u16 id_hdr_size);
void machines__set_comm_exec(struct machines *machines, bool comm_exec); void machines__set_comm_exec(struct machines *machines, bool comm_exec);
......
...@@ -1356,8 +1356,6 @@ static struct machine *machines__find_for_cpumode(struct machines *machines, ...@@ -1356,8 +1356,6 @@ static struct machine *machines__find_for_cpumode(struct machines *machines,
union perf_event *event, union perf_event *event,
struct perf_sample *sample) struct perf_sample *sample)
{ {
struct machine *machine;
if (perf_guest && if (perf_guest &&
((sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL) || ((sample->cpumode == PERF_RECORD_MISC_GUEST_KERNEL) ||
(sample->cpumode == PERF_RECORD_MISC_GUEST_USER))) { (sample->cpumode == PERF_RECORD_MISC_GUEST_USER))) {
...@@ -1369,10 +1367,7 @@ static struct machine *machines__find_for_cpumode(struct machines *machines, ...@@ -1369,10 +1367,7 @@ static struct machine *machines__find_for_cpumode(struct machines *machines,
else else
pid = sample->pid; pid = sample->pid;
machine = machines__find(machines, pid); return machines__find_guest(machines, pid);
if (!machine)
machine = machines__findnew(machines, DEFAULT_GUEST_KERNEL_ID);
return machine;
} }
return &machines->host; return &machines->host;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment