All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wang Nan <wangnan0@huawei.com>
To: <acme@kernel.org>, <jolsa@redhat.com>, <brendan.d.gregg@gmail.com>
Cc: <linux-kernel@vger.kernel.org>, <pi3orama@163.com>,
	Wang Nan <wangnan0@huawei.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	"Alexei Starovoitov" <ast@kernel.org>,
	Jiri Olsa <jolsa@kernel.org>, Li Zefan <lizefan@huawei.com>
Subject: [RFC PATCH 10/13] perf tools: Register basic UBPF helpers
Date: Wed, 20 Apr 2016 18:01:50 +0000	[thread overview]
Message-ID: <1461175313-38310-11-git-send-email-wangnan0@huawei.com> (raw)
In-Reply-To: <1461175313-38310-1-git-send-email-wangnan0@huawei.com>

Reigster basic extern functions for ubpf programs.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Li Zefan <lizefan@huawei.com>
---
 tools/perf/perf.c                   |  3 ++
 tools/perf/util/Build               |  1 +
 tools/perf/util/ubpf-helpers-list.h |  7 ++++
 tools/perf/util/ubpf-helpers.c      | 66 +++++++++++++++++++++++++++++++++++++
 tools/perf/util/ubpf-helpers.h      | 21 ++++++++++++
 5 files changed, 98 insertions(+)
 create mode 100644 tools/perf/util/ubpf-helpers-list.h
 create mode 100644 tools/perf/util/ubpf-helpers.c
 create mode 100644 tools/perf/util/ubpf-helpers.h

diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 7b2df2b..f246364 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -16,6 +16,7 @@
 #include "util/parse-events.h"
 #include <subcmd/parse-options.h>
 #include "util/bpf-loader.h"
+#include "util/ubpf-helpers.h"
 #include "util/debug.h"
 #include <api/fs/tracing_path.h>
 #include <pthread.h>
@@ -618,6 +619,8 @@ int main(int argc, const char **argv)
 
 	perf_debug_setup();
 
