From: He Kuang <hekuang@huawei.com>
To: <acme@kernel.org>, <peterz@infradead.org>, <mingo@redhat.com>,
<jolsa@redhat.com>, <brendan.d.gregg@gmail.com>, <ast@kernel.org>,
<alexander.shishkin@linux.intel.com>, <wangnan0@huawei.com>,
<hekuang@huawei.com>
Cc: <linux-kernel@vger.kernel.org>
Subject: [RFC PATCH v2 12/26] perf bpf: Add libbpf-internal.h header file
Date: Sun, 26 Jun 2016 11:21:04 +0000 [thread overview]
Message-ID: <1466940078-65581-13-git-send-email-hekuang@huawei.com> (raw)
In-Reply-To: <1466940078-65581-1-git-send-email-hekuang@huawei.com>
Split part of codes in libbpf.c out for internal usage, debug print
functions are changed to non-static for other files to use.
Signed-off-by: He Kuang <hekuang@huawei.com>
---
tools/lib/bpf/libbpf-internal.h | 65 +++++++++++++++++++++++++++++++++++++++
tools/lib/bpf/libbpf.c | 68 +++++------------------------------------
2 files changed, 72 insertions(+), 61 deletions(-)
create mode 100644 tools/lib/bpf/libbpf-internal.h
diff --git a/tools/lib/bpf/libbpf-internal.h b/tools/lib/bpf/libbpf-internal.h
new file mode 100644
index 0000000..1c1619c
--- /dev/null
+++ b/tools/lib/bpf/libbpf-internal.h
@@ -0,0 +1,65 @@
+#ifndef _LIBBPF_INTERNAL_H
+#define _LIBBPF_INTERNAL_H
+
+#include "libbpf.h"
+
+#define __printf(a, b) __attribute__((format(printf, a, b)))
+
+#define __pr(func, fmt, ...) \
+do { \
+ if ((func)) \
+ (func)("libbpf: " fmt, ##__VA_ARGS__); \
+} while (0)
+
+extern libbpf_print_fn_t __pr_bpf_warning;
+extern libbpf_print_fn_t __pr_bpf_info;
+extern libbpf_print_fn_t __pr_bpf_debug;
+
+#define pr_warning(fmt, ...) __pr(__pr_bpf_warning, fmt, ##__VA_ARGS__)
+#define pr_info(fmt, ...) __pr(__pr_bpf_info, fmt, ##__VA_ARGS__)
+#define pr_debug(fmt, ...) __pr(__pr_bpf_debug, fmt, ##__VA_ARGS__)
+
+/* Copied from tools/perf/util/util.h */
+#ifndef zfree
+# define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
+#endif
+
+#ifndef zclose
+# define zclose(fd) ({ \
+ int ___err = 0; \
+ if ((fd) >= 0) \
+ ___err = close((fd)); \
+ fd = -1; \
+ ___err; })
+#endif
+
+/*
+ * bpf_prog should be a better name but it has been used in
+ * linux/filter.h.
+ */
+struct bpf_program {
+ /* Index in elf obj file, for relocation use. */
+ int idx;
+ char *section_name;
+ struct bpf_insn *insns;
+ size_t insns_cnt;
+
+ struct {
+ int insn_idx;
+ int map_idx;
+ } *reloc_desc;
+ int nr_reloc;
+
+ struct bpf_engine *engine;
+ struct {
+ int nr;
+ void *entries;
+ } instances;
+ bpf_program_prep_t preprocessor;
+
+ struct bpf_object *obj;
+ void *priv;
+ bpf_program_clear_priv_t clear_priv;
+};
+
+#endif /* _LIBBPF_INTERNAL_H */
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 97f72b2..0ad6c9e 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -23,8 +23,7 @@
#include "libbpf.h"
#include "bpf.h"
-
-#define __printf(a, b) __attribute__((format(printf, a, b)))
+#include "libbpf-internal.h"
__printf(1, 2)
static int __base_pr(const char *format, ...)
@@ -38,27 +37,17 @@ static int __base_pr(const char *format, ...)
return err;
}
-static __printf(1, 2) libbpf_print_fn_t __pr_warning = __base_pr;
-static __printf(1, 2) libbpf_print_fn_t __pr_info = __base_pr;
-static __printf(1, 2) libbpf_print_fn_t __pr_debug;
-
-#define __pr(func, fmt, ...) \
-do { \
- if ((func)) \
- (func)("libbpf: " fmt, ##__VA_ARGS__); \
-} while (0)
-
-#define pr_warning(fmt, ...) __pr(__pr_warning, fmt, ##__VA_ARGS__)
-#define pr_info(fmt, ...) __pr(__pr_info, fmt, ##__VA_ARGS__)
-#define pr_debug(fmt, ...) __pr(__pr_debug, fmt, ##__VA_ARGS__)
+__printf(1, 2) libbpf_print_fn_t __pr_bpf_warning = __base_pr;
+__printf(1, 2) libbpf_print_fn_t __pr_bpf_info = __base_pr;
+__printf(1, 2) libbpf_print_fn_t __pr_bpf_debug;
void libbpf_set_print(libbpf_print_fn_t warn,
libbpf_print_fn_t info,
libbpf_print_fn_t debug)
{
- __pr_warning = warn;
- __pr_info = info;
- __pr_debug = debug;
+ __pr_bpf_warning = warn;
+ __pr_bpf_info = info;
+ __pr_bpf_debug = debug;
}
#define STRERR_BUFSIZE 128
@@ -114,55 +103,12 @@ int libbpf_strerror(int err, char *buf, size_t size)
goto out; \
} while(0)
-
-/* Copied from tools/perf/util/util.h */
-#ifndef zfree
-# define zfree(ptr) ({ free(*ptr); *ptr = NULL; })
-#endif
-
-#ifndef zclose
-# define zclose(fd) ({ \
- int ___err = 0; \
- if ((fd) >= 0) \
- ___err = close((fd)); \
- fd = -1; \
- ___err; })
-#endif
-
#ifdef HAVE_LIBELF_MMAP_SUPPORT
# define LIBBPF_ELF_C_READ_MMAP ELF_C_READ_MMAP
#else
# define LIBBPF_ELF_C_READ_MMAP ELF_C_READ
#endif
-/*
- * bpf_prog should be a better name but it has been used in
- * linux/filter.h.
- */
-struct bpf_program {
- /* Index in elf obj file, for relocation use. */
- int idx;
- char *section_name;
- struct bpf_insn *insns;
- size_t insns_cnt;
-
- struct {
- int insn_idx;
- int map_idx;
- } *reloc_desc;
- int nr_reloc;
-
- struct {
- int nr;
- void *entries;
- } instances;
- bpf_program_prep_t preprocessor;
-
- struct bpf_object *obj;
- void *priv;
- bpf_program_clear_priv_t clear_priv;
-};
-
struct bpf_map {
int fd;
char *name;
--
1.8.5.2
next prev parent reply other threads:[~2016-06-26 11:26 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-26 11:20 [RFC PATCH v2 00/26] perf tools: Support uBPF script He Kuang
2016-06-26 11:20 ` [RFC PATCH v2 01/26] tools include: Adopt byte ordering macros from byteorder/generic.h He Kuang
2016-06-26 11:20 ` [RFC PATCH v2 02/26] tools include: Fix wrong macro definitions for cpu_to_le* for big endian He Kuang
2016-06-26 11:20 ` [RFC PATCH v2 03/26] bpf: split __bpf_prog_run code into new file He Kuang
2016-06-26 11:20 ` [RFC PATCH v2 04/26] bpf: extract jmp and default handler and introduce UBPF_BUILD flag He Kuang
2016-06-26 11:20 ` [RFC PATCH v2 05/26] tools include: Sync math64.h and div64.h He Kuang
2016-06-26 21:08 ` Nilay Vaish
2016-06-27 2:21 ` Hekuang
2016-06-27 18:13 ` Arnaldo Carvalho de Melo
2016-06-26 11:20 ` [RFC PATCH v2 06/26] tools include: Add (atomic|atomic64)_add implementation from the kernel sources He Kuang
2016-06-26 11:20 ` [RFC PATCH v2 07/26] perf bpf: Add map related BPF helper He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 08/26] perf bpf: Add UBPF flags and makefile options He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 09/26] perf bpf: Implement empty instruction handler and build bpf-vm He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 10/26] perf bpf: Remove unused code in libbpf He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 11/26] perf bpf: Store arbitrary entries instread fd array in bpf_program He Kuang
2016-06-26 11:21 ` He Kuang [this message]
2016-06-26 11:21 ` [RFC PATCH v2 13/26] perf bpf: Add abstraction for bpf program methods He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 14/26] perf bpf: Add -Wextra to cflags for more warnings and fix them He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 15/26] perf bpf: Introduce the entity and engine for userspace bpf He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 16/26] perf bpf: Add method for fetching nth ubpf vm He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 17/26] perf bpf: Add methods to set/check ubpf engine for bpf programs He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 18/26] perf bpf: Add ubpf helper function slots and set/get methods He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 19/26] perf tools: Register basic uBPF helpers He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 20/26] perf bpf: Accept uBPF programs He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 21/26] bpf: Support bpf load/store boundary check for ubpf He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 22/26] perf bpf: Implement boundary check code in ubpf He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 23/26] perf record: Add uBPF hooks at beginning and end of perf record He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 24/26] perf bpf: Fillup bpf jmp_call handler He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 25/26] perf bpf: Implement run_ubpf_program He Kuang
2016-06-26 11:21 ` [RFC PATCH v2 26/26] perf tests: Add uBPF test case He Kuang
2016-06-26 20:48 ` [RFC PATCH v2 00/26] perf tools: Support uBPF script Alexei Starovoitov
2016-06-27 2:10 ` Hekuang
2016-06-28 11:47 ` Hekuang
2016-06-28 14:57 ` Alexei Starovoitov
2016-06-29 10:15 ` Hekuang
2016-06-29 10:35 ` Wangnan (F)
2016-06-29 12:37 ` Alexei Starovoitov
2016-06-29 13:03 ` pi3orama
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1466940078-65581-13-git-send-email-hekuang@huawei.com \
--to=hekuang@huawei.com \
--cc=acme@kernel.org \
--cc=alexander.shishkin@linux.intel.com \
--cc=ast@kernel.org \
--cc=brendan.d.gregg@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=wangnan0@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®