Skip to contentSkip to conversation

Introduce attributes for timers subsystem and remove QEMU_CLOCK_VIRTUAL_EXT clock type

PATCH Superseded Artem Pisarenko 4 participants 13 messages Oct 17, 2018 – Oct 18, 2018

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Introduce attributes for timers subsystem and remove QEMU_CLOCK_VIRTUAL_EXT clock type

Recent patches from series [PATCH v6] "Fixing record/replay and adding reverse debugging" introduced new clock type QEMU_CLOCK_VIRTUAL_EXT and replaced virtual timers in some external subsystems with it.
This resulted in small change to existing behavior, which I consider to be unacceptable.
Processing of virtual timers, belonging to new clock type, was kicked off to main loop, which made them asynchronous with vCPU thread and, in icount mode, with whole guest execution. This breaks expected determinism in non-record/replay icount mode of emulation where these "external subsystems" are isolated from host (i.e. they external only to guest core, not to emulation environment).

Example for slirp ("user" backend for network device):
User runs qemu in icount mode with rtc clock=vm without any external communication interfaces but with "-netdev user,restrict=on". It expects deterministic execution, because network services are emulated inside qemu and isolated from host. There are no reasons to get reply from DHCP server with different delay or something like that.

These series of patches revert those commits and reimplement their modifications in a better way.

Current implementation of timers/clock processing is confusing (at least for me) because of exceptions from design concept behind them, which already introduced by icount mode (which adds QEMU_CLOCK_VIRTUAL_RT). Adding QEMU_CLOCK_VIRTUAL_EXT just made things even more complicated. I consider these "alternative" virtual clocks to be some kind of hacks being convinient only to authors of relevant qemu features. Lets don't touch fundamental clock types and keep them orthogonal to special cases of timers handling.

As far as I understand, original intention of author was just to make optimization in replay log by avoiding storing extra events which don't change guest state directly. Indeed, for example, ipv6 icmp timer in slirp does things which external to guest core and ends with sending network packet to guest, but record/replay will anyway catch event, corresponding to packet reception in guest network frontend, and store it to replay log, so there are no need in making checkpoint for corresponding clock when that timer fires. If so, then we just need to skip checkpoints for clock values, when only these specific timers are run. It is individual timers which are specific, not clock.
Adding some kind of attribute/flag/property to individual timer allows any special qemu feature (such as record/replay) to inspect it in any place of code and handle as needed. This design acheives less dependencies, more transparency and has more intuitive and clear sense. For record/replay feature it's acheived with 'EXTERNAL' attribute. The only drawback is that it required to add one extra mutex unlock/lock pair for virtual clock type in timerlist_run_timers() function (see patch 3), but it's being added only when qemu runs in record/replay mode.

Finally, this patch series optimizes checkpointing for all other clocks it applies to.

v2 changes:
- timers/aio interface refactored and improved, addition to couroutines removed (as Paolo Bonzini suggested)
- fixed wrong reimplementation in qemu-timer.c caused race conditions
- added bonus patch which optimizes checkpointing for other clocks

P.S. I've tried to test record/replay with slirp, but in replay mode qemu stucks at guest linux boot after "Configuring network interfaces..." message, where DHCP communication takes place. It's broken in a same way both in master and master with reverted commits being fixed.

P.S.2. I wasn't able to test these patches on purely clean master branch because of bugs https://bugs.launchpad.net/qemu/+bug/1790460 and https://bugs.launchpad.net/qemu/+bug/1795369, which workarounded by several not-accepted (yet?) modifications.

Artem Pisarenko (4):
Revert some patches from recent [PATCH v6] "Fixing record/replay and
adding reverse debugging"
Introduce attributes to qemu timer subsystem
Restores record/replay behavior related to special virtual clock
processing for timers used in external subsystems.
Optimize record/replay checkpointing for all clocks it applies to

 include/block/aio.h       |  57 +++++++++++++++---
 include/qemu/timer.h      | 143 +++++++++++++++++++++++++---------------------
 slirp/ip6_icmp.c          |   9 +--
 tests/ptimer-test-stubs.c |  13 +++--
 ui/input.c                |   9 +--
 util/qemu-timer.c         | 100 ++++++++++++++++++++++----------
 6 files changed, 219 insertions(+), 112 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/4 Revert some patches from recent [PATCH v6] "Fixing record/replay and adding reverse debugging"

