From patchwork Fri Jan 6 15:13:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13091426 X-Patchwork-Delegate: bpf@iogearbox.net 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 AAACEC3DA7A for ; Fri, 6 Jan 2023 15:13:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229969AbjAFPNw (ORCPT ); Fri, 6 Jan 2023 10:13:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234814AbjAFPNe (ORCPT ); Fri, 6 Jan 2023 10:13:34 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C3C681102 for ; Fri, 6 Jan 2023 07:13:33 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id y66-20020a25c845000000b00733b5049b6fso2147277ybf.3 for ; Fri, 06 Jan 2023 07:13:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=WQYhbBO5EgEKPlarlDf3lbw8Z+u809vOBp5gbzOXfWg=; b=ZglYSagXvvcpZ/nsgRjuPaZDjdPN8PQgxIP65++2BPx/oEUTNGiJ6AoAHFhWjzunNj z0Wh2NzigVLGZE5V70sHsDkSHRIlbX04YSsFY4kZj+VKrKXUSKQU/IHyWYpeZ4h6s+LM HuFMdrRs+7Os/tAO0gnglPLlsTOnUvsLWM2eD5F3eYPeJZTBYEIeitL6HpEE9KDqjSpQ fHJLpcogYbfis5/hdrejzsvN++vqkalAmAZWn3OYTiEmPV1uKdzaXwfIs9Cwkqa4oU3m vJ6baOqAhLGcADA5RNODdFXe/HvYbRrf2AfZG0Xg+OxM7u0cMNGAGrzoIYzm23eopTfF RLWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=WQYhbBO5EgEKPlarlDf3lbw8Z+u809vOBp5gbzOXfWg=; b=mWxweYbPyb2+eBVxVsizd0ZjGufLbs6fPLu+ThtOVH/NLW8XW81xBCYFpqnTeUtnJy wcSgh8cMfNhBoxBg2bULyxGicYm700U1Br6TAjW+whFKVnkshxPzLZLij8BtqgdT0qHC zF2ZZHj+b026SyfSIdd7IIv7jCDSKRDHyXLcRpOGgW9+s2cyOoGshZhTfmim2zM+dP3R yOYLp/vg90CNUC63Kiyjjs2EsHpfdB8Sntk4iUIZxRJgu7ECrjWp2/9yg18h8S8bntGb EVH08v+vbJpKYLEPKGrLAvVih2KIpKxHTez0jkigxvadzDGI2WhzsZUOshZqLzrkkam3 wQ3w== X-Gm-Message-State: AFqh2kqF0IWXTbl11wq5eClslRKlDr52ViNxP6uC5QKHnhDIbdmy17l4 IVH36dR1735qdhGGQY1HRlbyW7ec59X1 X-Google-Smtp-Source: AMrXdXv4uHiZIJSyj4+N+cNmODTWl//P88+WIKFyg84i0Dqs6IfbUibr86rm2sJOmfCfZgkb0LKGk2RcYAU8 X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b317:a30:653a:18e5]) (user=irogers job=sendgmr) by 2002:a0d:cbd5:0:b0:469:d2b9:d8e8 with SMTP id n204-20020a0dcbd5000000b00469d2b9d8e8mr5538863ywd.177.1673018012862; Fri, 06 Jan 2023 07:13:32 -0800 (PST) Date: Fri, 6 Jan 2023 07:13:19 -0800 Message-Id: <20230106151320.619514-1-irogers@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH v3 1/2] perf build: Properly guard libbpf includes From: Ian Rogers To: Mike Leach , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, acme@kernel.org, irogers@google.com, peterz@infradead.org, mingo@redhat.com, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org 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 --- tools/perf/builtin-trace.c | 2 ++ tools/perf/util/bpf_counter.h | 6 ++++++ 2 files changed, 8 insertions(+) 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..c6d21c07b14c 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; @@ -87,6 +90,8 @@ static inline void set_max_rlimit(void) setrlimit(RLIMIT_MEMLOCK, &rinf); } +#ifdef HAVE_BPF_SKEL + static inline __u32 bpf_link_get_id(int fd) { struct bpf_link_info link_info = { .id = 0, }; @@ -127,5 +132,6 @@ static inline int bperf_trigger_reading(int prog_fd, int cpu) return bpf_prog_test_run_opts(prog_fd, &opts); } +#endif /* HAVE_BPF_SKEL */ #endif /* __PERF_BPF_COUNTER_H */ From patchwork Fri Jan 6 15:13:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13091427 X-Patchwork-Delegate: bpf@iogearbox.net 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 58F4EC54EBF for ; Fri, 6 Jan 2023 15:13:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233754AbjAFPNy (ORCPT ); Fri, 6 Jan 2023 10:13:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235322AbjAFPNn (ORCPT ); Fri, 6 Jan 2023 10:13:43 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B80E281119 for ; Fri, 6 Jan 2023 07:13:42 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-434eb7c6fa5so20795967b3.14 for ; Fri, 06 Jan 2023 07:13:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=1ELKsvqp/CVQlQh6V4i31lh01VunlKiC/zGB5BPQtSo=; b=b1woKxlTxDe2aMky9Gxycj7tdnYGqz4wHF+OS3uMz1LMlDeH1+FDNBZHw6QGRgHJbE 8KrRqouh3zKL51ld/RXy0PvPwQ/BNTrQ3mOLgjhTT/8rXpw2ZFVBzsfIzg8d/8Po1Usf zcdtFlfNIb+0vGlczu0pDF7irJQLaScldPBTyI7U4131OMwmPcYr88HTkl+JM8Xq+yMH KcLDUd1Cw0RU8ccBM+008GgZ6idhgM1U+quqBNoEc1SU3z+gAaPQJZgfpbvtJQfM902M 9k1c+/R5CXLIvrS945izzUudap5Gvqigac4ZN/JCC6w5tg/19v8XvJDRQJnZEjbd/u2F tA4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1ELKsvqp/CVQlQh6V4i31lh01VunlKiC/zGB5BPQtSo=; b=oFCxvw63bs8+oq8eO3K5uYT+f80Oer4HPTs/c4b4FybZskeBEHcQk+u84pvXCKvb2C 6zNOgvoDG/dDdr7Pu10re5Ip6w4ztPQ9+06uyNUvJDPT8gHae3RfSP0K6PoXdvjiBFdr TWQ67e8XnuWAcBXtx7QS7YpgDsZjvYnc5Dusacdm2O8Sl7gtRaMJlWMB/6/XGddPO1qX Ecj4b9zayxO57mBgUfBSe/z5Jp9NNGtWZa74J/BxIQQRmwV/AfKcp1GQdEZRjXl4KtqX oWS4ol734wsJrxpQAuOr0SD3pWp4Dn6WzYgYozHhHbzR2NXib0BAWtzvBgspfviar5tq Q+SA== X-Gm-Message-State: AFqh2krTqDign0qjABfMBJUx7puW6LyWUSeNUmELTkbKVaObJ5JsP1vS oOnJXuYlXKgdKBbRCl5zRfwrxfLry3SF X-Google-Smtp-Source: AMrXdXvOmlZdfXY1yS0XS9Kwv3Fztvy4P5OCtKpH7XLsXyDAs64NyLwnS9FfEtbqBZEWbJ1J9cMhjXaXt1kn X-Received: from irogers.svl.corp.google.com ([2620:15c:2d4:203:b317:a30:653a:18e5]) (user=irogers job=sendgmr) by 2002:a25:5144:0:b0:753:4db:6fcc with SMTP id f65-20020a255144000000b0075304db6fccmr5824670ybb.1.1673018022074; Fri, 06 Jan 2023 07:13:42 -0800 (PST) Date: Fri, 6 Jan 2023 07:13:20 -0800 In-Reply-To: <20230106151320.619514-1-irogers@google.com> Message-Id: <20230106151320.619514-2-irogers@google.com> Mime-Version: 1.0 References: <20230106151320.619514-1-irogers@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Subject: [PATCH v3 2/2] perf build: Fix build error when NO_LIBBPF=1 From: Ian Rogers To: Mike Leach , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, acme@kernel.org, irogers@google.com, peterz@infradead.org, mingo@redhat.com, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org The $(LIBBPF) target should only be a dependency of prepare if the static version of libbpf is needed. Add a new LIBBPF_STATIC variable that is set by Makefile.config. Use LIBBPF_STATIC to determine whether the CFLAGS, etc. need updating and for adding $(LIBBPF) as a prepare dependency. As Makefile.config isn't loaded for "clean" as a target, always set LIBBPF_OUTPUT regardless of whether it is needed for $(LIBBPF). This is done to minimize conditional logic for $(LIBBPF)-clean. This issue and an original fix was reported by Mike Leach in: https://lore.kernel.org/lkml/20230105172243.7238-1-mike.leach@linaro.org/ Fixes: 746bd29e348f ("perf build: Use tools/lib headers from install path") Reported-by: Mike Leach Signed-off-by: Ian Rogers --- tools/perf/Makefile.config | 2 ++ tools/perf/Makefile.perf | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index c2504c39bdcb..7c00ce0a7464 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -602,6 +602,8 @@ ifndef NO_LIBELF dummy := $(error Error: No libbpf devel library found, please install libbpf-devel); endif else + # Libbpf will be built as a static library from tools/lib/bpf. + LIBBPF_STATIC := 1 CFLAGS += -DHAVE_LIBBPF_BTF__LOAD_FROM_KERNEL_BY_ID CFLAGS += -DHAVE_LIBBPF_BPF_PROG_LOAD CFLAGS += -DHAVE_LIBBPF_BPF_OBJECT__NEXT_PROGRAM diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 13e7d26e77f0..4e370462e7e1 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -303,10 +303,12 @@ ifneq ($(OUTPUT),) else LIBBPF_OUTPUT = $(CURDIR)/libbpf endif -LIBBPF_DESTDIR = $(LIBBPF_OUTPUT) -LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include -LIBBPF = $(LIBBPF_OUTPUT)/libbpf.a -CFLAGS += -I$(LIBBPF_OUTPUT)/include +ifdef LIBBPF_STATIC + LIBBPF_DESTDIR = $(LIBBPF_OUTPUT) + LIBBPF_INCLUDE = $(LIBBPF_DESTDIR)/include + LIBBPF = $(LIBBPF_OUTPUT)/libbpf.a + CFLAGS += -I$(LIBBPF_OUTPUT)/include +endif ifneq ($(OUTPUT),) LIBSUBCMD_OUTPUT = $(abspath $(OUTPUT))/libsubcmd @@ -393,10 +395,8 @@ endif export PERL_PATH PERFLIBS = $(LIBAPI) $(LIBPERF) $(LIBSUBCMD) $(LIBSYMBOL) -ifndef NO_LIBBPF - ifndef LIBBPF_DYNAMIC - PERFLIBS += $(LIBBPF) - endif +ifdef LIBBPF_STATIC + PERFLIBS += $(LIBBPF) endif # We choose to avoid "if .. else if .. else .. endif endif" @@ -756,12 +756,15 @@ prepare: $(OUTPUT)PERF-VERSION-FILE $(OUTPUT)common-cmds.h archheaders $(drm_ioc $(arch_errno_name_array) \ $(sync_file_range_arrays) \ $(LIBAPI) \ - $(LIBBPF) \ $(LIBPERF) \ $(LIBSUBCMD) \ $(LIBSYMBOL) \ bpf-skel +ifdef LIBBPF_STATIC +prepare: $(LIBBPF) +endif + $(OUTPUT)%.o: %.c prepare FORCE $(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=$(build-dir) $@