+	register_ubpf_helpers();
+
 	while (1) {
 		static int done_help;
 		int was_alias = run_argv(&argc, &argv);
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 90229a8..e193e6b 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -87,6 +87,7 @@ libperf-y += mem-events.o
 
 libperf-$(CONFIG_LIBBPF) += bpf-loader.o
 libperf-$(CONFIG_BPF_PROLOGUE) += bpf-prologue.o
+libperf-$(CONFIG_UBPF) += ubpf-helpers.o
 libperf-$(CONFIG_LIBELF) += symbol-elf.o
 libperf-$(CONFIG_LIBELF) += probe-file.o
 libperf-$(CONFIG_LIBELF) += probe-event.o
diff --git a/tools/perf/util/ubpf-helpers-list.h b/tools/perf/util/ubpf-helpers-list.h
new file mode 100644
index 0000000..b457963
--- /dev/null
+++ b/tools/perf/util/ubpf-helpers-list.h
@@ -0,0 +1,7 @@
+DEF_UBPF_HELPER(int, ubpf_memcmp, (void *s1, void *s2, unsigned int n))
+DEF_UBPF_HELPER(void, ubpf_memcpy, (void *d, void *s, unsigned int size))
+DEF_UBPF_HELPER(int, ubpf_strcmp, (char *s1, char *s2))
+DEF_UBPF_HELPER(int, ubpf_printf, (char *fmt, ...))
+DEF_UBPF_HELPER(int, ubpf_map_lookup_elem, (void *map_desc, void *key, void *value))
+DEF_UBPF_HELPER(int, ubpf_map_update_elem, (void *map_desc, void *key, void *value, unsigned long long flags))
+DEF_UBPF_HELPER(int, ubpf_map_get_next_key, (void *map_desc, void *key, void *next_key))
diff --git a/tools/perf/util/ubpf-helpers.c b/tools/perf/util/ubpf-helpers.c
new file mode 100644
index 0000000..b05f495
--- /dev/null
+++ b/tools/perf/util/ubpf-helpers.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2016, Wang Nan <wangnan0@huawei.com>
+ * Copyright (C) 2016, Huawei Inc.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+
+#include <bpf/libbpf.h>
+#include <bpf/bpf.h>
+#include <ubpf.h>
+
+#include "ubpf-helpers.h"
+
+static int ubpf_memcmp(void *s1, void *s2, unsigned int n)
+{
+	return memcmp(s1, s2, n);
+}
+
+static void ubpf_memcpy(void *d, void *s, unsigned int n)
+{
+	memcpy(d, s, n);
+}
+
+static int ubpf_strcmp(char *s1, char *s2)
+{
+	return strcmp(s1, s2);
+}
+
+static int ubpf_printf(char *fmt, ...)
+{
+	int ret;
+	va_list ap;
+
+	va_start(ap, fmt);
+	ret = vprintf(fmt, ap);
+	va_end(ap);
+
+	return ret;
+}
+
+static int ubpf_map_lookup_elem(int map_fd, void *key, void *value)
+{
+	return bpf_map_lookup_elem(map_fd, key, value);
+}
+
+static int ubpf_map_update_elem(int map_fd, void *key, void *value,
+				unsigned long long flags)
+{
+	return bpf_map_update_elem(map_fd, key, value, (u64)flags);
+}
+
+static int ubpf_map_get_next_key(int map_fd, void *key, void *next_key)
+{
+	return bpf_map_get_next_key(map_fd, key, next_key);
+}
+
+void register_ubpf_helpers(void)
+{
+#define DEF_UBPF_HELPER(type, name, param) \
+	libbpf_register_ubpf_func(UBPF_FUNC_##name, #name, name);
+#include "ubpf-helpers-list.h"
+#undef DEF_UBPF_HELPER
+}
diff --git a/tools/perf/util/ubpf-helpers.h b/tools/perf/util/ubpf-helpers.h
new file mode 100644
index 0000000..b4e778b
--- /dev/null
+++ b/tools/perf/util/ubpf-helpers.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2016, Wang Nan <wangnan0@huawei.com>
+ * Copyright (C) 2016, Huawei Inc.
+ */
+#ifndef __UBPF_HELPERS_H
+#define __UBPF_HELPERS_H
+
+#define DEF_UBPF_HELPER(type, name, param) UBPF_FUNC_##name,
+enum {
+	UBPF_FUNC_unspec = 0,
+#include "ubpf-helpers-list.h"
+	UBPF_FUNC_MAX
+};
+#undef DEF_UBPF_HELPER
+
+#ifdef HAVE_UBPF_SUPPORT
+void register_ubpf_helpers(void);
+#else
+inline static void register_ubpf_helpers(void) {};
+#endif
+#endif
-- 
1.8.3.4

  parent reply	other threads:[~2016-04-20 18:02 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-20 18:01 [RFC PATCH 00/13] perf tools: Support uBPF script Wang Nan
2016-04-20 18:01 ` [RFC PATCH 01/13] bpf tools: Add map related BPF helper Wang Nan
2016-04-20 18:01 ` [RFC PATCH 02/13] tools: Add ubpf feature test Wang Nan
2016-04-20 19:11   ` Arnaldo Carvalho de Melo
2016-04-20 18:01 ` [RFC PATCH 03/13] bpf tools: Add ubpf include and makefile options Wang Nan
2016-04-20 18:01 ` [RFC PATCH 04/13] bpf tools: Replace fd array to union array Wang Nan
2016-04-20 19:20   ` Arnaldo Carvalho de Melo
2016-04-20 18:01 ` [RFC PATCH 05/13] bpf tools: Save engine type in bpf_program Wang Nan
2016-04-20 19:23   ` Arnaldo Carvalho de Melo
2016-04-20 19:29     ` pi3orama
2016-04-20 18:01 ` [RFC PATCH 06/13] bpf tools: Introduce ubpf_vm to program instance union Wang Nan
2016-04-20 19:30   ` Arnaldo Carvalho de Melo
2016-04-20 18:01 ` [RFC PATCH 07/13] bpf tools: Load ubpf program Wang Nan
2016-04-20 19:34   ` Arnaldo Carvalho de Melo
2016-04-20 18:01 ` [RFC PATCH 08/13] bpf tools: Add API for fetching ubpf_vm Wang Nan
2016-04-20 18:01 ` [RFC PATCH 09/13] bpf tools: Register extern functions for ubpf programs Wang Nan
2016-04-20 18:01 ` Wang Nan [this message]
2016-04-20 18:01 ` [RFC PATCH 11/13] perf bpf: Accept " Wang Nan
2016-04-20 18:01 ` [RFC PATCH 12/13] perf record: Add UBPF hooks at beginning and end of perf record Wang Nan
2016-04-20 18:01 ` [RFC PATCH 13/13] perf tests: Add UBPF test case Wang Nan
2016-04-20 22:06 ` [RFC PATCH 00/13] perf tools: Support uBPF script Alexei Starovoitov
2016-04-21  8:17   ` Wangnan (F)

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=1461175313-38310-11-git-send-email-wangnan0@huawei.com \
    --to=wangnan0@huawei.com \
    --cc=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=ast@kernel.org \
    --cc=brendan.d.gregg@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=pi3orama@163.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.