Skip to contentSkip to conversation

gdb command: qemu aios, qemu aiohandlers

PATCH In review Dr. David Alan Gilbert (git) 4 participants 6 messages Oct 20, 2015 – Oct 27, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gdb command: qemu aios, qemu aiohandlers

From: "Dr. David Alan Gilbert" <[email protected]>

Two new gdb commands are added:

qemu iohandlers

that dumps the list of waiting iohandlers, this is particularly useful for trying to figure out where an incoming migration is blocked. For 'fd_coroutine_enter' cases we dump a full backtrace.

qemu aios
that dumps the qemu_aio_context list.

This is a rewrite of an earlier version prior to Fam's changes to the corresponding structures.

(gdb) qemu aios
----
{pfd = {fd = 12, events = 25, revents = 0}, io_read = 0x5634d4033cc0 <qemu_laio_completion_cb>, io_write = 0x0, deleted = 0, opaque = 0x5634d601e8b8, node = {le_next = 0x5634d5fd2330, le_prev = 0x5634d5fd22a0}}
----
{pfd = {fd = 6, events = 25, revents = 0}, io_read = 0x5634d3ff1750 <event_notifier_dummy_cb>, io_write = 0x0, deleted = 0, opaque = 0x5634d5fd22e8, node = {le_next = 0x0, le_prev = 0x5634d5fe8458}}
----

(gdb) qemu iohandlers
----
{pfd = {fd = 15, events = 25, revents = 0}, io_read = 0x559a843bd850 <fd_coroutine_enter>, io_write = 0x0, deleted = 0, opaque = 0x7fef1c5fed30, node = {le_next = 0x559a84e9d180, le_prev = 0x559a84e9c6b0}}
#0 0x0000559a843bdcf0 in qemu_coroutine_switch (from_=from_@entry=0x559a865fd8e0, to_=to_@entry=0x7fef37774ac8, action=action@entry=COROUTINE_YIELD) at /home/dgilbert/git/qemu-world3/coroutine-ucontext.c:177 #1 0x0000559a843bd0d0 in qemu_coroutine_yield () at /home/dgilbert/git/qemu-world3/qemu-coroutine.c:145
#2 0x0000559a843bd9c5 in yield_until_fd_readable (fd=15) at /home/dgilbert/git/qemu-world3/qemu-coroutine-io.c:90
#3 0x0000559a84362337 in socket_get_buffer (opaque=0x559a862f7a00, buf=0x559a84ea0a70 "", pos=<optimized out>, size=32768) at /home/dgilbert/git/qemu-world3/migration/qemu-file-unix.c:69 #4 0x0000559a84360c9c in qemu_fill_buffer (f=0x559a84ea0a40)

      at /home/dgilbert/git/qemu-world3/migration/qemu-file.c:215
  #5  0x0000559a84361569 in qemu_peek_byte (f=0x559a84ea0a40, offset=0)
      at /home/dgilbert/git/qemu-world3/migration/qemu-file.c:448
  #6  0x0000559a843617d4 in qemu_get_be32 (f=0x559a84ea0a40)
      at /home/dgilbert/git/qemu-world3/migration/qemu-file.c:461
  #7  0x0000559a843617d4 in qemu_get_be32 (f=f@entry=0x559a84ea0a40)
      at /home/dgilbert/git/qemu-world3/migration/qemu-file.c:545
  #8  0x0000559a84187d92 in qemu_loadvm_state (f=f@entry=0x559a84ea0a40)
      at /home/dgilbert/git/qemu-world3/migration/savevm.c:1070
  #9  0x0000559a8435dc42 in process_incoming_migration_co
  (opaque=0x559a84ea0a40)
      at /home/dgilbert/git/qemu-world3/migration/migration.c:285
  #10 0x0000559a843bdd5a in coroutine_trampoline (i0=<optimized out>,
  i1=<optimized out>)
      at /home/dgilbert/git/qemu-world3/coroutine-ucontext.c:80
  #11 0x00007fef2a462f10 in __start_context () at /lib64/libc.so.6
  #12 0x00007fffb7437b50 in  ()
  #13 0x0000000000000000 in  ()
  ----
  {pfd = {fd = 4, events = 25, revents = 0}, io_read = 0x559a843b7800
  <sigfd_handler>, io_write = 0x0, deleted = 0, opaque = 0x4, node =
  {le_next = 0x559a84e9c740, le_prev = 0x559a86325498}}
  ----
  {pfd = {fd = 5, events = 25, revents = 0}, io_read = 0x559a843ac750
  <event_notifier_dummy_cb>, io_write = 0x0, deleted = 0, opaque =
  0x559a84e9c6f8, node = {le_next = 0x0, le_prev = 0x559a84e9d1a8}}
  ----
