lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 18 Mar 2014 15:46:55 +0100
From:	Jiri Olsa <jolsa@...hat.com>
To:	linux-kernel@...r.kernel.org
Cc:	Jiri Olsa <jolsa@...hat.com>, Don Zickus <dzickus@...hat.com>,
	Corey Ashford <cjashfor@...ux.vnet.ibm.com>,
	David Ahern <dsahern@...il.com>,
	Frederic Weisbecker <fweisbec@...il.com>,
	Ingo Molnar <mingo@...nel.org>,
	Namhyung Kim <namhyung@...nel.org>,
	Paul Mackerras <paulus@...ba.org>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	Arnaldo Carvalho de Melo <acme@...stprotocols.net>
Subject: [PATCH 5/6] perf tools: Share process map groups within process threads

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

Signed-off-by: Jiri Olsa <jolsa@...hat.com>
Cc: Don Zickus <dzickus@...hat.com>
Cc: Corey Ashford <cjashfor@...ux.vnet.ibm.com>
Cc: David Ahern <dsahern@...il.com>
Cc: Frederic Weisbecker <fweisbec@...il.com>
Cc: Ingo Molnar <mingo@...nel.org>
Cc: Namhyung Kim <namhyung@...nel.org>
Cc: Paul Mackerras <paulus@...ba.org>
Cc: Peter Zijlstra <a.p.zijlstra@...llo.nl>
Cc: Arnaldo Carvalho de Melo <acme@...stprotocols.net>
---
 tools/perf/util/map.h    |  2 ++
 tools/perf/util/thread.c | 40 +++++++++++++++++++++++++++++++++++-----
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h
index 99a6488..472a686 100644
--- a/tools/perf/util/map.h
+++ b/tools/perf/util/map.h
@@ -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)
diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
index cbe451a..f34fda1 100644
--- a/tools/perf/util/thread.c
+++ b/tools/perf/util/thread.c
@@ -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;
 	}
 }
 
-- 
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