Received: from eggs.gnu.org ([2001:4830:134:3::10]:57939) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZcFvX-0002VV-AK for qemu-devel@nongnu.org; Wed, 16 Sep 2015 12:51:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZcFuw-0003IP-RC for qemu-devel@nongnu.org; Wed, 16 Sep 2015 12:50:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50121) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZcFuw-0003IJ-Hg for qemu-devel@nongnu.org; Wed, 16 Sep 2015 12:50:46 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 27B29C0B919C for ; Wed, 16 Sep 2015 16:50:46 +0000 (UTC) From: Markus Armbruster References: <1441192183-4812-1-git-send-email-marcandre.lureau@redhat.com> <1441192183-4812-4-git-send-email-marcandre.lureau@redhat.com> Date: Wed, 16 Sep 2015 18:50:43 +0200 In-Reply-To: <1441192183-4812-4-git-send-email-marcandre.lureau@redhat.com> (marcandre lureau's message of "Wed, 2 Sep 2015 13:09:43 +0200") Message-ID: <87mvwmjokc.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 3/3] monitor: remove old entries from event hash table List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: marcandre.lureau@redhat.com Cc: amit.shah@redhat.com, lersek@redhat.com, qemu-devel@nongnu.org marcandre.lureau@redhat.com writes: > From: Marc-Andr=C3=A9 Lureau > > Do not let the hash table grow without limit, schedule a cleanup for > outdated event. > > Signed-off-by: Marc-Andr=C3=A9 Lureau > --- > monitor.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 46 insertions(+), 1 deletion(-) > > diff --git a/monitor.c b/monitor.c > index 7f5c80f..8d0c61b 100644 > --- a/monitor.c > +++ b/monitor.c > @@ -540,6 +540,45 @@ monitor_qapi_event_pending_new(QAPIEvent event) > return p; > } >=20=20 > +static void monitor_qapi_event_id_remove(void *opaque) > +{ > + MonitorQAPIEventPending *p =3D opaque; > + MonitorQAPIEventState *s =3D &monitor_qapi_event_state[p->event]; > + GHashTable *ht =3D s->data; > + GHashTableIter iter; > + gpointer value; > + > + g_hash_table_iter_init(&iter, ht); > + while (g_hash_table_iter_next(&iter, NULL, &value)) { > + if (value =3D=3D p) { > + g_hash_table_iter_remove(&iter); > + return; > + } > + } > +} > + > +/* > + * do not let the hash table grow, if no later pending event > + * scheduled, remove the old entry after rate timeout. > + */ > +static void monitor_qapi_event_id_schedule_remove(MonitorQAPIEventPendin= g *p) > +{ > + MonitorQAPIEventState *s =3D &monitor_qapi_event_state[p->event]; > + int64_t now =3D qemu_clock_get_ns(QEMU_CLOCK_REALTIME); > + int64_t then =3D now + s->rate; > + > + p->timer->cb =3D monitor_qapi_event_id_remove; I doubt you're supposed to poke into p->timer like that. > + timer_mod_ns(p->timer, then); > +} > + > +static void monitor_qapi_event_id_handler(void *opaque) > +{ > + MonitorQAPIEventPending *p =3D opaque; > + > + monitor_qapi_event_handler(p); > + monitor_qapi_event_id_schedule_remove(p); > +} > + > static bool > monitor_qapi_event_id_delay(MonitorQAPIEventState *evstate, QDict *data) > { > @@ -554,7 +593,13 @@ monitor_qapi_event_id_delay(MonitorQAPIEventState *e= vstate, QDict *data) > g_hash_table_insert(ht, g_strdup(id), p); > } >=20=20 > - return monitor_qapi_event_pending_update(evstate, p, data); > + if (monitor_qapi_event_pending_update(evstate, p, data)) { > + p->timer->cb =3D monitor_qapi_event_id_handler; > + return true; > + } else { > + monitor_qapi_event_id_schedule_remove(p); > + return false; > + } > } >=20=20 > /* Possibly cleaner than messing with timer->cb: have a single callback that does the right thing, i.e. when the timer goes off, check whether we have an event. If yes, send it and rearm the timer. If no, remove the hash entry.