From: Adrian Hunter <adrian.hun...@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.hun...@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 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/