Skip to content

Commit 1d3e745

Browse files
committed
plugins/api: split out time control helpers
These are only usable in system mode where we control the timer. For user-mode make them NOPs. Reviewed-by: Richard Henderson <[email protected]> Signed-off-by: Alex Bennée <[email protected]> Message-Id: <[email protected]>
1 parent 455a2d2 commit 1d3e745

File tree

3 files changed

+51
-41
lines changed

3 files changed

+51
-41
lines changed

plugins/api-system.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,37 @@ const char *qemu_plugin_hwaddr_device_name(const struct qemu_plugin_hwaddr *h)
9595
return g_intern_static_string("RAM");
9696
}
9797
}
98+
99+
/*
100+
* Time control
101+
*/
102+
static bool has_control;
103+
static Error *migration_blocker;
104+
105+
const void *qemu_plugin_request_time_control(void)
106+
{
107+
if (!has_control) {
108+
has_control = true;
109+
error_setg(&migration_blocker,
110+
"TCG plugin time control does not support migration");
111+
migrate_add_blocker(&migration_blocker, NULL);
112+
return &has_control;
113+
}
114+
return NULL;
115+
}
116+
117+
static void advance_virtual_time__async(CPUState *cpu, run_on_cpu_data data)
118+
{
119+
int64_t new_time = data.host_ulong;
120+
qemu_clock_advance_virtual_time(new_time);
121+
}
122+
123+
void qemu_plugin_update_ns(const void *handle, int64_t new_time)
124+
{
125+
if (handle == &has_control) {
126+
/* Need to execute out of cpu_exec, so bql can be locked. */
127+
async_run_on_cpu(current_cpu,
128+
advance_virtual_time__async,
129+
RUN_ON_CPU_HOST_ULONG(new_time));
130+
}
131+
}

plugins/api-user.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "qemu/osdep.h"
1414
#include "qemu/plugin.h"
15+
#include "exec/log.h"
1516

1617
/*
1718
* Virtual Memory queries - these are all NOPs for user-mode which
@@ -38,3 +39,19 @@ const char *qemu_plugin_hwaddr_device_name(const struct qemu_plugin_hwaddr *h)
3839
{
3940
return g_intern_static_string("Invalid");
4041
}
42+
43+
/*
44+
* Time control - for user mode the only real time is wall clock time
45+
* so realistically all you can do in user mode is slow down execution
46+
* which doesn't require the ability to mess with the clock.
47+
*/
48+
49+
const void *qemu_plugin_request_time_control(void)
50+
{
51+
return NULL;
52+
}
53+
54+
void qemu_plugin_update_ns(const void *handle, int64_t new_time)
55+
{
56+
qemu_log_mask(LOG_UNIMP, "user-mode can't control time");
57+
}

plugins/api.c

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -526,44 +526,3 @@ uint64_t qemu_plugin_u64_sum(qemu_plugin_u64 entry)
526526
return total;
527527
}
528528

529-
/*
530-
* Time control
531-
*/
532-
static bool has_control;
533-
#ifdef CONFIG_SOFTMMU
534-
static Error *migration_blocker;
535-
#endif
536-
537-
const void *qemu_plugin_request_time_control(void)
538-
{
539-
if (!has_control) {
540-
has_control = true;
541-
#ifdef CONFIG_SOFTMMU
542-
error_setg(&migration_blocker,
543-
"TCG plugin time control does not support migration");
544-
migrate_add_blocker(&migration_blocker, NULL);
545-
#endif
546-
return &has_control;
547-
}
548-
return NULL;
549-
}
550-
551-
#ifdef CONFIG_SOFTMMU
552-
static void advance_virtual_time__async(CPUState *cpu, run_on_cpu_data data)
553-
{
554-
int64_t new_time = data.host_ulong;
555-
qemu_clock_advance_virtual_time(new_time);
556-
}
557-
#endif
558-
559-
void qemu_plugin_update_ns(const void *handle, int64_t new_time)
560-
{
561-
#ifdef CONFIG_SOFTMMU
562-
if (handle == &has_control) {
563-
/* Need to execute out of cpu_exec, so bql can be locked. */
564-
async_run_on_cpu(current_cpu,
565-
advance_virtual_time__async,
566-
RUN_ON_CPU_HOST_ULONG(new_time));
567-
}
568-
#endif
569-
}

0 commit comments

Comments
 (0)