Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754375AbbHHIOn (ORCPT ); Sat, 8 Aug 2015 04:14:43 -0400 Received: from terminus.zytor.com ([198.137.202.10]:53786 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754340AbbHHIOf (ORCPT ); Sat, 8 Aug 2015 04:14:35 -0400 Date: Sat, 8 Aug 2015 01:13:39 -0700 From: tip-bot for Wang Nan Message-ID: Cc: linux-kernel@vger.kernel.org, ast@plumgrid.com, xiakaixu@huawei.com, wangnan0@huawei.com, tglx@linutronix.de, dsahern@gmail.com, jolsa@kernel.org, hpa@zytor.com, lizefan@huawei.com, brendan.d.gregg@gmail.com, masami.hiramatsu.pt@hitachi.com, a.p.zijlstra@chello.nl, daniel@iogearbox.net, acme@redhat.com, namhyung@kernel.org, mingo@kernel.org, hekuang@huawei.com Reply-To: mingo@kernel.org, hekuang@huawei.com, namhyung@kernel.org, daniel@iogearbox.net, acme@redhat.com, a.p.zijlstra@chello.nl, masami.hiramatsu.pt@hitachi.com, lizefan@huawei.com, brendan.d.gregg@gmail.com, hpa@zytor.com, jolsa@kernel.org, dsahern@gmail.com, tglx@linutronix.de, ast@plumgrid.com, wangnan0@huawei.com, xiakaixu@huawei.com, linux-kernel@vger.kernel.org In-Reply-To: <1435716878-189507-16-git-send-email-wangnan0@huawei.com> References: <1435716878-189507-16-git-send-email-wangnan0@huawei.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] bpf tools: Add bpf.c/h for common bpf operations Git-Commit-ID: e3ed2fef22b694cf07b06abaa6481a9e6f868e1f X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3993 Lines: 132 Commit-ID: e3ed2fef22b694cf07b06abaa6481a9e6f868e1f Gitweb: http://git.kernel.org/tip/e3ed2fef22b694cf07b06abaa6481a9e6f868e1f Author: Wang Nan AuthorDate: Wed, 1 Jul 2015 02:14:03 +0000 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 7 Aug 2015 10:16:58 -0300 bpf tools: Add bpf.c/h for common bpf operations This patch introduces bpf.c and bpf.h, which hold common functions issuing bpf syscall. The goal of these two files is to hide syscall completely from user. Note that bpf.c and bpf.h deal with kernel interface only. Things like structure of 'map' section in the ELF object is not cared by of bpf.[ch]. We first introduce bpf_create_map(). Note that, since functions in bpf.[ch] are wrapper of sys_bpf, they don't use OO style naming. Signed-off-by: Wang Nan Acked-by: Alexei Starovoitov Cc: Brendan Gregg Cc: Daniel Borkmann Cc: David Ahern Cc: He Kuang Cc: Jiri Olsa Cc: Kaixu Xia Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/r/1435716878-189507-16-git-send-email-wangnan0@huawei.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/lib/bpf/Build | 2 +- tools/lib/bpf/bpf.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ tools/lib/bpf/bpf.h | 16 ++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/tools/lib/bpf/Build b/tools/lib/bpf/Build index a316484..d874975 100644 --- a/tools/lib/bpf/Build +++ b/tools/lib/bpf/Build @@ -1 +1 @@ -libbpf-y := libbpf.o +libbpf-y := libbpf.o bpf.o diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c new file mode 100644 index 0000000..208de7c3 --- /dev/null +++ b/tools/lib/bpf/bpf.c @@ -0,0 +1,51 @@ +/* + * common eBPF ELF operations. + * + * Copyright (C) 2013-2015 Alexei Starovoitov + * Copyright (C) 2015 Wang Nan + * Copyright (C) 2015 Huawei Inc. + */ + +#include +#include +#include +#include +#include +#include "bpf.h" + +/* + * When building perf, unistd.h is override. Define __NR_bpf is + * required to be defined. + */ +#ifndef __NR_bpf +# if defined(__i386__) +# define __NR_bpf 357 +# elif defined(__x86_64__) +# define __NR_bpf 321 +# elif defined(__aarch64__) +# define __NR_bpf 280 +# else +# error __NR_bpf not defined. libbpf does not support your arch. +# endif +#endif + +static int sys_bpf(enum bpf_cmd cmd, union bpf_attr *attr, + unsigned int size) +{ + return syscall(__NR_bpf, cmd, attr, size); +} + +int bpf_create_map(enum bpf_map_type map_type, int key_size, + int value_size, int max_entries) +{ + union bpf_attr attr; + + memset(&attr, '\0', sizeof(attr)); + + attr.map_type = map_type; + attr.key_size = key_size; + attr.value_size = value_size; + attr.max_entries = max_entries; + + return sys_bpf(BPF_MAP_CREATE, &attr, sizeof(attr)); +} diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h new file mode 100644 index 0000000..28f7942 --- /dev/null +++ b/tools/lib/bpf/bpf.h @@ -0,0 +1,16 @@ +/* + * common eBPF ELF operations. + * + * Copyright (C) 2013-2015 Alexei Starovoitov + * Copyright (C) 2015 Wang Nan + * Copyright (C) 2015 Huawei Inc. + */ +#ifndef __BPF_BPF_H +#define __BPF_BPF_H + +#include + +int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size, + int max_entries); + +#endif -- 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/