Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2097859imm; Wed, 16 May 2018 07:52:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoZoqYnH9IhE41EOO3D9g6ELb1DtyBt5zFkEE+A6/hB1vp6t0FAR+nR6dD/g1mPybw6qwA1 X-Received: by 2002:a17:902:6b44:: with SMTP id g4-v6mr1260036plt.390.1526482352375; Wed, 16 May 2018 07:52:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526482352; cv=none; d=google.com; s=arc-20160816; b=NWHBXlPn2cw5nj22vVES0BwKKLGpzXhAfXPoImF+B5qUbTA/MnhNOgvkmuuVtAuP/J ElsU9kzoei+WcRch5/7jXLG0h2pNIxHpW4IM/PFrfzGV1Vn7DxGDQs3q9NV5N3JEfGHY 50tm250YlkEVvvU93I8Onq5ykBX6GsVx5Ulxvhv1/bj9MeSaFonAY9CW9aMaBjMuHmTO dNENUJskougIIr6rLet6uIqgwqNKkq0imC6H47y9wkuXJAGC9hM8Tl8QO9setp0prKT+ rWuhVWkQhDuozjVcWwoFhP+ei/zXrJVTpJTbG9VwfVEU/oGCAvtfhapNFTSVRIHT8d3X i26Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=rfdJN/1dZrWQIzl1K4+ZfXgW0Nze3rBZ0Z+BgAzJ7Pk=; b=ZB+3EC64W0mHfx2HP8a9g92aCN5wED8qqgd2HX1Yp1PLiK3eLowRGNTam21SW62XjK wvwQ9EM0lPRknjMJN/GdoDnjANWm2Fm7nNHq41WcV/1YYFtZQ0nofH28O3H5OE8c4oMT K59Me7Mpnnol0O7lREiSL0rwHDaAbVcMjliUdjWAJkadBLKfssAC9vCTXQgiiPnq9EqS tHAdPl6LiRDS43Au7bKLl+2ZYSGeUjEfj3TP2DtEKY7zJxY2chfeluhgqibyQfFiwVcV 7/EUGfvcIcXhRdcmb1q2A1rCs8TS4Uzd4dQ/bPPeaDwGAxprlebHrsWpGXlUYZpQ16p9 VQ/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=memQNca/; 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=pass (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 x191-v6si2315414pgx.83.2018.05.16.07.52.17; Wed, 16 May 2018 07:52:32 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=memQNca/; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751644AbeEPOti (ORCPT + 99 others); Wed, 16 May 2018 10:49:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:46056 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751467AbeEPOtf (ORCPT ); Wed, 16 May 2018 10:49:35 -0400 Received: from jouet.infradead.org (unknown [179.97.41.186]) (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 56FB22083F; Wed, 16 May 2018 14:49:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1526482174; bh=RNPe/QBJpIpemyepz0y97FaoNcTRElk9ivQyf5sVcsI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=memQNca/4ZmLcV8A0XOYJPbQ099vFKj1MO2A6oB3VTOelTCbu20xxQ0LqNKRsYyIq AebwMB2vjEzBKPqTh+gGegozhzjAufeUSkoq+mXPFO44owiEo/bdE5t2gD4FAeAXTp JWmArnj5vRqPe874k7VV89w8FTFI/Le3ZbDp4G/M= From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: Clark Williams , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Adrian Hunter , David Ahern , Jiri Olsa , Namhyung Kim , Wang Nan Subject: [PATCH 04/11] perf bpf: Add 'examples' directories Date: Wed, 16 May 2018 11:49:01 -0300 Message-Id: <20180516144908.22212-5-acme@kernel.org> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180516144908.22212-1-acme@kernel.org> References: <20180516144908.22212-1-acme@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnaldo Carvalho de Melo The first one is the bare minimum that bpf infrastructure accepts before it expects actual events to be set up: $ cat tools/perf/examples/bpf/empty.c char _license[] __attribute__((section("license"), used)) = "GPL"; int _version __attribute__((section("version"), used)) = LINUX_VERSION_CODE; $ If you remove that "version" line, then it will be refused with: # perf trace -e tools/perf/examples/bpf/empty.c event syntax error: 'tools/perf/examples/bpf/empty.c' \___ Failed to load tools/perf/examples/bpf/empty.c from source: 'version' section incorrect or lost (add -v to see detail) Run 'perf list' for a list of valid events Usage: perf trace [] [] or: perf trace [] -- [] or: perf trace record [] [] or: perf trace record [] -- [] -e, --event event/syscall selector. use 'perf list' to list available events # The next ones will, step by step, show simple filters, then the needs for headers will be made clear, it will be put in place and tested with new examples, rinse, repeat. Back to using this first one to test the perf+bpf infrastructure: If we run it will fail, as no functions are present connecting with, say, a tracepoint or a function using the kprobes or uprobes infrastructure: # perf trace -e tools/perf/examples/bpf/empty.c WARNING: event parser found nothing invalid or unsupported event: 'tools/perf/examples/bpf/empty.c' Run 'perf list' for a list of valid events Usage: perf trace [] [] or: perf trace [] -- [] or: perf trace record [] [] or: perf trace record [] -- [] -e, --event event/syscall selector. use 'perf list' to list available events # But, if we set things up to dump the generated object file to a file, and do this after having run 'make install', still on the developer's $HOME directory: # cat ~/.perfconfig [llvm] dump-obj = true # # perf trace -e ~acme/lib/examples/perf/bpf/empty.c LLVM: dumping /home/acme/lib/examples/perf/bpf/empty.o WARNING: event parser found nothing invalid or unsupported event: '/home/acme/lib/examples/perf/bpf/empty.c' # We can look at the dumped object file: # ls -la ~acme/lib/examples/perf/bpf/empty.o -rw-r--r--. 1 root root 576 May 4 12:10 /home/acme/lib/examples/perf/bpf/empty.o # file ~acme/lib/examples/perf/bpf/empty.o /home/acme/lib/examples/perf/bpf/empty.o: ELF 64-bit LSB relocatable, *unknown arch 0xf7* version 1 (SYSV), not stripped # readelf -sw ~acme/lib/examples/perf/bpf/empty.o Symbol table '.symtab' contains 3 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000000 0 NOTYPE GLOBAL DEFAULT 3 _license 2: 0000000000000000 0 NOTYPE GLOBAL DEFAULT 4 _version # # tools/bpf/bpftool/bpftool --pretty ~acme/lib/examples/perf/bpf/empty.o null # Cc: Adrian Hunter Cc: David Ahern Cc: Jiri Olsa Cc: Namhyung Kim Cc: Wang Nan Link: https://lkml.kernel.org/n/tip-y7dkhakejz3013o0w21n98xd@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Makefile.config | 7 +++++++ tools/perf/Makefile.perf | 3 +++ tools/perf/examples/bpf/empty.c | 2 ++ 3 files changed, 12 insertions(+) create mode 100644 tools/perf/examples/bpf/empty.c diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config index 3bca9a733f0e..b5ac356ba323 100644 --- a/tools/perf/Makefile.config +++ b/tools/perf/Makefile.config @@ -886,6 +886,7 @@ endif # Among the variables below, these: # perfexecdir # perf_include_dir +# perf_examples_dir # template_dir # mandir # infodir @@ -906,6 +907,7 @@ mandir = share/man infodir = share/info perfexecdir = libexec/perf-core perf_include_dir = lib/include/perf +perf_examples_dir = lib/examples/perf sharedir = $(prefix)/share template_dir = share/perf-core/templates STRACE_GROUPS_DIR = share/perf-core/strace/groups @@ -937,6 +939,7 @@ mandir_SQ = $(subst ','\'',$(mandir)) infodir_SQ = $(subst ','\'',$(infodir)) perfexecdir_SQ = $(subst ','\'',$(perfexecdir)) perf_include_dir_SQ = $(subst ','\'',$(perf_include_dir)) +perf_examples_dir_SQ = $(subst ','\'',$(perf_examples_dir)) template_dir_SQ = $(subst ','\'',$(template_dir)) htmldir_SQ = $(subst ','\'',$(htmldir)) tipdir_SQ = $(subst ','\'',$(tipdir)) @@ -948,16 +951,19 @@ srcdir_SQ = $(subst ','\'',$(srcdir)) ifneq ($(filter /%,$(firstword $(perfexecdir))),) perfexec_instdir = $(perfexecdir) perf_include_instdir = $(perf_include_dir) +perf_examples_instdir = $(perf_examples_dir) STRACE_GROUPS_INSTDIR = $(STRACE_GROUPS_DIR) tip_instdir = $(tipdir) else perfexec_instdir = $(prefix)/$(perfexecdir) perf_include_instdir = $(prefix)/$(perf_include_dir) +perf_examples_instdir = $(prefix)/$(perf_examples_dir) STRACE_GROUPS_INSTDIR = $(prefix)/$(STRACE_GROUPS_DIR) tip_instdir = $(prefix)/$(tipdir) endif perfexec_instdir_SQ = $(subst ','\'',$(perfexec_instdir)) perf_include_instdir_SQ = $(subst ','\'',$(perf_include_instdir)) +perf_examples_instdir_SQ = $(subst ','\'',$(perf_examples_instdir)) STRACE_GROUPS_INSTDIR_SQ = $(subst ','\'',$(STRACE_GROUPS_INSTDIR)) tip_instdir_SQ = $(subst ','\'',$(tip_instdir)) @@ -1006,6 +1012,7 @@ $(call detected_var,STRACE_GROUPS_DIR_SQ) $(call detected_var,prefix_SQ) $(call detected_var,perfexecdir_SQ) $(call detected_var,perf_include_dir_SQ) +$(call detected_var,perf_examples_dir_SQ) $(call detected_var,tipdir_SQ) $(call detected_var,srcdir_SQ) $(call detected_var,LIBDIR) diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index d9663b1cf43e..9343b7d945bb 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -770,6 +770,9 @@ endif ifndef NO_LIBBPF $(call QUIET_INSTALL, lib) \ $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf' + $(call QUIET_INSTALL, lib) \ + $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf' + $(INSTALL) examples/bpf/*.c '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf' endif $(call QUIET_INSTALL, perf-archive) \ $(INSTALL) $(OUTPUT)perf-archive -t '$(DESTDIR_SQ)$(perfexec_instdir_SQ)' diff --git a/tools/perf/examples/bpf/empty.c b/tools/perf/examples/bpf/empty.c new file mode 100644 index 000000000000..78754df53ac1 --- /dev/null +++ b/tools/perf/examples/bpf/empty.c @@ -0,0 +1,2 @@ +char _license[] __attribute__((section("license"), used)) = "GPL"; +int _version __attribute__((section("version"), used)) = LINUX_VERSION_CODE; -- 2.14.3