[libvirt] [PATCH v4 0/2] qemu: add debug-threads support

QEMU (somewhere around 2.0) added a new sub-option to the -name flag -name debug-threads=on This causes the naming of individual QEMU threads to be helpful; e.g. 'CPU/KVM 0' or 'migration' these show up in top once the H key is pressed, and also show up in a core dump, making it easy to figure out which thread is which. The following 2 patches add a capability check and enable debug-threads if supported. Related to: https://bugzilla.redhat.com/show_bug.cgi?id=1140121 cheers v3->v4: - simplify a bit command generation - added a test v2->v3: - move -name command generation in seperate function - fix syntax-check - fix leak v1->v2: - drop the configuration, enable debug-thread automatically Marc-André Lureau (2): qemu: check for debug-threads capability qemu: enable debug threads src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 34 +++++++++++++++++----- tests/qemucapabilitiesdata/caps_2.1.1-1.caps | 1 + tests/qemucapabilitiesdata/caps_2.4.0-1.caps | 1 + tests/qemucapabilitiesdata/caps_2.5.0-1.caps | 1 + tests/qemucapabilitiesdata/caps_2.6.0-1.caps | 1 + .../qemuxml2argv-debug-threads.args | 22 ++++++++++++++ .../qemuxml2argv-debug-threads.xml | 34 ++++++++++++++++++++++ tests/qemuxml2argvtest.c | 2 ++ 10 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-debug-threads.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-debug-threads.xml -- 2.5.0

