From patchwork Tue Nov 7 09:49:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1860826 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=LLm+/0fJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SPk4D2CVTz1yQK for ; Tue, 7 Nov 2023 20:50:52 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r0Iid-0005hd-42; Tue, 07 Nov 2023 04:49:59 -0500 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 1r0Iib-0005hD-VF for qemu-devel@nongnu.org; Tue, 07 Nov 2023 04:49:57 -0500 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 1r0Iia-0006Wd-Gk for qemu-devel@nongnu.org; Tue, 07 Nov 2023 04:49:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699350595; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=lSp5s88JqE53+iDjE9NMtQoVBixzW55KFUTn7dS46ns=; b=LLm+/0fJhcLZ4TZfGdcPmd00vvu+ddc7gOA5HCn25WAhImNcvrzjMW4aw66q4+SWzoH48k 3GBcg9myMcXy2pi9MY2jUDg+SxYE03b8eUaNihYiJ/ekz5rtEIMl2Fe2tb4+cvEIvMJfHl TllbDzWdpNLKF95IyqemYjagW0Iri78= Received: from mail-oo1-f70.google.com (mail-oo1-f70.google.com [209.85.161.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-622-MDA83HpHPUWHRwrCJxuJyA-1; Tue, 07 Nov 2023 04:49:28 -0500 X-MC-Unique: MDA83HpHPUWHRwrCJxuJyA-1 Received: by mail-oo1-f70.google.com with SMTP id 006d021491bc7-581e2609a5dso7569267eaf.0 for ; Tue, 07 Nov 2023 01:49:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699350567; x=1699955367; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=lSp5s88JqE53+iDjE9NMtQoVBixzW55KFUTn7dS46ns=; b=PbLC1CbxF6vROmL+1Je88HK9Ys+7Pk7Rvk25x6EuL2OnSe7XgkTUyEDO1+BKr91SBT +qM1HB6K06I7YxqsWod6UFamh3H5HAI4hlu6YP6uuYphZ6TPAEn6/F4XWevzTLTYGScM zvu0dnKVpKSRDXDVCase/jSZ2EtW1mv3ewLWQA6MpzvCUjSUvwmi895mm8Mrj0+qFabe Ri5X6utj0GHUAo7bZdiMV55omyUYteK1gieLqbQlHn25+gfyhah5JSxCqCuEhy7oknsZ sogIgmDILfEnEgG1ikLhnSb7gp5B9DTBgD9RFE1mB3DHatW8echw3PnBWgM00wAJX9T0 qWRA== X-Gm-Message-State: AOJu0YzPOBB2l7JgoakiX6XXhki/0wLF/85WhkU0uJi2U7KFeU47/Lbe ImocxF2a/F1MG1s5bCtS4DYafrwJ6d3rxul5RjYL7QoMQP/sBYxUi6WbQSccMBGPtt3sV0VPGv3 mwAd7IMx7TWapXXefmRVGrpaX/DySZ0oR4sRDzSqPJihYcwRBh80cyhHicx38Sh9VnYtF X-Received: by 2002:a05:6820:1a08:b0:56c:d297:164c with SMTP id bq8-20020a0568201a0800b0056cd297164cmr36842215oob.4.1699350567799; Tue, 07 Nov 2023 01:49:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IENaIS9ovKdllFytI+yEPFYxBqgWKM5cVBIIzHYrq7obj2WNYQm5/VN3ExxF82c9tTYleQHfA== X-Received: by 2002:a05:6820:1a08:b0:56c:d297:164c with SMTP id bq8-20020a0568201a0800b0056cd297164cmr36842201oob.4.1699350567500; Tue, 07 Nov 2023 01:49:27 -0800 (PST) Received: from redhat.com ([2.55.5.143]) by smtp.gmail.com with ESMTPSA id c5-20020a4ad8c5000000b0057b38a94f38sm1898827oov.12.2023.11.07.01.49.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 01:49:26 -0800 (PST) Date: Tue, 7 Nov 2023 04:49:21 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Paolo Bonzini , =?utf-8?q?Marc?= =?utf-8?q?-Andr=C3=A9?= Lureau , Daniel =?utf-8?b?UC4gQmVycmFuZ8Op?= , Thomas Huth , Philippe =?utf-8?q?Mathieu-Daud=C3=A9?= Subject: [PATCH RFC 1/2] osdep: add getloadavg Message-ID: <1e64d2a47b63ba7d7f49a23c02c2be91ff5c15fe.1699350487.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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, 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org getloadavg is supported on Linux, BSDs, Solaris. Following man page: RETURN VALUE If the load average was unobtainable, -1 is returned; otherwise, the number of samples actually retrieved is returned. accordingly, make stub for systems which don't support this function return -1 for consistency. Signed-off-by: Michael S. Tsirkin --- include/qemu/osdep.h | 10 ++++++++++ meson.build | 1 + 2 files changed, 11 insertions(+) diff --git a/include/qemu/osdep.h b/include/qemu/osdep.h index 475a1c62ff..d30ba73eda 100644 --- a/include/qemu/osdep.h +++ b/include/qemu/osdep.h @@ -779,6 +779,16 @@ static inline int platform_does_not_support_system(const char *command) } #endif /* !HAVE_SYSTEM_FUNCTION */ +/** + * If the load average was unobtainable, -1 is returned + */ +#ifndef HAVE_GETLOADAVG_FUNCTION +static inline int getloadavg(double loadavg[], int nelem) +{ + return -1; +} +#endif /* !HAVE_GETLOADAVG_FUNCTION */ + #ifdef __cplusplus } #endif diff --git a/meson.build b/meson.build index dcef8b1e79..7f333cb80e 100644 --- a/meson.build +++ b/meson.build @@ -2254,6 +2254,7 @@ config_host_data.set('HAVE_GLIB_WITH_SLICE_ALLOCATOR', glib_has_gslice) config_host_data.set('HAVE_OPENPTY', cc.has_function('openpty', dependencies: util)) config_host_data.set('HAVE_STRCHRNUL', cc.has_function('strchrnul')) config_host_data.set('HAVE_SYSTEM_FUNCTION', cc.has_function('system', prefix: '#include ')) +config_host_data.set('HAVE_GETLOADAVG_FUNCTION', cc.has_function('getloadavg', prefix: '#include ')) if rbd.found() config_host_data.set('HAVE_RBD_NAMESPACE_EXISTS', cc.has_function('rbd_namespace_exists', From patchwork Tue Nov 7 09:49:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 1860824 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=V2Z7K4Lq; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=patchwork.ozlabs.org) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SPk3z4XFMz1yQK for ; Tue, 7 Nov 2023 20:50:39 +1100 (AEDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1r0IiV-0005Yi-8Y; Tue, 07 Nov 2023 04:49:51 -0500 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 1r0IiU-0005VI-Al for qemu-devel@nongnu.org; Tue, 07 Nov 2023 04:49:50 -0500 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 1r0IiS-0006VU-P9 for qemu-devel@nongnu.org; Tue, 07 Nov 2023 04:49:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699350588; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=CqGUbUKz1J6foLX0wqsHp2msAP52n1m0k2H2ScM6SAM=; b=V2Z7K4LqJouPDdCW8/MdAuWe5l7gXfCF95rXWxEXQROEQwoayoVm+O5/QktEs8dwtYpa26 WM8sOOFcJNC+YwboGEOTHoOLQa+U6CDXOqigLjltNOQuZ4rxO/H5y50xbMILow6fKBWl/a MXLzrS7B9IyzUpl/c0sTg9ZKEsW6dsg= Received: from mail-yb1-f199.google.com (mail-yb1-f199.google.com [209.85.219.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-466-riyc-tXWO9qsQEZEDz2GnQ-1; Tue, 07 Nov 2023 04:49:35 -0500 X-MC-Unique: riyc-tXWO9qsQEZEDz2GnQ-1 Received: by mail-yb1-f199.google.com with SMTP id 3f1490d57ef6-da0c6d62ec8so6385218276.1 for ; Tue, 07 Nov 2023 01:49:35 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699350574; x=1699955374; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=CqGUbUKz1J6foLX0wqsHp2msAP52n1m0k2H2ScM6SAM=; b=g0gy/Qiz2GdmplVzSR9bigDRzeEwyVom0tvyCT516Qr6PbWaQjXDJu5M/teH8n5jBu PtUNEm6LmjWCTLYqWpTFsMJhQVf5VbjlWV5EEVLVU8wjjsX4w8fm8Lj5jC+FbVzwv5Kp BLdyODTZFaJYyF2wwknBOVqd3tNeUWCuKRufhL0/s0IAdrGZHNuQvPz+QARkgRx+e3n9 4l7bkvN6gxlj9hcd8SFDb1shTAp7etFqmD9Vv6TPqZuQE0DUiSIyfAR4We/Xoj+4TyX9 UD5Ok6kcG/T2LOY3AcUmK7bKFizhg2zqmTqz+oS7lO+DSudh/xp5YxxTQCs70HZFdKaS Q8QA== X-Gm-Message-State: AOJu0Ywv+5eJdQW50AOh410TP2lFDnjvAm35EPXcaG/pcDYw1DZ0AHCr XIp3lvUmbZmRHn0QMPEV42BjzMa87rDmPedKhRBPVgxwrUr9wAFyZSuROgmm7STpG6XCMZf2QHN ePNgmFXDzQiy2bR0j7jEHXxAmR9Bw8EIIymX5HQ/7jOD5q6liVm9FkXXdO1EI5RWG2s+Z X-Received: by 2002:a25:6b43:0:b0:d9b:3ed:41a5 with SMTP id o3-20020a256b43000000b00d9b03ed41a5mr30032179ybm.21.1699350574107; Tue, 07 Nov 2023 01:49:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IH0NjKgp7rs/qMhoZgxMsv8dWut6K7Cco+KvuEuwoghhI70UL/5jw2zPmbmEgSVjK1T1lZk5A== X-Received: by 2002:a25:6b43:0:b0:d9b:3ed:41a5 with SMTP id o3-20020a256b43000000b00d9b03ed41a5mr30032159ybm.21.1699350573585; Tue, 07 Nov 2023 01:49:33 -0800 (PST) Received: from redhat.com ([2.55.5.143]) by smtp.gmail.com with ESMTPSA id h96-20020a25a569000000b00d9ace05037csm4972908ybi.13.2023.11.07.01.49.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Nov 2023 01:49:32 -0800 (PST) Date: Tue, 7 Nov 2023 04:49:27 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: stefanha@redhat.com, Thomas Huth , Laurent Vivier , Paolo Bonzini Subject: [PATCH RFC 2/2] netdev: set timeout depending on loadavg Message-ID: References: <1e64d2a47b63ba7d7f49a23c02c2be91ff5c15fe.1699350487.git.mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1e64d2a47b63ba7d7f49a23c02c2be91ff5c15fe.1699350487.git.mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass client-ip=170.10.133.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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, 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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org netdev test keeps failing sometimes. I don't think we should increase the timeout some more: let's try something else instead, testing how busy the system is. Seems to work for me. Signed-off-by: Michael S. Tsirkin --- tests/qtest/netdev-socket.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/qtest/netdev-socket.c b/tests/qtest/netdev-socket.c index 7ba1eff120..bb99d08b5e 100644 --- a/tests/qtest/netdev-socket.c +++ b/tests/qtest/netdev-socket.c @@ -18,6 +18,32 @@ #define CONNECTION_TIMEOUT 120 +static double connection_timeout(void) +{ + double load; + int ret = getloadavg(&load, 1); + + /* + * If we can't get load data, or load is low because we just started + * running, assume load of 1 (we are alone in this system). + */ + if (ret < 1 || load < 1.0) { + load = 1.0; + } + /* + * No one wants to wait more than 10 minutes for this test. Higher load? + * Too bad. + */ + if (load > 10.0) { + fprintf(stderr, "Warning: load %f higher than 10 - test might timeout\n", + load); + load = 10.0; + } + + /* if load is high increase timeout as we might not get a chance to run */ + return load * CONNECTION_TIMEOUT; +} + #define EXPECT_STATE(q, e, t) \ do { \ char *resp = NULL; \ @@ -31,7 +57,7 @@ do { \ if (g_str_equal(resp, e)) { \ break; \ } \ - } while (g_test_timer_elapsed() < CONNECTION_TIMEOUT); \ + } while (g_test_timer_elapsed() < connection_timeout()); \ g_assert_cmpstr(resp, ==, e); \ g_free(resp); \ } while (0)