From nobody Wed Feb 5 18:06:33 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1738669393; cv=none; d=zohomail.com; s=zohoarc; b=I6wJpivnnLr3lzMVKZqvtuf5OZ2xj3BnzkcjSKbUvKwklrJcM2c+DJOQBQllFxq7SfkwWR6jDsV2fWbOH7J3BGO23N4i4JZXPuAv1N8oPC5ZIDvfS2BjDBBfbLSViAyzhk00QRS7zCM/eLps9/52lgOQTnRn3KLNBYwr0c8T64U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1738669393; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=SBhBlO+itbvBLHIPM4oErzYEWzlr9/4zHcSqtxBR1Ww=; b=Ashx0UPa3YcoqlP+NNbul9JfzTSIlFzqIJ+85Xhr3L0IYoIXjOEL7VI/KOveblkseFBq+6sP2cwBBzvJgWHaeMJXCmV5u5sN+YwHAApl+vP2zjNrbcWJPp9BVcRR3oeGZJChCm9qTJyianUGo7/gzoU0Vle+J0btn7kTcU1dUfY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1738669393324449.1390646291293; Tue, 4 Feb 2025 03:43:13 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.881349.1291486 (Exim 4.92) (envelope-from ) id 1tfHKV-0007lB-4t; Tue, 04 Feb 2025 11:42:59 +0000 Received: by outflank-mailman (output) from mailman id 881349.1291486; Tue, 04 Feb 2025 11:42:59 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tfHKV-0007l4-13; Tue, 04 Feb 2025 11:42:59 +0000 Received: by outflank-mailman (input) for mailman id 881349; Tue, 04 Feb 2025 11:42:58 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1tfHCq-0001MV-79 for xen-devel@lists.xenproject.org; Tue, 04 Feb 2025 11:35:04 +0000 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 12b9572c-e2ec-11ef-99a4-01e77a169b0f; Tue, 04 Feb 2025 12:35:02 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 52CD0210FB; Tue, 4 Feb 2025 11:35:02 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 2A84C1393E; Tue, 4 Feb 2025 11:35:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id b67wCGb7oWf6LAAAD6G6ig (envelope-from ); Tue, 04 Feb 2025 11:35:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 12b9572c-e2ec-11ef-99a4-01e77a169b0f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1738668902; h=from:from:reply-to: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=SBhBlO+itbvBLHIPM4oErzYEWzlr9/4zHcSqtxBR1Ww=; b=uzsvKMi/YWzuHwLVOXXHwprVjZ9I2mh/lWTQmHi1Pdz+DSnnvCBnBBsNnu+gO7ZbBRAQSx cTtUTVSGEaVyYz/DF6vuOBwaanFlvhGgfhKM/i+E8/J66whx0rjwD3ZZ7JfzOkW18P3TDF iRQvDO+w5n/0egMLjPIHo2VDcotWB/Q= Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.com header.s=susede1 header.b="uzsvKMi/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1738668902; h=from:from:reply-to: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=SBhBlO+itbvBLHIPM4oErzYEWzlr9/4zHcSqtxBR1Ww=; b=uzsvKMi/YWzuHwLVOXXHwprVjZ9I2mh/lWTQmHi1Pdz+DSnnvCBnBBsNnu+gO7ZbBRAQSx cTtUTVSGEaVyYz/DF6vuOBwaanFlvhGgfhKM/i+E8/J66whx0rjwD3ZZ7JfzOkW18P3TDF iRQvDO+w5n/0egMLjPIHo2VDcotWB/Q= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Julien Grall , Anthony PERARD Subject: [PATCH v8 9/9] tools/xenstored: use xenmanage_poll_changed_domain() Date: Tue, 4 Feb 2025 12:34:07 +0100 Message-ID: <20250204113407.16839-10-jgross@suse.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250204113407.16839-1-jgross@suse.com> References: <20250204113407.16839-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 52CD0210FB X-Spam-Level: X-Spamd-Result: default: False [-3.01 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; MID_CONTAINS_FROM(1.00)[]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.com:s=susede1]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:email,suse.com:dkim,suse.com:mid,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; RCPT_COUNT_THREE(0.00)[4]; DKIM_TRACE(0.00)[suse.com:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -3.01 X-Spam-Flag: NO X-ZohoMail-DKIM: pass (identity @suse.com) X-ZM-MESSAGEID: 1738669395811019100 Content-Type: text/plain; charset="utf-8" Instead of checking each known domain after having received a VIRQ_DOM_EXC event, use the new xenmanage_poll_changed_domain() function for directly getting the domid of a domain having changed its state. A test doing "xl shutdown" of 1000 guests has shown to reduce the consumed cpu time of xenstored by 6% with this change applied. Signed-off-by: Juergen Gross --- V8: - new patch --- tools/xenstored/domain.c | 64 +++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/tools/xenstored/domain.c b/tools/xenstored/domain.c index 63df24030e..ad16a00ce3 100644 --- a/tools/xenstored/domain.c +++ b/tools/xenstored/domain.c @@ -621,30 +621,24 @@ static int destroy_domain(void *_domain) return 0; } =20 -static int check_domain(const void *k, void *v, void *arg) +static int do_check_domain(struct domain *domain, bool *notify, + unsigned int state, uint64_t unique_id) { - unsigned int state; struct connection *conn; - int dom_invalid; - struct domain *domain =3D v; - bool *notify =3D arg; - uint64_t unique_id; =20 - dom_invalid =3D xenmanage_get_domain_info(xm_handle, domain->domid, - &state, &unique_id); - if (!dom_invalid) { + if (unique_id) { if (!domain->unique_id) domain->unique_id =3D unique_id; else if (domain->unique_id !=3D unique_id) - dom_invalid =3D 1; + unique_id =3D 0; } =20 if (!domain->introduced) { - if (dom_invalid) + if (!unique_id) talloc_free(domain); return 0; } - if (!dom_invalid) { + if (unique_id) { if ((state & XENMANAGE_GETDOMSTATE_STATE_SHUTDOWN) && !domain->shutdown) { domain->shutdown =3D true; @@ -667,6 +661,21 @@ static int check_domain(const void *k, void *v, void *= arg) return 0; } =20 +static int check_domain(const void *k, void *v, void *arg) +{ + struct domain *domain =3D v; + unsigned int state; + uint64_t unique_id; + + if (xenmanage_get_domain_info(xm_handle, domain->domid, &state, + &unique_id)) { + unique_id =3D 0; + state =3D 0; + } + + return do_check_domain(domain, arg, state, unique_id); +} + void check_domains(void) { bool notify =3D false; @@ -678,6 +687,30 @@ void check_domains(void) fire_special_watches("@releaseDomain"); } =20 +static struct domain *find_domain_struct(unsigned int domid) +{ + return hashtable_search(domhash, &domid); +} + +static void do_check_domains(void) +{ + unsigned int domid; + unsigned int state; + uint64_t unique_id; + struct domain *domain; + bool notify =3D false; + + while (!xenmanage_poll_changed_domain(xm_handle, &domid, &state, + &unique_id)) { + domain =3D find_domain_struct(domid); + if (domain) + do_check_domain(domain, ¬ify, state, unique_id); + } + + if (notify) + fire_special_watches("@releaseDomain"); +} + /* We scan all domains rather than use the information given here. */ void handle_event(void) { @@ -687,7 +720,7 @@ void handle_event(void) barf_perror("Failed to read from event fd"); =20 if (port =3D=3D virq_port) - check_domains(); + do_check_domains(); =20 if (xenevtchn_unmask(xce_handle, port) =3D=3D -1) barf_perror("Failed to write to event fd"); @@ -698,11 +731,6 @@ static char *talloc_domain_path(const void *context, u= nsigned int domid) return talloc_asprintf(context, "/local/domain/%u", domid); } =20 -static struct domain *find_domain_struct(unsigned int domid) -{ - return hashtable_search(domhash, &domid); -} - int domain_get_quota(const void *ctx, struct connection *conn, unsigned int domid) { --=20 2.43.0