From nobody Thu Apr 25 11:43:44 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1557512983; cv=none; d=zoho.com; s=zohoarc; b=H/9u3hmDmvfrjAGu89FCz/SmQpAWqhKuAYZD8p/4BHMmidYY/jl8EwYdBGeORmUGNOI7PfSNH47RoeYKrRfc0G45syLNx5FqJabCwoiRkLNJOPj1sjUIDwSilGwz6CTvVaSlaUrtd0H1SXSLwBx2Sq/kkEEyvumXC14im4C53qs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557512983; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=2eTrEyF0/kxL92mfLvBn4p6lf8IuCrU4lmIMzPfujxY=; b=GUShQAiHUEtEX7tU5G3Fo5PpAuXE3PsYXUFfZj974dUI028hgPsVgvrrar7mlMgooloLoDfNrDA3v8S2uCVmY9zCju70E/2IVmACYVqKsqxasoHTS5kqGVCV+7WXzAgmCjrg2sukyTmOXh3LJdgVAUA44+m+cmFTUtvr8IN0BAU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1557512983295385.32085431667224; Fri, 10 May 2019 11:29:43 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hPAFl-0006wJ-FT; Fri, 10 May 2019 18:28:17 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hPAFj-0006vy-N7 for xen-devel@lists.xenproject.org; Fri, 10 May 2019 18:28:15 +0000 Received: from SMTP03.CITRIX.COM (unknown [162.221.156.55]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5cba340a-7351-11e9-b1a9-c7d1e482a741; Fri, 10 May 2019 18:28:10 +0000 (UTC) X-Inumbo-ID: 5cba340a-7351-11e9-b1a9-c7d1e482a741 X-IronPort-AV: E=Sophos;i="5.60,454,1549929600"; d="scan'208";a="85337736" From: Andrew Cooper To: Xen-devel Date: Fri, 10 May 2019 19:28:02 +0100 Message-ID: <1557512884-32395-3-git-send-email-andrew.cooper3@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1557512884-32395-1-git-send-email-andrew.cooper3@citrix.com> References: <1557512884-32395-1-git-send-email-andrew.cooper3@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 2/4] xen/watchdog: Rearrange the logic to fold the timer-arming paths X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , George Dunlap , Andrew Cooper , Christian Lindig , Pau Ruiz Safont , Julien Grall , =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= , Jan Beulich , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" By rearranging the logic, the timer allocation loop can reuse the common ti= mer arming/clearing logic. This results in easier to follow code, and a modest reduction in compiled code size (-64, 290 =3D> 226). For domains which use watchdogs, the overwhemling majoriy of hypercalls will be re-arming an existing timer. Arrange the fastpath to match. This does cause one change in behaviour for a corner case. Previously, specifying id =3D 0, timeout =3D 0 would instantly kill the domain, as the = timer would fire before returning to the guest. This corner case is going to be reused for a different purpose in a later change. Signed-off-by: Andrew Cooper --- CC: Jan Beulich CC: Wei Liu CC: Roger Pau Monn=C3=A9 CC: Stefano Stabellini CC: Julien Grall CC: George Dunlap CC: Edwin T=C3=B6r=C3=B6k CC: Christian Lindig CC: Pau Ruiz Safont --- xen/common/schedule.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/xen/common/schedule.c b/xen/common/schedule.c index 47f5d04..89aba88 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -1057,35 +1057,39 @@ static long domain_watchdog(struct domain *d, uint3= 2_t id, uint32_t timeout) =20 spin_lock(&d->watchdog_lock); =20 - if ( id =3D=3D 0 ) + if ( likely(id !=3D 0) ) /* Operate on a specific timer. */ + { + id -=3D 1; + if ( !test_bit(id, &d->watchdog_inuse_map) ) + { + rc =3D -EINVAL; + goto unlock; + } + } + else /* Allocate the next available timer. */ { for ( id =3D 0; id < NR_DOMAIN_WATCHDOG_TIMERS; id++ ) { if ( test_and_set_bit(id, &d->watchdog_inuse_map) ) continue; - set_timer(&d->watchdog_timer[id], NOW() + SECONDS(timeout)); break; } - rc =3D id =3D=3D NR_DOMAIN_WATCHDOG_TIMERS ? -ENOSPC : id + 1; - goto unlock; - } - - id -=3D 1; - if ( !test_bit(id, &d->watchdog_inuse_map) ) - { - rc =3D -EINVAL; - goto unlock; + if ( id =3D=3D NR_DOMAIN_WATCHDOG_TIMERS ) + { + rc =3D -ENOSPC; + goto unlock; + } + rc =3D id + 1; } =20 - if ( timeout =3D=3D 0 ) + /* (re-)arm, or clear a specific timer. */ + if ( unlikely(timeout =3D=3D 0) ) { stop_timer(&d->watchdog_timer[id]); clear_bit(id, &d->watchdog_inuse_map); } else - { set_timer(&d->watchdog_timer[id], NOW() + SECONDS(timeout)); - } =20 unlock: spin_unlock(&d->watchdog_lock); --=20 2.1.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel