diff mbox

[RFC,5/6] monitor: Throttle event VSERPORT_CHANGE separately by "id"

Message ID 1443189647-11417-6-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster Sept. 25, 2015, 2 p.m. UTC
VSERPORT_CHANGE is emitted when the guest opens or closes a
virtio-serial port.  The event's member "id" identifies the port.

When several events arrive quickly, throttling drops all but the last
of them.  Because of that, a QMP client must assume that *any* port
may have changed state when it receives a VSERPORT_CHANGE event and
throttling may have happened.

Make the event more useful by throttling it for each port separately.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 monitor.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

Comments

Eric Blake Sept. 25, 2015, 7:24 p.m. UTC | #1
On 09/25/2015 08:00 AM, Markus Armbruster wrote:
> VSERPORT_CHANGE is emitted when the guest opens or closes a
> virtio-serial port.  The event's member "id" identifies the port.
> 
> When several events arrive quickly, throttling drops all but the last
> of them.  Because of that, a QMP client must assume that *any* port
> may have changed state when it receives a VSERPORT_CHANGE event and
> throttling may have happened.
> 
> Make the event more useful by throttling it for each port separately.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  monitor.c | 18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
> 

All future differentiation would be added as additional special cases
within the hash functions, but I like this approach for keeping the rest
of the algorithm independent from what the hashing considers as equivalent.

Reviewed-by: Eric Blake <eblake@redhat.com>
Markus Armbruster Sept. 28, 2015, 8:33 a.m. UTC | #2
Eric Blake <eblake@redhat.com> writes:

> On 09/25/2015 08:00 AM, Markus Armbruster wrote:
>> VSERPORT_CHANGE is emitted when the guest opens or closes a
>> virtio-serial port.  The event's member "id" identifies the port.
>> 
>> When several events arrive quickly, throttling drops all but the last
>> of them.  Because of that, a QMP client must assume that *any* port
>> may have changed state when it receives a VSERPORT_CHANGE event and
>> throttling may have happened.
>> 
>> Make the event more useful by throttling it for each port separately.
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  monitor.c | 18 ++++++++++++++++--
>>  1 file changed, 16 insertions(+), 2 deletions(-)
>> 
>
> All future differentiation would be added as additional special cases
> within the hash functions, but I like this approach for keeping the rest
> of the algorithm independent from what the hashing considers as equivalent.

Should that ever become unwieldy, we can easily add indirections right
there.

> Reviewed-by: Eric Blake <eblake@redhat.com>

Thanks!
diff mbox

Patch

diff --git a/monitor.c b/monitor.c
index 9807a5b..7e21407 100644
--- a/monitor.c
+++ b/monitor.c
@@ -567,8 +567,13 @@  static void monitor_qapi_event_handler(void *opaque)
 static unsigned int qapi_event_throttle_hash(const void *key)
 {
     const MonitorQAPIEventState *evstate = key;
+    unsigned int hash = evstate->event * 255;
 
-    return evstate->event * 255;
+    if (evstate->event == QAPI_EVENT_VSERPORT_CHANGE) {
+        hash += g_str_hash(qdict_get_str(evstate->qdict, "id"));
+    }
+
+    return hash;
 }
 
 static gboolean qapi_event_throttle_equal(const void *a, const void *b)
@@ -576,7 +581,16 @@  static gboolean qapi_event_throttle_equal(const void *a, const void *b)
     const MonitorQAPIEventState *eva = a;
     const MonitorQAPIEventState *evb = b;
 
-    return eva->event == evb->event;
+    if (eva->event != evb->event) {
+        return FALSE;
+    }
+
+    if (eva->event == QAPI_EVENT_VSERPORT_CHANGE) {
+        return !strcmp(qdict_get_str(eva->qdict, "id"),
+                       qdict_get_str(evb->qdict, "id"));
+    }
+
+    return TRUE;
 }
 
 static void monitor_qapi_event_init(void)