Skip to content

Commit

Permalink
perf machine: Add ability to record the current tid for each cpu
Browse files Browse the repository at this point in the history
Add an array to struct machine to store the current tid running on each
cpu.

Add machine functions to get / set the tid for a cpu.

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

Signed-off-by: Adrian Hunter <[email protected]>
Cc: David Ahern <[email protected]>
Cc: Frederic Weisbecker <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Stephane Eranian <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
  • Loading branch information
ahunter6 authored and acmel committed Jul 23, 2014
1 parent bf49c35 commit b9d266b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tools/perf/util/machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
thread__set_comm(thread, comm, 0);
}

machine->current_tid = NULL;

return 0;
}

Expand Down Expand Up @@ -104,6 +106,7 @@ void machine__exit(struct machine *machine)
dsos__delete(&machine->user_dsos);
dsos__delete(&machine->kernel_dsos);
zfree(&machine->root_dir);
zfree(&machine->current_tid);
}

void machine__delete(struct machine *machine)
Expand Down Expand Up @@ -1481,3 +1484,46 @@ int __machine__synthesize_threads(struct machine *machine, struct perf_tool *too
/* command specified */
return 0;
}

pid_t machine__get_current_tid(struct machine *machine, int cpu)
{
if (cpu < 0 || cpu >= MAX_NR_CPUS || !machine->current_tid)
return -1;

return machine->current_tid[cpu];
}

int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid,
pid_t tid)
{
struct thread *thread;

if (cpu < 0)
return -EINVAL;

if (!machine->current_tid) {
int i;

machine->current_tid = calloc(MAX_NR_CPUS, sizeof(pid_t));
if (!machine->current_tid)
return -ENOMEM;
for (i = 0; i < MAX_NR_CPUS; i++)
machine->current_tid[i] = -1;
}

if (cpu >= MAX_NR_CPUS) {
pr_err("Requested CPU %d too large. ", cpu);
pr_err("Consider raising MAX_NR_CPUS\n");
return -EINVAL;
}

machine->current_tid[cpu] = tid;

thread = machine__findnew_thread(machine, pid, tid);
if (!thread)
return -ENOMEM;

thread->cpu = cpu;

return 0;
}
5 changes: 5 additions & 0 deletions tools/perf/util/machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ struct machine {
struct map_groups kmaps;
struct map *vmlinux_maps[MAP__NR_TYPES];
symbol_filter_t symbol_filter;
pid_t *current_tid;
};

static inline
Expand Down Expand Up @@ -191,4 +192,8 @@ int machine__synthesize_threads(struct machine *machine, struct target *target,
perf_event__process, data_mmap);
}

pid_t machine__get_current_tid(struct machine *machine, int cpu);
int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid,
pid_t tid);

#endif /* __PERF_MACHINE_H */

0 comments on commit b9d266b

Please sign in to comment.