Skip to contentSkip to conversation

perf tools: Share map groups within process

PATCH In review Jiri Olsa 4 participants 11 messages Mar 18, 2014 – Mar 20, 2014 perf events

lore
Share & tools
lore

Jiri Olsa

author
#0 lore raw

cover perf tools: Share map groups within process

hi,
this patchset moves thread's map_groups to be dynamically allocated and shared within process threads.

The main benefit would be to be able to look up memory map from any thread that belongs to the process.

This implements one of the solution ideas for issue described by Don in following thread:
http://marc.info/?l=linux-kernel&m=139403876017159&w=2

RFC changes:
- added automated test for thread map groups get/put methods
- fix reference count for case described by Namhyung
- rename the mmap-events.c test to mmap-thread-lookup.c
- added PROT_EXEC to mmap call in tests/mmap-thread-lookup.c as it's not implied by default on all archs (Namhyung)
- lazy mg allocation in thread__find_addr_map (Namhyung)
- fix compilation failures (Arnaldo)

also available in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/core_mmaps

thanks,
jirka

Cc Don Zickus <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

---
Jiri Olsa (6):
perf tests: Add thread maps lookup automated tests perf tools: Remove thread__find_map function
perf tools: Allocate thread map_groups dynamically perf tools: Add machine pointer into thread struct perf tools: Share process map groups within process threads perf tests: Add map groups sharing with thread object test

 tools/perf/Makefile.perf                 |   2 +
 tools/perf/arch/x86/tests/dwarf-unwind.c |   9 +++-
 tools/perf/perf.h                        |   6 +++
 tools/perf/tests/builtin-test.c          |   8 ++++
 tools/perf/tests/mmap-thread-lookup.c    | 233 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/tests/tests.h                 |   2 +
 tools/perf/tests/thread-mg-share.c       | 110 +++++++++++++++++++++++++++++++++++++++++++
 tools/perf/ui/stdio/hist.c               |   9 +++-
 tools/perf/util/event.c                  |  10 +++-
 tools/perf/util/machine.c                |   8 ++--
 tools/perf/util/map.h                    |   3 +-
 tools/perf/util/thread.c                 | 120 +++++++++++++++++++++++++++++++++++++++++-----
 tools/perf/util/thread.h                 |  19 ++++----
 13 files changed, 508 insertions(+), 31 deletions(-)
 create mode 100644 tools/perf/tests/mmap-thread-lookup.c
 create mode 100644 tools/perf/tests/thread-mg-share.c
author
#1 lore raw

PATCH 1/6 perf tests: Add thread maps lookup automated tests

Adding automated test for memory maps lookup within multiple machines threads.

The test creates 4 threads and separated memory maps.

It checks that we could use thread__find_addr_map
function with thread object based on TID to find
memory maps.

Currently map info is reachable only from thread leader. Upcoming patches for map groups sharing allow to find maps from any thread.

Cc Don Zickus <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
 tools/perf/Makefile.perf              |   1 +
 tools/perf/perf.h                     |   6 +
 tools/perf/tests/builtin-test.c       |   4 +
 tools/perf/tests/mmap-thread-lookup.c | 233 ++++++++++++++++++++++++++++++++++
 tools/perf/tests/tests.h              |   1 +
 5 files changed, 245 insertions(+)
 create mode 100644 tools/perf/tests/mmap-thread-lookup.c
tools/perf/Makefile.perf +1 -0
index 50d875d..667e85a 100644
@@ -414,6 +414,7 @@ ifeq ($(ARCH),x86)
 LIB_OBJS += $(OUTPUT)tests/dwarf-unwind.o
 endif
 endif
+LIB_OBJS += $(OUTPUT)tests/mmap-thread-lookup.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
tools/perf/perf.h +6 -0
index e18a8b5..1138c41 100644
@@ -15,6 +15,9 @@
 #ifndef __NR_futex
 # define __NR_futex 240
 #endif
+#ifndef __NR_gettid
+# define __NR_gettid 224
+#endif
 #endif
 
 #if defined(__x86_64__)
@@ -29,6 +32,9 @@
 #ifndef __NR_futex
 # define __NR_futex 202
 #endif
+#ifndef __NR_gettid
+# define __NR_gettid 186
+#endif
 #endif
 
 #ifdef __powerpc__
