[PATCH 23/29] system: Introduce -sync-quantum command line option

Ruslan Ruslichenko posted 29 patches 1 day, 11 hours ago
[PATCH 23/29] system: Introduce -sync-quantum command line option
Posted by Ruslan Ruslichenko 1 day, 11 hours ago
From: Ruslan Ruslichenko <Ruslan_Ruslichenko@epam.com>

Add a new global option '-sync-quantum' to specify the maximum time
interval, in nanoseconds, between synchronizations with remote peers.

In co-simulation environments (such as QEMU coupled with a SystemC
simulator), time must be synchronized periodically to ensure functional
accuracy. The 'sync-quantum' defines the maximum amount of time QEMU
can simulate ahead of its remote peers before a mandatory synchronization
event (sync packet) occurs.

This value is stored in the global 'global_sync_quantum' variable and
serves as a default hint for device models and Remote Port instances
to manage their simulation time.

Signed-off-by: Edgar E. Iglesias <edgar.iglesias@amd.com>
Signed-off-by: Takahiro Nakata <takahiro.nakata.wr@renesas.com>
Signed-off-by: Ruslan Ruslichenko <Ruslan_Ruslichenko@epam.com>
---
 include/system/system.h |  2 ++
 qemu-options.hx         | 11 +++++++++++
 system/vl.c             |  8 ++++++++
 3 files changed, 21 insertions(+)

diff --git a/include/system/system.h b/include/system/system.h
index 0cd012004d..f187544147 100644
--- a/include/system/system.h
+++ b/include/system/system.h
@@ -59,6 +59,8 @@ extern MlockState mlock_state;
 
 extern const char *machine_path;
 
+extern uint64_t global_sync_quantum;
+
 #define MAX_OPTION_ROMS 16
 typedef struct QEMUOptionRom {
     const char *name;
diff --git a/qemu-options.hx b/qemu-options.hx
index b7dd2a64f0..8ef0c57507 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -765,6 +765,17 @@ SRST
     Preallocate memory when using -mem-path.
 ERST
 
+DEF("sync-quantum", HAS_ARG, QEMU_OPTION_sync_quantum,
+    "-sync-quantum Max time between synchroniation, nanoseconds.\n",
+    QEMU_ARCH_ALL)
+SRST
+``-sync-quantum val``
+    Maximum time between synchronization <val>.
+    This value is used to drive periodic synchronization with remote port peers.
+    It is also used to set device models sync-quantum properties controlling
+    the maximum amount of ahead of time simulation that is prefered (only a hint).
+ERST
+
 DEF("machine-path", HAS_ARG, QEMU_OPTION_machine_path,
     "-machine-path DIR A directory in which to create machine nodes\n",
     QEMU_ARCH_ALL)
diff --git a/system/vl.c b/system/vl.c
index 4750b1cf69..467646c3ff 100644
--- a/system/vl.c
+++ b/system/vl.c
@@ -182,6 +182,7 @@ static QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list);
 static BlockdevOptionsQueue bdo_queue = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue);
 static bool nographic = false;
 static int mem_prealloc; /* force preallocation of physical target memory */
+uint64_t global_sync_quantum;
 const char *machine_path;
 static const char *vga_model = NULL;
 static DisplayOptions dpy;
@@ -3129,6 +3130,13 @@ void qemu_init(int argc, char **argv)
             case QEMU_OPTION_mem_prealloc:
                 mem_prealloc = 1;
                 break;
+            case QEMU_OPTION_sync_quantum:
+                if (qemu_strtou64(optarg, &optarg, 10,
+                                  &global_sync_quantum)) {
+                    error_report("failed to parse sync_quantum");
+                    exit(1);
+                }
+                break;
             case QEMU_OPTION_machine_path:
                 machine_path = optarg;
                 break;
-- 
2.43.0
Re: [PATCH 23/29] system: Introduce -sync-quantum command line option
Posted by Daniel P. Berrangé 1 day, 10 hours ago
On Thu, Feb 05, 2026 at 08:58:18PM +0100, Ruslan Ruslichenko wrote:
> From: Ruslan Ruslichenko <Ruslan_Ruslichenko@epam.com>
> 
> Add a new global option '-sync-quantum' to specify the maximum time
> interval, in nanoseconds, between synchronizations with remote peers.

