Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4156907ybc; Tue, 26 Nov 2019 04:50:28 -0800 (PST) X-Google-Smtp-Source: APXvYqyWJd1zVvr6yN66ZQgwuYMEv7/ACOwGKJlUHHVsQpK/xTnD7hTyyTxRyyTBVbPKmgdycR52 X-Received: by 2002:aa7:d7d7:: with SMTP id e23mr24296055eds.236.1574772628344; Tue, 26 Nov 2019 04:50:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574772628; cv=none; d=google.com; s=arc-20160816; b=X+JwI7jtflJuUs6UdpcgmO8/aAeJ3cGcq8pQHVr+v1BEIULaMuAh2QvWDxnqJOs4Og o97sJsi+AZRyHqZkOMxJfAieRtf9ehb5Fu2/++zJPEbHHK5UhIl0QUDju23rCFqLH1UV oy4kHn05z2lVn5RAIipOqXzFhHK+AyPEVfB/3MsXoveyD74dxN27f/uoRA1m52f0KWsa nKRdXnuUDmT2XeZEU+3sQoQ+5CTXqllYbpxvmiVkT+gFZpgTdbpaRploAEaRODlQg2PX yCUkfgUecVLglJ99J3i3vx37lonKmK+w+RFWt44YU/4DbpU4qEDXeSG/Y48YwdczIVlW 3A6A== 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 :message-id:date:subject:cc:to:from; bh=hqNUJPbYaRH5o/lTppT2GLh7coel+PR0vdQiPDgJ6Ls=; b=J58RMGfhcU5KI1d0G240HoouQVrOFJnDP7ebpFKPRlaHZLjY/BYkFgpOF8LZ/mAOwT IKymunS3RXkd4LEgF3j6M0GCPixNejl1GDcnlgWbi2xpMamGAqOd+ha47IvdwHhxM6qm 2PIHUk5iS//poM9/kU0xTuyNwUiU+JyWoOlIeS8qcBi/a5iu2BDSGjyVAuiWbQ51yTaj mDn0M93lC+o5q8cVjye24JphOKl+4na7hS8K8FidQQEST3zZrKg+0hnbGq1IZpAyisDM c5bx1JWuQZfCbktLpxveM2v2N6NUPYhf4QeeIJtZ3M8QB6uKWE/EqG0Ffh+Ofptu6wdd DIzg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z35si7845955edz.260.2019.11.26.04.50.04; Tue, 26 Nov 2019 04:50:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727704AbfKZMNL convert rfc822-to-8bit (ORCPT + 99 others); Tue, 26 Nov 2019 07:13:11 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:52279 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728216AbfKZMNL (ORCPT ); Tue, 26 Nov 2019 07:13:11 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-272-Lf3LCucJOjqU-xrFJNGEEw-1; Tue, 26 Nov 2019 07:13:06 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8BE1080058F; Tue, 26 Nov 2019 12:13:04 +0000 (UTC) Received: from krava.redhat.com (unknown [10.43.17.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D0D160BEC; Tue, 26 Nov 2019 12:12:54 +0000 (UTC) From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , netdev@vger.kernel.org, bpf@vger.kernel.org, Ingo Molnar , Namhyung Kim , Alexander Shishkin , Peter Zijlstra , Michael Petlan , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Jesper Dangaard Brouer , Daniel Borkmann , Alexei Starovoitov , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko Subject: [PATCH] perf tools: Allow to link with libbpf dynamicaly Date: Tue, 26 Nov 2019 13:12:53 +0100 Message-Id: <20191126121253.28253-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-MC-Unique: Lf3LCucJOjqU-xrFJNGEEw-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently we support only static linking with kernel's libbpf (tools/lib/bpf). This patch adds libbpf package detection and support to link perf with it dynamically. The libbpf package status is displayed with: $ make VF=1 Auto-detecting system features: ... ... libbpf: [ on ] It's not checked by default, because it's quite new. Once it's on most distros we can switch it on. For the same reason it's not added to the test-all check. Perf does not need advanced version of libbpf, so we can check just for the base bpf_object__open function. Adding new compile variable to detect libbpf package and link bpf dynamically: $ make LIBBPF_DYNAMIC=1 ... LINK perf $ ldd perf | grep bpf libbpf.so.0 => /lib64/libbpf.so.0 (0x00007f46818bc000) If libbpf is not installed, build stops with: Makefile.config:486: *** Error: No libbpf devel library found,\ please install libbpf-devel. Stop. Link: http://lkml.kernel.org/n/tip-kjdr6k37nuoiwbl0yltla1nh@git.kernel.org Signed-off-by: Jiri Olsa --- tools/build/Makefile.feature | 3 ++- tools/build/feature/Makefile | 4 ++++ tools/build/feature/test-libbpf.c | 7 +++++++ tools/perf/Makefile.config | 10 ++++++++++ tools/perf/Makefile.perf | 6 +++++- 5 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 tools/build/feature/test-libbpf.c diff --git a/tools/build/Makefile.feature b/tools/build/Makefile.feature index 8a19753cc26a..574c2e0b9d20 100644 --- a/tools/build/Makefile.feature +++ b/tools/build/Makefile.feature @@ -96,7 +96,8 @@ FEATURE_TESTS_EXTRA := \ cxx \ llvm \ llvm-version \ - clang + clang \ + libbpf FEATURE_TESTS ?= $(FEATURE_TESTS_BASIC) diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile index 8499385365c0..f30a89046aa3 100644 --- a/tools/build/feature/Makefile +++ b/tools/build/feature/Makefile @@ -53,6 +53,7 @@ FILES= \ test-zlib.bin \ test-lzma.bin \ test-bpf.bin \ + test-libbpf.bin \ test-get_cpuid.bin \ test-sdt.bin \ test-cxx.bin \ @@ -270,6 +271,9 @@ $(OUTPUT)test-get_cpuid.bin: $(OUTPUT)test-bpf.bin: $(BUILD) +$(OUTPUT)test-libbpf.bin: + $(BUILD) -lbpf + $(OUTPUT)test-sdt.bin: $(BUILD) diff --git a/tools/build/feature/test-libbpf.c b/tools/build/feature/test-libbpf.c new file mode 100644 index 000000000000..a508756cf4cc --- /dev/null +++ b/tools/build/feature/test-libbpf.c @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0 +#include + +int main(void) +{ + return bpf_object__open("test") ? 0 : -1; +} diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index 1783427da9b0..c90f4146e5a2 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -483,6 +483,16 @@ ifndef NO_LIBELF ifeq ($(feature-bpf), 1) CFLAGS += -DHAVE_LIBBPF_SUPPORT $(call detected,CONFIG_LIBBPF) + + # detecting libbpf without LIBBPF_DYNAMIC, so make VF=1 shows libbpf detection status + $(call feature_check,libbpf) + ifdef LIBBPF_DYNAMIC + ifeq ($(feature-libbpf), 1) + EXTLIBS += -lbpf + else + dummy := $(error Error: No libbpf devel library found, please install libbpf-devel); + endif + endif endif ifndef NO_DWARF diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 1cd294468a1f..eae5d5e95952 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -116,6 +116,8 @@ include ../scripts/utilities.mak # # Define TCMALLOC to enable tcmalloc heap profiling. # +# Define LIBBPF_DYNAMIC to enable libbpf dynamic linking. +# # As per kernel Makefile, avoid funny character set dependencies unexport LC_ALL @@ -360,7 +362,9 @@ export PERL_PATH PERFLIBS = $(LIBAPI) $(LIBTRACEEVENT) $(LIBSUBCMD) $(LIBPERF) ifndef NO_LIBBPF - PERFLIBS += $(LIBBPF) + ifndef LIBBPF_DYNAMIC + PERFLIBS += $(LIBBPF) + endif endif # We choose to avoid "if .. else if .. else .. endif endif" -- 2.21.0