public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Andi Kleen <ak@linux.intel.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Alexander Antonov <alexander.antonov@linux.intel.com>,
	Alexei Budankov <abudankov@huawei.com>,
	Riccardo Mancini <rickyman7@gmail.com>
Subject: Re: [PATCH v13 03/16] perf record: Introduce thread specific data array
Date: Mon, 31 Jan 2022 18:39:39 -0300	[thread overview]
Message-ID: <YfhXG5yEHhrGDjvl@kernel.org> (raw)
In-Reply-To: <fc9f74af6f822d9c0fa0e145c3564a760dbe3d4b.1642440724.git.alexey.v.bayduraev@linux.intel.com>

Em Mon, Jan 17, 2022 at 09:34:23PM +0300, Alexey Bayduraev escreveu:
> Introduce thread specific data object and array of such objects
> to store and manage thread local data. Implement functions to
> allocate, initialize, finalize and release thread specific data.
> 
> Thread local maps and overwrite_maps arrays keep pointers to
> mmap buffer objects to serve according to maps thread mask.
> Thread local pollfd array keeps event fds connected to mmaps
> buffers according to maps thread mask.
> 
> Thread control commands are delivered via thread local comm pipes
> and ctlfd_pos fd. External control commands (--control option)
> are delivered via evlist ctlfd_pos fd and handled by the main
> tool thread.
> 
> Acked-by: Namhyung Kim <namhyung@gmail.com>
> Reviewed-by: Riccardo Mancini <rickyman7@gmail.com>
> Tested-by: Riccardo Mancini <rickyman7@gmail.com>
> Signed-off-by: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>