tools/perf/tests/builtin-test.c +4 -0
index b11bf8a..d947d1a 100644
@@ -124,6 +124,10 @@ static struct test {
 #endif
 #endif
 	{
+		.desc = "Test mmap thread lookup",
+		.func = test__mmap_thread_lookup,
+	},
+	{
 		.func = NULL,
 	},
 };
tools/perf/tests/mmap-thread-lookup.c new file +233 -0

233 lines not on this page · raw message

tools/perf/tests/tests.h +1 -0
index a24795c..6db764c 100644
@@ -41,6 +41,7 @@ int test__sample_parsing(void);
 int test__keep_tracking(void);
 int test__parse_no_sample_id_all(void);
 int test__dwarf_unwind(void);
+int test__mmap_thread_lookup(void);
 
 #if defined(__x86_64__) || defined(__i386__)
 #ifdef HAVE_DWARF_UNWIND_SUPPORT
Signature · 1 line
1.8.3.1
author
#2 lore raw

PATCH 2/6 perf tools: Remove thread__find_map function

In reply to Jiri Olsa

Because it's not used any more.

Cc Don Zickus <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
 tools/perf/util/thread.h | 6 ------
 1 file changed, 6 deletions(-)
tools/perf/util/thread.h +0 -6
index 9a07074..9b29f08 100644
@@ -44,12 +44,6 @@ void thread__insert_map(struct thread *thread, struct map *map);
 int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp);
 size_t thread__fprintf(struct thread *thread, FILE *fp);
 
-static inline struct map *thread__find_map(struct thread *thread,
-					   enum map_type type, u64 addr)
-{
-	return thread ? map_groups__find(&thread->mg, type, addr) : NULL;
-}
-
 void thread__find_addr_map(struct thread *thread, struct machine *machine,
 			   u8 cpumode, enum map_type type, u64 addr,
 			   struct addr_location *al);
Signature · 1 line
1.8.3.1
#3 lore raw

[tip:perf/core] perf tools: Remove thread__find_map function

perf tools: Remove thread__find_map function
Commit-ID:  8fffdb6821e8ca249f56fba796ef463ac74ab196
Gitweb:     http://git.kernel.org/tip/8fffdb6821e8ca249f56fba796ef463ac74ab196
Author:     Jiri Olsa <[email protected]>
AuthorDate: Tue, 18 Mar 2014 15:46:52 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Tue, 18 Mar 2014 18:17:04 -0300

perf tools: Remove thread__find_map function

Because it's not used any more.

Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Don Zickus <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/util/thread.h | 6 ------
 1 file changed, 6 deletions(-)
tools/perf/util/thread.h +0 -6
index 9a07074..9b29f08 100644
@@ -44,12 +44,6 @@ void thread__insert_map(struct thread *thread, struct map *map);
 int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp);
 size_t thread__fprintf(struct thread *thread, FILE *fp);
 
-static inline struct map *thread__find_map(struct thread *thread,
-					   enum map_type type, u64 addr)
-{
-	return thread ? map_groups__find(&thread->mg, type, addr) : NULL;
-}
-
 void thread__find_addr_map(struct thread *thread, struct machine *machine,
 			   u8 cpumode, enum map_type type, u64 addr,
 			   struct addr_location *al);
author
#4 lore raw

PATCH 3/6 perf tools: Allocate thread map_groups dynamically

In reply to Jiri Olsa

Moving towards sharing map groups within a process threads.

Because of this we need the map groups to be dynamically allocated. No other functional change is intended in here.

Adding new interface to get/put map groups:
thread__map_groups_get
- allocates map groups for thread

thread__map_groups_put
- frees map groups for thread

Cc Don Zickus <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
 tools/perf/arch/x86/tests/dwarf-unwind.c |  9 +++-
 tools/perf/ui/stdio/hist.c               |  9 +++-
 tools/perf/util/event.c                  | 10 +++-
 tools/perf/util/machine.c                |  6 +--
 tools/perf/util/map.h                    |  1 -
 tools/perf/util/thread.c                 | 86 +++++++++++++++++++++++++++-----
 tools/perf/util/thread.h                 |  8 ++-
 7 files changed, 107 insertions(+), 22 deletions(-)
