linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: jolsa@redhat.com
Cc: acme@kernel.org, linux-kernel@vger.kernel.org,
	namhyung@kernel.org, jolsa@kernel.org
Subject: Re: [PATCH RFC] hist lookups
Date: Sun, 04 Nov 2018 16:50:39 -0800 (PST)	[thread overview]
Message-ID: <20181104.165039.878682622135788379.davem@davemloft.net> (raw)
In-Reply-To: <20181104201821.GA22049@krava>

From: Jiri Olsa <jolsa@redhat.com>
Date: Sun, 4 Nov 2018 21:18:21 +0100

> do you have some code I could check on?

All I have is this patch which parallelizes the mmap readers in perf
top.

It's not complete and you need to add proper locking, particularly around
the machine__resolve() call.

diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index d21d875..e214225 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -725,7 +725,9 @@ static void perf_event__process_sample(struct perf_tool *tool,
 	if (event->header.misc & PERF_RECORD_MISC_EXACT_IP)
 		top->exact_samples++;
 
-	if (machine__resolve(machine, &al, sample) < 0)
+	err = machine__resolve(machine, &al, sample);
+
+	if (err < 0)
 		return;
 
 	if (!machine->kptr_restrict_warned &&
@@ -877,6 +879,7 @@ static void perf_top__mmap_read_idx(struct perf_top *top, int idx)
 	perf_mmap__read_done(md);
 }
 
+#if 0
 static void perf_top__mmap_read(struct perf_top *top)
 {
 	bool overwrite = top->record_opts.overwrite;
@@ -903,6 +906,7 @@ static void perf_top__mmap_read(struct perf_top *top)
 			    "decreasing the freq (-F) or\n"
 			    "limiting the number of CPUs (-C)\n");
 }
+#endif
 
 /*
  * Check per-event overwrite term.
@@ -1063,6 +1067,59 @@ static int callchain_param__setup_sample_type(struct callchain_param *callchain)
 	return 0;
 }
 
+struct mmap_thread_arg {
+	struct perf_top *top;
+	int index;
+};
+
+static void *mmap_thread_worker(void *arg)
+{
+	struct mmap_thread_arg *ap = arg;
+
+	while (!done)
+		perf_top__mmap_read_idx(ap->top, ap->index);
+
+	return NULL;
+}
+
+static pthread_t *mmap_threads;
+
+static int blitzkreig_bop(struct perf_top *top)
+{
+	struct perf_evlist *evlist = top->evlist;
+	int i, nr_threads = evlist->nr_mmaps;
+	struct mmap_thread_arg *ap;
+
+	fprintf(stderr, "Creating %d mmap threads\n", nr_threads);
+	fflush(stderr);
+
+	ap = calloc(sizeof(*ap), nr_threads);
+	if (!ap)
+		return -ENOMEM;
+
+	mmap_threads = calloc(sizeof(pthread_t), nr_threads);
+	if (!mmap_threads) {
+		free(ap);
+		return -ENOMEM;
+	}
+
+	for (i = 0; i < nr_threads; i++) {
+		ap[i].top = top;
+		ap[i].index = i;
+	}
+
+	/* Current thread will handle index zero.  */
+	for (i = 1; i < nr_threads; i++) {
+		int err = pthread_create(&mmap_threads[i], NULL,
+					 mmap_thread_worker, &ap[i]);
+
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
 static int __cmd_top(struct perf_top *top)
 {
 	char msg[512];
@@ -1134,11 +1191,6 @@ static int __cmd_top(struct perf_top *top)
         if (!target__none(&opts->target))
                 perf_evlist__enable(top->evlist);
 
-	/* Wait for a minimal set of events before starting the snapshot */
-	perf_evlist__poll(top->evlist, 100);
-
-	perf_top__mmap_read(top);
-
 	ret = -1;
 	if (pthread_create(&thread, NULL, (use_browser > 0 ? display_thread_tui :
 							    display_thread), top)) {
@@ -1156,13 +1208,30 @@ static int __cmd_top(struct perf_top *top)
 		}
 	}
 
+	ret = blitzkreig_bop(top);
+	if (ret)
+		goto out_join;
+
+#if 1
+	perf_top__mmap_read_idx(top, 0);
+#else
+	/* Wait for a minimal set of events before starting the snapshot */
+	perf_evlist__poll(top->evlist, 100);
+	perf_top__mmap_read(top);
+#endif
+
 	while (!done) {
+#if 0
 		u64 hits = top->samples;
+#endif
 
+#if 1
+		perf_top__mmap_read_idx(top, 0);
+#else
 		perf_top__mmap_read(top);
-
 		if (opts->overwrite || (hits == top->samples))
 			ret = perf_evlist__poll(top->evlist, 100);
+#endif
 
 		if (resize) {
 			perf_top__resize(top);
@@ -1257,7 +1326,7 @@ int cmd_top(int argc, const char **argv)
 				.uses_mmap   = true,
 			},
 			.proc_map_timeout    = 500,
-			.overwrite	= 1,
+			.overwrite	= 0,
 		},
 		.max_stack	     = sysctl__max_stack(),
 		.annotation_opts     = annotation__default_options,

  reply	other threads:[~2018-11-05  0:50 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-31  5:03 [PATCH RFC] hist lookups David Miller
2018-10-31 12:43 ` Arnaldo Carvalho de Melo
2018-10-31 15:39   ` Jiri Olsa
2018-10-31 16:08     ` David Miller
2018-11-03  6:30       ` David Miller
2018-11-04 20:18         ` Jiri Olsa
2018-11-05  0:50           ` David Miller [this message]
2018-11-05 20:34             ` Jiri Olsa
2018-11-05 22:52               ` David Miller
2018-11-06  3:45               ` David Miller
2018-11-06  4:03                 ` David Miller
2018-11-06  4:53                   ` David Miller
2018-11-06 11:54                     ` Jiri Olsa
2018-11-19  5:26                       ` Namhyung Kim
2018-11-19  9:12                         ` Jiri Olsa
2018-11-20  1:13                           ` Namhyung Kim
2018-11-06 20:42                     ` Jiri Olsa
2018-11-07  6:13                       ` David Miller
2018-11-07  8:32                         ` Jiri Olsa
2018-11-07 19:43                           ` Jiri Olsa
2018-11-07 20:01                             ` David Miller
2018-11-07 20:28                               ` Arnaldo Carvalho de Melo
2018-11-08  6:04                                 ` David Miller
2018-11-08  7:13                               ` Jiri Olsa
2018-11-09  1:07                                 ` David Miller
2018-11-11 19:41                                   ` Jiri Olsa
2018-11-11 19:41                                     ` Jiri Olsa
2018-11-11 22:32                                     ` David Miller
2018-11-11 22:43                                       ` Jiri Olsa
2018-11-11 22:58                                         ` David Miller
2018-11-11 23:08                                     ` David Miller
2018-11-11 23:26                                       ` Jiri Olsa
2018-11-11 23:32                                         ` David Miller
2018-11-13 10:40                                           ` Jiri Olsa
2018-11-19  4:52                                             ` David Miller
2018-11-19  6:28                                               ` Namhyung Kim
2018-11-19  6:33                                                 ` David Miller
2018-11-19  7:16                                                   ` Namhyung Kim
2018-11-19  9:14                                               ` Jiri Olsa
2018-11-06 11:51                 ` Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181104.165039.878682622135788379.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=acme@kernel.org \
    --cc=jolsa@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).