Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2863357rwr; Fri, 21 Apr 2023 15:50:42 -0700 (PDT) X-Google-Smtp-Source: AKy350Z9lwx9rMQpoAUC3ViTQYKPSt0WJymKqTopq9iaUiJK2fk2ZpVJ5BbjDqAn1q0qLdh+pAwt X-Received: by 2002:a05:6a20:54a6:b0:f1:1ab5:5076 with SMTP id i38-20020a056a2054a600b000f11ab55076mr9678264pzk.2.1682117442366; Fri, 21 Apr 2023 15:50:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682117442; cv=none; d=google.com; s=arc-20160816; b=eHXnyGRAYpn09i3NqUOQjFxjGRsxvP/Eil8x67wmlahQj5yoFcJdTAfT87dhDxXAFD QxNPaZy/JuQVIxPoYCWkYxqfXQRcL1MoYJ/pHuc1kV0IliQ8Wno3vNCYf5mLR/5yGFFh Ntto6MS8r5nROdcmjWokYLmuBOFwvdXzqoFNyyW4kNj8Js8Ah/eTBIWvnpYb/uE/6R1I qEWhZeKqisJgYNWmTa7b9AjU3KfWyLWvumpQNyRD2TW3B+8dntRzM6/SYrLWPe3sxeBw oYfhzi1ghyYe8epePp/j5jIZ4489o5HEpwPSUURHSF3k6cUhmtEO/IyxRJHTxLRtnKNo qJJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Tvf5j/bINAOiQrCkYKeeaDxMIaoN8V+mcRrm9nEicRY=; b=M15f2I4xWJCYjZ8CbiMtuEBY2Hn4iPRd0Rrw6fhA9kK2Qho3N31D18TI6XoVbfpd7V fnhZwGjWsK4sjbczBIaWTS0hVE71BHYJ0cOWKH6VpqeZxihVHiQ+IPFYf0EUF6N4cu2g 8WAH+aC0GkgmNIiLEajUBTcpBk3GfD8O0o0fVWVkE//4T3ANsO2KiKczoje5Jfchctx/ hX5pmF4Zt2aIfmVENjP9CMkmoIDZkqql2P/H4U9+9U4PFWuWh/OPHVJfToaUFnZpXpmY s6uh0lQ7xNk4VLhZeeG4MBjsdyInx+jGn4/+X70iGU4SAADrI6/1ScZ2mx7NvtVfEPQk ObYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@isovalent.com header.s=google header.b=Ov7f87q+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=isovalent.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e6-20020a635446000000b00519b9bfd44bsi4937955pgm.569.2023.04.21.15.50.29; Fri, 21 Apr 2023 15:50:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@isovalent.com header.s=google header.b=Ov7f87q+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=isovalent.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233922AbjDUWoQ (ORCPT + 99 others); Fri, 21 Apr 2023 18:44:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233763AbjDUWoM (ORCPT ); Fri, 21 Apr 2023 18:44:12 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D75A91FCD for ; Fri, 21 Apr 2023 15:44:09 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id 4fb4d7f45d1cf-50685f1b6e0so3877138a12.0 for ; Fri, 21 Apr 2023 15:44:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent.com; s=google; t=1682117048; x=1684709048; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Tvf5j/bINAOiQrCkYKeeaDxMIaoN8V+mcRrm9nEicRY=; b=Ov7f87q+/GNcxXrkOnaERdvsYozN6ITub+SEYzIvIhDWs4EDVBoknOMx+R5E1AudF8 +hNH3cwIO85Ba53Hx2FGdcP4Ke3cVEfmjDIB8LAeJvesnVwsjMws0taaAC0Z3ScxxppB f9sXawapASYud7MGVUciJPDAF8I3L9G8ENjp4DM9u9bpNnlajdgg3qcx1MBdiZ3UB2Fa NeMLvIL9E+9M/rsaxsq7SOYCpkvY46G7xYRFTef5MFdtwOEXwRjkmSPi4eWGePakMnwZ pXbehglwI+R+IHSTPYmZvVuA5yinKq8YLUw6Tc0gYBDSpxIRk1T3lHX200NH/BlXRa// ja/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682117048; x=1684709048; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Tvf5j/bINAOiQrCkYKeeaDxMIaoN8V+mcRrm9nEicRY=; b=Vw7mf2E0UyQrTSkU5ymeWQ83qS2PuzE6TOW1GQmyGaG0VMjarHyzKrpXB+lLOAGvGU /B5eoZ2V3TTaHUQyv/FLBK9PPwgl9w6QHaeKPuhFiUSaPGxyQ7vT/H5h8KOr8b6yJe+o MNC+1Pa9tjarcfRZufrXio1OCsO5+6ZzrT0sGDoSKLh9mzfxc4Y4IrNhhgWpc/Gh05z0 R0dGRlrLsYwUWg7xXGYByPhZzGKDX8qdbnSngjnD4ZO4vj+UZcUAPpO6cuwmDGujHTns VVG2HURm59NrEd6IOoEN8DUjP83A4YsYsgr1sb13CViep8DETGkZs/RmDF7oXBreiPh6 sI0g== X-Gm-Message-State: AAQBX9c3HFIvTTzA8eOj2vhl9xAwG6Qy7dSsc9J8nIN3qbBK+xrIww99 DFY8V4cs8PJJqrTk9zg/ztfupxWjDWVxcFzxF5Usaw== X-Received: by 2002:a05:6402:1ad1:b0:504:7f60:9f6d with SMTP id ba17-20020a0564021ad100b005047f609f6dmr5201714edb.9.1682117048360; Fri, 21 Apr 2023 15:44:08 -0700 (PDT) MIME-Version: 1.0 References: <20230421101154.23690-1-kuro@kuroa.me> In-Reply-To: <20230421101154.23690-1-kuro@kuroa.me> From: Quentin Monnet Date: Fri, 21 Apr 2023 23:43:57 +0100 Message-ID: Subject: Re: [PATCH] Dump map id instead of value for map_of_maps types To: Xueming Feng Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 21 Apr 2023 at 11:12, Xueming Feng wrote: > > When using `bpftool map dump` in plain format, it is usually > more convenient to show the inner map id instead of raw value. > Changing this behavior would help with quick debugging with > `bpftool`, without disruption scripted behavior. Since user s/disruption/disrupting/ ? > could dump the inner map with id, but need to convert value. > > Signed-off-by: Xueming Feng Thanks for this patch! It looks good, with some minor comments below. > --- > tools/bpf/bpftool/main.c | 16 ++++++++++++++++ > tools/bpf/bpftool/main.h | 1 + > tools/bpf/bpftool/map.c | 9 +++++++-- > 3 files changed, 24 insertions(+), 2 deletions(-) > > diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c > index 08d0ac543c67..d297200c91f7 100644 > --- a/tools/bpf/bpftool/main.c > +++ b/tools/bpf/bpftool/main.c > @@ -251,6 +251,22 @@ int detect_common_prefix(const char *arg, ...) > return 0; > } > > +void fprint_uint(FILE *f, void *arg, unsigned int n) I suppose you based this function on fprint_hex(). But for your function, let's remove the first argument? We always print to stdout. We can always turn it to a "fprint" version again if we need to print elsewhere in the future. Also, "arg" should probably be a "const"? Can you please rename "n" to "arg_size" or something similar? > +{ > + unsigned char *data = arg; > + unsigned int data_uint = 0; > + > + for (unsigned int i = 0; i < n && i < 4; i++) { Please move the declaration for "i" to the top of the function, for consistency. Also, why stop at i == 4? Couldn't this function be used for 8-byte long integers too? It should be up to the caller function to set "n" correctly. > + #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ > + data_uint |= data[i] << (i * 8); > + #else > + data_uint |= data[i] << ((n - i - 1) * 8); > + #endif > + } > + > + fprintf(f, "%d", data_uint); > +} > + > void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep) > { > unsigned char *data = arg; > diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h > index 0ef373cef4c7..7488ef38e7a9 100644 > --- a/tools/bpf/bpftool/main.h > +++ b/tools/bpf/bpftool/main.h > @@ -90,6 +90,7 @@ void __printf(1, 2) p_info(const char *fmt, ...); > > bool is_prefix(const char *pfx, const char *str); > int detect_common_prefix(const char *arg, ...); > +void fprint_uint(FILE *f, void *arg, unsigned int n); > void fprint_hex(FILE *f, void *arg, unsigned int n, const char *sep); > void usage(void) __noreturn; > > diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c > index aaeb8939e137..638bd8de8135 100644 > --- a/tools/bpf/bpftool/map.c > +++ b/tools/bpf/bpftool/map.c > @@ -259,8 +259,13 @@ static void print_entry_plain(struct bpf_map_info *info, unsigned char *key, > } > > if (info->value_size) { > - printf("value:%c", break_names ? '\n' : ' '); > - fprint_hex(stdout, value, info->value_size, " "); > + if (map_is_map_of_maps(info->type)) { > + printf("id:%c", break_names ? '\n' : ' '); > + fprint_uint(stdout, value, info->value_size); > + } else { > + printf("value:%c", break_names ? '\n' : ' '); > + fprint_hex(stdout, value, info->value_size, " "); > + } > } > > printf("\n"); > -- > 2.37.1 (Apple Git-137.1) >