tools/perf/arch/x86/tests/dwarf-unwind.c +8 -1
index b602ad9..4e2088c 100644
@@ -23,7 +23,14 @@ static int sample_ustack(struct perf_sample *sample,
 
 	sp = (unsigned long) regs[PERF_REG_X86_SP];
 
-	map = map_groups__find(&thread->mg, MAP__FUNCTION, (u64) sp);
+	/*
+	 * The generic code (test__dwarf_unwind) synthesizes and
+	 * processes mmap events, so if we get NULL in thread->mg,
+	 * it's bug.
+	 */
+	BUG_ON(!thread->mg);
+
+	map = map_groups__find(thread->mg, MAP__FUNCTION, (u64) sp);
 	if (!map) {
 		pr_debug("failed to get stack map\n");
 		return -1;
tools/perf/ui/stdio/hist.c +8 -1
index d59893e..fc318c3 100644
@@ -495,7 +495,14 @@ print_entries:
 			break;
 
 		if (h->ms.map == NULL && verbose > 1) {
-			__map_groups__fprintf_maps(&h->thread->mg,
+			struct map_groups *mg;
+
+			mg = thread__map_groups_get(h->thread);
+			if (!mg) {
+				ret = -ENOMEM;
+				break;
+			}
+			__map_groups__fprintf_maps(mg,
 						   MAP__FUNCTION, verbose, fp);
 			fprintf(fp, "%.10s end\n", graph_dotted_line);
 		}
tools/perf/util/event.c +9 -1
index 9c18b126..bc1da4d 100644
@@ -699,7 +699,7 @@ void thread__find_addr_map(struct thread *thread,
 			   enum map_type type, u64 addr,
 			   struct addr_location *al)
 {
-	struct map_groups *mg = &thread->mg;
+	struct map_groups *mg;
 	bool load_map = false;
 
 	al->machine = machine;
@@ -719,12 +719,14 @@ void thread__find_addr_map(struct thread *thread,
 		load_map = true;
 	} else if (cpumode == PERF_RECORD_MISC_USER && perf_host) {
 		al->level = '.';
+		mg = thread__map_groups_get(thread);
 	} else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
 		al->level = 'g';
 		mg = &machine->kmaps;
 		load_map = true;
 	} else if (cpumode == PERF_RECORD_MISC_GUEST_USER && perf_guest) {
 		al->level = 'u';
+		mg = thread__map_groups_get(thread);
 	} else {
 		al->level = 'H';
 		al->map = NULL;
@@ -740,6 +742,12 @@ void thread__find_addr_map(struct thread *thread,
 
 		return;
 	}
+
+	if (mg == NULL) {
+		al->map = NULL;
+		return;
+	}
+
 try_again:
 	al->map = map_groups__find(mg, type, al->addr);
 	if (al->map == NULL) {
tools/perf/util/machine.c +2 -4
index a53cd0b..d1f06d2 100644
@@ -1046,8 +1046,7 @@ int machine__process_mmap2_event(struct machine *machine,
 	if (map == NULL)
 		goto out_problem;
 
-	thread__insert_map(thread, map);
-	return 0;
+	return thread__insert_map(thread, map);
 
 out_problem:
 	dump_printf("problem processing PERF_RECORD_MMAP2, skipping event.\n");
@@ -1093,8 +1092,7 @@ int machine__process_mmap_event(struct machine *machine, union perf_event *event
 	if (map == NULL)
 		goto out_problem;
 
-	thread__insert_map(thread, map);
-	return 0;
+	return thread__insert_map(thread, map);
 
 out_problem:
 	dump_printf("problem processing PERF_RECORD_MMAP, skipping event.\n");
tools/perf/util/map.h +0 -1
index f00f058..99a6488 100644
@@ -202,5 +202,4 @@ struct map *map_groups__find_by_name(struct map_groups *mg,
 				     enum map_type type, const char *name);
 
 void map_groups__flush(struct map_groups *mg);
-
 #endif /* __PERF_MAP_H */
tools/perf/util/thread.c +74 -12

124 lines not on this page · raw message

tools/perf/util/thread.h +6 -2
index 9b29f08..b3f7d8e 100644
@@ -13,7 +13,7 @@ struct thread {
 		struct rb_node	 rb_node;
 		struct list_head node;
 	};
-	struct map_groups	mg;
+	struct map_groups	*mg;
 	pid_t			pid_; /* Not all tools update this */
 	pid_t			tid;
 	pid_t			ppid;
@@ -40,7 +40,7 @@ int thread__set_comm(struct thread *thread, const char *comm, u64 timestamp);
 int thread__comm_len(struct thread *thread);
 struct comm *thread__comm(const struct thread *thread);
 const char *thread__comm_str(const struct thread *thread);
-void thread__insert_map(struct thread *thread, struct map *map);
+int thread__insert_map(struct thread *thread, struct map *map);
 int thread__fork(struct thread *thread, struct thread *parent, u64 timestamp);
 size_t thread__fprintf(struct thread *thread, FILE *fp);
 
@@ -77,4 +77,8 @@ static inline bool thread__is_filtered(struct thread *thread)
 	return false;
 }
 
+struct map_groups *thread__map_groups_get(struct thread *thread);
+
+void thread__map_groups_put(struct thread *thread);
+
 #endif	/* __PERF_THREAD_H */
Signature · 1 line
1.8.3.1
author
#5 lore raw

PATCH 4/6 perf tools: Add machine pointer into thread struct

In reply to Jiri Olsa

Need machine pointer in thread object, so we could lookup the process thread in following patch.

Cc Don Zickus <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
 tools/perf/util/machine.c | 2 +-
 tools/perf/util/thread.c  | 4 +++-
 tools/perf/util/thread.h  | 5 ++++-
 3 files changed, 8 insertions(+), 3 deletions(-)
tools/perf/util/machine.c +1 -1
index d1f06d2..237d7c2 100644
@@ -311,7 +311,7 @@ static struct thread *__machine__findnew_thread(struct machine *machine,
 	if (!create)
 		return NULL;
 
-	th = thread__new(pid, tid);
+	th = thread__new(pid, tid, machine);
 	if (th != NULL) {
 		rb_link_node(&th->rb_node, parent, p);
 		rb_insert_color(&th->rb_node, &machine->threads);
tools/perf/util/thread.c +3 -1
index bacf60b..cbe451a 100644
@@ -8,13 +8,15 @@
 #include "debug.h"
 #include "comm.h"
 
-struct thread *thread__new(pid_t pid, pid_t tid)
+struct thread *thread__new(pid_t pid, pid_t tid,
+			   struct machine *machine)
 {
 	char *comm_str;
 	struct comm *comm;
 	struct thread *thread = zalloc(sizeof(*thread));
 
 	if (thread != NULL) {
+		thread->machine = machine;
 		thread->pid_ = pid;
 		thread->tid = tid;
 		thread->ppid = -1;
tools/perf/util/thread.h +4 -1
index b3f7d8e..21521e1 100644
@@ -7,12 +7,14 @@
 #include <sys/types.h>
 #include "symbol.h"
 #include <strlist.h>
+#include "machine.h"
 
 struct thread {
 	union {
 		struct rb_node	 rb_node;
 		struct list_head node;
 	};
+	struct machine		*machine;
 	struct map_groups	*mg;
 	pid_t			pid_; /* Not all tools update this */
 	pid_t			tid;
@@ -29,7 +31,8 @@ struct thread {
 struct machine;
 struct comm;
 
-struct thread *thread__new(pid_t pid, pid_t tid);
+struct thread *thread__new(pid_t pid, pid_t tid,
+			   struct machine *machine);
 void thread__delete(struct thread *thread);
 static inline void thread__exited(struct thread *thread)
 {
Signature · 1 line
1.8.3.1
author
#6 lore raw

PATCH 5/6 perf tools: Share process map groups within process threads

In reply to Jiri Olsa

Sharing map groups within all process threads. This way there's only one copy of mmap info and it's reachable from any thread within the process.

Adding reference counting for struct map_groups and changing the thread map groups get/put interface.

Adding reference counter 'refcnt' into struct map_groups.

Function thread__map_groups_get now:
- lookup (&create) thread leader and returns its mg, allocates one if needed
- increments reference counter for each copy

Function thread__map_groups_put now:
- decrease map groups reference counter and sets its pointer to NULL
- frees map groups data if it was last copy

Cc Don Zickus <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
 tools/perf/util/map.h    |  2 ++
 tools/perf/util/thread.c | 40 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 37 insertions(+), 5 deletions(-)
tools/perf/util/map.h +2 -0
index 99a6488..472a686 100644
@@ -59,6 +59,8 @@ struct map_groups {
 	struct rb_root	 maps[MAP__NR_TYPES];
 	struct list_head removed_maps[MAP__NR_TYPES];
 	struct machine	 *machine;
+	/* Used for thread sharing. */
+	int		  refcnt;
 };
 
 static inline struct kmap *map__kmap(struct map *map)
tools/perf/util/thread.c +35 -5
index cbe451a..f34fda1 100644
@@ -130,6 +130,13 @@ int thread__insert_map(struct thread *thread, struct map *map)
 	return 0;
 }
 
+static struct thread *thread__get_leader(struct thread *thread)
+{
+	pid_t pid = thread->pid_;
+
+	return machine__findnew_thread(thread->machine, pid, pid);
+}
+
 static struct map_groups *thread__map_groups_alloc(struct thread *thread)
 {
 	struct map_groups *mg = zalloc(sizeof(*mg));
@@ -137,6 +144,7 @@ static struct map_groups *thread__map_groups_alloc(struct thread *thread)
 	if (mg) {
 		map_groups__init(mg);
 		thread->mg = mg;
+		mg->refcnt = 1;
 	}
 
 	return mg;
@@ -146,17 +154,39 @@ struct map_groups *thread__map_groups_get(struct thread *thread)
 {
 	struct map_groups *mg = thread->mg;
 
-	if (!mg)
-		mg = thread__map_groups_alloc(thread);
+	if (!mg) {
+		struct thread *leader = thread__get_leader(thread);
+
+		if (!leader)
+			return NULL;
+
+		if (leader->mg)
+			mg = leader->mg;
+		else
+			mg = thread__map_groups_alloc(leader);
+
+		if (leader != thread) {
+			thread->mg = mg;
+			mg->refcnt++;
+		}
+	}
 
 	return mg;
 }
 
 void thread__map_groups_put(struct thread *thread)
 {
-	if (thread->mg) {
-		map_groups__exit(thread->mg);
-		zfree(&thread->mg);
+	struct map_groups *mg = thread->mg;
+
+	if (mg) {
+		BUG_ON(!mg->refcnt);
+
+		if (!--mg->refcnt) {
+			map_groups__exit(thread->mg);
+			free(thread->mg);
+		}
+
+		thread->mg = NULL;
 	}
 }
 
Signature · 1 line
1.8.3.1
author
#7 lore raw

PATCH 6/6 perf tests: Add map groups sharing with thread object test

In reply to Jiri Olsa

This test create 2 processes abstractions, with several threads and checks they properly share and maintain map groups info.

Cc Don Zickus <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
 tools/perf/Makefile.perf           |   1 +
 tools/perf/tests/builtin-test.c    |   4 ++
 tools/perf/tests/tests.h           |   1 +
 tools/perf/tests/thread-mg-share.c | 110 +++++++++++++++++++++++++++++++++++++
 4 files changed, 116 insertions(+)
 create mode 100644 tools/perf/tests/thread-mg-share.c
tools/perf/Makefile.perf +1 -0
index 667e85a..ffa6cac 100644
@@ -415,6 +415,7 @@ LIB_OBJS += $(OUTPUT)tests/dwarf-unwind.o
 endif
 endif
 LIB_OBJS += $(OUTPUT)tests/mmap-thread-lookup.o
+LIB_OBJS += $(OUTPUT)tests/thread-mg-share.o
 
 BUILTIN_OBJS += $(OUTPUT)builtin-annotate.o
 BUILTIN_OBJS += $(OUTPUT)builtin-bench.o
tools/perf/tests/builtin-test.c +4 -0
index d947d1a..a1145d1 100644
@@ -128,6 +128,10 @@ static struct test {
 		.func = test__mmap_thread_lookup,
 	},
 	{
+		.desc = "Test thread mg sharing",
+		.func = test__thread_mg_share,
+	},
+	{
 		.func = NULL,
 	},
 };
tools/perf/tests/tests.h +1 -0
index 6db764c..5ed3bd5 100644
@@ -42,6 +42,7 @@ int test__keep_tracking(void);
 int test__parse_no_sample_id_all(void);
 int test__dwarf_unwind(void);
 int test__mmap_thread_lookup(void);
+int test__thread_mg_share(void);
 
 #if defined(__x86_64__) || defined(__i386__)
 #ifdef HAVE_DWARF_UNWIND_SUPPORT
tools/perf/tests/thread-mg-share.c new file +110 -0

110 lines not on this page · raw message

Signature · 1 line
1.8.3.1
Tested-by on the v1 series
#8 lore raw
In reply to Jiri Olsa
Quoted 20 lines · Jiri Olsa

hi,
this patchset moves thread's map_groups to be dynamically allocated and shared within process threads.

The main benefit would be to be able to look up memory map from any thread that belongs to the process.

This implements one of the solution ideas for issue described by Don in following thread:
http://marc.info/?l=linux-kernel&m=139403876017159&w=2

RFC changes:
- added automated test for thread map groups get/put methods
- fix reference count for case described by Namhyung
- rename the mmap-events.c test to mmap-thread-lookup.c
- added PROT_EXEC to mmap call in tests/mmap-thread-lookup.c as it's not implied by default on all archs (Namhyung)
- lazy mg allocation in thread__find_addr_map (Namhyung)
- fix compilation failures (Arnaldo)

Quoted 3 lines

also available in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/core_mmaps

I ran this patchset through my multi-threaded java test (SPECJBB) and saw no issues. The threads seemed to have matched with their pids properly. I even took an old perf.data file (with old synthesized mmap2 events using pids) and the tids from the samples matched the pids correctly (for what it is worth).

So I will add my

I don't know the code well enough to know if it is right or not, but my quick review didn't see anything wrong.

Cheers,
Don

Quoted 40 lines

thanks,
jirka

Cc Don Zickus <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>

---
Jiri Olsa (6):
perf tests: Add thread maps lookup automated tests perf tools: Remove thread__find_map function
perf tools: Allocate thread map_groups dynamically perf tools: Add machine pointer into thread struct perf tools: Share process map groups within process threads perf tests: Add map groups sharing with thread object test

 tools/perf/Makefile.perf                 |   2 +
 tools/perf/arch/x86/tests/dwarf-unwind.c |   9 +++-
 tools/perf/perf.h                        |   6 +++
 tools/perf/tests/builtin-test.c          |   8 ++++
 tools/perf/tests/mmap-thread-lookup.c    | 233 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/tests/tests.h                 |   2 +
 tools/perf/tests/thread-mg-share.c       | 110 +++++++++++++++++++++++++++++++++++++++++++
 tools/perf/ui/stdio/hist.c               |   9 +++-
 tools/perf/util/event.c                  |  10 +++-
 tools/perf/util/machine.c                |   8 ++--
 tools/perf/util/map.h                    |   3 +-
 tools/perf/util/thread.c                 | 120 +++++++++++++++++++++++++++++++++++++++++-----
 tools/perf/util/thread.h                 |  19 ++++----
 13 files changed, 508 insertions(+), 31 deletions(-)
 create mode 100644 tools/perf/tests/mmap-thread-lookup.c
 create mode 100644 tools/perf/tests/thread-mg-share.c
maintainer Reviewed-by on the v1 series
#9 lore raw
In reply to Jiri Olsa

Hi Jiri,

Quoted 11 lines · Jiri Olsa

hi,
this patchset moves thread's map_groups to be dynamically allocated and shared within process threads.

The main benefit would be to be able to look up memory map from any thread that belongs to the process.

This implements one of the solution ideas for issue described by Don in following thread:
http://marc.info/?l=linux-kernel&m=139403876017159&w=2

Quoted 8 lines

RFC changes:
- added automated test for thread map groups get/put methods
- fix reference count for case described by Namhyung
- rename the mmap-events.c test to mmap-thread-lookup.c
- added PROT_EXEC to mmap call in tests/mmap-thread-lookup.c as it's not implied by default on all archs (Namhyung)
- lazy mg allocation in thread__find_addr_map (Namhyung)
- fix compilation failures (Arnaldo)

Looks good to me!

Thanks,
Namhyung

author
#10 lore raw
In reply to Jiri Olsa
Quoted 20 lines · Jiri Olsa

hi,
this patchset moves thread's map_groups to be dynamically allocated and shared within process threads.

The main benefit would be to be able to look up memory map from any thread that belongs to the process.

This implements one of the solution ideas for issue described by Don in following thread:
http://marc.info/?l=linux-kernel&m=139403876017159&w=2

RFC changes:
- added automated test for thread map groups get/put methods
- fix reference count for case described by Namhyung
- rename the mmap-events.c test to mmap-thread-lookup.c
- added PROT_EXEC to mmap call in tests/mmap-thread-lookup.c as it's not implied by default on all archs (Namhyung)
- lazy mg allocation in thread__find_addr_map (Namhyung)
- fix compilation failures (Arnaldo)

Quoted 3 lines

also available in here:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/core_mmaps

Arnaldo,
I rebased this to your latest perf/core

thanks,
jirka