All of lore.kernel.org
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>
To: Jiri Olsa <jolsa@redhat.com>
Cc: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>,
	Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Clark Williams <williams@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Song Liu <songliubraving@fb.com>, Wang Nan <wangnan0@huawei.com>
Subject: Re: [PATCH 7/7] perf record: Introduce --switch-output-event
Date: Tue, 28 Apr 2020 15:05:18 -0300	[thread overview]
Message-ID: <20200428180518.GF5460@kernel.org> (raw)
In-Reply-To: <20200428132257.GH1476763@krava>

Em Tue, Apr 28, 2020 at 03:22:57PM +0200, Jiri Olsa escreveu:
> On Tue, Apr 28, 2020 at 09:16:01AM -0300, Arnaldo Carvalho de Melo wrote:
> 
> SNIP
> 
> > > > +				pr_err("Couldn't create side band evlist.\n.");
> > > > +				goto out_child;
> > > > +			}
> > > >  		}

> > > >  		if (evlist__add_bpf_sb_event(rec->sb_evlist, &session->header.env)) {

> > > it's getting bigger, I wonder we should put all the sb_* setup in
> > > separated functions like sb_start/sb_stop

> > Well, the rec->thread_id = pthread_self(); part is just for reusing a
> > 'perf record' specific mechanism, what to do when the event appears in
> > the side band thread ring buffer, the evlist__set_cb() also is related
> > to that, moving thread_id to evlist seems too much at this time.

> hum, I meant record specific static functions sb_start/sb_stop,
> not inside evlist.. just to have it separated

Ok, so I have the patch below on top of that series, and its all
available in my perf/switch-output-event, that is on top of more patches
collected today, all going well, this perf/switch-output-event will turn
into perf/core ang go upstream soon, then I have to loo at Adrian's
kernel+tooling patchkit,

- Arnaldo

commit a25516b4db23ba8f956b990d37ec6728e5221718
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date:   Tue Apr 28 14:58:29 2020 -0300

    perf record: Move side band evlist setup to separate routine
    
    It is quite big by now, move that code to a separate
    record__setup_sb_evlist() routine.
    
    Suggested-by: Jiri Olsa <jolsa@redhat.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Song Liu <songliubraving@fb.com>
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 7a6a89972691..bb3d30616bf3 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1445,6 +1445,44 @@ static int record__process_signal_event(union perf_event *event __maybe_unused,
 	return 0;
 }
 
+static int record__setup_sb_evlist(struct record *rec)
+{
+	struct record_opts *opts = &rec->opts;
+
+	if (rec->sb_evlist != NULL) {
+		/*
+		 * We get here if --switch-output-event populated the
+		 * sb_evlist, so associate a callback that will send a SIGUSR2
+		 * to the main thread.
+		 */
+		evlist__set_cb(rec->sb_evlist, record__process_signal_event, rec);
+		rec->thread_id = pthread_self();
+	}
+
+	if (!opts->no_bpf_event) {
+		if (rec->sb_evlist == NULL) {
+			rec->sb_evlist = evlist__new();
+
+			if (rec->sb_evlist == NULL) {
+				pr_err("Couldn't create side band evlist.\n.");
+				return -1;
+			}
+		}
+
+		if (evlist__add_bpf_sb_event(rec->sb_evlist, &rec->session->header.env)) {
+			pr_err("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n.");
+			return -1;
+		}
+	}
+
+	if (perf_evlist__start_sb_thread(rec->sb_evlist, &rec->opts.target)) {
+		pr_debug("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n");
+		opts->no_bpf_event = true;
+	}
+
+	return 0;
+}
+
 static int __cmd_record(struct record *rec, int argc, const char **argv)
 {
 	int err;
@@ -1589,36 +1627,9 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
 		goto out_child;
 	}
 
-	if (rec->sb_evlist != NULL) {
-		/*
-		 * We get here if --switch-output-event populated the
-		 * sb_evlist, so associate a callback that will send a SIGUSR2
-		 * to the main thread.
-		 */
-		evlist__set_cb(rec->sb_evlist, record__process_signal_event, rec);
-		rec->thread_id = pthread_self();
-	}
-
-	if (!opts->no_bpf_event) {
-		if (rec->sb_evlist == NULL) {
-			rec->sb_evlist = evlist__new();
-
-			if (rec->sb_evlist == NULL) {
-				pr_err("Couldn't create side band evlist.\n.");
-				goto out_child;
-			}
-		}
-
-		if (evlist__add_bpf_sb_event(rec->sb_evlist, &session->header.env)) {
-			pr_err("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n.");
-			goto out_child;
-		}
-	}
-
-	if (perf_evlist__start_sb_thread(rec->sb_evlist, &rec->opts.target)) {
-		pr_debug("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n");
-		opts->no_bpf_event = true;
-	}
+	err = record__setup_sb_evlist(rec);
+	if (err)
+		goto out_child;
 
 	err = record__synthesize(rec, false);
 	if (err < 0)

  reply	other threads:[~2020-04-28 18:05 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-27 21:19 [RFC PATCHSET] Implement --switch-output-events Arnaldo Carvalho de Melo
2020-04-27 21:19 ` [PATCH 1/7] perf record: Move sb_evlist to 'struct record' Arnaldo Carvalho de Melo
2020-04-27 21:19 ` [PATCH 2/7] perf top: Move sb_evlist to 'struct perf_top' Arnaldo Carvalho de Melo
2020-04-27 21:19 ` [PATCH 3/7] perf bpf: Decouple creating the evlist from adding the SB event Arnaldo Carvalho de Melo
2020-04-27 21:19 ` [PATCH 4/7] " Arnaldo Carvalho de Melo
2020-04-28  9:48   ` Jiri Olsa
2020-04-28 17:21     ` Arnaldo Carvalho de Melo
2020-04-27 21:19 ` [PATCH 5/7] perf parse-events: Add parse_events_option() variant that creates evlist Arnaldo Carvalho de Melo
2020-04-27 21:19 ` [PATCH 6/7] perf evlist: Allow reusing the side band thread for more purposes Arnaldo Carvalho de Melo
2020-04-27 21:19 ` [PATCH 7/7] perf record: Introduce --switch-output-event Arnaldo Carvalho de Melo
2020-04-28  9:48   ` Jiri Olsa
2020-04-28 12:16     ` Arnaldo Carvalho de Melo
2020-04-28 13:22       ` Jiri Olsa
2020-04-28 18:05         ` Arnaldo Carvalho de Melo [this message]
2020-04-29  8:18           ` 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=20200428180518.GF5460@kernel.org \
    --to=arnaldo.melo@gmail.com \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=jolsa@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=songliubraving@fb.com \
    --cc=tglx@linutronix.de \
    --cc=wangnan0@huawei.com \
    --cc=williams@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.