blob: caf1189e0b55865b1b9ffbe526adaea8874a927c [file] [log] [blame]
Philippe Mathieu-Daudé00c9a5c2022-12-19 18:09:40 +01001/*
2 * SPDX-License-Identifier: LGPL-2.1-or-later
3 *
4 * QEMU TCG monitor
5 *
6 * Copyright (c) 2003-2005 Fabrice Bellard
7 */
8
9#include "qemu/osdep.h"
Peter Maydelle726acd2023-04-17 17:40:38 +010010#include "qemu/accel.h"
Philippe Mathieu-Daudé00c9a5c2022-12-19 18:09:40 +010011#include "qapi/error.h"
12#include "qapi/type-helpers.h"
13#include "qapi/qapi-commands-machine.h"
14#include "monitor/monitor.h"
15#include "sysemu/cpus.h"
16#include "sysemu/cpu-timers.h"
17#include "sysemu/tcg.h"
Richard Hendersone5b49062023-03-27 18:24:50 -070018#include "tcg/tcg.h"
Philippe Mathieu-Daudé59346602023-09-14 20:57:15 +020019#include "internal-common.h"
Philippe Mathieu-Daudé00c9a5c2022-12-19 18:09:40 +010020
21
22static void dump_drift_info(GString *buf)
23{
24 if (!icount_enabled()) {
25 return;
26 }
27
28 g_string_append_printf(buf, "Host - Guest clock %"PRIi64" ms\n",
29 (cpu_get_clock() - icount_get()) / SCALE_MS);
30 if (icount_align_option) {
31 g_string_append_printf(buf, "Max guest delay %"PRIi64" ms\n",
32 -max_delay / SCALE_MS);
33 g_string_append_printf(buf, "Max guest advance %"PRIi64" ms\n",
34 max_advance / SCALE_MS);
35 } else {
36 g_string_append_printf(buf, "Max guest delay NA\n");
37 g_string_append_printf(buf, "Max guest advance NA\n");
38 }
39}
40
Peter Maydelle726acd2023-04-17 17:40:38 +010041static void dump_accel_info(GString *buf)
42{
43 AccelState *accel = current_accel();
44 bool one_insn_per_tb = object_property_get_bool(OBJECT(accel),
45 "one-insn-per-tb",
46 &error_fatal);
47
48 g_string_append_printf(buf, "Accelerator settings:\n");
49 g_string_append_printf(buf, "one-insn-per-tb: %s\n\n",
50 one_insn_per_tb ? "on" : "off");
51}
52
Philippe Mathieu-Daudé00c9a5c2022-12-19 18:09:40 +010053HumanReadableText *qmp_x_query_jit(Error **errp)
54{
55 g_autoptr(GString) buf = g_string_new("");
56
57 if (!tcg_enabled()) {
58 error_setg(errp, "JIT information is only available with accel=tcg");
59 return NULL;
60 }
61
Peter Maydelle726acd2023-04-17 17:40:38 +010062 dump_accel_info(buf);
Philippe Mathieu-Daudé00c9a5c2022-12-19 18:09:40 +010063 dump_exec_info(buf);
64 dump_drift_info(buf);
65
66 return human_readable_text_from_str(buf);
67}
68
69HumanReadableText *qmp_x_query_opcount(Error **errp)
70{
71 g_autoptr(GString) buf = g_string_new("");
72
73 if (!tcg_enabled()) {
74 error_setg(errp,
75 "Opcode count information is only available with accel=tcg");
76 return NULL;
77 }
78
79 tcg_dump_op_count(buf);
80
81 return human_readable_text_from_str(buf);
82}
83
Philippe Mathieu-Daudé00c9a5c2022-12-19 18:09:40 +010084static void hmp_tcg_register(void)
85{
86 monitor_register_hmp_info_hrt("jit", qmp_x_query_jit);
87 monitor_register_hmp_info_hrt("opcount", qmp_x_query_opcount);
88}
89
90type_init(hmp_tcg_register);