From: Yonghong Song <yhs@fb.com>
To: Arnaldo Carvalho de Melo <acme@redhat.com>,
Magnus Karlsson <magnus.karlsson@intel.com>,
<netdev@vger.kernel.org>
Cc: Alexei Starovoitov <ast@fb.com>,
Daniel Borkmann <daniel@iogearbox.net>, <kernel-team@fb.com>,
Yonghong Song <yhs@fb.com>
Subject: [PATCH bpf-next v2 2/3] tools/bpf: print out btf log at LIBBPF_WARN level
Date: Fri, 1 Feb 2019 09:47:32 -0800 [thread overview]
Message-ID: <20190201174732.695592-1-yhs@fb.com> (raw)
In-Reply-To: <20190201174731.695459-1-yhs@fb.com>
Currently, the btf log is allocated and printed out in case
of error at LIBBPF_DEBUG level.
Such logs from kernel are very important for debugging.
For example, bpf syscall BPF_PROG_LOAD command can get
verifier logs back to user space. In function load_program()
of libbpf.c, the log buffer is allocated unconditionally
and printed out at pr_warning() level.
Let us do the similar thing here for btf. Allocate buffer
unconditionally and print out error logs at pr_warning() level.
This is to reduce one global function and
optimize for common situations where pr_warning()
is activated either by default or by user supplied
debug output function.
Signed-off-by: Yonghong Song <yhs@fb.com>
---
tools/lib/bpf/btf.c | 19 +++++++++----------
tools/lib/bpf/libbpf.c | 10 ----------
tools/lib/bpf/util.h | 2 --
3 files changed, 9 insertions(+), 22 deletions(-)
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 159104ec31dc..46271bc19572 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -377,16 +377,15 @@ struct btf *btf__new(__u8 *data, __u32 size)
btf->fd = -1;
- if (libbpf_dprint_level_available(LIBBPF_DEBUG)) {
- log_buf = malloc(BPF_LOG_BUF_SIZE);
- if (!log_buf) {
- err = -ENOMEM;
- goto done;
- }
- *log_buf = 0;
- log_buf_size = BPF_LOG_BUF_SIZE;
+ log_buf = malloc(BPF_LOG_BUF_SIZE);
+ if (!log_buf) {
+ err = -ENOMEM;
+ goto done;
}
+ *log_buf = 0;
+ log_buf_size = BPF_LOG_BUF_SIZE;
+
btf->data = malloc(size);
if (!btf->data) {
err = -ENOMEM;
@@ -401,9 +400,9 @@ struct btf *btf__new(__u8 *data, __u32 size)
if (btf->fd == -1) {
err = -errno;
- pr_debug("Error loading BTF: %s(%d)\n", strerror(errno), errno);
+ pr_warning("Error loading BTF: %s(%d)\n", strerror(errno), errno);
if (log_buf && *log_buf)
- pr_debug("%s\n", log_buf);
+ pr_warning("%s\n", log_buf);
goto done;
}
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 1ede6b93653e..1b1c0b504d25 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -98,16 +98,6 @@ void libbpf_debug_print(enum libbpf_print_level level, const char *format, ...)
va_end(args);
}
-bool libbpf_dprint_level_available(enum libbpf_print_level level)
-{
- if (level == LIBBPF_WARN)
- return !!__pr_warning;
- else if (level == LIBBPF_INFO)
- return !!__pr_info;
- else
- return !!__pr_debug;
-}
-
#define STRERR_BUFSIZE 128
#define CHECK_ERR(action, err, out) do { \
diff --git a/tools/lib/bpf/util.h b/tools/lib/bpf/util.h
index 3ae80f486875..66d65b803095 100644
--- a/tools/lib/bpf/util.h
+++ b/tools/lib/bpf/util.h
@@ -14,8 +14,6 @@ extern void libbpf_debug_print(enum libbpf_print_level level,
const char *format, ...)
__attribute__((format(printf, 2, 3)));
-extern bool libbpf_dprint_level_available(enum libbpf_print_level level);
-
#define __pr(level, fmt, ...) \
do { \
libbpf_debug_print(level, "libbpf: " fmt, ##__VA_ARGS__); \
--
2.17.1
next prev parent reply other threads:[~2019-02-01 17:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-01 17:47 [PATCH bpf-next v2 0/3] tools/bpf: changes of libbpf debug interfaces Yonghong Song
2019-02-01 17:47 ` [PATCH bpf-next v2 1/3] tools/bpf: move libbpf pr_* debug print functions to headers Yonghong Song
2019-02-01 23:10 ` Arnaldo Carvalho de Melo
2019-02-01 23:20 ` Yonghong Song
2019-02-01 23:29 ` Arnaldo Carvalho de Melo
2019-02-01 17:47 ` Yonghong Song [this message]
2019-02-01 17:47 ` [PATCH bpf-next v2 3/3] tools/bpf: simplify libbpf API function libbpf_set_print() Yonghong Song
2019-02-01 19:02 ` Andrii Nakryiko
2019-02-01 20:37 ` Yonghong Song
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=20190201174732.695592-1-yhs@fb.com \
--to=yhs@fb.com \
--cc=acme@redhat.com \
--cc=ast@fb.com \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=magnus.karlsson@intel.com \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).