Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752521AbbD3LCh (ORCPT ); Thu, 30 Apr 2015 07:02:37 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:65194 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751211AbbD3Kxb (ORCPT ); Thu, 30 Apr 2015 06:53:31 -0400 From: Wang Nan To: , , , , , , CC: , , , Subject: [RFC PATCH 03/22] perf: add bpf common operations. Date: Thu, 30 Apr 2015 10:52:26 +0000 Message-ID: <1430391165-30267-4-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 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3196 Lines: 129 Add bpf syscall and related structure to perf for bpf loader use. Signed-off-by: Wang Nan --- tools/perf/perf-sys.h | 6 ++++++ tools/perf/util/Build | 1 + tools/perf/util/bpf.c | 39 +++++++++++++++++++++++++++++++++++++++ tools/perf/util/bpf.h | 22 ++++++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 tools/perf/util/bpf.c create mode 100644 tools/perf/util/bpf.h diff --git a/tools/perf/perf-sys.h b/tools/perf/perf-sys.h index 6ef6816..b38ca8b 100644 --- a/tools/perf/perf-sys.h +++ b/tools/perf/perf-sys.h @@ -22,6 +22,9 @@ #ifndef __NR_gettid # define __NR_gettid 224 #endif +#ifndef __NR_bpf +# define __NR_bpf 357 +#endif #endif #if defined(__x86_64__) @@ -39,6 +42,9 @@ #ifndef __NR_gettid # define __NR_gettid 186 #endif +#ifndef __NR_bpf +# define __NR_bpf 321 +#endif #endif #ifdef __powerpc__ diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 797490a..dfba2f0 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -74,6 +74,7 @@ libperf-y += data.o libperf-$(CONFIG_X86) += tsc.o libperf-y += cloexec.o libperf-y += thread-stack.o +libperf-y += bpf.o libperf-$(CONFIG_LIBELF) += symbol-elf.o libperf-$(CONFIG_LIBELF) += probe-event.o diff --git a/tools/perf/util/bpf.c b/tools/perf/util/bpf.c new file mode 100644 index 0000000..f752723 --- /dev/null +++ b/tools/perf/util/bpf.c @@ -0,0 +1,39 @@ +/* + * common BPF operations. + * + * 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 +#include +#include +#include +#include "perf.h" +#include "bpf.h" + +int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr, size_t size) +{ + return syscall(__NR_bpf, cmd, attr, size); +} + +int bpf_create_map(struct bpf_map_def *map_def) +{ + union bpf_attr attr; + + if (!map_def) + return -EFAULT; + + bzero(&attr, sizeof(attr)); + + attr.map_type = map_def->type; + attr.key_size = map_def->key_size; + attr.value_size = map_def->value_size; + attr.max_entries = map_def->max_entries; + + return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); +} diff --git a/tools/perf/util/bpf.h b/tools/perf/util/bpf.h new file mode 100644 index 0000000..be106b0 --- /dev/null +++ b/tools/perf/util/bpf.h @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2015, Wang Nan + * Copyright (C) 2015, Huawei Inc. + * + * Released under the GPL v2. (and only v2, not any later version) + */ +#ifndef __PERF_BPF_H +#define __PERF_BPF_H + +#include + +struct bpf_map_def { + unsigned int type; + unsigned int key_size; + unsigned int value_size; + unsigned int max_entries; +}; + +int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr, size_t size); + +int bpf_create_map(struct bpf_map_def *map_def); +#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/