---
 scripts/qemu-gdb.py    |  4 +++-
 scripts/qemugdb/aio.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 scripts/qemugdb/aio.py
scripts/qemu-gdb.py +3 -1
index d6f2e5a..99344c7 100644
@@ -26,7 +26,7 @@ import os, sys
 
 sys.path.append(os.path.dirname(__file__))
 
-from qemugdb import mtree, coroutine
+from qemugdb import aio, mtree, coroutine
 
 class QemuCommand(gdb.Command):
     '''Prefix for QEMU debug support commands'''
@@ -37,6 +37,8 @@ class QemuCommand(gdb.Command):
 QemuCommand()
 coroutine.CoroutineCommand()
 mtree.MtreeCommand()
+aio.IOhandlersCommand()
+aio.AIOsCommand()
 
 # Default to silently passing through SIGUSR1, because QEMU sends it
 # to itself a lot.
scripts/qemugdb/aio.py new file +52 -0

52 lines not on this page · raw message

Signature · 1 line
2.5.0
#1 lore raw
Quoted 4 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Two new gdb commands are added:

Quoted 8 lines

qemu iohandlers

that dumps the list of waiting iohandlers, this is particularly useful for trying to figure out where an incoming migration is blocked. For 'fd_coroutine_enter' cases we dump a full backtrace.

qemu aios
that dumps the qemu_aio_context list.

I'd assume "qemu aios" is a command to print the list of AioContext instances rather than handlers in a particular context (qemu_aio_context). How about "qemu handlers"?

Quoted 46 lines

This is a rewrite of an earlier version prior to Fam's changes to the corresponding structures.

(gdb) qemu aios
----
{pfd = {fd = 12, events = 25, revents = 0}, io_read = 0x5634d4033cc0 <qemu_laio_completion_cb>, io_write = 0x0, deleted = 0, opaque = 0x5634d601e8b8, node = {le_next = 0x5634d5fd2330, le_prev = 0x5634d5fd22a0}}
----
{pfd = {fd = 6, events = 25, revents = 0}, io_read = 0x5634d3ff1750 <event_notifier_dummy_cb>, io_write = 0x0, deleted = 0, opaque = 0x5634d5fd22e8, node = {le_next = 0x0, le_prev = 0x5634d5fe8458}}
----

(gdb) qemu iohandlers
----
{pfd = {fd = 15, events = 25, revents = 0}, io_read = 0x559a843bd850 <fd_coroutine_enter>, io_write = 0x0, deleted = 0, opaque = 0x7fef1c5fed30, node = {le_next = 0x559a84e9d180, le_prev = 0x559a84e9c6b0}}
#0 0x0000559a843bdcf0 in qemu_coroutine_switch (from_=from_@entry=0x559a865fd8e0, to_=to_@entry=0x7fef37774ac8, action=action@entry=COROUTINE_YIELD) at /home/dgilbert/git/qemu-world3/coroutine-ucontext.c:177 #1 0x0000559a843bd0d0 in qemu_coroutine_yield () at /home/dgilbert/git/qemu-world3/qemu-coroutine.c:145
#2 0x0000559a843bd9c5 in yield_until_fd_readable (fd=15) at /home/dgilbert/git/qemu-world3/qemu-coroutine-io.c:90
#3 0x0000559a84362337 in socket_get_buffer (opaque=0x559a862f7a00, buf=0x559a84ea0a70 "", pos=<optimized out>, size=32768) at /home/dgilbert/git/qemu-world3/migration/qemu-file-unix.c:69 #4 0x0000559a84360c9c in qemu_fill_buffer (f=0x559a84ea0a40)

      at /home/dgilbert/git/qemu-world3/migration/qemu-file.c:215
  #5  0x0000559a84361569 in qemu_peek_byte (f=0x559a84ea0a40, offset=0)
      at /home/dgilbert/git/qemu-world3/migration/qemu-file.c:448
  #6  0x0000559a843617d4 in qemu_get_be32 (f=0x559a84ea0a40)
      at /home/dgilbert/git/qemu-world3/migration/qemu-file.c:461
  #7  0x0000559a843617d4 in qemu_get_be32 (f=f@entry=0x559a84ea0a40)
      at /home/dgilbert/git/qemu-world3/migration/qemu-file.c:545
  #8  0x0000559a84187d92 in qemu_loadvm_state (f=f@entry=0x559a84ea0a40)
      at /home/dgilbert/git/qemu-world3/migration/savevm.c:1070
  #9  0x0000559a8435dc42 in process_incoming_migration_co
