Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0a7c74ea authored by Arnaldo Carvalho de Melo's avatar Arnaldo Carvalho de Melo
Browse files

perf tools: Provide mutex wrappers for pthreads rwlocks



Andi reported a performance drop in single threaded perf tools such as
'perf script' due to the growing number of locks being put in place to
allow for multithreaded tools, so wrap the POSIX threads rwlock routines
with the names used for such kinds of locks in the Linux kernel and then
allow for tools to ask for those locks to be used or not.

I.e. a tool may have a multithreaded phase and then switch to single
threaded, like the upcoming patches for the synthesizing of
PERF_RECORD_{FORK,MMAP,etc} for pre-existing processes to then switch to
single threaded mode in 'perf top'.

The init routines will not be conditional, this way starting as single
threaded to then move to multi threaded mode should be possible.

Reported-by: default avatarAndi Kleen <ak@linux.intel.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/20170404161739.GH12903@kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 6ae8eefc
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@
#include <termios.h>
#include <semaphore.h>
#include <signal.h>
#include <pthread.h>
#include <math.h>

static const char *get_filename_for_perf_kvm(void)
+2 −0
Original line number Diff line number Diff line
@@ -2829,6 +2829,8 @@ int cmd_script(int argc, const char **argv)
		NULL
	};

	perf_set_singlethreaded();

	setup_scripting();

	argc = parse_options_subcommand(argc, argv, options, script_subcommands, script_usage,
+1 −0
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ libperf-y += data.o
libperf-y += tsc.o
libperf-y += cloexec.o
libperf-y += call-path.o
libperf-y += rwsem.o
libperf-y += thread-stack.o
libperf-$(CONFIG_AUXTRACE) += auxtrace.o
libperf-$(CONFIG_AUXTRACE) += intel-pt-decoder/
+6 −6
Original line number Diff line number Diff line
@@ -1366,9 +1366,9 @@ void __dsos__add(struct dsos *dsos, struct dso *dso)

void dsos__add(struct dsos *dsos, struct dso *dso)
{
	pthread_rwlock_wrlock(&dsos->lock);
	down_write(&dsos->lock);
	__dsos__add(dsos, dso);
	pthread_rwlock_unlock(&dsos->lock);
	up_write(&dsos->lock);
}

struct dso *__dsos__find(struct dsos *dsos, const char *name, bool cmp_short)
@@ -1387,9 +1387,9 @@ struct dso *__dsos__find(struct dsos *dsos, const char *name, bool cmp_short)
struct dso *dsos__find(struct dsos *dsos, const char *name, bool cmp_short)
{
	struct dso *dso;
	pthread_rwlock_rdlock(&dsos->lock);
	down_read(&dsos->lock);
	dso = __dsos__find(dsos, name, cmp_short);
	pthread_rwlock_unlock(&dsos->lock);
	up_read(&dsos->lock);
	return dso;
}

@@ -1416,9 +1416,9 @@ struct dso *__dsos__findnew(struct dsos *dsos, const char *name)
struct dso *dsos__findnew(struct dsos *dsos, const char *name)
{
	struct dso *dso;
	pthread_rwlock_wrlock(&dsos->lock);
	down_write(&dsos->lock);
	dso = dso__get(__dsos__findnew(dsos, name));
	pthread_rwlock_unlock(&dsos->lock);
	up_write(&dsos->lock);
	return dso;
}

+2 −2
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
#include <linux/rbtree.h>
#include <sys/types.h>
#include <stdbool.h>
#include <pthread.h>
#include "rwsem.h"
#include <linux/types.h>
#include <linux/bitops.h>
#include "map.h"
@@ -129,7 +129,7 @@ struct dso_cache {
struct dsos {
	struct list_head head;
	struct rb_root	 root;	/* rbtree root sorted by long name */
	pthread_rwlock_t lock;
	struct rw_semaphore lock;
};

struct auxtrace_cache;
Loading