Skip to content

Commit deaee27

Browse files
jognesspmladek
authored andcommitted
scripts/gdb: lx-dmesg: read records individually
For the gdb command lx-dmesg, the entire descriptor, info, and text data regions are read into memory before printing any records. For large kernel log buffers, this not only causes a huge delay before seeing any records, but it may also lead to python errors of too much memory allocation. Rather than reading in all these regions in advance, read them as needed and only read the regions for the particular record that is being printed. The gdb macro "dmesg" in Documentation/admin-guide/kdump/gdbmacros.txt already prints out the kernel log buffer like this. Signed-off-by: John Ogness <[email protected]> Signed-off-by: Petr Mladek <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 52e68cd commit deaee27

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

scripts/gdb/linux/dmesg.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,29 @@ def invoke(self, arg, from_tty):
4444
sz = prb_desc_ring_type.get_type().sizeof
4545
desc_ring = utils.read_memoryview(inf, addr, sz).tobytes()
4646

47-
# read in descriptor array
47+
# read in descriptor count, size, and address
4848
off = prb_desc_ring_type.get_type()['count_bits'].bitpos // 8
4949
desc_ring_count = 1 << utils.read_u32(desc_ring, off)
5050
desc_sz = prb_desc_type.get_type().sizeof
5151
off = prb_desc_ring_type.get_type()['descs'].bitpos // 8
52-
addr = utils.read_ulong(desc_ring, off)
53-
descs = utils.read_memoryview(inf, addr, desc_sz * desc_ring_count).tobytes()
52+
desc_addr = utils.read_ulong(desc_ring, off)
5453

55-
# read in info array
54+
# read in info size and address
5655
info_sz = printk_info_type.get_type().sizeof
5756
off = prb_desc_ring_type.get_type()['infos'].bitpos // 8
58-
addr = utils.read_ulong(desc_ring, off)
59-
infos = utils.read_memoryview(inf, addr, info_sz * desc_ring_count).tobytes()
57+
info_addr = utils.read_ulong(desc_ring, off)
6058

6159
# read in text data ring structure
6260
off = printk_ringbuffer_type.get_type()['text_data_ring'].bitpos // 8
6361
addr = prb_addr + off
6462
sz = prb_data_ring_type.get_type().sizeof
6563
text_data_ring = utils.read_memoryview(inf, addr, sz).tobytes()
6664

67-
# read in text data
65+
# read in text data size and address
6866
off = prb_data_ring_type.get_type()['size_bits'].bitpos // 8
6967
text_data_sz = 1 << utils.read_u32(text_data_ring, off)
7068
off = prb_data_ring_type.get_type()['data'].bitpos // 8
71-
addr = utils.read_ulong(text_data_ring, off)
72-
text_data = utils.read_memoryview(inf, addr, text_data_sz).tobytes()
69+
text_data_addr = utils.read_ulong(text_data_ring, off)
7370

7471
counter_off = atomic_long_type.get_type()['counter'].bitpos // 8
7572

@@ -102,17 +99,20 @@ def invoke(self, arg, from_tty):
10299
desc_off = desc_sz * ind
103100
info_off = info_sz * ind
104101

102+
desc = utils.read_memoryview(inf, desc_addr + desc_off, desc_sz).tobytes()
103+
105104
# skip non-committed record
106-
state = 3 & (utils.read_u64(descs, desc_off + sv_off +
107-
counter_off) >> desc_flags_shift)
105+
state = 3 & (utils.read_u64(desc, sv_off + counter_off) >> desc_flags_shift)
108106
if state != desc_committed and state != desc_finalized:
109107
if did == head_id:
110108
break
111109
did = (did + 1) & desc_id_mask
112110
continue
113111

114-
begin = utils.read_ulong(descs, desc_off + begin_off) % text_data_sz
115-
end = utils.read_ulong(descs, desc_off + next_off) % text_data_sz
112+
begin = utils.read_ulong(desc, begin_off) % text_data_sz
113+
end = utils.read_ulong(desc, next_off) % text_data_sz
114+
115+
info = utils.read_memoryview(inf, info_addr + info_off, info_sz).tobytes()
116116

117117
# handle data-less record
118118
if begin & 1 == 1:
@@ -125,16 +125,17 @@ def invoke(self, arg, from_tty):
125125
# skip over descriptor id
126126
text_start = begin + utils.get_long_type().sizeof
127127

128-
text_len = utils.read_u16(infos, info_off + len_off)
128+
text_len = utils.read_u16(info, len_off)
129129

130130
# handle truncated message
131131
if end - text_start < text_len:
132132
text_len = end - text_start
133133

134-
text = text_data[text_start:text_start + text_len].decode(
135-
encoding='utf8', errors='replace')
134+
text_data = utils.read_memoryview(inf, text_data_addr + text_start,
135+
text_len).tobytes()
136+
text = text_data[0:text_len].decode(encoding='utf8', errors='replace')
136137

137-
time_stamp = utils.read_u64(infos, info_off + ts_off)
138+
time_stamp = utils.read_u64(info, ts_off)
138139

139140
for line in text.splitlines():
140141
msg = u"[{time:12.6f}] {line}\n".format(

0 commit comments

Comments
 (0)