Em Wed, Dec 11, 2013 at 02:36:26PM +0200, Alexander Shishkin escreveu: > 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. > > > +++ 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; > +}
What is the problem with: struct thread *thread = machine__find_thread(machine, tid); pid_t pid = thread->pid_; int cpu = thread->cpu; In your case you'll have: int pid; int cpu = machine__get_thread_cpu(machine, tid, &pid); Which is slightly more compact, but then we end up with a function that from its name should just get a 'cpu' but also asks for the pid. I think it is better to just use what we have (machine__find_thread), have a 'thread' variable and then use any of its members, directly. - ARnaldo -- 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/