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=-13.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 39878C2BB84 for ; Mon, 7 Sep 2020 15:56:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F395A21473 for ; Mon, 7 Sep 2020 15:56:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=isovalent-com.20150623.gappssmtp.com header.i=@isovalent-com.20150623.gappssmtp.com header.b="zVxkI05+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730178AbgIGP40 (ORCPT ); Mon, 7 Sep 2020 11:56:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730013AbgIGOuk (ORCPT ); Mon, 7 Sep 2020 10:50:40 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC2B2C061574 for ; Mon, 7 Sep 2020 07:50:39 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id e11so12480489wme.0 for ; Mon, 07 Sep 2020 07:50:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=DinUSQlSNAtBZl1poOuoTi8r63ZyczWh89UGQokdimg=; b=zVxkI05+Lzjv1QKQLFyDIqCe+3maw5Wwz4fbaRSokoA4LeQLM+HrfTXeMCEVGPV1Q3 b6WdkBjOuZB2lq9VcrB/xew5mV14f62DAzDrWsXhhWGinorDyzuOPLb92zMNg0+XJnBe Ob0dAcm2uNIVZwL3xPDW3c9MWpHz7wnODe96tw0izmRZJX83vEEz1v1bfPp4LNtCHDUB qzIaBTZXD4rVKnDk/iDjiqkVdfRVKSh2OItjPO+dFuxUIWZzJ66LGDDryObpAY7pnDDR kIfzRXNG2J3MH4wmd6cwNH9fmm1129pFCwaSz8eUZWy2C98r+7uhwGNHCz6pF9D8tMZ3 dniA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=DinUSQlSNAtBZl1poOuoTi8r63ZyczWh89UGQokdimg=; b=fH/9bXGWYn2N/9epY4wltAc57UoPC0u994IkphK5fj/uNtBgit7XVu89fWKjCKzdAe rnae1M1VF0FUlOT0JQtXJoq/dtavrbnvIgEds+4KBvw9MgTrZkkDyR0VQMnpJHe7Xy5g cIBvyvuraUshQBCl+zATXQ4O+xlAO9tossoA9QS6iIQi2HesRCWRp53oWaNH1Xs70NVm RQZFBdwstR2CtknW/krbOaIgIrI+lxcRVYMWIH6xyl3NvQLNKP3t0K/Kokzrz6PNTIJ6 5XqJoylWupb2CjPrDRcuYdlnSqd4lopkOzRuigJUP0kjOjy1YtHbVJeJGwQTOGuO01Mh vb4w== X-Gm-Message-State: AOAM531EXungTuPVULiBnm2pbRqt+IgWR5cTI//EII1VE4mmWJWFJyum Jivo1/b58OC8+5v+W8UEhcjbhg== X-Google-Smtp-Source: ABdhPJxmuPA2M4lnE9NsRAz2mPX4QG5I05M4IYHHAfAH5+Xqn3PLwXdtfryUfO6kViHxXLdydjC8tA== X-Received: by 2002:a1c:28c1:: with SMTP id o184mr22014621wmo.91.1599490237107; Mon, 07 Sep 2020 07:50:37 -0700 (PDT) Received: from [192.168.1.12] ([194.35.119.8]) by smtp.gmail.com with ESMTPSA id o9sm28010621wrw.58.2020.09.07.07.50.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 07 Sep 2020 07:50:36 -0700 (PDT) Subject: Re: [PATCH bpf-next 1/3] tools: bpftool: print optional built-in features along with version To: Andrii Nakryiko Cc: Alexei Starovoitov , Daniel Borkmann , bpf , Networking References: <20200904205657.27922-1-quentin@isovalent.com> <20200904205657.27922-2-quentin@isovalent.com> From: Quentin Monnet Message-ID: <05b0ff4c-cf69-a452-6c0e-187ec2961063@isovalent.com> Date: Mon, 7 Sep 2020 15:50:36 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On 04/09/2020 22:45, Andrii Nakryiko wrote: > On Fri, Sep 4, 2020 at 1:57 PM Quentin Monnet wrote: >> >> Bpftool has a number of features that can be included or left aside >> during compilation. This includes: >> >> - Support for libbfd, providing the disassembler for JIT-compiled >> programs. >> - Support for BPF skeletons, used for profiling programs or iterating on >> the PIDs of processes associated with BPF objects. >> >> In order to make it easy for users to understand what features were >> compiled for a given bpftool binary, print the status of the two >> features above when showing the version number for bpftool ("bpftool -V" >> or "bpftool version"). Document this in the main manual page. Example >> invocation: >> >> $ bpftool -p version >> { >> "version": "5.9.0-rc1", >> "features": [ >> "libbfd": true, >> "skeletons": true >> ] > > Is this a valid JSON? array of key/value pairs? No it's not, silly me :'(. I'll fix that, thanks for spotting it. >> } >> >> Some other parameters are optional at compilation >> ("DISASM_FOUR_ARGS_SIGNATURE", LIBCAP support) but they do not impact >> significantly bpftool's behaviour from a user's point of view, so their >> status is not reported. >> >> Available commands and supported program types depend on the version >> number, and are therefore not reported either. Note that they are >> already available, albeit without JSON, via bpftool's help messages. >> >> Signed-off-by: Quentin Monnet >> --- >> tools/bpf/bpftool/Documentation/bpftool.rst | 8 +++++++- >> tools/bpf/bpftool/main.c | 22 +++++++++++++++++++++ >> 2 files changed, 29 insertions(+), 1 deletion(-) >> >> diff --git a/tools/bpf/bpftool/Documentation/bpftool.rst b/tools/bpf/bpftool/Documentation/bpftool.rst >> index 420d4d5df8b6..a3629a3f1175 100644 >> --- a/tools/bpf/bpftool/Documentation/bpftool.rst >> +++ b/tools/bpf/bpftool/Documentation/bpftool.rst >> @@ -50,7 +50,13 @@ OPTIONS >> Print short help message (similar to **bpftool help**). >> >> -V, --version >> - Print version number (similar to **bpftool version**). >> + Print version number (similar to **bpftool version**), and >> + optional features that were included when bpftool was >> + compiled. Optional features include linking against libbfd to >> + provide the disassembler for JIT-ted programs (**bpftool prog >> + dump jited**) and usage of BPF skeletons (some features like >> + **bpftool prog profile** or showing pids associated to BPF >> + objects may rely on it). > > nit: I'd emit it as a list, easier to see list of features visually > >> >> -j, --json >> Generate JSON output. For commands that cannot produce JSON, this >> diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c >> index 4a191fcbeb82..2ae8c0d82030 100644 >> --- a/tools/bpf/bpftool/main.c >> +++ b/tools/bpf/bpftool/main.c >> @@ -70,13 +70,35 @@ static int do_help(int argc, char **argv) >> >> static int do_version(int argc, char **argv) >> { >> +#ifdef HAVE_LIBBFD_SUPPORT >> + const bool has_libbfd = true; >> +#else >> + const bool has_libbfd = false; >> +#endif >> +#ifdef BPFTOOL_WITHOUT_SKELETONS >> + const bool has_skeletons = false; >> +#else >> + const bool has_skeletons = true; >> +#endif >> + >> if (json_output) { >> jsonw_start_object(json_wtr); >> + >> jsonw_name(json_wtr, "version"); >> jsonw_printf(json_wtr, "\"%s\"", BPFTOOL_VERSION); >> + >> + jsonw_name(json_wtr, "features"); >> + jsonw_start_array(json_wtr); >> + jsonw_bool_field(json_wtr, "libbfd", has_libbfd); >> + jsonw_bool_field(json_wtr, "skeletons", has_skeletons); >> + jsonw_end_array(json_wtr); >> + >> jsonw_end_object(json_wtr); >> } else { >> printf("%s v%s\n", bin_name, BPFTOOL_VERSION); >> + printf("features: libbfd=%s, skeletons=%s\n", >> + has_libbfd ? "true" : "false", >> + has_skeletons ? "true" : "false"); > > now imagine parsing this with CLI text tools, you'll have to find > "skeletons=(false|true)" and then parse "true" to know skeletons are > supported. Why not just print out features that are supported? You could just grep for "skeletons=true" (not too hard) (And generally speaking I'd recommend against parsing bpftool's plain output, JSON is more stable - Once you're parsing the JSON, checking the feature is present or checking whether it's at "true" does not make a great difference). Anyway, the reason I have those booleans is that if you just list the features and run "bpftool version | grep libbpfd" and get no result, you cannot tell if the binary has been compiled without the disassembler or if you are running an older version of bpftool that does not list built-in features. You could then parse the version number and double check, but you need to find in what version the change has been added. Besides libbfd and skeletons, this could happen again for future optional features if we add them to bpftool but forget to immediately add the related check for "bpftool version". So I would be inclined to keep the booleans. Or do you still believe a list is preferable? Quentin