That patch series introduced new virtual clock type for use in external subsystems. It breaks desired behavior in non-record/replay usage scenarios.

This reverts commit 87f4fe7653baf55b5c2f2753fe6003f473c07342. This reverts commit 775a412bf83f6bc0c5c02091ee06cf649b34c593. This reverts commit 9888091404a702d7ec79d51b088d994b9fc121bd.

---
 include/qemu/timer.h | 9 ---------
 slirp/ip6_icmp.c     | 7 +++----
 ui/input.c           | 8 ++++----
 util/qemu-timer.c    | 2 --
 4 files changed, 7 insertions(+), 19 deletions(-)
include/qemu/timer.h +0 -9
index a005ed2..39ea907 100644
@@ -42,14 +42,6 @@
  * In icount mode, this clock counts nanoseconds while the virtual
  * machine is running.  It is used to increase @QEMU_CLOCK_VIRTUAL
  * while the CPUs are sleeping and thus not executing instructions.
- *
- * @QEMU_CLOCK_VIRTUAL_EXT: virtual clock for external subsystems
- *
- * The virtual clock only runs during the emulation. It stops
- * when the virtual machine is stopped. The timers for this clock
- * do not recorded in rr mode, therefore this clock could be used
- * for the subsystems that operate outside the guest core.
- *
  */
 
 typedef enum {
@@ -57,7 +49,6 @@ typedef enum {
     QEMU_CLOCK_VIRTUAL = 1,
     QEMU_CLOCK_HOST = 2,
     QEMU_CLOCK_VIRTUAL_RT = 3,
-    QEMU_CLOCK_VIRTUAL_EXT = 4,
     QEMU_CLOCK_MAX
 } QEMUClockType;
 
slirp/ip6_icmp.c +3 -4
index 3f41187..ee333d0 100644
@@ -17,7 +17,7 @@ static void ra_timer_handler(void *opaque)
 {
     Slirp *slirp = opaque;
     timer_mod(slirp->ra_timer,
-              qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_EXT) + NDP_Interval);
+              qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NDP_Interval);
     ndp_send_ra(slirp);
 }
 
@@ -27,10 +27,9 @@ void icmp6_init(Slirp *slirp)
         return;
     }
 
-    slirp->ra_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL_EXT,
-                                   ra_timer_handler, slirp);
+    slirp->ra_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, ra_timer_handler, slirp);
     timer_mod(slirp->ra_timer,
-              qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_EXT) + NDP_Interval);
+              qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NDP_Interval);
 }
 
 void icmp6_cleanup(Slirp *slirp)
ui/input.c +4 -4
index dd7f6d7..51b1019 100644
@@ -271,7 +271,7 @@ static void qemu_input_queue_process(void *opaque)
         item = QTAILQ_FIRST(queue);
         switch (item->type) {
         case QEMU_INPUT_QUEUE_DELAY:
-            timer_mod(item->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_EXT)
+            timer_mod(item->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL)
                       + item->delay_ms);
             return;
         case QEMU_INPUT_QUEUE_EVENT:
@@ -301,7 +301,7 @@ static void qemu_input_queue_delay(struct QemuInputEventQueueHead *queue,
     queue_count++;
 
     if (start_timer) {
-        timer_mod(item->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_EXT)
+        timer_mod(item->timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL)
                   + item->delay_ms);
     }
 }
