From nobody Mon Apr 6 18:24:25 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=1773827660; cv=none; d=zohomail.com; s=zohoarc; b=ZwEN+mbGxWK0dXFMvcssyItTnhD6o3wSkOh540AEcEHxUpIltyJCGpuTIEwI7MGKTAJoCJz+9PLEtqL02hL15nP7A/EG+sZXvj0LW0SkMJt4gkIvtewBta3G22v1bO2+qsFlGSQhLaRhmD8ESOS2o+vIkOayiSl2RCtrpqZ6Jk0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773827660; 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=RvBXdTr4DVin3js9aNW8Atx0nJgqqA/jNtNiPt71jVY=; b=A0h0jY5a23Kc00n8QzEQ0gmU115vtdefAFDnnec/s8xiNcDXTCRI9BpU+ADu7m1RIJLQLPh0Qvaj00DgeIhKiFs35zU5h503g627tdMVZisEdgGdIyPDdU+AuD/TdUcnePOhwytm9Xy/lRoIr9hhVIWiKi3TaiL2TK8ZTeERFQw= 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 1773827660292228.1379033868684; Wed, 18 Mar 2026 02:54:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w2nb4-0007VC-Ng; Wed, 18 Mar 2026 05:53:51 -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 1w2naq-0007Tl-Qx for qemu-devel@nongnu.org; Wed, 18 Mar 2026 05:53:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w2nan-0000GY-31 for qemu-devel@nongnu.org; Wed, 18 Mar 2026 05:53:34 -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-391-Gs3Su6S6PVK1oQMk2Uo-Aw-1; Wed, 18 Mar 2026 05:53:28 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 67F8119560AA; Wed, 18 Mar 2026 09:53:27 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.45.242.6]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E919E1800351; Wed, 18 Mar 2026 09:53:26 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5B43221E675A; 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=1773827611; 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=RvBXdTr4DVin3js9aNW8Atx0nJgqqA/jNtNiPt71jVY=; b=IhcCdsQxRQ+taKysYRRLLKhLvJTqNjHvq0Bx8rcPrOebmw/7f73ivFRRepTeidjQnZWHZt KHqxnkk4TMgE5VbIV255uckN4chSIPHnAfGpw6yubJKmYJuKkjXkXBUDdA8c9pUa5WUHMG 2nW7zl2qVhMmXV5noSgjYax+mdldk+E= X-MC-Unique: Gs3Su6S6PVK1oQMk2Uo-Aw-1 X-Mimecast-MFC-AGG-ID: Gs3Su6S6PVK1oQMk2Uo-Aw_1773827607 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: dave@treblig.org, kwolf@redhat.com Subject: [PATCH 1/3] monitor: Fix event rate limit tracing Date: Wed, 18 Mar 2026 10:53:21 +0100 Message-ID: <20260318095323.2705117-2-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.111 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.129.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_H3=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: 1773827662401154100 Content-Type: text/plain; charset="utf-8" Trace event monitor_protocol_event_queue argument @rate is the rate event's limit. It's 1000000000 for BLOCK_IO_ERROR with BLOCK_ERROR_ACTION_STOP, but the actual rate limit is 0, i.e. unlimited. Fix that. Fixes: 544ddbb6373d (block: Never drop BLOCK_IO_ERROR with action=3Dstop fo= r rate limiting) Signed-off-by: Markus Armbruster --- monitor/monitor.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/monitor/monitor.c b/monitor/monitor.c index 00b93ed612..8277f41a9d 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -330,12 +330,11 @@ monitor_qapi_event_queue_no_reenter(QAPIEvent event, = QDict *qdict) { MonitorQAPIEventConf *evconf; MonitorQAPIEventState *evstate; - bool throttled; + int64_t rate_limit; =20 assert(event < QAPI_EVENT__MAX); evconf =3D &monitor_qapi_event_conf[event]; - trace_monitor_protocol_event_queue(event, qdict, evconf->rate); - throttled =3D evconf->rate; + rate_limit =3D evconf->rate; =20 /* * Rate limit BLOCK_IO_ERROR only for action !=3D "stop". @@ -350,13 +349,15 @@ monitor_qapi_event_queue_no_reenter(QAPIEvent event, = QDict *qdict) QDict *data =3D qobject_to(QDict, qdict_get(qdict, "data")); const char *action =3D qdict_get_str(data, "action"); if (!strcmp(action, "stop")) { - throttled =3D false; + rate_limit =3D 0; } } =20 + trace_monitor_protocol_event_queue(event, qdict, rate_limit); + QEMU_LOCK_GUARD(&monitor_lock); =20 - if (!throttled) { + if (!rate_limit) { /* Unthrottled event */ monitor_qapi_event_emit(event, qdict); } else { @@ -368,7 +369,7 @@ monitor_qapi_event_queue_no_reenter(QAPIEvent event, QD= ict *qdict) =20 if (evstate) { /* - * Timer is pending for (at least) evconf->rate ns after + * Timer is pending for (at least) @rate_limit ns after * last send. Store event for sending when timer fires, * replacing a prior stored event if any. */ @@ -376,9 +377,9 @@ monitor_qapi_event_queue_no_reenter(QAPIEvent event, QD= ict *qdict) evstate->qdict =3D qobject_ref(qdict); } else { /* - * Last send was (at least) evconf->rate ns ago. + * Last send was (at least) @rate_limit ns ago. * Send immediately, and arm the timer to call - * monitor_qapi_event_handler() in evconf->rate ns. Any + * monitor_qapi_event_handler() in @rate_limit ns. Any * events arriving before then will be delayed until then. */ int64_t now =3D qemu_clock_get_ns(monitor_get_event_clock()); @@ -393,7 +394,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 + evconf->rate); + timer_mod_ns(evstate->timer, now + rate_limit); } } } --=20 2.53.0 From nobody Mon Apr 6 18:24:25 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=1773827649; cv=none; d=zohomail.com; s=zohoarc; b=KEd17Hao0llOaIRF7U4DStpmYeVRpf3KQEz5HKrMT6y0qZlC1Qxh1w+qmh3efs8OkE6LcRqsXeXO9lOcebWephnfzvGomgbxyzPnCvvPYF7RG2VPZ8/7nB9IPjKTXQnAqbj2feHYD9/H8y+gBlaQTTi/ZBVxlymj7WuOl3ZbEdo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773827649; 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=SLc8TUGCVbI2hNqsv8kPvh67lVtYioZvfSsq0QAiRoE=; b=eGm9NV8htVCzWgRo18lyzq2tCeYoJDd2MAvOvi2k4+BftnmxZgzTU2AxF3jlHJOUHDHMa/dyV0E6nkMCi5tsKx2Pz46ZzbedUWzE4gXDU+hjXban1FkZiQMKa3/H2e4SL2fE0YKLJA0mxXAf28SewNjSnbYbxnSyMyeLCFCKL64= 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 1773827649884489.86856927583995; Wed, 18 Mar 2026 02:54:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w2nb8-0007Wm-CO; Wed, 18 Mar 2026 05:53:54 -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 1w2naq-0007Tj-OO for qemu-devel@nongnu.org; Wed, 18 Mar 2026 05:53:37 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w2nal-0000BR-RL for qemu-devel@nongnu.org; Wed, 18 Mar 2026 05:53:34 -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-407-dRHuYLGqMmS53YGGLQq1XQ-1; Wed, 18 Mar 2026 05:53:27 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 63514195605E; Wed, 18 Mar 2026 09:53:26 +0000 (UTC) Received: from blackfin.pond.sub.org (unknown [10.45.242.6]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 07BCE1955F19; Wed, 18 Mar 2026 09:53:25 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 5FD7F21E66E5; 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=SLc8TUGCVbI2hNqsv8kPvh67lVtYioZvfSsq0QAiRoE=; b=TnokTp5m9TGiVpe3hq6mHLvg2QAFpjzHhDCdc0oMhLcyeBu7995ThvZY9k32FKu39lVdsV SV/M69G0PmIOvTqhgRqtc3V0JBBB+lygej6TrgdQshuDXZrKPmYGxpmQmnVvWCAMmNKx/i xj8YI8uS7A23aKBD3fH+hL3ZYipEc84= X-MC-Unique: dRHuYLGqMmS53YGGLQq1XQ-1 X-Mimecast-MFC-AGG-ID: dRHuYLGqMmS53YGGLQq1XQ_1773827606 From: Markus Armbruster To: qemu-devel@nongnu.org Cc: dave@treblig.org, kwolf@redhat.com Subject: [PATCH 2/3] monitor: Factor out monitor_event_rate_limited() Date: Wed, 18 Mar 2026 10:53:22 +0100 Message-ID: <20260318095323.2705117-3-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.0 on 10.30.177.17 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.129.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_H3=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: 1773827651043158500 Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster --- monitor/monitor.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/monitor/monitor.c b/monitor/monitor.c index 8277f41a9d..87f6e4860b 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -319,17 +319,9 @@ static void monitor_qapi_event_emit(QAPIEvent event, Q= Dict *qdict) } } =20 -static void monitor_qapi_event_handler(void *opaque); - -/* - * Queue a new event for emission to Monitor instances, - * applying any rate limiting if required. - */ -static void -monitor_qapi_event_queue_no_reenter(QAPIEvent event, QDict *qdict) +static int64_t monitor_event_rate_limit(QAPIEvent event, QDict *data) { MonitorQAPIEventConf *evconf; - MonitorQAPIEventState *evstate; int64_t rate_limit; =20 assert(event < QAPI_EVENT__MAX); @@ -346,13 +338,28 @@ monitor_qapi_event_queue_no_reenter(QAPIEvent event, = QDict *qdict) * limited, so we can do without rate limiting. */ if (event =3D=3D QAPI_EVENT_BLOCK_IO_ERROR) { - QDict *data =3D qobject_to(QDict, qdict_get(qdict, "data")); const char *action =3D qdict_get_str(data, "action"); if (!strcmp(action, "stop")) { rate_limit =3D 0; } } =20 + return rate_limit; +} + +static void monitor_qapi_event_handler(void *opaque); + +/* + * Queue a new event for emission to Monitor instances, + * applying any rate limiting if required. + */ +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); + MonitorQAPIEventState *evstate; + trace_monitor_protocol_event_queue(event, qdict, rate_limit); =20 QEMU_LOCK_GUARD(&monitor_lock); @@ -361,7 +368,6 @@ monitor_qapi_event_queue_no_reenter(QAPIEvent event, QD= ict *qdict) /* Unthrottled event */ monitor_qapi_event_emit(event, qdict); } else { - QDict *data =3D qobject_to(QDict, qdict_get(qdict, "data")); MonitorQAPIEventState key =3D { .event =3D event, .data =3D data }; =20 evstate =3D g_hash_table_lookup(monitor_qapi_event_state, &key); --=20 2.53.0 From nobody Mon Apr 6 18:24:25 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