aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2014-07-22 09:17:25 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-07-23 10:35:43 -0400
commitb9d266baac0429f70df3f9cf751b045730d612e3 (patch)
treed4625908c8f0d9e972a489da208725f460048e4a
parentbf49c35f630452d85c9cd7205a72df841e8d99b9 (diff)
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 <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Namhyung Kim <namhyung@gmail.com> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1406035081-14301-17-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/util/machine.c46
-rw-r--r--tools/perf/util/machine.h5
2 files changed, 51 insertions, 0 deletions
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 93c8b6fbc799..cfc691000f13 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -45,6 +45,8 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid)
45 thread__set_comm(thread, comm, 0); 45 thread__set_comm(thread, comm, 0);
46 } 46 }
47 47
48 machine->current_tid = NULL;
49
48 return 0; 50 return 0;
49} 51}
50 52
@@ -104,6 +106,7 @@ void machine__exit(struct machine *machine)
104 dsos__delete(&machine->user_dsos); 106 dsos__delete(&machine->user_dsos);
105 dsos__delete(&machine->kernel_dsos); 107 dsos__delete(&machine->kernel_dsos);
106 zfree(&machine->root_dir); 108 zfree(&machine->root_dir);
109 zfree(&machine->current_tid);
107} 110}
108 111
109void machine__delete(struct machine *machine) 112void machine__delete(struct machine *machine)
@@ -1481,3 +1484,46 @@ int __machine__synthesize_threads(struct machine *machine, struct perf_tool *too
1481 /* command specified */ 1484 /* command specified */
1482 return 0; 1485 return 0;
1483} 1486}
1487
1488pid_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
1496int 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}
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index c8c74a119398..8771d0cbe9cb 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -33,6 +33,7 @@ struct machine {
33 struct map_groups kmaps; 33 struct map_groups kmaps;
34 struct map *vmlinux_maps[MAP__NR_TYPES]; 34 struct map *vmlinux_maps[MAP__NR_TYPES];
35 symbol_filter_t symbol_filter; 35 symbol_filter_t symbol_filter;
36 pid_t *current_tid;
36}; 37};
37 38
38static inline 39static inline
@@ -191,4 +192,8 @@ int machine__synthesize_threads(struct machine *machine, struct target *target,
191 perf_event__process, data_mmap); 192 perf_event__process, data_mmap);
192} 193}
193 194
195pid_t machine__get_current_tid(struct machine *machine, int cpu);
196int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid,
197 pid_t tid);
198
194#endif /* __PERF_MACHINE_H */ 199#endif /* __PERF_MACHINE_H */