From: Marc-André Lureau <marcandre.lureau@gmail.com> QEMU (somewhere around 2.0) added a new sub-option to the -name flag -name debug-threads=on. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + tests/qemucapabilitiesdata/caps_2.1.1-1.caps | 1 + tests/qemucapabilitiesdata/caps_2.4.0-1.caps | 1 + tests/qemucapabilitiesdata/caps_2.5.0-1.caps | 1 + tests/qemucapabilitiesdata/caps_2.6.0-1.caps | 1 + 6 files changed, 7 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index fce79f8..403d872 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -320,6 +320,7 @@ VIR_ENUM_IMPL(virQEMUCaps, QEMU_CAPS_LAST, "qxl-vga.vram64_size_mb", /* 215 */ "chardev-logfile", + "debug-threads", ); @@ -2636,6 +2637,7 @@ static struct virQEMUCapsCommandLineProps virQEMUCapsCommandLine[] = { { "chardev", "append", QEMU_CAPS_CHARDEV_FILE_APPEND }, { "spice", "gl", QEMU_CAPS_SPICE_GL }, { "chardev", "logfile", QEMU_CAPS_CHARDEV_LOGFILE }, + { "name", "debug-threads", QEMU_CAPS_NAME_DEBUG_THREADS }, }; static int diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index af8d15b..01ceb8e 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -350,6 +350,7 @@ typedef enum { /* 215 */ QEMU_CAPS_QXL_VGA_VRAM64, /* -device qxl-vga.vram64_size_mb */ QEMU_CAPS_CHARDEV_LOGFILE, /* -chardev logfile=xxxx */ + QEMU_CAPS_NAME_DEBUG_THREADS, /* Is -name debug-threads= available */ QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/tests/qemucapabilitiesdata/caps_2.1.1-1.caps b/tests/qemucapabilitiesdata/caps_2.1.1-1.caps index fd2639d..59d0323 100644 --- a/tests/qemucapabilitiesdata/caps_2.1.1-1.caps +++ b/tests/qemucapabilitiesdata/caps_2.1.1-1.caps @@ -162,4 +162,5 @@ <flag name='vserport-change-event'/> <flag name='qxl.vram64_size_mb'/> <flag name='qxl-vga.vram64_size_mb'/> + <flag name='debug-threads'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_2.4.0-1.caps b/tests/qemucapabilitiesdata/caps_2.4.0-1.caps index 4b61fc1..efbf9af 100644 --- a/tests/qemucapabilitiesdata/caps_2.4.0-1.caps +++ b/tests/qemucapabilitiesdata/caps_2.4.0-1.caps @@ -173,4 +173,5 @@ <flag name='virtio-balloon-pci.deflate-on-oom'/> <flag name='qxl.vram64_size_mb'/> <flag name='qxl-vga.vram64_size_mb'/> + <flag name='debug-threads'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_2.5.0-1.caps b/tests/qemucapabilitiesdata/caps_2.5.0-1.caps index 2061d0e..5fd3bce 100644 --- a/tests/qemucapabilitiesdata/caps_2.5.0-1.caps +++ b/tests/qemucapabilitiesdata/caps_2.5.0-1.caps @@ -174,4 +174,5 @@ <flag name='virtio-balloon-pci.deflate-on-oom'/> <flag name='qxl.vram64_size_mb'/> <flag name='qxl-vga.vram64_size_mb'/> + <flag name='debug-threads'/> </qemuCaps> diff --git a/tests/qemucapabilitiesdata/caps_2.6.0-1.caps b/tests/qemucapabilitiesdata/caps_2.6.0-1.caps index 8374cda..549759c 100644 --- a/tests/qemucapabilitiesdata/caps_2.6.0-1.caps +++ b/tests/qemucapabilitiesdata/caps_2.6.0-1.caps @@ -177,4 +177,5 @@ <flag name='spice-gl'/> <flag name='qxl.vram64_size_mb'/> <flag name='qxl-vga.vram64_size_mb'/> + <flag name='debug-threads'/> </qemuCaps> -- 2.5.0

When debug-threads is enabled, individual threads are given a separate name (on Linux) Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1140121 Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> --- src/qemu/qemu_command.c | 34 +++++++++++++++++----- .../qemuxml2argv-debug-threads.args | 22 ++++++++++++++ .../qemuxml2argv-debug-threads.xml | 34 ++++++++++++++++++++++ tests/qemuxml2argvtest.c | 2 ++ 4 files changed, 84 insertions(+), 8 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-debug-threads.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-debug-threads.xml diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index ee06479..bf39a45 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5333,6 +5333,30 @@ qemuAppendKeyWrapMachineParms(virBuffer *buf, virQEMUCapsPtr qemuCaps, } static int +qemuBuildNameCommandLine(virCommandPtr cmd, + virQEMUDriverConfigPtr cfg, + const virDomainDef *def, + virQEMUCapsPtr qemuCaps) +{ + virBuffer buf = VIR_BUFFER_INITIALIZER; + + virCommandAddArg(cmd, "-name"); + + virBufferAsprintf(&buf, "%s", def->name); + + if (cfg->setProcessName && + virQEMUCapsGet(qemuCaps, QEMU_CAPS_NAME_PROCESS)) + virBufferAsprintf(&buf, ",process=qemu:%s", def->name); + + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_NAME_DEBUG_THREADS)) + virBufferAddLit(&buf, ",debug-threads=on"); + + virCommandAddArgBuffer(cmd, &buf); + + return 0; +} + +static int qemuBuildMachineCommandLine(virCommandPtr cmd, const virDomainDef *def, virQEMUCapsPtr qemuCaps) @@ -7192,14 +7216,8 @@ qemuBuildCommandLine(virConnectPtr conn, virCommandAddEnvPassCommon(cmd); - virCommandAddArg(cmd, "-name"); - if (cfg->setProcessName && - virQEMUCapsGet(qemuCaps, QEMU_CAPS_NAME_PROCESS)) { - virCommandAddArgFormat(cmd, "%s,process=qemu:%s", - def->name, def->name); - } else { - virCommandAddArg(cmd, def->name); - } + if (qemuBuildNameCommandLine(cmd, cfg, def, qemuCaps) < 0) + goto error; if (!standalone) virCommandAddArg(cmd, "-S"); /* freeze CPU */ diff --git a/tests/qemuxml2argvdata/qemuxml2argv-debug-threads.args b/tests/qemuxml2argvdata/qemuxml2argv-debug-threads.args new file mode 100644 index 0000000..2ad6fcf --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-debug-threads.args @@ -0,0 +1,22 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/home/test \ +USER=test \ +LOGNAME=test \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu \ +-name QEMUGuest1,debug-threads=on \ +-S \ +-M pc \ +-m 214 \ +-smp 1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-nographic \ +-nodefaults \ +-monitor unix:/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server,nowait \ +-no-acpi \ +-boot c \ +-usb \ +-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \ +-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-debug-threads.xml b/tests/qemuxml2argvdata/qemuxml2argv-debug-threads.xml new file mode 100644 index 0000000..bfdd1aa --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-debug-threads.xml @@ -0,0 +1,34 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <title>A description of the test machine.</title> + <description> + A test of qemu's minimal configuration. + This test also tests the description and title elements. + </description> + <memory unit='KiB'>219100</memory> + <currentMemory unit='KiB'>219100</currentMemory> + <vcpu placement='static' cpuset='1-4,8-20,525'>1</vcpu> + <os> + <type arch='i686' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu</emulator> + <disk type='block' device='disk'> + <source dev='/dev/HostVG/QEMUGuest1'/> + <target dev='hda' bus='ide'/> + <address type='drive' controller='0' bus='0' target='0' unit='0'/> + </disk> + <controller type='usb' index='0'/> + <controller type='ide' index='0'/> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 4f6291d..e15da37 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1893,6 +1893,8 @@ mymain(void) VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS, NONE); + DO_TEST("debug-threads", QEMU_CAPS_NAME_DEBUG_THREADS); + qemuTestDriverFree(&driver); return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; -- 2.5.0

On 03/10/2016 02:46 PM, Marc-André Lureau wrote:
QEMU (somewhere around 2.0) added a new sub-option to the -name flag -name debug-threads=on
This causes the naming of individual QEMU threads to be helpful; e.g. 'CPU/KVM 0' or 'migration' these show up in top once the H key is pressed, and also show up in a core dump, making it easy to figure out which thread is which.
The following 2 patches add a capability check and enable debug-threads if supported.
Related to: https://bugzilla.redhat.com/show_bug.cgi?id=1140121
cheers
v3->v4: - simplify a bit command generation - added a test
v2->v3: - move -name command generation in seperate function - fix syntax-check - fix leak
v1->v2: - drop the configuration, enable debug-thread automatically
Marc-André Lureau (2): qemu: check for debug-threads capability qemu: enable debug threads
src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 34 +++++++++++++++++----- tests/qemucapabilitiesdata/caps_2.1.1-1.caps | 1 + tests/qemucapabilitiesdata/caps_2.4.0-1.caps | 1 + tests/qemucapabilitiesdata/caps_2.5.0-1.caps | 1 + tests/qemucapabilitiesdata/caps_2.6.0-1.caps | 1 + .../qemuxml2argv-debug-threads.args | 22 ++++++++++++++ .../qemuxml2argv-debug-threads.xml | 34 ++++++++++++++++++++++ tests/qemuxml2argvtest.c | 2 ++ 10 files changed, 91 insertions(+), 8 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-debug-threads.args create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-debug-threads.xml
ACK series - Cole

On Thu, Mar 10, 2016 at 16:05:32 -0500, Cole Robinson wrote:
On 03/10/2016 02:46 PM, Marc-André Lureau wrote:
QEMU (somewhere around 2.0) added a new sub-option to the -name flag -name debug-threads=on
This causes the naming of individual QEMU threads to be helpful; e.g. 'CPU/KVM 0' or 'migration' these show up in top once the H key is pressed, and also show up in a core dump, making it easy to figure out which thread is which.
The following 2 patches add a capability check and enable debug-threads if supported.
Related to: https://bugzilla.redhat.com/show_bug.cgi?id=1140121
cheers
v3->v4: - simplify a bit command generation - added a test
v2->v3: - move -name command generation in seperate function - fix syntax-check - fix leak
v1->v2: - drop the configuration, enable debug-thread automatically
Marc-André Lureau (2): qemu: check for debug-threads capability qemu: enable debug threads
ACK series
I pushed both patches. Jirka
participants (3)
-
Cole Robinson
-
Jiri Denemark
-
Marc-André Lureau