Skip to contentSkip to conversation

qqq: module for synchronizing with a simulation clock

PATCH Superseded James J. Nutaro 2 participants 2 messages Sep 6, 2016 Kbuild

v2 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 qqq: module for synchronizing with a simulation clock

This module enables QEMU running in the icount mode to synchronize the emulator's rtc with the simulation time in some external simulation pacakge.

Signed-off by: James J. Nutaro <[email protected]>

---
 Makefile.target          |   3 ++
 docs/simulation-sync.txt |  60 ++++++++++++++++++++++++++
 qemu-options.hx          |  16 +++++++
 qqq.c                    | 109 +++++++++++++++++++++++++++++++++++++++++++++++
 qqq.h                    |  35 +++++++++++++++
 vl.c                     |  33 +++++++++++++-
 6 files changed, 255 insertions(+), 1 deletion(-)
 create mode 100644 docs/simulation-sync.txt
 create mode 100644 qqq.c
 create mode 100644 qqq.h
Makefile.target +3 -0
index 8c7a072..b7f6c4c 100644
@@ -103,6 +103,9 @@ obj-$(CONFIG_LIBDECNUMBER) += libdecnumber/dpd/decimal32.o
 obj-$(CONFIG_LIBDECNUMBER) += libdecnumber/dpd/decimal64.o
 obj-$(CONFIG_LIBDECNUMBER) += libdecnumber/dpd/decimal128.o
 
+# qqq
+obj-y += qqq.o
+
 #########################################################
 # Linux user emulator target
 
docs/simulation-sync.txt new file +60 -0

60 lines not on this page · raw message

qemu-options.hx +16 -0
index a71aaf8..d52cc9c 100644
@@ -3359,6 +3359,22 @@ many timer interrupts were not processed by the Windows guest and will
 re-inject them.
 ETEXI
 
+DEF("qqq", HAS_ARG, QEMU_OPTION_qqq, \
+    "-qqq read=fd,write=fd\n" \
+    "                enable synchronization of the virtual clock \n" \
+    "                with an external simulation clock\n", QEMU_ARCH_ALL)
+STEXI
+@item -qqq read=@var{fd0},write=@var{fd1}
+@findex -qqq
+Qemu will use the supplied pipes to synchronize its virtual clock with
+an external simulation clock. Qemu will wait until a time slice size in
+microseconds is supplied on the read pipe. Then it will execute for at
+least that number of virtual microseconds before writing the actual
+virtual time that has elapsed in microseconds to the write pipe. This
+cycle will repeat until a zero is elaspsed time is requested, which
+will cause qemu to exit.
+ETEXI
+
 DEF("icount", HAS_ARG, QEMU_OPTION_icount, \
     "-icount [shift=N|auto][,align=on|off][,sleep=on|off,rr=record|replay,rrfile=<filename>]\n" \
     "                enable virtual instruction counter with 2^N clock ticks per\n" \
qqq.c new file +109 -0

109 lines not on this page · raw message

qqq.h new file +35 -0
new file mode 100644
index 0000000..40a24e3
@@ -0,0 +1,35 @@
+/*
+ * This work is licensed under the terms of the GNU GPL
+ * version 2. Seethe COPYING file in the top-level directory.
+ *
+ * A module for pacing the rate of advance of the computer
+ * clock in reference to an external simulation clock. The
+ * basic approach used here is adapted from QBox from Green
+ * Socs. The mode of operation is as follows:
+ *
+ * The simulator uses pipes to exchange time advance data.
+ * The external simulator starts the exchange by forking a
+ * QEMU process and passing is descriptors for a read and
+ * write pipe. Then the external simulator writes an integer
+ * (native endian) to the pipe to indicate the number of
+ * microseconds that QEMU should advance. QEMU advances its
+ * virtual clock by this amount and writes to its write pipe
+ * the actual number of microseconds that have advanced.
+ * This process continues until a pipe on either side is
+ * closed, which will either cause QEMU to exit (if the
+ * external simulator closes a pipe) or raise SIGPIPE in the
+ * external simulator (if QEMU closes a pipe).
+ *
+ * Authors:
+ *   James Nutaro <[email protected]>
+ *
+ */
+#ifndef QQQ_H
+#define QQQ_H
+
+#include "qemu/osdep.h"
+#include "qemu-options.h"
+
+void setup_qqq(QemuOpts *opts);
+
+#endif
vl.c +32 -1
index ee557a1..3f2f9a3 100644
@@ -122,6 +122,8 @@ int main(int argc, char **argv)
 #include "sysemu/replay.h"
 #include "qapi/qmp/qerror.h"
 
+#include "qqq.h"
+
 #define MAX_VIRTIO_CONSOLES 1
 #define MAX_SCLP_CONSOLES 1
 
@@ -231,6 +233,23 @@ static struct {
     { .driver = "virtio-vga",           .flag = &default_vga       },
 };
 
+static QemuOptsList qemu_qqq_opts = {
+    .name = "qqq",
+    .implied_opt_name = "",
+    .merge_lists = true,
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_qqq_opts.head),
+    .desc = {
+        {
+            .name = "read",
+            .type = QEMU_OPT_NUMBER,
+        }, {
+            .name = "write",
+            .type = QEMU_OPT_NUMBER,
+        },
+        { /* end of list */ }
+    },
+};
+
 static QemuOptsList qemu_rtc_opts = {
     .name = "rtc",
     .head = QTAILQ_HEAD_INITIALIZER(qemu_rtc_opts.head),
@@ -2951,7 +2970,7 @@ int main(int argc, char **argv, char **envp)
     const char *boot_once = NULL;
     DisplayState *ds;
     int cyls, heads, secs, translation;
-    QemuOpts *hda_opts = NULL, *opts, *machine_opts, *icount_opts = NULL;
+    QemuOpts *hda_opts = NULL, *opts, *machine_opts, *icount_opts = NULL, *qqq_opts = NULL;
     QemuOptsList *olist;
     int optind;
     const char *optarg;
@@ -2987,6 +3006,7 @@ int main(int argc, char **argv, char **envp)
 
     module_call_init(MODULE_INIT_QOM);
 
+    qemu_add_opts(&qemu_qqq_opts);
     qemu_add_opts(&qemu_drive_opts);
     qemu_add_drive_opts(&qemu_legacy_drive_opts);
     qemu_add_drive_opts(&qemu_common_drive_opts);
@@ -3847,6 +3867,13 @@ int main(int argc, char **argv, char **envp)
                     exit(1);
                 }
                 break;
