From nobody Sun Nov 24 14:12:09 2024 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=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1722501929; cv=none; d=zohomail.com; s=zohoarc; b=GI8joNO0oKq4Sdj+5hUbHQAoelvKvbfBD9n9g1DYWRQfHon9/+L9p9G5kG4grsgYU3ZJRGnti6oA//3NErv3oX8wFWtGAkKOGoGh0DLDsPKX9vOFUZY8wnOoM5V4I7YvLgVlnc7DnPtwQZNN1fyakTr2IADgQgX6b9VdZpsX4mQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722501929; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=z25aylodNUmaRECFBFJ0qpEZDzKdJk8uzwwNHcV1bMA=; b=iAhqpIIColprdflclIJxCD6HrmNDDZWfY9/0AHG2LnvBf2333BvtElMsBHXXILQhsfs07U+9hp9duNHQorjK0iWvbtI93Wwh53CUPTxihC/sQvvW7p3pKRhwcZwaLMSqttBTUeBrnWmAQxjjWbbh04OmoKoG9Hr1zyDxzYxUfIY= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1722501929687956.5854367776574; Thu, 1 Aug 2024 01:45:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sZRQt-0003DY-Vo; Thu, 01 Aug 2024 04:45:12 -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 1sZRQr-0003D4-Hs for qemu-devel@nongnu.org; Thu, 01 Aug 2024 04:45:09 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sZRQp-0005n1-Hn for qemu-devel@nongnu.org; Thu, 01 Aug 2024 04:45:09 -0400 Received: from mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:a52d:0:640:f75d:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 41D3760AF8; Thu, 1 Aug 2024 11:45:04 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6b8:b081:b657::1:21]) by mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id giSnBU7GXSw0-XwVR4L84; Thu, 01 Aug 2024 11:45:03 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1722501903; bh=z25aylodNUmaRECFBFJ0qpEZDzKdJk8uzwwNHcV1bMA=; h=Message-Id:Date:Cc:Subject:To:From; b=aXwP/D0fUkD0TBjIxPW/f86e4TfWSPTUmeHUlUUzZ4r5ls0uoJJNGW6hBBoGvGjiU gg4g3xt351biEhdB0kAyQi5j3AW4E88Dv/gAeAzWlVmMXD4UQZv/q5iF/ybMSixqlo zZWbA1abIDKH2XS27JqwKQP2/QpePAmnruxjBMdE= Authentication-Results: mail-nwsmtp-smtp-corp-main-66.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, marcandre.lureau@redhat.com, raphael@enfabrica.net, mst@redhat.com, yc-core@yandex-team.ru, den-plotnikov@yandex-team.ru, vsementsov@yandex-team.ru, d-tatianin@yandex-team.ru Subject: [PATCH] char-socket: grow timeout from smaller value Date: Thu, 1 Aug 2024 11:44:39 +0300 Message-Id: <20240801084439.10515-1-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: 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 @yandex-team.ru) X-ZM-MESSAGEID: 1722501931238116600 Content-Type: text/plain; charset="utf-8" The smallest possible timeout for reconnect to set in QAPI is 1 second. But for system where reconnect is considered a regular situation and backend is guaranteed to start in tens of milliseconds this timeout of 1 second becomes an extra throttling. On the other hand, just allowing smaller timeout would be ineffective when we consider unplanned disconnect for larger time. Let's do a simple thing: without any change to API, start reconnecting with some small constant timeout (5 ms), increasing it exponentially up to user given value. Signed-off-by: Vladimir Sementsov-Ogievskiy --- Hi all! We faced too long (1 second) pauses in IO during reconnect to vhost server, and this 1 second is exactly reconnect=3D1 parameter of char-socket. Here is our solution for the problem. chardev/char-socket.c | 21 ++++++++++++++++----- include/chardev/char-socket.h | 5 ++++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 1ca9441b1b..4a35f75ebe 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -74,9 +74,10 @@ static void qemu_chr_socket_restart_timer(Chardev *chr) assert(!s->reconnect_timer); name =3D g_strdup_printf("chardev-socket-reconnect-%s", chr->label); s->reconnect_timer =3D qemu_chr_timeout_add_ms(chr, - s->reconnect_time * 1000, + s->reconnect_ms, socket_reconnect_timeout, chr); + s->reconnect_ms =3D MIN(s->reconnect_ms * 2, s->reconnect_ms_max); g_source_set_name(s->reconnect_timer, name); g_free(name); } @@ -481,7 +482,7 @@ static void tcp_chr_disconnect_locked(Chardev *chr) if (emit_close) { qemu_chr_be_event(chr, CHR_EVENT_CLOSED); } - if (s->reconnect_time && !s->reconnect_timer) { + if (s->reconnect_ms && !s->reconnect_timer) { qemu_chr_socket_restart_timer(chr); } } @@ -1080,9 +1081,11 @@ static int tcp_chr_wait_connected(Chardev *chr, Erro= r **errp) } else { Error *err =3D NULL; if (tcp_chr_connect_client_sync(chr, &err) < 0) { - if (s->reconnect_time) { + if (s->reconnect_ms) { error_free(err); - g_usleep(s->reconnect_time * 1000ULL * 1000ULL); + g_usleep(s->reconnect_ms * 1000ULL); + s->reconnect_ms =3D MIN(s->reconnect_ms * 2, + s->reconnect_ms_max); } else { error_propagate(errp, err); return -1; @@ -1091,6 +1094,10 @@ static int tcp_chr_wait_connected(Chardev *chr, Erro= r **errp) } } =20 + if (s->reconnect_ms) { + s->reconnect_ms =3D SOCKET_CHARDEV_RECONNECT_MS_MIN; + } + return 0; } =20 @@ -1147,6 +1154,9 @@ static void qemu_chr_socket_connected(QIOTask *task, = void *opaque) goto cleanup; } =20 + if (s->reconnect_ms) { + s->reconnect_ms =3D SOCKET_CHARDEV_RECONNECT_MS_MIN; + } s->connect_err_reported =3D false; tcp_chr_new_client(chr, sioc); =20 @@ -1273,7 +1283,8 @@ static int qmp_chardev_open_socket_client(Chardev *ch= r, SocketChardev *s =3D SOCKET_CHARDEV(chr); =20 if (reconnect > 0) { - s->reconnect_time =3D reconnect; + s->reconnect_ms_max =3D reconnect * 1000; + s->reconnect_ms =3D SOCKET_CHARDEV_RECONNECT_MS_MIN; tcp_chr_connect_client_async(chr); return 0; } else { diff --git a/include/chardev/char-socket.h b/include/chardev/char-socket.h index 0708ca6fa9..f464c4c1c7 100644 --- a/include/chardev/char-socket.h +++ b/include/chardev/char-socket.h @@ -33,6 +33,8 @@ =20 #define TCP_MAX_FDS 16 =20 +#define SOCKET_CHARDEV_RECONNECT_MS_MIN 5 + typedef struct { char buf[21]; size_t buflen; @@ -74,7 +76,8 @@ struct SocketChardev { bool is_websock; =20 GSource *reconnect_timer; - int64_t reconnect_time; + int64_t reconnect_ms_max; + int64_t reconnect_ms; bool connect_err_reported; =20 QIOTask *connect_task; --=20 2.34.1