From patchwork Thu Oct 8 08:29:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 54627 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by patches.linaro.org (Postfix) with ESMTPS id BBF4822FF8 for ; Thu, 8 Oct 2015 08:32:12 +0000 (UTC) Received: by wicb12 with SMTP id b12sf6781348wic.1 for ; Thu, 08 Oct 2015 01:32:12 -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=KqGhYXCIEYBtdC15h+875JqB1KVi9cFeqVCdsxzbSZkHZYTGRb0MpB9STJO17rugid WLW6iVJcP4Znb0/B1Fh1mJSYJLLVP9IAWlnw4eBGfIPLUD25eqI02Fkc+Vcy8idsHLBt D+VVSOWsqXKQkyTbGwmBMh/dL6iyHxb0fZPhBw4YpQQz5jy1Fr4SYpOw+gZz2VPtClk+ fafiW9n2ALvLs/u/BIblEgSeb53XXdeIZwaN3ErJh5A3JqwMTfkqTu6Eoiqy72REQgux x/kBzm8jIyRgcGsI51A9cTFdLZ/C1bcxlsUhILPb8kap1jQd27IaK2Rjb7E7SXmN2ZEu 24BQ== X-Gm-Message-State: ALoCoQkaTUzrT0me9O+twrUHRrVfp/v40XRXsYyzo6G90YIXjNc6dxRIDeGRguQvAbmQm9mr62rm X-Received: by 10.112.130.41 with SMTP id ob9mr1091618lbb.17.1444293131962; Thu, 08 Oct 2015 01:32:11 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.43.133 with SMTP id r127ls145485lfr.74.gmail; Thu, 08 Oct 2015 01:32:11 -0700 (PDT) X-Received: by 10.112.54.169 with SMTP id k9mr2852868lbp.95.1444293131795; Thu, 08 Oct 2015 01:32:11 -0700 (PDT) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id 101si269579lfp.99.2015.10.08.01.32.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 08 Oct 2015 01:32:11 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by lbbwt4 with SMTP id wt4so38573019lbb.1 for ; Thu, 08 Oct 2015 01:32:11 -0700 (PDT) X-Received: by 10.25.77.133 with SMTP id a127mr1925491lfb.19.1444293131597; Thu, 08 Oct 2015 01:32:11 -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 w3csp438118lbq; Thu, 8 Oct 2015 01:32:10 -0700 (PDT) X-Received: by 10.68.195.3 with SMTP id ia3mr6657448pbc.106.1444293130357; Thu, 08 Oct 2015 01:32:10 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id wx5si64685563pbc.188.2015.10.08.01.32.09; Thu, 08 Oct 2015 01:32:10 -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 S1754139AbbJHIcG (ORCPT + 30 others); Thu, 8 Oct 2015 04:32:06 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:49450 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754077AbbJHIbz (ORCPT ); Thu, 8 Oct 2015 04:31:55 -0400 Received: from 172.24.1.47 (EHLO szxeml427-hub.china.huawei.com) ([172.24.1.47]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CTW16022; Thu, 08 Oct 2015 16:29:47 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml427-hub.china.huawei.com (10.82.67.182) with Microsoft SMTP Server id 14.3.235.1; Thu, 8 Oct 2015 16:29:25 +0800 From: Wang Nan To: CC: , , , Wang Nan , Brendan Gregg , Daniel Borkmann , David Ahern , "He Kuang" , Jiri Olsa , Kaixu Xia , Masami Hiramatsu , Namhyung Kim , Paul Mackerras , Peter Zijlstra Subject: [PATCH 02/22] perf ebpf: Add the libbpf glue Date: Thu, 8 Oct 2015 08:29:24 +0000 Message-ID: <1444292984-13135-3-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1444292984-13135-1-git-send-email-wangnan0@huawei.com> References: <1444292984-13135-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.175 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