From nobody Tue Jan 21 07:39:44 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1736365591680381.907969918362; Wed, 8 Jan 2025 11:46:31 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id A04D91424; Wed, 8 Jan 2025 14:46:30 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 36A79147D; Wed, 8 Jan 2025 14:43:29 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id C5F6F1471; Wed, 8 Jan 2025 14:43:24 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 95A59140F for ; Wed, 8 Jan 2025 14:43:10 -0500 (EST) 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-278-XjG5B-BUPiKphijl80FUsQ-1; Wed, 08 Jan 2025 14:43:08 -0500 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 C16D71944EB6 for ; Wed, 8 Jan 2025 19:43:07 +0000 (UTC) Received: from toolbx.redhat.com (unknown [10.42.28.103]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E4DA3300018D; Wed, 8 Jan 2025 19:43:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736365390; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dCW6gkCrKP3QHYqUd6hi2oNZzGe/XGt9l30+d9QUdPw=; b=C4qqQ881p40yAdLdesV6alNmQI+b+VNQHWsuN5fQ7mvBXWVHvdcOtJwgOGUQBLdLIWEMIb s90pPuFJLTjY+G9+AqSwWN7H0VKz0WwGYPssqDD8X7xVNg+KuQAtgbdxrpYZ93Iif0IGH8 RmkOEtwGEF9JNfH8gG2DJQMYMY6bM2M= X-MC-Unique: XjG5B-BUPiKphijl80FUsQ-1 X-Mimecast-MFC-AGG-ID: XjG5B-BUPiKphijl80FUsQ From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: devel@lists.libvirt.org Cc: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH 05/26] hypervisor: add support for delay interval during autostart Date: Wed, 8 Jan 2025 19:42:38 +0000 Message-ID: <20250108194259.1171990-6-berrange@redhat.com> In-Reply-To: <20250108194259.1171990-1-berrange@redhat.com> References: <20250108194259.1171990-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: mqqyrAl_zjyrW_EfROMx4hVKAXqWLszr3sWtmhswmtI_1736365387 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: HXISMT5PLGM3RPRAAR43ADLQZGMWSJKV X-Message-ID-Hash: HXISMT5PLGM3RPRAAR43ADLQZGMWSJKV X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1736365706800116600 Content-Type: text/plain; charset="utf-8" This delay can reduce the CPU/IO load storm when autostarting many guests. Signed-off-by: Daniel P. Berrang=C3=A9 --- src/hypervisor/domain_driver.c | 20 +++++++++++++++++--- src/hypervisor/domain_driver.h | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index c5b082fd00..44c8fad4d5 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -656,11 +656,16 @@ virDomainDriverGetIOThreadsConfig(virDomainDef *targe= tDef, return ret; } =20 +typedef struct _virDomainDriverAutoStartState { + virDomainDriverAutoStartConfig *cfg; + bool first; +} virDomainDriverAutoStartState; + static int virDomainDriverAutoStartOne(virDomainObj *vm, void *opaque) { - virDomainDriverAutoStartConfig *cfg =3D opaque; + virDomainDriverAutoStartState *state =3D opaque; =20 virObjectLock(vm); virObjectRef(vm); @@ -670,7 +675,15 @@ virDomainDriverAutoStartOne(virDomainObj *vm, =20 if (vm->autostart && !virDomainObjIsActive(vm)) { virResetLastError(); - cfg->callback(vm, cfg->opaque); + if (state->cfg->delayMS) { + if (!state->first) { + g_usleep(state->cfg->delayMS * 1000ull); + } else { + state->first =3D false; + } + } + + state->cfg->callback(vm, state->cfg->opaque); } =20 virDomainObjEndAPI(&vm); @@ -682,6 +695,7 @@ virDomainDriverAutoStartOne(virDomainObj *vm, void virDomainDriverAutoStart(virDomainObjList *domains, virDomainDriverAutoStartConfig *cfg) { + virDomainDriverAutoStartState state =3D { .cfg =3D cfg, .first =3D tru= e }; bool autostart; VIR_DEBUG("Run autostart stateDir=3D%s", cfg->stateDir); if (virDriverShouldAutostart(cfg->stateDir, &autostart) < 0 || @@ -690,5 +704,5 @@ void virDomainDriverAutoStart(virDomainObjList *domains, return; } =20 - virDomainObjListForEach(domains, false, virDomainDriverAutoStartOne, c= fg); + virDomainObjListForEach(domains, false, virDomainDriverAutoStartOne, &= state); } diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index c27ed9155e..d695e26f90 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -84,6 +84,7 @@ typedef struct _virDomainDriverAutoStartConfig { char *stateDir; virDomainDriverAutoStartCallback callback; void *opaque; + int delayMS; /* milliseconds between starting each guest */ } virDomainDriverAutoStartConfig; =20 void virDomainDriverAutoStart(virDomainObjList *domains, --=20 2.47.1