From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B06A1C169C4 for ; Thu, 31 Jan 2019 19:36:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 78CC720B1F for ; Thu, 31 Jan 2019 19:36:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pkrhvq0W" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727176AbfAaTgB (ORCPT ); Thu, 31 Jan 2019 14:36:01 -0500 Received: from mail-it1-f193.google.com ([209.85.166.193]:51581 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725807AbfAaTgA (ORCPT ); Thu, 31 Jan 2019 14:36:00 -0500 Received: by mail-it1-f193.google.com with SMTP id w18so5507483ite.1 for ; Thu, 31 Jan 2019 11:35:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=b25QAux0T0VzXDD07W2h+4xrUq12vdsaX2fsyH5kM58=; b=pkrhvq0W0PadBJUE+43IVSe/+9JkJW5buVrlgZgkhWnZFS78xepPdgcZ4ql8MJtm4I 8lIYZYQFTS/9kBYJsvK8oNdMjZ8Se096jNPMk9VSo7erZMFQmfnQm2SbIwZnyuQ32pDZ xBMJgMAFdUcpYeSfB+wr5iXAFzlMCw0mfW2obg1eI4PDR/tfVj83JxpXYYUZ+hX5SI+H QcH9W8c1o733R7WUWCEeCID5VFfZKPZKIVBJ5bDbYyA7SUo5rU7vUNaJfN5sb+1LPNtu LgqYOKZ3C0XszKU1HCnJXwlZTlucyDZHRy3vAAbk6fPy2xt6gtd2bfHnhY9To7Bdd0KE NQEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=b25QAux0T0VzXDD07W2h+4xrUq12vdsaX2fsyH5kM58=; b=b6gO1MLvtRNFDksjoRcBZuyDzPKGwja54oGuLQl/Yo7IjmGngf74SZXfEfuFQAcTus LxlQa1LC8ipuGL9NxgW6C7uWBQYm42GP9dUGfzduNwo3qRIkyLT+X+2G4TSKd6tocjKv FzFb+EFwzthy6dSL+4hPPyxHvoiaEoCzyhUahmfVoiuym/AsLGZtRNdx+wHzisyFYaHq e+SuIkdkNbpmjHEWxJ+ZccqTlvSyBPFK7tCh5v0Kq5DtAqaG1kNKPh+Dr3qlpPDOgjhL yi2i0BHXIXhsz8n51IqokP+HNROd3dSZ/OKiwS6H+UGFFZDdfvDZMoe8opKky250J/S5 9Kcg== X-Gm-Message-State: AJcUukdYlxhSxVfmFCxt7MULD4aG+2TsYXZF9+L/z2vZR8tl4r+hCfki WNIp7bllrE7PuNNjMM+4y6oW3kMYUkVeov8QU/0= X-Google-Smtp-Source: ALg8bN7NvfgD0G7UKNkajxgw3Nh7LBvGQWORA5XWKtAz5kjRiwGeqoipV/TjJEVcyILKKZJ6ExyJidN6VK1gJN1N008= X-Received: by 2002:a24:710:: with SMTP id f16mr16880899itf.121.1548963359140; Thu, 31 Jan 2019 11:35:59 -0800 (PST) MIME-Version: 1.0 References: <1548774737-16579-1-git-send-email-magnus.karlsson@intel.com> <1548774737-16579-2-git-send-email-magnus.karlsson@intel.com> In-Reply-To: <1548774737-16579-2-git-send-email-magnus.karlsson@intel.com> From: Y Song Date: Thu, 31 Jan 2019 11:35:22 -0800 Message-ID: Subject: Re: [PATCH bpf-next v3 1/3] libbpf: move pr_*() functions to common header file To: Magnus Karlsson Cc: =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Alexei Starovoitov , Daniel Borkmann , netdev , Jakub Kicinski , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , qi.z.zhang@intel.com, Jesper Dangaard Brouer Content-Type: text/plain; charset="UTF-8" Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Tue, Jan 29, 2019 at 7:13 AM Magnus Karlsson wrote: > > Move the pr_*() functions in libbpf.c to a common header file called > libbpf_internal.h. This so that the later libbpf AF_XDP helper library > code in xsk.c can use these printing functions too. > > Signed-off-by: Magnus Karlsson > --- > tools/lib/bpf/libbpf.c | 30 +----------------------------- > tools/lib/bpf/libbpf_internal.h | 41 +++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 42 insertions(+), 29 deletions(-) > create mode 100644 tools/lib/bpf/libbpf_internal.h > > diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c > index 2ccde17..1d7fe26 100644 > --- a/tools/lib/bpf/libbpf.c > +++ b/tools/lib/bpf/libbpf.c > @@ -39,6 +39,7 @@ > #include > > #include "libbpf.h" > +#include "libbpf_internal.h" > #include "bpf.h" > #include "btf.h" > #include "str_error.h" > @@ -51,34 +52,6 @@ > #define BPF_FS_MAGIC 0xcafe4a11 > #endif > > -#define __printf(a, b) __attribute__((format(printf, a, b))) > - > -__printf(1, 2) > -static int __base_pr(const char *format, ...) > -{ > - va_list args; > - int err; > - > - va_start(args, format); > - err = vfprintf(stderr, format, args); > - va_end(args); > - return err; > -} > - > -static __printf(1, 2) libbpf_print_fn_t __pr_warning = __base_pr; > -static __printf(1, 2) libbpf_print_fn_t __pr_info = __base_pr; > -static __printf(1, 2) libbpf_print_fn_t __pr_debug; > - > -#define __pr(func, fmt, ...) \ > -do { \ > - if ((func)) \ > - (func)("libbpf: " fmt, ##__VA_ARGS__); \ > -} while (0) > - > -#define pr_warning(fmt, ...) __pr(__pr_warning, fmt, ##__VA_ARGS__) > -#define pr_info(fmt, ...) __pr(__pr_info, fmt, ##__VA_ARGS__) > -#define pr_debug(fmt, ...) __pr(__pr_debug, fmt, ##__VA_ARGS__) > - > void libbpf_set_print(libbpf_print_fn_t warn, > libbpf_print_fn_t info, > libbpf_print_fn_t debug) > @@ -96,7 +69,6 @@ void libbpf_set_print(libbpf_print_fn_t warn, > goto out; \ > } while(0) > > - > /* Copied from tools/perf/util/util.h */ > #ifndef zfree > # define zfree(ptr) ({ free(*ptr); *ptr = NULL; }) > diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h > new file mode 100644 > index 0000000..951c078 > --- /dev/null > +++ b/tools/lib/bpf/libbpf_internal.h > @@ -0,0 +1,41 @@ > +/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ > + > +/* > + * Common internal libbpf functions and definitions. > + * > + * Copyright (C) 2013-2015 Alexei Starovoitov > + * Copyright (C) 2015 Wang Nan > + * Copyright (C) 2015 Huawei Inc. > + */ > +#ifndef __LIBBPF_LIBBPF_INTERNAL_H > +#define __LIBBPF_LIBBPF_INTERNAL_H > + > +#define __printf(a, b) __attribute__((format(printf, a, b))) > + > +__printf(1, 2) > +static int __base_pr(const char *format, ...) > +{ > + va_list args; > + int err; > + > + va_start(args, format); > + err = vfprintf(stderr, format, args); > + va_end(args); > + return err; > +} Hmm. This will introduce this static function into every .c file. Maybe we could define a global function in libbpf.c like libbpf_debug_pr(level, ...) This function will be internal to the library and implemented in libbpf.c. All files can call this function to print out the debug information based on level? > + > +static __maybe_unused __printf(1, 2) libbpf_print_fn_t __pr_warning = __base_pr; > +static __maybe_unused __printf(1, 2) libbpf_print_fn_t __pr_info = __base_pr; > +static __maybe_unused __printf(1, 2) libbpf_print_fn_t __pr_debug; > + > +#define __pr(func, fmt, ...) \ > +do { \ > + if ((func)) \ > + (func)("libbpf: " fmt, ##__VA_ARGS__); \ > +} while (0) > + > +#define pr_warning(fmt, ...) __pr(__pr_warning, fmt, ##__VA_ARGS__) > +#define pr_info(fmt, ...) __pr(__pr_info, fmt, ##__VA_ARGS__) > +#define pr_debug(fmt, ...) __pr(__pr_debug, fmt, ##__VA_ARGS__) > + > +#endif /* __LIBBPF_LIBBPF_INTERNAL_H */ > -- > 2.7.4 >