Some changes to reduce patch size, I have them in my local tree, will
publish later.

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 1645b40540b870aa..a8c7118a95c6a3fa 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -924,7 +924,7 @@ static void record__thread_data_close_pipes(struct record_thread *thread_data)
 
 static int record__thread_data_init_maps(struct record_thread *thread_data, struct evlist *evlist)
 {
-	int m, tm, nr_mmaps = evlist->core.nr_mmaps;
+	int nr_mmaps = evlist->core.nr_mmaps;
 	struct mmap *mmap = evlist->mmap;
 	struct mmap *overwrite_mmap = evlist->overwrite_mmap;
 	struct perf_cpu_map *cpus = evlist->core.cpus;
@@ -946,7 +946,7 @@ static int record__thread_data_init_maps(struct record_thread *thread_data, stru
 	pr_debug2("thread_data[%p]: nr_mmaps=%d, maps=%p, ow_maps=%p\n", thread_data,
 		 thread_data->nr_mmaps, thread_data->maps, thread_data->overwrite_maps);
 
-	for (m = 0, tm = 0; m < nr_mmaps && tm < thread_data->nr_mmaps; m++) {
+	for (int m = 0, tm = 0; m < nr_mmaps && tm < thread_data->nr_mmaps; m++) {
 		if (test_bit(cpus->map[m].cpu, thread_data->mask->maps.bits)) {
 			if (thread_data->maps) {
 				thread_data->maps[tm] = &mmap[m];
@@ -967,21 +967,18 @@ static int record__thread_data_init_maps(struct record_thread *thread_data, stru
 
 static int record__thread_data_init_pollfd(struct record_thread *thread_data, struct evlist *evlist)
 {
-	int f, tm, pos;
-	struct mmap *map, *overwrite_map;
-
 	fdarray__init(&thread_data->pollfd, 64);
 
-	for (tm = 0; tm < thread_data->nr_mmaps; tm++) {
-		map = thread_data->maps ? thread_data->maps[tm] : NULL;
-		overwrite_map = thread_data->overwrite_maps ?
-				thread_data->overwrite_maps[tm] : NULL;
+	for (int tm = 0; tm < thread_data->nr_mmaps; tm++) {
+		struct mmap *map = thread_data->maps ? thread_data->maps[tm] : NULL,
+			    *overwrite_map = thread_data->overwrite_maps ?
+						thread_data->overwrite_maps[tm] : NULL;
 
-		for (f = 0; f < evlist->core.pollfd.nr; f++) {
+		for (int f = 0; f < evlist->core.pollfd.nr; f++) {
 			void *ptr = evlist->core.pollfd.priv[f].ptr;
 
 			if ((map && ptr == map) || (overwrite_map && ptr == overwrite_map)) {
-				pos = fdarray__dup_entry_from(&thread_data->pollfd, f,
+				int pos = fdarray__dup_entry_from(&thread_data->pollfd, f,
 							      &evlist->core.pollfd);
 				if (pos < 0)
 					return pos;
@@ -996,13 +993,12 @@ static int record__thread_data_init_pollfd(struct record_thread *thread_data, st
 
 static void record__free_thread_data(struct record *rec)
 {
-	int t;
 	struct record_thread *thread_data = rec->thread_data;
 
 	if (thread_data == NULL)
 		return;
 
-	for (t = 0; t < rec->nr_threads; t++) {
+	for (int t = 0; t < rec->nr_threads; t++) {
 		record__thread_data_close_pipes(&thread_data[t]);
 		zfree(&thread_data[t].maps);
 		zfree(&thread_data[t].overwrite_maps);
@@ -1014,20 +1010,18 @@ static void record__free_thread_data(struct record *rec)
 
 static int record__alloc_thread_data(struct record *rec, struct evlist *evlist)
 {
-	int t, ret;
-	struct record_thread *thread_data;
+	struct record_thread *thread_data = rec->thread_data = zalloc(rec->nr_threads * sizeof(*(rec->thread_data)));
+	int ret;
 
-	rec->thread_data = zalloc(rec->nr_threads * sizeof(*(rec->thread_data)));
 	if (!rec->thread_data) {
 		pr_err("Failed to allocate thread data\n");
 		return -ENOMEM;
 	}
-	thread_data = rec->thread_data;
 
-	for (t = 0; t < rec->nr_threads; t++)
+	for (int t = 0; t < rec->nr_threads; t++)
 		record__thread_data_init_pipes(&thread_data[t]);
 
-	for (t = 0; t < rec->nr_threads; t++) {
+	for (int t = 0; t < rec->nr_threads; t++) {
 		thread_data[t].rec = rec;
 		thread_data[t].mask = &rec->thread_masks[t];
 		ret = record__thread_data_init_maps(&thread_data[t], evlist);

  reply	other threads:[~2022-01-31 21:42 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-17 18:34 [PATCH v13 00/16] Introduce threaded trace streaming for basic perf record operation Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 01/16] perf record: Introduce thread affinity and mmap masks Alexey Bayduraev
2022-01-31 21:00   ` Arnaldo Carvalho de Melo
2022-01-31 21:16     ` Arnaldo Carvalho de Melo
2022-02-01 11:46       ` Bayduraev, Alexey V
2022-01-31 22:03     ` Arnaldo Carvalho de Melo
2022-01-31 22:04       ` Arnaldo Carvalho de Melo
2022-04-04 22:25   ` Ian Rogers
2022-04-05 16:21     ` Bayduraev, Alexey V
2022-04-06 16:46       ` Ian Rogers
2022-01-17 18:34 ` [PATCH v13 02/16] tools lib: Introduce fdarray duplicate function Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 03/16] perf record: Introduce thread specific data array Alexey Bayduraev
2022-01-31 21:39   ` Arnaldo Carvalho de Melo [this message]
2022-01-31 22:21     ` Arnaldo Carvalho de Melo
2022-02-11 16:51       ` Arnaldo Carvalho de Melo
2022-02-11 16:52         ` Arnaldo Carvalho de Melo
2022-02-11 19:34         ` Alexei Budankov
2022-01-17 18:34 ` [PATCH v13 04/16] perf record: Introduce function to propagate control commands Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 05/16] perf record: Introduce thread local variable Alexey Bayduraev
2022-01-31 21:42   ` Arnaldo Carvalho de Melo
2022-01-31 21:45   ` Arnaldo Carvalho de Melo
2022-02-01  7:35     ` Bayduraev, Alexey V
2022-01-17 18:34 ` [PATCH v13 06/16] perf record: Stop threads in the end of trace streaming Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 07/16] perf record: Start threads in the beginning " Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 08/16] perf record: Introduce data file at mmap buffer object Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 09/16] perf record: Introduce bytes written stats Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 10/16] perf record: Introduce compressor at mmap buffer object Alexey Bayduraev
2022-01-31 21:56   ` Arnaldo Carvalho de Melo
2022-02-01  8:08     ` Bayduraev, Alexey V
2022-01-17 18:34 ` [PATCH v13 11/16] perf record: Introduce data transferred and compressed stats Alexey Bayduraev
2022-01-24 15:28   ` Arnaldo Carvalho de Melo
2022-01-24 16:39     ` Arnaldo Carvalho de Melo
2022-01-17 18:34 ` [PATCH v13 12/16] perf record: Introduce --threads command line option Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 13/16] perf record: Extend " Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 14/16] perf record: Implement compatibility checks Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 15/16] perf session: Load data directory files for analysis Alexey Bayduraev
2022-01-17 18:34 ` [PATCH v13 16/16] perf report: Output data file name in raw trace dump Alexey Bayduraev
2022-01-24 15:45 ` [PATCH v13 00/16] Introduce threaded trace streaming for basic perf record operation 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=YfhXG5yEHhrGDjvl@kernel.org \
    --to=acme@kernel.org \
    --cc=abudankov@huawei.com \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.antonov@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexey.v.bayduraev@linux.intel.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rickyman7@gmail.com \
    /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