Quoted 8 lines
  (opaque=0x559a84ea0a40)
      at /home/dgilbert/git/qemu-world3/migration/migration.c:285
  #10 0x0000559a843bdd5a in coroutine_trampoline (i0=<optimized out>,
  i1=<optimized out>)
      at /home/dgilbert/git/qemu-world3/coroutine-ucontext.c:80
  #11 0x00007fef2a462f10 in __start_context () at /lib64/libc.so.6
  #12 0x00007fffb7437b50 in  ()
  #13 0x0000000000000000 in  ()

This sort of clutters the output, I'm wondering if making the backtrace optional (only dumped when "qemu iohandlers --backtrace") is better? It's OK if you decide to keep this, though.

Quoted 70 lines

----
{pfd = {fd = 4, events = 25, revents = 0}, io_read = 0x559a843b7800 <sigfd_handler>, io_write = 0x0, deleted = 0, opaque = 0x4, node = {le_next = 0x559a84e9c740, le_prev = 0x559a86325498}}
----
{pfd = {fd = 5, events = 25, revents = 0}, io_read = 0x559a843ac750 <event_notifier_dummy_cb>, io_write = 0x0, deleted = 0, opaque = 0x559a84e9c6f8, node = {le_next = 0x0, le_prev = 0x559a84e9d1a8}}
----

---
 scripts/qemu-gdb.py    |  4 +++-
 scripts/qemugdb/aio.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100644 scripts/qemugdb/aio.py
scripts/qemu-gdb.py +3 -1
index d6f2e5a..99344c7 100644
@@ -26,7 +26,7 @@ import os, sys
 
 sys.path.append(os.path.dirname(__file__))
 
-from qemugdb import mtree, coroutine
+from qemugdb import aio, mtree, coroutine
 
 class QemuCommand(gdb.Command):
     '''Prefix for QEMU debug support commands'''
@@ -37,6 +37,8 @@ class QemuCommand(gdb.Command):
 QemuCommand()
 coroutine.CoroutineCommand()
 mtree.MtreeCommand()
+aio.IOhandlersCommand()
+aio.AIOsCommand()
 
 # Default to silently passing through SIGUSR1, because QEMU sends it
 # to itself a lot.
scripts/qemugdb/aio.py new file +27 -0
new file mode 100644
index 0000000..cda2c37
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+
+# GDB debugging support: aio/iohandler debug
+#
+# Copyright (c) 2015 Red Hat, Inc.
+#
+# Author: Dr. David Alan Gilbert <[email protected]>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or
+# later.  See the COPYING file in the top-level directory.
+#
+
+import gdb
+from qemugdb import coroutine
+
+def isnull(ptr):
+    return ptr == gdb.Value(0).cast(ptr.type)
+
+def dump_aiocontext(context):
+    '''Display a dump and backtrace for an aiocontext'''
+    cur = context['aio_handlers']['lh_first']
+    # Get pointers to functions we're going to process specially
+    sym_fd_coroutine_enter = gdb.parse_and_eval('fd_coroutine_enter')
+
+    while not isnull(cur):
+        entry = cur.dereference()
+        gdb.write('----\n%s\n' % entry)

scripts/qemugdb/aio.py line 37

Quoted 10 lines
scripts/qemugdb/aio.py new file +10 -0
+        if cur['io_read'] == sym_fd_coroutine_enter:
+            coptr = (cur['opaque'].cast(gdb.lookup_type('FDYieldUntilData').pointer()))['co']
+            coptr = coptr.cast(gdb.lookup_type('CoroutineUContext').pointer())
+            coroutine.bt_jmpbuf(coptr['env']['__jmpbuf'])
+        cur = cur['node']['le_next'];
+
+    gdb.write('----\n')
+
+class AIOsCommand(gdb.Command):
+    '''Display aio handlers'''

Maybe also

s/aio handlers/aio handlers in main loop/

?

