Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752414AbbEKGiQ (ORCPT ); Mon, 11 May 2015 02:38:16 -0400 Received: from lgeamrelo02.lge.com ([156.147.1.126]:55368 "EHLO lgeamrelo02.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751065AbbEKGiO (ORCPT ); Mon, 11 May 2015 02:38:14 -0400 X-Original-SENDERIP: 10.177.220.203 X-Original-MAILFROM: namhyung@kernel.org Date: Mon, 11 May 2015 15:28:12 +0900 From: Namhyung Kim To: Wang Nan Cc: ast@plumgrid.com, davem@davemloft.net, acme@kernel.org, mingo@redhat.com, a.p.zijlstra@chello.nl, masami.hiramatsu.pt@hitachi.com, jolsa@kernel.org, lizefan@kernel.org, linux-kernel@vger.kernel.org, pi3orama@163.com, hekuang@huawei.com Subject: Re: [RFC PATCH 04/22] perf tools: Add new 'perf bpf' command. Message-ID: <20150511062812.GB1630@sejong> References: <1430391165-30267-1-git-send-email-wangnan0@huawei.com> <1430391165-30267-5-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <1430391165-30267-5-git-send-email-wangnan0@huawei.com> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3581 Lines: 145 Hi, On Thu, Apr 30, 2015 at 10:52:27AM +0000, Wang Nan wrote: > Adding new 'perf bpf' command to provide eBPF program loading and > management support. > > Signed-off-by: Wang Nan > --- > tools/perf/Build | 1 + > tools/perf/Documentation/perf-bpf.txt | 18 ++++++++++ > tools/perf/builtin-bpf.c | 63 +++++++++++++++++++++++++++++++++++ > tools/perf/builtin.h | 1 + > tools/perf/perf.c | 1 + > tools/perf/util/Build | 1 + > tools/perf/util/bpf-loader.c | 35 +++++++++++++++++++ > tools/perf/util/bpf-loader.h | 21 ++++++++++++ > 8 files changed, 141 insertions(+) > create mode 100644 tools/perf/Documentation/perf-bpf.txt > create mode 100644 tools/perf/builtin-bpf.c > create mode 100644 tools/perf/util/bpf-loader.c > create mode 100644 tools/perf/util/bpf-loader.h > > diff --git a/tools/perf/Build b/tools/perf/Build > index b77370e..c69f0c1 100644 > --- a/tools/perf/Build > +++ b/tools/perf/Build > @@ -19,6 +19,7 @@ perf-y += builtin-kvm.o > perf-y += builtin-inject.o > perf-y += builtin-mem.o > perf-y += builtin-data.o > +perf-y += builtin-bpf.o > > perf-$(CONFIG_AUDIT) += builtin-trace.o > perf-$(CONFIG_LIBELF) += builtin-probe.o > diff --git a/tools/perf/Documentation/perf-bpf.txt b/tools/perf/Documentation/perf-bpf.txt > new file mode 100644 > index 0000000..634d588 > --- /dev/null > +++ b/tools/perf/Documentation/perf-bpf.txt > @@ -0,0 +1,18 @@ > +perf-bpf(1) > +============== > + > +NAME > +---- > +perf-bpf - loads eBPF programs into kernel. > + > +SYNOPSIS > +-------- > +[verse] > +'perf bpf' [] ", > + > +DESCRIPTION > +----------- > +Loading eBPF programs into kernel. > + > +OPTIONS > +------- > diff --git a/tools/perf/builtin-bpf.c b/tools/perf/builtin-bpf.c > new file mode 100644 > index 0000000..0fc7a82 > --- /dev/null > +++ b/tools/perf/builtin-bpf.c > @@ -0,0 +1,63 @@ > +/* > + * buildin-bpf.c s/buildin/builtn/ > + * > + * Buildin bpf command: Load bpf and attach bpf programs onto kprobes. ditto. > + */ > +#include "builtin.h" > +#include "perf.h" > +#include "debug.h" > +#include "parse-options.h" > +#include "bpf-loader.h" > + > +static const char *bpf_usage[] = { > + "perf bpf [] ", > + NULL > +}; > + > +static void print_usage(void) > +{ > + printf("Usage:\n"); > + printf("\t%s\n\n", bpf_usage[0]); > +} Why not using usage_with_options() for this? Thanks, Namhyung > + > +struct option __bpf_options[] = { > + OPT_INCR('v', "verbose", &verbose, "be more verbose"), > + OPT_END() > +}; > + > +struct option *bpf_options = __bpf_options; > + > +int cmd_bpf(int argc, const char **argv, > + const char *prefix __maybe_unused) > +{ > + int err; > + const char **pfn; > + > + if (argc < 2) > + goto usage; > + > + argc = parse_options(argc, argv, bpf_options, bpf_usage, > + PARSE_OPT_STOP_AT_NON_OPTION); > + if (argc < 1) > + goto usage; > + > + pfn = argv; > + while (*pfn != NULL) { > + const char *fn = *pfn++; > + > + err = bpf__load(fn); > + if (err) { > + pr_err("bpf: load bpf program from %s: result: %d\n", > + fn, err); > + break; > + } > + } > + > + if (!err) > + bpf__run(); > + return err; > +usage: > + print_usage(); > + return -1; > +} > + -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/