lkml.org 
[lkml]   [2013]   [Dec]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v0 14/71] perf tools: Add cpu to struct thread
Date
From: Adrian Hunter <adrian.hunter@intel.com>

Tools may wish to track on which cpu a thread
is running. Add 'cpu' to struct thread for
that purpose. Also add machine functions to
get / set the cpu for a tid.

This will be used to determine the cpu when
decoding a per-thread Instruction Trace.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
tools/perf/util/machine.c | 26 ++++++++++++++++++++++++++
tools/perf/util/machine.h | 3 +++
tools/perf/util/thread.c | 1 +
tools/perf/util/thread.h | 1 +
4 files changed, 31 insertions(+)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 55f3608..52fbfb6 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -1412,3 +1412,29 @@ pid_t machine__get_thread_pid(struct machine *machine, pid_t tid)

return thread->pid_;
}
+
+int machine__get_thread_cpu(struct machine *machine, pid_t tid, pid_t *pid)
+{
+ struct thread *thread = machine__find_thread(machine, tid);
+
+ if (!thread)
+ return -1;
+
+ if (pid)
+ *pid = thread->pid_;
+
+ return thread->cpu;
+}
+
+int machine__set_thread_cpu(struct machine *machine, pid_t pid, pid_t tid,
+ int cpu)
+{
+ struct thread *thread = machine__findnew_thread(machine, pid, tid);
+
+ if (!thread)
+ return -ENOMEM;
+
+ thread->cpu = cpu;
+
+ return 0;
+}
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index b800a5a..27486af 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -191,5 +191,8 @@ int machine__synthesize_threads(struct machine *machine, struct target *target,
}

pid_t machine__get_thread_pid(struct machine *machine, pid_t tid);
+int machine__get_thread_cpu(struct machine *machine, pid_t tid, pid_t *pid);
+int machine__set_thread_cpu(struct machine *machine, pid_t pid, pid_t tid,
+ int cpu);

#endif /* __PERF_MACHINE_H */
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index 49eaf1d..a120af3 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -19,6 +19,7 @@ struct thread *thread__new(pid_t pid, pid_t tid)
thread->pid_ = pid;
thread->tid = tid;
thread->ppid = -1;
+ thread->cpu = -1;
INIT_LIST_HEAD(&thread->comm_list);

comm_str = malloc(32);
diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
index 5b856bf..7914050 100644
--- a/tools/perf/util/thread.h
+++ b/tools/perf/util/thread.h
@@ -17,6 +17,7 @@ struct thread {
pid_t pid_; /* Not all tools update this */
pid_t tid;
pid_t ppid;
+ int cpu;
char shortname[3];
bool comm_set;
bool dead; /* if set thread has exited */
--
1.8.5.1


\
 
 \ /
  Last update: 2013-12-11 17:41    [W:0.984 / U:0.140 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site