Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp603650ybz; Wed, 29 Apr 2020 06:13:30 -0700 (PDT) X-Google-Smtp-Source: APiQypKaXvbeAB4MRyW6WIz/FxmjhfsLMDCQOsIpt7o//vHJrq5xo9MXFbfPRdKVbLtg3wMnwjB+ X-Received: by 2002:a50:f0dc:: with SMTP id a28mr2246398edm.87.1588166010175; Wed, 29 Apr 2020 06:13:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588166010; cv=none; d=google.com; s=arc-20160816; b=e5LjRqc9KpWAPkjPvXnpx3zEpVUnIQpzsQsR/4bZbzBg92l+GsHhN4bB1u/zoKAsRE XAWbwibuMuRRUnJewjUP4+P7yrQgXbIq1Q03X2a5Nf4jFsK/WN4PW2qCJqInvHImca1p Z0q9949P3oHDUG6Q+fpekaqFU5xnHWxYMz/qV7ZD5gm/5kF+uiaD1ZWW+fowuT1offEm SpSF432LKL2SDMM+NgmXrR83r79CBQgHmCKZzjt/RCq+M72u3BdNoJiC2dUfd2Dc7440 IjQdOtKrrwUhwA8y3onAng3X+l+jWLCpZK6Yx3lrFhV5/kCOrHmS984JPS+gKt22QX1a /syA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3iXO1F8JNj9MvYevuTVEyLkhqVMGxP9O/0TjNsuE8sE=; b=d02EUuhToDRhEb7OMhwwSZSqOj7Bg+8gveqJu/VqWhNFc/iPIF5x9B7p91v3TP9Z/D 7nRrweG5NRY1uw2a3A2XILbYOSxVVtJQdf62pk/m7mnRki1Di4bU5GShULopMTKA/04C 99pkscmA9akqDY936cqtwzxaSxOZuOnJUcBLc5Zqlh9J9+nlgu3I1coEG+zneEOynLK5 eOdMWikasmT3LXZX+GluiPQfSSxhStWbh6JWUm3yN01ZloMKjCGgNXioFdWKjug7FPJg QKIDue5qJrtXCQ2Z3tFUsZZ14nweBldrDDC0xBHYjvtRO++fg0QKQIJjZuZtWgkM0gX0 uuig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=W25M6flC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s11si3752302edg.77.2020.04.29.06.13.06; Wed, 29 Apr 2020 06:13:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=W25M6flC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727085AbgD2NLZ (ORCPT + 99 others); Wed, 29 Apr 2020 09:11:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:47960 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726847AbgD2NLX (ORCPT ); Wed, 29 Apr 2020 09:11:23 -0400 Received: from quaco.ghostprotocols.net (unknown [179.97.37.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AFF4222202; Wed, 29 Apr 2020 13:11:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588165882; bh=O6/slAuNjtLT8FNgNucnuPsCjAxOw2HTz1nN5+EVxGo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W25M6flCbmiQUfjeRfu9D29ZPeLmi54FjD09apMt6wnVGfcrQyP2CkeE/jdiWiG5H ffIqv2KSuKqHXJMT88ZXyFIr4vFv8o2IwjABdLNY4EEzbBrjpIaE1df7OeCoyFLcEE t1wakE24z017XgIBSEQAn83ny+8qH0C4/XyScwi4= From: Arnaldo Carvalho de Melo To: Jiri Olsa , Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Adrian Hunter , Song Liu Subject: [PATCH 3/8] perf bpf: Decouple creating the evlist from adding the SB event Date: Wed, 29 Apr 2020 10:11:01 -0300 Message-Id: <20200429131106.27974-4-acme@kernel.org> X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200429131106.27974-1-acme@kernel.org> References: <20200429131106.27974-1-acme@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnaldo Carvalho de Melo Renaming bpf_event__add_sb_event() to evlist__add_sb_event() and requiring that the evlist be allocated beforehand. This will allow using the same side band thread and evlist to be used for multiple purposes in addition to react to PERF_RECORD_BPF_EVENT soon after they are generated. Cc: Adrian Hunter Cc: Jiri Olsa Cc: Namhyung Kim Cc: Song Liu Link: http://lore.kernel.org/lkml/20200427211935.25789-4-acme@kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-record.c | 17 ++++++++++++++--- tools/perf/builtin-top.c | 15 +++++++++++++-- tools/perf/util/bpf-event.c | 3 +-- tools/perf/util/bpf-event.h | 7 +++---- tools/perf/util/evlist.c | 17 +++-------------- tools/perf/util/evlist.h | 2 +- 6 files changed, 35 insertions(+), 26 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 2348c4205e59..ed2244847400 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1572,16 +1572,27 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) goto out_child; } + err = -1; if (!rec->no_buildid && !perf_header__has_feat(&session->header, HEADER_BUILD_ID)) { pr_err("Couldn't generate buildids. " "Use --no-buildid to profile anyway.\n"); - err = -1; goto out_child; } - if (!opts->no_bpf_event) - bpf_event__add_sb_event(&rec->sb_evlist, &session->header.env); + if (!opts->no_bpf_event) { + 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"); diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c index 70e1c732db6a..de24aced7213 100644 --- a/tools/perf/builtin-top.c +++ b/tools/perf/builtin-top.c @@ -1742,8 +1742,19 @@ int cmd_top(int argc, const char **argv) goto out_delete_evlist; } - if (!top.record_opts.no_bpf_event) - bpf_event__add_sb_event(&top.sb_evlist, &perf_env); + if (!top.record_opts.no_bpf_event) { + top.sb_evlist = evlist__new(); + + if (top.sb_evlist == NULL) { + pr_err("Couldn't create side band evlist.\n."); + goto out_delete_evlist; + } + + if (evlist__add_bpf_sb_event(top.sb_evlist, &perf_env)) { + pr_err("Couldn't ask for PERF_RECORD_BPF_EVENT side band events.\n."); + goto out_delete_evlist; + } + } if (perf_evlist__start_sb_thread(top.sb_evlist, target)) { pr_debug("Couldn't start the BPF side band thread:\nBPF programs starting from now on won't be annotatable\n"); diff --git a/tools/perf/util/bpf-event.c b/tools/perf/util/bpf-event.c index 0cd41a862952..3742511a08d1 100644 --- a/tools/perf/util/bpf-event.c +++ b/tools/perf/util/bpf-event.c @@ -509,8 +509,7 @@ static int bpf_event__sb_cb(union perf_event *event, void *data) return 0; } -int bpf_event__add_sb_event(struct evlist **evlist, - struct perf_env *env) +int evlist__add_bpf_sb_event(struct evlist *evlist, struct perf_env *env) { struct perf_event_attr attr = { .type = PERF_TYPE_SOFTWARE, diff --git a/tools/perf/util/bpf-event.h b/tools/perf/util/bpf-event.h index 81fdc88e6c1a..68f315c3df5b 100644 --- a/tools/perf/util/bpf-event.h +++ b/tools/perf/util/bpf-event.h @@ -33,8 +33,7 @@ struct btf_node { #ifdef HAVE_LIBBPF_SUPPORT int machine__process_bpf(struct machine *machine, union perf_event *event, struct perf_sample *sample); -int bpf_event__add_sb_event(struct evlist **evlist, - struct perf_env *env); +int evlist__add_bpf_sb_event(struct evlist *evlist, struct perf_env *env); void bpf_event__print_bpf_prog_info(struct bpf_prog_info *info, struct perf_env *env, FILE *fp); @@ -46,8 +45,8 @@ static inline int machine__process_bpf(struct machine *machine __maybe_unused, return 0; } -static inline int bpf_event__add_sb_event(struct evlist **evlist __maybe_unused, - struct perf_env *env __maybe_unused) +static inline int evlist__add_bpf_sb_event(struct evlist *evlist __maybe_unused, + struct perf_env *env __maybe_unused) { return 0; } diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 82d9f9bb8975..1d0d36da223b 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c @@ -1704,38 +1704,27 @@ struct evsel *perf_evlist__reset_weak_group(struct evlist *evsel_list, return leader; } -int perf_evlist__add_sb_event(struct evlist **evlist, +int perf_evlist__add_sb_event(struct evlist *evlist, struct perf_event_attr *attr, perf_evsel__sb_cb_t cb, void *data) { struct evsel *evsel; - bool new_evlist = (*evlist) == NULL; - - if (*evlist == NULL) - *evlist = evlist__new(); - if (*evlist == NULL) - return -1; if (!attr->sample_id_all) { pr_warning("enabling sample_id_all for all side band events\n"); attr->sample_id_all = 1; } - evsel = perf_evsel__new_idx(attr, (*evlist)->core.nr_entries); + evsel = perf_evsel__new_idx(attr, evlist->core.nr_entries); if (!evsel) goto out_err; evsel->side_band.cb = cb; evsel->side_band.data = data; - evlist__add(*evlist, evsel); + evlist__add(evlist, evsel); return 0; - out_err: - if (new_evlist) { - evlist__delete(*evlist); - *evlist = NULL; - } return -1; } diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index f5bd5c386df1..0f02408fff3e 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h @@ -107,7 +107,7 @@ int __perf_evlist__add_default_attrs(struct evlist *evlist, int perf_evlist__add_dummy(struct evlist *evlist); -int perf_evlist__add_sb_event(struct evlist **evlist, +int perf_evlist__add_sb_event(struct evlist *evlist, struct perf_event_attr *attr, perf_evsel__sb_cb_t cb, void *data); -- 2.21.1