summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2021-02-18 10:57:56 +0100
committerArnaldo Carvalho de Melo <acme@redhat.com>2021-02-18 20:14:33 +0100
commit3035cb6cbd2d62a764fa451ed9534eafdd0b446c (patch)
tree4b7fc4f6d8eee83223cd9214909d6bab7d422459
parentperf machine: Factor out machines__find_guest() (diff)
downloadlinux-3035cb6cbd2d62a764fa451ed9534eafdd0b446c.tar.xz
linux-3035cb6cbd2d62a764fa451ed9534eafdd0b446c.zip
perf machine: Factor out machine__idle_thread()
Factor out machine__idle_thread() so it can be re-used for guest machines. A thread is needed to find executable code, even for the guest kernel. To avoid possible future pid number conflicts, the idle thread can be used. Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Acked-by: Andi 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-7-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/machine.c18
-rw-r--r--tools/perf/util/machine.h1
-rw-r--r--tools/perf/util/session.c25
3 files changed, 22 insertions, 22 deletions
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 90703b7ca6de..b5c2d8be4144 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -598,6 +598,24 @@ struct thread *machine__find_thread(struct machine *machine, pid_t pid,
return th;
}
+/*
+ * Threads are identified by pid and tid, and the idle task has pid == tid == 0.
+ * So here a single thread is created for that, but actually there is a separate
+ * idle task per cpu, so there should be one 'struct thread' per cpu, but there
+ * is only 1. That causes problems for some tools, requiring workarounds. For
+ * example get_idle_thread() in builtin-sched.c, or thread_stack__per_cpu().
+ */
+struct thread *machine__idle_thread(struct machine *machine)
+{
+ struct thread *thread = machine__findnew_thread(machine, 0, 0);
+
+ if (!thread || thread__set_comm(thread, "swapper", 0) ||
+ thread__set_namespaces(thread, 0, NULL))
+ pr_err("problem inserting idle task for machine pid %d\n", machine->pid);
+
+ return thread;
+}
+
struct comm *machine__thread_exec_comm(struct machine *machine,
struct thread *thread)
{
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index 022c19ecd287..7377ed6efdf1 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -106,6 +106,7 @@ u8 machine__addr_cpumode(struct machine *machine, u8 cpumode, u64 addr);
struct thread *machine__find_thread(struct machine *machine, pid_t pid,
pid_t tid);
+struct thread *machine__idle_thread(struct machine *machine);
struct comm *machine__thread_exec_comm(struct machine *machine,
struct thread *thread);
diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 7b0d0c9e3dd1..859832a82496 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -1789,32 +1789,13 @@ struct thread *perf_session__findnew(struct perf_session *session, pid_t pid)
return machine__findnew_thread(&session->machines.host, -1, pid);
}
-/*
- * Threads are identified by pid and tid, and the idle task has pid == tid == 0.
- * So here a single thread is created for that, but actually there is a separate
- * idle task per cpu, so there should be one 'struct thread' per cpu, but there
- * is only 1. That causes problems for some tools, requiring workarounds. For
- * example get_idle_thread() in builtin-sched.c, or thread_stack__per_cpu().
- */
int perf_session__register_idle_thread(struct perf_session *session)
{
- struct thread *thread;
- int err = 0;
-
- thread = machine__findnew_thread(&session->machines.host, 0, 0);
- if (thread == NULL || thread__set_comm(thread, "swapper", 0)) {
- pr_err("problem inserting idle task.\n");
- err = -1;
- }
+ struct thread *thread = machine__idle_thread(&session->machines.host);
- if (thread == NULL || thread__set_namespaces(thread, 0, NULL)) {
- pr_err("problem inserting idle task.\n");
- err = -1;
- }
-
- /* machine__findnew_thread() got the thread, so put it */
+ /* machine__idle_thread() got the thread, so put it */
thread__put(thread);
- return err;
+ return thread ? 0 : -1;
}
static void