Again, we don't really want to introduced new top level command
line options, so try to find an existing place that's suitable
to fit this in, perhaps a prop -machine.

> 
> In co-simulation environments (such as QEMU coupled with a SystemC
> simulator), time must be synchronized periodically to ensure functional
> accuracy. The 'sync-quantum' defines the maximum amount of time QEMU
> can simulate ahead of its remote peers before a mandatory synchronization
> event (sync packet) occurs.
> 
> This value is stored in the global 'global_sync_quantum' variable and
> serves as a default hint for device models and Remote Port instances
> to manage their simulation time.
> 
> Signed-off-by: Edgar E. Iglesias <edgar.iglesias@amd.com>
> Signed-off-by: Takahiro Nakata <takahiro.nakata.wr@renesas.com>
> Signed-off-by: Ruslan Ruslichenko <Ruslan_Ruslichenko@epam.com>
> ---
>  include/system/system.h |  2 ++
>  qemu-options.hx         | 11 +++++++++++
>  system/vl.c             |  8 ++++++++
>  3 files changed, 21 insertions(+)
> 
> diff --git a/include/system/system.h b/include/system/system.h
> index 0cd012004d..f187544147 100644
> --- a/include/system/system.h
> +++ b/include/system/system.h
> @@ -59,6 +59,8 @@ extern MlockState mlock_state;
>  
>  extern const char *machine_path;
>  
> +extern uint64_t global_sync_quantum;
> +
>  #define MAX_OPTION_ROMS 16
>  typedef struct QEMUOptionRom {
>      const char *name;
> diff --git a/qemu-options.hx b/qemu-options.hx
> index b7dd2a64f0..8ef0c57507 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -765,6 +765,17 @@ SRST
>      Preallocate memory when using -mem-path.
>  ERST
>  
> +DEF("sync-quantum", HAS_ARG, QEMU_OPTION_sync_quantum,
> +    "-sync-quantum Max time between synchroniation, nanoseconds.\n",
> +    QEMU_ARCH_ALL)
> +SRST
> +``-sync-quantum val``
> +    Maximum time between synchronization <val>.
> +    This value is used to drive periodic synchronization with remote port peers.
> +    It is also used to set device models sync-quantum properties controlling
> +    the maximum amount of ahead of time simulation that is prefered (only a hint).
> +ERST
> +
>  DEF("machine-path", HAS_ARG, QEMU_OPTION_machine_path,
>      "-machine-path DIR A directory in which to create machine nodes\n",
>      QEMU_ARCH_ALL)
> diff --git a/system/vl.c b/system/vl.c
> index 4750b1cf69..467646c3ff 100644
> --- a/system/vl.c
> +++ b/system/vl.c
> @@ -182,6 +182,7 @@ static QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list);
>  static BlockdevOptionsQueue bdo_queue = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue);
>  static bool nographic = false;
>  static int mem_prealloc; /* force preallocation of physical target memory */
> +uint64_t global_sync_quantum;
>  const char *machine_path;
>  static const char *vga_model = NULL;
>  static DisplayOptions dpy;
> @@ -3129,6 +3130,13 @@ void qemu_init(int argc, char **argv)
>              case QEMU_OPTION_mem_prealloc:
>                  mem_prealloc = 1;
>                  break;
> +            case QEMU_OPTION_sync_quantum:
> +                if (qemu_strtou64(optarg, &optarg, 10,
> +                                  &global_sync_quantum)) {
> +                    error_report("failed to parse sync_quantum");
> +                    exit(1);
> +                }
> +                break;
>              case QEMU_OPTION_machine_path:
>                  machine_path = optarg;
>                  break;
> -- 
> 2.43.0
> 
> 

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
Re: [PATCH 23/29] system: Introduce -sync-quantum command line option
Posted by Ruslan Ruslichenko 13 hours ago
On Thu, Feb 5, 2026 at 9:41 PM Daniel P. Berrangé <berrange@redhat.com> wrote:
>
> On Thu, Feb 05, 2026 at 08:58:18PM +0100, Ruslan Ruslichenko wrote:
> > From: Ruslan Ruslichenko <Ruslan_Ruslichenko@epam.com>
> >
> > Add a new global option '-sync-quantum' to specify the maximum time
> > interval, in nanoseconds, between synchronizations with remote peers.
>
> Again, we don't really want to introduced new top level command
> line options, so try to find an existing place that's suitable
> to fit this in, perhaps a prop -machine.
>

