lkml.org 
[lkml]   [2013]   [Dec]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v0 14/71] perf tools: Add cpu to struct thread
On 11/12/13 16:19, Arnaldo Carvalho de Melo wrote:
> Em Wed, Dec 11, 2013 at 02:36:26PM +0200, Alexander Shishkin escreveu:
>> 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.
>>
>>
>> +++ 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.

OK





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