Quoted 18 lines
scripts/qemugdb/aio.py new file +15 -0
+    def __init__(self):
+        gdb.Command.__init__(self, 'qemu aios', gdb.COMMAND_DATA,
+                             gdb.COMPLETE_NONE)
+
+    def invoke(self, arg, from_tty):
+        dump_aiocontext(gdb.parse_and_eval('qemu_aio_context'))
+
+class IOhandlersCommand(gdb.Command):
+    '''Display io handlers'''
+    def __init__(self):
+        gdb.Command.__init__(self, 'qemu iohandlers', gdb.COMMAND_DATA,
+                             gdb.COMPLETE_NONE)
+
+    def invoke(self, arg, from_tty):
+        dump_aiocontext(gdb.parse_and_eval('iohandler_ctx'))
Signature · 1 line
2.5.0
#2 lore raw
Quoted 11 lines · Fam Zheng
Quoted 10 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Two new gdb commands are added:

qemu iohandlers

that dumps the list of waiting iohandlers, this is particularly useful for trying to figure out where an incoming migration is blocked. For 'fd_coroutine_enter' cases we dump a full backtrace.

Quoted 6 lines
Quoted 2 lines

qemu aios
that dumps the qemu_aio_context list.

I'd assume "qemu aios" is a command to print the list of AioContext instances rather than handlers in a particular context (qemu_aio_context). How about "qemu handlers"?

Seems fine to me but it would be useful to add an optional AioContext pointer argument.

That way the command prints qemu_aio_context by default but can also be used to inspect arbitrary AioContexts.

Stefan

#3 lore raw
Quoted 19 lines · Stefan Hajnoczi
Quoted 11 lines · Fam Zheng
Quoted 10 lines · Dr. David Alan Gilbert (git)

From: "Dr. David Alan Gilbert" <[email protected]>

Two new gdb commands are added:

qemu iohandlers

that dumps the list of waiting iohandlers, this is particularly useful for trying to figure out where an incoming migration is blocked. For 'fd_coroutine_enter' cases we dump a full backtrace.

Quoted 6 lines
Quoted 2 lines

qemu aios
that dumps the qemu_aio_context list.

I'd assume "qemu aios" is a command to print the list of AioContext instances rather than handlers in a particular context (qemu_aio_context). How about "qemu handlers"?

Quoted 6 lines

Seems fine to me but it would be useful to add an optional AioContext pointer argument.

That way the command prints qemu_aio_context by default but can also be used to inspect arbitrary AioContexts.

That is a good idea.

Fam

#4 lore raw
In reply to Dr. David Alan Gilbert (git)

scripts/qemugdb/aio.py line 31

Quoted 6 lines · Dr. David Alan Gilbert (git)
scripts/qemugdb/aio.py new file +6 -0
+        entry = cur.dereference()
+        gdb.write('----\n%s\n' % entry)
+        if cur['io_read'] == sym_fd_coroutine_enter:
+            coptr = (cur['opaque'].cast(gdb.lookup_type('FDYieldUntilData').pointer()))['co']
+            coptr = coptr.cast(gdb.lookup_type('CoroutineUContext').pointer())
+            coroutine.bt_jmpbuf(coptr['env']['__jmpbuf'])

The last two lines here can be written as

coroutine.bt_jmpbuf(coroutine.coroutine_to_jmpbuf(coptr))

with the head of Stefan's trace branch.

Paolo

#5 lore raw
Quoted 10 lines · * Paolo Bonzini ([email protected]) wrote:

scripts/qemugdb/aio.py line 31

Quoted 6 lines · Dr. David Alan Gilbert (git)
scripts/qemugdb/aio.py new file +6 -0
+        entry = cur.dereference()
+        gdb.write('----\n%s\n' % entry)
+        if cur['io_read'] == sym_fd_coroutine_enter:
+            coptr = (cur['opaque'].cast(gdb.lookup_type('FDYieldUntilData').pointer()))['co']
+            coptr = coptr.cast(gdb.lookup_type('CoroutineUContext').pointer())
+            coroutine.bt_jmpbuf(coptr['env']['__jmpbuf'])
Quoted 5 lines

The last two lines here can be written as

coroutine.bt_jmpbuf(coroutine.coroutine_to_jmpbuf(coptr))

with the head of Stefan's trace branch.

I've just posted a new version with all the other changes in, but I can easily change that one when the trace change lands.

Dave

Quoted 2 lines

Paolo

--
Dr. David Alan Gilbert / [email protected] / Manchester, UK