Understood, not sure machine options are applicable here,
but encapsulating it within remote-port itself may be possible. I will
investigate it for v2.

> >
> > In co-simulation environments (such as QEMU coupled with a SystemC
> > simulator), time must be synchronized periodically to ensure functional
> > accuracy. The 'sync-quantum' defines the maximum amount of time QEMU
> > can simulate ahead of its remote peers before a mandatory synchronization
> > event (sync packet) occurs.
> >
> > This value is stored in the global 'global_sync_quantum' variable and
> > serves as a default hint for device models and Remote Port instances
> > to manage their simulation time.
> >
> > Signed-off-by: Edgar E. Iglesias <edgar.iglesias@amd.com>
> > Signed-off-by: Takahiro Nakata <takahiro.nakata.wr@renesas.com>
> > Signed-off-by: Ruslan Ruslichenko <Ruslan_Ruslichenko@epam.com>
> > ---
> >  include/system/system.h |  2 ++
> >  qemu-options.hx         | 11 +++++++++++
> >  system/vl.c             |  8 ++++++++
> >  3 files changed, 21 insertions(+)
> >
> > diff --git a/include/system/system.h b/include/system/system.h
> > index 0cd012004d..f187544147 100644
> > --- a/include/system/system.h
> > +++ b/include/system/system.h
> > @@ -59,6 +59,8 @@ extern MlockState mlock_state;
> >
> >  extern const char *machine_path;
> >
> > +extern uint64_t global_sync_quantum;
> > +
> >  #define MAX_OPTION_ROMS 16
> >  typedef struct QEMUOptionRom {
> >      const char *name;
> > diff --git a/qemu-options.hx b/qemu-options.hx
> > index b7dd2a64f0..8ef0c57507 100644
> > --- a/qemu-options.hx
> > +++ b/qemu-options.hx
> > @@ -765,6 +765,17 @@ SRST
> >      Preallocate memory when using -mem-path.
> >  ERST
> >
> > +DEF("sync-quantum", HAS_ARG, QEMU_OPTION_sync_quantum,
> > +    "-sync-quantum Max time between synchroniation, nanoseconds.\n",
> > +    QEMU_ARCH_ALL)
> > +SRST
> > +``-sync-quantum val``
> > +    Maximum time between synchronization <val>.
> > +    This value is used to drive periodic synchronization with remote port peers.
> > +    It is also used to set device models sync-quantum properties controlling
> > +    the maximum amount of ahead of time simulation that is prefered (only a hint).
> > +ERST
> > +
> >  DEF("machine-path", HAS_ARG, QEMU_OPTION_machine_path,
> >      "-machine-path DIR A directory in which to create machine nodes\n",
> >      QEMU_ARCH_ALL)
> > diff --git a/system/vl.c b/system/vl.c
> > index 4750b1cf69..467646c3ff 100644
> > --- a/system/vl.c
> > +++ b/system/vl.c
> > @@ -182,6 +182,7 @@ static QemuPluginList plugin_list = QTAILQ_HEAD_INITIALIZER(plugin_list);
> >  static BlockdevOptionsQueue bdo_queue = QSIMPLEQ_HEAD_INITIALIZER(bdo_queue);
> >  static bool nographic = false;
> >  static int mem_prealloc; /* force preallocation of physical target memory */
> > +uint64_t global_sync_quantum;
> >  const char *machine_path;
> >  static const char *vga_model = NULL;
> >  static DisplayOptions dpy;
> > @@ -3129,6 +3130,13 @@ void qemu_init(int argc, char **argv)
> >              case QEMU_OPTION_mem_prealloc:
> >                  mem_prealloc = 1;
> >                  break;
> > +            case QEMU_OPTION_sync_quantum:
> > +                if (qemu_strtou64(optarg, &optarg, 10,
> > +                                  &global_sync_quantum)) {
> > +                    error_report("failed to parse sync_quantum");
> > +                    exit(1);
> > +                }
> > +                break;
> >              case QEMU_OPTION_machine_path:
> >                  machine_path = optarg;
> >                  break;
> > --
> > 2.43.0
> >
> >
>
> With regards,
> Daniel
> --
> |: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org         -o-            https://fstop138.berrange.com :|
> |: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
>

--
BR,
Ruslan