From nobody Mon Apr 6 19:45:50 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1773827641; cv=none; d=zohomail.com; s=zohoarc; b=Q/jMdUE8wa9Hbcw1gYN5akL4ojWjz0Wka1OnBMD3YHpWsaK4RONXpyu9bEAIdniDP9pssfAvS8zfAqMRWNzT+J64iRJP7mRkd9CF8achAEYkZR9RdpJreUAJJjrNE4aPLqrj7rDiuSB0m1a3Hw1P/yVvJQIxQ8F/bhV6a/SDeRA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773827641; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=cf3ZlZYJuPivZ4fXOeU11NHa9pyR7htPxznZa5js3xQ=; b=DGW1hFNYsaHpDTn2NUSkffH9zrwr6NXjF7OLw9RSRluTTVOlBUIszktx73DHZ+r669NgBg5mH0RtfSd1oo9yfrey2I1z2NL11mX8wafoTHZY2j2pgWVOqyUCF92HXm1w0SC2hDsYijipA1tGD5tCvegLxRyUYlwVXBZxaHLb5ts= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177382764120776.77005322365596; Wed, 18 Mar 2026 02:54:01 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w2nb2-0007Uf-6F; Wed, 18 Mar 2026 05:53:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w2nap-0007TU-GD for qemu-devel@nongnu.org; Wed, 18 Mar 2026 05:53:35 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w2nal-0000B8-Cw for qemu-devel@nongnu.org; Wed, 18 Mar 2026 05:53:33 -0400 Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-662-7B11esURPoepzyDHzo29cw-1; Wed, 18 Mar 2026 05:53:27 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A28C5195607B; Wed, 18 Mar 2026 09:53:26 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.45.242.6]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EDDCE30001A1; Wed, 18 Mar 2026 09:53:25 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 63F0E21E66EA; Wed, 18 Mar 2026 10:53:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773827610; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cf3ZlZYJuPivZ4fXOeU11NHa9pyR7htPxznZa5js3xQ=; b=OPdVG4PrzXLHb+TYKRpIBQCtp/f9YHwl+uozGVbCJAyuE1pwULDe1ehAv5DiHjVuwW4ARC PabtN3MQbTm6VSRAWFTX/nBODEf/bUiwIssxuyhjenKAN/oxgzKCaCZjsEpXp1JaGDT51y MyZPy8g1rVwE4nVB9yfI7zzl8enaNnU= X-MC-Unique: 7B11esURPoepzyDHzo29cw-1 X-Mimecast-MFC-AGG-ID: 7B11esURPoepzyDHzo29cw_1773827606 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: dave@treblig.org, kwolf@redhat.com Subject: [PATCH 3/3] monitor: Dumb down to a single event rate limit Date: Wed, 18 Mar 2026 10:53:23 +0100 Message-ID: <20260318095323.2705117-4-armbru@redhat.com> In-Reply-To: <20260318095323.2705117-1-armbru@redhat.com> References: <20260318095323.2705117-1-armbru@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1773827644392154100 Content-Type: text/plain; charset="utf-8" The code lets us define event-specific rate limits. In more than a decade, we've only ever used the same 1s limit for all rate-limited events. Drop the ability and simplify. Signed-off-by: Markus Armbruster --- monitor/monitor.c | 56 ++++++++++++++++++++------------------------ monitor/trace-events | 2 +- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/monitor/monitor.c b/monitor/monitor.c index 87f6e4860b..5be2ec02c2 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -46,9 +46,8 @@ typedef struct MonitorQAPIEventState { QDict *qdict; /* Delayed event (if any) */ } MonitorQAPIEventState; =20 -typedef struct { - int64_t rate; /* Minimum time (in ns) between two events */ -} MonitorQAPIEventConf; +/* Minimum time (in ns) between events if the event is rate-limited */ +#define EVENT_RATE (1000 * SCALE_MS) =20 /* Shared monitor I/O thread */ IOThread *mon_iothread; @@ -268,19 +267,6 @@ void monitor_printc(Monitor *mon, int c) monitor_printf(mon, "'"); } =20 -static MonitorQAPIEventConf monitor_qapi_event_conf[QAPI_EVENT__MAX] =3D { - /* Limit guest-triggerable events to 1 per second */ - [QAPI_EVENT_RTC_CHANGE] =3D { 1000 * SCALE_MS }, - [QAPI_EVENT_BLOCK_IO_ERROR] =3D { 1000 * SCALE_MS }, - [QAPI_EVENT_WATCHDOG] =3D { 1000 * SCALE_MS }, - [QAPI_EVENT_BALLOON_CHANGE] =3D { 1000 * SCALE_MS }, - [QAPI_EVENT_QUORUM_REPORT_BAD] =3D { 1000 * SCALE_MS }, - [QAPI_EVENT_QUORUM_FAILURE] =3D { 1000 * SCALE_MS }, - [QAPI_EVENT_VSERPORT_CHANGE] =3D { 1000 * SCALE_MS }, - [QAPI_EVENT_MEMORY_DEVICE_SIZE_CHANGE] =3D { 1000 * SCALE_MS }, - [QAPI_EVENT_HV_BALLOON_STATUS_REPORT] =3D { 1000 * SCALE_MS }, -}; - /* * Return the clock to use for recording an event's time. * It's QEMU_CLOCK_REALTIME, except for qtests it's @@ -319,14 +305,23 @@ static void monitor_qapi_event_emit(QAPIEvent event, = QDict *qdict) } } =20 -static int64_t monitor_event_rate_limit(QAPIEvent event, QDict *data) +static bool monitor_event_is_rate_limited(QAPIEvent event, QDict *data) { - MonitorQAPIEventConf *evconf; - int64_t rate_limit; + static bool event_is_ratelimited[QAPI_EVENT__MAX] =3D { + [QAPI_EVENT_RTC_CHANGE] =3D true, + [QAPI_EVENT_BLOCK_IO_ERROR] =3D true, + [QAPI_EVENT_WATCHDOG] =3D true, + [QAPI_EVENT_BALLOON_CHANGE] =3D true, + [QAPI_EVENT_QUORUM_REPORT_BAD] =3D true, + [QAPI_EVENT_QUORUM_FAILURE] =3D true, + [QAPI_EVENT_VSERPORT_CHANGE] =3D true, + [QAPI_EVENT_MEMORY_DEVICE_SIZE_CHANGE] =3D true, + [QAPI_EVENT_HV_BALLOON_STATUS_REPORT] =3D true, + }; + bool rate_limited; =20 assert(event < QAPI_EVENT__MAX); - evconf =3D &monitor_qapi_event_conf[event]; - rate_limit =3D evconf->rate; + rate_limited =3D event_is_ratelimited[event]; =20 /* * Rate limit BLOCK_IO_ERROR only for action !=3D "stop". @@ -340,11 +335,11 @@ static int64_t monitor_event_rate_limit(QAPIEvent eve= nt, QDict *data) if (event =3D=3D QAPI_EVENT_BLOCK_IO_ERROR) { const char *action =3D qdict_get_str(data, "action"); if (!strcmp(action, "stop")) { - rate_limit =3D 0; + rate_limited =3D false; } } =20 - return rate_limit; + return rate_limited; } =20 static void monitor_qapi_event_handler(void *opaque); @@ -357,14 +352,14 @@ static void monitor_qapi_event_queue_no_reenter(QAPIEvent event, QDict *qdict) { QDict *data =3D qobject_to(QDict, qdict_get(qdict, "data")); - int64_t rate_limit =3D monitor_event_rate_limit(event, data); + bool rate_limited =3D monitor_event_is_rate_limited(event, data); MonitorQAPIEventState *evstate; =20 - trace_monitor_protocol_event_queue(event, qdict, rate_limit); + trace_monitor_protocol_event_queue(event, qdict, rate_limited); =20 QEMU_LOCK_GUARD(&monitor_lock); =20 - if (!rate_limit) { + if (!rate_limited) { /* Unthrottled event */ monitor_qapi_event_emit(event, qdict); } else { @@ -375,7 +370,7 @@ monitor_qapi_event_queue_no_reenter(QAPIEvent event, QD= ict *qdict) =20 if (evstate) { /* - * Timer is pending for (at least) @rate_limit ns after + * Timer is pending for (at least) @EVENT_RATE ns after * last send. Store event for sending when timer fires, * replacing a prior stored event if any. */ @@ -385,7 +380,7 @@ monitor_qapi_event_queue_no_reenter(QAPIEvent event, QD= ict *qdict) /* * Last send was (at least) @rate_limit ns ago. * Send immediately, and arm the timer to call - * monitor_qapi_event_handler() in @rate_limit ns. Any + * monitor_qapi_event_handler() in @EVENT_RATE ns. Any * events arriving before then will be delayed until then. */ int64_t now =3D qemu_clock_get_ns(monitor_get_event_clock()); @@ -400,7 +395,7 @@ monitor_qapi_event_queue_no_reenter(QAPIEvent event, QD= ict *qdict) monitor_qapi_event_handler, evstate); g_hash_table_add(monitor_qapi_event_state, evstate); - timer_mod_ns(evstate->timer, now + rate_limit); + timer_mod_ns(evstate->timer, now + EVENT_RATE); } } } @@ -454,7 +449,6 @@ void qapi_event_emit(QAPIEvent event, QDict *qdict) static void monitor_qapi_event_handler(void *opaque) { MonitorQAPIEventState *evstate =3D opaque; - MonitorQAPIEventConf *evconf =3D &monitor_qapi_event_conf[evstate->eve= nt]; =20 trace_monitor_protocol_event_handler(evstate->event, evstate->qdict); QEMU_LOCK_GUARD(&monitor_lock); @@ -465,7 +459,7 @@ static void monitor_qapi_event_handler(void *opaque) monitor_qapi_event_emit(evstate->event, evstate->qdict); qobject_unref(evstate->qdict); evstate->qdict =3D NULL; - timer_mod_ns(evstate->timer, now + evconf->rate); + timer_mod_ns(evstate->timer, now + EVENT_RATE); } else { g_hash_table_remove(monitor_qapi_event_state, evstate); qobject_unref(evstate->data); diff --git a/monitor/trace-events b/monitor/trace-events index 032d1220e1..7f0b4b9dd9 100644 --- a/monitor/trace-events +++ b/monitor/trace-events @@ -6,7 +6,7 @@ handle_hmp_command(void *mon, const char *cmdline) "mon %p = cmdline: %s" # monitor.c monitor_protocol_event_handler(uint32_t event, void *qdict) "event=3D%d da= ta=3D%p" monitor_protocol_event_emit(uint32_t event, void *data) "event=3D%d data= =3D%p" -monitor_protocol_event_queue(uint32_t event, void *qdict, uint64_t rate) "= event=3D%d data=3D%p rate=3D%" PRId64 +monitor_protocol_event_queue(uint32_t event, void *qdict, bool rate_limite= d) "event=3D%d data=3D%p rate_limited=3D%d" monitor_suspend(void *ptr, int cnt) "mon %p: %d" =20 # qmp.c --=20 2.53.0