From patchwork Wed Oct 14 12:41:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 54940 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by patches.linaro.org (Postfix) with ESMTPS id 317CA23012 for ; Wed, 14 Oct 2015 12:49:10 +0000 (UTC) Received: by wijq8 with SMTP id q8sf26108857wij.1 for ; Wed, 14 Oct 2015 05:49:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe; bh=lhpkOEczNpH/Cy5N9mpBQT2e2V2dTTlvCZ6wDwDSkOY=; b=G6ThtctsDzwzArlvJ6bPke9B90BBnKN3zDoTek37dITuYJuJOgmPhqFSD+dipD+dSh z6Pgfxa8m1mCtQz7+ZJPnHqRGaual06IoD8SSUV1VMzyLbV7d2jHyWMQ4yFghXMbZmtq tBmUqzrUEtZvhSvvFr9kF5Xm2hqB4a7MNjVTLbxnvEGtkcMvxy7LmuPfvHx6O/Bdq86e sPvXIToxSncK0ce5i3puBaZmWcEH7Z2SL1KSc28DIJlWv/6Dqbp8NcSaUAr4SxQLZxh1 SUaPr9EU3d2Bp73fF5J0W/8aj64GjH86nhgFS1rXQjmZbZQxo934IwO+BaXVJhhcFFDS fbSg== X-Gm-Message-State: ALoCoQnimvylENZ8CWUgKre1ISp/z+ojILsAU3p+iiv5+lE+NVk8jSjj7POHWju6jivVApf56jYO X-Received: by 10.112.173.136 with SMTP id bk8mr743924lbc.20.1444826949514; Wed, 14 Oct 2015 05:49:09 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.21.42 with SMTP id l42ls27767lfi.96.gmail; Wed, 14 Oct 2015 05:49:09 -0700 (PDT) X-Received: by 10.25.161.136 with SMTP id k130mr1007996lfe.25.1444826949354; Wed, 14 Oct 2015 05:49:09 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id pz6si5422721lbb.172.2015.10.14.05.49.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Oct 2015 05:49:09 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbcao8 with SMTP id ao8so45333094lbc.3 for ; Wed, 14 Oct 2015 05:49:09 -0700 (PDT) X-Received: by 10.112.135.9 with SMTP id po9mr1544996lbb.56.1444826949212; Wed, 14 Oct 2015 05:49:09 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp2712709lbq; Wed, 14 Oct 2015 05:49:08 -0700 (PDT) X-Received: by 10.66.157.135 with SMTP id wm7mr3635982pab.22.1444826948061; Wed, 14 Oct 2015 05:49:08 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id qw9si13041049pbc.223.2015.10.14.05.49.07; Wed, 14 Oct 2015 05:49:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932520AbbJNMsx (ORCPT + 30 others); Wed, 14 Oct 2015 08:48:53 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:50250 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753434AbbJNMmz (ORCPT ); Wed, 14 Oct 2015 08:42:55 -0400 Received: from 172.24.1.49 (EHLO szxeml425-hub.china.huawei.com) ([172.24.1.49]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CWT05936; Wed, 14 Oct 2015 20:42:22 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml425-hub.china.huawei.com (10.82.67.180) with Microsoft SMTP Server id 14.3.235.1; Wed, 14 Oct 2015 20:42:08 +0800 From: Wang Nan To: , , CC: , , , , , , , , , , , , Wang Nan , Arnaldo Carvalho de Melo Subject: [PATCH 02/31] perf ebpf: Add the libbpf glue Date: Wed, 14 Oct 2015 12:41:13 +0000 Message-ID: <1444826502-49291-3-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1444826502-49291-1-git-send-email-wangnan0@huawei.com> References: <1444826502-49291-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: wangnan0@huawei.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The 'bpf-loader.[ch]' files are introduced in this patch. Which will be the interface between perf and libbpf. bpf__prepare_load() resides in bpf-loader.c. Following patches will enrich these two files. Signed-off-by: Wang Nan Signed-off-by: Arnaldo Carvalho de Melo Acked-by: Alexei Starovoitov Cc: Brendan Gregg Cc: Daniel Borkmann Cc: David Ahern Cc: He Kuang Cc: Jiri Olsa Cc: Kaixu Xia Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Paul Mackerras Cc: Peter Zijlstra Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/n/ebpf-6yw9eg0ej3l4jnqhinngkw86@git.kernel.org --- tools/perf/util/bpf-loader.c | 57 ++++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/bpf-loader.h | 29 ++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 tools/perf/util/bpf-loader.c create mode 100644 tools/perf/util/bpf-loader.h diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c new file mode 100644 index 0000000..ab56073 --- /dev/null +++ b/tools/perf/util/bpf-loader.c @@ -0,0 +1,57 @@ +/* + * bpf-loader.c + * + * Copyright (C) 2015 Wang Nan + * Copyright (C) 2015 Huawei Inc. + */ + +#include +#include +#include "perf.h" +#include "debug.h" +#include "bpf-loader.h" + +#define DEFINE_PRINT_FN(name, level) \ +static int libbpf_##name(const char *fmt, ...) \ +{ \ + va_list args; \ + int ret; \ + \ + va_start(args, fmt); \ + ret = veprintf(level, verbose, pr_fmt(fmt), args);\ + va_end(args); \ + return ret; \ +} + +DEFINE_PRINT_FN(warning, 0) +DEFINE_PRINT_FN(info, 0) +DEFINE_PRINT_FN(debug, 1) + +struct bpf_object *bpf__prepare_load(const char *filename) +{ + struct bpf_object *obj; + static bool libbpf_initialized; + + if (!libbpf_initialized) { + libbpf_set_print(libbpf_warning, + libbpf_info, + libbpf_debug); + libbpf_initialized = true; + } + + obj = bpf_object__open(filename); + if (!obj) { + pr_debug("bpf: failed to load %s\n", filename); + return ERR_PTR(-EINVAL); + } + + return obj; +} + +void bpf__clear(void) +{ + struct bpf_object *obj, *tmp; + + bpf_object__for_each_safe(obj, tmp) + bpf_object__close(obj); +} diff --git a/tools/perf/util/bpf-loader.h b/tools/perf/util/bpf-loader.h new file mode 100644 index 0000000..f402d7c --- /dev/null +++ b/tools/perf/util/bpf-loader.h @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2015, Wang Nan + * Copyright (C) 2015, Huawei Inc. + */ +#ifndef __BPF_LOADER_H +#define __BPF_LOADER_H + +#include +#include +#include +#include "debug.h" + +struct bpf_object; + +#ifdef HAVE_LIBBPF_SUPPORT +struct bpf_object *bpf__prepare_load(const char *filename); + +void bpf__clear(void); +#else +static inline struct bpf_object * +bpf__prepare_load(const char *filename __maybe_unused) +{ + pr_debug("ERROR: eBPF object loading is disabled during compiling.\n"); + return ERR_PTR(-ENOTSUP); +} + +static inline void bpf__clear(void) { } +#endif +#endif