netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yonghong Song <yhs@fb.com>
To: <netdev@vger.kernel.org>
Cc: Alexei Starovoitov <ast@fb.com>,
	Daniel Borkmann <daniel@iogearbox.net>, <kernel-team@fb.com>,
	Martin KaFai Lau <kafai@fb.com>
Subject: [PATCH bpf-next v2 7/8] tools: bpftool: refactor btf_dumper_int_bits()
Date: Fri, 14 Dec 2018 15:34:33 -0800	[thread overview]
Message-ID: <20181214233433.2668012-1-yhs@fb.com> (raw)
In-Reply-To: <20181214233425.2667487-1-yhs@fb.com>

The core dump funcitonality in btf_dumper_int_bits() is
refactored into a separate function btf_dumper_bitfield()
which will be used by the next patch.

Signed-off-by: Yonghong Song <yhs@fb.com>
---
 tools/bpf/bpftool/btf_dumper.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c
index 5cdb2ef8b6f1..ec1da87c3d65 100644
--- a/tools/bpf/bpftool/btf_dumper.c
+++ b/tools/bpf/bpftool/btf_dumper.c
@@ -73,20 +73,17 @@ static int btf_dumper_array(const struct btf_dumper *d, __u32 type_id,
 	return ret;
 }
 
-static void btf_dumper_int_bits(__u32 int_type, __u8 bit_offset,
+static void btf_dumper_bitfield(__u32 nr_bits, __u8 bit_offset,
 				const void *data, json_writer_t *jw,
 				bool is_plain_text)
 {
 	int left_shift_bits, right_shift_bits;
-	int nr_bits = BTF_INT_BITS(int_type);
-	int total_bits_offset;
 	int bytes_to_copy;
 	int bits_to_copy;
 	__u64 print_num;
 
-	total_bits_offset = bit_offset + BTF_INT_OFFSET(int_type);
-	data += BITS_ROUNDDOWN_BYTES(total_bits_offset);
-	bit_offset = BITS_PER_BYTE_MASKED(total_bits_offset);
+	data += BITS_ROUNDDOWN_BYTES(bit_offset);
+	bit_offset = BITS_PER_BYTE_MASKED(bit_offset);
 	bits_to_copy = bit_offset + nr_bits;
 	bytes_to_copy = BITS_ROUNDUP_BYTES(bits_to_copy);
 
@@ -109,6 +106,19 @@ static void btf_dumper_int_bits(__u32 int_type, __u8 bit_offset,
 		jsonw_printf(jw, "%llu", print_num);
 }
 
+
+static void btf_dumper_int_bits(__u32 int_type, __u8 bit_offset,
+				const void *data, json_writer_t *jw,
+				bool is_plain_text)
+{
+	int nr_bits = BTF_INT_BITS(int_type);
+	int total_bits_offset;
+
+	total_bits_offset = bit_offset + BTF_INT_OFFSET(int_type);
+	btf_dumper_bitfield(nr_bits, total_bits_offset, data, jw,
+			    is_plain_text);
+}
+
 static int btf_dumper_int(const struct btf_type *t, __u8 bit_offset,
 			  const void *data, json_writer_t *jw,
 			  bool is_plain_text)
-- 
2.17.1

  parent reply	other threads:[~2018-12-14 23:34 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-14 23:34 [PATCH bpf-next v2 0/8] bpf: btf: fix struct/union/fwd types with kind_flag Yonghong Song
2018-12-14 23:34 ` [PATCH bpf-next v2 1/8] bpf: btf: refactor btf_int_bits_seq_show() Yonghong Song
2018-12-15 16:44   ` Martin Lau
2018-12-14 23:34 ` [PATCH bpf-next v2 2/8] bpf: btf: fix struct/union/fwd types with kind_flag Yonghong Song
2018-12-15 16:37   ` Martin Lau
2018-12-15 17:42     ` Yonghong Song
2018-12-15 17:44     ` Alexei Starovoitov
2018-12-15 22:10       ` Martin Lau
2018-12-15 22:26         ` Yonghong Song
2018-12-15 23:04           ` Martin Lau
2018-12-15 23:13             ` Yonghong Song
2018-12-15 23:19               ` Alexei Starovoitov
2018-12-16  6:18       ` Yonghong Song
2018-12-15 22:37   ` Daniel Borkmann
2018-12-15 23:12     ` Yonghong Song
2018-12-14 23:34 ` [PATCH bpf-next v2 3/8] bpf: enable cgroup local storage map pretty print " Yonghong Song
2018-12-15 16:43   ` Martin Lau
2018-12-14 23:34 ` [PATCH bpf-next v2 4/8] tools/bpf: sync btf.h header from kernel to tools Yonghong Song
2018-12-15 20:56   ` Martin Lau
2018-12-14 23:34 ` [PATCH bpf-next v2 5/8] tools/bpf: add test_btf unit tests for kind_flag Yonghong Song
2018-12-15 21:03   ` Martin Lau
2018-12-16  4:10     ` Yonghong Song
2018-12-14 23:34 ` [PATCH bpf-next v2 6/8] tools/bpf: test kernel bpffs map pretty print with struct kind_flag Yonghong Song
2018-12-15 21:18   ` Martin Lau
2018-12-14 23:34 ` Yonghong Song [this message]
2018-12-15 21:26   ` [PATCH bpf-next v2 7/8] tools: bpftool: refactor btf_dumper_int_bits() Martin Lau
2018-12-16  5:31     ` Yonghong Song
2018-12-14 23:34 ` [PATCH bpf-next v2 8/8] tools: bpftool: support pretty print with kind_flag set Yonghong Song
2018-12-15 21:49   ` Martin Lau
2018-12-16  5:36     ` Yonghong Song

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=20181214233433.2668012-1-yhs@fb.com \
    --to=yhs@fb.com \
    --cc=ast@fb.com \
    --cc=daniel@iogearbox.net \
    --cc=kafai@fb.com \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).