Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752610AbcDTSCr (ORCPT ); Wed, 20 Apr 2016 14:02:47 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:22022 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752378AbcDTSCj (ORCPT ); Wed, 20 Apr 2016 14:02:39 -0400 From: Wang Nan To: , , CC: , , Wang Nan , Arnaldo Carvalho de Melo , "Alexei Starovoitov" , Jiri Olsa , Li Zefan Subject: [RFC PATCH 10/13] perf tools: Register basic UBPF helpers Date: Wed, 20 Apr 2016 18:01:50 +0000 Message-ID: <1461175313-38310-11-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1461175313-38310-1-git-send-email-wangnan0@huawei.com> References: <1461175313-38310-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020201.5717C42B.00B9,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: dfb60307f11b0ca40962a296beed283a Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4701 Lines: 166 Reigster basic extern functions for ubpf programs. Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Brendan Gregg Cc: Jiri Olsa Cc: Li Zefan --- 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 #include "util/bpf-loader.h" +#include "util/ubpf-helpers.h" #include "util/debug.h" #include #include @@ -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 + * Copyright (C) 2016, Huawei Inc. + */ + +#include +#include +#include +#include + +#include +#include +#include + +#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 + * 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