@@ -448,8 +448,8 @@ void qemu_input_event_send_key_delay(uint32_t delay_ms)
     }
 
     if (!kbd_timer) {
-        kbd_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL_EXT,
-                                 qemu_input_queue_process, &kbd_queue);
+        kbd_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, qemu_input_queue_process,
+                                 &kbd_queue);
     }
     if (queue_count < queue_limit) {
         qemu_input_queue_delay(&kbd_queue, kbd_timer,
util/qemu-timer.c +0 -2
index eb60d8f..86bfe84 100644
@@ -496,7 +496,6 @@ bool timerlist_run_timers(QEMUTimerList *timer_list)
 
     switch (timer_list->clock->type) {
     case QEMU_CLOCK_REALTIME:
-    case QEMU_CLOCK_VIRTUAL_EXT:
         break;
     default:
     case QEMU_CLOCK_VIRTUAL:
@@ -598,7 +597,6 @@ int64_t qemu_clock_get_ns(QEMUClockType type)
         return get_clock();
     default:
     case QEMU_CLOCK_VIRTUAL:
-    case QEMU_CLOCK_VIRTUAL_EXT:
         if (use_icount) {
             return cpu_get_icount();
         } else {
Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 2/4 Introduce attributes to qemu timer subsystem

In reply to Artem Pisarenko

Attributes are simple flags, associated with individual timers for their whole lifetime.
They intended to be used to mark individual timers for special handling by various qemu features operating at qemu core level.
New/init functions family in timer interface updated and refactored (new 'attribute' argument added, timer_list replaced with timer_list_group+type combinations, comments improved to avoid info duplication). Also existing aio interface extended with attribute-enabled variants of functions, which create/initialize timers.

---

Notes:
v2:
- timer creation/initialize functions reworked and and their unnecessary variants removed (as Paolo Bonzini suggested)
- also their comments improved to avoid info duplication

 include/block/aio.h       |  57 ++++++++++++++++++---
 include/qemu/timer.h      | 128 ++++++++++++++++++++++++++--------------------
 tests/ptimer-test-stubs.c |  13 +++--
 util/qemu-timer.c         |  18 +++++--
 4 files changed, 146 insertions(+), 70 deletions(-)
include/block/aio.h +50 -7
index f08630c..fce9d48 100644
@@ -388,6 +388,31 @@ struct LinuxAioState *aio_setup_linux_aio(AioContext *ctx, Error **errp);
 struct LinuxAioState *aio_get_linux_aio(AioContext *ctx);
 
 /**
+ * aio_timer_new_with_attrs:
+ * @ctx: the aio context
+ * @type: the clock type
+ * @scale: the scale
+ * @attributes: 0, or one to multiple OR'ed QEMU_TIMER_ATTR(id) values to assign
+ * @cb: the callback to call on timer expiry
+ * @opaque: the opaque pointer to pass to the callback
+ *
+ * Allocate a new timer (with attributes) attached to the context @ctx.
+ * The function is responsible for memory allocation.
+ *
+ * The preferred interface is aio_timer_init or aio_timer_init_with_attrs.
+ * Use that unless you really need dynamic memory allocation.
+ *
+ * Returns: a pointer to the new timer
+ */
+static inline QEMUTimer *aio_timer_new_with_attrs(AioContext *ctx,
+                                                  QEMUClockType type,
+                                                  int scale, int attributes,
+                                                  QEMUTimerCB *cb, void *opaque)
+{
+    return timer_new_full(&ctx->tlg, type, scale, attributes, cb, opaque);
+}
+
+/**
  * aio_timer_new:
  * @ctx: the aio context
  * @type: the clock type
@@ -396,10 +421,7 @@ struct LinuxAioState *aio_get_linux_aio(AioContext *ctx);
  * @opaque: the opaque pointer to pass to the callback
  *
  * Allocate a new timer attached to the context @ctx.
- * The function is responsible for memory allocation.
- *
- * The preferred interface is aio_timer_init. Use that
- * unless you really need dynamic memory allocation.
+ * See aio_timer_new_with_attrs for details.
  *
  * Returns: a pointer to the new timer
  */
@@ -407,7 +429,28 @@ static inline QEMUTimer *aio_timer_new(AioContext *ctx, QEMUClockType type,
                                        int scale,
                                        QEMUTimerCB *cb, void *opaque)
 {
-    return timer_new_tl(ctx->tlg.tl[type], scale, cb, opaque);
+    return timer_new_full(&ctx->tlg, type, scale, 0, cb, opaque);
+}
+
+/**
+ * aio_timer_init_with_attrs:
+ * @ctx: the aio context
+ * @ts: the timer
+ * @type: the clock type
+ * @scale: the scale
+ * @attributes: 0, or one to multiple OR'ed QEMU_TIMER_ATTR(id) values to assign
+ * @cb: the callback to call on timer expiry
+ * @opaque: the opaque pointer to pass to the callback
+ *
+ * Initialise a new timer (with attributes) attached to the context @ctx.
+ * The caller is responsible for memory allocation.
+ */
+static inline void aio_timer_init_with_attrs(AioContext *ctx,
+                                             QEMUTimer *ts, QEMUClockType type,
+                                             int scale, int attributes,
+                                             QEMUTimerCB *cb, void *opaque)
+{
+    timer_init_full(ts, &ctx->tlg, type, scale, attributes, cb, opaque);
 }
 
 /**
@@ -420,14 +463,14 @@ static inline QEMUTimer *aio_timer_new(AioContext *ctx, QEMUClockType type,
  * @opaque: the opaque pointer to pass to the callback
  *
  * Initialise a new timer attached to the context @ctx.
- * The caller is responsible for memory allocation.
+ * See aio_timer_init_with_attrs for details.
  */
 static inline void aio_timer_init(AioContext *ctx,
                                   QEMUTimer *ts, QEMUClockType type,
                                   int scale,
                                   QEMUTimerCB *cb, void *opaque)
 {
-    timer_init_tl(ts, ctx->tlg.tl[type], scale, cb, opaque);
+    timer_init_full(ts, &ctx->tlg, type, scale, 0, cb, opaque);
 }
 
 /**
include/qemu/timer.h +73 -55

242 lines not on this page · raw message

tests/ptimer-test-stubs.c +9 -4
index ca5cc3b..54b3fd2 100644
@@ -34,14 +34,19 @@ int64_t ptimer_test_time_ns;
 int use_icount = 1;
 bool qtest_allowed;
 
-void timer_init_tl(QEMUTimer *ts,
-                   QEMUTimerList *timer_list, int scale,
-                   QEMUTimerCB *cb, void *opaque)
+void timer_init_full(QEMUTimer *ts,
+                     QEMUTimerListGroup *timer_list_group, QEMUClockType type,
+                     int scale, int attributes,
+                     QEMUTimerCB *cb, void *opaque)
 {
-    ts->timer_list = timer_list;
+    if (!timer_list_group) {
+        timer_list_group = &main_loop_tlg;
+    }
+    ts->timer_list = timer_list_group->tl[type];
     ts->cb = cb;
     ts->opaque = opaque;
     ts->scale = scale;
+    ts->attributes = attributes;
     ts->expire_time = -1;
 }
 
util/qemu-timer.c +14 -4
index 86bfe84..2046b68 100644
@@ -339,17 +339,27 @@ int qemu_poll_ns(GPollFD *fds, guint nfds, int64_t timeout)
 }
 
 
-void timer_init_tl(QEMUTimer *ts,
-                   QEMUTimerList *timer_list, int scale,
-                   QEMUTimerCB *cb, void *opaque)
+void timer_init_full(QEMUTimer *ts,
+                     QEMUTimerListGroup *timer_list_group, QEMUClockType type,
+                     int scale, int attributes,
+                     QEMUTimerCB *cb, void *opaque)
 {
-    ts->timer_list = timer_list;
+    if (!timer_list_group) {
+        timer_list_group = &main_loop_tlg;
+    }
+    ts->timer_list = timer_list_group->tl[type];
     ts->cb = cb;
     ts->opaque = opaque;
     ts->scale = scale;
+    ts->attributes = attributes;
     ts->expire_time = -1;
 }
 
+int timer_get_attributes(QEMUTimer *ts)
+{
+    return ts->attributes;
+}
+
 void timer_deinit(QEMUTimer *ts)
 {
     assert(ts->expire_time == -1);
Signature · 1 line
2.7.4
#3 lore raw

Re: [Qemu-devel] [Qemu-block] [PATCH v2 2/4] Introduce attributes to qemu timer subsystem

Quoted 2 lines · Artem Pisarenko

Attributes are simple flags, associated with individual timers for their whole lifetime.
They intended to be used to mark individual timers for special handling by various qemu features operating at qemu core level.

I'm worried that this sentence suggests various parts of QEMU will stash state in ts->attributes. That's messy and they shouldn't do this. Make the field private to qemu-timer.c.

Attributes should only affect qemu-timer.c behavior. Other parts of QEMU should not act differently based on timer attributes (i.e. checking bits). If they need to do that then it suggests something isn't properly encapsulated in qemu-timer.c.

include/block/aio.h struct LinuxAioState *aio_setup_linux_aio(AioContext *ctx, Error **errp); · line 395

Quoted 13 lines
include/block/aio.h +5 -0
index f08630c..fce9d48 100644
@@ -388,6 +388,31 @@ struct LinuxAioState *aio_setup_linux_aio(AioContext *ctx, Error **errp);
 struct LinuxAioState *aio_get_linux_aio(AioContext *ctx);
 
 /**
+ * aio_timer_new_with_attrs:
+ * @ctx: the aio context
+ * @type: the clock type
+ * @scale: the scale
+ * @attributes: 0, or one to multiple OR'ed QEMU_TIMER_ATTR(id) values to assign

Further down in this patch the notation is QEMU_TIMER_ATTR_<id>, which I think is clearer because QEMU_TIMER_ATTR(id) looks like a (non-existent) macro. Please use the QEMU_TIMER_ATTR_<id> notation consistently.

Quoted 11 lines
include/block/aio.h +11 -0
+/**
+ * QEMU Timer attributes:
+ *
+ * An individual timer may be assigned with one or multiple attributes when
+ * initialized.
+ * Attribute is a static flag, meaning that timer has corresponding property.
+ * Attributes are defined in QEMUTimerAttrBit enum and encoded to bit set,
+ * which used to initialize timer, stored to 'attributes' member and can be
+ * retrieved externally with timer_get_attributes() call.
+ * Values of QEMUTimerAttrBit aren't used directly,
+ * instead each attribute in bit set accessed with QEMU_TIMER_ATTR_<id> macro,

include/block/aio.h struct LinuxAioState *aio_setup_linux_aio(AioContext *ctx, Error **errp); · line 416

Quoted 10 lines
include/block/aio.h +10 -0
+ * where <id> is a unique part of attribute identifier.
+ *
+ * No attributes defined currently.
+ */
+
+typedef enum {
+    QEMU_TIMER_ATTRBIT__NONE
+} QEMUTimerAttrBit;
+
+#define QEMU_TIMER_ATTR__NONE (1 << QEMU_TIMER_ATTRBIT__NONE)

What is the purpose of this bit? I guess it's just here as a placeholder because no real bits have been defined yet. Hopefully the next patch removes it (/* This placeholder is removed in the next patch */ would be a nice way to document this for reviewers).

The enum isn't needed and makes debugging harder since the bit number is implicit in the enum ordering. This alternative is clearer and more concise:

  #define QEMU_TIMER_ATTR_foo BIT(n)
#4 lore raw

Re: [Qemu-devel] [Qemu-block] [PATCH v2 2/4] Introduce attributes to qemu timer subsystem

Quoted 5 lines · Stefan Hajnoczi
Quoted 2 lines

Attributes are simple flags, associated with individual timers for their whole lifetime.
They intended to be used to mark individual timers for special handling by various qemu features operating at qemu core level.

I'm worried that this sentence suggests various parts of QEMU will stash state in ts->attributes. That's messy and they shouldn't do this. Make the field private to qemu-timer.c.

Yes, the contents of the fields are private. Are you suggesting a different wording for the commit message or the "QEMU Timer attributes" doc comment, or something more than that? Possibly removing timer_get_attributes altogether?

Paolo

#5 lore raw

Re: [Qemu-devel] [Qemu-block] [PATCH v2 2/4] Introduce attributes to qemu timer subsystem

Quoted 3 lines

Further down in this patch the notation is QEMU_TIMER_ATTR_<id>, which I think is clearer because QEMU_TIMER_ATTR(id) looks like a (non-existent) macro. Please use the QEMU_TIMER_ATTR_<id> notation consistently.

Yes, I've just forgot to update comments after previous patch version, where it actually was macro.

Quoted 4 lines

What is the purpose of this bit? I guess it's just here as a placeholder because no real bits have been defined yet. Hopefully the next patch removes it (/* This placeholder is removed in the next patch */ would be a nice way to document this for reviewers).

It's just to prevent compilation errors, as required by
https://wiki.qemu.org/Contribute/SubmitAPatch#Split_up_long_patches

Quoted 5 lines

The enum isn't needed and makes debugging harder since the bit number is implicit in the enum ordering. This alternative is clearer and more concise:

  #define QEMU_TIMER_ATTR_foo BIT(n)

Agree.

Quoted 3 lines

ср, 17 окт. 2018 г. в 15:15, Paolo Bonzini <[email protected]>:

Quoted 1 line · Stefan Hajnoczi
Quoted 1 line

Attributes are simple flags, associated with individual timers for

their whole lifetime.

Quoted 1 line
Quoted 1 line
Quoted 1 line

They intended to be used to mark individual timers for special handling

by various qemu features operating at qemu core level.

Quoted 8 lines
Quoted 3 lines

I'm worried that this sentence suggests various parts of QEMU will stash state in ts->attributes. That's messy and they shouldn't do this. Make the field private to qemu-timer.c.

Yes, the contents of the fields are private. Are you suggesting a different wording for the commit message or the "QEMU Timer attributes" doc comment, or something more than that? Possibly removing timer_get_attributes altogether?

Actually, attributes aren't intended to be changed externally of timers code.
The purpose of timer_get_attributes() is just informational, same like if timer_get_clock(), timer_get_scale(), etc. would exist. But since none of such accessors exists, adding just one for 'attributes' looks exceptional. And it isn't being used even after whole patch series applied. As such, it could be just removed.
Any suggestons to improve commit message and/or comments, if any ?

Signature · 2 lines
С уважением,
  Артем Писаренко
#6 lore raw

Re: [Qemu-devel] [Qemu-block] [PATCH v2 2/4] Introduce attributes to qemu timer subsystem

Quoted 15 lines · Artem Pisarenko
Quoted 3 lines

Further down in this patch the notation is QEMU_TIMER_ATTR_<id>, which I think is clearer because QEMU_TIMER_ATTR(id) looks like a (non-existent) macro.  Please use the QEMU_TIMER_ATTR_<id> notation consistently.

Yes, I've just forgot to update comments after previous patch version, where it actually was macro.

Quoted 4 lines

What is the purpose of this bit?  I guess it's just here as a placeholder because no real bits have been defined yet.  Hopefully the next patch removes it (/* This placeholder is removed in the next patch */ would be a nice way to document this for reviewers).

It's just to prevent compilation errors, as required by
https://wiki.qemu.org/Contribute/SubmitAPatch#Split_up_long_patches

Quoted 7 lines
Quoted 5 lines

The enum isn't needed and makes debugging harder since the bit number is implicit in the enum ordering.  This alternative is clearer and more concise:

   #define QEMU_TIMER_ATTR_foo BIT(n)

Agree.

Like this?

include/qemu/timer.h +0 -3
index 86ce70f20e..ef7526e389 100644
@@ -55,25 +55,13 @@ typedef enum {
 /**
  * QEMU Timer attributes:
  *
- * An individual timer may be assigned with one or multiple attributes when
- * initialized.
- * Attribute is a static flag, meaning that timer has corresponding

property.
- * Attributes are defined in QEMUTimerAttrBit enum and encoded to bit set,
- * which used to initialize timer, stored to 'attributes' member and can be
- * retrieved externally with timer_get_attributes() call.
- * Values of QEMUTimerAttrBit aren't used directly,
- * instead each attribute in bit set accessed with QEMU_TIMER_ATTR_<id> macro,
- * where <id> is a unique part of attribute identifier.
+ * An individual timer may be given one or multiple attributes when initialized.
+ * Each attribute corresponds to one bit. Attributes modify the processing
+ * of timers when they fire.
*
* No attributes defined currently.
*/

-typedef enum {
- QEMU_TIMER_ATTRBIT__NONE
-} QEMUTimerAttrBit;
-
-#define QEMU_TIMER_ATTR__NONE (1 << QEMU_TIMER_ATTRBIT__NONE) -
typedef struct QEMUTimerList QEMUTimerList;

struct QEMUTimerListGroup {
@@ -640,14 +628,6 @@ static inline QEMUTimer *timer_new_ms(QEMUClockType type, QEMUTimerCB *cb,

     return timer_new(type, SCALE_MS, cb, opaque);

}

-/**
- * timer_get_attributes:
- * @ts: the timer
- *
- * Return 0, or one to multiple OR'ed QEMU_TIMER_ATTR(id) values
- */
-int timer_get_attributes(QEMUTimer *ts);
-
/**
* timer_deinit:
* @ts: the timer to be de-initialised

util/qemu-timer.c +0 -5
index 2046b68c15..04527a343f 100644
@@ -355,11 +355,6 @@ void timer_init_full(QEMUTimer *ts,
     ts->expire_time = -1;
 }
 
-int timer_get_attributes(QEMUTimer *ts)
-{
-    return ts->attributes;
-}
-
 void timer_deinit(QEMUTimer *ts)
 {
     assert(ts->expire_time == -1);
#7 lore raw

Re: [Qemu-devel] [Qemu-block] [PATCH v2 2/4] Introduce attributes to qemu timer subsystem

Yes, but without words ..."when they fire" in attributes comments.

ср, 17 окт. 2018 г. в 17:24, Paolo Bonzini <[email protected]>:

Quoted 22 lines · Artem Pisarenko
Quoted 21 lines
Quoted 3 lines

Further down in this patch the notation is QEMU_TIMER_ATTR_<id>, which I think is clearer because QEMU_TIMER_ATTR(id) looks like a (non-existent) macro. Please use the QEMU_TIMER_ATTR_<id> notation consistently.

Yes, I've just forgot to update comments after previous patch version, where it actually was macro.

Quoted 4 lines

What is the purpose of this bit? I guess it's just here as a placeholder because no real bits have been defined yet. Hopefully the next patch removes it (/* This placeholder is removed in the next patch */ would be a nice way to document this for reviewers).

It's just to prevent compilation errors, as required by
https://wiki.qemu.org/Contribute/SubmitAPatch#Split_up_long_patches

Quoted 5 lines

The enum isn't needed and makes debugging harder since the bit number is implicit in the enum ordering. This alternative is clearer and more concise:

  #define QEMU_TIMER_ATTR_foo BIT(n)
Quoted 7 lines
Quoted 1 line

Agree.

Like this?

...

--

С уважением,
Артем Писаренко

#8 lore raw

Re: [Qemu-devel] [Qemu-block] [PATCH v2 2/4] Introduce attributes to qemu timer subsystem

Quoted 1 line · Artem Pisarenko

Yes, but without words ..."when they fire" in attributes comments.

For now the only attribute applies when timers fire; that sentence was a way to clarify the intended scope and address Stefan's comment. I can remove it too, but I'd like to understand if you have other ideas for attributes.

Paolo

#9 lore raw

Re: [Qemu-devel] [Qemu-block] [PATCH v2 2/4] Introduce attributes to qemu timer subsystem

Quoted 8 lines

ср, 17 окт. 2018 г. в 20:43, Paolo Bonzini:

Quoted 1 line · Artem Pisarenko

Yes, but without words ..."when they fire" in attributes comments.

For now the only attribute applies when timers fire; that sentence was a way to clarify the intended scope and address Stefan's comment. I can remove it too, but I'd like to understand if you have other ideas for attributes.

No, I haven't. I don't think that this partcular narrowing has any relevance to Stefan's comment, so I just considered it to be unnecessary. I don't insist.

Signature · 2 lines
С уважением,
  Артем Писаренко
#10 lore raw

Re: [Qemu-devel] [Qemu-block] [PATCH v2 2/4] Introduce attributes to qemu timer subsystem

In reply to Paolo Bonzini
Quoted 22 lines · Paolo Bonzini
Quoted 21 lines · Artem Pisarenko
Quoted 3 lines

Further down in this patch the notation is QEMU_TIMER_ATTR_<id>, which I think is clearer because QEMU_TIMER_ATTR(id) looks like a (non-existent) macro.  Please use the QEMU_TIMER_ATTR_<id> notation consistently.

Yes, I've just forgot to update comments after previous patch version, where it actually was macro.

Quoted 4 lines

What is the purpose of this bit?  I guess it's just here as a placeholder because no real bits have been defined yet.  Hopefully the next patch removes it (/* This placeholder is removed in the next patch */ would be a nice way to document this for reviewers).

It's just to prevent compilation errors, as required by
https://wiki.qemu.org/Contribute/SubmitAPatch#Split_up_long_patches

Quoted 5 lines

The enum isn't needed and makes debugging harder since the bit number is implicit in the enum ordering.  This alternative is clearer and more concise:

   #define QEMU_TIMER_ATTR_foo BIT(n)

Quoted 3 lines
Quoted 1 line

Agree.

Like this?

Yes, something like that is good.

#11 lore raw

PATCH v2 3/4 Restores record/replay behavior related to special virtual clock processing for timers used in external subsystems.

In reply to Artem Pisarenko

Adds EXTERNAL attribute definition to qemu timers subsystem and assigns it to virtual clock timers, used in slirp (ICMP IPv6) and ui (key queue). Virtual clock processing in rr mode reimplemented using this attribute.

Fixes 87f4fe7653baf55b5c2f2753fe6003f473c07342
Fixes 775a412bf83f6bc0c5c02091ee06cf649b34c593
Fixes 9888091404a702d7ec79d51b088d994b9fc121bd

---

Notes:
v2: fixes race condition and reimplements synchronization between checkpointing and timers processing in qemu-timer.c

 include/qemu/timer.h | 12 +++++++++---
 slirp/ip6_icmp.c     |  4 +++-
 ui/input.c           |  5 +++--
 util/qemu-timer.c    | 50 +++++++++++++++++++++++++++++++++++++++++++-------
 4 files changed, 58 insertions(+), 13 deletions(-)
include/qemu/timer.h +9 -3
index e225ad4..8e3f236 100644
@@ -65,14 +65,20 @@ typedef enum {
  * instead each attribute in bit set accessed with QEMU_TIMER_ATTR_<id> macro,
  * where <id> is a unique part of attribute identifier.
  *
- * No attributes defined currently.
+ * The following attributes are available:
+ *
+ * QEMU_TIMER_ATTR_EXTERNAL: drives external subsystem
+ *
+ * Timers with this attribute do not recorded in rr mode, therefore it could be
+ * used for the subsystems that operate outside the guest core. Applicable only
+ * with virtual clock type.
  */
 
 typedef enum {
-    QEMU_TIMER_ATTRBIT__NONE
+    QEMU_TIMER_ATTRBIT_EXTERNAL,
 } QEMUTimerAttrBit;
 
-#define QEMU_TIMER_ATTR__NONE (1 << QEMU_TIMER_ATTRBIT__NONE)
+#define QEMU_TIMER_ATTR_EXTERNAL (1 << QEMU_TIMER_ATTRBIT_EXTERNAL)
 
 typedef struct QEMUTimerList QEMUTimerList;
 
slirp/ip6_icmp.c +3 -1
index ee333d0..cd1e0b9 100644
@@ -27,7 +27,9 @@ void icmp6_init(Slirp *slirp)
         return;
     }
 
-    slirp->ra_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, ra_timer_handler, slirp);
+    slirp->ra_timer = timer_new_full(NULL, QEMU_CLOCK_VIRTUAL,
+                                     SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL,
+                                     ra_timer_handler, slirp);
     timer_mod(slirp->ra_timer,
               qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + NDP_Interval);
 }
ui/input.c +3 -2
index 51b1019..7c9a410 100644
@@ -448,8 +448,9 @@ void qemu_input_event_send_key_delay(uint32_t delay_ms)
     }
 
     if (!kbd_timer) {
-        kbd_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL, qemu_input_queue_process,
-                                 &kbd_queue);
+        kbd_timer = timer_new_full(NULL, QEMU_CLOCK_VIRTUAL,
+                                   SCALE_MS, QEMU_TIMER_ATTR_EXTERNAL,
+                                   qemu_input_queue_process, &kbd_queue);
     }
     if (queue_count < queue_limit) {
         qemu_input_queue_delay(&kbd_queue, kbd_timer,
util/qemu-timer.c +43 -7

82 lines not on this page · raw message

Signature · 1 line
2.7.4
#12 lore raw

PATCH v2 4/4 Optimize record/replay checkpointing for all clocks it applies to

In reply to Artem Pisarenko

Removes redundant checkpoints in replay log when there are no expired timers in timers list, associated with corresponding clock (i.e. no rr events associated with current clock value). This also improves performance in rr mode.

---
 include/qemu/timer.h |  2 +-
 util/qemu-timer.c    | 62 +++++++++++++++++++++++++---------------------------
 2 files changed, 31 insertions(+), 33 deletions(-)
include/qemu/timer.h +1 -1
index 8e3f236..bd627dc 100644
@@ -70,7 +70,7 @@ typedef enum {
  * QEMU_TIMER_ATTR_EXTERNAL: drives external subsystem
  *
  * Timers with this attribute do not recorded in rr mode, therefore it could be
- * used for the subsystems that operate outside the guest core. Applicable only
+ * used for the subsystems that operate outside the guest core. Relevant only
  * with virtual clock type.
  */
 
util/qemu-timer.c +30 -32

86 lines not on this page · raw message

Signature · 1 line
2.7.4