mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Stringer <joe@ovn.org>
To: linux-kernel@vger.kernel.org
Cc: wangnan0@huawei.com, ast@fb.com, daniel@iogearbox.net, acme@kernel.org
Subject: [PATCH perf/core 3/6] tools lib bpf: Define prog_type fns with macro
Date: Wed, 18 Jan 2017 15:57:21 -0800	[thread overview]
Message-ID: <20170118235724.26103-4-joe@ovn.org> (raw)
In-Reply-To: <20170118235724.26103-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>
---
 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 653b1b368deb..aa2a04bfd494 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -1422,37 +1422,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

  parent reply	other threads:[~2017-01-18 23:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-18 23:57 [PATCH perf/core 0/6] Libbpf improvements Joe Stringer
2017-01-18 23:57 ` [PATCH perf/core 1/6] tools lib bpf: Fix map offsets in relocation Joe Stringer
2017-01-19  6:07   ` Wangnan (F)
2017-01-19  9:53   ` [PATCH -improve] " Wang Nan
2017-01-18 23:57 ` [PATCH perf/core 2/6] tools lib bpf: Fix grammar in map_idx warning Joe Stringer
2017-01-19 10:10   ` Wangnan (F)
2017-01-18 23:57 ` Joe Stringer [this message]
2017-01-18 23:57 ` [PATCH perf/core 4/6] tools lib bpf: Add set/is helpers for all prog types Joe Stringer
2017-01-18 23:57 ` [PATCH perf/core 5/6] tools lib bpf: Add libbpf_get_error() Joe Stringer
2017-01-18 23:57 ` [PATCH perf/core 6/6] tools lib bpf: Add bpf_object__pin() Joe Stringer
2017-01-19 10:22   ` Wangnan (F)
2017-01-19 23:56     ` Joe Stringer
2017-01-19 10:24 ` [PATCH perf/core 0/6] Libbpf improvements Wangnan (F)
2017-01-23  1:12   ` 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=20170118235724.26103-4-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=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®