xref: /openbmc/qemu/accel/tcg/monitor.c (revision 0489d5bd)
1 /*
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"
10 #include "qapi/error.h"
11 #include "qapi/type-helpers.h"
12 #include "qapi/qapi-commands-machine.h"
13 #include "monitor/monitor.h"
14 #include "sysemu/cpus.h"
15 #include "sysemu/cpu-timers.h"
16 #include "sysemu/tcg.h"
17 #include "internal.h"
18 
19 
20 static void dump_drift_info(GString *buf)
21 {
22     if (!icount_enabled()) {
23         return;
24     }
25 
26     g_string_append_printf(buf, "Host - Guest clock  %"PRIi64" ms\n",
27                            (cpu_get_clock() - icount_get()) / SCALE_MS);
28     if (icount_align_option) {
29         g_string_append_printf(buf, "Max guest delay     %"PRIi64" ms\n",
30                                -max_delay / SCALE_MS);
31         g_string_append_printf(buf, "Max guest advance   %"PRIi64" ms\n",
32                                max_advance / SCALE_MS);
33     } else {
34         g_string_append_printf(buf, "Max guest delay     NA\n");
35         g_string_append_printf(buf, "Max guest advance   NA\n");
36     }
37 }
38 
39 HumanReadableText *qmp_x_query_jit(Error **errp)
40 {
41     g_autoptr(GString) buf = g_string_new("");
42 
43     if (!tcg_enabled()) {
44         error_setg(errp, "JIT information is only available with accel=tcg");
45         return NULL;
46     }
47 
48     dump_exec_info(buf);
49     dump_drift_info(buf);
50 
51     return human_readable_text_from_str(buf);
52 }
53 
54 HumanReadableText *qmp_x_query_opcount(Error **errp)
55 {
56     g_autoptr(GString) buf = g_string_new("");
57 
58     if (!tcg_enabled()) {
59         error_setg(errp,
60                    "Opcode count information is only available with accel=tcg");
61         return NULL;
62     }
63 
64     tcg_dump_op_count(buf);
65 
66     return human_readable_text_from_str(buf);
67 }
68 
69 #ifdef CONFIG_PROFILER
70 
71 int64_t dev_time;
72 
73 HumanReadableText *qmp_x_query_profile(Error **errp)
74 {
75     g_autoptr(GString) buf = g_string_new("");
76     static int64_t last_cpu_exec_time;
77     int64_t cpu_exec_time;
78     int64_t delta;
79 
80     cpu_exec_time = tcg_cpu_exec_time();
81     delta = cpu_exec_time - last_cpu_exec_time;
82 
83     g_string_append_printf(buf, "async time  %" PRId64 " (%0.3f)\n",
84                            dev_time, dev_time / (double)NANOSECONDS_PER_SECOND);
85     g_string_append_printf(buf, "qemu time   %" PRId64 " (%0.3f)\n",
86                            delta, delta / (double)NANOSECONDS_PER_SECOND);
87     last_cpu_exec_time = cpu_exec_time;
88     dev_time = 0;
89 
90     return human_readable_text_from_str(buf);
91 }
92 #else
93 HumanReadableText *qmp_x_query_profile(Error **errp)
94 {
95     error_setg(errp, "Internal profiler not compiled");
96     return NULL;
97 }
98 #endif
99 
100 static void hmp_tcg_register(void)
101 {
102     monitor_register_hmp_info_hrt("jit", qmp_x_query_jit);
103     monitor_register_hmp_info_hrt("opcount", qmp_x_query_opcount);
104 }
105 
106 type_init(hmp_tcg_register);
107