From patchwork Wed Mar 21 16:32:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 132241 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp2356708ljb; Wed, 21 Mar 2018 09:35:35 -0700 (PDT) X-Google-Smtp-Source: AG47ELvQZhCbZLmd8it8yLoiSp5wHCDX/gBRt3dqKT9pdibVPQJVAjxbeW/NRemRJjjqtwLTRI5D X-Received: by 10.107.164.199 with SMTP id d68mr21769211ioj.34.1521650135539; Wed, 21 Mar 2018 09:35:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521650135; cv=none; d=google.com; s=arc-20160816; b=WR9EoEonuveNAVFB0Ehf8SapYkz2aIQuuKe5zU7uIRgNywmIxrGoX+mDBsAE0V7ra7 WhoYeTdsPPc9D/0mfSbigy7WSvL3WGqE9ZHe1X/EEXz75h1coiqxMtusUjaCrjyAmfbd DBusXkRdrQP1416aVTTnWGKu7waWzHbkj5IV9aJE5HK86SWqkV2KNJpFvRY7mKlCYdp8 NLr8DwSx4qJXjH5W5NVgtKzzR/uqjLn5vLwC0W0bsnK/dDkVJHKxgHVyuKEwcW9DNBgO bBtNHTkGaztVC7JHdbujqWbDG1xLZJfgNCLmIj6EhYDN6n90ZMDnQ1Yxw+yKyBvfiPmO l0Pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from :dkim-signature:arc-authentication-results; bh=hoLXJgob8O97M4ORhHMoVQ04SvCT0I49xgG6ocN28Ic=; b=EveBrbNJ5IPD94Zub4rPCKBuhueFMNlKn1WglstSwF+ckoCJyTrzvi86I8A/l5O1q6 sa+ANQ3ZT0gIHHtLSFX8is1eZ/LC4/abBN/1+wQYB+LFM0dPSE1nPeFPEC/FlNOm8NYZ wIkEYzkFhaOx5LubxuD77M0Q74MIFzuuR9oZIODOosfViETlBSvHA8I2lbNANbh4HK/J LLLHwwCKSCAgVIimszxpV2u1cpqTlkytHA+/CLWR7Zwhq9YBNgCaLQMKqIM7ydeWmRsF kT3+GBqbw33qfkuEmRUijyy1GgGqq3WAcSMazNUwRsNSnp5eU8Myid73Itefoe26oh52 +mKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Di9FiPp/; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id k23-v6si3585670iti.78.2018.03.21.09.35.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Mar 2018 09:35:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Di9FiPp/; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1eygfh-0002EE-C0; Wed, 21 Mar 2018 16:33:05 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1eygff-0002C2-SL for xen-devel@lists.xenproject.org; Wed, 21 Mar 2018 16:33:03 +0000 X-Inumbo-ID: 7d0f61c5-2d25-11e8-9728-bc764e045a96 Received: from mail-wr0-x241.google.com (unknown [2a00:1450:400c:c0c::241]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 7d0f61c5-2d25-11e8-9728-bc764e045a96; Wed, 21 Mar 2018 17:32:47 +0100 (CET) Received: by mail-wr0-x241.google.com with SMTP id o8so5839357wra.1 for ; Wed, 21 Mar 2018 09:33:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=p4CaT+9lth1tnc0+qypu5RlbSyrPXpUesf3JEBWQiXE=; b=Di9FiPp/KSUypOMyme8ULY8SchEZfJNhGB02AKHaXClOu9kqRTY/x7p7dkLW1UegI1 i9RMVdlSt8X46TSiqNpQ5usexnAwXBF5ePVPVduDbbKE+unc9vTDKMczoX+FEKBemTG1 lxyUq9V2/Tw0yLhx5Qw7/xOb9mZ2CvlI32iGs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=p4CaT+9lth1tnc0+qypu5RlbSyrPXpUesf3JEBWQiXE=; b=R+xUieIYjrfPPdkwVubTTMMvW+WfESsuy/UiYSGbMC7Pz4DtmBPi4aba9OiqVmcVru GZBl/T+9v9qSijkU8Sd+GkMPUDZIDr4wfQnLsTPhNFmpxPyeuWvXoBfRj25CCeOVdRJB XuFR2iyKuBxvgDOZhQH0NurEFtWtWpKpxrIUY4BiYLjnyYfvllXHp2KGMKzSWKjljcVm 2PER9fU3LL6/epvVv7A8RlpM2JiNbrXPCRnbOW2ydj5UrvSrbREYLt0B17Uy4hKxZOZY nOfYcVpzkf67OY6H7fUU7JMCXKJXBL/HQlDfK2O7b3zvm+x8UpGmh38TDS230ly82D/B BJdw== X-Gm-Message-State: AElRT7GcUChvY2wvxXSHO5QksZonxhlz52dFlduw3wA7hpwCnE8IHsxI n6khIs12Ikv/3jHFymP7BTJodg== X-Received: by 10.223.150.111 with SMTP id c44mr17708025wra.90.1521649981209; Wed, 21 Mar 2018 09:33:01 -0700 (PDT) Received: from e104803-lin.lan (mail.andrep.de. [217.160.17.100]) by smtp.gmail.com with ESMTPSA id n64sm4423724wmd.11.2018.03.21.09.33.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Mar 2018 09:33:00 -0700 (PDT) From: Andre Przywara To: Julien Grall , Stefano Stabellini Date: Wed, 21 Mar 2018 16:32:08 +0000 Message-Id: <20180321163235.12529-13-andre.przywara@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180321163235.12529-1-andre.przywara@linaro.org> References: <20180321163235.12529-1-andre.przywara@linaro.org> Subject: [Xen-devel] [PATCH v3 12/39] ARM: new VGIC: Add IRQ sorting 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: xen-devel@lists.xenproject.org, Andre Przywara MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Adds the sorting function to cover the case where you have more IRQs to consider than you have LRs. We consider their priorities. This uses the new sort_list() implementation imported from Linux. This is based on Linux commit 8e4447457965, written by Christoffer Dall. Signed-off-by: Andre Przywara Reviewed-by: Julien Grall Acked-by: Stefano Stabellini --- xen/arch/arm/vgic/vgic.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/xen/arch/arm/vgic/vgic.c b/xen/arch/arm/vgic/vgic.c index f7dfd01c1d..ee0de8d2e0 100644 --- a/xen/arch/arm/vgic/vgic.c +++ b/xen/arch/arm/vgic/vgic.c @@ -15,6 +15,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -193,6 +194,64 @@ static struct vcpu *vgic_target_oracle(struct vgic_irq *irq) return NULL; } +/* + * The order of items in the ap_lists defines how we'll pack things in LRs as + * well, the first items in the list being the first things populated in the + * LRs. + * + * A hard rule is that active interrupts can never be pushed out of the LRs + * (and therefore take priority) since we cannot reliably trap on deactivation + * of IRQs and therefore they have to be present in the LRs. + * + * Otherwise things should be sorted by the priority field and the GIC + * hardware support will take care of preemption of priority groups etc. + * + * Return negative if "a" sorts before "b", 0 to preserve order, and positive + * to sort "b" before "a". + */ +static int vgic_irq_cmp(void *priv, struct list_head *a, struct list_head *b) +{ + struct vgic_irq *irqa = container_of(a, struct vgic_irq, ap_list); + struct vgic_irq *irqb = container_of(b, struct vgic_irq, ap_list); + bool penda, pendb; + int ret; + + spin_lock(&irqa->irq_lock); + spin_lock(&irqb->irq_lock); + + if ( irqa->active || irqb->active ) + { + ret = (int)irqb->active - (int)irqa->active; + goto out; + } + + penda = irqa->enabled && irq_is_pending(irqa); + pendb = irqb->enabled && irq_is_pending(irqb); + + if ( !penda || !pendb ) + { + ret = (int)pendb - (int)penda; + goto out; + } + + /* Both pending and enabled, sort by priority */ + ret = irqa->priority - irqb->priority; +out: + spin_unlock(&irqb->irq_lock); + spin_unlock(&irqa->irq_lock); + return ret; +} + +/* Must be called with the ap_list_lock held */ +static void vgic_sort_ap_list(struct vcpu *vcpu) +{ + struct vgic_cpu *vgic_cpu = &vcpu->arch.vgic; + + ASSERT(spin_is_locked(&vgic_cpu->ap_list_lock)); + + list_sort(NULL, &vgic_cpu->ap_list_head, vgic_irq_cmp); +} + /* * Only valid injection if changing level for level-triggered IRQs or for a * rising edge.