qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: marcandre.lureau@redhat.com
To: qemu-devel@nongnu.org
Cc: amit.shah@redhat.com, lersek@redhat.com,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [PATCH 3/3] monitor: remove old entries from event hash table
Date: Wed,  2 Sep 2015 13:09:43 +0200	[thread overview]
Message-ID: <1441192183-4812-4-git-send-email-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <1441192183-4812-1-git-send-email-marcandre.lureau@redhat.com>

From: Marc-André Lureau <marcandre.lureau@redhat.com>

Do not let the hash table grow without limit, schedule a cleanup for
outdated event.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 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;
 }
 
+static void monitor_qapi_event_id_remove(void *opaque)
+{
+    MonitorQAPIEventPending *p = opaque;
+    MonitorQAPIEventState *s = &monitor_qapi_event_state[p->event];
+    GHashTable *ht = s->data;
+    GHashTableIter iter;
+    gpointer value;
+
+    g_hash_table_iter_init(&iter, ht);
+    while (g_hash_table_iter_next(&iter, NULL, &value)) {
+        if (value == 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(MonitorQAPIEventPending *p)
+{
+    MonitorQAPIEventState *s = &monitor_qapi_event_state[p->event];
+    int64_t now = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
+    int64_t then = now + s->rate;
+
+    p->timer->cb = monitor_qapi_event_id_remove;
+    timer_mod_ns(p->timer, then);
+}
+
+static void monitor_qapi_event_id_handler(void *opaque)
+{
+    MonitorQAPIEventPending *p = 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 *evstate, QDict *data)
         g_hash_table_insert(ht, g_strdup(id), p);
     }
 
-    return monitor_qapi_event_pending_update(evstate, p, data);
+    if (monitor_qapi_event_pending_update(evstate, p, data)) {
+        p->timer->cb = monitor_qapi_event_id_handler;
+        return true;
+    } else {
+        monitor_qapi_event_id_schedule_remove(p);
+        return false;
+    }
 }
 
 /*
-- 
2.4.3

  parent reply	other threads:[~2015-09-02 11:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-02 11:09 [Qemu-devel] [PATCH 0/3] monitor: throttle VSERPORT_CHANGED by "id" marcandre.lureau
2015-09-02 11:09 ` [Qemu-devel] [PATCH 1/3] monitor: split MonitorQAPIEventState marcandre.lureau
2015-09-10  8:34   ` Daniel P. Berrange
2015-09-16 13:57   ` Markus Armbruster
2015-09-17 13:17     ` Marc-André Lureau
2015-09-02 11:09 ` [Qemu-devel] [PATCH 2/3] monitor: throttle QAPI_EVENT_VSERPORT_CHANGE by "id" marcandre.lureau
2015-09-10  8:35   ` Daniel P. Berrange
2015-09-16 16:40   ` Markus Armbruster
2015-09-17 11:28     ` Marc-André Lureau
2015-09-17 14:06     ` Marc-André Lureau
2015-09-02 11:09 ` marcandre.lureau [this message]
2015-09-10  8:35   ` [Qemu-devel] [PATCH 3/3] monitor: remove old entries from event hash table Daniel P. Berrange
2015-09-16 16:50   ` Markus Armbruster
2015-09-17 14:43     ` Marc-André Lureau
2015-09-08 10:18 ` [Qemu-devel] [PATCH 0/3] monitor: throttle VSERPORT_CHANGED by "id" Marc-André Lureau
2015-09-10  4:22   ` Amit Shah
2015-09-10  6:46     ` Markus Armbruster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1441192183-4812-4-git-send-email-marcandre.lureau@redhat.com \
    --to=marcandre.lureau@redhat.com \
    --cc=amit.shah@redhat.com \
    --cc=lersek@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).