Initial conversion of HMP debugging commands to QMP
This introduces a new policy that all HMP commands will be converted to have QMP equivalents, marked unstable if no formal QAPI modelling is intended to be done. New unstable commands are added as follows: - HMP "info roms" => QMP "x-query-roms" - HMP "info profile" => QMP "x-query-profile" - HMP "info numa" => QMP "x-query-numa" - HMP "info usb" => QMP "x-query-usb" - HMP "info rdma" => QMP "x-query-rdma" - HMP "info ramblock" => QMP "x-query-ramblock" - HMP "info irq" => QMP "x-query-irq" - HMP "info jit" => QMP "x-query-jit" - HMP "info opcount" => QMP "x-query-opcount" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEE2vOm/bJrYpEtDo4/vobrtBUQT98FAmGBe1QACgkQvobrtBUQ T9+8XA/9Ex3VtJZpW3FEgk29hvCXxBqM7S6vMpJ+BoySzjf9zeN1b7DJx4uE7urI GeIB8x9gtwdlin2E7lFZPG0nzJ35YFctsPjWIn2Nm/i5uIYz68R+SwugJJ7z26Ep kn2eN814vONTUk0KL6e4+XQ+LkKI26o2R0mAEy+iWOB3lazCkalHY6u/Z/D5Xcqp aRBn/VIWnH4LyIGj9vJuc74nsfo6IbaxFQWnXCjgw7NUVHC33q6R+gXKenf5dXL6 FhGRV8G6JVMIhRmp8n8BNQiysBLcve7r9LOeSlUMYwDMqBreeS7rNwd5jPoXu4v/ KfYtqQaXV+YhqEoUR3AWBq0Legz2P2gEDxDg+QMIqb+5kX0+tg2/vTvRNsrhnpIm d+9TBqZ8BtJEIyz8MJ/R4G6a7Ytx6cyjLPL0CjswD/0Jsg7XWzyIpcUtJ5OH+tT3 24NB/Aq++iSReAT53TmypAuijL5kNioB00A+RR0hW5ZPuAiqZzXAXoECOxjNSLOC 9IBWugug3W7vj3HJIEgDGjFNWcdP0KmCL6dkiWjEfWThDeG39ApQmCL+FlKNRKdC 7EPcuu3G7Yl8dkG4kmpwR9zCC4fin9TxJajagUlJyJkl/EpbWeebswh175kREnRE 46CdCRcVTJ4HLbRzWlUkZAtmfzFKKvjQTcmH3cTlgH6vWpfCNCY= =AQdc -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/berrange/tags/hmp-x-qmp-620-pull-request' into staging Initial conversion of HMP debugging commands to QMP This introduces a new policy that all HMP commands will be converted to have QMP equivalents, marked unstable if no formal QAPI modelling is intended to be done. New unstable commands are added as follows: - HMP "info roms" => QMP "x-query-roms" - HMP "info profile" => QMP "x-query-profile" - HMP "info numa" => QMP "x-query-numa" - HMP "info usb" => QMP "x-query-usb" - HMP "info rdma" => QMP "x-query-rdma" - HMP "info ramblock" => QMP "x-query-ramblock" - HMP "info irq" => QMP "x-query-irq" - HMP "info jit" => QMP "x-query-jit" - HMP "info opcount" => QMP "x-query-opcount" # gpg: Signature made Tue 02 Nov 2021 01:54:28 PM EDT # gpg: using RSA key DAF3A6FDB26B62912D0E8E3FBE86EBB415104FDF # gpg: Good signature from "Daniel P. Berrange <dan@berrange.com>" [full] # gpg: aka "Daniel P. Berrange <berrange@redhat.com>" [full] * remotes/berrange/tags/hmp-x-qmp-620-pull-request: qapi: introduce x-query-opcount QMP command qapi: introduce x-query-jit QMP command qapi: introduce x-query-irq QMP command qapi: introduce x-query-ramblock QMP command qapi: introduce x-query-rdma QMP command qapi: introduce x-query-usb QMP command qapi: introduce x-query-numa QMP command qapi: introduce x-query-profile QMP command qapi: introduce x-query-roms QMP command docs/devel: document expectations for HMP commands in the future docs/devel: add example of command returning unstructured text docs/devel: document expectations for QAPI data modelling for QMP monitor: introduce HumanReadableText and HMP support docs/devel: update error handling guidance for HMP commands docs/devel: tweak headings in monitor command docs docs/devel: rename file for writing monitor commands monitor: make hmp_handle_error return a boolean monitor: remove 'info ioapic' HMP command Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
commit
e86e00a249
@ -20,6 +20,9 @@
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu-common.h"
|
||||
#include "qemu/qemu-print.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qapi-commands-machine.h"
|
||||
#include "qapi/type-helpers.h"
|
||||
#include "hw/core/tcg-cpu-ops.h"
|
||||
#include "trace.h"
|
||||
#include "disas/disas.h"
|
||||
@ -38,6 +41,7 @@
|
||||
#include "exec/cpu-all.h"
|
||||
#include "sysemu/cpu-timers.h"
|
||||
#include "sysemu/replay.h"
|
||||
#include "sysemu/tcg.h"
|
||||
#include "exec/helper-proto.h"
|
||||
#include "tb-hash.h"
|
||||
#include "tb-context.h"
|
||||
@ -1029,23 +1033,52 @@ void tcg_exec_unrealizefn(CPUState *cpu)
|
||||
|
||||
#ifndef CONFIG_USER_ONLY
|
||||
|
||||
void dump_drift_info(void)
|
||||
void dump_drift_info(GString *buf)
|
||||
{
|
||||
if (!icount_enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
qemu_printf("Host - Guest clock %"PRIi64" ms\n",
|
||||
g_string_append_printf(buf, "Host - Guest clock %"PRIi64" ms\n",
|
||||
(cpu_get_clock() - icount_get()) / SCALE_MS);
|
||||
if (icount_align_option) {
|
||||
qemu_printf("Max guest delay %"PRIi64" ms\n",
|
||||
g_string_append_printf(buf, "Max guest delay %"PRIi64" ms\n",
|
||||
-max_delay / SCALE_MS);
|
||||
qemu_printf("Max guest advance %"PRIi64" ms\n",
|
||||
g_string_append_printf(buf, "Max guest advance %"PRIi64" ms\n",
|
||||
max_advance / SCALE_MS);
|
||||
} else {
|
||||
qemu_printf("Max guest delay NA\n");
|
||||
qemu_printf("Max guest advance NA\n");
|
||||
g_string_append_printf(buf, "Max guest delay NA\n");
|
||||
g_string_append_printf(buf, "Max guest advance NA\n");
|
||||
}
|
||||
}
|
||||
|
||||
HumanReadableText *qmp_x_query_jit(Error **errp)
|
||||
{
|
||||
g_autoptr(GString) buf = g_string_new("");
|
||||
|
||||
if (!tcg_enabled()) {
|
||||
error_setg(errp, "JIT information is only available with accel=tcg");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dump_exec_info(buf);
|
||||
dump_drift_info(buf);
|
||||
|
||||
return human_readable_text_from_str(buf);
|
||||
}
|
||||
|
||||
HumanReadableText *qmp_x_query_opcount(Error **errp)
|
||||
{
|
||||
g_autoptr(GString) buf = g_string_new("");
|
||||
|
||||
if (!tcg_enabled()) {
|
||||
error_setg(errp, "Opcode count information is only available with accel=tcg");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dump_opcount_info(buf);
|
||||
|
||||
return human_readable_text_from_str(buf);
|
||||
}
|
||||
|
||||
#endif /* !CONFIG_USER_ONLY */
|
||||
|
@ -1,29 +1,15 @@
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qapi-commands-machine.h"
|
||||
#include "exec/exec-all.h"
|
||||
#include "monitor/monitor.h"
|
||||
#include "sysemu/tcg.h"
|
||||
|
||||
static void hmp_info_jit(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
if (!tcg_enabled()) {
|
||||
error_report("JIT information is only available with accel=tcg");
|
||||
return;
|
||||
}
|
||||
|
||||
dump_exec_info();
|
||||
dump_drift_info();
|
||||
}
|
||||
|
||||
static void hmp_info_opcount(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
dump_opcount_info();
|
||||
}
|
||||
|
||||
static void hmp_tcg_register(void)
|
||||
{
|
||||
monitor_register_hmp("jit", true, hmp_info_jit);
|
||||
monitor_register_hmp("opcount", true, hmp_info_opcount);
|
||||
monitor_register_hmp_info_hrt("jit", qmp_x_query_jit);
|
||||
monitor_register_hmp_info_hrt("opcount", qmp_x_query_opcount);
|
||||
}
|
||||
|
||||
type_init(hmp_tcg_register);
|
||||
|
@ -1991,7 +1991,7 @@ void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr)
|
||||
cpu_loop_exit_noexc(cpu);
|
||||
}
|
||||
|
||||
static void print_qht_statistics(struct qht_stats hst)
|
||||
static void print_qht_statistics(struct qht_stats hst, GString *buf)
|
||||
{
|
||||
uint32_t hgram_opts;
|
||||
size_t hgram_bins;
|
||||
@ -2000,9 +2000,11 @@ static void print_qht_statistics(struct qht_stats hst)
|
||||
if (!hst.head_buckets) {
|
||||
return;
|
||||
}
|
||||
qemu_printf("TB hash buckets %zu/%zu (%0.2f%% head buckets used)\n",
|
||||
g_string_append_printf(buf, "TB hash buckets %zu/%zu "
|
||||
"(%0.2f%% head buckets used)\n",
|
||||
hst.used_head_buckets, hst.head_buckets,
|
||||
(double)hst.used_head_buckets / hst.head_buckets * 100);
|
||||
(double)hst.used_head_buckets /
|
||||
hst.head_buckets * 100);
|
||||
|
||||
hgram_opts = QDIST_PR_BORDER | QDIST_PR_LABELS;
|
||||
hgram_opts |= QDIST_PR_100X | QDIST_PR_PERCENT;
|
||||
@ -2010,7 +2012,8 @@ static void print_qht_statistics(struct qht_stats hst)
|
||||
hgram_opts |= QDIST_PR_NODECIMAL;
|
||||
}
|
||||
hgram = qdist_pr(&hst.occupancy, 10, hgram_opts);
|
||||
qemu_printf("TB hash occupancy %0.2f%% avg chain occ. Histogram: %s\n",
|
||||
g_string_append_printf(buf, "TB hash occupancy %0.2f%% avg chain occ. "
|
||||
"Histogram: %s\n",
|
||||
qdist_avg(&hst.occupancy) * 100, hgram);
|
||||
g_free(hgram);
|
||||
|
||||
@ -2023,7 +2026,8 @@ static void print_qht_statistics(struct qht_stats hst)
|
||||
hgram_opts |= QDIST_PR_NODECIMAL | QDIST_PR_NOBINRANGE;
|
||||
}
|
||||
hgram = qdist_pr(&hst.chain, hgram_bins, hgram_opts);
|
||||
qemu_printf("TB hash avg chain %0.3f buckets. Histogram: %s\n",
|
||||
g_string_append_printf(buf, "TB hash avg chain %0.3f buckets. "
|
||||
"Histogram: %s\n",
|
||||
qdist_avg(&hst.chain), hgram);
|
||||
g_free(hgram);
|
||||
}
|
||||
@ -2061,7 +2065,7 @@ static gboolean tb_tree_stats_iter(gpointer key, gpointer value, gpointer data)
|
||||
return false;
|
||||
}
|
||||
|
||||
void dump_exec_info(void)
|
||||
void dump_exec_info(GString *buf)
|
||||
{
|
||||
struct tb_tree_stats tst = {};
|
||||
struct qht_stats hst;
|
||||
@ -2070,49 +2074,53 @@ void dump_exec_info(void)
|
||||
tcg_tb_foreach(tb_tree_stats_iter, &tst);
|
||||
nb_tbs = tst.nb_tbs;
|
||||
/* XXX: avoid using doubles ? */
|
||||
qemu_printf("Translation buffer state:\n");
|
||||
g_string_append_printf(buf, "Translation buffer state:\n");
|
||||
/*
|
||||
* Report total code size including the padding and TB structs;
|
||||
* otherwise users might think "-accel tcg,tb-size" is not honoured.
|
||||
* For avg host size we use the precise numbers from tb_tree_stats though.
|
||||
*/
|
||||
qemu_printf("gen code size %zu/%zu\n",
|
||||
g_string_append_printf(buf, "gen code size %zu/%zu\n",
|
||||
tcg_code_size(), tcg_code_capacity());
|
||||
qemu_printf("TB count %zu\n", nb_tbs);
|
||||
qemu_printf("TB avg target size %zu max=%zu bytes\n",
|
||||
g_string_append_printf(buf, "TB count %zu\n", nb_tbs);
|
||||
g_string_append_printf(buf, "TB avg target size %zu max=%zu bytes\n",
|
||||
nb_tbs ? tst.target_size / nb_tbs : 0,
|
||||
tst.max_target_size);
|
||||
qemu_printf("TB avg host size %zu bytes (expansion ratio: %0.1f)\n",
|
||||
g_string_append_printf(buf, "TB avg host size %zu bytes "
|
||||
"(expansion ratio: %0.1f)\n",
|
||||
nb_tbs ? tst.host_size / nb_tbs : 0,
|
||||
tst.target_size ? (double)tst.host_size / tst.target_size : 0);
|
||||
qemu_printf("cross page TB count %zu (%zu%%)\n", tst.cross_page,
|
||||
tst.target_size ?
|
||||
(double)tst.host_size / tst.target_size : 0);
|
||||
g_string_append_printf(buf, "cross page TB count %zu (%zu%%)\n",
|
||||
tst.cross_page,
|
||||
nb_tbs ? (tst.cross_page * 100) / nb_tbs : 0);
|
||||
qemu_printf("direct jump count %zu (%zu%%) (2 jumps=%zu %zu%%)\n",
|
||||
g_string_append_printf(buf, "direct jump count %zu (%zu%%) "
|
||||
"(2 jumps=%zu %zu%%)\n",
|
||||
tst.direct_jmp_count,
|
||||
nb_tbs ? (tst.direct_jmp_count * 100) / nb_tbs : 0,
|
||||
tst.direct_jmp2_count,
|
||||
nb_tbs ? (tst.direct_jmp2_count * 100) / nb_tbs : 0);
|
||||
|
||||
qht_statistics_init(&tb_ctx.htable, &hst);
|
||||
print_qht_statistics(hst);
|
||||
print_qht_statistics(hst, buf);
|
||||
qht_statistics_destroy(&hst);
|
||||
|
||||
qemu_printf("\nStatistics:\n");
|
||||
qemu_printf("TB flush count %u\n",
|
||||
g_string_append_printf(buf, "\nStatistics:\n");
|
||||
g_string_append_printf(buf, "TB flush count %u\n",
|
||||
qatomic_read(&tb_ctx.tb_flush_count));
|
||||
qemu_printf("TB invalidate count %u\n",
|
||||
g_string_append_printf(buf, "TB invalidate count %u\n",
|
||||
qatomic_read(&tb_ctx.tb_phys_invalidate_count));
|
||||
|
||||
tlb_flush_counts(&flush_full, &flush_part, &flush_elide);
|
||||
qemu_printf("TLB full flushes %zu\n", flush_full);
|
||||
qemu_printf("TLB partial flushes %zu\n", flush_part);
|
||||
qemu_printf("TLB elided flushes %zu\n", flush_elide);
|
||||
tcg_dump_info();
|
||||
g_string_append_printf(buf, "TLB full flushes %zu\n", flush_full);
|
||||
g_string_append_printf(buf, "TLB partial flushes %zu\n", flush_part);
|
||||
g_string_append_printf(buf, "TLB elided flushes %zu\n", flush_elide);
|
||||
tcg_dump_info(buf);
|
||||
}
|
||||
|
||||
void dump_opcount_info(void)
|
||||
void dump_opcount_info(GString *buf)
|
||||
{
|
||||
tcg_dump_op_count();
|
||||
tcg_dump_op_count(buf);
|
||||
}
|
||||
|
||||
#else /* CONFIG_USER_ONLY */
|
||||
|
@ -44,4 +44,4 @@ modifying QEMU's source code.
|
||||
ebpf_rss
|
||||
vfio-migration
|
||||
qapi-code-gen
|
||||
writing-qmp-commands
|
||||
writing-monitor-commands
|
||||
|
@ -1,8 +1,8 @@
|
||||
How to write QMP commands using the QAPI framework
|
||||
==================================================
|
||||
How to write monitor commands
|
||||
=============================
|
||||
|
||||
This document is a step-by-step guide on how to write new QMP commands using
|
||||
the QAPI framework. It also shows how to implement new style HMP commands.
|
||||
the QAPI framework and HMP commands.
|
||||
|
||||
This document doesn't discuss QMP protocol level details, nor does it dive
|
||||
into the QAPI framework implementation.
|
||||
@ -11,6 +11,14 @@ For an in-depth introduction to the QAPI framework, please refer to
|
||||
docs/devel/qapi-code-gen.txt. For documentation about the QMP protocol,
|
||||
start with docs/interop/qmp-intro.txt.
|
||||
|
||||
New commands may be implemented in QMP only. New HMP commands should be
|
||||
implemented on top of QMP. The typical HMP command wraps around an
|
||||
equivalent QMP command, but HMP convenience commands built from QMP
|
||||
building blocks are also fine. The long term goal is to make all
|
||||
existing HMP commands conform to this, to fully isolate HMP from the
|
||||
internals of QEMU. Refer to the `Writing a debugging aid returning
|
||||
unstructured text`_ section for further guidance on commands that
|
||||
would have traditionally been HMP only.
|
||||
|
||||
Overview
|
||||
--------
|
||||
@ -85,8 +93,8 @@ any data". Now you're ready to enter the QMP example commands as explained in
|
||||
the following sections.
|
||||
|
||||
|
||||
Writing a command that doesn't return data
|
||||
------------------------------------------
|
||||
Writing a simple command: hello-world
|
||||
-------------------------------------
|
||||
|
||||
That's the most simple QMP command that can be written. Usually, this kind of
|
||||
command carries some meaningful action in QEMU but here it will just print
|
||||
@ -293,9 +301,7 @@ Here's the implementation of the "hello-world" HMP command::
|
||||
Error *err = NULL;
|
||||
|
||||
qmp_hello_world(!!message, message, &err);
|
||||
if (err) {
|
||||
monitor_printf(mon, "%s\n", error_get_pretty(err));
|
||||
error_free(err);
|
||||
if (hmp_handle_error(mon, err)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -307,9 +313,10 @@ There are three important points to be noticed:
|
||||
1. The "mon" and "qdict" arguments are mandatory for all HMP functions. The
|
||||
former is the monitor object. The latter is how the monitor passes
|
||||
arguments entered by the user to the command implementation
|
||||
2. hmp_hello_world() performs error checking. In this example we just print
|
||||
the error description to the user, but we could do more, like taking
|
||||
different actions depending on the error qmp_hello_world() returns
|
||||
2. hmp_hello_world() performs error checking. In this example we just call
|
||||
hmp_handle_error() which prints a message to the user, but we could do
|
||||
more, like taking different actions depending on the error
|
||||
qmp_hello_world() returns
|
||||
3. The "err" variable must be initialized to NULL before performing the
|
||||
QMP call
|
||||
|
||||
@ -340,8 +347,8 @@ Please, check the "-monitor" command-line option to know how to open a user
|
||||
monitor.
|
||||
|
||||
|
||||
Writing a command that returns data
|
||||
-----------------------------------
|
||||
Writing more complex commands
|
||||
-----------------------------
|
||||
|
||||
A QMP command is capable of returning any data the QAPI supports like integers,
|
||||
strings, booleans, enumerations and user defined types.
|
||||
@ -350,6 +357,35 @@ In this section we will focus on user defined types. Please, check the QAPI
|
||||
documentation for information about the other types.
|
||||
|
||||
|
||||
Modelling data in QAPI
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
For a QMP command that to be considered stable and supported long term,
|
||||
there is a requirement returned data should be explicitly modelled
|
||||
using fine-grained QAPI types. As a general guide, a caller of the QMP
|
||||
command should never need to parse individual returned data fields. If
|
||||
a field appears to need parsing, then it should be split into separate
|
||||
fields corresponding to each distinct data item. This should be the
|
||||
common case for any new QMP command that is intended to be used by
|
||||
machines, as opposed to exclusively human operators.
|
||||
|
||||
Some QMP commands, however, are only intended as ad hoc debugging aids
|
||||
for human operators. While they may return large amounts of formatted
|
||||
data, it is not expected that machines will need to parse the result.
|
||||
The overhead of defining a fine grained QAPI type for the data may not
|
||||
be justified by the potential benefit. In such cases, it is permitted
|
||||
to have a command return a simple string that contains formatted data,
|
||||
however, it is mandatory for the command to use the 'x-' name prefix.
|
||||
This indicates that the command is not guaranteed to be long term
|
||||
stable / liable to change in future and is not following QAPI design
|
||||
best practices. An example where this approach is taken is the QMP
|
||||
command "x-query-registers". This returns a formatted dump of the
|
||||
architecture specific CPU state. The way the data is formatted varies
|
||||
across QEMU targets, is liable to change over time, and is only
|
||||
intended to be consumed as an opaque string by machines. Refer to the
|
||||
`Writing a debugging aid returning unstructured text`_ section for
|
||||
an illustration.
|
||||
|
||||
User Defined Types
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
@ -466,9 +502,7 @@ Here's the HMP counterpart of the query-alarm-clock command::
|
||||
Error *err = NULL;
|
||||
|
||||
clock = qmp_query_alarm_clock(&err);
|
||||
if (err) {
|
||||
monitor_printf(mon, "Could not query alarm clock information\n");
|
||||
error_free(err);
|
||||
if (hmp_handle_error(mon, err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -607,9 +641,7 @@ has to traverse the list, it's shown below for reference::
|
||||
Error *err = NULL;
|
||||
|
||||
method_list = qmp_query_alarm_methods(&err);
|
||||
if (err) {
|
||||
monitor_printf(mon, "Could not query alarm methods\n");
|
||||
error_free(err);
|
||||
if (hmp_handle_error(mon, err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -620,3 +652,100 @@ has to traverse the list, it's shown below for reference::
|
||||
|
||||
qapi_free_TimerAlarmMethodList(method_list);
|
||||
}
|
||||
|
||||
Writing a debugging aid returning unstructured text
|
||||
---------------------------------------------------
|
||||
|
||||
As discussed in section `Modelling data in QAPI`_, it is required that
|
||||
commands expecting machine usage be using fine-grained QAPI data types.
|
||||
The exception to this rule applies when the command is solely intended
|
||||
as a debugging aid and allows for returning unstructured text. This is
|
||||
commonly needed for query commands that report aspects of QEMU's
|
||||
internal state that are useful to human operators.
|
||||
|
||||
In this example we will consider a simplified variant of the HMP
|
||||
command ``info roms``. Following the earlier rules, this command will
|
||||
need to live under the ``x-`` name prefix, so its QMP implementation
|
||||
will be called ``x-query-roms``. It will have no parameters and will
|
||||
return a single text string::
|
||||
|
||||
{ 'struct': 'HumanReadableText',
|
||||
'data': { 'human-readable-text': 'str' } }
|
||||
|
||||
{ 'command': 'x-query-roms',
|
||||
'returns': 'HumanReadableText' }
|
||||
|
||||
The ``HumanReadableText`` struct is intended to be used for all
|
||||
commands, under the ``x-`` name prefix that are returning unstructured
|
||||
text targetted at humans. It should never be used for commands outside
|
||||
the ``x-`` name prefix, as those should be using structured QAPI types.
|
||||
|
||||
Implementing the QMP command
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The QMP implementation will typically involve creating a ``GString``
|
||||
object and printing formatted data into it::
|
||||
|
||||
HumanReadableText *qmp_x_query_roms(Error **errp)
|
||||
{
|
||||
g_autoptr(GString) buf = g_string_new("");
|
||||
Rom *rom;
|
||||
|
||||
QTAILQ_FOREACH(rom, &roms, next) {
|
||||
g_string_append_printf("%s size=0x%06zx name=\"%s\"\n",
|
||||
memory_region_name(rom->mr),
|
||||
rom->romsize,
|
||||
rom->name);
|
||||
}
|
||||
|
||||
return human_readable_text_from_str(buf);
|
||||
}
|
||||
|
||||
|
||||
Implementing the HMP command
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Now that the QMP command is in place, we can also make it available in
|
||||
the human monitor (HMP) as shown in previous examples. The HMP
|
||||
implementations will all look fairly similar, as all they need do is
|
||||
invoke the QMP command and then print the resulting text or error
|
||||
message. Here's the implementation of the "info roms" HMP command::
|
||||
|
||||
void hmp_info_roms(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
Error err = NULL;
|
||||
g_autoptr(HumanReadableText) info = qmp_x_query_roms(&err);
|
||||
|
||||
if (hmp_handle_error(mon, err)) {
|
||||
return;
|
||||
}
|
||||
monitor_printf(mon, "%s", info->human_readable_text);
|
||||
}
|
||||
|
||||
Also, you have to add the function's prototype to the hmp.h file.
|
||||
|
||||
There's one last step to actually make the command available to
|
||||
monitor users, we should add it to the hmp-commands-info.hx file::
|
||||
|
||||
{
|
||||
.name = "roms",
|
||||
.args_type = "",
|
||||
.params = "",
|
||||
.help = "show roms",
|
||||
.cmd = hmp_info_roms,
|
||||
},
|
||||
|
||||
The case of writing a HMP info handler that calls a no-parameter QMP query
|
||||
command is quite common. To simplify the implementation there is a general
|
||||
purpose HMP info handler for this scenario. All that is required to expose
|
||||
a no-parameter QMP query command via HMP is to declare it using the
|
||||
'.cmd_info_hrt' field to point to the QMP handler, and leave the '.cmd'
|
||||
field NULL::
|
||||
|
||||
{
|
||||
.name = "roms",
|
||||
.args_type = "",
|
||||
.params = "",
|
||||
.help = "show roms",
|
||||
.cmd_info_hrt = qmp_x_query_roms,
|
||||
},
|
@ -127,21 +127,6 @@ SRST
|
||||
Show local APIC state
|
||||
ERST
|
||||
|
||||
#if defined(TARGET_I386)
|
||||
{
|
||||
.name = "ioapic",
|
||||
.args_type = "",
|
||||
.params = "",
|
||||
.help = "show io apic state",
|
||||
.cmd = hmp_info_io_apic,
|
||||
},
|
||||
#endif
|
||||
|
||||
SRST
|
||||
``info ioapic``
|
||||
Show io APIC state
|
||||
ERST
|
||||
|
||||
{
|
||||
.name = "cpus",
|
||||
.args_type = "",
|
||||
@ -174,7 +159,7 @@ ERST
|
||||
.args_type = "",
|
||||
.params = "",
|
||||
.help = "show the interrupts statistics (if available)",
|
||||
.cmd = hmp_info_irq,
|
||||
.cmd_info_hrt = qmp_x_query_irq,
|
||||
},
|
||||
|
||||
SRST
|
||||
@ -200,7 +185,7 @@ ERST
|
||||
.args_type = "",
|
||||
.params = "",
|
||||
.help = "show RDMA state",
|
||||
.cmd = hmp_info_rdma,
|
||||
.cmd_info_hrt = qmp_x_query_rdma,
|
||||
},
|
||||
|
||||
SRST
|
||||
@ -340,7 +325,7 @@ ERST
|
||||
.args_type = "",
|
||||
.params = "",
|
||||
.help = "show NUMA information",
|
||||
.cmd = hmp_info_numa,
|
||||
.cmd_info_hrt = qmp_x_query_numa,
|
||||
},
|
||||
|
||||
SRST
|
||||
@ -353,7 +338,7 @@ ERST
|
||||
.args_type = "",
|
||||
.params = "",
|
||||
.help = "show guest USB devices",
|
||||
.cmd = hmp_info_usb,
|
||||
.cmd_info_hrt = qmp_x_query_usb,
|
||||
},
|
||||
|
||||
SRST
|
||||
@ -378,7 +363,7 @@ ERST
|
||||
.args_type = "",
|
||||
.params = "",
|
||||
.help = "show profiling information",
|
||||
.cmd = hmp_info_profile,
|
||||
.cmd_info_hrt = qmp_x_query_profile,
|
||||
},
|
||||
|
||||
SRST
|
||||
@ -609,7 +594,7 @@ ERST
|
||||
.args_type = "",
|
||||
.params = "",
|
||||
.help = "show roms",
|
||||
.cmd = hmp_info_roms,
|
||||
.cmd_info_hrt = qmp_x_query_roms,
|
||||
},
|
||||
|
||||
SRST
|
||||
@ -787,7 +772,7 @@ ERST
|
||||
.args_type = "",
|
||||
.params = "",
|
||||
.help = "Display system ramblock information",
|
||||
.cmd = hmp_info_ramblock,
|
||||
.cmd_info_hrt = qmp_x_query_ramblock,
|
||||
},
|
||||
|
||||
SRST
|
||||
|
@ -46,6 +46,8 @@
|
||||
#include "qemu-common.h"
|
||||
#include "qemu/datadir.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qapi-commands-machine.h"
|
||||
#include "qapi/type-helpers.h"
|
||||
#include "trace.h"
|
||||
#include "hw/hw.h"
|
||||
#include "disas/disas.h"
|
||||
@ -1474,25 +1476,26 @@ void *rom_ptr_for_as(AddressSpace *as, hwaddr addr, size_t size)
|
||||
return cbdata.rom;
|
||||
}
|
||||
|
||||
void hmp_info_roms(Monitor *mon, const QDict *qdict)
|
||||
HumanReadableText *qmp_x_query_roms(Error **errp)
|
||||
{
|
||||
Rom *rom;
|
||||
g_autoptr(GString) buf = g_string_new("");
|
||||
|
||||
QTAILQ_FOREACH(rom, &roms, next) {
|
||||
if (rom->mr) {
|
||||
monitor_printf(mon, "%s"
|
||||
g_string_append_printf(buf, "%s"
|
||||
" size=0x%06zx name=\"%s\"\n",
|
||||
memory_region_name(rom->mr),
|
||||
rom->romsize,
|
||||
rom->name);
|
||||
} else if (!rom->fw_file) {
|
||||
monitor_printf(mon, "addr=" TARGET_FMT_plx
|
||||
g_string_append_printf(buf, "addr=" TARGET_FMT_plx
|
||||
" size=0x%06zx mem=%s name=\"%s\"\n",
|
||||
rom->addr, rom->romsize,
|
||||
rom->isrom ? "rom" : "ram",
|
||||
rom->name);
|
||||
} else {
|
||||
monitor_printf(mon, "fw=%s/%s"
|
||||
g_string_append_printf(buf, "fw=%s/%s"
|
||||
" size=0x%06zx name=\"%s\"\n",
|
||||
rom->fw_dir,
|
||||
rom->fw_file,
|
||||
@ -1500,6 +1503,8 @@ void hmp_info_roms(Monitor *mon, const QDict *qdict)
|
||||
rom->name);
|
||||
}
|
||||
}
|
||||
|
||||
return human_readable_text_from_str(buf);
|
||||
}
|
||||
|
||||
typedef enum HexRecord HexRecord;
|
||||
|
@ -53,8 +53,7 @@ void hmp_hotpluggable_cpus(Monitor *mon, const QDict *qdict)
|
||||
HotpluggableCPUList *saved = l;
|
||||
CpuInstanceProperties *c;
|
||||
|
||||
if (err != NULL) {
|
||||
hmp_handle_error(mon, err);
|
||||
if (hmp_handle_error(mon, err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -131,38 +130,3 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
|
||||
qapi_free_MemdevList(memdev_list);
|
||||
hmp_handle_error(mon, err);
|
||||
}
|
||||
|
||||
void hmp_info_numa(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
int i, nb_numa_nodes;
|
||||
NumaNodeMem *node_mem;
|
||||
CpuInfoFastList *cpu_list, *cpu;
|
||||
MachineState *ms = MACHINE(qdev_get_machine());
|
||||
|
||||
nb_numa_nodes = ms->numa_state ? ms->numa_state->num_nodes : 0;
|
||||
monitor_printf(mon, "%d nodes\n", nb_numa_nodes);
|
||||
if (!nb_numa_nodes) {
|
||||
return;
|
||||
}
|
||||
|
||||
cpu_list = qmp_query_cpus_fast(&error_abort);
|
||||
node_mem = g_new0(NumaNodeMem, nb_numa_nodes);
|
||||
|
||||
query_numa_node_mem(node_mem, ms);
|
||||
for (i = 0; i < nb_numa_nodes; i++) {
|
||||
monitor_printf(mon, "node %d cpus:", i);
|
||||
for (cpu = cpu_list; cpu; cpu = cpu->next) {
|
||||
if (cpu->value->has_props && cpu->value->props->has_node_id &&
|
||||
cpu->value->props->node_id == i) {
|
||||
monitor_printf(mon, " %" PRIi64, cpu->value->cpu_index);
|
||||
}
|
||||
}
|
||||
monitor_printf(mon, "\n");
|
||||
monitor_printf(mon, "node %d size: %" PRId64 " MB\n", i,
|
||||
node_mem[i].node_mem >> 20);
|
||||
monitor_printf(mon, "node %d plugged: %" PRId64 " MB\n", i,
|
||||
node_mem[i].node_plugged_mem >> 20);
|
||||
}
|
||||
qapi_free_CpuInfoFastList(cpu_list);
|
||||
g_free(node_mem);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "qapi/qmp/qerror.h"
|
||||
#include "qapi/qmp/qobject.h"
|
||||
#include "qapi/qobject-input-visitor.h"
|
||||
#include "qapi/type-helpers.h"
|
||||
#include "qemu/main-loop.h"
|
||||
#include "qom/qom-qobject.h"
|
||||
#include "sysemu/hostmem.h"
|
||||
@ -204,3 +205,42 @@ MemdevList *qmp_query_memdev(Error **errp)
|
||||
object_child_foreach(obj, query_memdev, &list);
|
||||
return list;
|
||||
}
|
||||
|
||||
HumanReadableText *qmp_x_query_numa(Error **errp)
|
||||
{
|
||||
g_autoptr(GString) buf = g_string_new("");
|
||||
int i, nb_numa_nodes;
|
||||
NumaNodeMem *node_mem;
|
||||
CpuInfoFastList *cpu_list, *cpu;
|
||||
MachineState *ms = MACHINE(qdev_get_machine());
|
||||
|
||||
nb_numa_nodes = ms->numa_state ? ms->numa_state->num_nodes : 0;
|
||||
g_string_append_printf(buf, "%d nodes\n", nb_numa_nodes);
|
||||
if (!nb_numa_nodes) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
cpu_list = qmp_query_cpus_fast(&error_abort);
|
||||
node_mem = g_new0(NumaNodeMem, nb_numa_nodes);
|
||||
|
||||
query_numa_node_mem(node_mem, ms);
|
||||
for (i = 0; i < nb_numa_nodes; i++) {
|
||||
g_string_append_printf(buf, "node %d cpus:", i);
|
||||
for (cpu = cpu_list; cpu; cpu = cpu->next) {
|
||||
if (cpu->value->has_props && cpu->value->props->has_node_id &&
|
||||
cpu->value->props->node_id == i) {
|
||||
g_string_append_printf(buf, " %" PRIi64, cpu->value->cpu_index);
|
||||
}
|
||||
}
|
||||
g_string_append_printf(buf, "\n");
|
||||
g_string_append_printf(buf, "node %d size: %" PRId64 " MB\n", i,
|
||||
node_mem[i].node_mem >> 20);
|
||||
g_string_append_printf(buf, "node %d plugged: %" PRId64 " MB\n", i,
|
||||
node_mem[i].node_plugged_mem >> 20);
|
||||
}
|
||||
qapi_free_CpuInfoFastList(cpu_list);
|
||||
g_free(node_mem);
|
||||
|
||||
done:
|
||||
return human_readable_text_from_str(buf);
|
||||
}
|
||||
|
@ -27,57 +27,57 @@
|
||||
#define PG_DIR_SZ { TARGET_PAGE_SIZE / sizeof(__u64) }
|
||||
#define PG_TBL_SZ { TARGET_PAGE_SIZE / sizeof(__u64) }
|
||||
|
||||
void rdma_dump_device_counters(Monitor *mon, RdmaDeviceResources *dev_res)
|
||||
void rdma_format_device_counters(RdmaDeviceResources *dev_res, GString *buf)
|
||||
{
|
||||
monitor_printf(mon, "\ttx : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\ttx : %" PRId64 "\n",
|
||||
dev_res->stats.tx);
|
||||
monitor_printf(mon, "\ttx_len : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\ttx_len : %" PRId64 "\n",
|
||||
dev_res->stats.tx_len);
|
||||
monitor_printf(mon, "\ttx_err : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\ttx_err : %" PRId64 "\n",
|
||||
dev_res->stats.tx_err);
|
||||
monitor_printf(mon, "\trx_bufs : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\trx_bufs : %" PRId64 "\n",
|
||||
dev_res->stats.rx_bufs);
|
||||
monitor_printf(mon, "\trx_srq : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\trx_srq : %" PRId64 "\n",
|
||||
dev_res->stats.rx_srq);
|
||||
monitor_printf(mon, "\trx_bufs_len : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\trx_bufs_len : %" PRId64 "\n",
|
||||
dev_res->stats.rx_bufs_len);
|
||||
monitor_printf(mon, "\trx_bufs_err : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\trx_bufs_err : %" PRId64 "\n",
|
||||
dev_res->stats.rx_bufs_err);
|
||||
monitor_printf(mon, "\tcomps : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\tcomps : %" PRId64 "\n",
|
||||
dev_res->stats.completions);
|
||||
monitor_printf(mon, "\tmissing_comps : %" PRId32 "\n",
|
||||
g_string_append_printf(buf, "\tmissing_comps : %" PRId32 "\n",
|
||||
dev_res->stats.missing_cqe);
|
||||
monitor_printf(mon, "\tpoll_cq (bk) : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\tpoll_cq (bk) : %" PRId64 "\n",
|
||||
dev_res->stats.poll_cq_from_bk);
|
||||
monitor_printf(mon, "\tpoll_cq_ppoll_to : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\tpoll_cq_ppoll_to : %" PRId64 "\n",
|
||||
dev_res->stats.poll_cq_ppoll_to);
|
||||
monitor_printf(mon, "\tpoll_cq (fe) : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\tpoll_cq (fe) : %" PRId64 "\n",
|
||||
dev_res->stats.poll_cq_from_guest);
|
||||
monitor_printf(mon, "\tpoll_cq_empty : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\tpoll_cq_empty : %" PRId64 "\n",
|
||||
dev_res->stats.poll_cq_from_guest_empty);
|
||||
monitor_printf(mon, "\tmad_tx : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\tmad_tx : %" PRId64 "\n",
|
||||
dev_res->stats.mad_tx);
|
||||
monitor_printf(mon, "\tmad_tx_err : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\tmad_tx_err : %" PRId64 "\n",
|
||||
dev_res->stats.mad_tx_err);
|
||||
monitor_printf(mon, "\tmad_rx : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\tmad_rx : %" PRId64 "\n",
|
||||
dev_res->stats.mad_rx);
|
||||
monitor_printf(mon, "\tmad_rx_err : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\tmad_rx_err : %" PRId64 "\n",
|
||||
dev_res->stats.mad_rx_err);
|
||||
monitor_printf(mon, "\tmad_rx_bufs : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\tmad_rx_bufs : %" PRId64 "\n",
|
||||
dev_res->stats.mad_rx_bufs);
|
||||
monitor_printf(mon, "\tmad_rx_bufs_err : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\tmad_rx_bufs_err : %" PRId64 "\n",
|
||||
dev_res->stats.mad_rx_bufs_err);
|
||||
monitor_printf(mon, "\tPDs : %" PRId32 "\n",
|
||||
g_string_append_printf(buf, "\tPDs : %" PRId32 "\n",
|
||||
dev_res->pd_tbl.used);
|
||||
monitor_printf(mon, "\tMRs : %" PRId32 "\n",
|
||||
g_string_append_printf(buf, "\tMRs : %" PRId32 "\n",
|
||||
dev_res->mr_tbl.used);
|
||||
monitor_printf(mon, "\tUCs : %" PRId32 "\n",
|
||||
g_string_append_printf(buf, "\tUCs : %" PRId32 "\n",
|
||||
dev_res->uc_tbl.used);
|
||||
monitor_printf(mon, "\tQPs : %" PRId32 "\n",
|
||||
g_string_append_printf(buf, "\tQPs : %" PRId32 "\n",
|
||||
dev_res->qp_tbl.used);
|
||||
monitor_printf(mon, "\tCQs : %" PRId32 "\n",
|
||||
g_string_append_printf(buf, "\tCQs : %" PRId32 "\n",
|
||||
dev_res->cq_tbl.used);
|
||||
monitor_printf(mon, "\tCEQ_CTXs : %" PRId32 "\n",
|
||||
g_string_append_printf(buf, "\tCEQ_CTXs : %" PRId32 "\n",
|
||||
dev_res->cqe_ctx_tbl.used);
|
||||
}
|
||||
|
||||
|
@ -92,6 +92,6 @@ static inline union ibv_gid *rdma_rm_get_gid(RdmaDeviceResources *dev_res,
|
||||
{
|
||||
return &dev_res->port.gid_tbl[sgid_idx].gid;
|
||||
}
|
||||
void rdma_dump_device_counters(Monitor *mon, RdmaDeviceResources *dev_res);
|
||||
void rdma_format_device_counters(RdmaDeviceResources *dev_res, GString *buf);
|
||||
|
||||
#endif
|
||||
|
@ -58,24 +58,25 @@ static Property pvrdma_dev_properties[] = {
|
||||
DEFINE_PROP_END_OF_LIST(),
|
||||
};
|
||||
|
||||
static void pvrdma_print_statistics(Monitor *mon, RdmaProvider *obj)
|
||||
static void pvrdma_format_statistics(RdmaProvider *obj, GString *buf)
|
||||
{
|
||||
PVRDMADev *dev = PVRDMA_DEV(obj);
|
||||
PCIDevice *pdev = PCI_DEVICE(dev);
|
||||
|
||||
monitor_printf(mon, "%s, %x.%x\n", pdev->name, PCI_SLOT(pdev->devfn),
|
||||
g_string_append_printf(buf, "%s, %x.%x\n",
|
||||
pdev->name, PCI_SLOT(pdev->devfn),
|
||||
PCI_FUNC(pdev->devfn));
|
||||
monitor_printf(mon, "\tcommands : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\tcommands : %" PRId64 "\n",
|
||||
dev->stats.commands);
|
||||
monitor_printf(mon, "\tregs_reads : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\tregs_reads : %" PRId64 "\n",
|
||||
dev->stats.regs_reads);
|
||||
monitor_printf(mon, "\tregs_writes : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\tregs_writes : %" PRId64 "\n",
|
||||
dev->stats.regs_writes);
|
||||
monitor_printf(mon, "\tuar_writes : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\tuar_writes : %" PRId64 "\n",
|
||||
dev->stats.uar_writes);
|
||||
monitor_printf(mon, "\tinterrupts : %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "\tinterrupts : %" PRId64 "\n",
|
||||
dev->stats.interrupts);
|
||||
rdma_dump_device_counters(mon, &dev->rdma_dev_res);
|
||||
rdma_format_device_counters(&dev->rdma_dev_res, buf);
|
||||
}
|
||||
|
||||
static void free_dev_ring(PCIDevice *pci_dev, PvrdmaRing *ring,
|
||||
@ -699,7 +700,7 @@ static void pvrdma_class_init(ObjectClass *klass, void *data)
|
||||
device_class_set_props(dc, pvrdma_dev_properties);
|
||||
set_bit(DEVICE_CATEGORY_NETWORK, dc->categories);
|
||||
|
||||
ir->print_statistics = pvrdma_print_statistics;
|
||||
ir->format_statistics = pvrdma_format_statistics;
|
||||
}
|
||||
|
||||
static const TypeInfo pvrdma_info = {
|
||||
|
14
hw/usb/bus.c
14
hw/usb/bus.c
@ -2,6 +2,8 @@
|
||||
#include "hw/qdev-properties.h"
|
||||
#include "hw/usb.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qapi-commands-machine.h"
|
||||
#include "qapi/type-helpers.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qemu/module.h"
|
||||
#include "sysemu/sysemu.h"
|
||||
@ -631,15 +633,16 @@ static char *usb_get_fw_dev_path(DeviceState *qdev)
|
||||
return fw_path;
|
||||
}
|
||||
|
||||
void hmp_info_usb(Monitor *mon, const QDict *qdict)
|
||||
HumanReadableText *qmp_x_query_usb(Error **errp)
|
||||
{
|
||||
g_autoptr(GString) buf = g_string_new("");
|
||||
USBBus *bus;
|
||||
USBDevice *dev;
|
||||
USBPort *port;
|
||||
|
||||
if (QTAILQ_EMPTY(&busses)) {
|
||||
monitor_printf(mon, "USB support not enabled\n");
|
||||
return;
|
||||
error_setg(errp, "USB support not enabled");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
QTAILQ_FOREACH(bus, &busses, next) {
|
||||
@ -647,7 +650,8 @@ void hmp_info_usb(Monitor *mon, const QDict *qdict)
|
||||
dev = port->dev;
|
||||
if (!dev)
|
||||
continue;
|
||||
monitor_printf(mon, " Device %d.%d, Port %s, Speed %s Mb/s, "
|
||||
g_string_append_printf(buf,
|
||||
" Device %d.%d, Port %s, Speed %s Mb/s, "
|
||||
"Product %s%s%s\n",
|
||||
bus->busnr, dev->addr, port->path,
|
||||
usb_speed(dev->speed), dev->product_desc,
|
||||
@ -655,6 +659,8 @@ void hmp_info_usb(Monitor *mon, const QDict *qdict)
|
||||
dev->qdev.id ?: "");
|
||||
}
|
||||
}
|
||||
|
||||
return human_readable_text_from_str(buf);
|
||||
}
|
||||
|
||||
/* handle legacy -usbdevice cmd line option */
|
||||
|
@ -429,10 +429,10 @@ static inline bool tlb_hit(target_ulong tlb_addr, target_ulong addr)
|
||||
|
||||
#ifdef CONFIG_TCG
|
||||
/* accel/tcg/cpu-exec.c */
|
||||
void dump_drift_info(void);
|
||||
void dump_drift_info(GString *buf);
|
||||
/* accel/tcg/translate-all.c */
|
||||
void dump_exec_info(void);
|
||||
void dump_opcount_info(void);
|
||||
void dump_exec_info(GString *buf);
|
||||
void dump_opcount_info(GString *buf);
|
||||
#endif /* CONFIG_TCG */
|
||||
|
||||
#endif /* !CONFIG_USER_ONLY */
|
||||
|
@ -80,6 +80,6 @@ void ram_block_notify_add(void *host, size_t size, size_t max_size);
|
||||
void ram_block_notify_remove(void *host, size_t size, size_t max_size);
|
||||
void ram_block_notify_resize(void *host, size_t old_size, size_t new_size);
|
||||
|
||||
void ram_block_dump(Monitor *mon);
|
||||
GString *ram_block_format(void);
|
||||
|
||||
#endif /* RAMLIST_H */
|
||||
|
@ -31,7 +31,7 @@ typedef struct RdmaProvider RdmaProvider;
|
||||
struct RdmaProviderClass {
|
||||
InterfaceClass parent;
|
||||
|
||||
void (*print_statistics)(Monitor *mon, RdmaProvider *obj);
|
||||
void (*format_statistics)(RdmaProvider *obj, GString *buf);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -48,7 +48,6 @@ void hmp_info_mem(Monitor *mon, const QDict *qdict);
|
||||
void hmp_info_tlb(Monitor *mon, const QDict *qdict);
|
||||
void hmp_mce(Monitor *mon, const QDict *qdict);
|
||||
void hmp_info_local_apic(Monitor *mon, const QDict *qdict);
|
||||
void hmp_info_io_apic(Monitor *mon, const QDict *qdict);
|
||||
void hmp_info_sev(Monitor *mon, const QDict *qdict);
|
||||
void hmp_info_sgx(Monitor *mon, const QDict *qdict);
|
||||
|
||||
|
@ -15,8 +15,9 @@
|
||||
#define HMP_H
|
||||
|
||||
#include "qemu/readline.h"
|
||||
#include "qapi/qapi-types-common.h"
|
||||
|
||||
void hmp_handle_error(Monitor *mon, Error *err);
|
||||
bool hmp_handle_error(Monitor *mon, Error *err);
|
||||
|
||||
void hmp_info_name(Monitor *mon, const QDict *qdict);
|
||||
void hmp_info_version(Monitor *mon, const QDict *qdict);
|
||||
@ -130,5 +131,7 @@ void hmp_replay_delete_break(Monitor *mon, const QDict *qdict);
|
||||
void hmp_replay_seek(Monitor *mon, const QDict *qdict);
|
||||
void hmp_info_dirty_rate(Monitor *mon, const QDict *qdict);
|
||||
void hmp_calc_dirty_rate(Monitor *mon, const QDict *qdict);
|
||||
void hmp_human_readable_text_helper(Monitor *mon,
|
||||
HumanReadableText *(*qmp_handler)(Error **));
|
||||
|
||||
#endif
|
||||
|
@ -53,5 +53,7 @@ int64_t monitor_fdset_dup_fd_find(int dup_fd);
|
||||
|
||||
void monitor_register_hmp(const char *name, bool info,
|
||||
void (*cmd)(Monitor *mon, const QDict *qdict));
|
||||
void monitor_register_hmp_info_hrt(const char *name,
|
||||
HumanReadableText *(*handler)(Error **errp));
|
||||
|
||||
#endif /* MONITOR_H */
|
||||
|
14
include/qapi/type-helpers.h
Normal file
14
include/qapi/type-helpers.h
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* QAPI common helper functions
|
||||
*
|
||||
* This file provides helper functions related to types defined
|
||||
* in the QAPI schema.
|
||||
*
|
||||
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
||||
* See the COPYING.LIB file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "qapi/qapi-types-common.h"
|
||||
|
||||
HumanReadableText *human_readable_text_from_str(GString *str);
|
@ -937,8 +937,8 @@ int tcg_check_temp_count(void);
|
||||
#endif
|
||||
|
||||
int64_t tcg_cpu_exec_time(void);
|
||||
void tcg_dump_info(void);
|
||||
void tcg_dump_op_count(void);
|
||||
void tcg_dump_info(GString *buf);
|
||||
void tcg_dump_op_count(GString *buf);
|
||||
|
||||
#define TCG_CT_CONST 1 /* any constant of register size */
|
||||
|
||||
|
@ -52,9 +52,7 @@
|
||||
#include "ui/console.h"
|
||||
#include "qemu/cutils.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "exec/ramlist.h"
|
||||
#include "hw/intc/intc.h"
|
||||
#include "hw/rdma/rdma.h"
|
||||
#include "migration/snapshot.h"
|
||||
#include "migration/misc.h"
|
||||
|
||||
@ -62,11 +60,13 @@
|
||||
#include <spice/enums.h>
|
||||
#endif
|
||||
|
||||
void hmp_handle_error(Monitor *mon, Error *err)
|
||||
bool hmp_handle_error(Monitor *mon, Error *err)
|
||||
{
|
||||
if (err) {
|
||||
error_reportf_err(err, "Error: ");
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -577,8 +577,7 @@ void hmp_info_vnc(Monitor *mon, const QDict *qdict)
|
||||
|
||||
info2l = qmp_query_vnc_servers(&err);
|
||||
info2l_head = info2l;
|
||||
if (err) {
|
||||
hmp_handle_error(mon, err);
|
||||
if (hmp_handle_error(mon, err)) {
|
||||
return;
|
||||
}
|
||||
if (!info2l) {
|
||||
@ -693,8 +692,7 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict)
|
||||
Error *err = NULL;
|
||||
|
||||
info = qmp_query_balloon(&err);
|
||||
if (err) {
|
||||
hmp_handle_error(mon, err);
|
||||
if (hmp_handle_error(mon, err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -786,44 +784,6 @@ static void hmp_info_pci_device(Monitor *mon, const PciDeviceInfo *dev)
|
||||
}
|
||||
}
|
||||
|
||||
static int hmp_info_irq_foreach(Object *obj, void *opaque)
|
||||
{
|
||||
InterruptStatsProvider *intc;
|
||||
InterruptStatsProviderClass *k;
|
||||
Monitor *mon = opaque;
|
||||
|
||||
if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
|
||||
intc = INTERRUPT_STATS_PROVIDER(obj);
|
||||
k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
|
||||
uint64_t *irq_counts;
|
||||
unsigned int nb_irqs, i;
|
||||
if (k->get_statistics &&
|
||||
k->get_statistics(intc, &irq_counts, &nb_irqs)) {
|
||||
if (nb_irqs > 0) {
|
||||
monitor_printf(mon, "IRQ statistics for %s:\n",
|
||||
object_get_typename(obj));
|
||||
for (i = 0; i < nb_irqs; i++) {
|
||||
if (irq_counts[i] > 0) {
|
||||
monitor_printf(mon, "%2d: %" PRId64 "\n", i,
|
||||
irq_counts[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
monitor_printf(mon, "IRQ statistics not available for %s.\n",
|
||||
object_get_typename(obj));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hmp_info_irq(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
object_child_foreach_recursive(object_get_root(),
|
||||
hmp_info_irq_foreach, mon);
|
||||
}
|
||||
|
||||
static int hmp_info_pic_foreach(Object *obj, void *opaque)
|
||||
{
|
||||
InterruptStatsProvider *intc;
|
||||
@ -850,32 +810,6 @@ void hmp_info_pic(Monitor *mon, const QDict *qdict)
|
||||
hmp_info_pic_foreach, mon);
|
||||
}
|
||||
|
||||
static int hmp_info_rdma_foreach(Object *obj, void *opaque)
|
||||
{
|
||||
RdmaProvider *rdma;
|
||||
RdmaProviderClass *k;
|
||||
Monitor *mon = opaque;
|
||||
|
||||
if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) {
|
||||
rdma = RDMA_PROVIDER(obj);
|
||||
k = RDMA_PROVIDER_GET_CLASS(obj);
|
||||
if (k->print_statistics) {
|
||||
k->print_statistics(mon, rdma);
|
||||
} else {
|
||||
monitor_printf(mon, "RDMA statistics not available for %s.\n",
|
||||
object_get_typename(obj));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void hmp_info_rdma(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
object_child_foreach_recursive(object_get_root(),
|
||||
hmp_info_rdma_foreach, mon);
|
||||
}
|
||||
|
||||
void hmp_info_pci(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
PciInfoList *info_list, *info;
|
||||
@ -1065,8 +999,7 @@ void hmp_ringbuf_read(Monitor *mon, const QDict *qdict)
|
||||
int i;
|
||||
|
||||
data = qmp_ringbuf_read(chardev, size, false, 0, &err);
|
||||
if (err) {
|
||||
hmp_handle_error(mon, err);
|
||||
if (hmp_handle_error(mon, err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1582,8 +1515,7 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
|
||||
|
||||
qmp_migrate(uri, !!blk, blk, !!inc, inc,
|
||||
false, false, true, resume, &err);
|
||||
if (err) {
|
||||
hmp_handle_error(mon, err);
|
||||
if (hmp_handle_error(mon, err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1917,8 +1849,7 @@ void hmp_rocker(Monitor *mon, const QDict *qdict)
|
||||
Error *err = NULL;
|
||||
|
||||
rocker = qmp_query_rocker(name, &err);
|
||||
if (err != NULL) {
|
||||
hmp_handle_error(mon, err);
|
||||
if (hmp_handle_error(mon, err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1936,8 +1867,7 @@ void hmp_rocker_ports(Monitor *mon, const QDict *qdict)
|
||||
Error *err = NULL;
|
||||
|
||||
list = qmp_query_rocker_ports(name, &err);
|
||||
if (err != NULL) {
|
||||
hmp_handle_error(mon, err);
|
||||
if (hmp_handle_error(mon, err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1965,8 +1895,7 @@ void hmp_rocker_of_dpa_flows(Monitor *mon, const QDict *qdict)
|
||||
Error *err = NULL;
|
||||
|
||||
list = qmp_query_rocker_of_dpa_flows(name, tbl_id != -1, tbl_id, &err);
|
||||
if (err != NULL) {
|
||||
hmp_handle_error(mon, err);
|
||||
if (hmp_handle_error(mon, err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2115,8 +2044,7 @@ void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
|
||||
Error *err = NULL;
|
||||
|
||||
list = qmp_query_rocker_of_dpa_groups(name, type != 9, type, &err);
|
||||
if (err != NULL) {
|
||||
hmp_handle_error(mon, err);
|
||||
if (hmp_handle_error(mon, err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2209,11 +2137,6 @@ void hmp_rocker_of_dpa_groups(Monitor *mon, const QDict *qdict)
|
||||
qapi_free_RockerOfDpaGroupList(list);
|
||||
}
|
||||
|
||||
void hmp_info_ramblock(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
ram_block_dump(mon);
|
||||
}
|
||||
|
||||
void hmp_info_vm_generation_id(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
Error *err = NULL;
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <dirent.h>
|
||||
#include "hw/qdev-core.h"
|
||||
#include "monitor-internal.h"
|
||||
#include "monitor/hmp.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qmp/qdict.h"
|
||||
#include "qapi/qmp/qnum.h"
|
||||
@ -1061,6 +1062,31 @@ fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void hmp_info_human_readable_text(Monitor *mon,
|
||||
HumanReadableText *(*handler)(Error **))
|
||||
{
|
||||
Error *err = NULL;
|
||||
g_autoptr(HumanReadableText) info = handler(&err);
|
||||
|
||||
if (hmp_handle_error(mon, err)) {
|
||||
return;
|
||||
}
|
||||
|
||||
monitor_printf(mon, "%s", info->human_readable_text);
|
||||
}
|
||||
|
||||
static void handle_hmp_command_exec(Monitor *mon,
|
||||
const HMPCommand *cmd,
|
||||
QDict *qdict)
|
||||
{
|
||||
if (cmd->cmd_info_hrt) {
|
||||
hmp_info_human_readable_text(mon,
|
||||
cmd->cmd_info_hrt);
|
||||
} else {
|
||||
cmd->cmd(mon, qdict);
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct HandleHmpCommandCo {
|
||||
Monitor *mon;
|
||||
const HMPCommand *cmd;
|
||||
@ -1071,7 +1097,7 @@ typedef struct HandleHmpCommandCo {
|
||||
static void handle_hmp_command_co(void *opaque)
|
||||
{
|
||||
HandleHmpCommandCo *data = opaque;
|
||||
data->cmd->cmd(data->mon, data->qdict);
|
||||
handle_hmp_command_exec(data->mon, data->cmd, data->qdict);
|
||||
monitor_set_cur(qemu_coroutine_self(), NULL);
|
||||
data->done = true;
|
||||
}
|
||||
@ -1089,7 +1115,7 @@ void handle_hmp_command(MonitorHMP *mon, const char *cmdline)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cmd->cmd) {
|
||||
if (!cmd->cmd && !cmd->cmd_info_hrt) {
|
||||
/* FIXME: is it useful to try autoload modules here ??? */
|
||||
monitor_printf(&mon->common, "Command \"%.*s\" is not available.\n",
|
||||
(int)(cmdline - cmd_start), cmd_start);
|
||||
@ -1109,7 +1135,7 @@ void handle_hmp_command(MonitorHMP *mon, const char *cmdline)
|
||||
if (!cmd->coroutine) {
|
||||
/* old_mon is non-NULL when called from qmp_human_monitor_command() */
|
||||
Monitor *old_mon = monitor_set_cur(qemu_coroutine_self(), &mon->common);
|
||||
cmd->cmd(&mon->common, qdict);
|
||||
handle_hmp_command_exec(&mon->common, cmd, qdict);
|
||||
monitor_set_cur(qemu_coroutine_self(), old_mon);
|
||||
} else {
|
||||
HandleHmpCommandCo data = {
|
||||
|
@ -71,6 +71,7 @@
|
||||
#include "qapi/qapi-commands-misc.h"
|
||||
#include "qapi/qapi-commands-qom.h"
|
||||
#include "qapi/qapi-commands-trace.h"
|
||||
#include "qapi/qapi-commands-machine.h"
|
||||
#include "qapi/qapi-init-commands.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qmp-event.h"
|
||||
@ -930,33 +931,6 @@ static void hmp_info_mtree(Monitor *mon, const QDict *qdict)
|
||||
mtree_info(flatview, dispatch_tree, owner, disabled);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PROFILER
|
||||
|
||||
int64_t dev_time;
|
||||
|
||||
static void hmp_info_profile(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
static int64_t last_cpu_exec_time;
|
||||
int64_t cpu_exec_time;
|
||||
int64_t delta;
|
||||
|
||||
cpu_exec_time = tcg_cpu_exec_time();
|
||||
delta = cpu_exec_time - last_cpu_exec_time;
|
||||
|
||||
monitor_printf(mon, "async time %" PRId64 " (%0.3f)\n",
|
||||
dev_time, dev_time / (double)NANOSECONDS_PER_SECOND);
|
||||
monitor_printf(mon, "qemu time %" PRId64 " (%0.3f)\n",
|
||||
delta, delta / (double)NANOSECONDS_PER_SECOND);
|
||||
last_cpu_exec_time = cpu_exec_time;
|
||||
dev_time = 0;
|
||||
}
|
||||
#else
|
||||
static void hmp_info_profile(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
monitor_printf(mon, "Internal profiler not compiled\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Capture support */
|
||||
static QLIST_HEAD (capture_list_head, CaptureState) capture_head;
|
||||
|
||||
@ -1964,7 +1938,7 @@ void monitor_register_hmp(const char *name, bool info,
|
||||
|
||||
while (table->name != NULL) {
|
||||
if (strcmp(table->name, name) == 0) {
|
||||
g_assert(table->cmd == NULL);
|
||||
g_assert(table->cmd == NULL && table->cmd_info_hrt == NULL);
|
||||
table->cmd = cmd;
|
||||
return;
|
||||
}
|
||||
@ -1973,6 +1947,22 @@ void monitor_register_hmp(const char *name, bool info,
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
void monitor_register_hmp_info_hrt(const char *name,
|
||||
HumanReadableText *(*handler)(Error **errp))
|
||||
{
|
||||
HMPCommand *table = hmp_info_cmds;
|
||||
|
||||
while (table->name != NULL) {
|
||||
if (strcmp(table->name, name) == 0) {
|
||||
g_assert(table->cmd == NULL && table->cmd_info_hrt == NULL);
|
||||
table->cmd_info_hrt = handler;
|
||||
return;
|
||||
}
|
||||
table++;
|
||||
}
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
void monitor_init_globals(void)
|
||||
{
|
||||
monitor_init_globals_core();
|
||||
|
@ -74,6 +74,13 @@ typedef struct HMPCommand {
|
||||
const char *help;
|
||||
const char *flags; /* p=preconfig */
|
||||
void (*cmd)(Monitor *mon, const QDict *qdict);
|
||||
/*
|
||||
* If implementing a command that takes no arguments and simply
|
||||
* prints formatted data, then leave @cmd NULL, and then set
|
||||
* @cmd_info_hrt to the corresponding QMP handler that returns
|
||||
* the formatted text.
|
||||
*/
|
||||
HumanReadableText *(*cmd_info_hrt)(Error **errp);
|
||||
bool coroutine;
|
||||
/*
|
||||
* @sub_table is a list of 2nd level of commands. If it does not exist,
|
||||
|
@ -36,9 +36,13 @@
|
||||
#include "qapi/qapi-commands-machine.h"
|
||||
#include "qapi/qapi-commands-misc.h"
|
||||
#include "qapi/qapi-commands-ui.h"
|
||||
#include "qapi/type-helpers.h"
|
||||
#include "qapi/qmp/qerror.h"
|
||||
#include "exec/ramlist.h"
|
||||
#include "hw/mem/memory-device.h"
|
||||
#include "hw/acpi/acpi_dev_interface.h"
|
||||
#include "hw/intc/intc.h"
|
||||
#include "hw/rdma/rdma.h"
|
||||
|
||||
NameInfo *qmp_query_name(Error **errp)
|
||||
{
|
||||
@ -350,3 +354,115 @@ void qmp_display_reload(DisplayReloadOptions *arg, Error **errp)
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PROFILER
|
||||
|
||||
int64_t dev_time;
|
||||
|
||||
HumanReadableText *qmp_x_query_profile(Error **errp)
|
||||
{
|
||||
g_autoptr(GString) buf = g_string_new("");
|
||||
static int64_t last_cpu_exec_time;
|
||||
int64_t cpu_exec_time;
|
||||
int64_t delta;
|
||||
|
||||
cpu_exec_time = tcg_cpu_exec_time();
|
||||
delta = cpu_exec_time - last_cpu_exec_time;
|
||||
|
||||
g_string_append_printf(buf, "async time %" PRId64 " (%0.3f)\n",
|
||||
dev_time, dev_time / (double)NANOSECONDS_PER_SECOND);
|
||||
g_string_append_printf(buf, "qemu time %" PRId64 " (%0.3f)\n",
|
||||
delta, delta / (double)NANOSECONDS_PER_SECOND);
|
||||
last_cpu_exec_time = cpu_exec_time;
|
||||
dev_time = 0;
|
||||
|
||||
return human_readable_text_from_str(buf);
|
||||
}
|
||||
#else
|
||||
HumanReadableText *qmp_x_query_profile(Error **errp)
|
||||
{
|
||||
error_setg(errp, "Internal profiler not compiled");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int qmp_x_query_rdma_foreach(Object *obj, void *opaque)
|
||||
{
|
||||
RdmaProvider *rdma;
|
||||
RdmaProviderClass *k;
|
||||
GString *buf = opaque;
|
||||
|
||||
if (object_dynamic_cast(obj, INTERFACE_RDMA_PROVIDER)) {
|
||||
rdma = RDMA_PROVIDER(obj);
|
||||
k = RDMA_PROVIDER_GET_CLASS(obj);
|
||||
if (k->format_statistics) {
|
||||
k->format_statistics(rdma, buf);
|
||||
} else {
|
||||
g_string_append_printf(buf,
|
||||
"RDMA statistics not available for %s.\n",
|
||||
object_get_typename(obj));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
HumanReadableText *qmp_x_query_rdma(Error **errp)
|
||||
{
|
||||
g_autoptr(GString) buf = g_string_new("");
|
||||
|
||||
object_child_foreach_recursive(object_get_root(),
|
||||
qmp_x_query_rdma_foreach, buf);
|
||||
|
||||
return human_readable_text_from_str(buf);
|
||||
}
|
||||
|
||||
HumanReadableText *qmp_x_query_ramblock(Error **errp)
|
||||
{
|
||||
g_autoptr(GString) buf = ram_block_format();
|
||||
|
||||
return human_readable_text_from_str(buf);
|
||||
}
|
||||
|
||||
static int qmp_x_query_irq_foreach(Object *obj, void *opaque)
|
||||
{
|
||||
InterruptStatsProvider *intc;
|
||||
InterruptStatsProviderClass *k;
|
||||
GString *buf = opaque;
|
||||
|
||||
if (object_dynamic_cast(obj, TYPE_INTERRUPT_STATS_PROVIDER)) {
|
||||
intc = INTERRUPT_STATS_PROVIDER(obj);
|
||||
k = INTERRUPT_STATS_PROVIDER_GET_CLASS(obj);
|
||||
uint64_t *irq_counts;
|
||||
unsigned int nb_irqs, i;
|
||||
if (k->get_statistics &&
|
||||
k->get_statistics(intc, &irq_counts, &nb_irqs)) {
|
||||
if (nb_irqs > 0) {
|
||||
g_string_append_printf(buf, "IRQ statistics for %s:\n",
|
||||
object_get_typename(obj));
|
||||
for (i = 0; i < nb_irqs; i++) {
|
||||
if (irq_counts[i] > 0) {
|
||||
g_string_append_printf(buf, "%2d: %" PRId64 "\n", i,
|
||||
irq_counts[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
g_string_append_printf(buf,
|
||||
"IRQ statistics not available for %s.\n",
|
||||
object_get_typename(obj));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
HumanReadableText *qmp_x_query_irq(Error **errp)
|
||||
{
|
||||
g_autoptr(GString) buf = g_string_new("");
|
||||
|
||||
object_child_foreach_recursive(object_get_root(),
|
||||
qmp_x_query_irq_foreach, buf);
|
||||
|
||||
return human_readable_text_from_str(buf);
|
||||
}
|
||||
|
@ -197,3 +197,14 @@
|
||||
{ 'enum': 'GrabToggleKeys',
|
||||
'data': [ 'ctrl-ctrl', 'alt-alt', 'shift-shift','meta-meta', 'scrolllock',
|
||||
'ctrl-scrolllock' ] }
|
||||
|
||||
##
|
||||
# @HumanReadableText:
|
||||
#
|
||||
# @human-readable-text: Formatted output intended for humans.
|
||||
#
|
||||
# Since: 6.2
|
||||
#
|
||||
##
|
||||
{ 'struct': 'HumanReadableText',
|
||||
'data': { 'human-readable-text': 'str' } }
|
||||
|
@ -1411,3 +1411,113 @@
|
||||
'*cores': 'int',
|
||||
'*threads': 'int',
|
||||
'*maxcpus': 'int' } }
|
||||
|
||||
##
|
||||
# @x-query-irq:
|
||||
#
|
||||
# Query interrupt statistics
|
||||
#
|
||||
# Returns: interrupt statistics
|
||||
#
|
||||
# Since: 6.2
|
||||
##
|
||||
{ 'command': 'x-query-irq',
|
||||
'returns': 'HumanReadableText' }
|
||||
|
||||
##
|
||||
# @x-query-jit:
|
||||
#
|
||||
# Query TCG compiler statistics
|
||||
#
|
||||
# Returns: TCG compiler statistics
|
||||
#
|
||||
# Since: 6.2
|
||||
##
|
||||
{ 'command': 'x-query-jit',
|
||||
'returns': 'HumanReadableText',
|
||||
'if': 'CONFIG_TCG' }
|
||||
|
||||
##
|
||||
# @x-query-numa:
|
||||
#
|
||||
# Query NUMA topology information
|
||||
#
|
||||
# Returns: topology information
|
||||
#
|
||||
# Since: 6.2
|
||||
##
|
||||
{ 'command': 'x-query-numa',
|
||||
'returns': 'HumanReadableText' }
|
||||
|
||||
##
|
||||
# @x-query-opcount:
|
||||
#
|
||||
# Query TCG opcode counters
|
||||
#
|
||||
# Returns: TCG opcode counters
|
||||
#
|
||||
# Since: 6.2
|
||||
##
|
||||
{ 'command': 'x-query-opcount',
|
||||
'returns': 'HumanReadableText',
|
||||
'if': 'CONFIG_TCG' }
|
||||
|
||||
##
|
||||
# @x-query-profile:
|
||||
#
|
||||
# Query TCG profiling information
|
||||
#
|
||||
# Returns: profile information
|
||||
#
|
||||
# Since: 6.2
|
||||
##
|
||||
{ 'command': 'x-query-profile',
|
||||
'returns': 'HumanReadableText' }
|
||||
|
||||
##
|
||||
# @x-query-ramblock:
|
||||
#
|
||||
# Query system ramblock information
|
||||
#
|
||||
# Returns: system ramblock information
|
||||
#
|
||||
# Since: 6.2
|
||||
##
|
||||
{ 'command': 'x-query-ramblock',
|
||||
'returns': 'HumanReadableText' }
|
||||
|
||||
##
|
||||
# @x-query-rdma:
|
||||
#
|
||||
# Query RDMA state
|
||||
#
|
||||
# Returns: RDMA state
|
||||
#
|
||||
# Since: 6.2
|
||||
##
|
||||
{ 'command': 'x-query-rdma',
|
||||
'returns': 'HumanReadableText' }
|
||||
|
||||
##
|
||||
# @x-query-roms:
|
||||
#
|
||||
# Query information on the registered ROMS
|
||||
#
|
||||
# Returns: registered ROMs
|
||||
#
|
||||
# Since: 6.2
|
||||
##
|
||||
{ 'command': 'x-query-roms',
|
||||
'returns': 'HumanReadableText' }
|
||||
|
||||
##
|
||||
# @x-query-usb:
|
||||
#
|
||||
# Query information on the USB devices
|
||||
#
|
||||
# Returns: USB device information
|
||||
#
|
||||
# Since: 6.2
|
||||
##
|
||||
{ 'command': 'x-query-usb',
|
||||
'returns': 'HumanReadableText' }
|
||||
|
@ -10,6 +10,9 @@ util_ss.add(files(
|
||||
'string-input-visitor.c',
|
||||
'string-output-visitor.c',
|
||||
))
|
||||
if have_system
|
||||
util_ss.add(files('qapi-type-helpers.c'))
|
||||
endif
|
||||
if have_system or have_tools
|
||||
util_ss.add(files(
|
||||
'qmp-dispatch.c',
|
||||
|
23
qapi/qapi-type-helpers.c
Normal file
23
qapi/qapi-type-helpers.c
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* QAPI common helper functions
|
||||
*
|
||||
* This file provides helper functions related to types defined
|
||||
* in the QAPI schema.
|
||||
*
|
||||
* This work is licensed under the terms of the GNU LGPL, version 2.1 or later.
|
||||
* See the COPYING.LIB file in the top-level directory.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/type-helpers.h"
|
||||
|
||||
HumanReadableText *human_readable_text_from_str(GString *str)
|
||||
{
|
||||
HumanReadableText *ret = g_new0(HumanReadableText, 1);
|
||||
|
||||
ret->human_readable_text = g_steal_pointer(&str->str);
|
||||
|
||||
return ret;
|
||||
}
|
@ -1296,23 +1296,26 @@ void qemu_mutex_unlock_ramlist(void)
|
||||
qemu_mutex_unlock(&ram_list.mutex);
|
||||
}
|
||||
|
||||
void ram_block_dump(Monitor *mon)
|
||||
GString *ram_block_format(void)
|
||||
{
|
||||
RAMBlock *block;
|
||||
char *psize;
|
||||
GString *buf = g_string_new("");
|
||||
|
||||
RCU_READ_LOCK_GUARD();
|
||||
monitor_printf(mon, "%24s %8s %18s %18s %18s\n",
|
||||
g_string_append_printf(buf, "%24s %8s %18s %18s %18s\n",
|
||||
"Block Name", "PSize", "Offset", "Used", "Total");
|
||||
RAMBLOCK_FOREACH(block) {
|
||||
psize = size_to_str(block->page_size);
|
||||
monitor_printf(mon, "%24s %8s 0x%016" PRIx64 " 0x%016" PRIx64
|
||||
g_string_append_printf(buf, "%24s %8s 0x%016" PRIx64 " 0x%016" PRIx64
|
||||
" 0x%016" PRIx64 "\n", block->idstr, psize,
|
||||
(uint64_t)block->offset,
|
||||
(uint64_t)block->used_length,
|
||||
(uint64_t)block->max_length);
|
||||
g_free(psize);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
|
@ -8,6 +8,8 @@
|
||||
|
||||
#include "qemu/osdep.h"
|
||||
#include "qemu/error-report.h"
|
||||
#include "qapi/error.h"
|
||||
#include "qapi/qapi-commands-machine.h"
|
||||
#include "sysemu/sysemu.h"
|
||||
#include "monitor/monitor.h"
|
||||
#include "hw/usb.h"
|
||||
@ -19,6 +21,12 @@ USBDevice *usbdevice_create(const char *driver)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
HumanReadableText *qmp_x_query_usb(Error **errp)
|
||||
{
|
||||
error_setg(errp, "Support for USB devices not built-in");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void hmp_info_usb(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
monitor_printf(mon, "Support for USB devices not built-in\n");
|
||||
|
@ -667,9 +667,3 @@ void hmp_info_local_apic(Monitor *mon, const QDict *qdict)
|
||||
}
|
||||
x86_cpu_dump_local_apic_state(cs, CPU_DUMP_FPU);
|
||||
}
|
||||
|
||||
void hmp_info_io_apic(Monitor *mon, const QDict *qdict)
|
||||
{
|
||||
monitor_printf(mon, "This command is obsolete and will be "
|
||||
"removed soon. Please use 'info pic' instead.\n");
|
||||
}
|
||||
|
66
tcg/tcg.c
66
tcg/tcg.c
@ -4116,14 +4116,14 @@ static void tcg_profile_snapshot_table(TCGProfile *prof)
|
||||
tcg_profile_snapshot(prof, false, true);
|
||||
}
|
||||
|
||||
void tcg_dump_op_count(void)
|
||||
void tcg_dump_op_count(GString *buf)
|
||||
{
|
||||
TCGProfile prof = {};
|
||||
int i;
|
||||
|
||||
tcg_profile_snapshot_table(&prof);
|
||||
for (i = 0; i < NB_OPS; i++) {
|
||||
qemu_printf("%s %" PRId64 "\n", tcg_op_defs[i].name,
|
||||
g_string_append_printf(buf, "%s %" PRId64 "\n", tcg_op_defs[i].name,
|
||||
prof.table_op_count[i]);
|
||||
}
|
||||
}
|
||||
@ -4143,9 +4143,9 @@ int64_t tcg_cpu_exec_time(void)
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
void tcg_dump_op_count(void)
|
||||
void tcg_dump_op_count(GString *buf)
|
||||
{
|
||||
qemu_printf("[TCG profiler not compiled]\n");
|
||||
g_string_append_printf(buf, "[TCG profiler not compiled]\n");
|
||||
}
|
||||
|
||||
int64_t tcg_cpu_exec_time(void)
|
||||
@ -4383,7 +4383,7 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PROFILER
|
||||
void tcg_dump_info(void)
|
||||
void tcg_dump_info(GString *buf)
|
||||
{
|
||||
TCGProfile prof = {};
|
||||
const TCGProfile *s;
|
||||
@ -4397,53 +4397,59 @@ void tcg_dump_info(void)
|
||||
tb_div_count = tb_count ? tb_count : 1;
|
||||
tot = s->interm_time + s->code_time;
|
||||
|
||||
qemu_printf("JIT cycles %" PRId64 " (%0.3f s at 2.4 GHz)\n",
|
||||
g_string_append_printf(buf, "JIT cycles %" PRId64
|
||||
" (%0.3f s at 2.4 GHz)\n",
|
||||
tot, tot / 2.4e9);
|
||||
qemu_printf("translated TBs %" PRId64 " (aborted=%" PRId64
|
||||
" %0.1f%%)\n",
|
||||
g_string_append_printf(buf, "translated TBs %" PRId64
|
||||
" (aborted=%" PRId64 " %0.1f%%)\n",
|
||||
tb_count, s->tb_count1 - tb_count,
|
||||
(double)(s->tb_count1 - s->tb_count)
|
||||
/ (s->tb_count1 ? s->tb_count1 : 1) * 100.0);
|
||||
qemu_printf("avg ops/TB %0.1f max=%d\n",
|
||||
g_string_append_printf(buf, "avg ops/TB %0.1f max=%d\n",
|
||||
(double)s->op_count / tb_div_count, s->op_count_max);
|
||||
qemu_printf("deleted ops/TB %0.2f\n",
|
||||
g_string_append_printf(buf, "deleted ops/TB %0.2f\n",
|
||||
(double)s->del_op_count / tb_div_count);
|
||||
qemu_printf("avg temps/TB %0.2f max=%d\n",
|
||||
(double)s->temp_count / tb_div_count, s->temp_count_max);
|
||||
qemu_printf("avg host code/TB %0.1f\n",
|
||||
g_string_append_printf(buf, "avg temps/TB %0.2f max=%d\n",
|
||||
(double)s->temp_count / tb_div_count,
|
||||
s->temp_count_max);
|
||||
g_string_append_printf(buf, "avg host code/TB %0.1f\n",
|
||||
(double)s->code_out_len / tb_div_count);
|
||||
qemu_printf("avg search data/TB %0.1f\n",
|
||||
g_string_append_printf(buf, "avg search data/TB %0.1f\n",
|
||||
(double)s->search_out_len / tb_div_count);
|
||||
|
||||
qemu_printf("cycles/op %0.1f\n",
|
||||
g_string_append_printf(buf, "cycles/op %0.1f\n",
|
||||
s->op_count ? (double)tot / s->op_count : 0);
|
||||
qemu_printf("cycles/in byte %0.1f\n",
|
||||
g_string_append_printf(buf, "cycles/in byte %0.1f\n",
|
||||
s->code_in_len ? (double)tot / s->code_in_len : 0);
|
||||
qemu_printf("cycles/out byte %0.1f\n",
|
||||
g_string_append_printf(buf, "cycles/out byte %0.1f\n",
|
||||
s->code_out_len ? (double)tot / s->code_out_len : 0);
|
||||
qemu_printf("cycles/search byte %0.1f\n",
|
||||
s->search_out_len ? (double)tot / s->search_out_len : 0);
|
||||
g_string_append_printf(buf, "cycles/search byte %0.1f\n",
|
||||
s->search_out_len ?
|
||||
(double)tot / s->search_out_len : 0);
|
||||
if (tot == 0) {
|
||||
tot = 1;
|
||||
}
|
||||
qemu_printf(" gen_interm time %0.1f%%\n",
|
||||
g_string_append_printf(buf, " gen_interm time %0.1f%%\n",
|
||||
(double)s->interm_time / tot * 100.0);
|
||||
qemu_printf(" gen_code time %0.1f%%\n",
|
||||
g_string_append_printf(buf, " gen_code time %0.1f%%\n",
|
||||
(double)s->code_time / tot * 100.0);
|
||||
qemu_printf("optim./code time %0.1f%%\n",
|
||||
(double)s->opt_time / (s->code_time ? s->code_time : 1)
|
||||
g_string_append_printf(buf, "optim./code time %0.1f%%\n",
|
||||
(double)s->opt_time / (s->code_time ?
|
||||
s->code_time : 1)
|
||||
* 100.0);
|
||||
qemu_printf("liveness/code time %0.1f%%\n",
|
||||
(double)s->la_time / (s->code_time ? s->code_time : 1) * 100.0);
|
||||
qemu_printf("cpu_restore count %" PRId64 "\n",
|
||||
g_string_append_printf(buf, "liveness/code time %0.1f%%\n",
|
||||
(double)s->la_time / (s->code_time ?
|
||||
s->code_time : 1) * 100.0);
|
||||
g_string_append_printf(buf, "cpu_restore count %" PRId64 "\n",
|
||||
s->restore_count);
|
||||
qemu_printf(" avg cycles %0.1f\n",
|
||||
s->restore_count ? (double)s->restore_time / s->restore_count : 0);
|
||||
g_string_append_printf(buf, " avg cycles %0.1f\n",
|
||||
s->restore_count ?
|
||||
(double)s->restore_time / s->restore_count : 0);
|
||||
}
|
||||
#else
|
||||
void tcg_dump_info(void)
|
||||
void tcg_dump_info(GString *buf)
|
||||
{
|
||||
qemu_printf("[TCG profiler not compiled]\n");
|
||||
g_string_append_printf(buf, "[TCG profiler not compiled]\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -46,6 +46,14 @@ static int query_error_class(const char *cmd)
|
||||
{ "query-balloon", ERROR_CLASS_DEVICE_NOT_ACTIVE },
|
||||
{ "query-hotpluggable-cpus", ERROR_CLASS_GENERIC_ERROR },
|
||||
{ "query-vm-generation-id", ERROR_CLASS_GENERIC_ERROR },
|
||||
#ifndef CONFIG_PROFILER
|
||||
{ "x-query-profile", ERROR_CLASS_GENERIC_ERROR },
|
||||
#endif
|
||||
/* Only valid with a USB bus added */
|
||||
{ "x-query-usb", ERROR_CLASS_GENERIC_ERROR },
|
||||
/* Only valid with accel=tcg */
|
||||
{ "x-query-jit", ERROR_CLASS_GENERIC_ERROR },
|
||||
{ "x-query-opcount", ERROR_CLASS_GENERIC_ERROR },
|
||||
{ NULL, -1 }
|
||||
};
|
||||
int i;
|
||||
|
Loading…
Reference in New Issue
Block a user