Skip to content

Commit b9d266b

Browse files
ahunter6acmel
authored andcommitted
perf machine: Add ability to record the current tid for each cpu
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]>
1 parent bf49c35 commit b9d266b

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

tools/perf/util/machine.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
4545
thread__set_comm(thread, comm, 0);
4646
}
4747

48+
machine->current_tid = NULL;
49+
4850
return 0;
4951
}
5052

@@ -104,6 +106,7 @@ void machine__exit(struct machine *machine)
104106
dsos__delete(&machine->user_dsos);
105107
dsos__delete(&machine->kernel_dsos);
106108
zfree(&machine->root_dir);
109+
zfree(&machine->current_tid);
107110
}
108111

109112
void machine__delete(struct machine *machine)
@@ -1481,3 +1484,46 @@ int __machine__synthesize_threads(struct machine *machine, struct perf_tool *too
14811484
/* command specified */
14821485
return 0;
14831486
}
1487+
1488+
pid_t machine__get_current_tid(struct machine *machine, int cpu)
1489+
{
1490+
if (cpu < 0 || cpu >= MAX_NR_CPUS || !machine->current_tid)
1491+
return -1;
1492+
1493+
return machine->current_tid[cpu];
1494+
}
1495+
1496+
int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid,
1497+
pid_t tid)
1498+
{
1499+
struct thread *thread;
1500+
1501+
if (cpu < 0)
1502+
return -EINVAL;
1503+
1504+
if (!machine->current_tid) {
1505+
int i;
1506+
1507+
machine->current_tid = calloc(MAX_NR_CPUS, sizeof(pid_t));
1508+
if (!machine->current_tid)
1509+
return -ENOMEM;
1510+
for (i = 0; i < MAX_NR_CPUS; i++)
1511+
machine->current_tid[i] = -1;
1512+
}
1513+
1514+
if (cpu >= MAX_NR_CPUS) {
1515+
pr_err("Requested CPU %d too large. ", cpu);
1516+
pr_err("Consider raising MAX_NR_CPUS\n");
1517+
return -EINVAL;
1518+
}
1519+
1520+
machine->current_tid[cpu] = tid;
1521+
1522+
thread = machine__findnew_thread(machine, pid, tid);
1523+
if (!thread)
1524+
return -ENOMEM;
1525+
1526+
thread->cpu = cpu;
1527+
1528+
return 0;
1529+
}

tools/perf/util/machine.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ struct machine {
3333
struct map_groups kmaps;
3434
struct map *vmlinux_maps[MAP__NR_TYPES];
3535
symbol_filter_t symbol_filter;
36+
pid_t *current_tid;
3637
};
3738

3839
static inline
@@ -191,4 +192,8 @@ int machine__synthesize_threads(struct machine *machine, struct target *target,
191192
perf_event__process, data_mmap);
192193
}
193194

195+
pid_t machine__get_current_tid(struct machine *machine, int cpu);
196+
int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid,
197+
pid_t tid);
198+
194199
#endif /* __PERF_MACHINE_H */

0 commit comments

Comments
 (0)