Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752493AbbD3LBA (ORCPT ); Thu, 30 Apr 2015 07:01:00 -0400 Received: from szxga03-in.huawei.com ([119.145.14.66]:14282 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751444AbbD3Kxe (ORCPT ); Thu, 30 Apr 2015 06:53:34 -0400 From: Wang Nan To: , , , , , , CC: , , , Subject: [RFC PATCH 04/22] perf tools: Add new 'perf bpf' command. Date: Thu, 30 Apr 2015 10:52:27 +0000 Message-ID: <1430391165-30267-5-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1430391165-30267-1-git-send-email-wangnan0@huawei.com> References: <1430391165-30267-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.197.210] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.554209A9.010F,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 844f6b5957316f882bd56c6e80d62e54 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5970 Lines: 236 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 + * + * Buildin bpf command: Load bpf and attach bpf programs onto kprobes. + */ +#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]); +} + +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; +} + diff --git a/tools/perf/builtin.h b/tools/perf/builtin.h index 3688ad2..c2c4a0d 100644 --- a/tools/perf/builtin.h +++ b/tools/perf/builtin.h @@ -38,6 +38,7 @@ extern int cmd_trace(int argc, const char **argv, const char *prefix); extern int cmd_inject(int argc, const char **argv, const char *prefix); extern int cmd_mem(int argc, const char **argv, const char *prefix); extern int cmd_data(int argc, const char **argv, const char *prefix); +extern int cmd_bpf(int argc, const char **argv, const char *prefix); extern int find_scripts(char **scripts_array, char **scripts_path_array); #endif diff --git a/tools/perf/perf.c b/tools/perf/perf.c index b857fcb..779f2fb 100644 --- a/tools/perf/perf.c +++ b/tools/perf/perf.c @@ -64,6 +64,7 @@ static struct cmd_struct commands[] = { { "inject", cmd_inject, 0 }, { "mem", cmd_mem, 0 }, { "data", cmd_data, 0 }, + { "bpf", cmd_bpf, 0 }, }; struct pager_config { diff --git a/tools/perf/util/Build b/tools/perf/util/Build index dfba2f0..39287a5 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -75,6 +75,7 @@ libperf-$(CONFIG_X86) += tsc.o libperf-y += cloexec.o libperf-y += thread-stack.o libperf-y += bpf.o +libperf-y += bpf-loader.o libperf-$(CONFIG_LIBELF) += symbol-elf.o libperf-$(CONFIG_LIBELF) += probe-event.o diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c new file mode 100644 index 0000000..84d3cc3 --- /dev/null +++ b/tools/perf/util/bpf-loader.c @@ -0,0 +1,35 @@ +/* + * BPF loader support. + * + * Copyright (C) 2015, Wang Nan + * Copyright (C) 2015, Huawei Inc. + * + * Released under the GPL v2. (and only v2, not any later version) + */ +#include +#include + +#include "perf.h" +#include "debug.h" +#include "symbol.h" +#include "bpf-loader.h" +#include "probe-event.h" +#include "probe-finder.h" // for MAX_PROBES + +#include +#include +#include + +int bpf__load(const char *path) +{ + pr_debug("bpf: loading %s\n", path); + return 0; +} + +int bpf__run(void) +{ + pr_info("BPF is running. Use Ctrl-c to stop.\n"); + while(1) + sleep(1); + return 0; +} diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h new file mode 100644 index 0000000..122b178 --- /dev/null +++ b/tools/perf/util/bpf-loader.h @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2015, Wang Nan + * Copyright (C) 2015, Huawei Inc. + * + * Released under the GPL v2. (and only v2, not any later version) + */ +#ifndef __BPF_LOADER_H +#define __BPF_LOADER_H + +#include +#include +#include + +#include "perf.h" +#include "symbol.h" +#include "probe-event.h" + +int bpf__load(const char *path); +int bpf__run(void); + +#endif -- 1.8.3.4 -- 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/