From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44825) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zr0S3-0003On-E1 for qemu-devel@nongnu.org; Tue, 27 Oct 2015 05:21:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zr0S2-0003i9-3Q for qemu-devel@nongnu.org; Tue, 27 Oct 2015 05:21:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54225) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zr0S1-0003hr-SA for qemu-devel@nongnu.org; Tue, 27 Oct 2015 05:21:54 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 5E61796EB for ; Tue, 27 Oct 2015 09:21:53 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-42.ams2.redhat.com [10.36.116.42]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9R9Lowr004318 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Tue, 27 Oct 2015 05:21:52 -0400 From: Markus Armbruster Date: Tue, 27 Oct 2015 10:21:46 +0100 Message-Id: <1445937707-22768-13-git-send-email-armbru@redhat.com> In-Reply-To: <1445937707-22768-1-git-send-email-armbru@redhat.com> References: <1445937707-22768-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PULL 12/13] monitor: Throttle event VSERPORT_CHANGE separately by "id" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 Reviewed-by: Eric Blake Message-Id: <1444921716-9511-7-git-send-email-armbru@redhat.com> --- monitor.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/monitor.c b/monitor.c index 525d8e4..6cd747f 100644 --- a/monitor.c +++ b/monitor.c @@ -181,7 +181,8 @@ typedef struct { * instance. */ typedef struct MonitorQAPIEventState { - QAPIEvent event; /* Event being tracked */ + QAPIEvent event; /* Throttling state for this event type and... */ + QDict *data; /* ... data, see qapi_event_throttle_equal() */ QEMUTimer *timer; /* Timer for handling delayed events */ QDict *qdict; /* Delayed event (if any) */ } MonitorQAPIEventState; @@ -490,7 +491,8 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *qdict, Error **errp) /* Unthrottled event */ monitor_qapi_event_emit(event, qdict); } else { - MonitorQAPIEventState key = { .event = event }; + QDict *data = qobject_to_qdict(qdict_get(qdict, "data")); + MonitorQAPIEventState key = { .event = event, .data = data }; evstate = g_hash_table_lookup(monitor_qapi_event_state, &key); assert(!evstate || timer_pending(evstate->timer)); @@ -517,6 +519,8 @@ monitor_qapi_event_queue(QAPIEvent event, QDict *qdict, Error **errp) evstate = g_new(MonitorQAPIEventState, 1); evstate->event = event; + evstate->data = data; + QINCREF(evstate->data); evstate->qdict = NULL; evstate->timer = timer_new_ns(QEMU_CLOCK_REALTIME, monitor_qapi_event_handler, @@ -551,6 +555,7 @@ static void monitor_qapi_event_handler(void *opaque) timer_mod_ns(evstate->timer, now + evconf->rate); } else { g_hash_table_remove(monitor_qapi_event_state, evstate); + QDECREF(evstate->data); timer_free(evstate->timer); g_free(evstate); } @@ -561,8 +566,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->data, "id")); + } + + return hash; } static gboolean qapi_event_throttle_equal(const void *a, const void *b) @@ -570,7 +580,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->data, "id"), + qdict_get_str(evb->data, "id")); + } + + return TRUE; } static void monitor_qapi_event_init(void) -- 2.4.3