lkml.org 
[lkml]   [2013]   [Dec]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v0 15/71] perf tools: Add ability to record the current tid for each cpu
Date
From: Adrian Hunter <adrian.hunter@intel.com>

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>
---
tools/perf/util/machine.c | 39 +++++++++++++++++++++++++++++++++++++++
tools/perf/util/machine.h | 4 ++++
2 files changed, 43 insertions(+)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 52fbfb6..a04210d 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -43,6 +43,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;
}

@@ -103,6 +105,8 @@ void machine__exit(struct machine *machine)
dsos__delete(&machine->kernel_dsos);
free(machine->root_dir);
machine->root_dir = NULL;
+ free(machine->current_tid);
+ machine->current_tid = NULL;
}

void machine__delete(struct machine *machine)
@@ -1438,3 +1442,38 @@ int machine__set_thread_cpu(struct machine *machine, pid_t pid, pid_t tid,

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)
+{
+ 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;
+
+ return machine__set_thread_cpu(machine, pid, tid, cpu);
+}
diff --git a/tools/perf/util/machine.h b/tools/perf/util/machine.h
index 27486af..aaad99a 100644
--- a/tools/perf/util/machine.h
+++ b/tools/perf/util/machine.h
@@ -31,6 +31,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
@@ -194,5 +195,8 @@ pid_t machine__get_thread_pid(struct machine *machine, pid_t tid);
int machine__get_thread_cpu(struct machine *machine, pid_t tid, pid_t *pid);
int machine__set_thread_cpu(struct machine *machine, pid_t pid, pid_t tid,
int cpu);
+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 */
--
1.8.5.1


\
 
 \ /
  Last update: 2013-12-11 14:21    [W:0.587 / U:0.220 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site