From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 752CBC54EBE for ; Fri, 6 Jan 2023 15:15:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232411AbjAFPPN (ORCPT ); Fri, 6 Jan 2023 10:15:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232981AbjAFPPB (ORCPT ); Fri, 6 Jan 2023 10:15:01 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E66F80AFA for ; Fri, 6 Jan 2023 07:15:00 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id l26so1248441wme.5 for ; Fri, 06 Jan 2023 07:15:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=IrpeNaKIi3qbKYOhoMFV4jENmjXkfJ5Lw7UV5vUFUN4=; b=qJVAXTrh0UjDONukH929lXDALK24r7/cE4bqo2NO7Y8TlhhQB5CMSXCgwDI3H+TOHg 3p9IARqukaJCsglnoHuVLP2LQSAuZkpvpuAXqi6viFalp//hXzY5cKJ+gf0kYFFCYkX1 Q3OIG9e/3/MU9KwJb3+a8/5XwnJYJGyYYYLWxFGjAwtApJgrIu/9MPcJEHFFjzSP23N/ ke6h8yy5As/NFHQ9aR0V54JoHpy61oc5fou3IsdTosMNbH5G14uQtdr5tUqbhqUGedb8 6YjwWJEO3Za9wZQgSuZs6LtDGLU7EwEA+9tvdPxUpFkTiObFJ+oBIpKrxQVd24Whr6Bl Ndhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IrpeNaKIi3qbKYOhoMFV4jENmjXkfJ5Lw7UV5vUFUN4=; b=OeKONSib30U0cIWAn/HYUCVDda08/jR8Wn8f6GzEpFHOemMQNH3azZse2pd9IBIK79 e9iPVZy5fmjxTuHZpE4txKx5R1+gL61Rqj4s2/kT1PX6RgK5N8tHqAqZ6SS/4nzNvTvg SEb7GrgjUFFeFlv3RfoxbjY5EMele35hk4bYBvQ7h02k5nyIgHYH082leLBcfAGc68+P MQp+tzCfAwrAummvMpDKFE+Z1+NAhtLmXSGEclqvpBZ73G9DHHQD1Z1SCHcv4uTRiHIw 6RS+qCbqg02v4MCmMy7yhVjazU3A1i0e0wmi/UWK1Wse4qgwDmPFGo751VlwE5JcXdeQ G3DQ== X-Gm-Message-State: AFqh2kpNQITO+GtoReSK5g1CCW+g4Fub/rZpIqBrauTon6DAfwzCPrOk kGjNTHMN+WHI5pQOSFKh29q9RtUWfzKd6xyLPiv11w== X-Google-Smtp-Source: AMrXdXs7rXE6Zem5ylaRY2fbqQ17dRvTnicAFsBgMmxxmOxjHwHeIulFBaGuonpnb/3AJO/Ar/OgXxcoigaJzssTANU= X-Received: by 2002:a05:600c:217:b0:3c6:c109:2d9 with SMTP id 23-20020a05600c021700b003c6c10902d9mr3663191wmi.149.1673018098956; Fri, 06 Jan 2023 07:14:58 -0800 (PST) MIME-Version: 1.0 References: <20230106142537.607399-1-irogers@google.com> In-Reply-To: From: Ian Rogers Date: Fri, 6 Jan 2023 07:14:46 -0800 Message-ID: Subject: Re: [PATCH v2 1/2] perf build: Properly guard libbpf includes To: Mike Leach Cc: Arnaldo Carvalho de Melo , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org On Fri, Jan 6, 2023 at 7:12 AM Mike Leach wrote: > > On Fri, 6 Jan 2023 at 14:55, Arnaldo Carvalho de Melo wrote: > > > > Em Fri, Jan 06, 2023 at 06:25:36AM -0800, Ian Rogers escreveu: > > > Including libbpf header files should be guarded by > > > HAVE_LIBBPF_SUPPORT. In bpf_counter.h, move the skeleton utilities > > > under HAVE_BPF_SKEL. > > > > > > Fixes: d6a735ef3277 ("perf bpf_counter: Move common functions to bpf_counter.h") > > > Reported-by: Mike Leach > > > Signed-off-by: Ian Rogers > > > > Can this be done in a way that reduces patch size? > > > > - Arnaldo Done in v3. Thanks, Ian > > > > > --- > > > tools/perf/builtin-trace.c | 2 + > > > tools/perf/util/bpf_counter.h | 85 ++++++++++++++++++----------------- > > > 2 files changed, 46 insertions(+), 41 deletions(-) > > > > > > diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c > > > index 86e06f136f40..d21fe0f32a6d 100644 > > > --- a/tools/perf/builtin-trace.c > > > +++ b/tools/perf/builtin-trace.c > > > @@ -16,7 +16,9 @@ > > > > > > #include "util/record.h" > > > #include > > > +#ifdef HAVE_LIBBPF_SUPPORT > > > #include > > > +#endif > > > #include "util/bpf_map.h" > > > #include "util/rlimit.h" > > > #include "builtin.h" > > > diff --git a/tools/perf/util/bpf_counter.h b/tools/perf/util/bpf_counter.h > > > index 4dbf26408b69..9113c8bf5cb0 100644 > > > --- a/tools/perf/util/bpf_counter.h > > > +++ b/tools/perf/util/bpf_counter.h > > > @@ -4,9 +4,12 @@ > > > > > > #include > > > #include > > > + > > > +#ifdef HAVE_LIBBPF_SUPPORT > > > #include > > > #include > > > #include > > > +#endif > > > > > > struct evsel; > > > struct target; > > > @@ -42,6 +45,47 @@ int bpf_counter__read(struct evsel *evsel); > > > void bpf_counter__destroy(struct evsel *evsel); > > > int bpf_counter__install_pe(struct evsel *evsel, int cpu_map_idx, int fd); > > > > > > +static inline __u32 bpf_link_get_id(int fd) > > > +{ > > > + struct bpf_link_info link_info = { .id = 0, }; > > > + __u32 link_info_len = sizeof(link_info); > > > + > > > + bpf_obj_get_info_by_fd(fd, &link_info, &link_info_len); > > > + return link_info.id; > > > +} > > > + > > > +static inline __u32 bpf_link_get_prog_id(int fd) > > > +{ > > > + struct bpf_link_info link_info = { .id = 0, }; > > > + __u32 link_info_len = sizeof(link_info); > > > + > > > + bpf_obj_get_info_by_fd(fd, &link_info, &link_info_len); > > > + return link_info.prog_id; > > > +} > > > + > > > +static inline __u32 bpf_map_get_id(int fd) > > > +{ > > > + struct bpf_map_info map_info = { .id = 0, }; > > > + __u32 map_info_len = sizeof(map_info); > > > + > > > + bpf_obj_get_info_by_fd(fd, &map_info, &map_info_len); > > > + return map_info.id; > > > +} > > > + > > > +/* trigger the leader program on a cpu */ > > > +static inline int bperf_trigger_reading(int prog_fd, int cpu) > > > +{ > > > + DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts, > > > + .ctx_in = NULL, > > > + .ctx_size_in = 0, > > > + .flags = BPF_F_TEST_RUN_ON_CPU, > > > + .cpu = cpu, > > > + .retval = 0, > > > + ); > > > + > > > + return bpf_prog_test_run_opts(prog_fd, &opts); > > > +} > > > + > > > #else /* HAVE_BPF_SKEL */ > > > > > > #include > > > @@ -87,45 +131,4 @@ static inline void set_max_rlimit(void) > > > setrlimit(RLIMIT_MEMLOCK, &rinf); > > > } > > > > > > -static inline __u32 bpf_link_get_id(int fd) > > > -{ > > > - struct bpf_link_info link_info = { .id = 0, }; > > > - __u32 link_info_len = sizeof(link_info); > > > - > > > - bpf_obj_get_info_by_fd(fd, &link_info, &link_info_len); > > > - return link_info.id; > > > -} > > > - > > > -static inline __u32 bpf_link_get_prog_id(int fd) > > > -{ > > > - struct bpf_link_info link_info = { .id = 0, }; > > > - __u32 link_info_len = sizeof(link_info); > > > - > > > - bpf_obj_get_info_by_fd(fd, &link_info, &link_info_len); > > > - return link_info.prog_id; > > > -} > > > - > > > -static inline __u32 bpf_map_get_id(int fd) > > > -{ > > > - struct bpf_map_info map_info = { .id = 0, }; > > > - __u32 map_info_len = sizeof(map_info); > > > - > > > - bpf_obj_get_info_by_fd(fd, &map_info, &map_info_len); > > > - return map_info.id; > > > -} > > > - > > > -/* trigger the leader program on a cpu */ > > > -static inline int bperf_trigger_reading(int prog_fd, int cpu) > > > -{ > > > - DECLARE_LIBBPF_OPTS(bpf_test_run_opts, opts, > > > - .ctx_in = NULL, > > > - .ctx_size_in = 0, > > > - .flags = BPF_F_TEST_RUN_ON_CPU, > > > - .cpu = cpu, > > > - .retval = 0, > > > - ); > > > - > > > - return bpf_prog_test_run_opts(prog_fd, &opts); > > > -} > > > - > > > #endif /* __PERF_BPF_COUNTER_H */ > > > -- > > > 2.39.0.314.g84b9a713c41-goog > > > > Tested-by: Mike Leach > > > -- > > > > - Arnaldo > > > -- > Mike Leach > Principal Engineer, ARM Ltd. > Manchester Design Centre. UK