+            case QEMU_OPTION_qqq:
+                qqq_opts = qemu_opts_parse_noisily(qemu_find_opts("qqq"),
+                                                      optarg, true);
+                if (!qqq_opts) {
+                    exit(1);
+                }
+                break;
             case QEMU_OPTION_incoming:
                 if (!incoming) {
                     runstate_set(RUN_STATE_INMIGRATE);
@@ -4350,6 +4377,10 @@ int main(int argc, char **argv, char **envp)
     /* spice needs the timers to be initialized by this point */
     qemu_spice_init();
 
+    if (qqq_opts) {
+        setup_qqq(qqq_opts);
+    }
+
     cpu_ticks_init();
     if (icount_opts) {
         if (kvm_enabled() || xen_enabled()) {
Signature · 1 line
2.5.0
#1 lore raw
Your series seems to have some coding style problems. See output below for more information:

Hi,

Your series seems to have some coding style problems. See output below for more information:

Subject: [Qemu-devel] [PATCH v2] qqq: module for synchronizing with a simulation clock
Type: series
Message-id: [email protected]

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git show --no-patch --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 Switched to a new branch 'test'
88bc925 qqq: module for synchronizing with a simulation clock

=== OUTPUT BEGIN ===
Checking PATCH 1/1: qqq: module for synchronizing with a simulation clock...
ERROR: do not initialise statics to 0 or NULL
#140: FILE: qqq.c:16:
+static int elapsed = 0;

ERROR: "foo* bar" should be "foo *bar"
#201: FILE: qqq.c:77:
+static void fd_read(void* opaque)

ERROR: trailing whitespace
#206: FILE: qqq.c:82:
+} $

ERROR: space required after that ',' (ctx:VxV)
#222: FILE: qqq.c:98:

+    qemu_set_fd_handler(read_fd,fd_read,NULL,NULL);
                                ^

ERROR: space required after that ',' (ctx:VxV)
#222: FILE: qqq.c:98:

+    qemu_set_fd_handler(read_fd,fd_read,NULL,NULL);
                                        ^

ERROR: space required after that ',' (ctx:VxV)
#222: FILE: qqq.c:98:

+    qemu_set_fd_handler(read_fd,fd_read,NULL,NULL);
                                             ^

ERROR: line over 90 characters
#317: FILE: vl.c:2973:
+ QemuOpts *hda_opts = NULL, *opts, *machine_opts, *icount_opts = NULL, *qqq_opts = NULL;

ERROR: Missing Signed-off-by: line(s)

total: 8 errors, 0 warnings, 304 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]