From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Jiri Olsa <jolsa@redhat.com>
Cc: lkml <linux-kernel@vger.kernel.org>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Ingo Molnar <mingo@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Namhyung Kim <namhyung@kernel.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Michael Petlan <mpetlan@redhat.com>,
Ian Rogers <irogers@google.com>,
Shunsuke Nakamura <nakamura.shun@fujitsu.com>,
linux-perf-users@vger.kernel.org
Subject: [PATCH] libperf: Remove BUG_ON() from library code in get_group_fd(). was Re: [PATCH 6/7] libperF: Add group support to perf_evsel__open
Date: Fri, 9 Jul 2021 14:57:23 -0300 [thread overview]
Message-ID: <YOiOA5zOtVH9IBbE@kernel.org> (raw)
In-Reply-To: <YOXvSpcxeAnrGBTi@krava>
Em Wed, Jul 07, 2021 at 08:15:38PM +0200, Jiri Olsa escreveu:
> On Wed, Jul 07, 2021 at 02:43:07PM -0300, Arnaldo Carvalho de Melo wrote:
> > Em Tue, Jul 06, 2021 at 05:17:03PM +0200, Jiri Olsa escreveu:
> > > +static int get_group_fd(struct perf_evsel *evsel, int cpu, int thread)
> > > +{
> > > + struct perf_evsel *leader = evsel->leader;
> > > + int fd;
> > > +
> > > + if (evsel == leader)
> > > + return -1;
> > > +
> > > + /*
> > > + * Leader must be already processed/open,
> > > + * if not it's a bug.
> > > + */
> > > + BUG_ON(!leader->fd);
> > Humm, having panics in library code looks ugly, why can't we just return
> > some errno and let the whatever is using the library to fail gracefully?
> true, I took it from perf code, did not realize this,
> I'll check what can we do in here
So, I've added this as a follow up patch:
commit 0ec138125eaea5f15157adcecc3e0def1ad2ed22
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date: Fri Jul 9 14:52:16 2021 -0300
libperf: Remove BUG_ON() from library code in get_group_fd()
We shouldn't just panic, return a value that doesn't clash with what
perf_evsel__open() was already returning in case of error, i.e. errno
when sys_perf_event_open() fails.
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Shunsuke Nakamura <nakamura.shun@fujitsu.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
diff --git a/tools/lib/perf/evsel.c b/tools/lib/perf/evsel.c
index 9ebf7122d4766c5e..d8886720e83d8dfe 100644
--- a/tools/lib/perf/evsel.c
+++ b/tools/lib/perf/evsel.c
@@ -77,23 +77,30 @@ sys_perf_event_open(struct perf_event_attr *attr,
return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags);
}
-static int get_group_fd(struct perf_evsel *evsel, int cpu, int thread)
+static int get_group_fd(struct perf_evsel *evsel, int cpu, int thread, int *group_fd)
{
struct perf_evsel *leader = evsel->leader;
int fd;
- if (evsel == leader)
- return -1;
+ if (evsel == leader) {
+ *group_fd = -1;
+ return 0;
+ }
/*
* Leader must be already processed/open,
* if not it's a bug.
*/
- BUG_ON(!leader->fd);
+ if (!leader->fd)
+ return -ENOTCONN;
fd = FD(leader, cpu, thread);
- BUG_ON(fd == -1);
- return fd;
+ if (fd == -1)
+ return -EBADF;
+
+ *group_fd = fd;
+
+ return 0;
}
int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
@@ -133,7 +140,9 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
for (thread = 0; thread < threads->nr; thread++) {
int fd, group_fd;
- group_fd = get_group_fd(evsel, cpu, thread);
+ err = get_group_fd(evsel, cpu, thread, &group_fd);
+ if (err < 0)
+ return err;
fd = sys_perf_event_open(&evsel->attr,
threads->map[thread].pid,
next prev parent reply other threads:[~2021-07-09 17:57 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-06 15:16 [RFCv2 0/7] libperf: Add leader/group info to perf_evsel Jiri Olsa
2021-07-06 15:16 ` [PATCH 1/7] libperf: Change tests to single static and shared binaries Jiri Olsa
2021-07-06 15:16 ` [PATCH 2/7] libperf: Move idx to perf_evsel::idx Jiri Olsa
2021-07-07 14:45 ` Arnaldo Carvalho de Melo
2021-07-07 18:17 ` Jiri Olsa
2021-07-07 18:36 ` Arnaldo Carvalho de Melo
2021-07-07 14:49 ` Arnaldo Carvalho de Melo
2021-07-07 17:48 ` Arnaldo Carvalho de Melo
2021-07-07 18:18 ` Jiri Olsa
2021-07-07 18:17 ` Jiri Olsa
2021-07-06 15:17 ` [PATCH 3/7] libperf: Move leader to perf_evsel::leader Jiri Olsa
2021-07-07 14:53 ` Arnaldo Carvalho de Melo
2021-07-07 18:14 ` Jiri Olsa
2021-07-07 18:34 ` Arnaldo Carvalho de Melo
2021-07-06 15:17 ` [PATCH 4/7] libperf: Move nr_groups to evlist::nr_groups Jiri Olsa
2021-07-06 15:17 ` [PATCH 5/7] libperf: Add perf_evlist__set_leader function Jiri Olsa
2021-07-06 15:17 ` [PATCH 6/7] libperF: Add group support to perf_evsel__open Jiri Olsa
2021-07-07 17:43 ` Arnaldo Carvalho de Melo
2021-07-07 18:15 ` Jiri Olsa
2021-07-09 17:57 ` Arnaldo Carvalho de Melo [this message]
2021-07-06 15:17 ` [PATCH 7/7] libperf: Add tests for perf_evlist__set_leader function Jiri Olsa
2021-07-09 17:59 ` Arnaldo Carvalho de Melo
2021-07-07 14:47 ` [RFCv2 0/7] libperf: Add leader/group info to perf_evsel Arnaldo Carvalho de Melo
2021-07-07 18:20 ` Jiri Olsa
2021-07-07 18:37 ` Arnaldo Carvalho de Melo
2021-07-09 8:32 ` nakamura.shun
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=YOiOA5zOtVH9IBbE@kernel.org \
--to=acme@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@kernel.org \
--cc=mpetlan@redhat.com \
--cc=nakamura.shun@fujitsu.com \
--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).