From: Yonghong Song <yhs@meta.com>
To: Xueming Feng <kuro@kuroa.me>, Quentin Monnet <quentin@isovalent.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
Martin KaFai Lau <martin.lau@linux.dev>,
Song Liu <song@kernel.org>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@kernel.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
Jiri Olsa <jolsa@kernel.org>,
bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next v4] bpftool: Dump map id instead of value for map_of_maps types
Date: Thu, 27 Apr 2023 07:43:48 -0700 [thread overview]
Message-ID: <3a96ec27-9175-e161-32ef-5cb40f4e1ea2@meta.com> (raw)
In-Reply-To: <20230427120313.43574-1-kuro@kuroa.me>
On 4/27/23 5:03 AM, Xueming Feng wrote:
> When using `bpftool map dump` with map_of_maps, it is usually
> more convenient to show the inner map id instead of raw value.
>
> We are changing the plain print behavior to show inner_map_id
> instead of hex value, this would help with quick look up of
> inner map with `bpftool map dump id <inner_map_id>`.
> To avoid disrupting scripted behavior, we will add a new
> `inner_map_id` field to json output instead of replacing value.
>
> plain print:
> ```
> $ bpftool map dump id 138
>
> Without Patch:
> key:
> fc 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05
> 27 16 06 00
> value:
> 8b 00 00 00
> Found 1 element
>
> With Patch:
> key:
> fc 00 00 00 00 00 00 00 00 00 00 00 00 00 00 05
> 27 16 06 00
> inner_map_id:
> 139
> Found 1 element
> ```
>
> json print:
> ```
> $ bpftool -p map dump id 567
>
> Without Patch:
> [{
> "key": ["0xc0","0x00","0x02","0x05","0x27","0x16","0x06","0x00"
> ],
> "value": ["0x38","0x02","0x00","0x00"
> ]
> }
> ]
>
> With Patch:
> [{
> "key": ["0xc0","0x00","0x02","0x05","0x27","0x16","0x06","0x00"
> ],
> "value": ["0x38","0x02","0x00","0x00"
> ],
> "inner_map_id": 568
> }
> ]
> ```
>
> Signed-off-by: Xueming Feng <kuro@kuroa.me>
You can carry my Ack from v3 since there is no big changes.
Anyway, Ack again.
Acked-by: Yonghong Song <yhs@fb.com>
> ---
>
> Changes in v4:
> - Remove unnecessary parenthesis ('{}').
>
> Changes in v3:
> - In plain print, use printf() directly since inner map id is always a 32bit int.
> - Remove unused print_uint() function.
> - Rename `id` to `inner_map_id` in plain print output for clearness.
> - Add a new `inner_map_id` field to json output.
> - Add example output to commit message.
>
> Changes in v2:
> - Fix commit message grammar.
> - Change `print_uint` to only print to stdout, make `arg` const,
> and rename `n` to `arg_size`.
> - Make `print_uint` able to take any size of argument up to `unsigned long`,
> and print it as unsigned decimal.
>
> tools/bpf/bpftool/map.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
> index aaeb8939e137..ae9e822aa3fe 100644
> --- a/tools/bpf/bpftool/map.c
> +++ b/tools/bpf/bpftool/map.c
> @@ -139,6 +139,9 @@ static void print_entry_json(struct bpf_map_info *info, unsigned char *key,
> print_hex_data_json(key, info->key_size);
> jsonw_name(json_wtr, "value");
> print_hex_data_json(value, info->value_size);
> + if (map_is_map_of_maps(info->type))
> + jsonw_uint_field(json_wtr, "inner_map_id",
> + *(unsigned int *)value);
> if (btf) {
> struct btf_dumper d = {
> .btf = btf,
> @@ -259,8 +262,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("inner_map_id:%c", break_names ? '\n' : ' ');
> + printf("%u ", *(unsigned int *)value);
> + } else {
> + printf("value:%c", break_names ? '\n' : ' ');
> + fprint_hex(stdout, value, info->value_size, " ");
> + }
> }
>
> printf("\n");
next prev parent reply other threads:[~2023-04-27 14:44 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-27 12:03 [PATCH bpf-next v4] bpftool: Dump map id instead of value for map_of_maps types Xueming Feng
2023-04-27 14:43 ` Yonghong Song [this message]
2023-04-27 21:28 ` patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3a96ec27-9175-e161-32ef-5cb40f4e1ea2@meta.com \
--to=yhs@meta.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kpsingh@kernel.org \
--cc=kuro@kuroa.me \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=quentin@isovalent.com \
--cc=sdf@google.com \
--cc=song@kernel.org \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox