From: Joe Stringer <joe@ovn.org>
To: acme@kernel.org
Cc: wangnan0@huawei.com, ast@fb.com, daniel@iogearbox.net,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCHv2 perf/core 2/7] tools lib bpf: Define prog_type fns with macro
Date: Sun, 22 Jan 2017 17:11:23 -0800 [thread overview]
Message-ID: <20170123011128.26534-3-joe@ovn.org> (raw)
In-Reply-To: <20170123011128.26534-1-joe@ovn.org>
Turning this into a macro allows future prog types to be added with a
single line per type.
Signed-off-by: Joe Stringer <joe@ovn.org>
Acked-by: Wang Nan <wangnan0@huawei.com>
---
v2: Add ack.
---
tools/lib/bpf/libbpf.c | 41 ++++++++++++++++-------------------------
1 file changed, 16 insertions(+), 25 deletions(-)
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 671d5ad07cf1..371cb40a2304 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1428,37 +1428,28 @@ static void bpf_program__set_type(struct bpf_program *prog,
prog->type = type;
}
-int bpf_program__set_tracepoint(struct bpf_program *prog)
-{
- if (!prog)
- return -EINVAL;
- bpf_program__set_type(prog, BPF_PROG_TYPE_TRACEPOINT);
- return 0;
-}
-
-int bpf_program__set_kprobe(struct bpf_program *prog)
-{
- if (!prog)
- return -EINVAL;
- bpf_program__set_type(prog, BPF_PROG_TYPE_KPROBE);
- return 0;
-}
-
static bool bpf_program__is_type(struct bpf_program *prog,
enum bpf_prog_type type)
{
return prog ? (prog->type == type) : false;
}
-bool bpf_program__is_tracepoint(struct bpf_program *prog)
-{
- return bpf_program__is_type(prog, BPF_PROG_TYPE_TRACEPOINT);
-}
-
-bool bpf_program__is_kprobe(struct bpf_program *prog)
-{
- return bpf_program__is_type(prog, BPF_PROG_TYPE_KPROBE);
-}
+#define BPF_PROG_TYPE_FNS(NAME, TYPE) \
+int bpf_program__set_##NAME(struct bpf_program *prog) \
+{ \
+ if (!prog) \
+ return -EINVAL; \
+ bpf_program__set_type(prog, TYPE); \
+ return 0; \
+} \
+ \
+bool bpf_program__is_##NAME(struct bpf_program *prog) \
+{ \
+ return bpf_program__is_type(prog, TYPE); \
+} \
+
+BPF_PROG_TYPE_FNS(kprobe, BPF_PROG_TYPE_KPROBE);
+BPF_PROG_TYPE_FNS(tracepoint, BPF_PROG_TYPE_TRACEPOINT);
int bpf_map__fd(struct bpf_map *map)
{
--
2.11.0
next prev parent reply other threads:[~2017-01-23 1:11 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-23 1:11 [PATCHv2 perf/core 0/7] Libbpf improvements Joe Stringer
2017-01-23 1:11 ` [PATCHv2 perf/core 1/7] tools lib bpf: Fix map offsets in relocation Joe Stringer
2017-01-23 1:11 ` Joe Stringer [this message]
2017-01-23 1:11 ` [PATCHv2 perf/core 3/7] tools lib bpf: Add set/is helpers for all prog types Joe Stringer
2017-01-23 1:11 ` [PATCHv2 perf/core 4/7] tools lib bpf: Add libbpf_get_error() Joe Stringer
2017-01-23 1:11 ` [PATCHv2 perf/core 5/7] tools lib bpf: Add bpf_program__pin() Joe Stringer
2017-01-25 1:04 ` Wangnan (F)
2017-01-25 1:06 ` Wangnan (F)
2017-01-25 1:16 ` Joe Stringer
2017-01-25 2:18 ` Wangnan (F)
2017-01-26 19:32 ` Arnaldo Carvalho de Melo
2017-01-26 19:43 ` Joe Stringer
2017-01-23 1:11 ` [PATCHv2 perf/core 6/7] tools lib bpf: Add bpf_map__pin() Joe Stringer
2017-01-23 1:11 ` [PATCHv2 perf/core 7/7] tools lib bpf: Add bpf_object__pin() Joe Stringer
2017-01-24 16:12 ` [PATCHv2 perf/core 0/7] Libbpf improvements Arnaldo Carvalho de Melo
2017-01-25 0:50 ` Joe Stringer
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=20170123011128.26534-3-joe@ovn.org \
--to=joe@ovn.org \
--cc=acme@kernel.org \
--cc=ast@fb.com \
--cc=daniel@iogearbox.net \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).